]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.10.5-201308052154.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.10.5-201308052154.patch
CommitLineData
823d7d7f
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..79768fb 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,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52+TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56@@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60+ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64@@ -92,19 +101,24 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68+builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74+clut_vga16.c
75+common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82+config.c
83 config.mak
84 config.mak.autogen
85+config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89@@ -115,9 +129,11 @@ devlist.h*
90 dnotify_test
91 docproc
92 dslm
93+dtc-lexer.lex.c
94 elf2ecoff
95 elfconfig.h*
96 evergreen_reg_safe.h
97+exception_policy.conf
98 fixdep
99 flask.h
100 fore200e_mkfirm
101@@ -125,12 +141,15 @@ fore200e_pca_fw.c*
102 gconf
103 gconf.glade.h
104 gen-devlist
105+gen-kdb_cmds.c
106 gen_crc32table
107 gen_init_cpio
108 generated
109 genheaders
110 genksyms
111 *_gray256.c
112+hash
113+hid-example
114 hpet_example
115 hugepage-mmap
116 hugepage-shm
117@@ -145,14 +164,14 @@ int32.c
118 int4.c
119 int8.c
120 kallsyms
121-kconfig
122+kern_constants.h
123 keywords.c
124 ksym.c*
125 ksym.h*
126 kxgettext
127 lex.c
128 lex.*.c
129-linux
130+lib1funcs.S
131 logo_*.c
132 logo_*_clut224.c
133 logo_*_mono.c
134@@ -162,14 +181,15 @@ mach-types.h
135 machtypes.h
136 map
137 map_hugetlb
138-media
139 mconf
140+mdp
141 miboot*
142 mk_elfconfig
143 mkboot
144 mkbugboot
145 mkcpustr
146 mkdep
147+mkpiggy
148 mkprep
149 mkregtable
150 mktables
151@@ -185,6 +205,8 @@ oui.c*
152 page-types
153 parse.c
154 parse.h
155+parse-events*
156+pasyms.h
157 patches*
158 pca200e.bin
159 pca200e_ecd.bin2
160@@ -194,6 +216,7 @@ perf-archive
161 piggyback
162 piggy.gzip
163 piggy.S
164+pmu-*
165 pnmtologo
166 ppc_defs.h*
167 pss_boot.h
168@@ -203,7 +226,10 @@ r200_reg_safe.h
169 r300_reg_safe.h
170 r420_reg_safe.h
171 r600_reg_safe.h
172+realmode.lds
173+realmode.relocs
174 recordmcount
175+regdb.c
176 relocs
177 rlim_names.h
178 rn50_reg_safe.h
179@@ -213,8 +239,12 @@ series
180 setup
181 setup.bin
182 setup.elf
183+signing_key*
184+size_overflow_hash.h
185 sImage
186+slabinfo
187 sm_tbl*
188+sortextable
189 split-include
190 syscalltab.h
191 tables.c
192@@ -224,6 +254,7 @@ tftpboot.img
193 timeconst.h
194 times.h*
195 trix_boot.h
196+user_constants.h
197 utsrelease.h*
198 vdso-syms.lds
199 vdso.lds
200@@ -235,13 +266,17 @@ vdso32.lds
201 vdso32.so.dbg
202 vdso64.lds
203 vdso64.so.dbg
204+vdsox32.lds
205+vdsox32-syms.lds
206 version.h*
207 vmImage
208 vmlinux
209 vmlinux-*
210 vmlinux.aout
211 vmlinux.bin.all
212+vmlinux.bin.bz2
213 vmlinux.lds
214+vmlinux.relocs
215 vmlinuz
216 voffset.h
217 vsyscall.lds
218@@ -249,9 +284,12 @@ vsyscall_32.lds
219 wanxlfw.inc
220 uImage
221 unifdef
222+utsrelease.h
223 wakeup.bin
224 wakeup.elf
225 wakeup.lds
226+x509*
227 zImage*
228 zconf.hash.c
229+zconf.lex.c
230 zoffset.h
231diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
232index 2fe6e76..df58221 100644
233--- a/Documentation/kernel-parameters.txt
234+++ b/Documentation/kernel-parameters.txt
235@@ -976,6 +976,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
236 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
237 Default: 1024
238
239+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
240+ ignore grsecurity's /proc restrictions
241+
242+
243 hashdist= [KNL,NUMA] Large hashes allocated during boot
244 are distributed across NUMA nodes. Defaults on
245 for 64-bit NUMA, off otherwise.
246@@ -2195,6 +2199,22 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
247 the specified number of seconds. This is to be used if
248 your oopses keep scrolling off the screen.
249
250+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
251+ virtualization environments that don't cope well with the
252+ expand down segment used by UDEREF on X86-32 or the frequent
253+ page table updates on X86-64.
254+
255+ pax_sanitize_slab=
256+ 0/1 to disable/enable slab object sanitization (enabled by
257+ default).
258+
259+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
260+
261+ pax_extra_latent_entropy
262+ Enable a very simple form of latent entropy extraction
263+ from the first 4GB of memory as the bootmem allocator
264+ passes the memory pages to the buddy allocator.
265+
266 pcbit= [HW,ISDN]
267
268 pcd. [PARIDE]
269diff --git a/Makefile b/Makefile
270index f8349d0..563a504 100644
271--- a/Makefile
272+++ b/Makefile
273@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
274
275 HOSTCC = gcc
276 HOSTCXX = g++
277-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
278-HOSTCXXFLAGS = -O2
279+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
280+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
281+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
282
283 # Decide whether to build built-in, modular, or both.
284 # Normally, just do built-in.
285@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
286 # Rules shared between *config targets and build targets
287
288 # Basic helpers built in scripts/
289-PHONY += scripts_basic
290-scripts_basic:
291+PHONY += scripts_basic gcc-plugins
292+scripts_basic: gcc-plugins
293 $(Q)$(MAKE) $(build)=scripts/basic
294 $(Q)rm -f .tmp_quiet_recordmcount
295
296@@ -576,6 +577,65 @@ else
297 KBUILD_CFLAGS += -O2
298 endif
299
300+ifndef DISABLE_PAX_PLUGINS
301+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
302+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
303+else
304+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
305+endif
306+ifneq ($(PLUGINCC),)
307+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
308+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
309+endif
310+ifdef CONFIG_PAX_MEMORY_STACKLEAK
311+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
312+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
313+endif
314+ifdef CONFIG_KALLOCSTAT_PLUGIN
315+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
316+endif
317+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
318+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
319+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
320+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
321+endif
322+ifdef CONFIG_CHECKER_PLUGIN
323+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
324+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
325+endif
326+endif
327+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
328+ifdef CONFIG_PAX_SIZE_OVERFLOW
329+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
330+endif
331+ifdef CONFIG_PAX_LATENT_ENTROPY
332+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
333+endif
334+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
335+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
336+endif
337+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
338+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
339+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
340+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
341+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
342+ifeq ($(KBUILD_EXTMOD),)
343+gcc-plugins:
344+ $(Q)$(MAKE) $(build)=tools/gcc
345+else
346+gcc-plugins: ;
347+endif
348+else
349+gcc-plugins:
350+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
351+ $(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.))
352+else
353+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
354+endif
355+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
356+endif
357+endif
358+
359 include $(srctree)/arch/$(SRCARCH)/Makefile
360
361 ifdef CONFIG_READABLE_ASM
362@@ -733,7 +793,7 @@ export mod_sign_cmd
363
364
365 ifeq ($(KBUILD_EXTMOD),)
366-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
367+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
368
369 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
370 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
371@@ -782,6 +842,8 @@ endif
372
373 # The actual objects are generated when descending,
374 # make sure no implicit rule kicks in
375+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
376+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
377 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
378
379 # Handle descending into subdirectories listed in $(vmlinux-dirs)
380@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
381 # Error messages still appears in the original language
382
383 PHONY += $(vmlinux-dirs)
384-$(vmlinux-dirs): prepare scripts
385+$(vmlinux-dirs): gcc-plugins prepare scripts
386 $(Q)$(MAKE) $(build)=$@
387
388 # Store (new) KERNELRELASE string in include/config/kernel.release
389@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
390 $(Q)$(MAKE) $(build)=.
391
392 # All the preparing..
393+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
394 prepare: prepare0
395
396 # Generate some files
397@@ -942,6 +1005,8 @@ all: modules
398 # using awk while concatenating to the final file.
399
400 PHONY += modules
401+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
402+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
403 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
404 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
405 @$(kecho) ' Building modules, stage 2.';
406@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
407
408 # Target to prepare building external modules
409 PHONY += modules_prepare
410-modules_prepare: prepare scripts
411+modules_prepare: gcc-plugins prepare scripts
412
413 # Target to install modules
414 PHONY += modules_install
415@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
416 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
417 signing_key.priv signing_key.x509 x509.genkey \
418 extra_certificates signing_key.x509.keyid \
419- signing_key.x509.signer
420+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
421
422 # clean - Delete most, but leave enough to build external modules
423 #
424@@ -1063,6 +1128,7 @@ distclean: mrproper
425 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
426 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
427 -o -name '.*.rej' \
428+ -o -name '.*.rej' -o -name '*.so' \
429 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
430 -type f -print | xargs rm -f
431
432@@ -1223,6 +1289,8 @@ PHONY += $(module-dirs) modules
433 $(module-dirs): crmodverdir $(objtree)/Module.symvers
434 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
435
436+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
437+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
438 modules: $(module-dirs)
439 @$(kecho) ' Building modules, stage 2.';
440 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
441@@ -1359,17 +1427,21 @@ else
442 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
443 endif
444
445-%.s: %.c prepare scripts FORCE
446+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
447+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
448+%.s: %.c gcc-plugins prepare scripts FORCE
449 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
450 %.i: %.c prepare scripts FORCE
451 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
452-%.o: %.c prepare scripts FORCE
453+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
454+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
455+%.o: %.c gcc-plugins prepare scripts FORCE
456 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
457 %.lst: %.c prepare scripts FORCE
458 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
459-%.s: %.S prepare scripts FORCE
460+%.s: %.S gcc-plugins prepare scripts FORCE
461 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
462-%.o: %.S prepare scripts FORCE
463+%.o: %.S gcc-plugins prepare scripts FORCE
464 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
465 %.symtypes: %.c prepare scripts FORCE
466 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
467@@ -1379,11 +1451,15 @@ endif
468 $(cmd_crmodverdir)
469 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
470 $(build)=$(build-dir)
471-%/: prepare scripts FORCE
472+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
473+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
474+%/: gcc-plugins prepare scripts FORCE
475 $(cmd_crmodverdir)
476 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
477 $(build)=$(build-dir)
478-%.ko: prepare scripts FORCE
479+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
480+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
481+%.ko: gcc-plugins prepare scripts FORCE
482 $(cmd_crmodverdir)
483 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
484 $(build)=$(build-dir) $(@:.ko=.o)
485diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
486index c2cbe4f..f7264b4 100644
487--- a/arch/alpha/include/asm/atomic.h
488+++ b/arch/alpha/include/asm/atomic.h
489@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
490 #define atomic_dec(v) atomic_sub(1,(v))
491 #define atomic64_dec(v) atomic64_sub(1,(v))
492
493+#define atomic64_read_unchecked(v) atomic64_read(v)
494+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
495+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
496+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
497+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
498+#define atomic64_inc_unchecked(v) atomic64_inc(v)
499+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
500+#define atomic64_dec_unchecked(v) atomic64_dec(v)
501+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
502+
503 #define smp_mb__before_atomic_dec() smp_mb()
504 #define smp_mb__after_atomic_dec() smp_mb()
505 #define smp_mb__before_atomic_inc() smp_mb()
506diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
507index ad368a9..fbe0f25 100644
508--- a/arch/alpha/include/asm/cache.h
509+++ b/arch/alpha/include/asm/cache.h
510@@ -4,19 +4,19 @@
511 #ifndef __ARCH_ALPHA_CACHE_H
512 #define __ARCH_ALPHA_CACHE_H
513
514+#include <linux/const.h>
515
516 /* Bytes per L1 (data) cache line. */
517 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
518-# define L1_CACHE_BYTES 64
519 # define L1_CACHE_SHIFT 6
520 #else
521 /* Both EV4 and EV5 are write-through, read-allocate,
522 direct-mapped, physical.
523 */
524-# define L1_CACHE_BYTES 32
525 # define L1_CACHE_SHIFT 5
526 #endif
527
528+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
529 #define SMP_CACHE_BYTES L1_CACHE_BYTES
530
531 #endif
532diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
533index 968d999..d36b2df 100644
534--- a/arch/alpha/include/asm/elf.h
535+++ b/arch/alpha/include/asm/elf.h
536@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
537
538 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
539
540+#ifdef CONFIG_PAX_ASLR
541+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
542+
543+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
544+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
545+#endif
546+
547 /* $0 is set by ld.so to a pointer to a function which might be
548 registered using atexit. This provides a mean for the dynamic
549 linker to call DT_FINI functions for shared libraries that have
550diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
551index bc2a0da..8ad11ee 100644
552--- a/arch/alpha/include/asm/pgalloc.h
553+++ b/arch/alpha/include/asm/pgalloc.h
554@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
555 pgd_set(pgd, pmd);
556 }
557
558+static inline void
559+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
560+{
561+ pgd_populate(mm, pgd, pmd);
562+}
563+
564 extern pgd_t *pgd_alloc(struct mm_struct *mm);
565
566 static inline void
567diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
568index 81a4342..348b927 100644
569--- a/arch/alpha/include/asm/pgtable.h
570+++ b/arch/alpha/include/asm/pgtable.h
571@@ -102,6 +102,17 @@ struct vm_area_struct;
572 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
573 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
574 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
575+
576+#ifdef CONFIG_PAX_PAGEEXEC
577+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
578+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
579+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
580+#else
581+# define PAGE_SHARED_NOEXEC PAGE_SHARED
582+# define PAGE_COPY_NOEXEC PAGE_COPY
583+# define PAGE_READONLY_NOEXEC PAGE_READONLY
584+#endif
585+
586 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
587
588 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
589diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
590index 2fd00b7..cfd5069 100644
591--- a/arch/alpha/kernel/module.c
592+++ b/arch/alpha/kernel/module.c
593@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
594
595 /* The small sections were sorted to the end of the segment.
596 The following should definitely cover them. */
597- gp = (u64)me->module_core + me->core_size - 0x8000;
598+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
599 got = sechdrs[me->arch.gotsecindex].sh_addr;
600
601 for (i = 0; i < n; i++) {
602diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
603index b9e37ad..44c24e7 100644
604--- a/arch/alpha/kernel/osf_sys.c
605+++ b/arch/alpha/kernel/osf_sys.c
606@@ -1297,10 +1297,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
607 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
608
609 static unsigned long
610-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
611- unsigned long limit)
612+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
613+ unsigned long limit, unsigned long flags)
614 {
615 struct vm_unmapped_area_info info;
616+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
617
618 info.flags = 0;
619 info.length = len;
620@@ -1308,6 +1309,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
621 info.high_limit = limit;
622 info.align_mask = 0;
623 info.align_offset = 0;
624+ info.threadstack_offset = offset;
625 return vm_unmapped_area(&info);
626 }
627
628@@ -1340,20 +1342,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
629 merely specific addresses, but regions of memory -- perhaps
630 this feature should be incorporated into all ports? */
631
632+#ifdef CONFIG_PAX_RANDMMAP
633+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
634+#endif
635+
636 if (addr) {
637- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
638+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
639 if (addr != (unsigned long) -ENOMEM)
640 return addr;
641 }
642
643 /* Next, try allocating at TASK_UNMAPPED_BASE. */
644- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
645- len, limit);
646+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
647+
648 if (addr != (unsigned long) -ENOMEM)
649 return addr;
650
651 /* Finally, try allocating in low memory. */
652- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
653+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
654
655 return addr;
656 }
657diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
658index 0c4132d..88f0d53 100644
659--- a/arch/alpha/mm/fault.c
660+++ b/arch/alpha/mm/fault.c
661@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
662 __reload_thread(pcb);
663 }
664
665+#ifdef CONFIG_PAX_PAGEEXEC
666+/*
667+ * PaX: decide what to do with offenders (regs->pc = fault address)
668+ *
669+ * returns 1 when task should be killed
670+ * 2 when patched PLT trampoline was detected
671+ * 3 when unpatched PLT trampoline was detected
672+ */
673+static int pax_handle_fetch_fault(struct pt_regs *regs)
674+{
675+
676+#ifdef CONFIG_PAX_EMUPLT
677+ int err;
678+
679+ do { /* PaX: patched PLT emulation #1 */
680+ unsigned int ldah, ldq, jmp;
681+
682+ err = get_user(ldah, (unsigned int *)regs->pc);
683+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
684+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
685+
686+ if (err)
687+ break;
688+
689+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
690+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
691+ jmp == 0x6BFB0000U)
692+ {
693+ unsigned long r27, addr;
694+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
695+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
696+
697+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
698+ err = get_user(r27, (unsigned long *)addr);
699+ if (err)
700+ break;
701+
702+ regs->r27 = r27;
703+ regs->pc = r27;
704+ return 2;
705+ }
706+ } while (0);
707+
708+ do { /* PaX: patched PLT emulation #2 */
709+ unsigned int ldah, lda, br;
710+
711+ err = get_user(ldah, (unsigned int *)regs->pc);
712+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
713+ err |= get_user(br, (unsigned int *)(regs->pc+8));
714+
715+ if (err)
716+ break;
717+
718+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
719+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
720+ (br & 0xFFE00000U) == 0xC3E00000U)
721+ {
722+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
723+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
724+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
725+
726+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
727+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
728+ return 2;
729+ }
730+ } while (0);
731+
732+ do { /* PaX: unpatched PLT emulation */
733+ unsigned int br;
734+
735+ err = get_user(br, (unsigned int *)regs->pc);
736+
737+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
738+ unsigned int br2, ldq, nop, jmp;
739+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
740+
741+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
742+ err = get_user(br2, (unsigned int *)addr);
743+ err |= get_user(ldq, (unsigned int *)(addr+4));
744+ err |= get_user(nop, (unsigned int *)(addr+8));
745+ err |= get_user(jmp, (unsigned int *)(addr+12));
746+ err |= get_user(resolver, (unsigned long *)(addr+16));
747+
748+ if (err)
749+ break;
750+
751+ if (br2 == 0xC3600000U &&
752+ ldq == 0xA77B000CU &&
753+ nop == 0x47FF041FU &&
754+ jmp == 0x6B7B0000U)
755+ {
756+ regs->r28 = regs->pc+4;
757+ regs->r27 = addr+16;
758+ regs->pc = resolver;
759+ return 3;
760+ }
761+ }
762+ } while (0);
763+#endif
764+
765+ return 1;
766+}
767+
768+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
769+{
770+ unsigned long i;
771+
772+ printk(KERN_ERR "PAX: bytes at PC: ");
773+ for (i = 0; i < 5; i++) {
774+ unsigned int c;
775+ if (get_user(c, (unsigned int *)pc+i))
776+ printk(KERN_CONT "???????? ");
777+ else
778+ printk(KERN_CONT "%08x ", c);
779+ }
780+ printk("\n");
781+}
782+#endif
783
784 /*
785 * This routine handles page faults. It determines the address,
786@@ -133,8 +251,29 @@ retry:
787 good_area:
788 si_code = SEGV_ACCERR;
789 if (cause < 0) {
790- if (!(vma->vm_flags & VM_EXEC))
791+ if (!(vma->vm_flags & VM_EXEC)) {
792+
793+#ifdef CONFIG_PAX_PAGEEXEC
794+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
795+ goto bad_area;
796+
797+ up_read(&mm->mmap_sem);
798+ switch (pax_handle_fetch_fault(regs)) {
799+
800+#ifdef CONFIG_PAX_EMUPLT
801+ case 2:
802+ case 3:
803+ return;
804+#endif
805+
806+ }
807+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
808+ do_group_exit(SIGKILL);
809+#else
810 goto bad_area;
811+#endif
812+
813+ }
814 } else if (!cause) {
815 /* Allow reads even for write-only mappings */
816 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
817diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
818index 136f263..f471277 100644
819--- a/arch/arm/Kconfig
820+++ b/arch/arm/Kconfig
821@@ -1766,7 +1766,7 @@ config ALIGNMENT_TRAP
822
823 config UACCESS_WITH_MEMCPY
824 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
825- depends on MMU
826+ depends on MMU && !PAX_MEMORY_UDEREF
827 default y if CPU_FEROCEON
828 help
829 Implement faster copy_to_user and clear_user methods for CPU
830diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
831index da1c77d..2ee6056 100644
832--- a/arch/arm/include/asm/atomic.h
833+++ b/arch/arm/include/asm/atomic.h
834@@ -17,17 +17,35 @@
835 #include <asm/barrier.h>
836 #include <asm/cmpxchg.h>
837
838+#ifdef CONFIG_GENERIC_ATOMIC64
839+#include <asm-generic/atomic64.h>
840+#endif
841+
842 #define ATOMIC_INIT(i) { (i) }
843
844 #ifdef __KERNEL__
845
846+#define _ASM_EXTABLE(from, to) \
847+" .pushsection __ex_table,\"a\"\n"\
848+" .align 3\n" \
849+" .long " #from ", " #to"\n" \
850+" .popsection"
851+
852 /*
853 * On ARM, ordinary assignment (str instruction) doesn't clear the local
854 * strex/ldrex monitor on some implementations. The reason we can use it for
855 * atomic_set() is the clrex or dummy strex done on every exception return.
856 */
857 #define atomic_read(v) (*(volatile int *)&(v)->counter)
858+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
859+{
860+ return v->counter;
861+}
862 #define atomic_set(v,i) (((v)->counter) = (i))
863+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
864+{
865+ v->counter = i;
866+}
867
868 #if __LINUX_ARM_ARCH__ >= 6
869
870@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
871 int result;
872
873 __asm__ __volatile__("@ atomic_add\n"
874+"1: ldrex %1, [%3]\n"
875+" adds %0, %1, %4\n"
876+
877+#ifdef CONFIG_PAX_REFCOUNT
878+" bvc 3f\n"
879+"2: bkpt 0xf103\n"
880+"3:\n"
881+#endif
882+
883+" strex %1, %0, [%3]\n"
884+" teq %1, #0\n"
885+" bne 1b"
886+
887+#ifdef CONFIG_PAX_REFCOUNT
888+"\n4:\n"
889+ _ASM_EXTABLE(2b, 4b)
890+#endif
891+
892+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
893+ : "r" (&v->counter), "Ir" (i)
894+ : "cc");
895+}
896+
897+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
898+{
899+ unsigned long tmp;
900+ int result;
901+
902+ __asm__ __volatile__("@ atomic_add_unchecked\n"
903 "1: ldrex %0, [%3]\n"
904 " add %0, %0, %4\n"
905 " strex %1, %0, [%3]\n"
906@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
907 smp_mb();
908
909 __asm__ __volatile__("@ atomic_add_return\n"
910+"1: ldrex %1, [%3]\n"
911+" adds %0, %1, %4\n"
912+
913+#ifdef CONFIG_PAX_REFCOUNT
914+" bvc 3f\n"
915+" mov %0, %1\n"
916+"2: bkpt 0xf103\n"
917+"3:\n"
918+#endif
919+
920+" strex %1, %0, [%3]\n"
921+" teq %1, #0\n"
922+" bne 1b"
923+
924+#ifdef CONFIG_PAX_REFCOUNT
925+"\n4:\n"
926+ _ASM_EXTABLE(2b, 4b)
927+#endif
928+
929+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
930+ : "r" (&v->counter), "Ir" (i)
931+ : "cc");
932+
933+ smp_mb();
934+
935+ return result;
936+}
937+
938+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
939+{
940+ unsigned long tmp;
941+ int result;
942+
943+ smp_mb();
944+
945+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
946 "1: ldrex %0, [%3]\n"
947 " add %0, %0, %4\n"
948 " strex %1, %0, [%3]\n"
949@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
950 int result;
951
952 __asm__ __volatile__("@ atomic_sub\n"
953+"1: ldrex %1, [%3]\n"
954+" subs %0, %1, %4\n"
955+
956+#ifdef CONFIG_PAX_REFCOUNT
957+" bvc 3f\n"
958+"2: bkpt 0xf103\n"
959+"3:\n"
960+#endif
961+
962+" strex %1, %0, [%3]\n"
963+" teq %1, #0\n"
964+" bne 1b"
965+
966+#ifdef CONFIG_PAX_REFCOUNT
967+"\n4:\n"
968+ _ASM_EXTABLE(2b, 4b)
969+#endif
970+
971+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
972+ : "r" (&v->counter), "Ir" (i)
973+ : "cc");
974+}
975+
976+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
977+{
978+ unsigned long tmp;
979+ int result;
980+
981+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
982 "1: ldrex %0, [%3]\n"
983 " sub %0, %0, %4\n"
984 " strex %1, %0, [%3]\n"
985@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
986 smp_mb();
987
988 __asm__ __volatile__("@ atomic_sub_return\n"
989-"1: ldrex %0, [%3]\n"
990-" sub %0, %0, %4\n"
991+"1: ldrex %1, [%3]\n"
992+" subs %0, %1, %4\n"
993+
994+#ifdef CONFIG_PAX_REFCOUNT
995+" bvc 3f\n"
996+" mov %0, %1\n"
997+"2: bkpt 0xf103\n"
998+"3:\n"
999+#endif
1000+
1001 " strex %1, %0, [%3]\n"
1002 " teq %1, #0\n"
1003 " bne 1b"
1004+
1005+#ifdef CONFIG_PAX_REFCOUNT
1006+"\n4:\n"
1007+ _ASM_EXTABLE(2b, 4b)
1008+#endif
1009+
1010 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1011 : "r" (&v->counter), "Ir" (i)
1012 : "cc");
1013@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1014 return oldval;
1015 }
1016
1017+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1018+{
1019+ unsigned long oldval, res;
1020+
1021+ smp_mb();
1022+
1023+ do {
1024+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1025+ "ldrex %1, [%3]\n"
1026+ "mov %0, #0\n"
1027+ "teq %1, %4\n"
1028+ "strexeq %0, %5, [%3]\n"
1029+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1030+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1031+ : "cc");
1032+ } while (res);
1033+
1034+ smp_mb();
1035+
1036+ return oldval;
1037+}
1038+
1039 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1040 {
1041 unsigned long tmp, tmp2;
1042@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1043
1044 return val;
1045 }
1046+
1047+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1048+{
1049+ return atomic_add_return(i, v);
1050+}
1051+
1052 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1053+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1054+{
1055+ (void) atomic_add_return(i, v);
1056+}
1057
1058 static inline int atomic_sub_return(int i, atomic_t *v)
1059 {
1060@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1061 return val;
1062 }
1063 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1064+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1065+{
1066+ (void) atomic_sub_return(i, v);
1067+}
1068
1069 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1070 {
1071@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1072 return ret;
1073 }
1074
1075+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1076+{
1077+ return atomic_cmpxchg(v, old, new);
1078+}
1079+
1080 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1081 {
1082 unsigned long flags;
1083@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1084 #endif /* __LINUX_ARM_ARCH__ */
1085
1086 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1087+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1088+{
1089+ return xchg(&v->counter, new);
1090+}
1091
1092 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1093 {
1094@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1095 }
1096
1097 #define atomic_inc(v) atomic_add(1, v)
1098+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1099+{
1100+ atomic_add_unchecked(1, v);
1101+}
1102 #define atomic_dec(v) atomic_sub(1, v)
1103+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1104+{
1105+ atomic_sub_unchecked(1, v);
1106+}
1107
1108 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1109+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1110+{
1111+ return atomic_add_return_unchecked(1, v) == 0;
1112+}
1113 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1114 #define atomic_inc_return(v) (atomic_add_return(1, v))
1115+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1116+{
1117+ return atomic_add_return_unchecked(1, v);
1118+}
1119 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1120 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1121
1122@@ -241,6 +428,14 @@ typedef struct {
1123 u64 __aligned(8) counter;
1124 } atomic64_t;
1125
1126+#ifdef CONFIG_PAX_REFCOUNT
1127+typedef struct {
1128+ u64 __aligned(8) counter;
1129+} atomic64_unchecked_t;
1130+#else
1131+typedef atomic64_t atomic64_unchecked_t;
1132+#endif
1133+
1134 #define ATOMIC64_INIT(i) { (i) }
1135
1136 #ifdef CONFIG_ARM_LPAE
1137@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1138 return result;
1139 }
1140
1141+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1142+{
1143+ u64 result;
1144+
1145+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1146+" ldrd %0, %H0, [%1]"
1147+ : "=&r" (result)
1148+ : "r" (&v->counter), "Qo" (v->counter)
1149+ );
1150+
1151+ return result;
1152+}
1153+
1154 static inline void atomic64_set(atomic64_t *v, u64 i)
1155 {
1156 __asm__ __volatile__("@ atomic64_set\n"
1157@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1158 : "r" (&v->counter), "r" (i)
1159 );
1160 }
1161+
1162+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1163+{
1164+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1165+" strd %2, %H2, [%1]"
1166+ : "=Qo" (v->counter)
1167+ : "r" (&v->counter), "r" (i)
1168+ );
1169+}
1170 #else
1171 static inline u64 atomic64_read(const atomic64_t *v)
1172 {
1173@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1174 return result;
1175 }
1176
1177+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1178+{
1179+ u64 result;
1180+
1181+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1182+" ldrexd %0, %H0, [%1]"
1183+ : "=&r" (result)
1184+ : "r" (&v->counter), "Qo" (v->counter)
1185+ );
1186+
1187+ return result;
1188+}
1189+
1190 static inline void atomic64_set(atomic64_t *v, u64 i)
1191 {
1192 u64 tmp;
1193@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1194 : "r" (&v->counter), "r" (i)
1195 : "cc");
1196 }
1197+
1198+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1199+{
1200+ u64 tmp;
1201+
1202+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1203+"1: ldrexd %0, %H0, [%2]\n"
1204+" strexd %0, %3, %H3, [%2]\n"
1205+" teq %0, #0\n"
1206+" bne 1b"
1207+ : "=&r" (tmp), "=Qo" (v->counter)
1208+ : "r" (&v->counter), "r" (i)
1209+ : "cc");
1210+}
1211+
1212 #endif
1213
1214 static inline void atomic64_add(u64 i, atomic64_t *v)
1215@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1216 __asm__ __volatile__("@ atomic64_add\n"
1217 "1: ldrexd %0, %H0, [%3]\n"
1218 " adds %0, %0, %4\n"
1219+" adcs %H0, %H0, %H4\n"
1220+
1221+#ifdef CONFIG_PAX_REFCOUNT
1222+" bvc 3f\n"
1223+"2: bkpt 0xf103\n"
1224+"3:\n"
1225+#endif
1226+
1227+" strexd %1, %0, %H0, [%3]\n"
1228+" teq %1, #0\n"
1229+" bne 1b"
1230+
1231+#ifdef CONFIG_PAX_REFCOUNT
1232+"\n4:\n"
1233+ _ASM_EXTABLE(2b, 4b)
1234+#endif
1235+
1236+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1237+ : "r" (&v->counter), "r" (i)
1238+ : "cc");
1239+}
1240+
1241+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1242+{
1243+ u64 result;
1244+ unsigned long tmp;
1245+
1246+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1247+"1: ldrexd %0, %H0, [%3]\n"
1248+" adds %0, %0, %4\n"
1249 " adc %H0, %H0, %H4\n"
1250 " strexd %1, %0, %H0, [%3]\n"
1251 " teq %1, #0\n"
1252@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1253
1254 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1255 {
1256- u64 result;
1257- unsigned long tmp;
1258+ u64 result, tmp;
1259
1260 smp_mb();
1261
1262 __asm__ __volatile__("@ atomic64_add_return\n"
1263+"1: ldrexd %1, %H1, [%3]\n"
1264+" adds %0, %1, %4\n"
1265+" adcs %H0, %H1, %H4\n"
1266+
1267+#ifdef CONFIG_PAX_REFCOUNT
1268+" bvc 3f\n"
1269+" mov %0, %1\n"
1270+" mov %H0, %H1\n"
1271+"2: bkpt 0xf103\n"
1272+"3:\n"
1273+#endif
1274+
1275+" strexd %1, %0, %H0, [%3]\n"
1276+" teq %1, #0\n"
1277+" bne 1b"
1278+
1279+#ifdef CONFIG_PAX_REFCOUNT
1280+"\n4:\n"
1281+ _ASM_EXTABLE(2b, 4b)
1282+#endif
1283+
1284+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1285+ : "r" (&v->counter), "r" (i)
1286+ : "cc");
1287+
1288+ smp_mb();
1289+
1290+ return result;
1291+}
1292+
1293+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1294+{
1295+ u64 result;
1296+ unsigned long tmp;
1297+
1298+ smp_mb();
1299+
1300+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1301 "1: ldrexd %0, %H0, [%3]\n"
1302 " adds %0, %0, %4\n"
1303 " adc %H0, %H0, %H4\n"
1304@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1305 __asm__ __volatile__("@ atomic64_sub\n"
1306 "1: ldrexd %0, %H0, [%3]\n"
1307 " subs %0, %0, %4\n"
1308+" sbcs %H0, %H0, %H4\n"
1309+
1310+#ifdef CONFIG_PAX_REFCOUNT
1311+" bvc 3f\n"
1312+"2: bkpt 0xf103\n"
1313+"3:\n"
1314+#endif
1315+
1316+" strexd %1, %0, %H0, [%3]\n"
1317+" teq %1, #0\n"
1318+" bne 1b"
1319+
1320+#ifdef CONFIG_PAX_REFCOUNT
1321+"\n4:\n"
1322+ _ASM_EXTABLE(2b, 4b)
1323+#endif
1324+
1325+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1326+ : "r" (&v->counter), "r" (i)
1327+ : "cc");
1328+}
1329+
1330+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1331+{
1332+ u64 result;
1333+ unsigned long tmp;
1334+
1335+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1336+"1: ldrexd %0, %H0, [%3]\n"
1337+" subs %0, %0, %4\n"
1338 " sbc %H0, %H0, %H4\n"
1339 " strexd %1, %0, %H0, [%3]\n"
1340 " teq %1, #0\n"
1341@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1342
1343 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1344 {
1345- u64 result;
1346- unsigned long tmp;
1347+ u64 result, tmp;
1348
1349 smp_mb();
1350
1351 __asm__ __volatile__("@ atomic64_sub_return\n"
1352-"1: ldrexd %0, %H0, [%3]\n"
1353-" subs %0, %0, %4\n"
1354-" sbc %H0, %H0, %H4\n"
1355+"1: ldrexd %1, %H1, [%3]\n"
1356+" subs %0, %1, %4\n"
1357+" sbcs %H0, %H1, %H4\n"
1358+
1359+#ifdef CONFIG_PAX_REFCOUNT
1360+" bvc 3f\n"
1361+" mov %0, %1\n"
1362+" mov %H0, %H1\n"
1363+"2: bkpt 0xf103\n"
1364+"3:\n"
1365+#endif
1366+
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 " bne 1b"
1370+
1371+#ifdef CONFIG_PAX_REFCOUNT
1372+"\n4:\n"
1373+ _ASM_EXTABLE(2b, 4b)
1374+#endif
1375+
1376 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1377 : "r" (&v->counter), "r" (i)
1378 : "cc");
1379@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1380 return oldval;
1381 }
1382
1383+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1384+{
1385+ u64 oldval;
1386+ unsigned long res;
1387+
1388+ smp_mb();
1389+
1390+ do {
1391+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1392+ "ldrexd %1, %H1, [%3]\n"
1393+ "mov %0, #0\n"
1394+ "teq %1, %4\n"
1395+ "teqeq %H1, %H4\n"
1396+ "strexdeq %0, %5, %H5, [%3]"
1397+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1398+ : "r" (&ptr->counter), "r" (old), "r" (new)
1399+ : "cc");
1400+ } while (res);
1401+
1402+ smp_mb();
1403+
1404+ return oldval;
1405+}
1406+
1407 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1408 {
1409 u64 result;
1410@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1411
1412 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1413 {
1414- u64 result;
1415- unsigned long tmp;
1416+ u64 result, tmp;
1417
1418 smp_mb();
1419
1420 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1421-"1: ldrexd %0, %H0, [%3]\n"
1422-" subs %0, %0, #1\n"
1423-" sbc %H0, %H0, #0\n"
1424+"1: ldrexd %1, %H1, [%3]\n"
1425+" subs %0, %1, #1\n"
1426+" sbcs %H0, %H1, #0\n"
1427+
1428+#ifdef CONFIG_PAX_REFCOUNT
1429+" bvc 3f\n"
1430+" mov %0, %1\n"
1431+" mov %H0, %H1\n"
1432+"2: bkpt 0xf103\n"
1433+"3:\n"
1434+#endif
1435+
1436 " teq %H0, #0\n"
1437-" bmi 2f\n"
1438+" bmi 4f\n"
1439 " strexd %1, %0, %H0, [%3]\n"
1440 " teq %1, #0\n"
1441 " bne 1b\n"
1442-"2:"
1443+"4:\n"
1444+
1445+#ifdef CONFIG_PAX_REFCOUNT
1446+ _ASM_EXTABLE(2b, 4b)
1447+#endif
1448+
1449 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1450 : "r" (&v->counter)
1451 : "cc");
1452@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1453 " teq %0, %5\n"
1454 " teqeq %H0, %H5\n"
1455 " moveq %1, #0\n"
1456-" beq 2f\n"
1457+" beq 4f\n"
1458 " adds %0, %0, %6\n"
1459-" adc %H0, %H0, %H6\n"
1460+" adcs %H0, %H0, %H6\n"
1461+
1462+#ifdef CONFIG_PAX_REFCOUNT
1463+" bvc 3f\n"
1464+"2: bkpt 0xf103\n"
1465+"3:\n"
1466+#endif
1467+
1468 " strexd %2, %0, %H0, [%4]\n"
1469 " teq %2, #0\n"
1470 " bne 1b\n"
1471-"2:"
1472+"4:\n"
1473+
1474+#ifdef CONFIG_PAX_REFCOUNT
1475+ _ASM_EXTABLE(2b, 4b)
1476+#endif
1477+
1478 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1479 : "r" (&v->counter), "r" (u), "r" (a)
1480 : "cc");
1481@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1482
1483 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1484 #define atomic64_inc(v) atomic64_add(1LL, (v))
1485+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1486 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1487+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1488 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1489 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1490 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1491+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1492 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1493 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1494 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1495diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1496index 75fe66b..ba3dee4 100644
1497--- a/arch/arm/include/asm/cache.h
1498+++ b/arch/arm/include/asm/cache.h
1499@@ -4,8 +4,10 @@
1500 #ifndef __ASMARM_CACHE_H
1501 #define __ASMARM_CACHE_H
1502
1503+#include <linux/const.h>
1504+
1505 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1506-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1507+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1508
1509 /*
1510 * Memory returned by kmalloc() may be used for DMA, so we must make
1511@@ -24,5 +26,6 @@
1512 #endif
1513
1514 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1515+#define __read_only __attribute__ ((__section__(".data..read_only")))
1516
1517 #endif
1518diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1519index 17d0ae8..014e350 100644
1520--- a/arch/arm/include/asm/cacheflush.h
1521+++ b/arch/arm/include/asm/cacheflush.h
1522@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1523 void (*dma_unmap_area)(const void *, size_t, int);
1524
1525 void (*dma_flush_range)(const void *, const void *);
1526-};
1527+} __no_const;
1528
1529 /*
1530 * Select the calling method
1531diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1532index 6dcc164..b14d917 100644
1533--- a/arch/arm/include/asm/checksum.h
1534+++ b/arch/arm/include/asm/checksum.h
1535@@ -37,7 +37,19 @@ __wsum
1536 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1537
1538 __wsum
1539-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1540+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1541+
1542+static inline __wsum
1543+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1544+{
1545+ __wsum ret;
1546+ pax_open_userland();
1547+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1548+ pax_close_userland();
1549+ return ret;
1550+}
1551+
1552+
1553
1554 /*
1555 * Fold a partial checksum without adding pseudo headers
1556diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1557index 4f009c1..466c59b 100644
1558--- a/arch/arm/include/asm/cmpxchg.h
1559+++ b/arch/arm/include/asm/cmpxchg.h
1560@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1561
1562 #define xchg(ptr,x) \
1563 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1564+#define xchg_unchecked(ptr,x) \
1565+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1566
1567 #include <asm-generic/cmpxchg-local.h>
1568
1569diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1570index 6ddbe44..b5e38b1 100644
1571--- a/arch/arm/include/asm/domain.h
1572+++ b/arch/arm/include/asm/domain.h
1573@@ -48,18 +48,37 @@
1574 * Domain types
1575 */
1576 #define DOMAIN_NOACCESS 0
1577-#define DOMAIN_CLIENT 1
1578 #ifdef CONFIG_CPU_USE_DOMAINS
1579+#define DOMAIN_USERCLIENT 1
1580+#define DOMAIN_KERNELCLIENT 1
1581 #define DOMAIN_MANAGER 3
1582+#define DOMAIN_VECTORS DOMAIN_USER
1583 #else
1584+
1585+#ifdef CONFIG_PAX_KERNEXEC
1586 #define DOMAIN_MANAGER 1
1587+#define DOMAIN_KERNEXEC 3
1588+#else
1589+#define DOMAIN_MANAGER 1
1590+#endif
1591+
1592+#ifdef CONFIG_PAX_MEMORY_UDEREF
1593+#define DOMAIN_USERCLIENT 0
1594+#define DOMAIN_UDEREF 1
1595+#define DOMAIN_VECTORS DOMAIN_KERNEL
1596+#else
1597+#define DOMAIN_USERCLIENT 1
1598+#define DOMAIN_VECTORS DOMAIN_USER
1599+#endif
1600+#define DOMAIN_KERNELCLIENT 1
1601+
1602 #endif
1603
1604 #define domain_val(dom,type) ((type) << (2*(dom)))
1605
1606 #ifndef __ASSEMBLY__
1607
1608-#ifdef CONFIG_CPU_USE_DOMAINS
1609+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1610 static inline void set_domain(unsigned val)
1611 {
1612 asm volatile(
1613@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1614 isb();
1615 }
1616
1617-#define modify_domain(dom,type) \
1618- do { \
1619- struct thread_info *thread = current_thread_info(); \
1620- unsigned int domain = thread->cpu_domain; \
1621- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1622- thread->cpu_domain = domain | domain_val(dom, type); \
1623- set_domain(thread->cpu_domain); \
1624- } while (0)
1625-
1626+extern void modify_domain(unsigned int dom, unsigned int type);
1627 #else
1628 static inline void set_domain(unsigned val) { }
1629 static inline void modify_domain(unsigned dom, unsigned type) { }
1630diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1631index 38050b1..9d90e8b 100644
1632--- a/arch/arm/include/asm/elf.h
1633+++ b/arch/arm/include/asm/elf.h
1634@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1635 the loader. We need to make sure that it is out of the way of the program
1636 that it will "exec", and that there is sufficient room for the brk. */
1637
1638-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1639+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1640+
1641+#ifdef CONFIG_PAX_ASLR
1642+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1643+
1644+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1645+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1646+#endif
1647
1648 /* When the program starts, a1 contains a pointer to a function to be
1649 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1650@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1651 extern void elf_set_personality(const struct elf32_hdr *);
1652 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1653
1654-struct mm_struct;
1655-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1656-#define arch_randomize_brk arch_randomize_brk
1657-
1658 #endif
1659diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1660index de53547..52b9a28 100644
1661--- a/arch/arm/include/asm/fncpy.h
1662+++ b/arch/arm/include/asm/fncpy.h
1663@@ -81,7 +81,9 @@
1664 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1665 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1666 \
1667+ pax_open_kernel(); \
1668 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1669+ pax_close_kernel(); \
1670 flush_icache_range((unsigned long)(dest_buf), \
1671 (unsigned long)(dest_buf) + (size)); \
1672 \
1673diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1674index e42cf59..7b94b8f 100644
1675--- a/arch/arm/include/asm/futex.h
1676+++ b/arch/arm/include/asm/futex.h
1677@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1679 return -EFAULT;
1680
1681+ pax_open_userland();
1682+
1683 smp_mb();
1684 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1685 "1: ldrex %1, [%4]\n"
1686@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1687 : "cc", "memory");
1688 smp_mb();
1689
1690+ pax_close_userland();
1691+
1692 *uval = val;
1693 return ret;
1694 }
1695@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1696 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1697 return -EFAULT;
1698
1699+ pax_open_userland();
1700+
1701 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1702 "1: " TUSER(ldr) " %1, [%4]\n"
1703 " teq %1, %2\n"
1704@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1705 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1706 : "cc", "memory");
1707
1708+ pax_close_userland();
1709+
1710 *uval = val;
1711 return ret;
1712 }
1713@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1714 return -EFAULT;
1715
1716 pagefault_disable(); /* implies preempt_disable() */
1717+ pax_open_userland();
1718
1719 switch (op) {
1720 case FUTEX_OP_SET:
1721@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1722 ret = -ENOSYS;
1723 }
1724
1725+ pax_close_userland();
1726 pagefault_enable(); /* subsumes preempt_enable() */
1727
1728 if (!ret) {
1729diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1730index 83eb2f7..ed77159 100644
1731--- a/arch/arm/include/asm/kmap_types.h
1732+++ b/arch/arm/include/asm/kmap_types.h
1733@@ -4,6 +4,6 @@
1734 /*
1735 * This is the "bare minimum". AIO seems to require this.
1736 */
1737-#define KM_TYPE_NR 16
1738+#define KM_TYPE_NR 17
1739
1740 #endif
1741diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1742index 9e614a1..3302cca 100644
1743--- a/arch/arm/include/asm/mach/dma.h
1744+++ b/arch/arm/include/asm/mach/dma.h
1745@@ -22,7 +22,7 @@ struct dma_ops {
1746 int (*residue)(unsigned int, dma_t *); /* optional */
1747 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1748 const char *type;
1749-};
1750+} __do_const;
1751
1752 struct dma_struct {
1753 void *addr; /* single DMA address */
1754diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1755index 2fe141f..192dc01 100644
1756--- a/arch/arm/include/asm/mach/map.h
1757+++ b/arch/arm/include/asm/mach/map.h
1758@@ -27,13 +27,16 @@ struct map_desc {
1759 #define MT_MINICLEAN 6
1760 #define MT_LOW_VECTORS 7
1761 #define MT_HIGH_VECTORS 8
1762-#define MT_MEMORY 9
1763+#define MT_MEMORY_RWX 9
1764 #define MT_ROM 10
1765-#define MT_MEMORY_NONCACHED 11
1766+#define MT_MEMORY_NONCACHED_RX 11
1767 #define MT_MEMORY_DTCM 12
1768 #define MT_MEMORY_ITCM 13
1769 #define MT_MEMORY_SO 14
1770 #define MT_MEMORY_DMA_READY 15
1771+#define MT_MEMORY_RW 16
1772+#define MT_MEMORY_RX 17
1773+#define MT_MEMORY_NONCACHED_RW 18
1774
1775 #ifdef CONFIG_MMU
1776 extern void iotable_init(struct map_desc *, int);
1777diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1778index 12f71a1..04e063c 100644
1779--- a/arch/arm/include/asm/outercache.h
1780+++ b/arch/arm/include/asm/outercache.h
1781@@ -35,7 +35,7 @@ struct outer_cache_fns {
1782 #endif
1783 void (*set_debug)(unsigned long);
1784 void (*resume)(void);
1785-};
1786+} __no_const;
1787
1788 #ifdef CONFIG_OUTER_CACHE
1789
1790diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1791index 812a494..71fc0b6 100644
1792--- a/arch/arm/include/asm/page.h
1793+++ b/arch/arm/include/asm/page.h
1794@@ -114,7 +114,7 @@ struct cpu_user_fns {
1795 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1796 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1797 unsigned long vaddr, struct vm_area_struct *vma);
1798-};
1799+} __no_const;
1800
1801 #ifdef MULTI_USER
1802 extern struct cpu_user_fns cpu_user;
1803diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1804index 943504f..c37a730 100644
1805--- a/arch/arm/include/asm/pgalloc.h
1806+++ b/arch/arm/include/asm/pgalloc.h
1807@@ -17,6 +17,7 @@
1808 #include <asm/processor.h>
1809 #include <asm/cacheflush.h>
1810 #include <asm/tlbflush.h>
1811+#include <asm/system_info.h>
1812
1813 #define check_pgt_cache() do { } while (0)
1814
1815@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1816 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1817 }
1818
1819+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1820+{
1821+ pud_populate(mm, pud, pmd);
1822+}
1823+
1824 #else /* !CONFIG_ARM_LPAE */
1825
1826 /*
1827@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1828 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1829 #define pmd_free(mm, pmd) do { } while (0)
1830 #define pud_populate(mm,pmd,pte) BUG()
1831+#define pud_populate_kernel(mm,pmd,pte) BUG()
1832
1833 #endif /* CONFIG_ARM_LPAE */
1834
1835@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1836 __free_page(pte);
1837 }
1838
1839+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1840+{
1841+#ifdef CONFIG_ARM_LPAE
1842+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1843+#else
1844+ if (addr & SECTION_SIZE)
1845+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1846+ else
1847+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1848+#endif
1849+ flush_pmd_entry(pmdp);
1850+}
1851+
1852 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1853 pmdval_t prot)
1854 {
1855@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1856 static inline void
1857 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1858 {
1859- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1860+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1861 }
1862 #define pmd_pgtable(pmd) pmd_page(pmd)
1863
1864diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1865index 5cfba15..f415e1a 100644
1866--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1867+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1868@@ -20,12 +20,15 @@
1869 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1870 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1871 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1872+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1873 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1874 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1875 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1876+
1877 /*
1878 * - section
1879 */
1880+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1881 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1882 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1883 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1884@@ -37,6 +40,7 @@
1885 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1886 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1887 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1888+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1889
1890 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1891 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1892@@ -66,6 +70,7 @@
1893 * - extended small page/tiny page
1894 */
1895 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1896+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1897 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1898 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1899 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1900diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1901index f97ee02..07f1be5 100644
1902--- a/arch/arm/include/asm/pgtable-2level.h
1903+++ b/arch/arm/include/asm/pgtable-2level.h
1904@@ -125,6 +125,7 @@
1905 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1906 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1907 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1908+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1909
1910 /*
1911 * These are the memory types, defined to be compatible with
1912diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1913index 18f5cef..25b8f43 100644
1914--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1915+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1916@@ -41,6 +41,7 @@
1917 */
1918 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1919 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1920+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1921 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1922 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1923 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1924@@ -71,6 +72,7 @@
1925 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1926 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1927 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1928+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1929 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1930
1931 /*
1932diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1933index 86b8fe3..e25f975 100644
1934--- a/arch/arm/include/asm/pgtable-3level.h
1935+++ b/arch/arm/include/asm/pgtable-3level.h
1936@@ -74,6 +74,7 @@
1937 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1938 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1939 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1940+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1941 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1942 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1943 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1944@@ -82,6 +83,7 @@
1945 /*
1946 * To be used in assembly code with the upper page attributes.
1947 */
1948+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1949 #define L_PTE_XN_HIGH (1 << (54 - 32))
1950 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1951
1952diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1953index 9bcd262..fba731c 100644
1954--- a/arch/arm/include/asm/pgtable.h
1955+++ b/arch/arm/include/asm/pgtable.h
1956@@ -30,6 +30,9 @@
1957 #include <asm/pgtable-2level.h>
1958 #endif
1959
1960+#define ktla_ktva(addr) (addr)
1961+#define ktva_ktla(addr) (addr)
1962+
1963 /*
1964 * Just any arbitrary offset to the start of the vmalloc VM area: the
1965 * current 8MB value just means that there will be a 8MB "hole" after the
1966@@ -45,6 +48,9 @@
1967 #define LIBRARY_TEXT_START 0x0c000000
1968
1969 #ifndef __ASSEMBLY__
1970+extern pteval_t __supported_pte_mask;
1971+extern pmdval_t __supported_pmd_mask;
1972+
1973 extern void __pte_error(const char *file, int line, pte_t);
1974 extern void __pmd_error(const char *file, int line, pmd_t);
1975 extern void __pgd_error(const char *file, int line, pgd_t);
1976@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1977 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1978 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1979
1980+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1981+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1982+
1983+#ifdef CONFIG_PAX_KERNEXEC
1984+#include <asm/domain.h>
1985+#include <linux/thread_info.h>
1986+#include <linux/preempt.h>
1987+#endif
1988+
1989+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1990+static inline int test_domain(int domain, int domaintype)
1991+{
1992+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1993+}
1994+#endif
1995+
1996+#ifdef CONFIG_PAX_KERNEXEC
1997+static inline unsigned long pax_open_kernel(void) {
1998+#ifdef CONFIG_ARM_LPAE
1999+ /* TODO */
2000+#else
2001+ preempt_disable();
2002+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2003+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2004+#endif
2005+ return 0;
2006+}
2007+
2008+static inline unsigned long pax_close_kernel(void) {
2009+#ifdef CONFIG_ARM_LPAE
2010+ /* TODO */
2011+#else
2012+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2013+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2014+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2015+ preempt_enable_no_resched();
2016+#endif
2017+ return 0;
2018+}
2019+#else
2020+static inline unsigned long pax_open_kernel(void) { return 0; }
2021+static inline unsigned long pax_close_kernel(void) { return 0; }
2022+#endif
2023+
2024 /*
2025 * This is the lowest virtual address we can permit any user space
2026 * mapping to be mapped at. This is particularly important for
2027@@ -72,8 +122,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2028 /*
2029 * The pgprot_* and protection_map entries will be fixed up in runtime
2030 * to include the cachable and bufferable bits based on memory policy,
2031- * as well as any architecture dependent bits like global/ASID and SMP
2032- * shared mapping bits.
2033+ * as well as any architecture dependent bits like global/ASID, PXN,
2034+ * and SMP shared mapping bits.
2035 */
2036 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2037
2038@@ -257,7 +307,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2039 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2040 {
2041 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2042- L_PTE_NONE | L_PTE_VALID;
2043+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2044 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2045 return pte;
2046 }
2047diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2048index f3628fb..a0672dd 100644
2049--- a/arch/arm/include/asm/proc-fns.h
2050+++ b/arch/arm/include/asm/proc-fns.h
2051@@ -75,7 +75,7 @@ extern struct processor {
2052 unsigned int suspend_size;
2053 void (*do_suspend)(void *);
2054 void (*do_resume)(void *);
2055-} processor;
2056+} __do_const processor;
2057
2058 #ifndef MULTI_CPU
2059 extern void cpu_proc_init(void);
2060diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2061index 06e7d50..8a8e251 100644
2062--- a/arch/arm/include/asm/processor.h
2063+++ b/arch/arm/include/asm/processor.h
2064@@ -65,9 +65,8 @@ struct thread_struct {
2065 regs->ARM_cpsr |= PSR_ENDSTATE; \
2066 regs->ARM_pc = pc & ~1; /* pc */ \
2067 regs->ARM_sp = sp; /* sp */ \
2068- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2069- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2070- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2071+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2072+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2073 nommu_start_thread(regs); \
2074 })
2075
2076diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2077index ce0dbe7..c085b6f 100644
2078--- a/arch/arm/include/asm/psci.h
2079+++ b/arch/arm/include/asm/psci.h
2080@@ -29,7 +29,7 @@ struct psci_operations {
2081 int (*cpu_off)(struct psci_power_state state);
2082 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2083 int (*migrate)(unsigned long cpuid);
2084-};
2085+} __no_const;
2086
2087 extern struct psci_operations psci_ops;
2088
2089diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2090index d3a22be..3a69ad5 100644
2091--- a/arch/arm/include/asm/smp.h
2092+++ b/arch/arm/include/asm/smp.h
2093@@ -107,7 +107,7 @@ struct smp_operations {
2094 int (*cpu_disable)(unsigned int cpu);
2095 #endif
2096 #endif
2097-};
2098+} __no_const;
2099
2100 /*
2101 * set platform specific SMP operations
2102diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2103index 1995d1a..76693a2 100644
2104--- a/arch/arm/include/asm/thread_info.h
2105+++ b/arch/arm/include/asm/thread_info.h
2106@@ -77,9 +77,9 @@ struct thread_info {
2107 .flags = 0, \
2108 .preempt_count = INIT_PREEMPT_COUNT, \
2109 .addr_limit = KERNEL_DS, \
2110- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2111- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2112- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2113+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2114+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2115+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2116 .restart_block = { \
2117 .fn = do_no_restart_syscall, \
2118 }, \
2119@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2120 #define TIF_SYSCALL_AUDIT 9
2121 #define TIF_SYSCALL_TRACEPOINT 10
2122 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2123-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2124+/* within 8 bits of TIF_SYSCALL_TRACE
2125+ * to meet flexible second operand requirements
2126+ */
2127+#define TIF_GRSEC_SETXID 12
2128+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2129 #define TIF_USING_IWMMXT 17
2130 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2131 #define TIF_RESTORE_SIGMASK 20
2132@@ -166,10 +170,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2133 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2134 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2135 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2136+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2137
2138 /* Checks for any syscall work in entry-common.S */
2139 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2140- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2141+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2142
2143 /*
2144 * Change these and you break ASM code in entry-common.S
2145diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2146index 7e1f760..d42d7f8 100644
2147--- a/arch/arm/include/asm/uaccess.h
2148+++ b/arch/arm/include/asm/uaccess.h
2149@@ -18,6 +18,7 @@
2150 #include <asm/domain.h>
2151 #include <asm/unified.h>
2152 #include <asm/compiler.h>
2153+#include <asm/pgtable.h>
2154
2155 #define VERIFY_READ 0
2156 #define VERIFY_WRITE 1
2157@@ -63,11 +64,35 @@ extern int __put_user_bad(void);
2158 static inline void set_fs(mm_segment_t fs)
2159 {
2160 current_thread_info()->addr_limit = fs;
2161- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2162+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2163 }
2164
2165 #define segment_eq(a,b) ((a) == (b))
2166
2167+static inline void pax_open_userland(void)
2168+{
2169+
2170+#ifdef CONFIG_PAX_MEMORY_UDEREF
2171+ if (segment_eq(get_fs(), USER_DS)) {
2172+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2173+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2174+ }
2175+#endif
2176+
2177+}
2178+
2179+static inline void pax_close_userland(void)
2180+{
2181+
2182+#ifdef CONFIG_PAX_MEMORY_UDEREF
2183+ if (segment_eq(get_fs(), USER_DS)) {
2184+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2185+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2186+ }
2187+#endif
2188+
2189+}
2190+
2191 #define __addr_ok(addr) ({ \
2192 unsigned long flag; \
2193 __asm__("cmp %2, %0; movlo %0, #0" \
2194@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2195
2196 #define get_user(x,p) \
2197 ({ \
2198+ int __e; \
2199 might_fault(); \
2200- __get_user_check(x,p); \
2201+ pax_open_userland(); \
2202+ __e = __get_user_check(x,p); \
2203+ pax_close_userland(); \
2204+ __e; \
2205 })
2206
2207 extern int __put_user_1(void *, unsigned int);
2208@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2209
2210 #define put_user(x,p) \
2211 ({ \
2212+ int __e; \
2213 might_fault(); \
2214- __put_user_check(x,p); \
2215+ pax_open_userland(); \
2216+ __e = __put_user_check(x,p); \
2217+ pax_close_userland(); \
2218+ __e; \
2219 })
2220
2221 #else /* CONFIG_MMU */
2222@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2223 #define __get_user(x,ptr) \
2224 ({ \
2225 long __gu_err = 0; \
2226+ pax_open_userland(); \
2227 __get_user_err((x),(ptr),__gu_err); \
2228+ pax_close_userland(); \
2229 __gu_err; \
2230 })
2231
2232 #define __get_user_error(x,ptr,err) \
2233 ({ \
2234+ pax_open_userland(); \
2235 __get_user_err((x),(ptr),err); \
2236+ pax_close_userland(); \
2237 (void) 0; \
2238 })
2239
2240@@ -312,13 +349,17 @@ do { \
2241 #define __put_user(x,ptr) \
2242 ({ \
2243 long __pu_err = 0; \
2244+ pax_open_userland(); \
2245 __put_user_err((x),(ptr),__pu_err); \
2246+ pax_close_userland(); \
2247 __pu_err; \
2248 })
2249
2250 #define __put_user_error(x,ptr,err) \
2251 ({ \
2252+ pax_open_userland(); \
2253 __put_user_err((x),(ptr),err); \
2254+ pax_close_userland(); \
2255 (void) 0; \
2256 })
2257
2258@@ -418,11 +459,44 @@ do { \
2259
2260
2261 #ifdef CONFIG_MMU
2262-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2263-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2264+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2265+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2266+
2267+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2268+{
2269+ unsigned long ret;
2270+
2271+ check_object_size(to, n, false);
2272+ pax_open_userland();
2273+ ret = ___copy_from_user(to, from, n);
2274+ pax_close_userland();
2275+ return ret;
2276+}
2277+
2278+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2279+{
2280+ unsigned long ret;
2281+
2282+ check_object_size(from, n, true);
2283+ pax_open_userland();
2284+ ret = ___copy_to_user(to, from, n);
2285+ pax_close_userland();
2286+ return ret;
2287+}
2288+
2289 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2290-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2291+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2292 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2293+
2294+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2295+{
2296+ unsigned long ret;
2297+ pax_open_userland();
2298+ ret = ___clear_user(addr, n);
2299+ pax_close_userland();
2300+ return ret;
2301+}
2302+
2303 #else
2304 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2305 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2306@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2307
2308 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2309 {
2310+ if ((long)n < 0)
2311+ return n;
2312+
2313 if (access_ok(VERIFY_READ, from, n))
2314 n = __copy_from_user(to, from, n);
2315 else /* security hole - plug it */
2316@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2317
2318 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2319 {
2320+ if ((long)n < 0)
2321+ return n;
2322+
2323 if (access_ok(VERIFY_WRITE, to, n))
2324 n = __copy_to_user(to, from, n);
2325 return n;
2326diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2327index 96ee092..37f1844 100644
2328--- a/arch/arm/include/uapi/asm/ptrace.h
2329+++ b/arch/arm/include/uapi/asm/ptrace.h
2330@@ -73,7 +73,7 @@
2331 * ARMv7 groups of PSR bits
2332 */
2333 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2334-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2335+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2336 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2337 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2338
2339diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2340index 60d3b73..e5a0f22 100644
2341--- a/arch/arm/kernel/armksyms.c
2342+++ b/arch/arm/kernel/armksyms.c
2343@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2344
2345 /* networking */
2346 EXPORT_SYMBOL(csum_partial);
2347-EXPORT_SYMBOL(csum_partial_copy_from_user);
2348+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2349 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2350 EXPORT_SYMBOL(__csum_ipv6_magic);
2351
2352@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2353 #ifdef CONFIG_MMU
2354 EXPORT_SYMBOL(copy_page);
2355
2356-EXPORT_SYMBOL(__copy_from_user);
2357-EXPORT_SYMBOL(__copy_to_user);
2358-EXPORT_SYMBOL(__clear_user);
2359+EXPORT_SYMBOL(___copy_from_user);
2360+EXPORT_SYMBOL(___copy_to_user);
2361+EXPORT_SYMBOL(___clear_user);
2362
2363 EXPORT_SYMBOL(__get_user_1);
2364 EXPORT_SYMBOL(__get_user_2);
2365diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2366index 582b405..a78366b 100644
2367--- a/arch/arm/kernel/entry-armv.S
2368+++ b/arch/arm/kernel/entry-armv.S
2369@@ -47,6 +47,87 @@
2370 9997:
2371 .endm
2372
2373+ .macro pax_enter_kernel
2374+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2375+ @ make aligned space for saved DACR
2376+ sub sp, sp, #8
2377+ @ save regs
2378+ stmdb sp!, {r1, r2}
2379+ @ read DACR from cpu_domain into r1
2380+ mov r2, sp
2381+ @ assume 8K pages, since we have to split the immediate in two
2382+ bic r2, r2, #(0x1fc0)
2383+ bic r2, r2, #(0x3f)
2384+ ldr r1, [r2, #TI_CPU_DOMAIN]
2385+ @ store old DACR on stack
2386+ str r1, [sp, #8]
2387+#ifdef CONFIG_PAX_KERNEXEC
2388+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2389+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2390+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2391+#endif
2392+#ifdef CONFIG_PAX_MEMORY_UDEREF
2393+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2394+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2395+#endif
2396+ @ write r1 to current_thread_info()->cpu_domain
2397+ str r1, [r2, #TI_CPU_DOMAIN]
2398+ @ write r1 to DACR
2399+ mcr p15, 0, r1, c3, c0, 0
2400+ @ instruction sync
2401+ instr_sync
2402+ @ restore regs
2403+ ldmia sp!, {r1, r2}
2404+#endif
2405+ .endm
2406+
2407+ .macro pax_open_userland
2408+#ifdef CONFIG_PAX_MEMORY_UDEREF
2409+ @ save regs
2410+ stmdb sp!, {r0, r1}
2411+ @ read DACR from cpu_domain into r1
2412+ mov r0, sp
2413+ @ assume 8K pages, since we have to split the immediate in two
2414+ bic r0, r0, #(0x1fc0)
2415+ bic r0, r0, #(0x3f)
2416+ ldr r1, [r0, #TI_CPU_DOMAIN]
2417+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2418+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2419+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2420+ @ write r1 to current_thread_info()->cpu_domain
2421+ str r1, [r0, #TI_CPU_DOMAIN]
2422+ @ write r1 to DACR
2423+ mcr p15, 0, r1, c3, c0, 0
2424+ @ instruction sync
2425+ instr_sync
2426+ @ restore regs
2427+ ldmia sp!, {r0, r1}
2428+#endif
2429+ .endm
2430+
2431+ .macro pax_close_userland
2432+#ifdef CONFIG_PAX_MEMORY_UDEREF
2433+ @ save regs
2434+ stmdb sp!, {r0, r1}
2435+ @ read DACR from cpu_domain into r1
2436+ mov r0, sp
2437+ @ assume 8K pages, since we have to split the immediate in two
2438+ bic r0, r0, #(0x1fc0)
2439+ bic r0, r0, #(0x3f)
2440+ ldr r1, [r0, #TI_CPU_DOMAIN]
2441+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2442+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2443+ @ write r1 to current_thread_info()->cpu_domain
2444+ str r1, [r0, #TI_CPU_DOMAIN]
2445+ @ write r1 to DACR
2446+ mcr p15, 0, r1, c3, c0, 0
2447+ @ instruction sync
2448+ instr_sync
2449+ @ restore regs
2450+ ldmia sp!, {r0, r1}
2451+#endif
2452+ .endm
2453+
2454 .macro pabt_helper
2455 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2456 #ifdef MULTI_PABORT
2457@@ -89,11 +170,15 @@
2458 * Invalid mode handlers
2459 */
2460 .macro inv_entry, reason
2461+
2462+ pax_enter_kernel
2463+
2464 sub sp, sp, #S_FRAME_SIZE
2465 ARM( stmib sp, {r1 - lr} )
2466 THUMB( stmia sp, {r0 - r12} )
2467 THUMB( str sp, [sp, #S_SP] )
2468 THUMB( str lr, [sp, #S_LR] )
2469+
2470 mov r1, #\reason
2471 .endm
2472
2473@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2474 .macro svc_entry, stack_hole=0
2475 UNWIND(.fnstart )
2476 UNWIND(.save {r0 - pc} )
2477+
2478+ pax_enter_kernel
2479+
2480 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2481+
2482 #ifdef CONFIG_THUMB2_KERNEL
2483 SPFIX( str r0, [sp] ) @ temporarily saved
2484 SPFIX( mov r0, sp )
2485@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2486 ldmia r0, {r3 - r5}
2487 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2488 mov r6, #-1 @ "" "" "" ""
2489+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2490+ @ offset sp by 8 as done in pax_enter_kernel
2491+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2492+#else
2493 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2494+#endif
2495 SPFIX( addeq r2, r2, #4 )
2496 str r3, [sp, #-4]! @ save the "real" r0 copied
2497 @ from the exception stack
2498@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2499 .macro usr_entry
2500 UNWIND(.fnstart )
2501 UNWIND(.cantunwind ) @ don't unwind the user space
2502+
2503+ pax_enter_kernel_user
2504+
2505 sub sp, sp, #S_FRAME_SIZE
2506 ARM( stmib sp, {r1 - r12} )
2507 THUMB( stmia sp, {r0 - r12} )
2508@@ -414,7 +511,9 @@ __und_usr:
2509 tst r3, #PSR_T_BIT @ Thumb mode?
2510 bne __und_usr_thumb
2511 sub r4, r2, #4 @ ARM instr at LR - 4
2512+ pax_open_userland
2513 1: ldrt r0, [r4]
2514+ pax_close_userland
2515 #ifdef CONFIG_CPU_ENDIAN_BE8
2516 rev r0, r0 @ little endian instruction
2517 #endif
2518@@ -449,10 +548,14 @@ __und_usr_thumb:
2519 */
2520 .arch armv6t2
2521 #endif
2522+ pax_open_userland
2523 2: ldrht r5, [r4]
2524+ pax_close_userland
2525 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2526 blo __und_usr_fault_16 @ 16bit undefined instruction
2527+ pax_open_userland
2528 3: ldrht r0, [r2]
2529+ pax_close_userland
2530 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2531 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2532 orr r0, r0, r5, lsl #16
2533@@ -481,7 +584,8 @@ ENDPROC(__und_usr)
2534 */
2535 .pushsection .fixup, "ax"
2536 .align 2
2537-4: mov pc, r9
2538+4: pax_close_userland
2539+ mov pc, r9
2540 .popsection
2541 .pushsection __ex_table,"a"
2542 .long 1b, 4b
2543@@ -690,7 +794,7 @@ ENTRY(__switch_to)
2544 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2545 THUMB( str sp, [ip], #4 )
2546 THUMB( str lr, [ip], #4 )
2547-#ifdef CONFIG_CPU_USE_DOMAINS
2548+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2549 ldr r6, [r2, #TI_CPU_DOMAIN]
2550 #endif
2551 set_tls r3, r4, r5
2552@@ -699,7 +803,7 @@ ENTRY(__switch_to)
2553 ldr r8, =__stack_chk_guard
2554 ldr r7, [r7, #TSK_STACK_CANARY]
2555 #endif
2556-#ifdef CONFIG_CPU_USE_DOMAINS
2557+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2558 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2559 #endif
2560 mov r5, r0
2561diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2562index bc5bc0a..d0998ca 100644
2563--- a/arch/arm/kernel/entry-common.S
2564+++ b/arch/arm/kernel/entry-common.S
2565@@ -10,18 +10,46 @@
2566
2567 #include <asm/unistd.h>
2568 #include <asm/ftrace.h>
2569+#include <asm/domain.h>
2570 #include <asm/unwind.h>
2571
2572+#include "entry-header.S"
2573+
2574 #ifdef CONFIG_NEED_RET_TO_USER
2575 #include <mach/entry-macro.S>
2576 #else
2577 .macro arch_ret_to_user, tmp1, tmp2
2578+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2579+ @ save regs
2580+ stmdb sp!, {r1, r2}
2581+ @ read DACR from cpu_domain into r1
2582+ mov r2, sp
2583+ @ assume 8K pages, since we have to split the immediate in two
2584+ bic r2, r2, #(0x1fc0)
2585+ bic r2, r2, #(0x3f)
2586+ ldr r1, [r2, #TI_CPU_DOMAIN]
2587+#ifdef CONFIG_PAX_KERNEXEC
2588+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2589+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2590+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2591+#endif
2592+#ifdef CONFIG_PAX_MEMORY_UDEREF
2593+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2594+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2595+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2596+#endif
2597+ @ write r1 to current_thread_info()->cpu_domain
2598+ str r1, [r2, #TI_CPU_DOMAIN]
2599+ @ write r1 to DACR
2600+ mcr p15, 0, r1, c3, c0, 0
2601+ @ instruction sync
2602+ instr_sync
2603+ @ restore regs
2604+ ldmia sp!, {r1, r2}
2605+#endif
2606 .endm
2607 #endif
2608
2609-#include "entry-header.S"
2610-
2611-
2612 .align 5
2613 /*
2614 * This is the fast syscall return path. We do as little as
2615@@ -350,6 +378,7 @@ ENDPROC(ftrace_stub)
2616
2617 .align 5
2618 ENTRY(vector_swi)
2619+
2620 sub sp, sp, #S_FRAME_SIZE
2621 stmia sp, {r0 - r12} @ Calling r0 - r12
2622 ARM( add r8, sp, #S_PC )
2623@@ -399,6 +428,12 @@ ENTRY(vector_swi)
2624 ldr scno, [lr, #-4] @ get SWI instruction
2625 #endif
2626
2627+ /*
2628+ * do this here to avoid a performance hit of wrapping the code above
2629+ * that directly dereferences userland to parse the SWI instruction
2630+ */
2631+ pax_enter_kernel_user
2632+
2633 #ifdef CONFIG_ALIGNMENT_TRAP
2634 ldr ip, __cr_alignment
2635 ldr ip, [ip]
2636diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2637index 160f337..db67ee4 100644
2638--- a/arch/arm/kernel/entry-header.S
2639+++ b/arch/arm/kernel/entry-header.S
2640@@ -73,6 +73,60 @@
2641 msr cpsr_c, \rtemp @ switch back to the SVC mode
2642 .endm
2643
2644+ .macro pax_enter_kernel_user
2645+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646+ @ save regs
2647+ stmdb sp!, {r0, r1}
2648+ @ read DACR from cpu_domain into r1
2649+ mov r0, sp
2650+ @ assume 8K pages, since we have to split the immediate in two
2651+ bic r0, r0, #(0x1fc0)
2652+ bic r0, r0, #(0x3f)
2653+ ldr r1, [r0, #TI_CPU_DOMAIN]
2654+#ifdef CONFIG_PAX_MEMORY_UDEREF
2655+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2656+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2657+#endif
2658+#ifdef CONFIG_PAX_KERNEXEC
2659+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2660+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2661+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2662+#endif
2663+ @ write r1 to current_thread_info()->cpu_domain
2664+ str r1, [r0, #TI_CPU_DOMAIN]
2665+ @ write r1 to DACR
2666+ mcr p15, 0, r1, c3, c0, 0
2667+ @ instruction sync
2668+ instr_sync
2669+ @ restore regs
2670+ ldmia sp!, {r0, r1}
2671+#endif
2672+ .endm
2673+
2674+ .macro pax_exit_kernel
2675+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2676+ @ save regs
2677+ stmdb sp!, {r0, r1}
2678+ @ read old DACR from stack into r1
2679+ ldr r1, [sp, #(8 + S_SP)]
2680+ sub r1, r1, #8
2681+ ldr r1, [r1]
2682+
2683+ @ write r1 to current_thread_info()->cpu_domain
2684+ mov r0, sp
2685+ @ assume 8K pages, since we have to split the immediate in two
2686+ bic r0, r0, #(0x1fc0)
2687+ bic r0, r0, #(0x3f)
2688+ str r1, [r0, #TI_CPU_DOMAIN]
2689+ @ write r1 to DACR
2690+ mcr p15, 0, r1, c3, c0, 0
2691+ @ instruction sync
2692+ instr_sync
2693+ @ restore regs
2694+ ldmia sp!, {r0, r1}
2695+#endif
2696+ .endm
2697+
2698 #ifndef CONFIG_THUMB2_KERNEL
2699 .macro svc_exit, rpsr, irq = 0
2700 .if \irq != 0
2701@@ -92,6 +146,9 @@
2702 blne trace_hardirqs_off
2703 #endif
2704 .endif
2705+
2706+ pax_exit_kernel
2707+
2708 msr spsr_cxsf, \rpsr
2709 #if defined(CONFIG_CPU_V6)
2710 ldr r0, [sp]
2711@@ -155,6 +212,9 @@
2712 blne trace_hardirqs_off
2713 #endif
2714 .endif
2715+
2716+ pax_exit_kernel
2717+
2718 ldr lr, [sp, #S_SP] @ top of the stack
2719 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2720 clrex @ clear the exclusive monitor
2721diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2722index 2adda11..7fbe958 100644
2723--- a/arch/arm/kernel/fiq.c
2724+++ b/arch/arm/kernel/fiq.c
2725@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2726 #if defined(CONFIG_CPU_USE_DOMAINS)
2727 memcpy((void *)0xffff001c, start, length);
2728 #else
2729+ pax_open_kernel();
2730 memcpy(vectors_page + 0x1c, start, length);
2731+ pax_close_kernel();
2732 #endif
2733 flush_icache_range(0xffff001c, 0xffff001c + length);
2734 if (!vectors_high())
2735diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2736index 8bac553..caee108 100644
2737--- a/arch/arm/kernel/head.S
2738+++ b/arch/arm/kernel/head.S
2739@@ -52,7 +52,9 @@
2740 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2741
2742 .macro pgtbl, rd, phys
2743- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2744+ mov \rd, #TEXT_OFFSET
2745+ sub \rd, #PG_DIR_SIZE
2746+ add \rd, \rd, \phys
2747 .endm
2748
2749 /*
2750@@ -434,7 +436,7 @@ __enable_mmu:
2751 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2752 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2753 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2754- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2755+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2756 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2757 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2758 #endif
2759diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2760index 1fd749e..47adb08 100644
2761--- a/arch/arm/kernel/hw_breakpoint.c
2762+++ b/arch/arm/kernel/hw_breakpoint.c
2763@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2764 return NOTIFY_OK;
2765 }
2766
2767-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2768+static struct notifier_block dbg_reset_nb = {
2769 .notifier_call = dbg_reset_notify,
2770 };
2771
2772diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2773index 1e9be5d..03edbc2 100644
2774--- a/arch/arm/kernel/module.c
2775+++ b/arch/arm/kernel/module.c
2776@@ -37,12 +37,37 @@
2777 #endif
2778
2779 #ifdef CONFIG_MMU
2780-void *module_alloc(unsigned long size)
2781+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2782 {
2783+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2784+ return NULL;
2785 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2786- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2787+ GFP_KERNEL, prot, -1,
2788 __builtin_return_address(0));
2789 }
2790+
2791+void *module_alloc(unsigned long size)
2792+{
2793+
2794+#ifdef CONFIG_PAX_KERNEXEC
2795+ return __module_alloc(size, PAGE_KERNEL);
2796+#else
2797+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2798+#endif
2799+
2800+}
2801+
2802+#ifdef CONFIG_PAX_KERNEXEC
2803+void module_free_exec(struct module *mod, void *module_region)
2804+{
2805+ module_free(mod, module_region);
2806+}
2807+
2808+void *module_alloc_exec(unsigned long size)
2809+{
2810+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2811+}
2812+#endif
2813 #endif
2814
2815 int
2816diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2817index 07314af..c46655c 100644
2818--- a/arch/arm/kernel/patch.c
2819+++ b/arch/arm/kernel/patch.c
2820@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2821 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2822 int size;
2823
2824+ pax_open_kernel();
2825 if (thumb2 && __opcode_is_thumb16(insn)) {
2826 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2827 size = sizeof(u16);
2828@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2829 *(u32 *)addr = insn;
2830 size = sizeof(u32);
2831 }
2832+ pax_close_kernel();
2833
2834 flush_icache_range((uintptr_t)(addr),
2835 (uintptr_t)(addr) + size);
2836diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2837index 1f2740e..b36e225 100644
2838--- a/arch/arm/kernel/perf_event_cpu.c
2839+++ b/arch/arm/kernel/perf_event_cpu.c
2840@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2841 return NOTIFY_OK;
2842 }
2843
2844-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2845+static struct notifier_block cpu_pmu_hotplug_notifier = {
2846 .notifier_call = cpu_pmu_notify,
2847 };
2848
2849diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2850index 6e8931c..82ec6a5 100644
2851--- a/arch/arm/kernel/process.c
2852+++ b/arch/arm/kernel/process.c
2853@@ -28,7 +28,6 @@
2854 #include <linux/tick.h>
2855 #include <linux/utsname.h>
2856 #include <linux/uaccess.h>
2857-#include <linux/random.h>
2858 #include <linux/hw_breakpoint.h>
2859 #include <linux/cpuidle.h>
2860 #include <linux/leds.h>
2861@@ -223,6 +222,7 @@ void machine_power_off(void)
2862
2863 if (pm_power_off)
2864 pm_power_off();
2865+ BUG();
2866 }
2867
2868 /*
2869@@ -236,7 +236,7 @@ void machine_power_off(void)
2870 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2871 * to use. Implementing such co-ordination would be essentially impossible.
2872 */
2873-void machine_restart(char *cmd)
2874+__noreturn void machine_restart(char *cmd)
2875 {
2876 smp_send_stop();
2877
2878@@ -258,8 +258,8 @@ void __show_regs(struct pt_regs *regs)
2879
2880 show_regs_print_info(KERN_DEFAULT);
2881
2882- print_symbol("PC is at %s\n", instruction_pointer(regs));
2883- print_symbol("LR is at %s\n", regs->ARM_lr);
2884+ printk("PC is at %pA\n", instruction_pointer(regs));
2885+ printk("LR is at %pA\n", regs->ARM_lr);
2886 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2887 "sp : %08lx ip : %08lx fp : %08lx\n",
2888 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2889@@ -426,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2890 return 0;
2891 }
2892
2893-unsigned long arch_randomize_brk(struct mm_struct *mm)
2894-{
2895- unsigned long range_end = mm->brk + 0x02000000;
2896- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2897-}
2898-
2899 #ifdef CONFIG_MMU
2900 /*
2901 * The vectors page is always readable from user space for the
2902@@ -441,12 +435,12 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
2903 static struct vm_area_struct gate_vma = {
2904 .vm_start = 0xffff0000,
2905 .vm_end = 0xffff0000 + PAGE_SIZE,
2906- .vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC,
2907+ .vm_flags = VM_NONE,
2908 };
2909
2910 static int __init gate_vma_init(void)
2911 {
2912- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2913+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2914 return 0;
2915 }
2916 arch_initcall(gate_vma_init);
2917diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2918index 3653164..d83e55d 100644
2919--- a/arch/arm/kernel/psci.c
2920+++ b/arch/arm/kernel/psci.c
2921@@ -24,7 +24,7 @@
2922 #include <asm/opcodes-virt.h>
2923 #include <asm/psci.h>
2924
2925-struct psci_operations psci_ops;
2926+struct psci_operations psci_ops __read_only;
2927
2928 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2929
2930diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2931index 03deeff..741ce88 100644
2932--- a/arch/arm/kernel/ptrace.c
2933+++ b/arch/arm/kernel/ptrace.c
2934@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2935 return current_thread_info()->syscall;
2936 }
2937
2938+#ifdef CONFIG_GRKERNSEC_SETXID
2939+extern void gr_delayed_cred_worker(void);
2940+#endif
2941+
2942 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2943 {
2944 current_thread_info()->syscall = scno;
2945
2946+#ifdef CONFIG_GRKERNSEC_SETXID
2947+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2948+ gr_delayed_cred_worker();
2949+#endif
2950+
2951 /* Do the secure computing check first; failures should be fast. */
2952 if (secure_computing(scno) == -1)
2953 return -1;
2954diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2955index b4b1d39..efdc9be 100644
2956--- a/arch/arm/kernel/setup.c
2957+++ b/arch/arm/kernel/setup.c
2958@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2959 unsigned int elf_hwcap __read_mostly;
2960 EXPORT_SYMBOL(elf_hwcap);
2961
2962+pteval_t __supported_pte_mask __read_only;
2963+pmdval_t __supported_pmd_mask __read_only;
2964
2965 #ifdef MULTI_CPU
2966-struct processor processor __read_mostly;
2967+struct processor processor;
2968 #endif
2969 #ifdef MULTI_TLB
2970-struct cpu_tlb_fns cpu_tlb __read_mostly;
2971+struct cpu_tlb_fns cpu_tlb __read_only;
2972 #endif
2973 #ifdef MULTI_USER
2974-struct cpu_user_fns cpu_user __read_mostly;
2975+struct cpu_user_fns cpu_user __read_only;
2976 #endif
2977 #ifdef MULTI_CACHE
2978-struct cpu_cache_fns cpu_cache __read_mostly;
2979+struct cpu_cache_fns cpu_cache __read_only;
2980 #endif
2981 #ifdef CONFIG_OUTER_CACHE
2982-struct outer_cache_fns outer_cache __read_mostly;
2983+struct outer_cache_fns outer_cache __read_only;
2984 EXPORT_SYMBOL(outer_cache);
2985 #endif
2986
2987@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2988 asm("mrc p15, 0, %0, c0, c1, 4"
2989 : "=r" (mmfr0));
2990 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2991- (mmfr0 & 0x000000f0) >= 0x00000030)
2992+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2993 cpu_arch = CPU_ARCH_ARMv7;
2994- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2995+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2996+ __supported_pte_mask |= L_PTE_PXN;
2997+ __supported_pmd_mask |= PMD_PXNTABLE;
2998+ }
2999+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3000 (mmfr0 & 0x000000f0) == 0x00000020)
3001 cpu_arch = CPU_ARCH_ARMv6;
3002 else
3003@@ -479,7 +485,7 @@ static void __init setup_processor(void)
3004 __cpu_architecture = __get_cpu_architecture();
3005
3006 #ifdef MULTI_CPU
3007- processor = *list->proc;
3008+ memcpy((void *)&processor, list->proc, sizeof processor);
3009 #endif
3010 #ifdef MULTI_TLB
3011 cpu_tlb = *list->tlb;
3012diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3013index 296786b..a8d4dd5 100644
3014--- a/arch/arm/kernel/signal.c
3015+++ b/arch/arm/kernel/signal.c
3016@@ -396,22 +396,14 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3017 __put_user(sigreturn_codes[idx+1], rc+1))
3018 return 1;
3019
3020- if (cpsr & MODE32_BIT) {
3021- /*
3022- * 32-bit code can use the new high-page
3023- * signal return code support.
3024- */
3025- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
3026- } else {
3027- /*
3028- * Ensure that the instruction cache sees
3029- * the return code written onto the stack.
3030- */
3031- flush_icache_range((unsigned long)rc,
3032- (unsigned long)(rc + 2));
3033+ /*
3034+ * Ensure that the instruction cache sees
3035+ * the return code written onto the stack.
3036+ */
3037+ flush_icache_range((unsigned long)rc,
3038+ (unsigned long)(rc + 2));
3039
3040- retcode = ((unsigned long)rc) + thumb;
3041- }
3042+ retcode = ((unsigned long)rc) + thumb;
3043 }
3044
3045 regs->ARM_r0 = map_sig(ksig->sig);
3046diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3047index 5919eb4..b5d6dfe 100644
3048--- a/arch/arm/kernel/smp.c
3049+++ b/arch/arm/kernel/smp.c
3050@@ -70,7 +70,7 @@ enum ipi_msg_type {
3051
3052 static DECLARE_COMPLETION(cpu_running);
3053
3054-static struct smp_operations smp_ops;
3055+static struct smp_operations smp_ops __read_only;
3056
3057 void __init smp_set_ops(struct smp_operations *ops)
3058 {
3059diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3060index 18b32e8..b0c8dca 100644
3061--- a/arch/arm/kernel/traps.c
3062+++ b/arch/arm/kernel/traps.c
3063@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3064 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3065 {
3066 #ifdef CONFIG_KALLSYMS
3067- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3068+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3069 #else
3070 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3071 #endif
3072@@ -259,6 +259,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3073 static int die_owner = -1;
3074 static unsigned int die_nest_count;
3075
3076+extern void gr_handle_kernel_exploit(void);
3077+
3078 static unsigned long oops_begin(void)
3079 {
3080 int cpu;
3081@@ -301,6 +303,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3082 panic("Fatal exception in interrupt");
3083 if (panic_on_oops)
3084 panic("Fatal exception");
3085+
3086+ gr_handle_kernel_exploit();
3087+
3088 if (signr)
3089 do_exit(signr);
3090 }
3091@@ -594,7 +599,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3092 * The user helper at 0xffff0fe0 must be used instead.
3093 * (see entry-armv.S for details)
3094 */
3095+ pax_open_kernel();
3096 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3097+ pax_close_kernel();
3098 }
3099 return 0;
3100
3101@@ -834,13 +841,10 @@ void __init early_trap_init(void *vectors_base)
3102 */
3103 kuser_get_tls_init(vectors);
3104
3105- /*
3106- * Copy signal return handlers into the vector page, and
3107- * set sigreturn to be a pointer to these.
3108- */
3109- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3110- sigreturn_codes, sizeof(sigreturn_codes));
3111-
3112 flush_icache_range(vectors, vectors + PAGE_SIZE);
3113- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3114+
3115+#ifndef CONFIG_PAX_MEMORY_UDEREF
3116+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3117+#endif
3118+
3119 }
3120diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3121index a871b8e..123b00a 100644
3122--- a/arch/arm/kernel/vmlinux.lds.S
3123+++ b/arch/arm/kernel/vmlinux.lds.S
3124@@ -8,7 +8,11 @@
3125 #include <asm/thread_info.h>
3126 #include <asm/memory.h>
3127 #include <asm/page.h>
3128-
3129+
3130+#ifdef CONFIG_PAX_KERNEXEC
3131+#include <asm/pgtable.h>
3132+#endif
3133+
3134 #define PROC_INFO \
3135 . = ALIGN(4); \
3136 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3137@@ -94,6 +98,11 @@ SECTIONS
3138 _text = .;
3139 HEAD_TEXT
3140 }
3141+
3142+#ifdef CONFIG_PAX_KERNEXEC
3143+ . = ALIGN(1<<SECTION_SHIFT);
3144+#endif
3145+
3146 .text : { /* Real text segment */
3147 _stext = .; /* Text and read-only data */
3148 __exception_text_start = .;
3149@@ -116,6 +125,8 @@ SECTIONS
3150 ARM_CPU_KEEP(PROC_INFO)
3151 }
3152
3153+ _etext = .; /* End of text section */
3154+
3155 RO_DATA(PAGE_SIZE)
3156
3157 . = ALIGN(4);
3158@@ -146,7 +157,9 @@ SECTIONS
3159
3160 NOTES
3161
3162- _etext = .; /* End of text and rodata section */
3163+#ifdef CONFIG_PAX_KERNEXEC
3164+ . = ALIGN(1<<SECTION_SHIFT);
3165+#endif
3166
3167 #ifndef CONFIG_XIP_KERNEL
3168 . = ALIGN(PAGE_SIZE);
3169@@ -207,6 +220,11 @@ SECTIONS
3170 . = PAGE_OFFSET + TEXT_OFFSET;
3171 #else
3172 __init_end = .;
3173+
3174+#ifdef CONFIG_PAX_KERNEXEC
3175+ . = ALIGN(1<<SECTION_SHIFT);
3176+#endif
3177+
3178 . = ALIGN(THREAD_SIZE);
3179 __data_loc = .;
3180 #endif
3181diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3182index 14a0d98..7771a7d 100644
3183--- a/arch/arm/lib/clear_user.S
3184+++ b/arch/arm/lib/clear_user.S
3185@@ -12,14 +12,14 @@
3186
3187 .text
3188
3189-/* Prototype: int __clear_user(void *addr, size_t sz)
3190+/* Prototype: int ___clear_user(void *addr, size_t sz)
3191 * Purpose : clear some user memory
3192 * Params : addr - user memory address to clear
3193 * : sz - number of bytes to clear
3194 * Returns : number of bytes NOT cleared
3195 */
3196 ENTRY(__clear_user_std)
3197-WEAK(__clear_user)
3198+WEAK(___clear_user)
3199 stmfd sp!, {r1, lr}
3200 mov r2, #0
3201 cmp r1, #4
3202@@ -44,7 +44,7 @@ WEAK(__clear_user)
3203 USER( strnebt r2, [r0])
3204 mov r0, #0
3205 ldmfd sp!, {r1, pc}
3206-ENDPROC(__clear_user)
3207+ENDPROC(___clear_user)
3208 ENDPROC(__clear_user_std)
3209
3210 .pushsection .fixup,"ax"
3211diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3212index 66a477a..bee61d3 100644
3213--- a/arch/arm/lib/copy_from_user.S
3214+++ b/arch/arm/lib/copy_from_user.S
3215@@ -16,7 +16,7 @@
3216 /*
3217 * Prototype:
3218 *
3219- * size_t __copy_from_user(void *to, const void *from, size_t n)
3220+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3221 *
3222 * Purpose:
3223 *
3224@@ -84,11 +84,11 @@
3225
3226 .text
3227
3228-ENTRY(__copy_from_user)
3229+ENTRY(___copy_from_user)
3230
3231 #include "copy_template.S"
3232
3233-ENDPROC(__copy_from_user)
3234+ENDPROC(___copy_from_user)
3235
3236 .pushsection .fixup,"ax"
3237 .align 0
3238diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3239index 6ee2f67..d1cce76 100644
3240--- a/arch/arm/lib/copy_page.S
3241+++ b/arch/arm/lib/copy_page.S
3242@@ -10,6 +10,7 @@
3243 * ASM optimised string functions
3244 */
3245 #include <linux/linkage.h>
3246+#include <linux/const.h>
3247 #include <asm/assembler.h>
3248 #include <asm/asm-offsets.h>
3249 #include <asm/cache.h>
3250diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3251index d066df6..df28194 100644
3252--- a/arch/arm/lib/copy_to_user.S
3253+++ b/arch/arm/lib/copy_to_user.S
3254@@ -16,7 +16,7 @@
3255 /*
3256 * Prototype:
3257 *
3258- * size_t __copy_to_user(void *to, const void *from, size_t n)
3259+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3260 *
3261 * Purpose:
3262 *
3263@@ -88,11 +88,11 @@
3264 .text
3265
3266 ENTRY(__copy_to_user_std)
3267-WEAK(__copy_to_user)
3268+WEAK(___copy_to_user)
3269
3270 #include "copy_template.S"
3271
3272-ENDPROC(__copy_to_user)
3273+ENDPROC(___copy_to_user)
3274 ENDPROC(__copy_to_user_std)
3275
3276 .pushsection .fixup,"ax"
3277diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3278index 7d08b43..f7ca7ea 100644
3279--- a/arch/arm/lib/csumpartialcopyuser.S
3280+++ b/arch/arm/lib/csumpartialcopyuser.S
3281@@ -57,8 +57,8 @@
3282 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3283 */
3284
3285-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3286-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3287+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3288+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3289
3290 #include "csumpartialcopygeneric.S"
3291
3292diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3293index 64dbfa5..84a3fd9 100644
3294--- a/arch/arm/lib/delay.c
3295+++ b/arch/arm/lib/delay.c
3296@@ -28,7 +28,7 @@
3297 /*
3298 * Default to the loop-based delay implementation.
3299 */
3300-struct arm_delay_ops arm_delay_ops = {
3301+struct arm_delay_ops arm_delay_ops __read_only = {
3302 .delay = __loop_delay,
3303 .const_udelay = __loop_const_udelay,
3304 .udelay = __loop_udelay,
3305diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3306index 025f742..8432b08 100644
3307--- a/arch/arm/lib/uaccess_with_memcpy.c
3308+++ b/arch/arm/lib/uaccess_with_memcpy.c
3309@@ -104,7 +104,7 @@ out:
3310 }
3311
3312 unsigned long
3313-__copy_to_user(void __user *to, const void *from, unsigned long n)
3314+___copy_to_user(void __user *to, const void *from, unsigned long n)
3315 {
3316 /*
3317 * This test is stubbed out of the main function above to keep
3318diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3319index f389228..592ef66 100644
3320--- a/arch/arm/mach-kirkwood/common.c
3321+++ b/arch/arm/mach-kirkwood/common.c
3322@@ -149,7 +149,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3323 clk_gate_ops.disable(hw);
3324 }
3325
3326-static struct clk_ops clk_gate_fn_ops;
3327+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3328+{
3329+ return clk_gate_ops.is_enabled(hw);
3330+}
3331+
3332+static struct clk_ops clk_gate_fn_ops = {
3333+ .enable = clk_gate_fn_enable,
3334+ .disable = clk_gate_fn_disable,
3335+ .is_enabled = clk_gate_fn_is_enabled,
3336+};
3337
3338 static struct clk __init *clk_register_gate_fn(struct device *dev,
3339 const char *name,
3340@@ -183,14 +192,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3341 gate_fn->fn_en = fn_en;
3342 gate_fn->fn_dis = fn_dis;
3343
3344- /* ops is the gate ops, but with our enable/disable functions */
3345- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3346- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3347- clk_gate_fn_ops = clk_gate_ops;
3348- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3349- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3350- }
3351-
3352 clk = clk_register(dev, &gate_fn->gate.hw);
3353
3354 if (IS_ERR(clk))
3355diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3356index f6eeb87..cc90868 100644
3357--- a/arch/arm/mach-omap2/board-n8x0.c
3358+++ b/arch/arm/mach-omap2/board-n8x0.c
3359@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3360 }
3361 #endif
3362
3363-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3364+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3365 .late_init = n8x0_menelaus_late_init,
3366 };
3367
3368diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3369index 6c4da12..d9ca72d 100644
3370--- a/arch/arm/mach-omap2/gpmc.c
3371+++ b/arch/arm/mach-omap2/gpmc.c
3372@@ -147,7 +147,6 @@ struct omap3_gpmc_regs {
3373 };
3374
3375 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3376-static struct irq_chip gpmc_irq_chip;
3377 static unsigned gpmc_irq_start;
3378
3379 static struct resource gpmc_mem_root;
3380@@ -711,6 +710,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3381
3382 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3383
3384+static struct irq_chip gpmc_irq_chip = {
3385+ .name = "gpmc",
3386+ .irq_startup = gpmc_irq_noop_ret,
3387+ .irq_enable = gpmc_irq_enable,
3388+ .irq_disable = gpmc_irq_disable,
3389+ .irq_shutdown = gpmc_irq_noop,
3390+ .irq_ack = gpmc_irq_noop,
3391+ .irq_mask = gpmc_irq_noop,
3392+ .irq_unmask = gpmc_irq_noop,
3393+
3394+};
3395+
3396 static int gpmc_setup_irq(void)
3397 {
3398 int i;
3399@@ -725,15 +736,6 @@ static int gpmc_setup_irq(void)
3400 return gpmc_irq_start;
3401 }
3402
3403- gpmc_irq_chip.name = "gpmc";
3404- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3405- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3406- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3407- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3408- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3409- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3410- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3411-
3412 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3413 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3414
3415diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3416index f8bb3b9..831e7b8 100644
3417--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3418+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3419@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3420 return NOTIFY_OK;
3421 }
3422
3423-static struct notifier_block __refdata irq_hotplug_notifier = {
3424+static struct notifier_block irq_hotplug_notifier = {
3425 .notifier_call = irq_cpu_hotplug_notify,
3426 };
3427
3428diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3429index e6d2307..d057195 100644
3430--- a/arch/arm/mach-omap2/omap_device.c
3431+++ b/arch/arm/mach-omap2/omap_device.c
3432@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3433 struct platform_device __init *omap_device_build(const char *pdev_name,
3434 int pdev_id,
3435 struct omap_hwmod *oh,
3436- void *pdata, int pdata_len)
3437+ const void *pdata, int pdata_len)
3438 {
3439 struct omap_hwmod *ohs[] = { oh };
3440
3441@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3442 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3443 int pdev_id,
3444 struct omap_hwmod **ohs,
3445- int oh_cnt, void *pdata,
3446+ int oh_cnt, const void *pdata,
3447 int pdata_len)
3448 {
3449 int ret = -ENOMEM;
3450diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3451index 044c31d..2ee0861 100644
3452--- a/arch/arm/mach-omap2/omap_device.h
3453+++ b/arch/arm/mach-omap2/omap_device.h
3454@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3455 /* Core code interface */
3456
3457 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3458- struct omap_hwmod *oh, void *pdata,
3459+ struct omap_hwmod *oh, const void *pdata,
3460 int pdata_len);
3461
3462 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3463 struct omap_hwmod **oh, int oh_cnt,
3464- void *pdata, int pdata_len);
3465+ const void *pdata, int pdata_len);
3466
3467 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3468 struct omap_hwmod **ohs, int oh_cnt);
3469diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3470index 7341eff..fd75e34 100644
3471--- a/arch/arm/mach-omap2/omap_hwmod.c
3472+++ b/arch/arm/mach-omap2/omap_hwmod.c
3473@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3474 int (*init_clkdm)(struct omap_hwmod *oh);
3475 void (*update_context_lost)(struct omap_hwmod *oh);
3476 int (*get_context_lost)(struct omap_hwmod *oh);
3477-};
3478+} __no_const;
3479
3480 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3481-static struct omap_hwmod_soc_ops soc_ops;
3482+static struct omap_hwmod_soc_ops soc_ops __read_only;
3483
3484 /* omap_hwmod_list contains all registered struct omap_hwmods */
3485 static LIST_HEAD(omap_hwmod_list);
3486diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3487index d15c7bb..b2d1f0c 100644
3488--- a/arch/arm/mach-omap2/wd_timer.c
3489+++ b/arch/arm/mach-omap2/wd_timer.c
3490@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3491 struct omap_hwmod *oh;
3492 char *oh_name = "wd_timer2";
3493 char *dev_name = "omap_wdt";
3494- struct omap_wd_timer_platform_data pdata;
3495+ static struct omap_wd_timer_platform_data pdata = {
3496+ .read_reset_sources = prm_read_reset_sources
3497+ };
3498
3499 if (!cpu_class_is_omap2() || of_have_populated_dt())
3500 return 0;
3501@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3502 return -EINVAL;
3503 }
3504
3505- pdata.read_reset_sources = prm_read_reset_sources;
3506-
3507 pdev = omap_device_build(dev_name, id, oh, &pdata,
3508 sizeof(struct omap_wd_timer_platform_data));
3509 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3510diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3511index 0cdba8d..297993e 100644
3512--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3513+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3514@@ -181,7 +181,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3515 bool entered_lp2 = false;
3516
3517 if (tegra_pending_sgi())
3518- ACCESS_ONCE(abort_flag) = true;
3519+ ACCESS_ONCE_RW(abort_flag) = true;
3520
3521 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3522
3523diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3524index cad3ca86..1d79e0f 100644
3525--- a/arch/arm/mach-ux500/setup.h
3526+++ b/arch/arm/mach-ux500/setup.h
3527@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3528 .type = MT_DEVICE, \
3529 }
3530
3531-#define __MEM_DEV_DESC(x, sz) { \
3532- .virtual = IO_ADDRESS(x), \
3533- .pfn = __phys_to_pfn(x), \
3534- .length = sz, \
3535- .type = MT_MEMORY, \
3536-}
3537-
3538 extern struct smp_operations ux500_smp_ops;
3539 extern void ux500_cpu_die(unsigned int cpu);
3540
3541diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3542index 35955b5..b475042 100644
3543--- a/arch/arm/mm/Kconfig
3544+++ b/arch/arm/mm/Kconfig
3545@@ -432,7 +432,7 @@ config CPU_32v5
3546
3547 config CPU_32v6
3548 bool
3549- select CPU_USE_DOMAINS if CPU_V6 && MMU
3550+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3551 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3552
3553 config CPU_32v6K
3554@@ -581,6 +581,7 @@ config CPU_CP15_MPU
3555
3556 config CPU_USE_DOMAINS
3557 bool
3558+ depends on !ARM_LPAE && !PAX_KERNEXEC
3559 help
3560 This option enables or disables the use of domain switching
3561 via the set_fs() function.
3562diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3563index 6f4585b..7b6f52b 100644
3564--- a/arch/arm/mm/alignment.c
3565+++ b/arch/arm/mm/alignment.c
3566@@ -211,10 +211,12 @@ union offset_union {
3567 #define __get16_unaligned_check(ins,val,addr) \
3568 do { \
3569 unsigned int err = 0, v, a = addr; \
3570+ pax_open_userland(); \
3571 __get8_unaligned_check(ins,v,a,err); \
3572 val = v << ((BE) ? 8 : 0); \
3573 __get8_unaligned_check(ins,v,a,err); \
3574 val |= v << ((BE) ? 0 : 8); \
3575+ pax_close_userland(); \
3576 if (err) \
3577 goto fault; \
3578 } while (0)
3579@@ -228,6 +230,7 @@ union offset_union {
3580 #define __get32_unaligned_check(ins,val,addr) \
3581 do { \
3582 unsigned int err = 0, v, a = addr; \
3583+ pax_open_userland(); \
3584 __get8_unaligned_check(ins,v,a,err); \
3585 val = v << ((BE) ? 24 : 0); \
3586 __get8_unaligned_check(ins,v,a,err); \
3587@@ -236,6 +239,7 @@ union offset_union {
3588 val |= v << ((BE) ? 8 : 16); \
3589 __get8_unaligned_check(ins,v,a,err); \
3590 val |= v << ((BE) ? 0 : 24); \
3591+ pax_close_userland(); \
3592 if (err) \
3593 goto fault; \
3594 } while (0)
3595@@ -249,6 +253,7 @@ union offset_union {
3596 #define __put16_unaligned_check(ins,val,addr) \
3597 do { \
3598 unsigned int err = 0, v = val, a = addr; \
3599+ pax_open_userland(); \
3600 __asm__( FIRST_BYTE_16 \
3601 ARM( "1: "ins" %1, [%2], #1\n" ) \
3602 THUMB( "1: "ins" %1, [%2]\n" ) \
3603@@ -268,6 +273,7 @@ union offset_union {
3604 " .popsection\n" \
3605 : "=r" (err), "=&r" (v), "=&r" (a) \
3606 : "0" (err), "1" (v), "2" (a)); \
3607+ pax_close_userland(); \
3608 if (err) \
3609 goto fault; \
3610 } while (0)
3611@@ -281,6 +287,7 @@ union offset_union {
3612 #define __put32_unaligned_check(ins,val,addr) \
3613 do { \
3614 unsigned int err = 0, v = val, a = addr; \
3615+ pax_open_userland(); \
3616 __asm__( FIRST_BYTE_32 \
3617 ARM( "1: "ins" %1, [%2], #1\n" ) \
3618 THUMB( "1: "ins" %1, [%2]\n" ) \
3619@@ -310,6 +317,7 @@ union offset_union {
3620 " .popsection\n" \
3621 : "=r" (err), "=&r" (v), "=&r" (a) \
3622 : "0" (err), "1" (v), "2" (a)); \
3623+ pax_close_userland(); \
3624 if (err) \
3625 goto fault; \
3626 } while (0)
3627diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3628index 5dbf13f..1a60561 100644
3629--- a/arch/arm/mm/fault.c
3630+++ b/arch/arm/mm/fault.c
3631@@ -25,6 +25,7 @@
3632 #include <asm/system_misc.h>
3633 #include <asm/system_info.h>
3634 #include <asm/tlbflush.h>
3635+#include <asm/sections.h>
3636
3637 #include "fault.h"
3638
3639@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3640 if (fixup_exception(regs))
3641 return;
3642
3643+#ifdef CONFIG_PAX_KERNEXEC
3644+ if ((fsr & FSR_WRITE) &&
3645+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3646+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3647+ {
3648+ if (current->signal->curr_ip)
3649+ 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),
3650+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3651+ else
3652+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3653+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3654+ }
3655+#endif
3656+
3657 /*
3658 * No handler, we'll have to terminate things with extreme prejudice.
3659 */
3660@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3661 }
3662 #endif
3663
3664+#ifdef CONFIG_PAX_PAGEEXEC
3665+ if (fsr & FSR_LNX_PF) {
3666+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3667+ do_group_exit(SIGKILL);
3668+ }
3669+#endif
3670+
3671 tsk->thread.address = addr;
3672 tsk->thread.error_code = fsr;
3673 tsk->thread.trap_no = 14;
3674@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3675 }
3676 #endif /* CONFIG_MMU */
3677
3678+#ifdef CONFIG_PAX_PAGEEXEC
3679+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3680+{
3681+ long i;
3682+
3683+ printk(KERN_ERR "PAX: bytes at PC: ");
3684+ for (i = 0; i < 20; i++) {
3685+ unsigned char c;
3686+ if (get_user(c, (__force unsigned char __user *)pc+i))
3687+ printk(KERN_CONT "?? ");
3688+ else
3689+ printk(KERN_CONT "%02x ", c);
3690+ }
3691+ printk("\n");
3692+
3693+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3694+ for (i = -1; i < 20; i++) {
3695+ unsigned long c;
3696+ if (get_user(c, (__force unsigned long __user *)sp+i))
3697+ printk(KERN_CONT "???????? ");
3698+ else
3699+ printk(KERN_CONT "%08lx ", c);
3700+ }
3701+ printk("\n");
3702+}
3703+#endif
3704+
3705 /*
3706 * First Level Translation Fault Handler
3707 *
3708@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3709 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3710 struct siginfo info;
3711
3712+#ifdef CONFIG_PAX_MEMORY_UDEREF
3713+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3714+ if (current->signal->curr_ip)
3715+ 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),
3716+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3717+ else
3718+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3719+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3720+ goto die;
3721+ }
3722+#endif
3723+
3724 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3725 return;
3726
3727+die:
3728 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3729 inf->name, fsr, addr);
3730
3731@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3732 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3733 struct siginfo info;
3734
3735+ if (user_mode(regs)) {
3736+ if (addr == 0xffff0fe0UL) {
3737+ /*
3738+ * PaX: __kuser_get_tls emulation
3739+ */
3740+ regs->ARM_r0 = current_thread_info()->tp_value;
3741+ regs->ARM_pc = regs->ARM_lr;
3742+ return;
3743+ }
3744+ }
3745+
3746+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3747+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3748+ if (current->signal->curr_ip)
3749+ 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),
3750+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3751+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3752+ else
3753+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3754+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3755+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3756+ goto die;
3757+ }
3758+#endif
3759+
3760+#ifdef CONFIG_PAX_REFCOUNT
3761+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3762+ unsigned int bkpt;
3763+
3764+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3765+ current->thread.error_code = ifsr;
3766+ current->thread.trap_no = 0;
3767+ pax_report_refcount_overflow(regs);
3768+ fixup_exception(regs);
3769+ return;
3770+ }
3771+ }
3772+#endif
3773+
3774 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3775 return;
3776
3777+die:
3778 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3779 inf->name, ifsr, addr);
3780
3781diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3782index cf08bdf..772656c 100644
3783--- a/arch/arm/mm/fault.h
3784+++ b/arch/arm/mm/fault.h
3785@@ -3,6 +3,7 @@
3786
3787 /*
3788 * Fault status register encodings. We steal bit 31 for our own purposes.
3789+ * Set when the FSR value is from an instruction fault.
3790 */
3791 #define FSR_LNX_PF (1 << 31)
3792 #define FSR_WRITE (1 << 11)
3793@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3794 }
3795 #endif
3796
3797+/* valid for LPAE and !LPAE */
3798+static inline int is_xn_fault(unsigned int fsr)
3799+{
3800+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3801+}
3802+
3803+static inline int is_domain_fault(unsigned int fsr)
3804+{
3805+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3806+}
3807+
3808 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3809 unsigned long search_exception_table(unsigned long addr);
3810
3811diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3812index 0ecc43f..190b956 100644
3813--- a/arch/arm/mm/init.c
3814+++ b/arch/arm/mm/init.c
3815@@ -30,6 +30,8 @@
3816 #include <asm/setup.h>
3817 #include <asm/tlb.h>
3818 #include <asm/fixmap.h>
3819+#include <asm/system_info.h>
3820+#include <asm/cp15.h>
3821
3822 #include <asm/mach/arch.h>
3823 #include <asm/mach/map.h>
3824@@ -726,7 +728,46 @@ void free_initmem(void)
3825 {
3826 #ifdef CONFIG_HAVE_TCM
3827 extern char __tcm_start, __tcm_end;
3828+#endif
3829
3830+#ifdef CONFIG_PAX_KERNEXEC
3831+ unsigned long addr;
3832+ pgd_t *pgd;
3833+ pud_t *pud;
3834+ pmd_t *pmd;
3835+ int cpu_arch = cpu_architecture();
3836+ unsigned int cr = get_cr();
3837+
3838+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3839+ /* make pages tables, etc before .text NX */
3840+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3841+ pgd = pgd_offset_k(addr);
3842+ pud = pud_offset(pgd, addr);
3843+ pmd = pmd_offset(pud, addr);
3844+ __section_update(pmd, addr, PMD_SECT_XN);
3845+ }
3846+ /* make init NX */
3847+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3848+ pgd = pgd_offset_k(addr);
3849+ pud = pud_offset(pgd, addr);
3850+ pmd = pmd_offset(pud, addr);
3851+ __section_update(pmd, addr, PMD_SECT_XN);
3852+ }
3853+ /* make kernel code/rodata RX */
3854+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3855+ pgd = pgd_offset_k(addr);
3856+ pud = pud_offset(pgd, addr);
3857+ pmd = pmd_offset(pud, addr);
3858+#ifdef CONFIG_ARM_LPAE
3859+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3860+#else
3861+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3862+#endif
3863+ }
3864+ }
3865+#endif
3866+
3867+#ifdef CONFIG_HAVE_TCM
3868 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3869 free_reserved_area(&__tcm_start, &__tcm_end, 0, "TCM link");
3870 #endif
3871diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3872index 04d9006..c547d85 100644
3873--- a/arch/arm/mm/ioremap.c
3874+++ b/arch/arm/mm/ioremap.c
3875@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3876 unsigned int mtype;
3877
3878 if (cached)
3879- mtype = MT_MEMORY;
3880+ mtype = MT_MEMORY_RX;
3881 else
3882- mtype = MT_MEMORY_NONCACHED;
3883+ mtype = MT_MEMORY_NONCACHED_RX;
3884
3885 return __arm_ioremap_caller(phys_addr, size, mtype,
3886 __builtin_return_address(0));
3887diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3888index 10062ce..8695745 100644
3889--- a/arch/arm/mm/mmap.c
3890+++ b/arch/arm/mm/mmap.c
3891@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3892 struct vm_area_struct *vma;
3893 int do_align = 0;
3894 int aliasing = cache_is_vipt_aliasing();
3895+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3896 struct vm_unmapped_area_info info;
3897
3898 /*
3899@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3900 if (len > TASK_SIZE)
3901 return -ENOMEM;
3902
3903+#ifdef CONFIG_PAX_RANDMMAP
3904+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3905+#endif
3906+
3907 if (addr) {
3908 if (do_align)
3909 addr = COLOUR_ALIGN(addr, pgoff);
3910@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3911 addr = PAGE_ALIGN(addr);
3912
3913 vma = find_vma(mm, addr);
3914- if (TASK_SIZE - len >= addr &&
3915- (!vma || addr + len <= vma->vm_start))
3916+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3917 return addr;
3918 }
3919
3920@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3921 info.high_limit = TASK_SIZE;
3922 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3923 info.align_offset = pgoff << PAGE_SHIFT;
3924+ info.threadstack_offset = offset;
3925 return vm_unmapped_area(&info);
3926 }
3927
3928@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3929 unsigned long addr = addr0;
3930 int do_align = 0;
3931 int aliasing = cache_is_vipt_aliasing();
3932+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3933 struct vm_unmapped_area_info info;
3934
3935 /*
3936@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3937 return addr;
3938 }
3939
3940+#ifdef CONFIG_PAX_RANDMMAP
3941+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3942+#endif
3943+
3944 /* requesting a specific address */
3945 if (addr) {
3946 if (do_align)
3947@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3948 else
3949 addr = PAGE_ALIGN(addr);
3950 vma = find_vma(mm, addr);
3951- if (TASK_SIZE - len >= addr &&
3952- (!vma || addr + len <= vma->vm_start))
3953+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3954 return addr;
3955 }
3956
3957@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3958 info.high_limit = mm->mmap_base;
3959 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3960 info.align_offset = pgoff << PAGE_SHIFT;
3961+ info.threadstack_offset = offset;
3962 addr = vm_unmapped_area(&info);
3963
3964 /*
3965@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3966 {
3967 unsigned long random_factor = 0UL;
3968
3969+#ifdef CONFIG_PAX_RANDMMAP
3970+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3971+#endif
3972+
3973 /* 8 bits of randomness in 20 address space bits */
3974 if ((current->flags & PF_RANDOMIZE) &&
3975 !(current->personality & ADDR_NO_RANDOMIZE))
3976@@ -180,10 +194,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3977
3978 if (mmap_is_legacy()) {
3979 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3980+
3981+#ifdef CONFIG_PAX_RANDMMAP
3982+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3983+ mm->mmap_base += mm->delta_mmap;
3984+#endif
3985+
3986 mm->get_unmapped_area = arch_get_unmapped_area;
3987 mm->unmap_area = arch_unmap_area;
3988 } else {
3989 mm->mmap_base = mmap_base(random_factor);
3990+
3991+#ifdef CONFIG_PAX_RANDMMAP
3992+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3993+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3994+#endif
3995+
3996 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3997 mm->unmap_area = arch_unmap_area_topdown;
3998 }
3999diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4000index 4d409e6..f375351 100644
4001--- a/arch/arm/mm/mmu.c
4002+++ b/arch/arm/mm/mmu.c
4003@@ -36,6 +36,22 @@
4004 #include "mm.h"
4005 #include "tcm.h"
4006
4007+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4008+void modify_domain(unsigned int dom, unsigned int type)
4009+{
4010+ struct thread_info *thread = current_thread_info();
4011+ unsigned int domain = thread->cpu_domain;
4012+ /*
4013+ * DOMAIN_MANAGER might be defined to some other value,
4014+ * use the arch-defined constant
4015+ */
4016+ domain &= ~domain_val(dom, 3);
4017+ thread->cpu_domain = domain | domain_val(dom, type);
4018+ set_domain(thread->cpu_domain);
4019+}
4020+EXPORT_SYMBOL(modify_domain);
4021+#endif
4022+
4023 /*
4024 * empty_zero_page is a special page that is used for
4025 * zero-initialized data and COW.
4026@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4027
4028 #endif /* ifdef CONFIG_CPU_CP15 / else */
4029
4030-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4031+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4032 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4033
4034-static struct mem_type mem_types[] = {
4035+#ifdef CONFIG_PAX_KERNEXEC
4036+#define L_PTE_KERNEXEC L_PTE_RDONLY
4037+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4038+#else
4039+#define L_PTE_KERNEXEC L_PTE_DIRTY
4040+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4041+#endif
4042+
4043+static struct mem_type mem_types[] __read_only = {
4044 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4045 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4046 L_PTE_SHARED,
4047@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4048 [MT_UNCACHED] = {
4049 .prot_pte = PROT_PTE_DEVICE,
4050 .prot_l1 = PMD_TYPE_TABLE,
4051- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4052+ .prot_sect = PROT_SECT_DEVICE,
4053 .domain = DOMAIN_IO,
4054 },
4055 [MT_CACHECLEAN] = {
4056- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4057+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4058 .domain = DOMAIN_KERNEL,
4059 },
4060 #ifndef CONFIG_ARM_LPAE
4061 [MT_MINICLEAN] = {
4062- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4063+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4064 .domain = DOMAIN_KERNEL,
4065 },
4066 #endif
4067@@ -277,36 +301,65 @@ static struct mem_type mem_types[] = {
4068 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4069 L_PTE_RDONLY,
4070 .prot_l1 = PMD_TYPE_TABLE,
4071- .domain = DOMAIN_USER,
4072+ .domain = DOMAIN_VECTORS,
4073 },
4074 [MT_HIGH_VECTORS] = {
4075- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4076- L_PTE_USER | L_PTE_RDONLY,
4077+ /* we always want the vector page to be noaccess for userland on archs with
4078+ XN where we can enforce some reasonable measure of security
4079+ therefore, when kernexec is disabled, instead of L_PTE_USER | L_PTE_RDONLY
4080+ which turns into supervisor rwx, userland rx, we instead omit that entirely,
4081+ leaving it as supervisor rwx only
4082+ */
4083+#ifdef CONFIG_PAX_KERNEXEC
4084+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_RDONLY,
4085+#elif __LINUX_ARM_ARCH__ >= 6
4086+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4087+#else
4088+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_USER | L_PTE_RDONLY,
4089+#endif
4090 .prot_l1 = PMD_TYPE_TABLE,
4091- .domain = DOMAIN_USER,
4092+ .domain = DOMAIN_VECTORS,
4093 },
4094- [MT_MEMORY] = {
4095+ [MT_MEMORY_RWX] = {
4096 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4097 .prot_l1 = PMD_TYPE_TABLE,
4098 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4099 .domain = DOMAIN_KERNEL,
4100 },
4101+ [MT_MEMORY_RW] = {
4102+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4103+ .prot_l1 = PMD_TYPE_TABLE,
4104+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4105+ .domain = DOMAIN_KERNEL,
4106+ },
4107+ [MT_MEMORY_RX] = {
4108+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4109+ .prot_l1 = PMD_TYPE_TABLE,
4110+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4111+ .domain = DOMAIN_KERNEL,
4112+ },
4113 [MT_ROM] = {
4114- .prot_sect = PMD_TYPE_SECT,
4115+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4116 .domain = DOMAIN_KERNEL,
4117 },
4118- [MT_MEMORY_NONCACHED] = {
4119+ [MT_MEMORY_NONCACHED_RW] = {
4120 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4121 L_PTE_MT_BUFFERABLE,
4122 .prot_l1 = PMD_TYPE_TABLE,
4123 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4124 .domain = DOMAIN_KERNEL,
4125 },
4126+ [MT_MEMORY_NONCACHED_RX] = {
4127+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4128+ L_PTE_MT_BUFFERABLE,
4129+ .prot_l1 = PMD_TYPE_TABLE,
4130+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4131+ .domain = DOMAIN_KERNEL,
4132+ },
4133 [MT_MEMORY_DTCM] = {
4134- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4135- L_PTE_XN,
4136+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4137 .prot_l1 = PMD_TYPE_TABLE,
4138- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4139+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4140 .domain = DOMAIN_KERNEL,
4141 },
4142 [MT_MEMORY_ITCM] = {
4143@@ -316,10 +369,10 @@ static struct mem_type mem_types[] = {
4144 },
4145 [MT_MEMORY_SO] = {
4146 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4147- L_PTE_MT_UNCACHED | L_PTE_XN,
4148+ L_PTE_MT_UNCACHED,
4149 .prot_l1 = PMD_TYPE_TABLE,
4150 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4151- PMD_SECT_UNCACHED | PMD_SECT_XN,
4152+ PMD_SECT_UNCACHED,
4153 .domain = DOMAIN_KERNEL,
4154 },
4155 [MT_MEMORY_DMA_READY] = {
4156@@ -405,9 +458,35 @@ static void __init build_mem_type_table(void)
4157 * to prevent speculative instruction fetches.
4158 */
4159 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4160+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4161 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4162+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4163 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4164+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4165 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4166+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4167+
4168+ /* Mark other regions on ARMv6+ as execute-never */
4169+
4170+#ifdef CONFIG_PAX_KERNEXEC
4171+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4172+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4173+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4174+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4175+#ifndef CONFIG_ARM_LPAE
4176+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4177+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4178+#endif
4179+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4180+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4181+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4182+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4183+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4184+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4185+#endif
4186+
4187+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4188+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4189 }
4190 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4191 /*
4192@@ -468,6 +547,9 @@ static void __init build_mem_type_table(void)
4193 * from SVC mode and no access from userspace.
4194 */
4195 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4196+#ifdef CONFIG_PAX_KERNEXEC
4197+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4198+#endif
4199 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4200 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4201 #endif
4202@@ -485,11 +567,17 @@ static void __init build_mem_type_table(void)
4203 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4204 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4205 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4206- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4207- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4208+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4209+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4210+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4211+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4212+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4213+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4214 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4215- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4216- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4217+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4218+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4219+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4220+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4221 }
4222 }
4223
4224@@ -500,15 +588,20 @@ static void __init build_mem_type_table(void)
4225 if (cpu_arch >= CPU_ARCH_ARMv6) {
4226 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4227 /* Non-cacheable Normal is XCB = 001 */
4228- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4229+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4230+ PMD_SECT_BUFFERED;
4231+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4232 PMD_SECT_BUFFERED;
4233 } else {
4234 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4235- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4236+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4237+ PMD_SECT_TEX(1);
4238+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4239 PMD_SECT_TEX(1);
4240 }
4241 } else {
4242- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4243+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4244+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4245 }
4246
4247 #ifdef CONFIG_ARM_LPAE
4248@@ -524,6 +617,8 @@ static void __init build_mem_type_table(void)
4249 vecs_pgprot |= PTE_EXT_AF;
4250 #endif
4251
4252+ user_pgprot |= __supported_pte_mask;
4253+
4254 for (i = 0; i < 16; i++) {
4255 pteval_t v = pgprot_val(protection_map[i]);
4256 protection_map[i] = __pgprot(v | user_pgprot);
4257@@ -541,10 +636,15 @@ static void __init build_mem_type_table(void)
4258
4259 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4260 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4261- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4262- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4263+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4264+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4265+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4266+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4267+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4268+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4269 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4270- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4271+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4272+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4273 mem_types[MT_ROM].prot_sect |= cp->pmd;
4274
4275 switch (cp->pmd) {
4276@@ -1166,18 +1266,15 @@ void __init arm_mm_memblock_reserve(void)
4277 * called function. This means you can't use any function or debugging
4278 * method which may touch any device, otherwise the kernel _will_ crash.
4279 */
4280+
4281+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4282+
4283 static void __init devicemaps_init(struct machine_desc *mdesc)
4284 {
4285 struct map_desc map;
4286 unsigned long addr;
4287- void *vectors;
4288
4289- /*
4290- * Allocate the vector page early.
4291- */
4292- vectors = early_alloc(PAGE_SIZE);
4293-
4294- early_trap_init(vectors);
4295+ early_trap_init(&vectors);
4296
4297 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4298 pmd_clear(pmd_off_k(addr));
4299@@ -1217,7 +1314,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4300 * location (0xffff0000). If we aren't using high-vectors, also
4301 * create a mapping at the low-vectors virtual address.
4302 */
4303- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4304+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4305 map.virtual = 0xffff0000;
4306 map.length = PAGE_SIZE;
4307 map.type = MT_HIGH_VECTORS;
4308@@ -1275,8 +1372,39 @@ static void __init map_lowmem(void)
4309 map.pfn = __phys_to_pfn(start);
4310 map.virtual = __phys_to_virt(start);
4311 map.length = end - start;
4312- map.type = MT_MEMORY;
4313
4314+#ifdef CONFIG_PAX_KERNEXEC
4315+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4316+ struct map_desc kernel;
4317+ struct map_desc initmap;
4318+
4319+ /* when freeing initmem we will make this RW */
4320+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4321+ initmap.virtual = (unsigned long)__init_begin;
4322+ initmap.length = _sdata - __init_begin;
4323+ initmap.type = MT_MEMORY_RWX;
4324+ create_mapping(&initmap);
4325+
4326+ /* when freeing initmem we will make this RX */
4327+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4328+ kernel.virtual = (unsigned long)_stext;
4329+ kernel.length = __init_begin - _stext;
4330+ kernel.type = MT_MEMORY_RWX;
4331+ create_mapping(&kernel);
4332+
4333+ if (map.virtual < (unsigned long)_stext) {
4334+ map.length = (unsigned long)_stext - map.virtual;
4335+ map.type = MT_MEMORY_RWX;
4336+ create_mapping(&map);
4337+ }
4338+
4339+ map.pfn = __phys_to_pfn(__pa(_sdata));
4340+ map.virtual = (unsigned long)_sdata;
4341+ map.length = end - __pa(_sdata);
4342+ }
4343+#endif
4344+
4345+ map.type = MT_MEMORY_RW;
4346 create_mapping(&map);
4347 }
4348 }
4349diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4350index 9704097..3e36dde 100644
4351--- a/arch/arm/mm/proc-v7-2level.S
4352+++ b/arch/arm/mm/proc-v7-2level.S
4353@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4354 tst r1, #L_PTE_XN
4355 orrne r3, r3, #PTE_EXT_XN
4356
4357+ tst r1, #L_PTE_PXN
4358+ orrne r3, r3, #PTE_EXT_PXN
4359+
4360 tst r1, #L_PTE_YOUNG
4361 tstne r1, #L_PTE_VALID
4362 #ifndef CONFIG_CPU_USE_DOMAINS
4363diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4364index a5bc92d..0bb4730 100644
4365--- a/arch/arm/plat-omap/sram.c
4366+++ b/arch/arm/plat-omap/sram.c
4367@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4368 * Looks like we need to preserve some bootloader code at the
4369 * beginning of SRAM for jumping to flash for reboot to work...
4370 */
4371+ pax_open_kernel();
4372 memset_io(omap_sram_base + omap_sram_skip, 0,
4373 omap_sram_size - omap_sram_skip);
4374+ pax_close_kernel();
4375 }
4376diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4377index ce6d763..cfea917 100644
4378--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4379+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4380@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4381 int (*started)(unsigned ch);
4382 int (*flush)(unsigned ch);
4383 int (*stop)(unsigned ch);
4384-};
4385+} __no_const;
4386
4387 extern void *samsung_dmadev_get_ops(void);
4388 extern void *s3c_dma_get_ops(void);
4389diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4390index f4726dc..39ed646 100644
4391--- a/arch/arm64/kernel/debug-monitors.c
4392+++ b/arch/arm64/kernel/debug-monitors.c
4393@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4394 return NOTIFY_OK;
4395 }
4396
4397-static struct notifier_block __cpuinitdata os_lock_nb = {
4398+static struct notifier_block os_lock_nb = {
4399 .notifier_call = os_lock_notify,
4400 };
4401
4402diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4403index 5ab825c..96aaec8 100644
4404--- a/arch/arm64/kernel/hw_breakpoint.c
4405+++ b/arch/arm64/kernel/hw_breakpoint.c
4406@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4407 return NOTIFY_OK;
4408 }
4409
4410-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4411+static struct notifier_block hw_breakpoint_reset_nb = {
4412 .notifier_call = hw_breakpoint_reset_notify,
4413 };
4414
4415diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4416index c3a58a1..78fbf54 100644
4417--- a/arch/avr32/include/asm/cache.h
4418+++ b/arch/avr32/include/asm/cache.h
4419@@ -1,8 +1,10 @@
4420 #ifndef __ASM_AVR32_CACHE_H
4421 #define __ASM_AVR32_CACHE_H
4422
4423+#include <linux/const.h>
4424+
4425 #define L1_CACHE_SHIFT 5
4426-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4427+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4428
4429 /*
4430 * Memory returned by kmalloc() may be used for DMA, so we must make
4431diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4432index d232888..87c8df1 100644
4433--- a/arch/avr32/include/asm/elf.h
4434+++ b/arch/avr32/include/asm/elf.h
4435@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4436 the loader. We need to make sure that it is out of the way of the program
4437 that it will "exec", and that there is sufficient room for the brk. */
4438
4439-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4440+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4441
4442+#ifdef CONFIG_PAX_ASLR
4443+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4444+
4445+#define PAX_DELTA_MMAP_LEN 15
4446+#define PAX_DELTA_STACK_LEN 15
4447+#endif
4448
4449 /* This yields a mask that user programs can use to figure out what
4450 instruction set this CPU supports. This could be done in user space,
4451diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4452index 479330b..53717a8 100644
4453--- a/arch/avr32/include/asm/kmap_types.h
4454+++ b/arch/avr32/include/asm/kmap_types.h
4455@@ -2,9 +2,9 @@
4456 #define __ASM_AVR32_KMAP_TYPES_H
4457
4458 #ifdef CONFIG_DEBUG_HIGHMEM
4459-# define KM_TYPE_NR 29
4460+# define KM_TYPE_NR 30
4461 #else
4462-# define KM_TYPE_NR 14
4463+# define KM_TYPE_NR 15
4464 #endif
4465
4466 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4467diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4468index b2f2d2d..d1c85cb 100644
4469--- a/arch/avr32/mm/fault.c
4470+++ b/arch/avr32/mm/fault.c
4471@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4472
4473 int exception_trace = 1;
4474
4475+#ifdef CONFIG_PAX_PAGEEXEC
4476+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4477+{
4478+ unsigned long i;
4479+
4480+ printk(KERN_ERR "PAX: bytes at PC: ");
4481+ for (i = 0; i < 20; i++) {
4482+ unsigned char c;
4483+ if (get_user(c, (unsigned char *)pc+i))
4484+ printk(KERN_CONT "???????? ");
4485+ else
4486+ printk(KERN_CONT "%02x ", c);
4487+ }
4488+ printk("\n");
4489+}
4490+#endif
4491+
4492 /*
4493 * This routine handles page faults. It determines the address and the
4494 * problem, and then passes it off to one of the appropriate routines.
4495@@ -174,6 +191,16 @@ bad_area:
4496 up_read(&mm->mmap_sem);
4497
4498 if (user_mode(regs)) {
4499+
4500+#ifdef CONFIG_PAX_PAGEEXEC
4501+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4502+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4503+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4504+ do_group_exit(SIGKILL);
4505+ }
4506+ }
4507+#endif
4508+
4509 if (exception_trace && printk_ratelimit())
4510 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4511 "sp %08lx ecr %lu\n",
4512diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4513index 568885a..f8008df 100644
4514--- a/arch/blackfin/include/asm/cache.h
4515+++ b/arch/blackfin/include/asm/cache.h
4516@@ -7,6 +7,7 @@
4517 #ifndef __ARCH_BLACKFIN_CACHE_H
4518 #define __ARCH_BLACKFIN_CACHE_H
4519
4520+#include <linux/const.h>
4521 #include <linux/linkage.h> /* for asmlinkage */
4522
4523 /*
4524@@ -14,7 +15,7 @@
4525 * Blackfin loads 32 bytes for cache
4526 */
4527 #define L1_CACHE_SHIFT 5
4528-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4529+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4530 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4531
4532 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4533diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4534index aea2718..3639a60 100644
4535--- a/arch/cris/include/arch-v10/arch/cache.h
4536+++ b/arch/cris/include/arch-v10/arch/cache.h
4537@@ -1,8 +1,9 @@
4538 #ifndef _ASM_ARCH_CACHE_H
4539 #define _ASM_ARCH_CACHE_H
4540
4541+#include <linux/const.h>
4542 /* Etrax 100LX have 32-byte cache-lines. */
4543-#define L1_CACHE_BYTES 32
4544 #define L1_CACHE_SHIFT 5
4545+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4546
4547 #endif /* _ASM_ARCH_CACHE_H */
4548diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4549index 7caf25d..ee65ac5 100644
4550--- a/arch/cris/include/arch-v32/arch/cache.h
4551+++ b/arch/cris/include/arch-v32/arch/cache.h
4552@@ -1,11 +1,12 @@
4553 #ifndef _ASM_CRIS_ARCH_CACHE_H
4554 #define _ASM_CRIS_ARCH_CACHE_H
4555
4556+#include <linux/const.h>
4557 #include <arch/hwregs/dma.h>
4558
4559 /* A cache-line is 32 bytes. */
4560-#define L1_CACHE_BYTES 32
4561 #define L1_CACHE_SHIFT 5
4562+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4563
4564 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4565
4566diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4567index b86329d..6709906 100644
4568--- a/arch/frv/include/asm/atomic.h
4569+++ b/arch/frv/include/asm/atomic.h
4570@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4571 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4572 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4573
4574+#define atomic64_read_unchecked(v) atomic64_read(v)
4575+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4576+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4577+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4578+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4579+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4580+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4581+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4582+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4583+
4584 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4585 {
4586 int c, old;
4587diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4588index 2797163..c2a401d 100644
4589--- a/arch/frv/include/asm/cache.h
4590+++ b/arch/frv/include/asm/cache.h
4591@@ -12,10 +12,11 @@
4592 #ifndef __ASM_CACHE_H
4593 #define __ASM_CACHE_H
4594
4595+#include <linux/const.h>
4596
4597 /* bytes per L1 cache line */
4598 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4599-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4600+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4601
4602 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4603 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4604diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4605index 43901f2..0d8b865 100644
4606--- a/arch/frv/include/asm/kmap_types.h
4607+++ b/arch/frv/include/asm/kmap_types.h
4608@@ -2,6 +2,6 @@
4609 #ifndef _ASM_KMAP_TYPES_H
4610 #define _ASM_KMAP_TYPES_H
4611
4612-#define KM_TYPE_NR 17
4613+#define KM_TYPE_NR 18
4614
4615 #endif
4616diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4617index 836f147..4cf23f5 100644
4618--- a/arch/frv/mm/elf-fdpic.c
4619+++ b/arch/frv/mm/elf-fdpic.c
4620@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4621 {
4622 struct vm_area_struct *vma;
4623 struct vm_unmapped_area_info info;
4624+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4625
4626 if (len > TASK_SIZE)
4627 return -ENOMEM;
4628@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4629 if (addr) {
4630 addr = PAGE_ALIGN(addr);
4631 vma = find_vma(current->mm, addr);
4632- if (TASK_SIZE - len >= addr &&
4633- (!vma || addr + len <= vma->vm_start))
4634+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4635 goto success;
4636 }
4637
4638@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4639 info.high_limit = (current->mm->start_stack - 0x00200000);
4640 info.align_mask = 0;
4641 info.align_offset = 0;
4642+ info.threadstack_offset = offset;
4643 addr = vm_unmapped_area(&info);
4644 if (!(addr & ~PAGE_MASK))
4645 goto success;
4646diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4647index f4ca594..adc72fd6 100644
4648--- a/arch/hexagon/include/asm/cache.h
4649+++ b/arch/hexagon/include/asm/cache.h
4650@@ -21,9 +21,11 @@
4651 #ifndef __ASM_CACHE_H
4652 #define __ASM_CACHE_H
4653
4654+#include <linux/const.h>
4655+
4656 /* Bytes per L1 cache line */
4657-#define L1_CACHE_SHIFT (5)
4658-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4659+#define L1_CACHE_SHIFT 5
4660+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4661
4662 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4663 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4664diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4665index 6e6fe18..a6ae668 100644
4666--- a/arch/ia64/include/asm/atomic.h
4667+++ b/arch/ia64/include/asm/atomic.h
4668@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4669 #define atomic64_inc(v) atomic64_add(1, (v))
4670 #define atomic64_dec(v) atomic64_sub(1, (v))
4671
4672+#define atomic64_read_unchecked(v) atomic64_read(v)
4673+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4674+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4675+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4676+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4677+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4678+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4679+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4680+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4681+
4682 /* Atomic operations are already serializing */
4683 #define smp_mb__before_atomic_dec() barrier()
4684 #define smp_mb__after_atomic_dec() barrier()
4685diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4686index 988254a..e1ee885 100644
4687--- a/arch/ia64/include/asm/cache.h
4688+++ b/arch/ia64/include/asm/cache.h
4689@@ -1,6 +1,7 @@
4690 #ifndef _ASM_IA64_CACHE_H
4691 #define _ASM_IA64_CACHE_H
4692
4693+#include <linux/const.h>
4694
4695 /*
4696 * Copyright (C) 1998-2000 Hewlett-Packard Co
4697@@ -9,7 +10,7 @@
4698
4699 /* Bytes per L1 (data) cache line. */
4700 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4701-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4702+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4703
4704 #ifdef CONFIG_SMP
4705 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4706diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4707index 5a83c5c..4d7f553 100644
4708--- a/arch/ia64/include/asm/elf.h
4709+++ b/arch/ia64/include/asm/elf.h
4710@@ -42,6 +42,13 @@
4711 */
4712 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4713
4714+#ifdef CONFIG_PAX_ASLR
4715+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4716+
4717+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4718+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4719+#endif
4720+
4721 #define PT_IA_64_UNWIND 0x70000001
4722
4723 /* IA-64 relocations: */
4724diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4725index 96a8d92..617a1cf 100644
4726--- a/arch/ia64/include/asm/pgalloc.h
4727+++ b/arch/ia64/include/asm/pgalloc.h
4728@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4729 pgd_val(*pgd_entry) = __pa(pud);
4730 }
4731
4732+static inline void
4733+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4734+{
4735+ pgd_populate(mm, pgd_entry, pud);
4736+}
4737+
4738 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4739 {
4740 return quicklist_alloc(0, GFP_KERNEL, NULL);
4741@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4742 pud_val(*pud_entry) = __pa(pmd);
4743 }
4744
4745+static inline void
4746+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4747+{
4748+ pud_populate(mm, pud_entry, pmd);
4749+}
4750+
4751 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4752 {
4753 return quicklist_alloc(0, GFP_KERNEL, NULL);
4754diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4755index 815810c..d60bd4c 100644
4756--- a/arch/ia64/include/asm/pgtable.h
4757+++ b/arch/ia64/include/asm/pgtable.h
4758@@ -12,7 +12,7 @@
4759 * David Mosberger-Tang <davidm@hpl.hp.com>
4760 */
4761
4762-
4763+#include <linux/const.h>
4764 #include <asm/mman.h>
4765 #include <asm/page.h>
4766 #include <asm/processor.h>
4767@@ -142,6 +142,17 @@
4768 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4769 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4770 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4771+
4772+#ifdef CONFIG_PAX_PAGEEXEC
4773+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4774+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4775+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4776+#else
4777+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4778+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4779+# define PAGE_COPY_NOEXEC PAGE_COPY
4780+#endif
4781+
4782 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4783 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4784 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4785diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4786index 54ff557..70c88b7 100644
4787--- a/arch/ia64/include/asm/spinlock.h
4788+++ b/arch/ia64/include/asm/spinlock.h
4789@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4790 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4791
4792 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4793- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4794+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4795 }
4796
4797 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4798diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4799index 449c8c0..18965fb 100644
4800--- a/arch/ia64/include/asm/uaccess.h
4801+++ b/arch/ia64/include/asm/uaccess.h
4802@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4803 static inline unsigned long
4804 __copy_to_user (void __user *to, const void *from, unsigned long count)
4805 {
4806+ if (count > INT_MAX)
4807+ return count;
4808+
4809+ if (!__builtin_constant_p(count))
4810+ check_object_size(from, count, true);
4811+
4812 return __copy_user(to, (__force void __user *) from, count);
4813 }
4814
4815 static inline unsigned long
4816 __copy_from_user (void *to, const void __user *from, unsigned long count)
4817 {
4818+ if (count > INT_MAX)
4819+ return count;
4820+
4821+ if (!__builtin_constant_p(count))
4822+ check_object_size(to, count, false);
4823+
4824 return __copy_user((__force void __user *) to, from, count);
4825 }
4826
4827@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4828 ({ \
4829 void __user *__cu_to = (to); \
4830 const void *__cu_from = (from); \
4831- long __cu_len = (n); \
4832+ unsigned long __cu_len = (n); \
4833 \
4834- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4835+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4836+ if (!__builtin_constant_p(n)) \
4837+ check_object_size(__cu_from, __cu_len, true); \
4838 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4839+ } \
4840 __cu_len; \
4841 })
4842
4843@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4844 ({ \
4845 void *__cu_to = (to); \
4846 const void __user *__cu_from = (from); \
4847- long __cu_len = (n); \
4848+ unsigned long __cu_len = (n); \
4849 \
4850 __chk_user_ptr(__cu_from); \
4851- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4852+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4853+ if (!__builtin_constant_p(n)) \
4854+ check_object_size(__cu_to, __cu_len, false); \
4855 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4856+ } \
4857 __cu_len; \
4858 })
4859
4860diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4861index 2d67317..07d8bfa 100644
4862--- a/arch/ia64/kernel/err_inject.c
4863+++ b/arch/ia64/kernel/err_inject.c
4864@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4865 return NOTIFY_OK;
4866 }
4867
4868-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4869+static struct notifier_block err_inject_cpu_notifier =
4870 {
4871 .notifier_call = err_inject_cpu_callback,
4872 };
4873diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4874index d7396db..b33e873 100644
4875--- a/arch/ia64/kernel/mca.c
4876+++ b/arch/ia64/kernel/mca.c
4877@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4878 return NOTIFY_OK;
4879 }
4880
4881-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4882+static struct notifier_block mca_cpu_notifier = {
4883 .notifier_call = mca_cpu_callback
4884 };
4885
4886diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4887index 24603be..948052d 100644
4888--- a/arch/ia64/kernel/module.c
4889+++ b/arch/ia64/kernel/module.c
4890@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4891 void
4892 module_free (struct module *mod, void *module_region)
4893 {
4894- if (mod && mod->arch.init_unw_table &&
4895- module_region == mod->module_init) {
4896+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4897 unw_remove_unwind_table(mod->arch.init_unw_table);
4898 mod->arch.init_unw_table = NULL;
4899 }
4900@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4901 }
4902
4903 static inline int
4904+in_init_rx (const struct module *mod, uint64_t addr)
4905+{
4906+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4907+}
4908+
4909+static inline int
4910+in_init_rw (const struct module *mod, uint64_t addr)
4911+{
4912+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4913+}
4914+
4915+static inline int
4916 in_init (const struct module *mod, uint64_t addr)
4917 {
4918- return addr - (uint64_t) mod->module_init < mod->init_size;
4919+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4920+}
4921+
4922+static inline int
4923+in_core_rx (const struct module *mod, uint64_t addr)
4924+{
4925+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4926+}
4927+
4928+static inline int
4929+in_core_rw (const struct module *mod, uint64_t addr)
4930+{
4931+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4932 }
4933
4934 static inline int
4935 in_core (const struct module *mod, uint64_t addr)
4936 {
4937- return addr - (uint64_t) mod->module_core < mod->core_size;
4938+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4939 }
4940
4941 static inline int
4942@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4943 break;
4944
4945 case RV_BDREL:
4946- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4947+ if (in_init_rx(mod, val))
4948+ val -= (uint64_t) mod->module_init_rx;
4949+ else if (in_init_rw(mod, val))
4950+ val -= (uint64_t) mod->module_init_rw;
4951+ else if (in_core_rx(mod, val))
4952+ val -= (uint64_t) mod->module_core_rx;
4953+ else if (in_core_rw(mod, val))
4954+ val -= (uint64_t) mod->module_core_rw;
4955 break;
4956
4957 case RV_LTV:
4958@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4959 * addresses have been selected...
4960 */
4961 uint64_t gp;
4962- if (mod->core_size > MAX_LTOFF)
4963+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4964 /*
4965 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4966 * at the end of the module.
4967 */
4968- gp = mod->core_size - MAX_LTOFF / 2;
4969+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4970 else
4971- gp = mod->core_size / 2;
4972- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4973+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4974+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4975 mod->arch.gp = gp;
4976 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4977 }
4978diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4979index 2b3c2d7..a318d84 100644
4980--- a/arch/ia64/kernel/palinfo.c
4981+++ b/arch/ia64/kernel/palinfo.c
4982@@ -980,7 +980,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4983 return NOTIFY_OK;
4984 }
4985
4986-static struct notifier_block __refdata palinfo_cpu_notifier =
4987+static struct notifier_block palinfo_cpu_notifier =
4988 {
4989 .notifier_call = palinfo_cpu_callback,
4990 .priority = 0,
4991diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4992index 4bc580a..7767f24 100644
4993--- a/arch/ia64/kernel/salinfo.c
4994+++ b/arch/ia64/kernel/salinfo.c
4995@@ -609,7 +609,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4996 return NOTIFY_OK;
4997 }
4998
4999-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
5000+static struct notifier_block salinfo_cpu_notifier =
5001 {
5002 .notifier_call = salinfo_cpu_callback,
5003 .priority = 0,
5004diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5005index 41e33f8..65180b2 100644
5006--- a/arch/ia64/kernel/sys_ia64.c
5007+++ b/arch/ia64/kernel/sys_ia64.c
5008@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5009 unsigned long align_mask = 0;
5010 struct mm_struct *mm = current->mm;
5011 struct vm_unmapped_area_info info;
5012+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5013
5014 if (len > RGN_MAP_LIMIT)
5015 return -ENOMEM;
5016@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5017 if (REGION_NUMBER(addr) == RGN_HPAGE)
5018 addr = 0;
5019 #endif
5020+
5021+#ifdef CONFIG_PAX_RANDMMAP
5022+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5023+ addr = mm->free_area_cache;
5024+ else
5025+#endif
5026+
5027 if (!addr)
5028 addr = TASK_UNMAPPED_BASE;
5029
5030@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5031 info.high_limit = TASK_SIZE;
5032 info.align_mask = align_mask;
5033 info.align_offset = 0;
5034+ info.threadstack_offset = offset;
5035 return vm_unmapped_area(&info);
5036 }
5037
5038diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5039index dc00b2c..cce53c2 100644
5040--- a/arch/ia64/kernel/topology.c
5041+++ b/arch/ia64/kernel/topology.c
5042@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5043 return NOTIFY_OK;
5044 }
5045
5046-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5047+static struct notifier_block cache_cpu_notifier =
5048 {
5049 .notifier_call = cache_cpu_callback
5050 };
5051diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5052index 0ccb28f..8992469 100644
5053--- a/arch/ia64/kernel/vmlinux.lds.S
5054+++ b/arch/ia64/kernel/vmlinux.lds.S
5055@@ -198,7 +198,7 @@ SECTIONS {
5056 /* Per-cpu data: */
5057 . = ALIGN(PERCPU_PAGE_SIZE);
5058 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5059- __phys_per_cpu_start = __per_cpu_load;
5060+ __phys_per_cpu_start = per_cpu_load;
5061 /*
5062 * ensure percpu data fits
5063 * into percpu page size
5064diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5065index 6cf0341..d352594 100644
5066--- a/arch/ia64/mm/fault.c
5067+++ b/arch/ia64/mm/fault.c
5068@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5069 return pte_present(pte);
5070 }
5071
5072+#ifdef CONFIG_PAX_PAGEEXEC
5073+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5074+{
5075+ unsigned long i;
5076+
5077+ printk(KERN_ERR "PAX: bytes at PC: ");
5078+ for (i = 0; i < 8; i++) {
5079+ unsigned int c;
5080+ if (get_user(c, (unsigned int *)pc+i))
5081+ printk(KERN_CONT "???????? ");
5082+ else
5083+ printk(KERN_CONT "%08x ", c);
5084+ }
5085+ printk("\n");
5086+}
5087+#endif
5088+
5089 # define VM_READ_BIT 0
5090 # define VM_WRITE_BIT 1
5091 # define VM_EXEC_BIT 2
5092@@ -149,8 +166,21 @@ retry:
5093 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5094 goto bad_area;
5095
5096- if ((vma->vm_flags & mask) != mask)
5097+ if ((vma->vm_flags & mask) != mask) {
5098+
5099+#ifdef CONFIG_PAX_PAGEEXEC
5100+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5101+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5102+ goto bad_area;
5103+
5104+ up_read(&mm->mmap_sem);
5105+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5106+ do_group_exit(SIGKILL);
5107+ }
5108+#endif
5109+
5110 goto bad_area;
5111+ }
5112
5113 /*
5114 * If for any reason at all we couldn't handle the fault, make
5115diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5116index 76069c1..c2aa816 100644
5117--- a/arch/ia64/mm/hugetlbpage.c
5118+++ b/arch/ia64/mm/hugetlbpage.c
5119@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5120 unsigned long pgoff, unsigned long flags)
5121 {
5122 struct vm_unmapped_area_info info;
5123+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5124
5125 if (len > RGN_MAP_LIMIT)
5126 return -ENOMEM;
5127@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5128 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5129 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5130 info.align_offset = 0;
5131+ info.threadstack_offset = offset;
5132 return vm_unmapped_area(&info);
5133 }
5134
5135diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5136index d1fe4b4..2628f37 100644
5137--- a/arch/ia64/mm/init.c
5138+++ b/arch/ia64/mm/init.c
5139@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5140 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5141 vma->vm_end = vma->vm_start + PAGE_SIZE;
5142 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5143+
5144+#ifdef CONFIG_PAX_PAGEEXEC
5145+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5146+ vma->vm_flags &= ~VM_EXEC;
5147+
5148+#ifdef CONFIG_PAX_MPROTECT
5149+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5150+ vma->vm_flags &= ~VM_MAYEXEC;
5151+#endif
5152+
5153+ }
5154+#endif
5155+
5156 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5157 down_write(&current->mm->mmap_sem);
5158 if (insert_vm_struct(current->mm, vma)) {
5159diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5160index 40b3ee9..8c2c112 100644
5161--- a/arch/m32r/include/asm/cache.h
5162+++ b/arch/m32r/include/asm/cache.h
5163@@ -1,8 +1,10 @@
5164 #ifndef _ASM_M32R_CACHE_H
5165 #define _ASM_M32R_CACHE_H
5166
5167+#include <linux/const.h>
5168+
5169 /* L1 cache line size */
5170 #define L1_CACHE_SHIFT 4
5171-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5172+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5173
5174 #endif /* _ASM_M32R_CACHE_H */
5175diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5176index 82abd15..d95ae5d 100644
5177--- a/arch/m32r/lib/usercopy.c
5178+++ b/arch/m32r/lib/usercopy.c
5179@@ -14,6 +14,9 @@
5180 unsigned long
5181 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5182 {
5183+ if ((long)n < 0)
5184+ return n;
5185+
5186 prefetch(from);
5187 if (access_ok(VERIFY_WRITE, to, n))
5188 __copy_user(to,from,n);
5189@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5190 unsigned long
5191 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5192 {
5193+ if ((long)n < 0)
5194+ return n;
5195+
5196 prefetchw(to);
5197 if (access_ok(VERIFY_READ, from, n))
5198 __copy_user_zeroing(to,from,n);
5199diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5200index 0395c51..5f26031 100644
5201--- a/arch/m68k/include/asm/cache.h
5202+++ b/arch/m68k/include/asm/cache.h
5203@@ -4,9 +4,11 @@
5204 #ifndef __ARCH_M68K_CACHE_H
5205 #define __ARCH_M68K_CACHE_H
5206
5207+#include <linux/const.h>
5208+
5209 /* bytes per L1 cache line */
5210 #define L1_CACHE_SHIFT 4
5211-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5212+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5213
5214 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5215
5216diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5217index 3c52fa6..11b2ad8 100644
5218--- a/arch/metag/mm/hugetlbpage.c
5219+++ b/arch/metag/mm/hugetlbpage.c
5220@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5221 info.high_limit = TASK_SIZE;
5222 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5223 info.align_offset = 0;
5224+ info.threadstack_offset = 0;
5225 return vm_unmapped_area(&info);
5226 }
5227
5228diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5229index 4efe96a..60e8699 100644
5230--- a/arch/microblaze/include/asm/cache.h
5231+++ b/arch/microblaze/include/asm/cache.h
5232@@ -13,11 +13,12 @@
5233 #ifndef _ASM_MICROBLAZE_CACHE_H
5234 #define _ASM_MICROBLAZE_CACHE_H
5235
5236+#include <linux/const.h>
5237 #include <asm/registers.h>
5238
5239 #define L1_CACHE_SHIFT 5
5240 /* word-granular cache in microblaze */
5241-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5242+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5243
5244 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5245
5246diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5247index 08b6079..eb272cf 100644
5248--- a/arch/mips/include/asm/atomic.h
5249+++ b/arch/mips/include/asm/atomic.h
5250@@ -21,6 +21,10 @@
5251 #include <asm/cmpxchg.h>
5252 #include <asm/war.h>
5253
5254+#ifdef CONFIG_GENERIC_ATOMIC64
5255+#include <asm-generic/atomic64.h>
5256+#endif
5257+
5258 #define ATOMIC_INIT(i) { (i) }
5259
5260 /*
5261@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5262 */
5263 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5264
5265+#define atomic64_read_unchecked(v) atomic64_read(v)
5266+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5267+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5268+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5269+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5270+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5271+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5272+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5273+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5274+
5275 #endif /* CONFIG_64BIT */
5276
5277 /*
5278diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5279index b4db69f..8f3b093 100644
5280--- a/arch/mips/include/asm/cache.h
5281+++ b/arch/mips/include/asm/cache.h
5282@@ -9,10 +9,11 @@
5283 #ifndef _ASM_CACHE_H
5284 #define _ASM_CACHE_H
5285
5286+#include <linux/const.h>
5287 #include <kmalloc.h>
5288
5289 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5290-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5291+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5292
5293 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5294 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5295diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5296index cf3ae24..238d22f 100644
5297--- a/arch/mips/include/asm/elf.h
5298+++ b/arch/mips/include/asm/elf.h
5299@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5300 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5301 #endif
5302
5303+#ifdef CONFIG_PAX_ASLR
5304+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5305+
5306+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5307+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5308+#endif
5309+
5310 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5311 struct linux_binprm;
5312 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5313 int uses_interp);
5314
5315-struct mm_struct;
5316-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5317-#define arch_randomize_brk arch_randomize_brk
5318-
5319 #endif /* _ASM_ELF_H */
5320diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5321index c1f6afa..38cc6e9 100644
5322--- a/arch/mips/include/asm/exec.h
5323+++ b/arch/mips/include/asm/exec.h
5324@@ -12,6 +12,6 @@
5325 #ifndef _ASM_EXEC_H
5326 #define _ASM_EXEC_H
5327
5328-extern unsigned long arch_align_stack(unsigned long sp);
5329+#define arch_align_stack(x) ((x) & ~0xfUL)
5330
5331 #endif /* _ASM_EXEC_H */
5332diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5333index f59552f..3abe9b9 100644
5334--- a/arch/mips/include/asm/page.h
5335+++ b/arch/mips/include/asm/page.h
5336@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5337 #ifdef CONFIG_CPU_MIPS32
5338 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5339 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5340- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5341+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5342 #else
5343 typedef struct { unsigned long long pte; } pte_t;
5344 #define pte_val(x) ((x).pte)
5345diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5346index 881d18b..cea38bc 100644
5347--- a/arch/mips/include/asm/pgalloc.h
5348+++ b/arch/mips/include/asm/pgalloc.h
5349@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5350 {
5351 set_pud(pud, __pud((unsigned long)pmd));
5352 }
5353+
5354+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5355+{
5356+ pud_populate(mm, pud, pmd);
5357+}
5358 #endif
5359
5360 /*
5361diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5362index 895320e..bf63e10 100644
5363--- a/arch/mips/include/asm/thread_info.h
5364+++ b/arch/mips/include/asm/thread_info.h
5365@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
5366 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5367 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5368 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5369+/* li takes a 32bit immediate */
5370+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5371 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5372
5373 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5374@@ -130,15 +132,18 @@ static inline struct thread_info *current_thread_info(void)
5375 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5376 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5377 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5378+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5379+
5380+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5381
5382 /* work to do in syscall_trace_leave() */
5383-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5384+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5385
5386 /* work to do on interrupt/exception return */
5387 #define _TIF_WORK_MASK \
5388 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5389 /* work to do on any return to u-space */
5390-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5391+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5392
5393 #endif /* __KERNEL__ */
5394
5395diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5396index 1188e00..41cf144 100644
5397--- a/arch/mips/kernel/binfmt_elfn32.c
5398+++ b/arch/mips/kernel/binfmt_elfn32.c
5399@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5400 #undef ELF_ET_DYN_BASE
5401 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5402
5403+#ifdef CONFIG_PAX_ASLR
5404+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5405+
5406+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5407+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5408+#endif
5409+
5410 #include <asm/processor.h>
5411 #include <linux/module.h>
5412 #include <linux/elfcore.h>
5413diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5414index 202e581..689ca79 100644
5415--- a/arch/mips/kernel/binfmt_elfo32.c
5416+++ b/arch/mips/kernel/binfmt_elfo32.c
5417@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5418 #undef ELF_ET_DYN_BASE
5419 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5420
5421+#ifdef CONFIG_PAX_ASLR
5422+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5423+
5424+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5425+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5426+#endif
5427+
5428 #include <asm/processor.h>
5429
5430 /*
5431diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5432index c6a041d..b3e7318 100644
5433--- a/arch/mips/kernel/process.c
5434+++ b/arch/mips/kernel/process.c
5435@@ -563,15 +563,3 @@ unsigned long get_wchan(struct task_struct *task)
5436 out:
5437 return pc;
5438 }
5439-
5440-/*
5441- * Don't forget that the stack pointer must be aligned on a 8 bytes
5442- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5443- */
5444-unsigned long arch_align_stack(unsigned long sp)
5445-{
5446- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5447- sp -= get_random_int() & ~PAGE_MASK;
5448-
5449- return sp & ALMASK;
5450-}
5451diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5452index 9c6299c..2fb4c22 100644
5453--- a/arch/mips/kernel/ptrace.c
5454+++ b/arch/mips/kernel/ptrace.c
5455@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5456 return arch;
5457 }
5458
5459+#ifdef CONFIG_GRKERNSEC_SETXID
5460+extern void gr_delayed_cred_worker(void);
5461+#endif
5462+
5463 /*
5464 * Notification of system call entry/exit
5465 * - triggered by current->work.syscall_trace
5466@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5467 /* do the secure computing check first */
5468 secure_computing_strict(regs->regs[2]);
5469
5470+#ifdef CONFIG_GRKERNSEC_SETXID
5471+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5472+ gr_delayed_cred_worker();
5473+#endif
5474+
5475 if (!(current->ptrace & PT_PTRACED))
5476 goto out;
5477
5478diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5479index 9b36424..e7f4154 100644
5480--- a/arch/mips/kernel/scall32-o32.S
5481+++ b/arch/mips/kernel/scall32-o32.S
5482@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5483
5484 stack_done:
5485 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5486- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5487+ li t1, _TIF_SYSCALL_WORK
5488 and t0, t1
5489 bnez t0, syscall_trace_entry # -> yes
5490
5491diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5492index 97a5909..59622f8 100644
5493--- a/arch/mips/kernel/scall64-64.S
5494+++ b/arch/mips/kernel/scall64-64.S
5495@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5496
5497 sd a3, PT_R26(sp) # save a3 for syscall restarting
5498
5499- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5500+ li t1, _TIF_SYSCALL_WORK
5501 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5502 and t0, t1, t0
5503 bnez t0, syscall_trace_entry
5504diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5505index edcb659..fb2ab09 100644
5506--- a/arch/mips/kernel/scall64-n32.S
5507+++ b/arch/mips/kernel/scall64-n32.S
5508@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5509
5510 sd a3, PT_R26(sp) # save a3 for syscall restarting
5511
5512- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5513+ li t1, _TIF_SYSCALL_WORK
5514 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5515 and t0, t1, t0
5516 bnez t0, n32_syscall_trace_entry
5517diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5518index 74f485d..47d2c38 100644
5519--- a/arch/mips/kernel/scall64-o32.S
5520+++ b/arch/mips/kernel/scall64-o32.S
5521@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5522 PTR 4b, bad_stack
5523 .previous
5524
5525- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5526+ li t1, _TIF_SYSCALL_WORK
5527 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5528 and t0, t1, t0
5529 bnez t0, trace_a_syscall
5530diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5531index 0fead53..a2c0fb5 100644
5532--- a/arch/mips/mm/fault.c
5533+++ b/arch/mips/mm/fault.c
5534@@ -27,6 +27,23 @@
5535 #include <asm/highmem.h> /* For VMALLOC_END */
5536 #include <linux/kdebug.h>
5537
5538+#ifdef CONFIG_PAX_PAGEEXEC
5539+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5540+{
5541+ unsigned long i;
5542+
5543+ printk(KERN_ERR "PAX: bytes at PC: ");
5544+ for (i = 0; i < 5; i++) {
5545+ unsigned int c;
5546+ if (get_user(c, (unsigned int *)pc+i))
5547+ printk(KERN_CONT "???????? ");
5548+ else
5549+ printk(KERN_CONT "%08x ", c);
5550+ }
5551+ printk("\n");
5552+}
5553+#endif
5554+
5555 /*
5556 * This routine handles page faults. It determines the address,
5557 * and the problem, and then passes it off to one of the appropriate
5558diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5559index 7e5fe27..9656513 100644
5560--- a/arch/mips/mm/mmap.c
5561+++ b/arch/mips/mm/mmap.c
5562@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5563 struct vm_area_struct *vma;
5564 unsigned long addr = addr0;
5565 int do_color_align;
5566+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5567 struct vm_unmapped_area_info info;
5568
5569 if (unlikely(len > TASK_SIZE))
5570@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5571 do_color_align = 1;
5572
5573 /* requesting a specific address */
5574+
5575+#ifdef CONFIG_PAX_RANDMMAP
5576+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5577+#endif
5578+
5579 if (addr) {
5580 if (do_color_align)
5581 addr = COLOUR_ALIGN(addr, pgoff);
5582@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5583 addr = PAGE_ALIGN(addr);
5584
5585 vma = find_vma(mm, addr);
5586- if (TASK_SIZE - len >= addr &&
5587- (!vma || addr + len <= vma->vm_start))
5588+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5589 return addr;
5590 }
5591
5592 info.length = len;
5593 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
5594 info.align_offset = pgoff << PAGE_SHIFT;
5595+ info.threadstack_offset = offset;
5596
5597 if (dir == DOWN) {
5598 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
5599@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5600 {
5601 unsigned long random_factor = 0UL;
5602
5603+#ifdef CONFIG_PAX_RANDMMAP
5604+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5605+#endif
5606+
5607 if (current->flags & PF_RANDOMIZE) {
5608 random_factor = get_random_int();
5609 random_factor = random_factor << PAGE_SHIFT;
5610@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5611
5612 if (mmap_is_legacy()) {
5613 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5614+
5615+#ifdef CONFIG_PAX_RANDMMAP
5616+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5617+ mm->mmap_base += mm->delta_mmap;
5618+#endif
5619+
5620 mm->get_unmapped_area = arch_get_unmapped_area;
5621 mm->unmap_area = arch_unmap_area;
5622 } else {
5623 mm->mmap_base = mmap_base(random_factor);
5624+
5625+#ifdef CONFIG_PAX_RANDMMAP
5626+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5627+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5628+#endif
5629+
5630 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5631 mm->unmap_area = arch_unmap_area_topdown;
5632 }
5633 }
5634
5635-static inline unsigned long brk_rnd(void)
5636-{
5637- unsigned long rnd = get_random_int();
5638-
5639- rnd = rnd << PAGE_SHIFT;
5640- /* 8MB for 32bit, 256MB for 64bit */
5641- if (TASK_IS_32BIT_ADDR)
5642- rnd = rnd & 0x7ffffful;
5643- else
5644- rnd = rnd & 0xffffffful;
5645-
5646- return rnd;
5647-}
5648-
5649-unsigned long arch_randomize_brk(struct mm_struct *mm)
5650-{
5651- unsigned long base = mm->brk;
5652- unsigned long ret;
5653-
5654- ret = PAGE_ALIGN(base + brk_rnd());
5655-
5656- if (ret < mm->brk)
5657- return mm->brk;
5658-
5659- return ret;
5660-}
5661-
5662 int __virt_addr_valid(const volatile void *kaddr)
5663 {
5664 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5665diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5666index 967d144..db12197 100644
5667--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5668+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5669@@ -11,12 +11,14 @@
5670 #ifndef _ASM_PROC_CACHE_H
5671 #define _ASM_PROC_CACHE_H
5672
5673+#include <linux/const.h>
5674+
5675 /* L1 cache */
5676
5677 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5678 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5679-#define L1_CACHE_BYTES 16 /* bytes per entry */
5680 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5681+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5682 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5683
5684 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5685diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5686index bcb5df2..84fabd2 100644
5687--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5688+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5689@@ -16,13 +16,15 @@
5690 #ifndef _ASM_PROC_CACHE_H
5691 #define _ASM_PROC_CACHE_H
5692
5693+#include <linux/const.h>
5694+
5695 /*
5696 * L1 cache
5697 */
5698 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5699 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5700-#define L1_CACHE_BYTES 32 /* bytes per entry */
5701 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5702+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5703 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5704
5705 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5706diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5707index 4ce7a01..449202a 100644
5708--- a/arch/openrisc/include/asm/cache.h
5709+++ b/arch/openrisc/include/asm/cache.h
5710@@ -19,11 +19,13 @@
5711 #ifndef __ASM_OPENRISC_CACHE_H
5712 #define __ASM_OPENRISC_CACHE_H
5713
5714+#include <linux/const.h>
5715+
5716 /* FIXME: How can we replace these with values from the CPU...
5717 * they shouldn't be hard-coded!
5718 */
5719
5720-#define L1_CACHE_BYTES 16
5721 #define L1_CACHE_SHIFT 4
5722+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5723
5724 #endif /* __ASM_OPENRISC_CACHE_H */
5725diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5726index 472886c..00e7df9 100644
5727--- a/arch/parisc/include/asm/atomic.h
5728+++ b/arch/parisc/include/asm/atomic.h
5729@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
5730 return dec;
5731 }
5732
5733+#define atomic64_read_unchecked(v) atomic64_read(v)
5734+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5735+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5736+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5737+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5738+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5739+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5740+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5741+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5742+
5743 #endif /* !CONFIG_64BIT */
5744
5745
5746diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5747index 47f11c7..3420df2 100644
5748--- a/arch/parisc/include/asm/cache.h
5749+++ b/arch/parisc/include/asm/cache.h
5750@@ -5,6 +5,7 @@
5751 #ifndef __ARCH_PARISC_CACHE_H
5752 #define __ARCH_PARISC_CACHE_H
5753
5754+#include <linux/const.h>
5755
5756 /*
5757 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5758@@ -15,13 +16,13 @@
5759 * just ruin performance.
5760 */
5761 #ifdef CONFIG_PA20
5762-#define L1_CACHE_BYTES 64
5763 #define L1_CACHE_SHIFT 6
5764 #else
5765-#define L1_CACHE_BYTES 32
5766 #define L1_CACHE_SHIFT 5
5767 #endif
5768
5769+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5770+
5771 #ifndef __ASSEMBLY__
5772
5773 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5774diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5775index ad2b503..bdf1651 100644
5776--- a/arch/parisc/include/asm/elf.h
5777+++ b/arch/parisc/include/asm/elf.h
5778@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5779
5780 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5781
5782+#ifdef CONFIG_PAX_ASLR
5783+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5784+
5785+#define PAX_DELTA_MMAP_LEN 16
5786+#define PAX_DELTA_STACK_LEN 16
5787+#endif
5788+
5789 /* This yields a mask that user programs can use to figure out what
5790 instruction set this CPU supports. This could be done in user space,
5791 but it's not easy, and we've already done it here. */
5792diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5793index fc987a1..6e068ef 100644
5794--- a/arch/parisc/include/asm/pgalloc.h
5795+++ b/arch/parisc/include/asm/pgalloc.h
5796@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5797 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5798 }
5799
5800+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5801+{
5802+ pgd_populate(mm, pgd, pmd);
5803+}
5804+
5805 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5806 {
5807 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5808@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5809 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5810 #define pmd_free(mm, x) do { } while (0)
5811 #define pgd_populate(mm, pmd, pte) BUG()
5812+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5813
5814 #endif
5815
5816diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5817index 1e40d7f..a3eb445 100644
5818--- a/arch/parisc/include/asm/pgtable.h
5819+++ b/arch/parisc/include/asm/pgtable.h
5820@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5821 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5822 #define PAGE_COPY PAGE_EXECREAD
5823 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5824+
5825+#ifdef CONFIG_PAX_PAGEEXEC
5826+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5827+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5828+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5829+#else
5830+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5831+# define PAGE_COPY_NOEXEC PAGE_COPY
5832+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5833+#endif
5834+
5835 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5836 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5837 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5838diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5839index e0a8235..ce2f1e1 100644
5840--- a/arch/parisc/include/asm/uaccess.h
5841+++ b/arch/parisc/include/asm/uaccess.h
5842@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5843 const void __user *from,
5844 unsigned long n)
5845 {
5846- int sz = __compiletime_object_size(to);
5847+ size_t sz = __compiletime_object_size(to);
5848 int ret = -EFAULT;
5849
5850- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5851+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5852 ret = __copy_from_user(to, from, n);
5853 else
5854 copy_from_user_overflow();
5855diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5856index 2a625fb..9908930 100644
5857--- a/arch/parisc/kernel/module.c
5858+++ b/arch/parisc/kernel/module.c
5859@@ -98,16 +98,38 @@
5860
5861 /* three functions to determine where in the module core
5862 * or init pieces the location is */
5863+static inline int in_init_rx(struct module *me, void *loc)
5864+{
5865+ return (loc >= me->module_init_rx &&
5866+ loc < (me->module_init_rx + me->init_size_rx));
5867+}
5868+
5869+static inline int in_init_rw(struct module *me, void *loc)
5870+{
5871+ return (loc >= me->module_init_rw &&
5872+ loc < (me->module_init_rw + me->init_size_rw));
5873+}
5874+
5875 static inline int in_init(struct module *me, void *loc)
5876 {
5877- return (loc >= me->module_init &&
5878- loc <= (me->module_init + me->init_size));
5879+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5880+}
5881+
5882+static inline int in_core_rx(struct module *me, void *loc)
5883+{
5884+ return (loc >= me->module_core_rx &&
5885+ loc < (me->module_core_rx + me->core_size_rx));
5886+}
5887+
5888+static inline int in_core_rw(struct module *me, void *loc)
5889+{
5890+ return (loc >= me->module_core_rw &&
5891+ loc < (me->module_core_rw + me->core_size_rw));
5892 }
5893
5894 static inline int in_core(struct module *me, void *loc)
5895 {
5896- return (loc >= me->module_core &&
5897- loc <= (me->module_core + me->core_size));
5898+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5899 }
5900
5901 static inline int in_local(struct module *me, void *loc)
5902@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5903 }
5904
5905 /* align things a bit */
5906- me->core_size = ALIGN(me->core_size, 16);
5907- me->arch.got_offset = me->core_size;
5908- me->core_size += gots * sizeof(struct got_entry);
5909+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5910+ me->arch.got_offset = me->core_size_rw;
5911+ me->core_size_rw += gots * sizeof(struct got_entry);
5912
5913- me->core_size = ALIGN(me->core_size, 16);
5914- me->arch.fdesc_offset = me->core_size;
5915- me->core_size += fdescs * sizeof(Elf_Fdesc);
5916+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5917+ me->arch.fdesc_offset = me->core_size_rw;
5918+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5919
5920 me->arch.got_max = gots;
5921 me->arch.fdesc_max = fdescs;
5922@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5923
5924 BUG_ON(value == 0);
5925
5926- got = me->module_core + me->arch.got_offset;
5927+ got = me->module_core_rw + me->arch.got_offset;
5928 for (i = 0; got[i].addr; i++)
5929 if (got[i].addr == value)
5930 goto out;
5931@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5932 #ifdef CONFIG_64BIT
5933 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5934 {
5935- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5936+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5937
5938 if (!value) {
5939 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5940@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5941
5942 /* Create new one */
5943 fdesc->addr = value;
5944- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5945+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5946 return (Elf_Addr)fdesc;
5947 }
5948 #endif /* CONFIG_64BIT */
5949@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5950
5951 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5952 end = table + sechdrs[me->arch.unwind_section].sh_size;
5953- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5954+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5955
5956 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5957 me->arch.unwind_section, table, end, gp);
5958diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5959index 5dfd248..64914ac 100644
5960--- a/arch/parisc/kernel/sys_parisc.c
5961+++ b/arch/parisc/kernel/sys_parisc.c
5962@@ -33,9 +33,11 @@
5963 #include <linux/utsname.h>
5964 #include <linux/personality.h>
5965
5966-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5967+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5968+ unsigned long flags)
5969 {
5970 struct vm_unmapped_area_info info;
5971+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5972
5973 info.flags = 0;
5974 info.length = len;
5975@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5976 info.high_limit = TASK_SIZE;
5977 info.align_mask = 0;
5978 info.align_offset = 0;
5979+ info.threadstack_offset = offset;
5980 return vm_unmapped_area(&info);
5981 }
5982
5983@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
5984 return (unsigned long) mapping >> 8;
5985 }
5986
5987-static unsigned long get_shared_area(struct address_space *mapping,
5988- unsigned long addr, unsigned long len, unsigned long pgoff)
5989+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5990+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5991 {
5992 struct vm_unmapped_area_info info;
5993+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5994
5995 info.flags = 0;
5996 info.length = len;
5997@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5998 info.high_limit = TASK_SIZE;
5999 info.align_mask = PAGE_MASK & (SHMLBA - 1);
6000 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
6001+ info.threadstack_offset = offset;
6002 return vm_unmapped_area(&info);
6003 }
6004
6005@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6006 return -EINVAL;
6007 return addr;
6008 }
6009- if (!addr)
6010+ if (!addr) {
6011 addr = TASK_UNMAPPED_BASE;
6012
6013+#ifdef CONFIG_PAX_RANDMMAP
6014+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
6015+ addr += current->mm->delta_mmap;
6016+#endif
6017+
6018+ }
6019+
6020 if (filp) {
6021- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6022+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6023 } else if(flags & MAP_SHARED) {
6024- addr = get_shared_area(NULL, addr, len, pgoff);
6025+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6026 } else {
6027- addr = get_unshared_area(addr, len);
6028+ addr = get_unshared_area(filp, addr, len, flags);
6029 }
6030 return addr;
6031 }
6032diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6033index 04e47c6..7a8faf6 100644
6034--- a/arch/parisc/kernel/traps.c
6035+++ b/arch/parisc/kernel/traps.c
6036@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6037
6038 down_read(&current->mm->mmap_sem);
6039 vma = find_vma(current->mm,regs->iaoq[0]);
6040- if (vma && (regs->iaoq[0] >= vma->vm_start)
6041- && (vma->vm_flags & VM_EXEC)) {
6042-
6043+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6044 fault_address = regs->iaoq[0];
6045 fault_space = regs->iasq[0];
6046
6047diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6048index f247a34..dc0f219 100644
6049--- a/arch/parisc/mm/fault.c
6050+++ b/arch/parisc/mm/fault.c
6051@@ -15,6 +15,7 @@
6052 #include <linux/sched.h>
6053 #include <linux/interrupt.h>
6054 #include <linux/module.h>
6055+#include <linux/unistd.h>
6056
6057 #include <asm/uaccess.h>
6058 #include <asm/traps.h>
6059@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6060 static unsigned long
6061 parisc_acctyp(unsigned long code, unsigned int inst)
6062 {
6063- if (code == 6 || code == 16)
6064+ if (code == 6 || code == 7 || code == 16)
6065 return VM_EXEC;
6066
6067 switch (inst & 0xf0000000) {
6068@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6069 }
6070 #endif
6071
6072+#ifdef CONFIG_PAX_PAGEEXEC
6073+/*
6074+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6075+ *
6076+ * returns 1 when task should be killed
6077+ * 2 when rt_sigreturn trampoline was detected
6078+ * 3 when unpatched PLT trampoline was detected
6079+ */
6080+static int pax_handle_fetch_fault(struct pt_regs *regs)
6081+{
6082+
6083+#ifdef CONFIG_PAX_EMUPLT
6084+ int err;
6085+
6086+ do { /* PaX: unpatched PLT emulation */
6087+ unsigned int bl, depwi;
6088+
6089+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6090+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6091+
6092+ if (err)
6093+ break;
6094+
6095+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6096+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6097+
6098+ err = get_user(ldw, (unsigned int *)addr);
6099+ err |= get_user(bv, (unsigned int *)(addr+4));
6100+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6101+
6102+ if (err)
6103+ break;
6104+
6105+ if (ldw == 0x0E801096U &&
6106+ bv == 0xEAC0C000U &&
6107+ ldw2 == 0x0E881095U)
6108+ {
6109+ unsigned int resolver, map;
6110+
6111+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6112+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6113+ if (err)
6114+ break;
6115+
6116+ regs->gr[20] = instruction_pointer(regs)+8;
6117+ regs->gr[21] = map;
6118+ regs->gr[22] = resolver;
6119+ regs->iaoq[0] = resolver | 3UL;
6120+ regs->iaoq[1] = regs->iaoq[0] + 4;
6121+ return 3;
6122+ }
6123+ }
6124+ } while (0);
6125+#endif
6126+
6127+#ifdef CONFIG_PAX_EMUTRAMP
6128+
6129+#ifndef CONFIG_PAX_EMUSIGRT
6130+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6131+ return 1;
6132+#endif
6133+
6134+ do { /* PaX: rt_sigreturn emulation */
6135+ unsigned int ldi1, ldi2, bel, nop;
6136+
6137+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6138+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6139+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6140+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6141+
6142+ if (err)
6143+ break;
6144+
6145+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6146+ ldi2 == 0x3414015AU &&
6147+ bel == 0xE4008200U &&
6148+ nop == 0x08000240U)
6149+ {
6150+ regs->gr[25] = (ldi1 & 2) >> 1;
6151+ regs->gr[20] = __NR_rt_sigreturn;
6152+ regs->gr[31] = regs->iaoq[1] + 16;
6153+ regs->sr[0] = regs->iasq[1];
6154+ regs->iaoq[0] = 0x100UL;
6155+ regs->iaoq[1] = regs->iaoq[0] + 4;
6156+ regs->iasq[0] = regs->sr[2];
6157+ regs->iasq[1] = regs->sr[2];
6158+ return 2;
6159+ }
6160+ } while (0);
6161+#endif
6162+
6163+ return 1;
6164+}
6165+
6166+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6167+{
6168+ unsigned long i;
6169+
6170+ printk(KERN_ERR "PAX: bytes at PC: ");
6171+ for (i = 0; i < 5; i++) {
6172+ unsigned int c;
6173+ if (get_user(c, (unsigned int *)pc+i))
6174+ printk(KERN_CONT "???????? ");
6175+ else
6176+ printk(KERN_CONT "%08x ", c);
6177+ }
6178+ printk("\n");
6179+}
6180+#endif
6181+
6182 int fixup_exception(struct pt_regs *regs)
6183 {
6184 const struct exception_table_entry *fix;
6185@@ -194,8 +305,33 @@ good_area:
6186
6187 acc_type = parisc_acctyp(code,regs->iir);
6188
6189- if ((vma->vm_flags & acc_type) != acc_type)
6190+ if ((vma->vm_flags & acc_type) != acc_type) {
6191+
6192+#ifdef CONFIG_PAX_PAGEEXEC
6193+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6194+ (address & ~3UL) == instruction_pointer(regs))
6195+ {
6196+ up_read(&mm->mmap_sem);
6197+ switch (pax_handle_fetch_fault(regs)) {
6198+
6199+#ifdef CONFIG_PAX_EMUPLT
6200+ case 3:
6201+ return;
6202+#endif
6203+
6204+#ifdef CONFIG_PAX_EMUTRAMP
6205+ case 2:
6206+ return;
6207+#endif
6208+
6209+ }
6210+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6211+ do_group_exit(SIGKILL);
6212+ }
6213+#endif
6214+
6215 goto bad_area;
6216+ }
6217
6218 /*
6219 * If for any reason at all we couldn't handle the fault, make
6220diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6221index e3b1d41..8e81edf 100644
6222--- a/arch/powerpc/include/asm/atomic.h
6223+++ b/arch/powerpc/include/asm/atomic.h
6224@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6225 return t1;
6226 }
6227
6228+#define atomic64_read_unchecked(v) atomic64_read(v)
6229+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6230+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6231+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6232+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6233+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6234+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6235+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6236+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6237+
6238 #endif /* __powerpc64__ */
6239
6240 #endif /* __KERNEL__ */
6241diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6242index 9e495c9..b6878e5 100644
6243--- a/arch/powerpc/include/asm/cache.h
6244+++ b/arch/powerpc/include/asm/cache.h
6245@@ -3,6 +3,7 @@
6246
6247 #ifdef __KERNEL__
6248
6249+#include <linux/const.h>
6250
6251 /* bytes per L1 cache line */
6252 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6253@@ -22,7 +23,7 @@
6254 #define L1_CACHE_SHIFT 7
6255 #endif
6256
6257-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6258+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6259
6260 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6261
6262diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6263index cc0655a..13eac2e 100644
6264--- a/arch/powerpc/include/asm/elf.h
6265+++ b/arch/powerpc/include/asm/elf.h
6266@@ -28,8 +28,19 @@
6267 the loader. We need to make sure that it is out of the way of the program
6268 that it will "exec", and that there is sufficient room for the brk. */
6269
6270-extern unsigned long randomize_et_dyn(unsigned long base);
6271-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6272+#define ELF_ET_DYN_BASE (0x20000000)
6273+
6274+#ifdef CONFIG_PAX_ASLR
6275+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6276+
6277+#ifdef __powerpc64__
6278+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6279+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6280+#else
6281+#define PAX_DELTA_MMAP_LEN 15
6282+#define PAX_DELTA_STACK_LEN 15
6283+#endif
6284+#endif
6285
6286 /*
6287 * Our registers are always unsigned longs, whether we're a 32 bit
6288@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6289 (0x7ff >> (PAGE_SHIFT - 12)) : \
6290 (0x3ffff >> (PAGE_SHIFT - 12)))
6291
6292-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6293-#define arch_randomize_brk arch_randomize_brk
6294-
6295-
6296 #ifdef CONFIG_SPU_BASE
6297 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6298 #define NT_SPU 1
6299diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6300index 8196e9c..d83a9f3 100644
6301--- a/arch/powerpc/include/asm/exec.h
6302+++ b/arch/powerpc/include/asm/exec.h
6303@@ -4,6 +4,6 @@
6304 #ifndef _ASM_POWERPC_EXEC_H
6305 #define _ASM_POWERPC_EXEC_H
6306
6307-extern unsigned long arch_align_stack(unsigned long sp);
6308+#define arch_align_stack(x) ((x) & ~0xfUL)
6309
6310 #endif /* _ASM_POWERPC_EXEC_H */
6311diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6312index 5acabbd..7ea14fa 100644
6313--- a/arch/powerpc/include/asm/kmap_types.h
6314+++ b/arch/powerpc/include/asm/kmap_types.h
6315@@ -10,7 +10,7 @@
6316 * 2 of the License, or (at your option) any later version.
6317 */
6318
6319-#define KM_TYPE_NR 16
6320+#define KM_TYPE_NR 17
6321
6322 #endif /* __KERNEL__ */
6323 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6324diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6325index 8565c25..2865190 100644
6326--- a/arch/powerpc/include/asm/mman.h
6327+++ b/arch/powerpc/include/asm/mman.h
6328@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6329 }
6330 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6331
6332-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6333+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6334 {
6335 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6336 }
6337diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6338index 988c812..63c7d70 100644
6339--- a/arch/powerpc/include/asm/page.h
6340+++ b/arch/powerpc/include/asm/page.h
6341@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6342 * and needs to be executable. This means the whole heap ends
6343 * up being executable.
6344 */
6345-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6346- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6347+#define VM_DATA_DEFAULT_FLAGS32 \
6348+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6349+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6350
6351 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6352 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6353@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6354 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6355 #endif
6356
6357+#define ktla_ktva(addr) (addr)
6358+#define ktva_ktla(addr) (addr)
6359+
6360 #ifndef CONFIG_PPC_BOOK3S_64
6361 /*
6362 * Use the top bit of the higher-level page table entries to indicate whether
6363diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6364index 88693ce..ac6f9ab 100644
6365--- a/arch/powerpc/include/asm/page_64.h
6366+++ b/arch/powerpc/include/asm/page_64.h
6367@@ -153,15 +153,18 @@ do { \
6368 * stack by default, so in the absence of a PT_GNU_STACK program header
6369 * we turn execute permission off.
6370 */
6371-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6372- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6373+#define VM_STACK_DEFAULT_FLAGS32 \
6374+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6375+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6376
6377 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6378 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6379
6380+#ifndef CONFIG_PAX_PAGEEXEC
6381 #define VM_STACK_DEFAULT_FLAGS \
6382 (is_32bit_task() ? \
6383 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6384+#endif
6385
6386 #include <asm-generic/getorder.h>
6387
6388diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6389index b66ae72..4a378cd 100644
6390--- a/arch/powerpc/include/asm/pgalloc-64.h
6391+++ b/arch/powerpc/include/asm/pgalloc-64.h
6392@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6393 #ifndef CONFIG_PPC_64K_PAGES
6394
6395 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6396+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6397
6398 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6399 {
6400@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6401 pud_set(pud, (unsigned long)pmd);
6402 }
6403
6404+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6405+{
6406+ pud_populate(mm, pud, pmd);
6407+}
6408+
6409 #define pmd_populate(mm, pmd, pte_page) \
6410 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6411 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6412@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
6413 #endif
6414
6415 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6416+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6417
6418 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6419 pte_t *pte)
6420diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6421index 7aeb955..19f748e 100644
6422--- a/arch/powerpc/include/asm/pgtable.h
6423+++ b/arch/powerpc/include/asm/pgtable.h
6424@@ -2,6 +2,7 @@
6425 #define _ASM_POWERPC_PGTABLE_H
6426 #ifdef __KERNEL__
6427
6428+#include <linux/const.h>
6429 #ifndef __ASSEMBLY__
6430 #include <asm/processor.h> /* For TASK_SIZE */
6431 #include <asm/mmu.h>
6432diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6433index 4aad413..85d86bf 100644
6434--- a/arch/powerpc/include/asm/pte-hash32.h
6435+++ b/arch/powerpc/include/asm/pte-hash32.h
6436@@ -21,6 +21,7 @@
6437 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6438 #define _PAGE_USER 0x004 /* usermode access allowed */
6439 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6440+#define _PAGE_EXEC _PAGE_GUARDED
6441 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6442 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6443 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6444diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6445index 362142b..8b22c1b 100644
6446--- a/arch/powerpc/include/asm/reg.h
6447+++ b/arch/powerpc/include/asm/reg.h
6448@@ -234,6 +234,7 @@
6449 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6450 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6451 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6452+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6453 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6454 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6455 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6456diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6457index ffbaabe..eabe843 100644
6458--- a/arch/powerpc/include/asm/smp.h
6459+++ b/arch/powerpc/include/asm/smp.h
6460@@ -50,7 +50,7 @@ struct smp_ops_t {
6461 int (*cpu_disable)(void);
6462 void (*cpu_die)(unsigned int nr);
6463 int (*cpu_bootable)(unsigned int nr);
6464-};
6465+} __no_const;
6466
6467 extern void smp_send_debugger_break(void);
6468 extern void start_secondary_resume(void);
6469diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6470index ba7b197..d292e26 100644
6471--- a/arch/powerpc/include/asm/thread_info.h
6472+++ b/arch/powerpc/include/asm/thread_info.h
6473@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
6474 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
6475 TIF_NEED_RESCHED */
6476 #define TIF_32BIT 4 /* 32 bit binary */
6477-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
6478 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6479 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6480 #define TIF_SINGLESTEP 8 /* singlestepping active */
6481@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
6482 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6483 for stack store? */
6484 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6485+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
6486+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6487+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
6488
6489 /* as above, but as bit values */
6490 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6491@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
6492 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6493 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6494 #define _TIF_NOHZ (1<<TIF_NOHZ)
6495+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6496 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6497 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6498- _TIF_NOHZ)
6499+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
6500
6501 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6502 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6503diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6504index 4db4959..aba5c41 100644
6505--- a/arch/powerpc/include/asm/uaccess.h
6506+++ b/arch/powerpc/include/asm/uaccess.h
6507@@ -318,52 +318,6 @@ do { \
6508 extern unsigned long __copy_tofrom_user(void __user *to,
6509 const void __user *from, unsigned long size);
6510
6511-#ifndef __powerpc64__
6512-
6513-static inline unsigned long copy_from_user(void *to,
6514- const void __user *from, unsigned long n)
6515-{
6516- unsigned long over;
6517-
6518- if (access_ok(VERIFY_READ, from, n))
6519- return __copy_tofrom_user((__force void __user *)to, from, n);
6520- if ((unsigned long)from < TASK_SIZE) {
6521- over = (unsigned long)from + n - TASK_SIZE;
6522- return __copy_tofrom_user((__force void __user *)to, from,
6523- n - over) + over;
6524- }
6525- return n;
6526-}
6527-
6528-static inline unsigned long copy_to_user(void __user *to,
6529- const void *from, unsigned long n)
6530-{
6531- unsigned long over;
6532-
6533- if (access_ok(VERIFY_WRITE, to, n))
6534- return __copy_tofrom_user(to, (__force void __user *)from, n);
6535- if ((unsigned long)to < TASK_SIZE) {
6536- over = (unsigned long)to + n - TASK_SIZE;
6537- return __copy_tofrom_user(to, (__force void __user *)from,
6538- n - over) + over;
6539- }
6540- return n;
6541-}
6542-
6543-#else /* __powerpc64__ */
6544-
6545-#define __copy_in_user(to, from, size) \
6546- __copy_tofrom_user((to), (from), (size))
6547-
6548-extern unsigned long copy_from_user(void *to, const void __user *from,
6549- unsigned long n);
6550-extern unsigned long copy_to_user(void __user *to, const void *from,
6551- unsigned long n);
6552-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6553- unsigned long n);
6554-
6555-#endif /* __powerpc64__ */
6556-
6557 static inline unsigned long __copy_from_user_inatomic(void *to,
6558 const void __user *from, unsigned long n)
6559 {
6560@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6561 if (ret == 0)
6562 return 0;
6563 }
6564+
6565+ if (!__builtin_constant_p(n))
6566+ check_object_size(to, n, false);
6567+
6568 return __copy_tofrom_user((__force void __user *)to, from, n);
6569 }
6570
6571@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6572 if (ret == 0)
6573 return 0;
6574 }
6575+
6576+ if (!__builtin_constant_p(n))
6577+ check_object_size(from, n, true);
6578+
6579 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6580 }
6581
6582@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6583 return __copy_to_user_inatomic(to, from, size);
6584 }
6585
6586+#ifndef __powerpc64__
6587+
6588+static inline unsigned long __must_check copy_from_user(void *to,
6589+ const void __user *from, unsigned long n)
6590+{
6591+ unsigned long over;
6592+
6593+ if ((long)n < 0)
6594+ return n;
6595+
6596+ if (access_ok(VERIFY_READ, from, n)) {
6597+ if (!__builtin_constant_p(n))
6598+ check_object_size(to, n, false);
6599+ return __copy_tofrom_user((__force void __user *)to, from, n);
6600+ }
6601+ if ((unsigned long)from < TASK_SIZE) {
6602+ over = (unsigned long)from + n - TASK_SIZE;
6603+ if (!__builtin_constant_p(n - over))
6604+ check_object_size(to, n - over, false);
6605+ return __copy_tofrom_user((__force void __user *)to, from,
6606+ n - over) + over;
6607+ }
6608+ return n;
6609+}
6610+
6611+static inline unsigned long __must_check copy_to_user(void __user *to,
6612+ const void *from, unsigned long n)
6613+{
6614+ unsigned long over;
6615+
6616+ if ((long)n < 0)
6617+ return n;
6618+
6619+ if (access_ok(VERIFY_WRITE, to, n)) {
6620+ if (!__builtin_constant_p(n))
6621+ check_object_size(from, n, true);
6622+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6623+ }
6624+ if ((unsigned long)to < TASK_SIZE) {
6625+ over = (unsigned long)to + n - TASK_SIZE;
6626+ if (!__builtin_constant_p(n))
6627+ check_object_size(from, n - over, true);
6628+ return __copy_tofrom_user(to, (__force void __user *)from,
6629+ n - over) + over;
6630+ }
6631+ return n;
6632+}
6633+
6634+#else /* __powerpc64__ */
6635+
6636+#define __copy_in_user(to, from, size) \
6637+ __copy_tofrom_user((to), (from), (size))
6638+
6639+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6640+{
6641+ if ((long)n < 0 || n > INT_MAX)
6642+ return n;
6643+
6644+ if (!__builtin_constant_p(n))
6645+ check_object_size(to, n, false);
6646+
6647+ if (likely(access_ok(VERIFY_READ, from, n)))
6648+ n = __copy_from_user(to, from, n);
6649+ else
6650+ memset(to, 0, n);
6651+ return n;
6652+}
6653+
6654+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6655+{
6656+ if ((long)n < 0 || n > INT_MAX)
6657+ return n;
6658+
6659+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6660+ if (!__builtin_constant_p(n))
6661+ check_object_size(from, n, true);
6662+ n = __copy_to_user(to, from, n);
6663+ }
6664+ return n;
6665+}
6666+
6667+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6668+ unsigned long n);
6669+
6670+#endif /* __powerpc64__ */
6671+
6672 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6673
6674 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6675diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6676index 645170a..6cf0271 100644
6677--- a/arch/powerpc/kernel/exceptions-64e.S
6678+++ b/arch/powerpc/kernel/exceptions-64e.S
6679@@ -757,6 +757,7 @@ storage_fault_common:
6680 std r14,_DAR(r1)
6681 std r15,_DSISR(r1)
6682 addi r3,r1,STACK_FRAME_OVERHEAD
6683+ bl .save_nvgprs
6684 mr r4,r14
6685 mr r5,r15
6686 ld r14,PACA_EXGEN+EX_R14(r13)
6687@@ -765,8 +766,7 @@ storage_fault_common:
6688 cmpdi r3,0
6689 bne- 1f
6690 b .ret_from_except_lite
6691-1: bl .save_nvgprs
6692- mr r5,r3
6693+1: mr r5,r3
6694 addi r3,r1,STACK_FRAME_OVERHEAD
6695 ld r4,_DAR(r1)
6696 bl .bad_page_fault
6697diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6698index 4e00d22..b26abcc 100644
6699--- a/arch/powerpc/kernel/exceptions-64s.S
6700+++ b/arch/powerpc/kernel/exceptions-64s.S
6701@@ -1356,10 +1356,10 @@ handle_page_fault:
6702 11: ld r4,_DAR(r1)
6703 ld r5,_DSISR(r1)
6704 addi r3,r1,STACK_FRAME_OVERHEAD
6705+ bl .save_nvgprs
6706 bl .do_page_fault
6707 cmpdi r3,0
6708 beq+ 12f
6709- bl .save_nvgprs
6710 mr r5,r3
6711 addi r3,r1,STACK_FRAME_OVERHEAD
6712 lwz r4,_DAR(r1)
6713diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6714index 2e3200c..72095ce 100644
6715--- a/arch/powerpc/kernel/module_32.c
6716+++ b/arch/powerpc/kernel/module_32.c
6717@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6718 me->arch.core_plt_section = i;
6719 }
6720 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6721- printk("Module doesn't contain .plt or .init.plt sections.\n");
6722+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6723 return -ENOEXEC;
6724 }
6725
6726@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6727
6728 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6729 /* Init, or core PLT? */
6730- if (location >= mod->module_core
6731- && location < mod->module_core + mod->core_size)
6732+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6733+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6734 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6735- else
6736+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6737+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6738 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6739+ else {
6740+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6741+ return ~0UL;
6742+ }
6743
6744 /* Find this entry, or if that fails, the next avail. entry */
6745 while (entry->jump[0]) {
6746diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6747index 076d124..6cb2cbf 100644
6748--- a/arch/powerpc/kernel/process.c
6749+++ b/arch/powerpc/kernel/process.c
6750@@ -874,8 +874,8 @@ void show_regs(struct pt_regs * regs)
6751 * Lookup NIP late so we have the best change of getting the
6752 * above info out without failing
6753 */
6754- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6755- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6756+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6757+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6758 #endif
6759 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
6760 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
6761@@ -1335,10 +1335,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6762 newsp = stack[0];
6763 ip = stack[STACK_FRAME_LR_SAVE];
6764 if (!firstframe || ip != lr) {
6765- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6766+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6767 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6768 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6769- printk(" (%pS)",
6770+ printk(" (%pA)",
6771 (void *)current->ret_stack[curr_frame].ret);
6772 curr_frame--;
6773 }
6774@@ -1358,7 +1358,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6775 struct pt_regs *regs = (struct pt_regs *)
6776 (sp + STACK_FRAME_OVERHEAD);
6777 lr = regs->link;
6778- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6779+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6780 regs->trap, (void *)regs->nip, (void *)lr);
6781 firstframe = 1;
6782 }
6783@@ -1394,58 +1394,3 @@ void notrace __ppc64_runlatch_off(void)
6784 mtspr(SPRN_CTRLT, ctrl);
6785 }
6786 #endif /* CONFIG_PPC64 */
6787-
6788-unsigned long arch_align_stack(unsigned long sp)
6789-{
6790- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6791- sp -= get_random_int() & ~PAGE_MASK;
6792- return sp & ~0xf;
6793-}
6794-
6795-static inline unsigned long brk_rnd(void)
6796-{
6797- unsigned long rnd = 0;
6798-
6799- /* 8MB for 32bit, 1GB for 64bit */
6800- if (is_32bit_task())
6801- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6802- else
6803- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6804-
6805- return rnd << PAGE_SHIFT;
6806-}
6807-
6808-unsigned long arch_randomize_brk(struct mm_struct *mm)
6809-{
6810- unsigned long base = mm->brk;
6811- unsigned long ret;
6812-
6813-#ifdef CONFIG_PPC_STD_MMU_64
6814- /*
6815- * If we are using 1TB segments and we are allowed to randomise
6816- * the heap, we can put it above 1TB so it is backed by a 1TB
6817- * segment. Otherwise the heap will be in the bottom 1TB
6818- * which always uses 256MB segments and this may result in a
6819- * performance penalty.
6820- */
6821- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6822- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6823-#endif
6824-
6825- ret = PAGE_ALIGN(base + brk_rnd());
6826-
6827- if (ret < mm->brk)
6828- return mm->brk;
6829-
6830- return ret;
6831-}
6832-
6833-unsigned long randomize_et_dyn(unsigned long base)
6834-{
6835- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6836-
6837- if (ret < base)
6838- return base;
6839-
6840- return ret;
6841-}
6842diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6843index 64f7bd5..8dd550f 100644
6844--- a/arch/powerpc/kernel/ptrace.c
6845+++ b/arch/powerpc/kernel/ptrace.c
6846@@ -1783,6 +1783,10 @@ long arch_ptrace(struct task_struct *child, long request,
6847 return ret;
6848 }
6849
6850+#ifdef CONFIG_GRKERNSEC_SETXID
6851+extern void gr_delayed_cred_worker(void);
6852+#endif
6853+
6854 /*
6855 * We must return the syscall number to actually look up in the table.
6856 * This can be -1L to skip running any syscall at all.
6857@@ -1795,6 +1799,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6858
6859 secure_computing_strict(regs->gpr[0]);
6860
6861+#ifdef CONFIG_GRKERNSEC_SETXID
6862+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6863+ gr_delayed_cred_worker();
6864+#endif
6865+
6866 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6867 tracehook_report_syscall_entry(regs))
6868 /*
6869@@ -1829,6 +1838,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6870 {
6871 int step;
6872
6873+#ifdef CONFIG_GRKERNSEC_SETXID
6874+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6875+ gr_delayed_cred_worker();
6876+#endif
6877+
6878 audit_syscall_exit(regs);
6879
6880 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6881diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6882index 0f83122..c0aca6a 100644
6883--- a/arch/powerpc/kernel/signal_32.c
6884+++ b/arch/powerpc/kernel/signal_32.c
6885@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6886 /* Save user registers on the stack */
6887 frame = &rt_sf->uc.uc_mcontext;
6888 addr = frame;
6889- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6890+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6891 sigret = 0;
6892 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6893 } else {
6894diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6895index 887e99d..310bc11 100644
6896--- a/arch/powerpc/kernel/signal_64.c
6897+++ b/arch/powerpc/kernel/signal_64.c
6898@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6899 #endif
6900
6901 /* Set up to return from userspace. */
6902- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6903+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6904 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6905 } else {
6906 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6907diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6908index e68a845..8b140e6 100644
6909--- a/arch/powerpc/kernel/sysfs.c
6910+++ b/arch/powerpc/kernel/sysfs.c
6911@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6912 return NOTIFY_OK;
6913 }
6914
6915-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6916+static struct notifier_block sysfs_cpu_nb = {
6917 .notifier_call = sysfs_cpu_notify,
6918 };
6919
6920diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6921index e4f205a..8bfffb8 100644
6922--- a/arch/powerpc/kernel/traps.c
6923+++ b/arch/powerpc/kernel/traps.c
6924@@ -143,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6925 return flags;
6926 }
6927
6928+extern void gr_handle_kernel_exploit(void);
6929+
6930 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6931 int signr)
6932 {
6933@@ -192,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6934 panic("Fatal exception in interrupt");
6935 if (panic_on_oops)
6936 panic("Fatal exception");
6937+
6938+ gr_handle_kernel_exploit();
6939+
6940 do_exit(signr);
6941 }
6942
6943diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6944index d4f463a..8fb7431 100644
6945--- a/arch/powerpc/kernel/vdso.c
6946+++ b/arch/powerpc/kernel/vdso.c
6947@@ -34,6 +34,7 @@
6948 #include <asm/firmware.h>
6949 #include <asm/vdso.h>
6950 #include <asm/vdso_datapage.h>
6951+#include <asm/mman.h>
6952
6953 #include "setup.h"
6954
6955@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6956 vdso_base = VDSO32_MBASE;
6957 #endif
6958
6959- current->mm->context.vdso_base = 0;
6960+ current->mm->context.vdso_base = ~0UL;
6961
6962 /* vDSO has a problem and was disabled, just don't "enable" it for the
6963 * process
6964@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6965 vdso_base = get_unmapped_area(NULL, vdso_base,
6966 (vdso_pages << PAGE_SHIFT) +
6967 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6968- 0, 0);
6969+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6970 if (IS_ERR_VALUE(vdso_base)) {
6971 rc = vdso_base;
6972 goto fail_mmapsem;
6973diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6974index 5eea6f3..5d10396 100644
6975--- a/arch/powerpc/lib/usercopy_64.c
6976+++ b/arch/powerpc/lib/usercopy_64.c
6977@@ -9,22 +9,6 @@
6978 #include <linux/module.h>
6979 #include <asm/uaccess.h>
6980
6981-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6982-{
6983- if (likely(access_ok(VERIFY_READ, from, n)))
6984- n = __copy_from_user(to, from, n);
6985- else
6986- memset(to, 0, n);
6987- return n;
6988-}
6989-
6990-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6991-{
6992- if (likely(access_ok(VERIFY_WRITE, to, n)))
6993- n = __copy_to_user(to, from, n);
6994- return n;
6995-}
6996-
6997 unsigned long copy_in_user(void __user *to, const void __user *from,
6998 unsigned long n)
6999 {
7000@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
7001 return n;
7002 }
7003
7004-EXPORT_SYMBOL(copy_from_user);
7005-EXPORT_SYMBOL(copy_to_user);
7006 EXPORT_SYMBOL(copy_in_user);
7007
7008diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
7009index 8726779..a33c512 100644
7010--- a/arch/powerpc/mm/fault.c
7011+++ b/arch/powerpc/mm/fault.c
7012@@ -33,6 +33,10 @@
7013 #include <linux/magic.h>
7014 #include <linux/ratelimit.h>
7015 #include <linux/context_tracking.h>
7016+#include <linux/slab.h>
7017+#include <linux/pagemap.h>
7018+#include <linux/compiler.h>
7019+#include <linux/unistd.h>
7020
7021 #include <asm/firmware.h>
7022 #include <asm/page.h>
7023@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7024 }
7025 #endif
7026
7027+#ifdef CONFIG_PAX_PAGEEXEC
7028+/*
7029+ * PaX: decide what to do with offenders (regs->nip = fault address)
7030+ *
7031+ * returns 1 when task should be killed
7032+ */
7033+static int pax_handle_fetch_fault(struct pt_regs *regs)
7034+{
7035+ return 1;
7036+}
7037+
7038+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7039+{
7040+ unsigned long i;
7041+
7042+ printk(KERN_ERR "PAX: bytes at PC: ");
7043+ for (i = 0; i < 5; i++) {
7044+ unsigned int c;
7045+ if (get_user(c, (unsigned int __user *)pc+i))
7046+ printk(KERN_CONT "???????? ");
7047+ else
7048+ printk(KERN_CONT "%08x ", c);
7049+ }
7050+ printk("\n");
7051+}
7052+#endif
7053+
7054 /*
7055 * Check whether the instruction at regs->nip is a store using
7056 * an update addressing form which will update r1.
7057@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7058 * indicate errors in DSISR but can validly be set in SRR1.
7059 */
7060 if (trap == 0x400)
7061- error_code &= 0x48200000;
7062+ error_code &= 0x58200000;
7063 else
7064 is_write = error_code & DSISR_ISSTORE;
7065 #else
7066@@ -371,7 +402,7 @@ good_area:
7067 * "undefined". Of those that can be set, this is the only
7068 * one which seems bad.
7069 */
7070- if (error_code & 0x10000000)
7071+ if (error_code & DSISR_GUARDED)
7072 /* Guarded storage error. */
7073 goto bad_area;
7074 #endif /* CONFIG_8xx */
7075@@ -386,7 +417,7 @@ good_area:
7076 * processors use the same I/D cache coherency mechanism
7077 * as embedded.
7078 */
7079- if (error_code & DSISR_PROTFAULT)
7080+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7081 goto bad_area;
7082 #endif /* CONFIG_PPC_STD_MMU */
7083
7084@@ -471,6 +502,23 @@ bad_area:
7085 bad_area_nosemaphore:
7086 /* User mode accesses cause a SIGSEGV */
7087 if (user_mode(regs)) {
7088+
7089+#ifdef CONFIG_PAX_PAGEEXEC
7090+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7091+#ifdef CONFIG_PPC_STD_MMU
7092+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7093+#else
7094+ if (is_exec && regs->nip == address) {
7095+#endif
7096+ switch (pax_handle_fetch_fault(regs)) {
7097+ }
7098+
7099+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7100+ do_group_exit(SIGKILL);
7101+ }
7102+ }
7103+#endif
7104+
7105 _exception(SIGSEGV, regs, code, address);
7106 goto bail;
7107 }
7108diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7109index 67a42ed..cd463e0 100644
7110--- a/arch/powerpc/mm/mmap_64.c
7111+++ b/arch/powerpc/mm/mmap_64.c
7112@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7113 {
7114 unsigned long rnd = 0;
7115
7116+#ifdef CONFIG_PAX_RANDMMAP
7117+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7118+#endif
7119+
7120 if (current->flags & PF_RANDOMIZE) {
7121 /* 8MB for 32bit, 1GB for 64bit */
7122 if (is_32bit_task())
7123@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7124 */
7125 if (mmap_is_legacy()) {
7126 mm->mmap_base = TASK_UNMAPPED_BASE;
7127+
7128+#ifdef CONFIG_PAX_RANDMMAP
7129+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7130+ mm->mmap_base += mm->delta_mmap;
7131+#endif
7132+
7133 mm->get_unmapped_area = arch_get_unmapped_area;
7134 mm->unmap_area = arch_unmap_area;
7135 } else {
7136 mm->mmap_base = mmap_base();
7137+
7138+#ifdef CONFIG_PAX_RANDMMAP
7139+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7140+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7141+#endif
7142+
7143 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7144 mm->unmap_area = arch_unmap_area_topdown;
7145 }
7146diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7147index e779642..e5bb889 100644
7148--- a/arch/powerpc/mm/mmu_context_nohash.c
7149+++ b/arch/powerpc/mm/mmu_context_nohash.c
7150@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7151 return NOTIFY_OK;
7152 }
7153
7154-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7155+static struct notifier_block mmu_context_cpu_nb = {
7156 .notifier_call = mmu_context_cpu_notify,
7157 };
7158
7159diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7160index 2859a1f..74f9a6e 100644
7161--- a/arch/powerpc/mm/numa.c
7162+++ b/arch/powerpc/mm/numa.c
7163@@ -919,7 +919,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7164 return ret;
7165 }
7166
7167-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7168+static struct notifier_block ppc64_numa_nb = {
7169 .notifier_call = cpu_numa_callback,
7170 .priority = 1 /* Must run before sched domains notifier. */
7171 };
7172diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7173index 3e99c14..f00953c 100644
7174--- a/arch/powerpc/mm/slice.c
7175+++ b/arch/powerpc/mm/slice.c
7176@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7177 if ((mm->task_size - len) < addr)
7178 return 0;
7179 vma = find_vma(mm, addr);
7180- return (!vma || (addr + len) <= vma->vm_start);
7181+ return check_heap_stack_gap(vma, addr, len, 0);
7182 }
7183
7184 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7185@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
7186 info.align_offset = 0;
7187
7188 addr = TASK_UNMAPPED_BASE;
7189+
7190+#ifdef CONFIG_PAX_RANDMMAP
7191+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7192+ addr += mm->delta_mmap;
7193+#endif
7194+
7195 while (addr < TASK_SIZE) {
7196 info.low_limit = addr;
7197 if (!slice_scan_available(addr, available, 1, &addr))
7198@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7199 if (fixed && addr > (mm->task_size - len))
7200 return -EINVAL;
7201
7202+#ifdef CONFIG_PAX_RANDMMAP
7203+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7204+ addr = 0;
7205+#endif
7206+
7207 /* If hint, make sure it matches our alignment restrictions */
7208 if (!fixed && addr) {
7209 addr = _ALIGN_UP(addr, 1ul << pshift);
7210diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7211index 9098692..3d54cd1 100644
7212--- a/arch/powerpc/platforms/cell/spufs/file.c
7213+++ b/arch/powerpc/platforms/cell/spufs/file.c
7214@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7215 return VM_FAULT_NOPAGE;
7216 }
7217
7218-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7219+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7220 unsigned long address,
7221- void *buf, int len, int write)
7222+ void *buf, size_t len, int write)
7223 {
7224 struct spu_context *ctx = vma->vm_file->private_data;
7225 unsigned long offset = address - vma->vm_start;
7226diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7227index bdb738a..49c9f95 100644
7228--- a/arch/powerpc/platforms/powermac/smp.c
7229+++ b/arch/powerpc/platforms/powermac/smp.c
7230@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7231 return NOTIFY_OK;
7232 }
7233
7234-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7235+static struct notifier_block smp_core99_cpu_nb = {
7236 .notifier_call = smp_core99_cpu_notify,
7237 };
7238 #endif /* CONFIG_HOTPLUG_CPU */
7239diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7240index c797832..ce575c8 100644
7241--- a/arch/s390/include/asm/atomic.h
7242+++ b/arch/s390/include/asm/atomic.h
7243@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7244 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7245 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7246
7247+#define atomic64_read_unchecked(v) atomic64_read(v)
7248+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7249+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7250+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7251+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7252+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7253+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7254+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7255+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7256+
7257 #define smp_mb__before_atomic_dec() smp_mb()
7258 #define smp_mb__after_atomic_dec() smp_mb()
7259 #define smp_mb__before_atomic_inc() smp_mb()
7260diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7261index 4d7ccac..d03d0ad 100644
7262--- a/arch/s390/include/asm/cache.h
7263+++ b/arch/s390/include/asm/cache.h
7264@@ -9,8 +9,10 @@
7265 #ifndef __ARCH_S390_CACHE_H
7266 #define __ARCH_S390_CACHE_H
7267
7268-#define L1_CACHE_BYTES 256
7269+#include <linux/const.h>
7270+
7271 #define L1_CACHE_SHIFT 8
7272+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7273 #define NET_SKB_PAD 32
7274
7275 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7276diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7277index 78f4f87..598ce39 100644
7278--- a/arch/s390/include/asm/elf.h
7279+++ b/arch/s390/include/asm/elf.h
7280@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
7281 the loader. We need to make sure that it is out of the way of the program
7282 that it will "exec", and that there is sufficient room for the brk. */
7283
7284-extern unsigned long randomize_et_dyn(unsigned long base);
7285-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7286+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7287+
7288+#ifdef CONFIG_PAX_ASLR
7289+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7290+
7291+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7292+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7293+#endif
7294
7295 /* This yields a mask that user programs can use to figure out what
7296 instruction set this CPU supports. */
7297@@ -222,9 +228,6 @@ struct linux_binprm;
7298 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7299 int arch_setup_additional_pages(struct linux_binprm *, int);
7300
7301-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7302-#define arch_randomize_brk arch_randomize_brk
7303-
7304 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7305
7306 #endif
7307diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7308index c4a93d6..4d2a9b4 100644
7309--- a/arch/s390/include/asm/exec.h
7310+++ b/arch/s390/include/asm/exec.h
7311@@ -7,6 +7,6 @@
7312 #ifndef __ASM_EXEC_H
7313 #define __ASM_EXEC_H
7314
7315-extern unsigned long arch_align_stack(unsigned long sp);
7316+#define arch_align_stack(x) ((x) & ~0xfUL)
7317
7318 #endif /* __ASM_EXEC_H */
7319diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7320index 9c33ed4..e40cbef 100644
7321--- a/arch/s390/include/asm/uaccess.h
7322+++ b/arch/s390/include/asm/uaccess.h
7323@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7324 copy_to_user(void __user *to, const void *from, unsigned long n)
7325 {
7326 might_fault();
7327+
7328+ if ((long)n < 0)
7329+ return n;
7330+
7331 return __copy_to_user(to, from, n);
7332 }
7333
7334@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7335 static inline unsigned long __must_check
7336 __copy_from_user(void *to, const void __user *from, unsigned long n)
7337 {
7338+ if ((long)n < 0)
7339+ return n;
7340+
7341 if (__builtin_constant_p(n) && (n <= 256))
7342 return uaccess.copy_from_user_small(n, from, to);
7343 else
7344@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7345 static inline unsigned long __must_check
7346 copy_from_user(void *to, const void __user *from, unsigned long n)
7347 {
7348- unsigned int sz = __compiletime_object_size(to);
7349+ size_t sz = __compiletime_object_size(to);
7350
7351 might_fault();
7352- if (unlikely(sz != -1 && sz < n)) {
7353+
7354+ if ((long)n < 0)
7355+ return n;
7356+
7357+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7358 copy_from_user_overflow();
7359 return n;
7360 }
7361diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7362index 7845e15..59c4353 100644
7363--- a/arch/s390/kernel/module.c
7364+++ b/arch/s390/kernel/module.c
7365@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7366
7367 /* Increase core size by size of got & plt and set start
7368 offsets for got and plt. */
7369- me->core_size = ALIGN(me->core_size, 4);
7370- me->arch.got_offset = me->core_size;
7371- me->core_size += me->arch.got_size;
7372- me->arch.plt_offset = me->core_size;
7373- me->core_size += me->arch.plt_size;
7374+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7375+ me->arch.got_offset = me->core_size_rw;
7376+ me->core_size_rw += me->arch.got_size;
7377+ me->arch.plt_offset = me->core_size_rx;
7378+ me->core_size_rx += me->arch.plt_size;
7379 return 0;
7380 }
7381
7382@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7383 if (info->got_initialized == 0) {
7384 Elf_Addr *gotent;
7385
7386- gotent = me->module_core + me->arch.got_offset +
7387+ gotent = me->module_core_rw + me->arch.got_offset +
7388 info->got_offset;
7389 *gotent = val;
7390 info->got_initialized = 1;
7391@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7392 rc = apply_rela_bits(loc, val, 0, 64, 0);
7393 else if (r_type == R_390_GOTENT ||
7394 r_type == R_390_GOTPLTENT) {
7395- val += (Elf_Addr) me->module_core - loc;
7396+ val += (Elf_Addr) me->module_core_rw - loc;
7397 rc = apply_rela_bits(loc, val, 1, 32, 1);
7398 }
7399 break;
7400@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7401 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7402 if (info->plt_initialized == 0) {
7403 unsigned int *ip;
7404- ip = me->module_core + me->arch.plt_offset +
7405+ ip = me->module_core_rx + me->arch.plt_offset +
7406 info->plt_offset;
7407 #ifndef CONFIG_64BIT
7408 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7409@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7410 val - loc + 0xffffUL < 0x1ffffeUL) ||
7411 (r_type == R_390_PLT32DBL &&
7412 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7413- val = (Elf_Addr) me->module_core +
7414+ val = (Elf_Addr) me->module_core_rx +
7415 me->arch.plt_offset +
7416 info->plt_offset;
7417 val += rela->r_addend - loc;
7418@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7419 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7420 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7421 val = val + rela->r_addend -
7422- ((Elf_Addr) me->module_core + me->arch.got_offset);
7423+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7424 if (r_type == R_390_GOTOFF16)
7425 rc = apply_rela_bits(loc, val, 0, 16, 0);
7426 else if (r_type == R_390_GOTOFF32)
7427@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7428 break;
7429 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7430 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7431- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7432+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7433 rela->r_addend - loc;
7434 if (r_type == R_390_GOTPC)
7435 rc = apply_rela_bits(loc, val, 1, 32, 0);
7436diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7437index 2bc3edd..ab9d598 100644
7438--- a/arch/s390/kernel/process.c
7439+++ b/arch/s390/kernel/process.c
7440@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
7441 }
7442 return 0;
7443 }
7444-
7445-unsigned long arch_align_stack(unsigned long sp)
7446-{
7447- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7448- sp -= get_random_int() & ~PAGE_MASK;
7449- return sp & ~0xf;
7450-}
7451-
7452-static inline unsigned long brk_rnd(void)
7453-{
7454- /* 8MB for 32bit, 1GB for 64bit */
7455- if (is_32bit_task())
7456- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7457- else
7458- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7459-}
7460-
7461-unsigned long arch_randomize_brk(struct mm_struct *mm)
7462-{
7463- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7464-
7465- if (ret < mm->brk)
7466- return mm->brk;
7467- return ret;
7468-}
7469-
7470-unsigned long randomize_et_dyn(unsigned long base)
7471-{
7472- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7473-
7474- if (!(current->flags & PF_RANDOMIZE))
7475- return base;
7476- if (ret < base)
7477- return base;
7478- return ret;
7479-}
7480diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7481index 06bafec..2bca531 100644
7482--- a/arch/s390/mm/mmap.c
7483+++ b/arch/s390/mm/mmap.c
7484@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7485 */
7486 if (mmap_is_legacy()) {
7487 mm->mmap_base = TASK_UNMAPPED_BASE;
7488+
7489+#ifdef CONFIG_PAX_RANDMMAP
7490+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7491+ mm->mmap_base += mm->delta_mmap;
7492+#endif
7493+
7494 mm->get_unmapped_area = arch_get_unmapped_area;
7495 mm->unmap_area = arch_unmap_area;
7496 } else {
7497 mm->mmap_base = mmap_base();
7498+
7499+#ifdef CONFIG_PAX_RANDMMAP
7500+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7501+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7502+#endif
7503+
7504 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7505 mm->unmap_area = arch_unmap_area_topdown;
7506 }
7507@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7508 */
7509 if (mmap_is_legacy()) {
7510 mm->mmap_base = TASK_UNMAPPED_BASE;
7511+
7512+#ifdef CONFIG_PAX_RANDMMAP
7513+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7514+ mm->mmap_base += mm->delta_mmap;
7515+#endif
7516+
7517 mm->get_unmapped_area = s390_get_unmapped_area;
7518 mm->unmap_area = arch_unmap_area;
7519 } else {
7520 mm->mmap_base = mmap_base();
7521+
7522+#ifdef CONFIG_PAX_RANDMMAP
7523+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7524+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7525+#endif
7526+
7527 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7528 mm->unmap_area = arch_unmap_area_topdown;
7529 }
7530diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7531index ae3d59f..f65f075 100644
7532--- a/arch/score/include/asm/cache.h
7533+++ b/arch/score/include/asm/cache.h
7534@@ -1,7 +1,9 @@
7535 #ifndef _ASM_SCORE_CACHE_H
7536 #define _ASM_SCORE_CACHE_H
7537
7538+#include <linux/const.h>
7539+
7540 #define L1_CACHE_SHIFT 4
7541-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7543
7544 #endif /* _ASM_SCORE_CACHE_H */
7545diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7546index f9f3cd5..58ff438 100644
7547--- a/arch/score/include/asm/exec.h
7548+++ b/arch/score/include/asm/exec.h
7549@@ -1,6 +1,6 @@
7550 #ifndef _ASM_SCORE_EXEC_H
7551 #define _ASM_SCORE_EXEC_H
7552
7553-extern unsigned long arch_align_stack(unsigned long sp);
7554+#define arch_align_stack(x) (x)
7555
7556 #endif /* _ASM_SCORE_EXEC_H */
7557diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7558index f4c6d02..e9355c3 100644
7559--- a/arch/score/kernel/process.c
7560+++ b/arch/score/kernel/process.c
7561@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
7562
7563 return task_pt_regs(task)->cp0_epc;
7564 }
7565-
7566-unsigned long arch_align_stack(unsigned long sp)
7567-{
7568- return sp;
7569-}
7570diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7571index ef9e555..331bd29 100644
7572--- a/arch/sh/include/asm/cache.h
7573+++ b/arch/sh/include/asm/cache.h
7574@@ -9,10 +9,11 @@
7575 #define __ASM_SH_CACHE_H
7576 #ifdef __KERNEL__
7577
7578+#include <linux/const.h>
7579 #include <linux/init.h>
7580 #include <cpu/cache.h>
7581
7582-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7583+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7584
7585 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7586
7587diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7588index 03f2b55..b0270327 100644
7589--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7590+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7591@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7592 return NOTIFY_OK;
7593 }
7594
7595-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7596+static struct notifier_block shx3_cpu_notifier = {
7597 .notifier_call = shx3_cpu_callback,
7598 };
7599
7600diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7601index 6777177..cb5e44f 100644
7602--- a/arch/sh/mm/mmap.c
7603+++ b/arch/sh/mm/mmap.c
7604@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7605 struct mm_struct *mm = current->mm;
7606 struct vm_area_struct *vma;
7607 int do_colour_align;
7608+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7609 struct vm_unmapped_area_info info;
7610
7611 if (flags & MAP_FIXED) {
7612@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7613 if (filp || (flags & MAP_SHARED))
7614 do_colour_align = 1;
7615
7616+#ifdef CONFIG_PAX_RANDMMAP
7617+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7618+#endif
7619+
7620 if (addr) {
7621 if (do_colour_align)
7622 addr = COLOUR_ALIGN(addr, pgoff);
7623@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7624 addr = PAGE_ALIGN(addr);
7625
7626 vma = find_vma(mm, addr);
7627- if (TASK_SIZE - len >= addr &&
7628- (!vma || addr + len <= vma->vm_start))
7629+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7630 return addr;
7631 }
7632
7633 info.flags = 0;
7634 info.length = len;
7635- info.low_limit = TASK_UNMAPPED_BASE;
7636+ info.low_limit = mm->mmap_base;
7637 info.high_limit = TASK_SIZE;
7638 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7639 info.align_offset = pgoff << PAGE_SHIFT;
7640@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7641 struct mm_struct *mm = current->mm;
7642 unsigned long addr = addr0;
7643 int do_colour_align;
7644+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7645 struct vm_unmapped_area_info info;
7646
7647 if (flags & MAP_FIXED) {
7648@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7649 if (filp || (flags & MAP_SHARED))
7650 do_colour_align = 1;
7651
7652+#ifdef CONFIG_PAX_RANDMMAP
7653+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7654+#endif
7655+
7656 /* requesting a specific address */
7657 if (addr) {
7658 if (do_colour_align)
7659@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7660 addr = PAGE_ALIGN(addr);
7661
7662 vma = find_vma(mm, addr);
7663- if (TASK_SIZE - len >= addr &&
7664- (!vma || addr + len <= vma->vm_start))
7665+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7666 return addr;
7667 }
7668
7669@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7670 VM_BUG_ON(addr != -ENOMEM);
7671 info.flags = 0;
7672 info.low_limit = TASK_UNMAPPED_BASE;
7673+
7674+#ifdef CONFIG_PAX_RANDMMAP
7675+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7676+ info.low_limit += mm->delta_mmap;
7677+#endif
7678+
7679 info.high_limit = TASK_SIZE;
7680 addr = vm_unmapped_area(&info);
7681 }
7682diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7683index be56a24..443328f 100644
7684--- a/arch/sparc/include/asm/atomic_64.h
7685+++ b/arch/sparc/include/asm/atomic_64.h
7686@@ -14,18 +14,40 @@
7687 #define ATOMIC64_INIT(i) { (i) }
7688
7689 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7690+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7691+{
7692+ return v->counter;
7693+}
7694 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7695+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7696+{
7697+ return v->counter;
7698+}
7699
7700 #define atomic_set(v, i) (((v)->counter) = i)
7701+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7702+{
7703+ v->counter = i;
7704+}
7705 #define atomic64_set(v, i) (((v)->counter) = i)
7706+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7707+{
7708+ v->counter = i;
7709+}
7710
7711 extern void atomic_add(int, atomic_t *);
7712+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7713 extern void atomic64_add(long, atomic64_t *);
7714+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7715 extern void atomic_sub(int, atomic_t *);
7716+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7717 extern void atomic64_sub(long, atomic64_t *);
7718+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7719
7720 extern int atomic_add_ret(int, atomic_t *);
7721+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7722 extern long atomic64_add_ret(long, atomic64_t *);
7723+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7724 extern int atomic_sub_ret(int, atomic_t *);
7725 extern long atomic64_sub_ret(long, atomic64_t *);
7726
7727@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7728 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7729
7730 #define atomic_inc_return(v) atomic_add_ret(1, v)
7731+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7732+{
7733+ return atomic_add_ret_unchecked(1, v);
7734+}
7735 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7736+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7737+{
7738+ return atomic64_add_ret_unchecked(1, v);
7739+}
7740
7741 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7742 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7743
7744 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7745+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7746+{
7747+ return atomic_add_ret_unchecked(i, v);
7748+}
7749 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7750+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7751+{
7752+ return atomic64_add_ret_unchecked(i, v);
7753+}
7754
7755 /*
7756 * atomic_inc_and_test - increment and test
7757@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7758 * other cases.
7759 */
7760 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7761+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7762+{
7763+ return atomic_inc_return_unchecked(v) == 0;
7764+}
7765 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7766
7767 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7768@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7769 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7770
7771 #define atomic_inc(v) atomic_add(1, v)
7772+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7773+{
7774+ atomic_add_unchecked(1, v);
7775+}
7776 #define atomic64_inc(v) atomic64_add(1, v)
7777+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7778+{
7779+ atomic64_add_unchecked(1, v);
7780+}
7781
7782 #define atomic_dec(v) atomic_sub(1, v)
7783+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7784+{
7785+ atomic_sub_unchecked(1, v);
7786+}
7787 #define atomic64_dec(v) atomic64_sub(1, v)
7788+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7789+{
7790+ atomic64_sub_unchecked(1, v);
7791+}
7792
7793 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7794 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7795
7796 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7797+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7798+{
7799+ return cmpxchg(&v->counter, old, new);
7800+}
7801 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7802+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7803+{
7804+ return xchg(&v->counter, new);
7805+}
7806
7807 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7808 {
7809- int c, old;
7810+ int c, old, new;
7811 c = atomic_read(v);
7812 for (;;) {
7813- if (unlikely(c == (u)))
7814+ if (unlikely(c == u))
7815 break;
7816- old = atomic_cmpxchg((v), c, c + (a));
7817+
7818+ asm volatile("addcc %2, %0, %0\n"
7819+
7820+#ifdef CONFIG_PAX_REFCOUNT
7821+ "tvs %%icc, 6\n"
7822+#endif
7823+
7824+ : "=r" (new)
7825+ : "0" (c), "ir" (a)
7826+ : "cc");
7827+
7828+ old = atomic_cmpxchg(v, c, new);
7829 if (likely(old == c))
7830 break;
7831 c = old;
7832@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7833 #define atomic64_cmpxchg(v, o, n) \
7834 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7835 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7836+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7837+{
7838+ return xchg(&v->counter, new);
7839+}
7840
7841 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7842 {
7843- long c, old;
7844+ long c, old, new;
7845 c = atomic64_read(v);
7846 for (;;) {
7847- if (unlikely(c == (u)))
7848+ if (unlikely(c == u))
7849 break;
7850- old = atomic64_cmpxchg((v), c, c + (a));
7851+
7852+ asm volatile("addcc %2, %0, %0\n"
7853+
7854+#ifdef CONFIG_PAX_REFCOUNT
7855+ "tvs %%xcc, 6\n"
7856+#endif
7857+
7858+ : "=r" (new)
7859+ : "0" (c), "ir" (a)
7860+ : "cc");
7861+
7862+ old = atomic64_cmpxchg(v, c, new);
7863 if (likely(old == c))
7864 break;
7865 c = old;
7866 }
7867- return c != (u);
7868+ return c != u;
7869 }
7870
7871 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7872diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7873index 5bb6991..5c2132e 100644
7874--- a/arch/sparc/include/asm/cache.h
7875+++ b/arch/sparc/include/asm/cache.h
7876@@ -7,10 +7,12 @@
7877 #ifndef _SPARC_CACHE_H
7878 #define _SPARC_CACHE_H
7879
7880+#include <linux/const.h>
7881+
7882 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7883
7884 #define L1_CACHE_SHIFT 5
7885-#define L1_CACHE_BYTES 32
7886+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7887
7888 #ifdef CONFIG_SPARC32
7889 #define SMP_CACHE_BYTES_SHIFT 5
7890diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7891index a24e41f..47677ff 100644
7892--- a/arch/sparc/include/asm/elf_32.h
7893+++ b/arch/sparc/include/asm/elf_32.h
7894@@ -114,6 +114,13 @@ typedef struct {
7895
7896 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7897
7898+#ifdef CONFIG_PAX_ASLR
7899+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7900+
7901+#define PAX_DELTA_MMAP_LEN 16
7902+#define PAX_DELTA_STACK_LEN 16
7903+#endif
7904+
7905 /* This yields a mask that user programs can use to figure out what
7906 instruction set this cpu supports. This can NOT be done in userspace
7907 on Sparc. */
7908diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7909index 370ca1e..d4f4a98 100644
7910--- a/arch/sparc/include/asm/elf_64.h
7911+++ b/arch/sparc/include/asm/elf_64.h
7912@@ -189,6 +189,13 @@ typedef struct {
7913 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7914 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7915
7916+#ifdef CONFIG_PAX_ASLR
7917+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7918+
7919+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7920+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7921+#endif
7922+
7923 extern unsigned long sparc64_elf_hwcap;
7924 #define ELF_HWCAP sparc64_elf_hwcap
7925
7926diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7927index 9b1c36d..209298b 100644
7928--- a/arch/sparc/include/asm/pgalloc_32.h
7929+++ b/arch/sparc/include/asm/pgalloc_32.h
7930@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7931 }
7932
7933 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7934+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7935
7936 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7937 unsigned long address)
7938diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7939index bcfe063..b333142 100644
7940--- a/arch/sparc/include/asm/pgalloc_64.h
7941+++ b/arch/sparc/include/asm/pgalloc_64.h
7942@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7943 }
7944
7945 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7946+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7947
7948 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7949 {
7950diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7951index 6fc1348..390c50a 100644
7952--- a/arch/sparc/include/asm/pgtable_32.h
7953+++ b/arch/sparc/include/asm/pgtable_32.h
7954@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7955 #define PAGE_SHARED SRMMU_PAGE_SHARED
7956 #define PAGE_COPY SRMMU_PAGE_COPY
7957 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7958+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7959+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7960+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7961 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7962
7963 /* Top-level page directory - dummy used by init-mm.
7964@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7965
7966 /* xwr */
7967 #define __P000 PAGE_NONE
7968-#define __P001 PAGE_READONLY
7969-#define __P010 PAGE_COPY
7970-#define __P011 PAGE_COPY
7971+#define __P001 PAGE_READONLY_NOEXEC
7972+#define __P010 PAGE_COPY_NOEXEC
7973+#define __P011 PAGE_COPY_NOEXEC
7974 #define __P100 PAGE_READONLY
7975 #define __P101 PAGE_READONLY
7976 #define __P110 PAGE_COPY
7977 #define __P111 PAGE_COPY
7978
7979 #define __S000 PAGE_NONE
7980-#define __S001 PAGE_READONLY
7981-#define __S010 PAGE_SHARED
7982-#define __S011 PAGE_SHARED
7983+#define __S001 PAGE_READONLY_NOEXEC
7984+#define __S010 PAGE_SHARED_NOEXEC
7985+#define __S011 PAGE_SHARED_NOEXEC
7986 #define __S100 PAGE_READONLY
7987 #define __S101 PAGE_READONLY
7988 #define __S110 PAGE_SHARED
7989diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7990index 79da178..c2eede8 100644
7991--- a/arch/sparc/include/asm/pgtsrmmu.h
7992+++ b/arch/sparc/include/asm/pgtsrmmu.h
7993@@ -115,6 +115,11 @@
7994 SRMMU_EXEC | SRMMU_REF)
7995 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7996 SRMMU_EXEC | SRMMU_REF)
7997+
7998+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7999+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8000+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
8001+
8002 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
8003 SRMMU_DIRTY | SRMMU_REF)
8004
8005diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
8006index 9689176..63c18ea 100644
8007--- a/arch/sparc/include/asm/spinlock_64.h
8008+++ b/arch/sparc/include/asm/spinlock_64.h
8009@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
8010
8011 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
8012
8013-static void inline arch_read_lock(arch_rwlock_t *lock)
8014+static inline void arch_read_lock(arch_rwlock_t *lock)
8015 {
8016 unsigned long tmp1, tmp2;
8017
8018 __asm__ __volatile__ (
8019 "1: ldsw [%2], %0\n"
8020 " brlz,pn %0, 2f\n"
8021-"4: add %0, 1, %1\n"
8022+"4: addcc %0, 1, %1\n"
8023+
8024+#ifdef CONFIG_PAX_REFCOUNT
8025+" tvs %%icc, 6\n"
8026+#endif
8027+
8028 " cas [%2], %0, %1\n"
8029 " cmp %0, %1\n"
8030 " bne,pn %%icc, 1b\n"
8031@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8032 " .previous"
8033 : "=&r" (tmp1), "=&r" (tmp2)
8034 : "r" (lock)
8035- : "memory");
8036+ : "memory", "cc");
8037 }
8038
8039-static int inline arch_read_trylock(arch_rwlock_t *lock)
8040+static inline int arch_read_trylock(arch_rwlock_t *lock)
8041 {
8042 int tmp1, tmp2;
8043
8044@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8045 "1: ldsw [%2], %0\n"
8046 " brlz,a,pn %0, 2f\n"
8047 " mov 0, %0\n"
8048-" add %0, 1, %1\n"
8049+" addcc %0, 1, %1\n"
8050+
8051+#ifdef CONFIG_PAX_REFCOUNT
8052+" tvs %%icc, 6\n"
8053+#endif
8054+
8055 " cas [%2], %0, %1\n"
8056 " cmp %0, %1\n"
8057 " bne,pn %%icc, 1b\n"
8058@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8059 return tmp1;
8060 }
8061
8062-static void inline arch_read_unlock(arch_rwlock_t *lock)
8063+static inline void arch_read_unlock(arch_rwlock_t *lock)
8064 {
8065 unsigned long tmp1, tmp2;
8066
8067 __asm__ __volatile__(
8068 "1: lduw [%2], %0\n"
8069-" sub %0, 1, %1\n"
8070+" subcc %0, 1, %1\n"
8071+
8072+#ifdef CONFIG_PAX_REFCOUNT
8073+" tvs %%icc, 6\n"
8074+#endif
8075+
8076 " cas [%2], %0, %1\n"
8077 " cmp %0, %1\n"
8078 " bne,pn %%xcc, 1b\n"
8079@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8080 : "memory");
8081 }
8082
8083-static void inline arch_write_lock(arch_rwlock_t *lock)
8084+static inline void arch_write_lock(arch_rwlock_t *lock)
8085 {
8086 unsigned long mask, tmp1, tmp2;
8087
8088@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8089 : "memory");
8090 }
8091
8092-static void inline arch_write_unlock(arch_rwlock_t *lock)
8093+static inline void arch_write_unlock(arch_rwlock_t *lock)
8094 {
8095 __asm__ __volatile__(
8096 " stw %%g0, [%0]"
8097@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8098 : "memory");
8099 }
8100
8101-static int inline arch_write_trylock(arch_rwlock_t *lock)
8102+static inline int arch_write_trylock(arch_rwlock_t *lock)
8103 {
8104 unsigned long mask, tmp1, tmp2, result;
8105
8106diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8107index dd38075..e7cac83 100644
8108--- a/arch/sparc/include/asm/thread_info_32.h
8109+++ b/arch/sparc/include/asm/thread_info_32.h
8110@@ -49,6 +49,8 @@ struct thread_info {
8111 unsigned long w_saved;
8112
8113 struct restart_block restart_block;
8114+
8115+ unsigned long lowest_stack;
8116 };
8117
8118 /*
8119diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8120index d5e5042..9bfee76 100644
8121--- a/arch/sparc/include/asm/thread_info_64.h
8122+++ b/arch/sparc/include/asm/thread_info_64.h
8123@@ -63,6 +63,8 @@ struct thread_info {
8124 struct pt_regs *kern_una_regs;
8125 unsigned int kern_una_insn;
8126
8127+ unsigned long lowest_stack;
8128+
8129 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8130 };
8131
8132@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8133 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8134 /* flag bit 6 is available */
8135 #define TIF_32BIT 7 /* 32-bit binary */
8136-/* flag bit 8 is available */
8137+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8138 #define TIF_SECCOMP 9 /* secure computing */
8139 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8140 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8141+
8142 /* NOTE: Thread flags >= 12 should be ones we have no interest
8143 * in using in assembly, else we can't use the mask as
8144 * an immediate value in instructions such as andcc.
8145@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8146 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8147 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8148 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8149+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8150
8151 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8152 _TIF_DO_NOTIFY_RESUME_MASK | \
8153 _TIF_NEED_RESCHED)
8154 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8155
8156+#define _TIF_WORK_SYSCALL \
8157+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8158+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8159+
8160+
8161 /*
8162 * Thread-synchronous status.
8163 *
8164diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8165index 0167d26..767bb0c 100644
8166--- a/arch/sparc/include/asm/uaccess.h
8167+++ b/arch/sparc/include/asm/uaccess.h
8168@@ -1,5 +1,6 @@
8169 #ifndef ___ASM_SPARC_UACCESS_H
8170 #define ___ASM_SPARC_UACCESS_H
8171+
8172 #if defined(__sparc__) && defined(__arch64__)
8173 #include <asm/uaccess_64.h>
8174 #else
8175diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8176index 53a28dd..50c38c3 100644
8177--- a/arch/sparc/include/asm/uaccess_32.h
8178+++ b/arch/sparc/include/asm/uaccess_32.h
8179@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8180
8181 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8182 {
8183- if (n && __access_ok((unsigned long) to, n))
8184+ if ((long)n < 0)
8185+ return n;
8186+
8187+ if (n && __access_ok((unsigned long) to, n)) {
8188+ if (!__builtin_constant_p(n))
8189+ check_object_size(from, n, true);
8190 return __copy_user(to, (__force void __user *) from, n);
8191- else
8192+ } else
8193 return n;
8194 }
8195
8196 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8197 {
8198+ if ((long)n < 0)
8199+ return n;
8200+
8201+ if (!__builtin_constant_p(n))
8202+ check_object_size(from, n, true);
8203+
8204 return __copy_user(to, (__force void __user *) from, n);
8205 }
8206
8207 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8208 {
8209- if (n && __access_ok((unsigned long) from, n))
8210+ if ((long)n < 0)
8211+ return n;
8212+
8213+ if (n && __access_ok((unsigned long) from, n)) {
8214+ if (!__builtin_constant_p(n))
8215+ check_object_size(to, n, false);
8216 return __copy_user((__force void __user *) to, from, n);
8217- else
8218+ } else
8219 return n;
8220 }
8221
8222 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8223 {
8224+ if ((long)n < 0)
8225+ return n;
8226+
8227 return __copy_user((__force void __user *) to, from, n);
8228 }
8229
8230diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8231index e562d3c..191f176 100644
8232--- a/arch/sparc/include/asm/uaccess_64.h
8233+++ b/arch/sparc/include/asm/uaccess_64.h
8234@@ -10,6 +10,7 @@
8235 #include <linux/compiler.h>
8236 #include <linux/string.h>
8237 #include <linux/thread_info.h>
8238+#include <linux/kernel.h>
8239 #include <asm/asi.h>
8240 #include <asm/spitfire.h>
8241 #include <asm-generic/uaccess-unaligned.h>
8242@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8243 static inline unsigned long __must_check
8244 copy_from_user(void *to, const void __user *from, unsigned long size)
8245 {
8246- unsigned long ret = ___copy_from_user(to, from, size);
8247+ unsigned long ret;
8248
8249+ if ((long)size < 0 || size > INT_MAX)
8250+ return size;
8251+
8252+ if (!__builtin_constant_p(size))
8253+ check_object_size(to, size, false);
8254+
8255+ ret = ___copy_from_user(to, from, size);
8256 if (unlikely(ret))
8257 ret = copy_from_user_fixup(to, from, size);
8258
8259@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8260 static inline unsigned long __must_check
8261 copy_to_user(void __user *to, const void *from, unsigned long size)
8262 {
8263- unsigned long ret = ___copy_to_user(to, from, size);
8264+ unsigned long ret;
8265
8266+ if ((long)size < 0 || size > INT_MAX)
8267+ return size;
8268+
8269+ if (!__builtin_constant_p(size))
8270+ check_object_size(from, size, true);
8271+
8272+ ret = ___copy_to_user(to, from, size);
8273 if (unlikely(ret))
8274 ret = copy_to_user_fixup(to, from, size);
8275 return ret;
8276diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8277index d432fb2..6056af1 100644
8278--- a/arch/sparc/kernel/Makefile
8279+++ b/arch/sparc/kernel/Makefile
8280@@ -3,7 +3,7 @@
8281 #
8282
8283 asflags-y := -ansi
8284-ccflags-y := -Werror
8285+#ccflags-y := -Werror
8286
8287 extra-y := head_$(BITS).o
8288
8289diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
8290index 5ef48da..11d460f 100644
8291--- a/arch/sparc/kernel/ds.c
8292+++ b/arch/sparc/kernel/ds.c
8293@@ -783,6 +783,16 @@ void ldom_set_var(const char *var, const char *value)
8294 char *base, *p;
8295 int msg_len, loops;
8296
8297+ if (strlen(var) + strlen(value) + 2 >
8298+ sizeof(pkt) - sizeof(pkt.header)) {
8299+ printk(KERN_ERR PFX
8300+ "contents length: %zu, which more than max: %lu,"
8301+ "so could not set (%s) variable to (%s).\n",
8302+ strlen(var) + strlen(value) + 2,
8303+ sizeof(pkt) - sizeof(pkt.header), var, value);
8304+ return;
8305+ }
8306+
8307 memset(&pkt, 0, sizeof(pkt));
8308 pkt.header.data.tag.type = DS_DATA;
8309 pkt.header.data.handle = cp->handle;
8310diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8311index fdd819d..5af08c8 100644
8312--- a/arch/sparc/kernel/process_32.c
8313+++ b/arch/sparc/kernel/process_32.c
8314@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
8315
8316 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8317 r->psr, r->pc, r->npc, r->y, print_tainted());
8318- printk("PC: <%pS>\n", (void *) r->pc);
8319+ printk("PC: <%pA>\n", (void *) r->pc);
8320 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8321 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8322 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8323 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8324 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8325 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8326- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8327+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8328
8329 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8330 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8331@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8332 rw = (struct reg_window32 *) fp;
8333 pc = rw->ins[7];
8334 printk("[%08lx : ", pc);
8335- printk("%pS ] ", (void *) pc);
8336+ printk("%pA ] ", (void *) pc);
8337 fp = rw->ins[6];
8338 } while (++count < 16);
8339 printk("\n");
8340diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8341index baebab2..9cd13b1 100644
8342--- a/arch/sparc/kernel/process_64.c
8343+++ b/arch/sparc/kernel/process_64.c
8344@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
8345 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8346 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8347 if (regs->tstate & TSTATE_PRIV)
8348- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8349+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8350 }
8351
8352 void show_regs(struct pt_regs *regs)
8353@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
8354
8355 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8356 regs->tpc, regs->tnpc, regs->y, print_tainted());
8357- printk("TPC: <%pS>\n", (void *) regs->tpc);
8358+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8359 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8360 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8361 regs->u_regs[3]);
8362@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
8363 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8364 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8365 regs->u_regs[15]);
8366- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8367+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8368 show_regwindow(regs);
8369 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8370 }
8371@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
8372 ((tp && tp->task) ? tp->task->pid : -1));
8373
8374 if (gp->tstate & TSTATE_PRIV) {
8375- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8376+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8377 (void *) gp->tpc,
8378 (void *) gp->o7,
8379 (void *) gp->i7,
8380diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8381index 79cc0d1..ec62734 100644
8382--- a/arch/sparc/kernel/prom_common.c
8383+++ b/arch/sparc/kernel/prom_common.c
8384@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8385
8386 unsigned int prom_early_allocated __initdata;
8387
8388-static struct of_pdt_ops prom_sparc_ops __initdata = {
8389+static struct of_pdt_ops prom_sparc_ops __initconst = {
8390 .nextprop = prom_common_nextprop,
8391 .getproplen = prom_getproplen,
8392 .getproperty = prom_getproperty,
8393diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8394index 7ff45e4..a58f271 100644
8395--- a/arch/sparc/kernel/ptrace_64.c
8396+++ b/arch/sparc/kernel/ptrace_64.c
8397@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8398 return ret;
8399 }
8400
8401+#ifdef CONFIG_GRKERNSEC_SETXID
8402+extern void gr_delayed_cred_worker(void);
8403+#endif
8404+
8405 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8406 {
8407 int ret = 0;
8408@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8409 /* do the secure computing check first */
8410 secure_computing_strict(regs->u_regs[UREG_G1]);
8411
8412+#ifdef CONFIG_GRKERNSEC_SETXID
8413+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8414+ gr_delayed_cred_worker();
8415+#endif
8416+
8417 if (test_thread_flag(TIF_SYSCALL_TRACE))
8418 ret = tracehook_report_syscall_entry(regs);
8419
8420@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8421
8422 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8423 {
8424+#ifdef CONFIG_GRKERNSEC_SETXID
8425+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8426+ gr_delayed_cred_worker();
8427+#endif
8428+
8429 audit_syscall_exit(regs);
8430
8431 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8432diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8433index 3a8d184..49498a8 100644
8434--- a/arch/sparc/kernel/sys_sparc_32.c
8435+++ b/arch/sparc/kernel/sys_sparc_32.c
8436@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8437 if (len > TASK_SIZE - PAGE_SIZE)
8438 return -ENOMEM;
8439 if (!addr)
8440- addr = TASK_UNMAPPED_BASE;
8441+ addr = current->mm->mmap_base;
8442
8443 info.flags = 0;
8444 info.length = len;
8445diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8446index 2daaaa6..4fb84dc 100644
8447--- a/arch/sparc/kernel/sys_sparc_64.c
8448+++ b/arch/sparc/kernel/sys_sparc_64.c
8449@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8450 struct vm_area_struct * vma;
8451 unsigned long task_size = TASK_SIZE;
8452 int do_color_align;
8453+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8454 struct vm_unmapped_area_info info;
8455
8456 if (flags & MAP_FIXED) {
8457 /* We do not accept a shared mapping if it would violate
8458 * cache aliasing constraints.
8459 */
8460- if ((flags & MAP_SHARED) &&
8461+ if ((filp || (flags & MAP_SHARED)) &&
8462 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8463 return -EINVAL;
8464 return addr;
8465@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8466 if (filp || (flags & MAP_SHARED))
8467 do_color_align = 1;
8468
8469+#ifdef CONFIG_PAX_RANDMMAP
8470+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8471+#endif
8472+
8473 if (addr) {
8474 if (do_color_align)
8475 addr = COLOR_ALIGN(addr, pgoff);
8476@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8477 addr = PAGE_ALIGN(addr);
8478
8479 vma = find_vma(mm, addr);
8480- if (task_size - len >= addr &&
8481- (!vma || addr + len <= vma->vm_start))
8482+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8483 return addr;
8484 }
8485
8486 info.flags = 0;
8487 info.length = len;
8488- info.low_limit = TASK_UNMAPPED_BASE;
8489+ info.low_limit = mm->mmap_base;
8490 info.high_limit = min(task_size, VA_EXCLUDE_START);
8491 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8492 info.align_offset = pgoff << PAGE_SHIFT;
8493+ info.threadstack_offset = offset;
8494 addr = vm_unmapped_area(&info);
8495
8496 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8497 VM_BUG_ON(addr != -ENOMEM);
8498 info.low_limit = VA_EXCLUDE_END;
8499+
8500+#ifdef CONFIG_PAX_RANDMMAP
8501+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8502+ info.low_limit += mm->delta_mmap;
8503+#endif
8504+
8505 info.high_limit = task_size;
8506 addr = vm_unmapped_area(&info);
8507 }
8508@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8509 unsigned long task_size = STACK_TOP32;
8510 unsigned long addr = addr0;
8511 int do_color_align;
8512+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8513 struct vm_unmapped_area_info info;
8514
8515 /* This should only ever run for 32-bit processes. */
8516@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8517 /* We do not accept a shared mapping if it would violate
8518 * cache aliasing constraints.
8519 */
8520- if ((flags & MAP_SHARED) &&
8521+ if ((filp || (flags & MAP_SHARED)) &&
8522 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8523 return -EINVAL;
8524 return addr;
8525@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8526 if (filp || (flags & MAP_SHARED))
8527 do_color_align = 1;
8528
8529+#ifdef CONFIG_PAX_RANDMMAP
8530+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8531+#endif
8532+
8533 /* requesting a specific address */
8534 if (addr) {
8535 if (do_color_align)
8536@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8537 addr = PAGE_ALIGN(addr);
8538
8539 vma = find_vma(mm, addr);
8540- if (task_size - len >= addr &&
8541- (!vma || addr + len <= vma->vm_start))
8542+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8543 return addr;
8544 }
8545
8546@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8547 info.high_limit = mm->mmap_base;
8548 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8549 info.align_offset = pgoff << PAGE_SHIFT;
8550+ info.threadstack_offset = offset;
8551 addr = vm_unmapped_area(&info);
8552
8553 /*
8554@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8555 VM_BUG_ON(addr != -ENOMEM);
8556 info.flags = 0;
8557 info.low_limit = TASK_UNMAPPED_BASE;
8558+
8559+#ifdef CONFIG_PAX_RANDMMAP
8560+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8561+ info.low_limit += mm->delta_mmap;
8562+#endif
8563+
8564 info.high_limit = STACK_TOP32;
8565 addr = vm_unmapped_area(&info);
8566 }
8567@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
8568 EXPORT_SYMBOL(get_fb_unmapped_area);
8569
8570 /* Essentially the same as PowerPC. */
8571-static unsigned long mmap_rnd(void)
8572+static unsigned long mmap_rnd(struct mm_struct *mm)
8573 {
8574 unsigned long rnd = 0UL;
8575
8576+#ifdef CONFIG_PAX_RANDMMAP
8577+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8578+#endif
8579+
8580 if (current->flags & PF_RANDOMIZE) {
8581 unsigned long val = get_random_int();
8582 if (test_thread_flag(TIF_32BIT))
8583@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
8584
8585 void arch_pick_mmap_layout(struct mm_struct *mm)
8586 {
8587- unsigned long random_factor = mmap_rnd();
8588+ unsigned long random_factor = mmap_rnd(mm);
8589 unsigned long gap;
8590
8591 /*
8592@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8593 gap == RLIM_INFINITY ||
8594 sysctl_legacy_va_layout) {
8595 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8596+
8597+#ifdef CONFIG_PAX_RANDMMAP
8598+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8599+ mm->mmap_base += mm->delta_mmap;
8600+#endif
8601+
8602 mm->get_unmapped_area = arch_get_unmapped_area;
8603 mm->unmap_area = arch_unmap_area;
8604 } else {
8605@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8606 gap = (task_size / 6 * 5);
8607
8608 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8609+
8610+#ifdef CONFIG_PAX_RANDMMAP
8611+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8612+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8613+#endif
8614+
8615 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8616 mm->unmap_area = arch_unmap_area_topdown;
8617 }
8618diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8619index 22a1098..6255eb9 100644
8620--- a/arch/sparc/kernel/syscalls.S
8621+++ b/arch/sparc/kernel/syscalls.S
8622@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
8623 #endif
8624 .align 32
8625 1: ldx [%g6 + TI_FLAGS], %l5
8626- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8627+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8628 be,pt %icc, rtrap
8629 nop
8630 call syscall_trace_leave
8631@@ -184,7 +184,7 @@ linux_sparc_syscall32:
8632
8633 srl %i5, 0, %o5 ! IEU1
8634 srl %i2, 0, %o2 ! IEU0 Group
8635- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8636+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8637 bne,pn %icc, linux_syscall_trace32 ! CTI
8638 mov %i0, %l5 ! IEU1
8639 call %l7 ! CTI Group brk forced
8640@@ -207,7 +207,7 @@ linux_sparc_syscall:
8641
8642 mov %i3, %o3 ! IEU1
8643 mov %i4, %o4 ! IEU0 Group
8644- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8645+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8646 bne,pn %icc, linux_syscall_trace ! CTI Group
8647 mov %i0, %l5 ! IEU0
8648 2: call %l7 ! CTI Group brk forced
8649@@ -223,7 +223,7 @@ ret_sys_call:
8650
8651 cmp %o0, -ERESTART_RESTARTBLOCK
8652 bgeu,pn %xcc, 1f
8653- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8654+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8655 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8656
8657 2:
8658diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8659index 654e8aa..45f431b 100644
8660--- a/arch/sparc/kernel/sysfs.c
8661+++ b/arch/sparc/kernel/sysfs.c
8662@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8663 return NOTIFY_OK;
8664 }
8665
8666-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8667+static struct notifier_block sysfs_cpu_nb = {
8668 .notifier_call = sysfs_cpu_notify,
8669 };
8670
8671diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8672index 6629829..036032d 100644
8673--- a/arch/sparc/kernel/traps_32.c
8674+++ b/arch/sparc/kernel/traps_32.c
8675@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8676 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8677 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8678
8679+extern void gr_handle_kernel_exploit(void);
8680+
8681 void die_if_kernel(char *str, struct pt_regs *regs)
8682 {
8683 static int die_counter;
8684@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8685 count++ < 30 &&
8686 (((unsigned long) rw) >= PAGE_OFFSET) &&
8687 !(((unsigned long) rw) & 0x7)) {
8688- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8689+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8690 (void *) rw->ins[7]);
8691 rw = (struct reg_window32 *)rw->ins[6];
8692 }
8693 }
8694 printk("Instruction DUMP:");
8695 instruction_dump ((unsigned long *) regs->pc);
8696- if(regs->psr & PSR_PS)
8697+ if(regs->psr & PSR_PS) {
8698+ gr_handle_kernel_exploit();
8699 do_exit(SIGKILL);
8700+ }
8701 do_exit(SIGSEGV);
8702 }
8703
8704diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8705index b3f833a..ac74b2d 100644
8706--- a/arch/sparc/kernel/traps_64.c
8707+++ b/arch/sparc/kernel/traps_64.c
8708@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8709 i + 1,
8710 p->trapstack[i].tstate, p->trapstack[i].tpc,
8711 p->trapstack[i].tnpc, p->trapstack[i].tt);
8712- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8713+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8714 }
8715 }
8716
8717@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8718
8719 lvl -= 0x100;
8720 if (regs->tstate & TSTATE_PRIV) {
8721+
8722+#ifdef CONFIG_PAX_REFCOUNT
8723+ if (lvl == 6)
8724+ pax_report_refcount_overflow(regs);
8725+#endif
8726+
8727 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8728 die_if_kernel(buffer, regs);
8729 }
8730@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8731 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8732 {
8733 char buffer[32];
8734-
8735+
8736 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8737 0, lvl, SIGTRAP) == NOTIFY_STOP)
8738 return;
8739
8740+#ifdef CONFIG_PAX_REFCOUNT
8741+ if (lvl == 6)
8742+ pax_report_refcount_overflow(regs);
8743+#endif
8744+
8745 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8746
8747 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8748@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8749 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8750 printk("%s" "ERROR(%d): ",
8751 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8752- printk("TPC<%pS>\n", (void *) regs->tpc);
8753+ printk("TPC<%pA>\n", (void *) regs->tpc);
8754 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8755 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8756 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8757@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8758 smp_processor_id(),
8759 (type & 0x1) ? 'I' : 'D',
8760 regs->tpc);
8761- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8762+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8763 panic("Irrecoverable Cheetah+ parity error.");
8764 }
8765
8766@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8767 smp_processor_id(),
8768 (type & 0x1) ? 'I' : 'D',
8769 regs->tpc);
8770- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8771+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8772 }
8773
8774 struct sun4v_error_entry {
8775@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8776
8777 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8778 regs->tpc, tl);
8779- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8780+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8781 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8782- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8783+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8784 (void *) regs->u_regs[UREG_I7]);
8785 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8786 "pte[%lx] error[%lx]\n",
8787@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8788
8789 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8790 regs->tpc, tl);
8791- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8792+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8793 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8794- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8795+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8796 (void *) regs->u_regs[UREG_I7]);
8797 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8798 "pte[%lx] error[%lx]\n",
8799@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8800 fp = (unsigned long)sf->fp + STACK_BIAS;
8801 }
8802
8803- printk(" [%016lx] %pS\n", pc, (void *) pc);
8804+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8805 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8806 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8807 int index = tsk->curr_ret_stack;
8808 if (tsk->ret_stack && index >= graph) {
8809 pc = tsk->ret_stack[index - graph].ret;
8810- printk(" [%016lx] %pS\n", pc, (void *) pc);
8811+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8812 graph++;
8813 }
8814 }
8815@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8816 return (struct reg_window *) (fp + STACK_BIAS);
8817 }
8818
8819+extern void gr_handle_kernel_exploit(void);
8820+
8821 void die_if_kernel(char *str, struct pt_regs *regs)
8822 {
8823 static int die_counter;
8824@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8825 while (rw &&
8826 count++ < 30 &&
8827 kstack_valid(tp, (unsigned long) rw)) {
8828- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8829+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8830 (void *) rw->ins[7]);
8831
8832 rw = kernel_stack_up(rw);
8833@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8834 }
8835 user_instruction_dump ((unsigned int __user *) regs->tpc);
8836 }
8837- if (regs->tstate & TSTATE_PRIV)
8838+ if (regs->tstate & TSTATE_PRIV) {
8839+ gr_handle_kernel_exploit();
8840 do_exit(SIGKILL);
8841+ }
8842 do_exit(SIGSEGV);
8843 }
8844 EXPORT_SYMBOL(die_if_kernel);
8845diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8846index 8201c25e..072a2a7 100644
8847--- a/arch/sparc/kernel/unaligned_64.c
8848+++ b/arch/sparc/kernel/unaligned_64.c
8849@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8850 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8851
8852 if (__ratelimit(&ratelimit)) {
8853- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8854+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8855 regs->tpc, (void *) regs->tpc);
8856 }
8857 }
8858diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8859index dbe119b..089c7c1 100644
8860--- a/arch/sparc/lib/Makefile
8861+++ b/arch/sparc/lib/Makefile
8862@@ -2,7 +2,7 @@
8863 #
8864
8865 asflags-y := -ansi -DST_DIV0=0x02
8866-ccflags-y := -Werror
8867+#ccflags-y := -Werror
8868
8869 lib-$(CONFIG_SPARC32) += ashrdi3.o
8870 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8871diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8872index 85c233d..68500e0 100644
8873--- a/arch/sparc/lib/atomic_64.S
8874+++ b/arch/sparc/lib/atomic_64.S
8875@@ -17,7 +17,12 @@
8876 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8877 BACKOFF_SETUP(%o2)
8878 1: lduw [%o1], %g1
8879- add %g1, %o0, %g7
8880+ addcc %g1, %o0, %g7
8881+
8882+#ifdef CONFIG_PAX_REFCOUNT
8883+ tvs %icc, 6
8884+#endif
8885+
8886 cas [%o1], %g1, %g7
8887 cmp %g1, %g7
8888 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8889@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8890 2: BACKOFF_SPIN(%o2, %o3, 1b)
8891 ENDPROC(atomic_add)
8892
8893+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8894+ BACKOFF_SETUP(%o2)
8895+1: lduw [%o1], %g1
8896+ add %g1, %o0, %g7
8897+ cas [%o1], %g1, %g7
8898+ cmp %g1, %g7
8899+ bne,pn %icc, 2f
8900+ nop
8901+ retl
8902+ nop
8903+2: BACKOFF_SPIN(%o2, %o3, 1b)
8904+ENDPROC(atomic_add_unchecked)
8905+
8906 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8907 BACKOFF_SETUP(%o2)
8908 1: lduw [%o1], %g1
8909- sub %g1, %o0, %g7
8910+ subcc %g1, %o0, %g7
8911+
8912+#ifdef CONFIG_PAX_REFCOUNT
8913+ tvs %icc, 6
8914+#endif
8915+
8916 cas [%o1], %g1, %g7
8917 cmp %g1, %g7
8918 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8919@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8920 2: BACKOFF_SPIN(%o2, %o3, 1b)
8921 ENDPROC(atomic_sub)
8922
8923+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8924+ BACKOFF_SETUP(%o2)
8925+1: lduw [%o1], %g1
8926+ sub %g1, %o0, %g7
8927+ cas [%o1], %g1, %g7
8928+ cmp %g1, %g7
8929+ bne,pn %icc, 2f
8930+ nop
8931+ retl
8932+ nop
8933+2: BACKOFF_SPIN(%o2, %o3, 1b)
8934+ENDPROC(atomic_sub_unchecked)
8935+
8936 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8937 BACKOFF_SETUP(%o2)
8938 1: lduw [%o1], %g1
8939- add %g1, %o0, %g7
8940+ addcc %g1, %o0, %g7
8941+
8942+#ifdef CONFIG_PAX_REFCOUNT
8943+ tvs %icc, 6
8944+#endif
8945+
8946 cas [%o1], %g1, %g7
8947 cmp %g1, %g7
8948 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8949@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8950 2: BACKOFF_SPIN(%o2, %o3, 1b)
8951 ENDPROC(atomic_add_ret)
8952
8953+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8954+ BACKOFF_SETUP(%o2)
8955+1: lduw [%o1], %g1
8956+ addcc %g1, %o0, %g7
8957+ cas [%o1], %g1, %g7
8958+ cmp %g1, %g7
8959+ bne,pn %icc, 2f
8960+ add %g7, %o0, %g7
8961+ sra %g7, 0, %o0
8962+ retl
8963+ nop
8964+2: BACKOFF_SPIN(%o2, %o3, 1b)
8965+ENDPROC(atomic_add_ret_unchecked)
8966+
8967 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8968 BACKOFF_SETUP(%o2)
8969 1: lduw [%o1], %g1
8970- sub %g1, %o0, %g7
8971+ subcc %g1, %o0, %g7
8972+
8973+#ifdef CONFIG_PAX_REFCOUNT
8974+ tvs %icc, 6
8975+#endif
8976+
8977 cas [%o1], %g1, %g7
8978 cmp %g1, %g7
8979 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8980@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8981 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8982 BACKOFF_SETUP(%o2)
8983 1: ldx [%o1], %g1
8984- add %g1, %o0, %g7
8985+ addcc %g1, %o0, %g7
8986+
8987+#ifdef CONFIG_PAX_REFCOUNT
8988+ tvs %xcc, 6
8989+#endif
8990+
8991 casx [%o1], %g1, %g7
8992 cmp %g1, %g7
8993 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8994@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8995 2: BACKOFF_SPIN(%o2, %o3, 1b)
8996 ENDPROC(atomic64_add)
8997
8998+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8999+ BACKOFF_SETUP(%o2)
9000+1: ldx [%o1], %g1
9001+ addcc %g1, %o0, %g7
9002+ casx [%o1], %g1, %g7
9003+ cmp %g1, %g7
9004+ bne,pn %xcc, 2f
9005+ nop
9006+ retl
9007+ nop
9008+2: BACKOFF_SPIN(%o2, %o3, 1b)
9009+ENDPROC(atomic64_add_unchecked)
9010+
9011 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9012 BACKOFF_SETUP(%o2)
9013 1: ldx [%o1], %g1
9014- sub %g1, %o0, %g7
9015+ subcc %g1, %o0, %g7
9016+
9017+#ifdef CONFIG_PAX_REFCOUNT
9018+ tvs %xcc, 6
9019+#endif
9020+
9021 casx [%o1], %g1, %g7
9022 cmp %g1, %g7
9023 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9024@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9025 2: BACKOFF_SPIN(%o2, %o3, 1b)
9026 ENDPROC(atomic64_sub)
9027
9028+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9029+ BACKOFF_SETUP(%o2)
9030+1: ldx [%o1], %g1
9031+ subcc %g1, %o0, %g7
9032+ casx [%o1], %g1, %g7
9033+ cmp %g1, %g7
9034+ bne,pn %xcc, 2f
9035+ nop
9036+ retl
9037+ nop
9038+2: BACKOFF_SPIN(%o2, %o3, 1b)
9039+ENDPROC(atomic64_sub_unchecked)
9040+
9041 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9042 BACKOFF_SETUP(%o2)
9043 1: ldx [%o1], %g1
9044- add %g1, %o0, %g7
9045+ addcc %g1, %o0, %g7
9046+
9047+#ifdef CONFIG_PAX_REFCOUNT
9048+ tvs %xcc, 6
9049+#endif
9050+
9051 casx [%o1], %g1, %g7
9052 cmp %g1, %g7
9053 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9054@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9055 2: BACKOFF_SPIN(%o2, %o3, 1b)
9056 ENDPROC(atomic64_add_ret)
9057
9058+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9059+ BACKOFF_SETUP(%o2)
9060+1: ldx [%o1], %g1
9061+ addcc %g1, %o0, %g7
9062+ casx [%o1], %g1, %g7
9063+ cmp %g1, %g7
9064+ bne,pn %xcc, 2f
9065+ add %g7, %o0, %g7
9066+ mov %g7, %o0
9067+ retl
9068+ nop
9069+2: BACKOFF_SPIN(%o2, %o3, 1b)
9070+ENDPROC(atomic64_add_ret_unchecked)
9071+
9072 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9073 BACKOFF_SETUP(%o2)
9074 1: ldx [%o1], %g1
9075- sub %g1, %o0, %g7
9076+ subcc %g1, %o0, %g7
9077+
9078+#ifdef CONFIG_PAX_REFCOUNT
9079+ tvs %xcc, 6
9080+#endif
9081+
9082 casx [%o1], %g1, %g7
9083 cmp %g1, %g7
9084 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9085diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9086index 0c4e35e..745d3e4 100644
9087--- a/arch/sparc/lib/ksyms.c
9088+++ b/arch/sparc/lib/ksyms.c
9089@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9090
9091 /* Atomic counter implementation. */
9092 EXPORT_SYMBOL(atomic_add);
9093+EXPORT_SYMBOL(atomic_add_unchecked);
9094 EXPORT_SYMBOL(atomic_add_ret);
9095+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9096 EXPORT_SYMBOL(atomic_sub);
9097+EXPORT_SYMBOL(atomic_sub_unchecked);
9098 EXPORT_SYMBOL(atomic_sub_ret);
9099 EXPORT_SYMBOL(atomic64_add);
9100+EXPORT_SYMBOL(atomic64_add_unchecked);
9101 EXPORT_SYMBOL(atomic64_add_ret);
9102+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9103 EXPORT_SYMBOL(atomic64_sub);
9104+EXPORT_SYMBOL(atomic64_sub_unchecked);
9105 EXPORT_SYMBOL(atomic64_sub_ret);
9106 EXPORT_SYMBOL(atomic64_dec_if_positive);
9107
9108diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9109index 30c3ecc..736f015 100644
9110--- a/arch/sparc/mm/Makefile
9111+++ b/arch/sparc/mm/Makefile
9112@@ -2,7 +2,7 @@
9113 #
9114
9115 asflags-y := -ansi
9116-ccflags-y := -Werror
9117+#ccflags-y := -Werror
9118
9119 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9120 obj-y += fault_$(BITS).o
9121diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9122index e98bfda..ea8d221 100644
9123--- a/arch/sparc/mm/fault_32.c
9124+++ b/arch/sparc/mm/fault_32.c
9125@@ -21,6 +21,9 @@
9126 #include <linux/perf_event.h>
9127 #include <linux/interrupt.h>
9128 #include <linux/kdebug.h>
9129+#include <linux/slab.h>
9130+#include <linux/pagemap.h>
9131+#include <linux/compiler.h>
9132
9133 #include <asm/page.h>
9134 #include <asm/pgtable.h>
9135@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9136 return safe_compute_effective_address(regs, insn);
9137 }
9138
9139+#ifdef CONFIG_PAX_PAGEEXEC
9140+#ifdef CONFIG_PAX_DLRESOLVE
9141+static void pax_emuplt_close(struct vm_area_struct *vma)
9142+{
9143+ vma->vm_mm->call_dl_resolve = 0UL;
9144+}
9145+
9146+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9147+{
9148+ unsigned int *kaddr;
9149+
9150+ vmf->page = alloc_page(GFP_HIGHUSER);
9151+ if (!vmf->page)
9152+ return VM_FAULT_OOM;
9153+
9154+ kaddr = kmap(vmf->page);
9155+ memset(kaddr, 0, PAGE_SIZE);
9156+ kaddr[0] = 0x9DE3BFA8U; /* save */
9157+ flush_dcache_page(vmf->page);
9158+ kunmap(vmf->page);
9159+ return VM_FAULT_MAJOR;
9160+}
9161+
9162+static const struct vm_operations_struct pax_vm_ops = {
9163+ .close = pax_emuplt_close,
9164+ .fault = pax_emuplt_fault
9165+};
9166+
9167+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9168+{
9169+ int ret;
9170+
9171+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9172+ vma->vm_mm = current->mm;
9173+ vma->vm_start = addr;
9174+ vma->vm_end = addr + PAGE_SIZE;
9175+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9176+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9177+ vma->vm_ops = &pax_vm_ops;
9178+
9179+ ret = insert_vm_struct(current->mm, vma);
9180+ if (ret)
9181+ return ret;
9182+
9183+ ++current->mm->total_vm;
9184+ return 0;
9185+}
9186+#endif
9187+
9188+/*
9189+ * PaX: decide what to do with offenders (regs->pc = fault address)
9190+ *
9191+ * returns 1 when task should be killed
9192+ * 2 when patched PLT trampoline was detected
9193+ * 3 when unpatched PLT trampoline was detected
9194+ */
9195+static int pax_handle_fetch_fault(struct pt_regs *regs)
9196+{
9197+
9198+#ifdef CONFIG_PAX_EMUPLT
9199+ int err;
9200+
9201+ do { /* PaX: patched PLT emulation #1 */
9202+ unsigned int sethi1, sethi2, jmpl;
9203+
9204+ err = get_user(sethi1, (unsigned int *)regs->pc);
9205+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9206+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9207+
9208+ if (err)
9209+ break;
9210+
9211+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9212+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9213+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9214+ {
9215+ unsigned int addr;
9216+
9217+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9218+ addr = regs->u_regs[UREG_G1];
9219+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9220+ regs->pc = addr;
9221+ regs->npc = addr+4;
9222+ return 2;
9223+ }
9224+ } while (0);
9225+
9226+ do { /* PaX: patched PLT emulation #2 */
9227+ unsigned int ba;
9228+
9229+ err = get_user(ba, (unsigned int *)regs->pc);
9230+
9231+ if (err)
9232+ break;
9233+
9234+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9235+ unsigned int addr;
9236+
9237+ if ((ba & 0xFFC00000U) == 0x30800000U)
9238+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9239+ else
9240+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9241+ regs->pc = addr;
9242+ regs->npc = addr+4;
9243+ return 2;
9244+ }
9245+ } while (0);
9246+
9247+ do { /* PaX: patched PLT emulation #3 */
9248+ unsigned int sethi, bajmpl, nop;
9249+
9250+ err = get_user(sethi, (unsigned int *)regs->pc);
9251+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9252+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9253+
9254+ if (err)
9255+ break;
9256+
9257+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9258+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9259+ nop == 0x01000000U)
9260+ {
9261+ unsigned int addr;
9262+
9263+ addr = (sethi & 0x003FFFFFU) << 10;
9264+ regs->u_regs[UREG_G1] = addr;
9265+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9266+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9267+ else
9268+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9269+ regs->pc = addr;
9270+ regs->npc = addr+4;
9271+ return 2;
9272+ }
9273+ } while (0);
9274+
9275+ do { /* PaX: unpatched PLT emulation step 1 */
9276+ unsigned int sethi, ba, nop;
9277+
9278+ err = get_user(sethi, (unsigned int *)regs->pc);
9279+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9280+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9281+
9282+ if (err)
9283+ break;
9284+
9285+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9286+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9287+ nop == 0x01000000U)
9288+ {
9289+ unsigned int addr, save, call;
9290+
9291+ if ((ba & 0xFFC00000U) == 0x30800000U)
9292+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9293+ else
9294+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9295+
9296+ err = get_user(save, (unsigned int *)addr);
9297+ err |= get_user(call, (unsigned int *)(addr+4));
9298+ err |= get_user(nop, (unsigned int *)(addr+8));
9299+ if (err)
9300+ break;
9301+
9302+#ifdef CONFIG_PAX_DLRESOLVE
9303+ if (save == 0x9DE3BFA8U &&
9304+ (call & 0xC0000000U) == 0x40000000U &&
9305+ nop == 0x01000000U)
9306+ {
9307+ struct vm_area_struct *vma;
9308+ unsigned long call_dl_resolve;
9309+
9310+ down_read(&current->mm->mmap_sem);
9311+ call_dl_resolve = current->mm->call_dl_resolve;
9312+ up_read(&current->mm->mmap_sem);
9313+ if (likely(call_dl_resolve))
9314+ goto emulate;
9315+
9316+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9317+
9318+ down_write(&current->mm->mmap_sem);
9319+ if (current->mm->call_dl_resolve) {
9320+ call_dl_resolve = current->mm->call_dl_resolve;
9321+ up_write(&current->mm->mmap_sem);
9322+ if (vma)
9323+ kmem_cache_free(vm_area_cachep, vma);
9324+ goto emulate;
9325+ }
9326+
9327+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9328+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9329+ up_write(&current->mm->mmap_sem);
9330+ if (vma)
9331+ kmem_cache_free(vm_area_cachep, vma);
9332+ return 1;
9333+ }
9334+
9335+ if (pax_insert_vma(vma, call_dl_resolve)) {
9336+ up_write(&current->mm->mmap_sem);
9337+ kmem_cache_free(vm_area_cachep, vma);
9338+ return 1;
9339+ }
9340+
9341+ current->mm->call_dl_resolve = call_dl_resolve;
9342+ up_write(&current->mm->mmap_sem);
9343+
9344+emulate:
9345+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9346+ regs->pc = call_dl_resolve;
9347+ regs->npc = addr+4;
9348+ return 3;
9349+ }
9350+#endif
9351+
9352+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9353+ if ((save & 0xFFC00000U) == 0x05000000U &&
9354+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9355+ nop == 0x01000000U)
9356+ {
9357+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9358+ regs->u_regs[UREG_G2] = addr + 4;
9359+ addr = (save & 0x003FFFFFU) << 10;
9360+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9361+ regs->pc = addr;
9362+ regs->npc = addr+4;
9363+ return 3;
9364+ }
9365+ }
9366+ } while (0);
9367+
9368+ do { /* PaX: unpatched PLT emulation step 2 */
9369+ unsigned int save, call, nop;
9370+
9371+ err = get_user(save, (unsigned int *)(regs->pc-4));
9372+ err |= get_user(call, (unsigned int *)regs->pc);
9373+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9374+ if (err)
9375+ break;
9376+
9377+ if (save == 0x9DE3BFA8U &&
9378+ (call & 0xC0000000U) == 0x40000000U &&
9379+ nop == 0x01000000U)
9380+ {
9381+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9382+
9383+ regs->u_regs[UREG_RETPC] = regs->pc;
9384+ regs->pc = dl_resolve;
9385+ regs->npc = dl_resolve+4;
9386+ return 3;
9387+ }
9388+ } while (0);
9389+#endif
9390+
9391+ return 1;
9392+}
9393+
9394+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9395+{
9396+ unsigned long i;
9397+
9398+ printk(KERN_ERR "PAX: bytes at PC: ");
9399+ for (i = 0; i < 8; i++) {
9400+ unsigned int c;
9401+ if (get_user(c, (unsigned int *)pc+i))
9402+ printk(KERN_CONT "???????? ");
9403+ else
9404+ printk(KERN_CONT "%08x ", c);
9405+ }
9406+ printk("\n");
9407+}
9408+#endif
9409+
9410 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9411 int text_fault)
9412 {
9413@@ -230,6 +504,24 @@ good_area:
9414 if (!(vma->vm_flags & VM_WRITE))
9415 goto bad_area;
9416 } else {
9417+
9418+#ifdef CONFIG_PAX_PAGEEXEC
9419+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9420+ up_read(&mm->mmap_sem);
9421+ switch (pax_handle_fetch_fault(regs)) {
9422+
9423+#ifdef CONFIG_PAX_EMUPLT
9424+ case 2:
9425+ case 3:
9426+ return;
9427+#endif
9428+
9429+ }
9430+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9431+ do_group_exit(SIGKILL);
9432+ }
9433+#endif
9434+
9435 /* Allow reads even for write-only mappings */
9436 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9437 goto bad_area;
9438diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9439index 5062ff3..e0b75f3 100644
9440--- a/arch/sparc/mm/fault_64.c
9441+++ b/arch/sparc/mm/fault_64.c
9442@@ -21,6 +21,9 @@
9443 #include <linux/kprobes.h>
9444 #include <linux/kdebug.h>
9445 #include <linux/percpu.h>
9446+#include <linux/slab.h>
9447+#include <linux/pagemap.h>
9448+#include <linux/compiler.h>
9449
9450 #include <asm/page.h>
9451 #include <asm/pgtable.h>
9452@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9453 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9454 regs->tpc);
9455 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9456- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9457+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9458 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9459 dump_stack();
9460 unhandled_fault(regs->tpc, current, regs);
9461@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9462 show_regs(regs);
9463 }
9464
9465+#ifdef CONFIG_PAX_PAGEEXEC
9466+#ifdef CONFIG_PAX_DLRESOLVE
9467+static void pax_emuplt_close(struct vm_area_struct *vma)
9468+{
9469+ vma->vm_mm->call_dl_resolve = 0UL;
9470+}
9471+
9472+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9473+{
9474+ unsigned int *kaddr;
9475+
9476+ vmf->page = alloc_page(GFP_HIGHUSER);
9477+ if (!vmf->page)
9478+ return VM_FAULT_OOM;
9479+
9480+ kaddr = kmap(vmf->page);
9481+ memset(kaddr, 0, PAGE_SIZE);
9482+ kaddr[0] = 0x9DE3BFA8U; /* save */
9483+ flush_dcache_page(vmf->page);
9484+ kunmap(vmf->page);
9485+ return VM_FAULT_MAJOR;
9486+}
9487+
9488+static const struct vm_operations_struct pax_vm_ops = {
9489+ .close = pax_emuplt_close,
9490+ .fault = pax_emuplt_fault
9491+};
9492+
9493+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9494+{
9495+ int ret;
9496+
9497+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9498+ vma->vm_mm = current->mm;
9499+ vma->vm_start = addr;
9500+ vma->vm_end = addr + PAGE_SIZE;
9501+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9502+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9503+ vma->vm_ops = &pax_vm_ops;
9504+
9505+ ret = insert_vm_struct(current->mm, vma);
9506+ if (ret)
9507+ return ret;
9508+
9509+ ++current->mm->total_vm;
9510+ return 0;
9511+}
9512+#endif
9513+
9514+/*
9515+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9516+ *
9517+ * returns 1 when task should be killed
9518+ * 2 when patched PLT trampoline was detected
9519+ * 3 when unpatched PLT trampoline was detected
9520+ */
9521+static int pax_handle_fetch_fault(struct pt_regs *regs)
9522+{
9523+
9524+#ifdef CONFIG_PAX_EMUPLT
9525+ int err;
9526+
9527+ do { /* PaX: patched PLT emulation #1 */
9528+ unsigned int sethi1, sethi2, jmpl;
9529+
9530+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9531+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9532+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9533+
9534+ if (err)
9535+ break;
9536+
9537+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9538+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9539+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9540+ {
9541+ unsigned long addr;
9542+
9543+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9544+ addr = regs->u_regs[UREG_G1];
9545+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9546+
9547+ if (test_thread_flag(TIF_32BIT))
9548+ addr &= 0xFFFFFFFFUL;
9549+
9550+ regs->tpc = addr;
9551+ regs->tnpc = addr+4;
9552+ return 2;
9553+ }
9554+ } while (0);
9555+
9556+ do { /* PaX: patched PLT emulation #2 */
9557+ unsigned int ba;
9558+
9559+ err = get_user(ba, (unsigned int *)regs->tpc);
9560+
9561+ if (err)
9562+ break;
9563+
9564+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9565+ unsigned long addr;
9566+
9567+ if ((ba & 0xFFC00000U) == 0x30800000U)
9568+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9569+ else
9570+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9571+
9572+ if (test_thread_flag(TIF_32BIT))
9573+ addr &= 0xFFFFFFFFUL;
9574+
9575+ regs->tpc = addr;
9576+ regs->tnpc = addr+4;
9577+ return 2;
9578+ }
9579+ } while (0);
9580+
9581+ do { /* PaX: patched PLT emulation #3 */
9582+ unsigned int sethi, bajmpl, nop;
9583+
9584+ err = get_user(sethi, (unsigned int *)regs->tpc);
9585+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9586+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9587+
9588+ if (err)
9589+ break;
9590+
9591+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9592+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9593+ nop == 0x01000000U)
9594+ {
9595+ unsigned long addr;
9596+
9597+ addr = (sethi & 0x003FFFFFU) << 10;
9598+ regs->u_regs[UREG_G1] = addr;
9599+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9600+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9601+ else
9602+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9603+
9604+ if (test_thread_flag(TIF_32BIT))
9605+ addr &= 0xFFFFFFFFUL;
9606+
9607+ regs->tpc = addr;
9608+ regs->tnpc = addr+4;
9609+ return 2;
9610+ }
9611+ } while (0);
9612+
9613+ do { /* PaX: patched PLT emulation #4 */
9614+ unsigned int sethi, mov1, call, mov2;
9615+
9616+ err = get_user(sethi, (unsigned int *)regs->tpc);
9617+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9618+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9619+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9620+
9621+ if (err)
9622+ break;
9623+
9624+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9625+ mov1 == 0x8210000FU &&
9626+ (call & 0xC0000000U) == 0x40000000U &&
9627+ mov2 == 0x9E100001U)
9628+ {
9629+ unsigned long addr;
9630+
9631+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9632+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9633+
9634+ if (test_thread_flag(TIF_32BIT))
9635+ addr &= 0xFFFFFFFFUL;
9636+
9637+ regs->tpc = addr;
9638+ regs->tnpc = addr+4;
9639+ return 2;
9640+ }
9641+ } while (0);
9642+
9643+ do { /* PaX: patched PLT emulation #5 */
9644+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9645+
9646+ err = get_user(sethi, (unsigned int *)regs->tpc);
9647+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9648+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9649+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9650+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9651+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9652+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9653+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9654+
9655+ if (err)
9656+ break;
9657+
9658+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9659+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9660+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9661+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9662+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9663+ sllx == 0x83287020U &&
9664+ jmpl == 0x81C04005U &&
9665+ nop == 0x01000000U)
9666+ {
9667+ unsigned long addr;
9668+
9669+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9670+ regs->u_regs[UREG_G1] <<= 32;
9671+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9672+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9673+ regs->tpc = addr;
9674+ regs->tnpc = addr+4;
9675+ return 2;
9676+ }
9677+ } while (0);
9678+
9679+ do { /* PaX: patched PLT emulation #6 */
9680+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9681+
9682+ err = get_user(sethi, (unsigned int *)regs->tpc);
9683+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9684+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9685+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9686+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9687+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9688+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9689+
9690+ if (err)
9691+ break;
9692+
9693+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9694+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9695+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9696+ sllx == 0x83287020U &&
9697+ (or & 0xFFFFE000U) == 0x8A116000U &&
9698+ jmpl == 0x81C04005U &&
9699+ nop == 0x01000000U)
9700+ {
9701+ unsigned long addr;
9702+
9703+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9704+ regs->u_regs[UREG_G1] <<= 32;
9705+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9706+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9707+ regs->tpc = addr;
9708+ regs->tnpc = addr+4;
9709+ return 2;
9710+ }
9711+ } while (0);
9712+
9713+ do { /* PaX: unpatched PLT emulation step 1 */
9714+ unsigned int sethi, ba, nop;
9715+
9716+ err = get_user(sethi, (unsigned int *)regs->tpc);
9717+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9718+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9719+
9720+ if (err)
9721+ break;
9722+
9723+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9724+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9725+ nop == 0x01000000U)
9726+ {
9727+ unsigned long addr;
9728+ unsigned int save, call;
9729+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9730+
9731+ if ((ba & 0xFFC00000U) == 0x30800000U)
9732+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9733+ else
9734+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9735+
9736+ if (test_thread_flag(TIF_32BIT))
9737+ addr &= 0xFFFFFFFFUL;
9738+
9739+ err = get_user(save, (unsigned int *)addr);
9740+ err |= get_user(call, (unsigned int *)(addr+4));
9741+ err |= get_user(nop, (unsigned int *)(addr+8));
9742+ if (err)
9743+ break;
9744+
9745+#ifdef CONFIG_PAX_DLRESOLVE
9746+ if (save == 0x9DE3BFA8U &&
9747+ (call & 0xC0000000U) == 0x40000000U &&
9748+ nop == 0x01000000U)
9749+ {
9750+ struct vm_area_struct *vma;
9751+ unsigned long call_dl_resolve;
9752+
9753+ down_read(&current->mm->mmap_sem);
9754+ call_dl_resolve = current->mm->call_dl_resolve;
9755+ up_read(&current->mm->mmap_sem);
9756+ if (likely(call_dl_resolve))
9757+ goto emulate;
9758+
9759+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9760+
9761+ down_write(&current->mm->mmap_sem);
9762+ if (current->mm->call_dl_resolve) {
9763+ call_dl_resolve = current->mm->call_dl_resolve;
9764+ up_write(&current->mm->mmap_sem);
9765+ if (vma)
9766+ kmem_cache_free(vm_area_cachep, vma);
9767+ goto emulate;
9768+ }
9769+
9770+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9771+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9772+ up_write(&current->mm->mmap_sem);
9773+ if (vma)
9774+ kmem_cache_free(vm_area_cachep, vma);
9775+ return 1;
9776+ }
9777+
9778+ if (pax_insert_vma(vma, call_dl_resolve)) {
9779+ up_write(&current->mm->mmap_sem);
9780+ kmem_cache_free(vm_area_cachep, vma);
9781+ return 1;
9782+ }
9783+
9784+ current->mm->call_dl_resolve = call_dl_resolve;
9785+ up_write(&current->mm->mmap_sem);
9786+
9787+emulate:
9788+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9789+ regs->tpc = call_dl_resolve;
9790+ regs->tnpc = addr+4;
9791+ return 3;
9792+ }
9793+#endif
9794+
9795+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9796+ if ((save & 0xFFC00000U) == 0x05000000U &&
9797+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9798+ nop == 0x01000000U)
9799+ {
9800+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9801+ regs->u_regs[UREG_G2] = addr + 4;
9802+ addr = (save & 0x003FFFFFU) << 10;
9803+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9804+
9805+ if (test_thread_flag(TIF_32BIT))
9806+ addr &= 0xFFFFFFFFUL;
9807+
9808+ regs->tpc = addr;
9809+ regs->tnpc = addr+4;
9810+ return 3;
9811+ }
9812+
9813+ /* PaX: 64-bit PLT stub */
9814+ err = get_user(sethi1, (unsigned int *)addr);
9815+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9816+ err |= get_user(or1, (unsigned int *)(addr+8));
9817+ err |= get_user(or2, (unsigned int *)(addr+12));
9818+ err |= get_user(sllx, (unsigned int *)(addr+16));
9819+ err |= get_user(add, (unsigned int *)(addr+20));
9820+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9821+ err |= get_user(nop, (unsigned int *)(addr+28));
9822+ if (err)
9823+ break;
9824+
9825+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9826+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9827+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9828+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9829+ sllx == 0x89293020U &&
9830+ add == 0x8A010005U &&
9831+ jmpl == 0x89C14000U &&
9832+ nop == 0x01000000U)
9833+ {
9834+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9835+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9836+ regs->u_regs[UREG_G4] <<= 32;
9837+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9838+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9839+ regs->u_regs[UREG_G4] = addr + 24;
9840+ addr = regs->u_regs[UREG_G5];
9841+ regs->tpc = addr;
9842+ regs->tnpc = addr+4;
9843+ return 3;
9844+ }
9845+ }
9846+ } while (0);
9847+
9848+#ifdef CONFIG_PAX_DLRESOLVE
9849+ do { /* PaX: unpatched PLT emulation step 2 */
9850+ unsigned int save, call, nop;
9851+
9852+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9853+ err |= get_user(call, (unsigned int *)regs->tpc);
9854+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9855+ if (err)
9856+ break;
9857+
9858+ if (save == 0x9DE3BFA8U &&
9859+ (call & 0xC0000000U) == 0x40000000U &&
9860+ nop == 0x01000000U)
9861+ {
9862+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9863+
9864+ if (test_thread_flag(TIF_32BIT))
9865+ dl_resolve &= 0xFFFFFFFFUL;
9866+
9867+ regs->u_regs[UREG_RETPC] = regs->tpc;
9868+ regs->tpc = dl_resolve;
9869+ regs->tnpc = dl_resolve+4;
9870+ return 3;
9871+ }
9872+ } while (0);
9873+#endif
9874+
9875+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9876+ unsigned int sethi, ba, nop;
9877+
9878+ err = get_user(sethi, (unsigned int *)regs->tpc);
9879+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9880+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9881+
9882+ if (err)
9883+ break;
9884+
9885+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9886+ (ba & 0xFFF00000U) == 0x30600000U &&
9887+ nop == 0x01000000U)
9888+ {
9889+ unsigned long addr;
9890+
9891+ addr = (sethi & 0x003FFFFFU) << 10;
9892+ regs->u_regs[UREG_G1] = addr;
9893+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9894+
9895+ if (test_thread_flag(TIF_32BIT))
9896+ addr &= 0xFFFFFFFFUL;
9897+
9898+ regs->tpc = addr;
9899+ regs->tnpc = addr+4;
9900+ return 2;
9901+ }
9902+ } while (0);
9903+
9904+#endif
9905+
9906+ return 1;
9907+}
9908+
9909+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9910+{
9911+ unsigned long i;
9912+
9913+ printk(KERN_ERR "PAX: bytes at PC: ");
9914+ for (i = 0; i < 8; i++) {
9915+ unsigned int c;
9916+ if (get_user(c, (unsigned int *)pc+i))
9917+ printk(KERN_CONT "???????? ");
9918+ else
9919+ printk(KERN_CONT "%08x ", c);
9920+ }
9921+ printk("\n");
9922+}
9923+#endif
9924+
9925 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9926 {
9927 struct mm_struct *mm = current->mm;
9928@@ -341,6 +804,29 @@ retry:
9929 if (!vma)
9930 goto bad_area;
9931
9932+#ifdef CONFIG_PAX_PAGEEXEC
9933+ /* PaX: detect ITLB misses on non-exec pages */
9934+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9935+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9936+ {
9937+ if (address != regs->tpc)
9938+ goto good_area;
9939+
9940+ up_read(&mm->mmap_sem);
9941+ switch (pax_handle_fetch_fault(regs)) {
9942+
9943+#ifdef CONFIG_PAX_EMUPLT
9944+ case 2:
9945+ case 3:
9946+ return;
9947+#endif
9948+
9949+ }
9950+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9951+ do_group_exit(SIGKILL);
9952+ }
9953+#endif
9954+
9955 /* Pure DTLB misses do not tell us whether the fault causing
9956 * load/store/atomic was a write or not, it only says that there
9957 * was no match. So in such a case we (carefully) read the
9958diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9959index d2b5944..bd813f2 100644
9960--- a/arch/sparc/mm/hugetlbpage.c
9961+++ b/arch/sparc/mm/hugetlbpage.c
9962@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9963
9964 info.flags = 0;
9965 info.length = len;
9966- info.low_limit = TASK_UNMAPPED_BASE;
9967+ info.low_limit = mm->mmap_base;
9968 info.high_limit = min(task_size, VA_EXCLUDE_START);
9969 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9970 info.align_offset = 0;
9971@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9972 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9973 VM_BUG_ON(addr != -ENOMEM);
9974 info.low_limit = VA_EXCLUDE_END;
9975+
9976+#ifdef CONFIG_PAX_RANDMMAP
9977+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9978+ info.low_limit += mm->delta_mmap;
9979+#endif
9980+
9981 info.high_limit = task_size;
9982 addr = vm_unmapped_area(&info);
9983 }
9984@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9985 VM_BUG_ON(addr != -ENOMEM);
9986 info.flags = 0;
9987 info.low_limit = TASK_UNMAPPED_BASE;
9988+
9989+#ifdef CONFIG_PAX_RANDMMAP
9990+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9991+ info.low_limit += mm->delta_mmap;
9992+#endif
9993+
9994 info.high_limit = STACK_TOP32;
9995 addr = vm_unmapped_area(&info);
9996 }
9997@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9998 struct mm_struct *mm = current->mm;
9999 struct vm_area_struct *vma;
10000 unsigned long task_size = TASK_SIZE;
10001+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
10002
10003 if (test_thread_flag(TIF_32BIT))
10004 task_size = STACK_TOP32;
10005@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10006 return addr;
10007 }
10008
10009+#ifdef CONFIG_PAX_RANDMMAP
10010+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10011+#endif
10012+
10013 if (addr) {
10014 addr = ALIGN(addr, HPAGE_SIZE);
10015 vma = find_vma(mm, addr);
10016- if (task_size - len >= addr &&
10017- (!vma || addr + len <= vma->vm_start))
10018+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10019 return addr;
10020 }
10021 if (mm->get_unmapped_area == arch_get_unmapped_area)
10022diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10023index f4500c6..889656c 100644
10024--- a/arch/tile/include/asm/atomic_64.h
10025+++ b/arch/tile/include/asm/atomic_64.h
10026@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10027
10028 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10029
10030+#define atomic64_read_unchecked(v) atomic64_read(v)
10031+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10032+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10033+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10034+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10035+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10036+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10037+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10038+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10039+
10040 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10041 #define smp_mb__before_atomic_dec() smp_mb()
10042 #define smp_mb__after_atomic_dec() smp_mb()
10043diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10044index a9a5299..0fce79e 100644
10045--- a/arch/tile/include/asm/cache.h
10046+++ b/arch/tile/include/asm/cache.h
10047@@ -15,11 +15,12 @@
10048 #ifndef _ASM_TILE_CACHE_H
10049 #define _ASM_TILE_CACHE_H
10050
10051+#include <linux/const.h>
10052 #include <arch/chip.h>
10053
10054 /* bytes per L1 data cache line */
10055 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10056-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10057+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10058
10059 /* bytes per L2 cache line */
10060 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10061diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10062index 8a082bc..7a6bf87 100644
10063--- a/arch/tile/include/asm/uaccess.h
10064+++ b/arch/tile/include/asm/uaccess.h
10065@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10066 const void __user *from,
10067 unsigned long n)
10068 {
10069- int sz = __compiletime_object_size(to);
10070+ size_t sz = __compiletime_object_size(to);
10071
10072- if (likely(sz == -1 || sz >= n))
10073+ if (likely(sz == (size_t)-1 || sz >= n))
10074 n = _copy_from_user(to, from, n);
10075 else
10076 copy_from_user_overflow();
10077diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
10078index 650ccff..45fe2d6 100644
10079--- a/arch/tile/mm/hugetlbpage.c
10080+++ b/arch/tile/mm/hugetlbpage.c
10081@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
10082 info.high_limit = TASK_SIZE;
10083 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10084 info.align_offset = 0;
10085+ info.threadstack_offset = 0;
10086 return vm_unmapped_area(&info);
10087 }
10088
10089@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
10090 info.high_limit = current->mm->mmap_base;
10091 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10092 info.align_offset = 0;
10093+ info.threadstack_offset = 0;
10094 addr = vm_unmapped_area(&info);
10095
10096 /*
10097diff --git a/arch/um/Makefile b/arch/um/Makefile
10098index 133f7de..1d6f2f1 100644
10099--- a/arch/um/Makefile
10100+++ b/arch/um/Makefile
10101@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10102 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10103 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10104
10105+ifdef CONSTIFY_PLUGIN
10106+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10107+endif
10108+
10109 #This will adjust *FLAGS accordingly to the platform.
10110 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10111
10112diff --git a/arch/um/defconfig b/arch/um/defconfig
10113index 08107a7..ab22afe 100644
10114--- a/arch/um/defconfig
10115+++ b/arch/um/defconfig
10116@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10117 CONFIG_X86_L1_CACHE_SHIFT=5
10118 CONFIG_X86_XADD=y
10119 CONFIG_X86_PPRO_FENCE=y
10120-CONFIG_X86_WP_WORKS_OK=y
10121 CONFIG_X86_INVLPG=y
10122 CONFIG_X86_BSWAP=y
10123 CONFIG_X86_POPAD_OK=y
10124diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10125index 19e1bdd..3665b77 100644
10126--- a/arch/um/include/asm/cache.h
10127+++ b/arch/um/include/asm/cache.h
10128@@ -1,6 +1,7 @@
10129 #ifndef __UM_CACHE_H
10130 #define __UM_CACHE_H
10131
10132+#include <linux/const.h>
10133
10134 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10135 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10136@@ -12,6 +13,6 @@
10137 # define L1_CACHE_SHIFT 5
10138 #endif
10139
10140-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10141+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10142
10143 #endif
10144diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10145index 2e0a6b1..a64d0f5 100644
10146--- a/arch/um/include/asm/kmap_types.h
10147+++ b/arch/um/include/asm/kmap_types.h
10148@@ -8,6 +8,6 @@
10149
10150 /* No more #include "asm/arch/kmap_types.h" ! */
10151
10152-#define KM_TYPE_NR 14
10153+#define KM_TYPE_NR 15
10154
10155 #endif
10156diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10157index 5ff53d9..5850cdf 100644
10158--- a/arch/um/include/asm/page.h
10159+++ b/arch/um/include/asm/page.h
10160@@ -14,6 +14,9 @@
10161 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10162 #define PAGE_MASK (~(PAGE_SIZE-1))
10163
10164+#define ktla_ktva(addr) (addr)
10165+#define ktva_ktla(addr) (addr)
10166+
10167 #ifndef __ASSEMBLY__
10168
10169 struct page;
10170diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10171index 0032f92..cd151e0 100644
10172--- a/arch/um/include/asm/pgtable-3level.h
10173+++ b/arch/um/include/asm/pgtable-3level.h
10174@@ -58,6 +58,7 @@
10175 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10176 #define pud_populate(mm, pud, pmd) \
10177 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10178+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10179
10180 #ifdef CONFIG_64BIT
10181 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10182diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10183index bbcef52..6a2a483 100644
10184--- a/arch/um/kernel/process.c
10185+++ b/arch/um/kernel/process.c
10186@@ -367,22 +367,6 @@ int singlestepping(void * t)
10187 return 2;
10188 }
10189
10190-/*
10191- * Only x86 and x86_64 have an arch_align_stack().
10192- * All other arches have "#define arch_align_stack(x) (x)"
10193- * in their asm/system.h
10194- * As this is included in UML from asm-um/system-generic.h,
10195- * we can use it to behave as the subarch does.
10196- */
10197-#ifndef arch_align_stack
10198-unsigned long arch_align_stack(unsigned long sp)
10199-{
10200- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10201- sp -= get_random_int() % 8192;
10202- return sp & ~0xf;
10203-}
10204-#endif
10205-
10206 unsigned long get_wchan(struct task_struct *p)
10207 {
10208 unsigned long stack_page, sp, ip;
10209diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10210index ad8f795..2c7eec6 100644
10211--- a/arch/unicore32/include/asm/cache.h
10212+++ b/arch/unicore32/include/asm/cache.h
10213@@ -12,8 +12,10 @@
10214 #ifndef __UNICORE_CACHE_H__
10215 #define __UNICORE_CACHE_H__
10216
10217-#define L1_CACHE_SHIFT (5)
10218-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10219+#include <linux/const.h>
10220+
10221+#define L1_CACHE_SHIFT 5
10222+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10223
10224 /*
10225 * Memory returned by kmalloc() may be used for DMA, so we must make
10226diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10227index fe120da..24177f7 100644
10228--- a/arch/x86/Kconfig
10229+++ b/arch/x86/Kconfig
10230@@ -239,7 +239,7 @@ config X86_HT
10231
10232 config X86_32_LAZY_GS
10233 def_bool y
10234- depends on X86_32 && !CC_STACKPROTECTOR
10235+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10236
10237 config ARCH_HWEIGHT_CFLAGS
10238 string
10239@@ -1073,6 +1073,7 @@ config MICROCODE_EARLY
10240
10241 config X86_MSR
10242 tristate "/dev/cpu/*/msr - Model-specific register support"
10243+ depends on !GRKERNSEC_KMEM
10244 ---help---
10245 This device gives privileged processes access to the x86
10246 Model-Specific Registers (MSRs). It is a character device with
10247@@ -1096,7 +1097,7 @@ choice
10248
10249 config NOHIGHMEM
10250 bool "off"
10251- depends on !X86_NUMAQ
10252+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10253 ---help---
10254 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10255 However, the address space of 32-bit x86 processors is only 4
10256@@ -1133,7 +1134,7 @@ config NOHIGHMEM
10257
10258 config HIGHMEM4G
10259 bool "4GB"
10260- depends on !X86_NUMAQ
10261+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10262 ---help---
10263 Select this if you have a 32-bit processor and between 1 and 4
10264 gigabytes of physical RAM.
10265@@ -1186,7 +1187,7 @@ config PAGE_OFFSET
10266 hex
10267 default 0xB0000000 if VMSPLIT_3G_OPT
10268 default 0x80000000 if VMSPLIT_2G
10269- default 0x78000000 if VMSPLIT_2G_OPT
10270+ default 0x70000000 if VMSPLIT_2G_OPT
10271 default 0x40000000 if VMSPLIT_1G
10272 default 0xC0000000
10273 depends on X86_32
10274@@ -1584,6 +1585,7 @@ config SECCOMP
10275
10276 config CC_STACKPROTECTOR
10277 bool "Enable -fstack-protector buffer overflow detection"
10278+ depends on X86_64 || !PAX_MEMORY_UDEREF
10279 ---help---
10280 This option turns on the -fstack-protector GCC feature. This
10281 feature puts, at the beginning of functions, a canary value on
10282@@ -1703,6 +1705,8 @@ config X86_NEED_RELOCS
10283 config PHYSICAL_ALIGN
10284 hex "Alignment value to which kernel should be aligned" if X86_32
10285 default "0x1000000"
10286+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10287+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10288 range 0x2000 0x1000000
10289 ---help---
10290 This value puts the alignment restrictions on physical address
10291@@ -1778,9 +1782,10 @@ config DEBUG_HOTPLUG_CPU0
10292 If unsure, say N.
10293
10294 config COMPAT_VDSO
10295- def_bool y
10296+ def_bool n
10297 prompt "Compat VDSO support"
10298 depends on X86_32 || IA32_EMULATION
10299+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10300 ---help---
10301 Map the 32-bit VDSO to the predictable old-style address too.
10302
10303diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10304index c026cca..14657ae 100644
10305--- a/arch/x86/Kconfig.cpu
10306+++ b/arch/x86/Kconfig.cpu
10307@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10308
10309 config X86_F00F_BUG
10310 def_bool y
10311- depends on M586MMX || M586TSC || M586 || M486
10312+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10313
10314 config X86_INVD_BUG
10315 def_bool y
10316@@ -327,7 +327,7 @@ config X86_INVD_BUG
10317
10318 config X86_ALIGNMENT_16
10319 def_bool y
10320- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10321+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10322
10323 config X86_INTEL_USERCOPY
10324 def_bool y
10325@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10326 # generates cmov.
10327 config X86_CMOV
10328 def_bool y
10329- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10330+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10331
10332 config X86_MINIMUM_CPU_FAMILY
10333 int
10334diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10335index c198b7e..63eea60 100644
10336--- a/arch/x86/Kconfig.debug
10337+++ b/arch/x86/Kconfig.debug
10338@@ -84,7 +84,7 @@ config X86_PTDUMP
10339 config DEBUG_RODATA
10340 bool "Write protect kernel read-only data structures"
10341 default y
10342- depends on DEBUG_KERNEL
10343+ depends on DEBUG_KERNEL && BROKEN
10344 ---help---
10345 Mark the kernel read-only data as write-protected in the pagetables,
10346 in order to catch accidental (and incorrect) writes to such const
10347@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10348
10349 config DEBUG_SET_MODULE_RONX
10350 bool "Set loadable kernel module data as NX and text as RO"
10351- depends on MODULES
10352+ depends on MODULES && BROKEN
10353 ---help---
10354 This option helps catch unintended modifications to loadable
10355 kernel module's text and read-only data. It also prevents execution
10356diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10357index 5c47726..8c4fa67 100644
10358--- a/arch/x86/Makefile
10359+++ b/arch/x86/Makefile
10360@@ -54,6 +54,7 @@ else
10361 UTS_MACHINE := x86_64
10362 CHECKFLAGS += -D__x86_64__ -m64
10363
10364+ biarch := $(call cc-option,-m64)
10365 KBUILD_AFLAGS += -m64
10366 KBUILD_CFLAGS += -m64
10367
10368@@ -234,3 +235,12 @@ define archhelp
10369 echo ' FDARGS="..." arguments for the booted kernel'
10370 echo ' FDINITRD=file initrd for the booted kernel'
10371 endef
10372+
10373+define OLD_LD
10374+
10375+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10376+*** Please upgrade your binutils to 2.18 or newer
10377+endef
10378+
10379+archprepare:
10380+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10381diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10382index 379814b..add62ce 100644
10383--- a/arch/x86/boot/Makefile
10384+++ b/arch/x86/boot/Makefile
10385@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10386 $(call cc-option, -fno-stack-protector) \
10387 $(call cc-option, -mpreferred-stack-boundary=2)
10388 KBUILD_CFLAGS += $(call cc-option, -m32)
10389+ifdef CONSTIFY_PLUGIN
10390+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10391+endif
10392 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10393 GCOV_PROFILE := n
10394
10395diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10396index 878e4b9..20537ab 100644
10397--- a/arch/x86/boot/bitops.h
10398+++ b/arch/x86/boot/bitops.h
10399@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10400 u8 v;
10401 const u32 *p = (const u32 *)addr;
10402
10403- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10404+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10405 return v;
10406 }
10407
10408@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10409
10410 static inline void set_bit(int nr, void *addr)
10411 {
10412- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10413+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10414 }
10415
10416 #endif /* BOOT_BITOPS_H */
10417diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10418index 5b75319..331a4ca 100644
10419--- a/arch/x86/boot/boot.h
10420+++ b/arch/x86/boot/boot.h
10421@@ -85,7 +85,7 @@ static inline void io_delay(void)
10422 static inline u16 ds(void)
10423 {
10424 u16 seg;
10425- asm("movw %%ds,%0" : "=rm" (seg));
10426+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10427 return seg;
10428 }
10429
10430@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10431 static inline int memcmp(const void *s1, const void *s2, size_t len)
10432 {
10433 u8 diff;
10434- asm("repe; cmpsb; setnz %0"
10435+ asm volatile("repe; cmpsb; setnz %0"
10436 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10437 return diff;
10438 }
10439diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10440index 5ef205c..342191d 100644
10441--- a/arch/x86/boot/compressed/Makefile
10442+++ b/arch/x86/boot/compressed/Makefile
10443@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10444 KBUILD_CFLAGS += $(cflags-y)
10445 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10446 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10447+ifdef CONSTIFY_PLUGIN
10448+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10449+endif
10450
10451 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10452 GCOV_PROFILE := n
10453diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10454index d606463..b887794 100644
10455--- a/arch/x86/boot/compressed/eboot.c
10456+++ b/arch/x86/boot/compressed/eboot.c
10457@@ -150,7 +150,6 @@ again:
10458 *addr = max_addr;
10459 }
10460
10461-free_pool:
10462 efi_call_phys1(sys_table->boottime->free_pool, map);
10463
10464 fail:
10465@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10466 if (i == map_size / desc_size)
10467 status = EFI_NOT_FOUND;
10468
10469-free_pool:
10470 efi_call_phys1(sys_table->boottime->free_pool, map);
10471 fail:
10472 return status;
10473diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
10474index a53440e..c3dbf1e 100644
10475--- a/arch/x86/boot/compressed/efi_stub_32.S
10476+++ b/arch/x86/boot/compressed/efi_stub_32.S
10477@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
10478 * parameter 2, ..., param n. To make things easy, we save the return
10479 * address of efi_call_phys in a global variable.
10480 */
10481- popl %ecx
10482- movl %ecx, saved_return_addr(%edx)
10483- /* get the function pointer into ECX*/
10484- popl %ecx
10485- movl %ecx, efi_rt_function_ptr(%edx)
10486+ popl saved_return_addr(%edx)
10487+ popl efi_rt_function_ptr(%edx)
10488
10489 /*
10490 * 3. Call the physical function.
10491 */
10492- call *%ecx
10493+ call *efi_rt_function_ptr(%edx)
10494
10495 /*
10496 * 4. Balance the stack. And because EAX contain the return value,
10497@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
10498 1: popl %edx
10499 subl $1b, %edx
10500
10501- movl efi_rt_function_ptr(%edx), %ecx
10502- pushl %ecx
10503+ pushl efi_rt_function_ptr(%edx)
10504
10505 /*
10506 * 10. Push the saved return address onto the stack and return.
10507 */
10508- movl saved_return_addr(%edx), %ecx
10509- pushl %ecx
10510- ret
10511+ jmpl *saved_return_addr(%edx)
10512 ENDPROC(efi_call_phys)
10513 .previous
10514
10515diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10516index 1e3184f..0d11e2e 100644
10517--- a/arch/x86/boot/compressed/head_32.S
10518+++ b/arch/x86/boot/compressed/head_32.S
10519@@ -118,7 +118,7 @@ preferred_addr:
10520 notl %eax
10521 andl %eax, %ebx
10522 #else
10523- movl $LOAD_PHYSICAL_ADDR, %ebx
10524+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10525 #endif
10526
10527 /* Target address to relocate to for decompression */
10528@@ -204,7 +204,7 @@ relocated:
10529 * and where it was actually loaded.
10530 */
10531 movl %ebp, %ebx
10532- subl $LOAD_PHYSICAL_ADDR, %ebx
10533+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10534 jz 2f /* Nothing to be done if loaded at compiled addr. */
10535 /*
10536 * Process relocations.
10537@@ -212,8 +212,7 @@ relocated:
10538
10539 1: subl $4, %edi
10540 movl (%edi), %ecx
10541- testl %ecx, %ecx
10542- jz 2f
10543+ jecxz 2f
10544 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10545 jmp 1b
10546 2:
10547diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10548index 16f24e6..47491a3 100644
10549--- a/arch/x86/boot/compressed/head_64.S
10550+++ b/arch/x86/boot/compressed/head_64.S
10551@@ -97,7 +97,7 @@ ENTRY(startup_32)
10552 notl %eax
10553 andl %eax, %ebx
10554 #else
10555- movl $LOAD_PHYSICAL_ADDR, %ebx
10556+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10557 #endif
10558
10559 /* Target address to relocate to for decompression */
10560@@ -272,7 +272,7 @@ preferred_addr:
10561 notq %rax
10562 andq %rax, %rbp
10563 #else
10564- movq $LOAD_PHYSICAL_ADDR, %rbp
10565+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10566 #endif
10567
10568 /* Target address to relocate to for decompression */
10569@@ -363,8 +363,8 @@ gdt:
10570 .long gdt
10571 .word 0
10572 .quad 0x0000000000000000 /* NULL descriptor */
10573- .quad 0x00af9a000000ffff /* __KERNEL_CS */
10574- .quad 0x00cf92000000ffff /* __KERNEL_DS */
10575+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
10576+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
10577 .quad 0x0080890000000000 /* TS descriptor */
10578 .quad 0x0000000000000000 /* TS continued */
10579 gdt_end:
10580diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10581index 7cb56c6..d382d84 100644
10582--- a/arch/x86/boot/compressed/misc.c
10583+++ b/arch/x86/boot/compressed/misc.c
10584@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10585 case PT_LOAD:
10586 #ifdef CONFIG_RELOCATABLE
10587 dest = output;
10588- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10589+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10590 #else
10591 dest = (void *)(phdr->p_paddr);
10592 #endif
10593@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10594 error("Destination address too large");
10595 #endif
10596 #ifndef CONFIG_RELOCATABLE
10597- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10598+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10599 error("Wrong destination address");
10600 #endif
10601
10602diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10603index 4d3ff03..e4972ff 100644
10604--- a/arch/x86/boot/cpucheck.c
10605+++ b/arch/x86/boot/cpucheck.c
10606@@ -74,7 +74,7 @@ static int has_fpu(void)
10607 u16 fcw = -1, fsw = -1;
10608 u32 cr0;
10609
10610- asm("movl %%cr0,%0" : "=r" (cr0));
10611+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10612 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10613 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10614 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10615@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10616 {
10617 u32 f0, f1;
10618
10619- asm("pushfl ; "
10620+ asm volatile("pushfl ; "
10621 "pushfl ; "
10622 "popl %0 ; "
10623 "movl %0,%1 ; "
10624@@ -115,7 +115,7 @@ static void get_flags(void)
10625 set_bit(X86_FEATURE_FPU, cpu.flags);
10626
10627 if (has_eflag(X86_EFLAGS_ID)) {
10628- asm("cpuid"
10629+ asm volatile("cpuid"
10630 : "=a" (max_intel_level),
10631 "=b" (cpu_vendor[0]),
10632 "=d" (cpu_vendor[1]),
10633@@ -124,7 +124,7 @@ static void get_flags(void)
10634
10635 if (max_intel_level >= 0x00000001 &&
10636 max_intel_level <= 0x0000ffff) {
10637- asm("cpuid"
10638+ asm volatile("cpuid"
10639 : "=a" (tfms),
10640 "=c" (cpu.flags[4]),
10641 "=d" (cpu.flags[0])
10642@@ -136,7 +136,7 @@ static void get_flags(void)
10643 cpu.model += ((tfms >> 16) & 0xf) << 4;
10644 }
10645
10646- asm("cpuid"
10647+ asm volatile("cpuid"
10648 : "=a" (max_amd_level)
10649 : "a" (0x80000000)
10650 : "ebx", "ecx", "edx");
10651@@ -144,7 +144,7 @@ static void get_flags(void)
10652 if (max_amd_level >= 0x80000001 &&
10653 max_amd_level <= 0x8000ffff) {
10654 u32 eax = 0x80000001;
10655- asm("cpuid"
10656+ asm volatile("cpuid"
10657 : "+a" (eax),
10658 "=c" (cpu.flags[6]),
10659 "=d" (cpu.flags[1])
10660@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10661 u32 ecx = MSR_K7_HWCR;
10662 u32 eax, edx;
10663
10664- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10665+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10666 eax &= ~(1 << 15);
10667- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10668+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10669
10670 get_flags(); /* Make sure it really did something */
10671 err = check_flags();
10672@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10673 u32 ecx = MSR_VIA_FCR;
10674 u32 eax, edx;
10675
10676- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10677+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10678 eax |= (1<<1)|(1<<7);
10679- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10680+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10681
10682 set_bit(X86_FEATURE_CX8, cpu.flags);
10683 err = check_flags();
10684@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10685 u32 eax, edx;
10686 u32 level = 1;
10687
10688- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10689- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10690- asm("cpuid"
10691+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10692+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10693+ asm volatile("cpuid"
10694 : "+a" (level), "=d" (cpu.flags[0])
10695 : : "ecx", "ebx");
10696- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10697+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10698
10699 err = check_flags();
10700 }
10701diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10702index 9ec06a1..2c25e79 100644
10703--- a/arch/x86/boot/header.S
10704+++ b/arch/x86/boot/header.S
10705@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10706 # single linked list of
10707 # struct setup_data
10708
10709-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10710+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10711
10712 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10713+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10714+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10715+#else
10716 #define VO_INIT_SIZE (VO__end - VO__text)
10717+#endif
10718 #if ZO_INIT_SIZE > VO_INIT_SIZE
10719 #define INIT_SIZE ZO_INIT_SIZE
10720 #else
10721diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10722index db75d07..8e6d0af 100644
10723--- a/arch/x86/boot/memory.c
10724+++ b/arch/x86/boot/memory.c
10725@@ -19,7 +19,7 @@
10726
10727 static int detect_memory_e820(void)
10728 {
10729- int count = 0;
10730+ unsigned int count = 0;
10731 struct biosregs ireg, oreg;
10732 struct e820entry *desc = boot_params.e820_map;
10733 static struct e820entry buf; /* static so it is zeroed */
10734diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10735index 11e8c6e..fdbb1ed 100644
10736--- a/arch/x86/boot/video-vesa.c
10737+++ b/arch/x86/boot/video-vesa.c
10738@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10739
10740 boot_params.screen_info.vesapm_seg = oreg.es;
10741 boot_params.screen_info.vesapm_off = oreg.di;
10742+ boot_params.screen_info.vesapm_size = oreg.cx;
10743 }
10744
10745 /*
10746diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10747index 43eda28..5ab5fdb 100644
10748--- a/arch/x86/boot/video.c
10749+++ b/arch/x86/boot/video.c
10750@@ -96,7 +96,7 @@ static void store_mode_params(void)
10751 static unsigned int get_entry(void)
10752 {
10753 char entry_buf[4];
10754- int i, len = 0;
10755+ unsigned int i, len = 0;
10756 int key;
10757 unsigned int v;
10758
10759diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10760index 9105655..5e37f27 100644
10761--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10762+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10763@@ -8,6 +8,8 @@
10764 * including this sentence is retained in full.
10765 */
10766
10767+#include <asm/alternative-asm.h>
10768+
10769 .extern crypto_ft_tab
10770 .extern crypto_it_tab
10771 .extern crypto_fl_tab
10772@@ -70,6 +72,8 @@
10773 je B192; \
10774 leaq 32(r9),r9;
10775
10776+#define ret pax_force_retaddr 0, 1; ret
10777+
10778 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10779 movq r1,r2; \
10780 movq r3,r4; \
10781diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10782index 477e9d7..3ab339f 100644
10783--- a/arch/x86/crypto/aesni-intel_asm.S
10784+++ b/arch/x86/crypto/aesni-intel_asm.S
10785@@ -31,6 +31,7 @@
10786
10787 #include <linux/linkage.h>
10788 #include <asm/inst.h>
10789+#include <asm/alternative-asm.h>
10790
10791 #ifdef __x86_64__
10792 .data
10793@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
10794 pop %r14
10795 pop %r13
10796 pop %r12
10797+ pax_force_retaddr 0, 1
10798 ret
10799 ENDPROC(aesni_gcm_dec)
10800
10801@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
10802 pop %r14
10803 pop %r13
10804 pop %r12
10805+ pax_force_retaddr 0, 1
10806 ret
10807 ENDPROC(aesni_gcm_enc)
10808
10809@@ -1722,6 +1725,7 @@ _key_expansion_256a:
10810 pxor %xmm1, %xmm0
10811 movaps %xmm0, (TKEYP)
10812 add $0x10, TKEYP
10813+ pax_force_retaddr_bts
10814 ret
10815 ENDPROC(_key_expansion_128)
10816 ENDPROC(_key_expansion_256a)
10817@@ -1748,6 +1752,7 @@ _key_expansion_192a:
10818 shufps $0b01001110, %xmm2, %xmm1
10819 movaps %xmm1, 0x10(TKEYP)
10820 add $0x20, TKEYP
10821+ pax_force_retaddr_bts
10822 ret
10823 ENDPROC(_key_expansion_192a)
10824
10825@@ -1768,6 +1773,7 @@ _key_expansion_192b:
10826
10827 movaps %xmm0, (TKEYP)
10828 add $0x10, TKEYP
10829+ pax_force_retaddr_bts
10830 ret
10831 ENDPROC(_key_expansion_192b)
10832
10833@@ -1781,6 +1787,7 @@ _key_expansion_256b:
10834 pxor %xmm1, %xmm2
10835 movaps %xmm2, (TKEYP)
10836 add $0x10, TKEYP
10837+ pax_force_retaddr_bts
10838 ret
10839 ENDPROC(_key_expansion_256b)
10840
10841@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
10842 #ifndef __x86_64__
10843 popl KEYP
10844 #endif
10845+ pax_force_retaddr 0, 1
10846 ret
10847 ENDPROC(aesni_set_key)
10848
10849@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
10850 popl KLEN
10851 popl KEYP
10852 #endif
10853+ pax_force_retaddr 0, 1
10854 ret
10855 ENDPROC(aesni_enc)
10856
10857@@ -1974,6 +1983,7 @@ _aesni_enc1:
10858 AESENC KEY STATE
10859 movaps 0x70(TKEYP), KEY
10860 AESENCLAST KEY STATE
10861+ pax_force_retaddr_bts
10862 ret
10863 ENDPROC(_aesni_enc1)
10864
10865@@ -2083,6 +2093,7 @@ _aesni_enc4:
10866 AESENCLAST KEY STATE2
10867 AESENCLAST KEY STATE3
10868 AESENCLAST KEY STATE4
10869+ pax_force_retaddr_bts
10870 ret
10871 ENDPROC(_aesni_enc4)
10872
10873@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
10874 popl KLEN
10875 popl KEYP
10876 #endif
10877+ pax_force_retaddr 0, 1
10878 ret
10879 ENDPROC(aesni_dec)
10880
10881@@ -2164,6 +2176,7 @@ _aesni_dec1:
10882 AESDEC KEY STATE
10883 movaps 0x70(TKEYP), KEY
10884 AESDECLAST KEY STATE
10885+ pax_force_retaddr_bts
10886 ret
10887 ENDPROC(_aesni_dec1)
10888
10889@@ -2273,6 +2286,7 @@ _aesni_dec4:
10890 AESDECLAST KEY STATE2
10891 AESDECLAST KEY STATE3
10892 AESDECLAST KEY STATE4
10893+ pax_force_retaddr_bts
10894 ret
10895 ENDPROC(_aesni_dec4)
10896
10897@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
10898 popl KEYP
10899 popl LEN
10900 #endif
10901+ pax_force_retaddr 0, 1
10902 ret
10903 ENDPROC(aesni_ecb_enc)
10904
10905@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
10906 popl KEYP
10907 popl LEN
10908 #endif
10909+ pax_force_retaddr 0, 1
10910 ret
10911 ENDPROC(aesni_ecb_dec)
10912
10913@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
10914 popl LEN
10915 popl IVP
10916 #endif
10917+ pax_force_retaddr 0, 1
10918 ret
10919 ENDPROC(aesni_cbc_enc)
10920
10921@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
10922 popl LEN
10923 popl IVP
10924 #endif
10925+ pax_force_retaddr 0, 1
10926 ret
10927 ENDPROC(aesni_cbc_dec)
10928
10929@@ -2550,6 +2568,7 @@ _aesni_inc_init:
10930 mov $1, TCTR_LOW
10931 MOVQ_R64_XMM TCTR_LOW INC
10932 MOVQ_R64_XMM CTR TCTR_LOW
10933+ pax_force_retaddr_bts
10934 ret
10935 ENDPROC(_aesni_inc_init)
10936
10937@@ -2579,6 +2598,7 @@ _aesni_inc:
10938 .Linc_low:
10939 movaps CTR, IV
10940 PSHUFB_XMM BSWAP_MASK IV
10941+ pax_force_retaddr_bts
10942 ret
10943 ENDPROC(_aesni_inc)
10944
10945@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
10946 .Lctr_enc_ret:
10947 movups IV, (IVP)
10948 .Lctr_enc_just_ret:
10949+ pax_force_retaddr 0, 1
10950 ret
10951 ENDPROC(aesni_ctr_enc)
10952
10953@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
10954 pxor INC, STATE4
10955 movdqu STATE4, 0x70(OUTP)
10956
10957+ pax_force_retaddr 0, 1
10958 ret
10959 ENDPROC(aesni_xts_crypt8)
10960
10961diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10962index 246c670..4d1ed00 100644
10963--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10964+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10965@@ -21,6 +21,7 @@
10966 */
10967
10968 #include <linux/linkage.h>
10969+#include <asm/alternative-asm.h>
10970
10971 .file "blowfish-x86_64-asm.S"
10972 .text
10973@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
10974 jnz .L__enc_xor;
10975
10976 write_block();
10977+ pax_force_retaddr 0, 1
10978 ret;
10979 .L__enc_xor:
10980 xor_block();
10981+ pax_force_retaddr 0, 1
10982 ret;
10983 ENDPROC(__blowfish_enc_blk)
10984
10985@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
10986
10987 movq %r11, %rbp;
10988
10989+ pax_force_retaddr 0, 1
10990 ret;
10991 ENDPROC(blowfish_dec_blk)
10992
10993@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
10994
10995 popq %rbx;
10996 popq %rbp;
10997+ pax_force_retaddr 0, 1
10998 ret;
10999
11000 .L__enc_xor4:
11001@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
11002
11003 popq %rbx;
11004 popq %rbp;
11005+ pax_force_retaddr 0, 1
11006 ret;
11007 ENDPROC(__blowfish_enc_blk_4way)
11008
11009@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
11010 popq %rbx;
11011 popq %rbp;
11012
11013+ pax_force_retaddr 0, 1
11014 ret;
11015 ENDPROC(blowfish_dec_blk_4way)
11016diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11017index 310319c..ce174a4 100644
11018--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11019+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11020@@ -21,6 +21,7 @@
11021 */
11022
11023 #include <linux/linkage.h>
11024+#include <asm/alternative-asm.h>
11025
11026 .file "camellia-x86_64-asm_64.S"
11027 .text
11028@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
11029 enc_outunpack(mov, RT1);
11030
11031 movq RRBP, %rbp;
11032+ pax_force_retaddr 0, 1
11033 ret;
11034
11035 .L__enc_xor:
11036 enc_outunpack(xor, RT1);
11037
11038 movq RRBP, %rbp;
11039+ pax_force_retaddr 0, 1
11040 ret;
11041 ENDPROC(__camellia_enc_blk)
11042
11043@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
11044 dec_outunpack();
11045
11046 movq RRBP, %rbp;
11047+ pax_force_retaddr 0, 1
11048 ret;
11049 ENDPROC(camellia_dec_blk)
11050
11051@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
11052
11053 movq RRBP, %rbp;
11054 popq %rbx;
11055+ pax_force_retaddr 0, 1
11056 ret;
11057
11058 .L__enc2_xor:
11059@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
11060
11061 movq RRBP, %rbp;
11062 popq %rbx;
11063+ pax_force_retaddr 0, 1
11064 ret;
11065 ENDPROC(__camellia_enc_blk_2way)
11066
11067@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
11068
11069 movq RRBP, %rbp;
11070 movq RXOR, %rbx;
11071+ pax_force_retaddr 0, 1
11072 ret;
11073 ENDPROC(camellia_dec_blk_2way)
11074diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11075index c35fd5d..c1ee236 100644
11076--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11077+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11078@@ -24,6 +24,7 @@
11079 */
11080
11081 #include <linux/linkage.h>
11082+#include <asm/alternative-asm.h>
11083
11084 .file "cast5-avx-x86_64-asm_64.S"
11085
11086@@ -281,6 +282,7 @@ __cast5_enc_blk16:
11087 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11088 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11089
11090+ pax_force_retaddr 0, 1
11091 ret;
11092 ENDPROC(__cast5_enc_blk16)
11093
11094@@ -352,6 +354,7 @@ __cast5_dec_blk16:
11095 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11096 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11097
11098+ pax_force_retaddr 0, 1
11099 ret;
11100
11101 .L__skip_dec:
11102@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
11103 vmovdqu RR4, (6*4*4)(%r11);
11104 vmovdqu RL4, (7*4*4)(%r11);
11105
11106+ pax_force_retaddr
11107 ret;
11108 ENDPROC(cast5_ecb_enc_16way)
11109
11110@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
11111 vmovdqu RR4, (6*4*4)(%r11);
11112 vmovdqu RL4, (7*4*4)(%r11);
11113
11114+ pax_force_retaddr
11115 ret;
11116 ENDPROC(cast5_ecb_dec_16way)
11117
11118@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
11119
11120 popq %r12;
11121
11122+ pax_force_retaddr
11123 ret;
11124 ENDPROC(cast5_cbc_dec_16way)
11125
11126@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
11127
11128 popq %r12;
11129
11130+ pax_force_retaddr
11131 ret;
11132 ENDPROC(cast5_ctr_16way)
11133diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11134index e3531f8..18ded3a 100644
11135--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11136+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11137@@ -24,6 +24,7 @@
11138 */
11139
11140 #include <linux/linkage.h>
11141+#include <asm/alternative-asm.h>
11142 #include "glue_helper-asm-avx.S"
11143
11144 .file "cast6-avx-x86_64-asm_64.S"
11145@@ -295,6 +296,7 @@ __cast6_enc_blk8:
11146 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11147 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11148
11149+ pax_force_retaddr 0, 1
11150 ret;
11151 ENDPROC(__cast6_enc_blk8)
11152
11153@@ -340,6 +342,7 @@ __cast6_dec_blk8:
11154 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11155 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11156
11157+ pax_force_retaddr 0, 1
11158 ret;
11159 ENDPROC(__cast6_dec_blk8)
11160
11161@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
11162
11163 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11164
11165+ pax_force_retaddr
11166 ret;
11167 ENDPROC(cast6_ecb_enc_8way)
11168
11169@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
11170
11171 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11172
11173+ pax_force_retaddr
11174 ret;
11175 ENDPROC(cast6_ecb_dec_8way)
11176
11177@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
11178
11179 popq %r12;
11180
11181+ pax_force_retaddr
11182 ret;
11183 ENDPROC(cast6_cbc_dec_8way)
11184
11185@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
11186
11187 popq %r12;
11188
11189+ pax_force_retaddr
11190 ret;
11191 ENDPROC(cast6_ctr_8way)
11192
11193@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
11194 /* dst <= regs xor IVs(in dst) */
11195 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11196
11197+ pax_force_retaddr
11198 ret;
11199 ENDPROC(cast6_xts_enc_8way)
11200
11201@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
11202 /* dst <= regs xor IVs(in dst) */
11203 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11204
11205+ pax_force_retaddr
11206 ret;
11207 ENDPROC(cast6_xts_dec_8way)
11208diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11209index 9279e0b..9270820 100644
11210--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11211+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11212@@ -1,4 +1,5 @@
11213 #include <linux/linkage.h>
11214+#include <asm/alternative-asm.h>
11215
11216 # enter salsa20_encrypt_bytes
11217 ENTRY(salsa20_encrypt_bytes)
11218@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
11219 add %r11,%rsp
11220 mov %rdi,%rax
11221 mov %rsi,%rdx
11222+ pax_force_retaddr 0, 1
11223 ret
11224 # bytesatleast65:
11225 ._bytesatleast65:
11226@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
11227 add %r11,%rsp
11228 mov %rdi,%rax
11229 mov %rsi,%rdx
11230+ pax_force_retaddr
11231 ret
11232 ENDPROC(salsa20_keysetup)
11233
11234@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
11235 add %r11,%rsp
11236 mov %rdi,%rax
11237 mov %rsi,%rdx
11238+ pax_force_retaddr
11239 ret
11240 ENDPROC(salsa20_ivsetup)
11241diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11242index 2f202f4..d9164d6 100644
11243--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11244+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11245@@ -24,6 +24,7 @@
11246 */
11247
11248 #include <linux/linkage.h>
11249+#include <asm/alternative-asm.h>
11250 #include "glue_helper-asm-avx.S"
11251
11252 .file "serpent-avx-x86_64-asm_64.S"
11253@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
11254 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11255 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11256
11257+ pax_force_retaddr
11258 ret;
11259 ENDPROC(__serpent_enc_blk8_avx)
11260
11261@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
11262 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11263 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11264
11265+ pax_force_retaddr
11266 ret;
11267 ENDPROC(__serpent_dec_blk8_avx)
11268
11269@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
11270
11271 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11272
11273+ pax_force_retaddr
11274 ret;
11275 ENDPROC(serpent_ecb_enc_8way_avx)
11276
11277@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
11278
11279 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11280
11281+ pax_force_retaddr
11282 ret;
11283 ENDPROC(serpent_ecb_dec_8way_avx)
11284
11285@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
11286
11287 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11288
11289+ pax_force_retaddr
11290 ret;
11291 ENDPROC(serpent_cbc_dec_8way_avx)
11292
11293@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
11294
11295 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11296
11297+ pax_force_retaddr
11298 ret;
11299 ENDPROC(serpent_ctr_8way_avx)
11300
11301@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
11302 /* dst <= regs xor IVs(in dst) */
11303 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11304
11305+ pax_force_retaddr
11306 ret;
11307 ENDPROC(serpent_xts_enc_8way_avx)
11308
11309@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
11310 /* dst <= regs xor IVs(in dst) */
11311 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11312
11313+ pax_force_retaddr
11314 ret;
11315 ENDPROC(serpent_xts_dec_8way_avx)
11316diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11317index acc066c..1559cc4 100644
11318--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11319+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11320@@ -25,6 +25,7 @@
11321 */
11322
11323 #include <linux/linkage.h>
11324+#include <asm/alternative-asm.h>
11325
11326 .file "serpent-sse2-x86_64-asm_64.S"
11327 .text
11328@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
11329 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11330 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11331
11332+ pax_force_retaddr
11333 ret;
11334
11335 .L__enc_xor8:
11336 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11337 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11338
11339+ pax_force_retaddr
11340 ret;
11341 ENDPROC(__serpent_enc_blk_8way)
11342
11343@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
11344 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11345 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11346
11347+ pax_force_retaddr
11348 ret;
11349 ENDPROC(serpent_dec_blk_8way)
11350diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11351index a410950..3356d42 100644
11352--- a/arch/x86/crypto/sha1_ssse3_asm.S
11353+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11354@@ -29,6 +29,7 @@
11355 */
11356
11357 #include <linux/linkage.h>
11358+#include <asm/alternative-asm.h>
11359
11360 #define CTX %rdi // arg1
11361 #define BUF %rsi // arg2
11362@@ -104,6 +105,7 @@
11363 pop %r12
11364 pop %rbp
11365 pop %rbx
11366+ pax_force_retaddr 0, 1
11367 ret
11368
11369 ENDPROC(\name)
11370diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11371index 0505813..63b1d00 100644
11372--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11373+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11374@@ -24,6 +24,7 @@
11375 */
11376
11377 #include <linux/linkage.h>
11378+#include <asm/alternative-asm.h>
11379 #include "glue_helper-asm-avx.S"
11380
11381 .file "twofish-avx-x86_64-asm_64.S"
11382@@ -284,6 +285,7 @@ __twofish_enc_blk8:
11383 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11384 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11385
11386+ pax_force_retaddr 0, 1
11387 ret;
11388 ENDPROC(__twofish_enc_blk8)
11389
11390@@ -324,6 +326,7 @@ __twofish_dec_blk8:
11391 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11392 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11393
11394+ pax_force_retaddr 0, 1
11395 ret;
11396 ENDPROC(__twofish_dec_blk8)
11397
11398@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
11399
11400 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11401
11402+ pax_force_retaddr 0, 1
11403 ret;
11404 ENDPROC(twofish_ecb_enc_8way)
11405
11406@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
11407
11408 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11409
11410+ pax_force_retaddr 0, 1
11411 ret;
11412 ENDPROC(twofish_ecb_dec_8way)
11413
11414@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
11415
11416 popq %r12;
11417
11418+ pax_force_retaddr 0, 1
11419 ret;
11420 ENDPROC(twofish_cbc_dec_8way)
11421
11422@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
11423
11424 popq %r12;
11425
11426+ pax_force_retaddr 0, 1
11427 ret;
11428 ENDPROC(twofish_ctr_8way)
11429
11430@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
11431 /* dst <= regs xor IVs(in dst) */
11432 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11433
11434+ pax_force_retaddr 0, 1
11435 ret;
11436 ENDPROC(twofish_xts_enc_8way)
11437
11438@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
11439 /* dst <= regs xor IVs(in dst) */
11440 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11441
11442+ pax_force_retaddr 0, 1
11443 ret;
11444 ENDPROC(twofish_xts_dec_8way)
11445diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11446index 1c3b7ce..b365c5e 100644
11447--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11448+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11449@@ -21,6 +21,7 @@
11450 */
11451
11452 #include <linux/linkage.h>
11453+#include <asm/alternative-asm.h>
11454
11455 .file "twofish-x86_64-asm-3way.S"
11456 .text
11457@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
11458 popq %r13;
11459 popq %r14;
11460 popq %r15;
11461+ pax_force_retaddr 0, 1
11462 ret;
11463
11464 .L__enc_xor3:
11465@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
11466 popq %r13;
11467 popq %r14;
11468 popq %r15;
11469+ pax_force_retaddr 0, 1
11470 ret;
11471 ENDPROC(__twofish_enc_blk_3way)
11472
11473@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
11474 popq %r13;
11475 popq %r14;
11476 popq %r15;
11477+ pax_force_retaddr 0, 1
11478 ret;
11479 ENDPROC(twofish_dec_blk_3way)
11480diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11481index a039d21..29e7615 100644
11482--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11483+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11484@@ -22,6 +22,7 @@
11485
11486 #include <linux/linkage.h>
11487 #include <asm/asm-offsets.h>
11488+#include <asm/alternative-asm.h>
11489
11490 #define a_offset 0
11491 #define b_offset 4
11492@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
11493
11494 popq R1
11495 movq $1,%rax
11496+ pax_force_retaddr 0, 1
11497 ret
11498 ENDPROC(twofish_enc_blk)
11499
11500@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
11501
11502 popq R1
11503 movq $1,%rax
11504+ pax_force_retaddr 0, 1
11505 ret
11506 ENDPROC(twofish_dec_blk)
11507diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11508index 52ff81c..98af645 100644
11509--- a/arch/x86/ia32/ia32_aout.c
11510+++ b/arch/x86/ia32/ia32_aout.c
11511@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11512 unsigned long dump_start, dump_size;
11513 struct user32 dump;
11514
11515+ memset(&dump, 0, sizeof(dump));
11516+
11517 fs = get_fs();
11518 set_fs(KERNEL_DS);
11519 has_dumped = 1;
11520diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11521index cf1a471..3bc4cf8 100644
11522--- a/arch/x86/ia32/ia32_signal.c
11523+++ b/arch/x86/ia32/ia32_signal.c
11524@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
11525 sp -= frame_size;
11526 /* Align the stack pointer according to the i386 ABI,
11527 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11528- sp = ((sp + 4) & -16ul) - 4;
11529+ sp = ((sp - 12) & -16ul) - 4;
11530 return (void __user *) sp;
11531 }
11532
11533@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
11534 * These are actually not used anymore, but left because some
11535 * gdb versions depend on them as a marker.
11536 */
11537- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11538+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11539 } put_user_catch(err);
11540
11541 if (err)
11542@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11543 0xb8,
11544 __NR_ia32_rt_sigreturn,
11545 0x80cd,
11546- 0,
11547+ 0
11548 };
11549
11550 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
11551@@ -463,16 +463,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11552
11553 if (ksig->ka.sa.sa_flags & SA_RESTORER)
11554 restorer = ksig->ka.sa.sa_restorer;
11555+ else if (current->mm->context.vdso)
11556+ /* Return stub is in 32bit vsyscall page */
11557+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11558 else
11559- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11560- rt_sigreturn);
11561+ restorer = &frame->retcode;
11562 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11563
11564 /*
11565 * Not actually used anymore, but left because some gdb
11566 * versions need it.
11567 */
11568- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11569+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11570 } put_user_catch(err);
11571
11572 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
11573diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11574index 474dc1b..24aaa3e 100644
11575--- a/arch/x86/ia32/ia32entry.S
11576+++ b/arch/x86/ia32/ia32entry.S
11577@@ -15,8 +15,10 @@
11578 #include <asm/irqflags.h>
11579 #include <asm/asm.h>
11580 #include <asm/smap.h>
11581+#include <asm/pgtable.h>
11582 #include <linux/linkage.h>
11583 #include <linux/err.h>
11584+#include <asm/alternative-asm.h>
11585
11586 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11587 #include <linux/elf-em.h>
11588@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11589 ENDPROC(native_irq_enable_sysexit)
11590 #endif
11591
11592+ .macro pax_enter_kernel_user
11593+ pax_set_fptr_mask
11594+#ifdef CONFIG_PAX_MEMORY_UDEREF
11595+ call pax_enter_kernel_user
11596+#endif
11597+ .endm
11598+
11599+ .macro pax_exit_kernel_user
11600+#ifdef CONFIG_PAX_MEMORY_UDEREF
11601+ call pax_exit_kernel_user
11602+#endif
11603+#ifdef CONFIG_PAX_RANDKSTACK
11604+ pushq %rax
11605+ pushq %r11
11606+ call pax_randomize_kstack
11607+ popq %r11
11608+ popq %rax
11609+#endif
11610+ .endm
11611+
11612+ .macro pax_erase_kstack
11613+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11614+ call pax_erase_kstack
11615+#endif
11616+ .endm
11617+
11618 /*
11619 * 32bit SYSENTER instruction entry.
11620 *
11621@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11622 CFI_REGISTER rsp,rbp
11623 SWAPGS_UNSAFE_STACK
11624 movq PER_CPU_VAR(kernel_stack), %rsp
11625- addq $(KERNEL_STACK_OFFSET),%rsp
11626- /*
11627- * No need to follow this irqs on/off section: the syscall
11628- * disabled irqs, here we enable it straight after entry:
11629- */
11630- ENABLE_INTERRUPTS(CLBR_NONE)
11631 movl %ebp,%ebp /* zero extension */
11632 pushq_cfi $__USER32_DS
11633 /*CFI_REL_OFFSET ss,0*/
11634@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11635 CFI_REL_OFFSET rsp,0
11636 pushfq_cfi
11637 /*CFI_REL_OFFSET rflags,0*/
11638- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11639- CFI_REGISTER rip,r10
11640+ orl $X86_EFLAGS_IF,(%rsp)
11641+ GET_THREAD_INFO(%r11)
11642+ movl TI_sysenter_return(%r11), %r11d
11643+ CFI_REGISTER rip,r11
11644 pushq_cfi $__USER32_CS
11645 /*CFI_REL_OFFSET cs,0*/
11646 movl %eax, %eax
11647- pushq_cfi %r10
11648+ pushq_cfi %r11
11649 CFI_REL_OFFSET rip,0
11650 pushq_cfi %rax
11651 cld
11652 SAVE_ARGS 0,1,0
11653+ pax_enter_kernel_user
11654+
11655+#ifdef CONFIG_PAX_RANDKSTACK
11656+ pax_erase_kstack
11657+#endif
11658+
11659+ /*
11660+ * No need to follow this irqs on/off section: the syscall
11661+ * disabled irqs, here we enable it straight after entry:
11662+ */
11663+ ENABLE_INTERRUPTS(CLBR_NONE)
11664 /* no need to do an access_ok check here because rbp has been
11665 32bit zero extended */
11666+
11667+#ifdef CONFIG_PAX_MEMORY_UDEREF
11668+ mov pax_user_shadow_base,%r11
11669+ add %r11,%rbp
11670+#endif
11671+
11672 ASM_STAC
11673 1: movl (%rbp),%ebp
11674 _ASM_EXTABLE(1b,ia32_badarg)
11675 ASM_CLAC
11676- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11677- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11678+ GET_THREAD_INFO(%r11)
11679+ orl $TS_COMPAT,TI_status(%r11)
11680+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11681 CFI_REMEMBER_STATE
11682 jnz sysenter_tracesys
11683 cmpq $(IA32_NR_syscalls-1),%rax
11684@@ -162,12 +204,15 @@ sysenter_do_call:
11685 sysenter_dispatch:
11686 call *ia32_sys_call_table(,%rax,8)
11687 movq %rax,RAX-ARGOFFSET(%rsp)
11688+ GET_THREAD_INFO(%r11)
11689 DISABLE_INTERRUPTS(CLBR_NONE)
11690 TRACE_IRQS_OFF
11691- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11692+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11693 jnz sysexit_audit
11694 sysexit_from_sys_call:
11695- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11696+ pax_exit_kernel_user
11697+ pax_erase_kstack
11698+ andl $~TS_COMPAT,TI_status(%r11)
11699 /* clear IF, that popfq doesn't enable interrupts early */
11700 andl $~0x200,EFLAGS-R11(%rsp)
11701 movl RIP-R11(%rsp),%edx /* User %eip */
11702@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11703 movl %eax,%esi /* 2nd arg: syscall number */
11704 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11705 call __audit_syscall_entry
11706+
11707+ pax_erase_kstack
11708+
11709 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11710 cmpq $(IA32_NR_syscalls-1),%rax
11711 ja ia32_badsys
11712@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11713 .endm
11714
11715 .macro auditsys_exit exit
11716- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11717+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11718 jnz ia32_ret_from_sys_call
11719 TRACE_IRQS_ON
11720 ENABLE_INTERRUPTS(CLBR_NONE)
11721@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11722 1: setbe %al /* 1 if error, 0 if not */
11723 movzbl %al,%edi /* zero-extend that into %edi */
11724 call __audit_syscall_exit
11725+ GET_THREAD_INFO(%r11)
11726 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11727 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11728 DISABLE_INTERRUPTS(CLBR_NONE)
11729 TRACE_IRQS_OFF
11730- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11731+ testl %edi,TI_flags(%r11)
11732 jz \exit
11733 CLEAR_RREGS -ARGOFFSET
11734 jmp int_with_check
11735@@ -237,7 +286,7 @@ sysexit_audit:
11736
11737 sysenter_tracesys:
11738 #ifdef CONFIG_AUDITSYSCALL
11739- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11740+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11741 jz sysenter_auditsys
11742 #endif
11743 SAVE_REST
11744@@ -249,6 +298,9 @@ sysenter_tracesys:
11745 RESTORE_REST
11746 cmpq $(IA32_NR_syscalls-1),%rax
11747 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11748+
11749+ pax_erase_kstack
11750+
11751 jmp sysenter_do_call
11752 CFI_ENDPROC
11753 ENDPROC(ia32_sysenter_target)
11754@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11755 ENTRY(ia32_cstar_target)
11756 CFI_STARTPROC32 simple
11757 CFI_SIGNAL_FRAME
11758- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11759+ CFI_DEF_CFA rsp,0
11760 CFI_REGISTER rip,rcx
11761 /*CFI_REGISTER rflags,r11*/
11762 SWAPGS_UNSAFE_STACK
11763 movl %esp,%r8d
11764 CFI_REGISTER rsp,r8
11765 movq PER_CPU_VAR(kernel_stack),%rsp
11766+ SAVE_ARGS 8*6,0,0
11767+ pax_enter_kernel_user
11768+
11769+#ifdef CONFIG_PAX_RANDKSTACK
11770+ pax_erase_kstack
11771+#endif
11772+
11773 /*
11774 * No need to follow this irqs on/off section: the syscall
11775 * disabled irqs and here we enable it straight after entry:
11776 */
11777 ENABLE_INTERRUPTS(CLBR_NONE)
11778- SAVE_ARGS 8,0,0
11779 movl %eax,%eax /* zero extension */
11780 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11781 movq %rcx,RIP-ARGOFFSET(%rsp)
11782@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11783 /* no need to do an access_ok check here because r8 has been
11784 32bit zero extended */
11785 /* hardware stack frame is complete now */
11786+
11787+#ifdef CONFIG_PAX_MEMORY_UDEREF
11788+ mov pax_user_shadow_base,%r11
11789+ add %r11,%r8
11790+#endif
11791+
11792 ASM_STAC
11793 1: movl (%r8),%r9d
11794 _ASM_EXTABLE(1b,ia32_badarg)
11795 ASM_CLAC
11796- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11797- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11798+ GET_THREAD_INFO(%r11)
11799+ orl $TS_COMPAT,TI_status(%r11)
11800+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11801 CFI_REMEMBER_STATE
11802 jnz cstar_tracesys
11803 cmpq $IA32_NR_syscalls-1,%rax
11804@@ -319,12 +384,15 @@ cstar_do_call:
11805 cstar_dispatch:
11806 call *ia32_sys_call_table(,%rax,8)
11807 movq %rax,RAX-ARGOFFSET(%rsp)
11808+ GET_THREAD_INFO(%r11)
11809 DISABLE_INTERRUPTS(CLBR_NONE)
11810 TRACE_IRQS_OFF
11811- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11812+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11813 jnz sysretl_audit
11814 sysretl_from_sys_call:
11815- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11816+ pax_exit_kernel_user
11817+ pax_erase_kstack
11818+ andl $~TS_COMPAT,TI_status(%r11)
11819 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11820 movl RIP-ARGOFFSET(%rsp),%ecx
11821 CFI_REGISTER rip,rcx
11822@@ -352,7 +420,7 @@ sysretl_audit:
11823
11824 cstar_tracesys:
11825 #ifdef CONFIG_AUDITSYSCALL
11826- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11827+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11828 jz cstar_auditsys
11829 #endif
11830 xchgl %r9d,%ebp
11831@@ -366,6 +434,9 @@ cstar_tracesys:
11832 xchgl %ebp,%r9d
11833 cmpq $(IA32_NR_syscalls-1),%rax
11834 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11835+
11836+ pax_erase_kstack
11837+
11838 jmp cstar_do_call
11839 END(ia32_cstar_target)
11840
11841@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11842 CFI_REL_OFFSET rip,RIP-RIP
11843 PARAVIRT_ADJUST_EXCEPTION_FRAME
11844 SWAPGS
11845- /*
11846- * No need to follow this irqs on/off section: the syscall
11847- * disabled irqs and here we enable it straight after entry:
11848- */
11849- ENABLE_INTERRUPTS(CLBR_NONE)
11850 movl %eax,%eax
11851 pushq_cfi %rax
11852 cld
11853 /* note the registers are not zero extended to the sf.
11854 this could be a problem. */
11855 SAVE_ARGS 0,1,0
11856- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11857- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11858+ pax_enter_kernel_user
11859+
11860+#ifdef CONFIG_PAX_RANDKSTACK
11861+ pax_erase_kstack
11862+#endif
11863+
11864+ /*
11865+ * No need to follow this irqs on/off section: the syscall
11866+ * disabled irqs and here we enable it straight after entry:
11867+ */
11868+ ENABLE_INTERRUPTS(CLBR_NONE)
11869+ GET_THREAD_INFO(%r11)
11870+ orl $TS_COMPAT,TI_status(%r11)
11871+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11872 jnz ia32_tracesys
11873 cmpq $(IA32_NR_syscalls-1),%rax
11874 ja ia32_badsys
11875@@ -442,6 +520,9 @@ ia32_tracesys:
11876 RESTORE_REST
11877 cmpq $(IA32_NR_syscalls-1),%rax
11878 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11879+
11880+ pax_erase_kstack
11881+
11882 jmp ia32_do_call
11883 END(ia32_syscall)
11884
11885diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11886index 8e0ceec..af13504 100644
11887--- a/arch/x86/ia32/sys_ia32.c
11888+++ b/arch/x86/ia32/sys_ia32.c
11889@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11890 */
11891 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11892 {
11893- typeof(ubuf->st_uid) uid = 0;
11894- typeof(ubuf->st_gid) gid = 0;
11895+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11896+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11897 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11898 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11899 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11900diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11901index 372231c..a5aa1a1 100644
11902--- a/arch/x86/include/asm/alternative-asm.h
11903+++ b/arch/x86/include/asm/alternative-asm.h
11904@@ -18,6 +18,45 @@
11905 .endm
11906 #endif
11907
11908+#ifdef KERNEXEC_PLUGIN
11909+ .macro pax_force_retaddr_bts rip=0
11910+ btsq $63,\rip(%rsp)
11911+ .endm
11912+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11913+ .macro pax_force_retaddr rip=0, reload=0
11914+ btsq $63,\rip(%rsp)
11915+ .endm
11916+ .macro pax_force_fptr ptr
11917+ btsq $63,\ptr
11918+ .endm
11919+ .macro pax_set_fptr_mask
11920+ .endm
11921+#endif
11922+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11923+ .macro pax_force_retaddr rip=0, reload=0
11924+ .if \reload
11925+ pax_set_fptr_mask
11926+ .endif
11927+ orq %r10,\rip(%rsp)
11928+ .endm
11929+ .macro pax_force_fptr ptr
11930+ orq %r10,\ptr
11931+ .endm
11932+ .macro pax_set_fptr_mask
11933+ movabs $0x8000000000000000,%r10
11934+ .endm
11935+#endif
11936+#else
11937+ .macro pax_force_retaddr rip=0, reload=0
11938+ .endm
11939+ .macro pax_force_fptr ptr
11940+ .endm
11941+ .macro pax_force_retaddr_bts rip=0
11942+ .endm
11943+ .macro pax_set_fptr_mask
11944+ .endm
11945+#endif
11946+
11947 .macro altinstruction_entry orig alt feature orig_len alt_len
11948 .long \orig - .
11949 .long \alt - .
11950diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11951index 58ed6d9..f1cbe58 100644
11952--- a/arch/x86/include/asm/alternative.h
11953+++ b/arch/x86/include/asm/alternative.h
11954@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11955 ".pushsection .discard,\"aw\",@progbits\n" \
11956 DISCARD_ENTRY(1) \
11957 ".popsection\n" \
11958- ".pushsection .altinstr_replacement, \"ax\"\n" \
11959+ ".pushsection .altinstr_replacement, \"a\"\n" \
11960 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11961 ".popsection"
11962
11963@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11964 DISCARD_ENTRY(1) \
11965 DISCARD_ENTRY(2) \
11966 ".popsection\n" \
11967- ".pushsection .altinstr_replacement, \"ax\"\n" \
11968+ ".pushsection .altinstr_replacement, \"a\"\n" \
11969 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11970 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11971 ".popsection"
11972diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11973index 3388034..050f0b9 100644
11974--- a/arch/x86/include/asm/apic.h
11975+++ b/arch/x86/include/asm/apic.h
11976@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11977
11978 #ifdef CONFIG_X86_LOCAL_APIC
11979
11980-extern unsigned int apic_verbosity;
11981+extern int apic_verbosity;
11982 extern int local_apic_timer_c2_ok;
11983
11984 extern int disable_apic;
11985diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11986index 20370c6..a2eb9b0 100644
11987--- a/arch/x86/include/asm/apm.h
11988+++ b/arch/x86/include/asm/apm.h
11989@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11990 __asm__ __volatile__(APM_DO_ZERO_SEGS
11991 "pushl %%edi\n\t"
11992 "pushl %%ebp\n\t"
11993- "lcall *%%cs:apm_bios_entry\n\t"
11994+ "lcall *%%ss:apm_bios_entry\n\t"
11995 "setc %%al\n\t"
11996 "popl %%ebp\n\t"
11997 "popl %%edi\n\t"
11998@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11999 __asm__ __volatile__(APM_DO_ZERO_SEGS
12000 "pushl %%edi\n\t"
12001 "pushl %%ebp\n\t"
12002- "lcall *%%cs:apm_bios_entry\n\t"
12003+ "lcall *%%ss:apm_bios_entry\n\t"
12004 "setc %%bl\n\t"
12005 "popl %%ebp\n\t"
12006 "popl %%edi\n\t"
12007diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
12008index 722aa3b..3a0bb27 100644
12009--- a/arch/x86/include/asm/atomic.h
12010+++ b/arch/x86/include/asm/atomic.h
12011@@ -22,7 +22,18 @@
12012 */
12013 static inline int atomic_read(const atomic_t *v)
12014 {
12015- return (*(volatile int *)&(v)->counter);
12016+ return (*(volatile const int *)&(v)->counter);
12017+}
12018+
12019+/**
12020+ * atomic_read_unchecked - read atomic variable
12021+ * @v: pointer of type atomic_unchecked_t
12022+ *
12023+ * Atomically reads the value of @v.
12024+ */
12025+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
12026+{
12027+ return (*(volatile const int *)&(v)->counter);
12028 }
12029
12030 /**
12031@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12032 }
12033
12034 /**
12035+ * atomic_set_unchecked - set atomic variable
12036+ * @v: pointer of type atomic_unchecked_t
12037+ * @i: required value
12038+ *
12039+ * Atomically sets the value of @v to @i.
12040+ */
12041+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12042+{
12043+ v->counter = i;
12044+}
12045+
12046+/**
12047 * atomic_add - add integer to atomic variable
12048 * @i: integer value to add
12049 * @v: pointer of type atomic_t
12050@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12051 */
12052 static inline void atomic_add(int i, atomic_t *v)
12053 {
12054- asm volatile(LOCK_PREFIX "addl %1,%0"
12055+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12056+
12057+#ifdef CONFIG_PAX_REFCOUNT
12058+ "jno 0f\n"
12059+ LOCK_PREFIX "subl %1,%0\n"
12060+ "int $4\n0:\n"
12061+ _ASM_EXTABLE(0b, 0b)
12062+#endif
12063+
12064+ : "+m" (v->counter)
12065+ : "ir" (i));
12066+}
12067+
12068+/**
12069+ * atomic_add_unchecked - add integer to atomic variable
12070+ * @i: integer value to add
12071+ * @v: pointer of type atomic_unchecked_t
12072+ *
12073+ * Atomically adds @i to @v.
12074+ */
12075+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12076+{
12077+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12078 : "+m" (v->counter)
12079 : "ir" (i));
12080 }
12081@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12082 */
12083 static inline void atomic_sub(int i, atomic_t *v)
12084 {
12085- asm volatile(LOCK_PREFIX "subl %1,%0"
12086+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12087+
12088+#ifdef CONFIG_PAX_REFCOUNT
12089+ "jno 0f\n"
12090+ LOCK_PREFIX "addl %1,%0\n"
12091+ "int $4\n0:\n"
12092+ _ASM_EXTABLE(0b, 0b)
12093+#endif
12094+
12095+ : "+m" (v->counter)
12096+ : "ir" (i));
12097+}
12098+
12099+/**
12100+ * atomic_sub_unchecked - subtract integer from atomic variable
12101+ * @i: integer value to subtract
12102+ * @v: pointer of type atomic_unchecked_t
12103+ *
12104+ * Atomically subtracts @i from @v.
12105+ */
12106+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12107+{
12108+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12109 : "+m" (v->counter)
12110 : "ir" (i));
12111 }
12112@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12113 {
12114 unsigned char c;
12115
12116- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12117+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12118+
12119+#ifdef CONFIG_PAX_REFCOUNT
12120+ "jno 0f\n"
12121+ LOCK_PREFIX "addl %2,%0\n"
12122+ "int $4\n0:\n"
12123+ _ASM_EXTABLE(0b, 0b)
12124+#endif
12125+
12126+ "sete %1\n"
12127 : "+m" (v->counter), "=qm" (c)
12128 : "ir" (i) : "memory");
12129 return c;
12130@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12131 */
12132 static inline void atomic_inc(atomic_t *v)
12133 {
12134- asm volatile(LOCK_PREFIX "incl %0"
12135+ asm volatile(LOCK_PREFIX "incl %0\n"
12136+
12137+#ifdef CONFIG_PAX_REFCOUNT
12138+ "jno 0f\n"
12139+ LOCK_PREFIX "decl %0\n"
12140+ "int $4\n0:\n"
12141+ _ASM_EXTABLE(0b, 0b)
12142+#endif
12143+
12144+ : "+m" (v->counter));
12145+}
12146+
12147+/**
12148+ * atomic_inc_unchecked - increment atomic variable
12149+ * @v: pointer of type atomic_unchecked_t
12150+ *
12151+ * Atomically increments @v by 1.
12152+ */
12153+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12154+{
12155+ asm volatile(LOCK_PREFIX "incl %0\n"
12156 : "+m" (v->counter));
12157 }
12158
12159@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12160 */
12161 static inline void atomic_dec(atomic_t *v)
12162 {
12163- asm volatile(LOCK_PREFIX "decl %0"
12164+ asm volatile(LOCK_PREFIX "decl %0\n"
12165+
12166+#ifdef CONFIG_PAX_REFCOUNT
12167+ "jno 0f\n"
12168+ LOCK_PREFIX "incl %0\n"
12169+ "int $4\n0:\n"
12170+ _ASM_EXTABLE(0b, 0b)
12171+#endif
12172+
12173+ : "+m" (v->counter));
12174+}
12175+
12176+/**
12177+ * atomic_dec_unchecked - decrement atomic variable
12178+ * @v: pointer of type atomic_unchecked_t
12179+ *
12180+ * Atomically decrements @v by 1.
12181+ */
12182+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12183+{
12184+ asm volatile(LOCK_PREFIX "decl %0\n"
12185 : "+m" (v->counter));
12186 }
12187
12188@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12189 {
12190 unsigned char c;
12191
12192- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12193+ asm volatile(LOCK_PREFIX "decl %0\n"
12194+
12195+#ifdef CONFIG_PAX_REFCOUNT
12196+ "jno 0f\n"
12197+ LOCK_PREFIX "incl %0\n"
12198+ "int $4\n0:\n"
12199+ _ASM_EXTABLE(0b, 0b)
12200+#endif
12201+
12202+ "sete %1\n"
12203 : "+m" (v->counter), "=qm" (c)
12204 : : "memory");
12205 return c != 0;
12206@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12207 {
12208 unsigned char c;
12209
12210- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12211+ asm volatile(LOCK_PREFIX "incl %0\n"
12212+
12213+#ifdef CONFIG_PAX_REFCOUNT
12214+ "jno 0f\n"
12215+ LOCK_PREFIX "decl %0\n"
12216+ "int $4\n0:\n"
12217+ _ASM_EXTABLE(0b, 0b)
12218+#endif
12219+
12220+ "sete %1\n"
12221+ : "+m" (v->counter), "=qm" (c)
12222+ : : "memory");
12223+ return c != 0;
12224+}
12225+
12226+/**
12227+ * atomic_inc_and_test_unchecked - increment and test
12228+ * @v: pointer of type atomic_unchecked_t
12229+ *
12230+ * Atomically increments @v by 1
12231+ * and returns true if the result is zero, or false for all
12232+ * other cases.
12233+ */
12234+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12235+{
12236+ unsigned char c;
12237+
12238+ asm volatile(LOCK_PREFIX "incl %0\n"
12239+ "sete %1\n"
12240 : "+m" (v->counter), "=qm" (c)
12241 : : "memory");
12242 return c != 0;
12243@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12244 {
12245 unsigned char c;
12246
12247- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12248+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12249+
12250+#ifdef CONFIG_PAX_REFCOUNT
12251+ "jno 0f\n"
12252+ LOCK_PREFIX "subl %2,%0\n"
12253+ "int $4\n0:\n"
12254+ _ASM_EXTABLE(0b, 0b)
12255+#endif
12256+
12257+ "sets %1\n"
12258 : "+m" (v->counter), "=qm" (c)
12259 : "ir" (i) : "memory");
12260 return c;
12261@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12262 */
12263 static inline int atomic_add_return(int i, atomic_t *v)
12264 {
12265+ return i + xadd_check_overflow(&v->counter, i);
12266+}
12267+
12268+/**
12269+ * atomic_add_return_unchecked - add integer and return
12270+ * @i: integer value to add
12271+ * @v: pointer of type atomic_unchecked_t
12272+ *
12273+ * Atomically adds @i to @v and returns @i + @v
12274+ */
12275+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12276+{
12277 return i + xadd(&v->counter, i);
12278 }
12279
12280@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12281 }
12282
12283 #define atomic_inc_return(v) (atomic_add_return(1, v))
12284+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12285+{
12286+ return atomic_add_return_unchecked(1, v);
12287+}
12288 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12289
12290 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12291@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12292 return cmpxchg(&v->counter, old, new);
12293 }
12294
12295+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12296+{
12297+ return cmpxchg(&v->counter, old, new);
12298+}
12299+
12300 static inline int atomic_xchg(atomic_t *v, int new)
12301 {
12302 return xchg(&v->counter, new);
12303 }
12304
12305+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12306+{
12307+ return xchg(&v->counter, new);
12308+}
12309+
12310 /**
12311 * __atomic_add_unless - add unless the number is already a given value
12312 * @v: pointer of type atomic_t
12313@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12314 */
12315 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12316 {
12317- int c, old;
12318+ int c, old, new;
12319 c = atomic_read(v);
12320 for (;;) {
12321- if (unlikely(c == (u)))
12322+ if (unlikely(c == u))
12323 break;
12324- old = atomic_cmpxchg((v), c, c + (a));
12325+
12326+ asm volatile("addl %2,%0\n"
12327+
12328+#ifdef CONFIG_PAX_REFCOUNT
12329+ "jno 0f\n"
12330+ "subl %2,%0\n"
12331+ "int $4\n0:\n"
12332+ _ASM_EXTABLE(0b, 0b)
12333+#endif
12334+
12335+ : "=r" (new)
12336+ : "0" (c), "ir" (a));
12337+
12338+ old = atomic_cmpxchg(v, c, new);
12339 if (likely(old == c))
12340 break;
12341 c = old;
12342@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12343 }
12344
12345 /**
12346+ * atomic_inc_not_zero_hint - increment if not null
12347+ * @v: pointer of type atomic_t
12348+ * @hint: probable value of the atomic before the increment
12349+ *
12350+ * This version of atomic_inc_not_zero() gives a hint of probable
12351+ * value of the atomic. This helps processor to not read the memory
12352+ * before doing the atomic read/modify/write cycle, lowering
12353+ * number of bus transactions on some arches.
12354+ *
12355+ * Returns: 0 if increment was not done, 1 otherwise.
12356+ */
12357+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12358+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12359+{
12360+ int val, c = hint, new;
12361+
12362+ /* sanity test, should be removed by compiler if hint is a constant */
12363+ if (!hint)
12364+ return __atomic_add_unless(v, 1, 0);
12365+
12366+ do {
12367+ asm volatile("incl %0\n"
12368+
12369+#ifdef CONFIG_PAX_REFCOUNT
12370+ "jno 0f\n"
12371+ "decl %0\n"
12372+ "int $4\n0:\n"
12373+ _ASM_EXTABLE(0b, 0b)
12374+#endif
12375+
12376+ : "=r" (new)
12377+ : "0" (c));
12378+
12379+ val = atomic_cmpxchg(v, c, new);
12380+ if (val == c)
12381+ return 1;
12382+ c = val;
12383+ } while (c);
12384+
12385+ return 0;
12386+}
12387+
12388+/**
12389 * atomic_inc_short - increment of a short integer
12390 * @v: pointer to type int
12391 *
12392@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12393 #endif
12394
12395 /* These are x86-specific, used by some header files */
12396-#define atomic_clear_mask(mask, addr) \
12397- asm volatile(LOCK_PREFIX "andl %0,%1" \
12398- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12399+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12400+{
12401+ asm volatile(LOCK_PREFIX "andl %1,%0"
12402+ : "+m" (v->counter)
12403+ : "r" (~(mask))
12404+ : "memory");
12405+}
12406
12407-#define atomic_set_mask(mask, addr) \
12408- asm volatile(LOCK_PREFIX "orl %0,%1" \
12409- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12410- : "memory")
12411+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12412+{
12413+ asm volatile(LOCK_PREFIX "andl %1,%0"
12414+ : "+m" (v->counter)
12415+ : "r" (~(mask))
12416+ : "memory");
12417+}
12418+
12419+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12420+{
12421+ asm volatile(LOCK_PREFIX "orl %1,%0"
12422+ : "+m" (v->counter)
12423+ : "r" (mask)
12424+ : "memory");
12425+}
12426+
12427+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12428+{
12429+ asm volatile(LOCK_PREFIX "orl %1,%0"
12430+ : "+m" (v->counter)
12431+ : "r" (mask)
12432+ : "memory");
12433+}
12434
12435 /* Atomic operations are already serializing on x86 */
12436 #define smp_mb__before_atomic_dec() barrier()
12437diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12438index b154de7..aadebd8 100644
12439--- a/arch/x86/include/asm/atomic64_32.h
12440+++ b/arch/x86/include/asm/atomic64_32.h
12441@@ -12,6 +12,14 @@ typedef struct {
12442 u64 __aligned(8) counter;
12443 } atomic64_t;
12444
12445+#ifdef CONFIG_PAX_REFCOUNT
12446+typedef struct {
12447+ u64 __aligned(8) counter;
12448+} atomic64_unchecked_t;
12449+#else
12450+typedef atomic64_t atomic64_unchecked_t;
12451+#endif
12452+
12453 #define ATOMIC64_INIT(val) { (val) }
12454
12455 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12456@@ -37,21 +45,31 @@ typedef struct {
12457 ATOMIC64_DECL_ONE(sym##_386)
12458
12459 ATOMIC64_DECL_ONE(add_386);
12460+ATOMIC64_DECL_ONE(add_unchecked_386);
12461 ATOMIC64_DECL_ONE(sub_386);
12462+ATOMIC64_DECL_ONE(sub_unchecked_386);
12463 ATOMIC64_DECL_ONE(inc_386);
12464+ATOMIC64_DECL_ONE(inc_unchecked_386);
12465 ATOMIC64_DECL_ONE(dec_386);
12466+ATOMIC64_DECL_ONE(dec_unchecked_386);
12467 #endif
12468
12469 #define alternative_atomic64(f, out, in...) \
12470 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12471
12472 ATOMIC64_DECL(read);
12473+ATOMIC64_DECL(read_unchecked);
12474 ATOMIC64_DECL(set);
12475+ATOMIC64_DECL(set_unchecked);
12476 ATOMIC64_DECL(xchg);
12477 ATOMIC64_DECL(add_return);
12478+ATOMIC64_DECL(add_return_unchecked);
12479 ATOMIC64_DECL(sub_return);
12480+ATOMIC64_DECL(sub_return_unchecked);
12481 ATOMIC64_DECL(inc_return);
12482+ATOMIC64_DECL(inc_return_unchecked);
12483 ATOMIC64_DECL(dec_return);
12484+ATOMIC64_DECL(dec_return_unchecked);
12485 ATOMIC64_DECL(dec_if_positive);
12486 ATOMIC64_DECL(inc_not_zero);
12487 ATOMIC64_DECL(add_unless);
12488@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12489 }
12490
12491 /**
12492+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12493+ * @p: pointer to type atomic64_unchecked_t
12494+ * @o: expected value
12495+ * @n: new value
12496+ *
12497+ * Atomically sets @v to @n if it was equal to @o and returns
12498+ * the old value.
12499+ */
12500+
12501+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12502+{
12503+ return cmpxchg64(&v->counter, o, n);
12504+}
12505+
12506+/**
12507 * atomic64_xchg - xchg atomic64 variable
12508 * @v: pointer to type atomic64_t
12509 * @n: value to assign
12510@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12511 }
12512
12513 /**
12514+ * atomic64_set_unchecked - set atomic64 variable
12515+ * @v: pointer to type atomic64_unchecked_t
12516+ * @n: value to assign
12517+ *
12518+ * Atomically sets the value of @v to @n.
12519+ */
12520+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12521+{
12522+ unsigned high = (unsigned)(i >> 32);
12523+ unsigned low = (unsigned)i;
12524+ alternative_atomic64(set, /* no output */,
12525+ "S" (v), "b" (low), "c" (high)
12526+ : "eax", "edx", "memory");
12527+}
12528+
12529+/**
12530 * atomic64_read - read atomic64 variable
12531 * @v: pointer to type atomic64_t
12532 *
12533@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12534 }
12535
12536 /**
12537+ * atomic64_read_unchecked - read atomic64 variable
12538+ * @v: pointer to type atomic64_unchecked_t
12539+ *
12540+ * Atomically reads the value of @v and returns it.
12541+ */
12542+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12543+{
12544+ long long r;
12545+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12546+ return r;
12547+ }
12548+
12549+/**
12550 * atomic64_add_return - add and return
12551 * @i: integer value to add
12552 * @v: pointer to type atomic64_t
12553@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12554 return i;
12555 }
12556
12557+/**
12558+ * atomic64_add_return_unchecked - add and return
12559+ * @i: integer value to add
12560+ * @v: pointer to type atomic64_unchecked_t
12561+ *
12562+ * Atomically adds @i to @v and returns @i + *@v
12563+ */
12564+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12565+{
12566+ alternative_atomic64(add_return_unchecked,
12567+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12568+ ASM_NO_INPUT_CLOBBER("memory"));
12569+ return i;
12570+}
12571+
12572 /*
12573 * Other variants with different arithmetic operators:
12574 */
12575@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12576 return a;
12577 }
12578
12579+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12580+{
12581+ long long a;
12582+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12583+ "S" (v) : "memory", "ecx");
12584+ return a;
12585+}
12586+
12587 static inline long long atomic64_dec_return(atomic64_t *v)
12588 {
12589 long long a;
12590@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12591 }
12592
12593 /**
12594+ * atomic64_add_unchecked - add integer to atomic64 variable
12595+ * @i: integer value to add
12596+ * @v: pointer to type atomic64_unchecked_t
12597+ *
12598+ * Atomically adds @i to @v.
12599+ */
12600+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12601+{
12602+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12603+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12604+ ASM_NO_INPUT_CLOBBER("memory"));
12605+ return i;
12606+}
12607+
12608+/**
12609 * atomic64_sub - subtract the atomic64 variable
12610 * @i: integer value to subtract
12611 * @v: pointer to type atomic64_t
12612diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12613index 0e1cbfc..5623683 100644
12614--- a/arch/x86/include/asm/atomic64_64.h
12615+++ b/arch/x86/include/asm/atomic64_64.h
12616@@ -18,7 +18,19 @@
12617 */
12618 static inline long atomic64_read(const atomic64_t *v)
12619 {
12620- return (*(volatile long *)&(v)->counter);
12621+ return (*(volatile const long *)&(v)->counter);
12622+}
12623+
12624+/**
12625+ * atomic64_read_unchecked - read atomic64 variable
12626+ * @v: pointer of type atomic64_unchecked_t
12627+ *
12628+ * Atomically reads the value of @v.
12629+ * Doesn't imply a read memory barrier.
12630+ */
12631+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12632+{
12633+ return (*(volatile const long *)&(v)->counter);
12634 }
12635
12636 /**
12637@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12638 }
12639
12640 /**
12641+ * atomic64_set_unchecked - set atomic64 variable
12642+ * @v: pointer to type atomic64_unchecked_t
12643+ * @i: required value
12644+ *
12645+ * Atomically sets the value of @v to @i.
12646+ */
12647+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12648+{
12649+ v->counter = i;
12650+}
12651+
12652+/**
12653 * atomic64_add - add integer to atomic64 variable
12654 * @i: integer value to add
12655 * @v: pointer to type atomic64_t
12656@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12657 */
12658 static inline void atomic64_add(long i, atomic64_t *v)
12659 {
12660+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12661+
12662+#ifdef CONFIG_PAX_REFCOUNT
12663+ "jno 0f\n"
12664+ LOCK_PREFIX "subq %1,%0\n"
12665+ "int $4\n0:\n"
12666+ _ASM_EXTABLE(0b, 0b)
12667+#endif
12668+
12669+ : "=m" (v->counter)
12670+ : "er" (i), "m" (v->counter));
12671+}
12672+
12673+/**
12674+ * atomic64_add_unchecked - add integer to atomic64 variable
12675+ * @i: integer value to add
12676+ * @v: pointer to type atomic64_unchecked_t
12677+ *
12678+ * Atomically adds @i to @v.
12679+ */
12680+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12681+{
12682 asm volatile(LOCK_PREFIX "addq %1,%0"
12683 : "=m" (v->counter)
12684 : "er" (i), "m" (v->counter));
12685@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12686 */
12687 static inline void atomic64_sub(long i, atomic64_t *v)
12688 {
12689- asm volatile(LOCK_PREFIX "subq %1,%0"
12690+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12691+
12692+#ifdef CONFIG_PAX_REFCOUNT
12693+ "jno 0f\n"
12694+ LOCK_PREFIX "addq %1,%0\n"
12695+ "int $4\n0:\n"
12696+ _ASM_EXTABLE(0b, 0b)
12697+#endif
12698+
12699+ : "=m" (v->counter)
12700+ : "er" (i), "m" (v->counter));
12701+}
12702+
12703+/**
12704+ * atomic64_sub_unchecked - subtract the atomic64 variable
12705+ * @i: integer value to subtract
12706+ * @v: pointer to type atomic64_unchecked_t
12707+ *
12708+ * Atomically subtracts @i from @v.
12709+ */
12710+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12711+{
12712+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12713 : "=m" (v->counter)
12714 : "er" (i), "m" (v->counter));
12715 }
12716@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12717 {
12718 unsigned char c;
12719
12720- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12721+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12722+
12723+#ifdef CONFIG_PAX_REFCOUNT
12724+ "jno 0f\n"
12725+ LOCK_PREFIX "addq %2,%0\n"
12726+ "int $4\n0:\n"
12727+ _ASM_EXTABLE(0b, 0b)
12728+#endif
12729+
12730+ "sete %1\n"
12731 : "=m" (v->counter), "=qm" (c)
12732 : "er" (i), "m" (v->counter) : "memory");
12733 return c;
12734@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12735 */
12736 static inline void atomic64_inc(atomic64_t *v)
12737 {
12738+ asm volatile(LOCK_PREFIX "incq %0\n"
12739+
12740+#ifdef CONFIG_PAX_REFCOUNT
12741+ "jno 0f\n"
12742+ LOCK_PREFIX "decq %0\n"
12743+ "int $4\n0:\n"
12744+ _ASM_EXTABLE(0b, 0b)
12745+#endif
12746+
12747+ : "=m" (v->counter)
12748+ : "m" (v->counter));
12749+}
12750+
12751+/**
12752+ * atomic64_inc_unchecked - increment atomic64 variable
12753+ * @v: pointer to type atomic64_unchecked_t
12754+ *
12755+ * Atomically increments @v by 1.
12756+ */
12757+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12758+{
12759 asm volatile(LOCK_PREFIX "incq %0"
12760 : "=m" (v->counter)
12761 : "m" (v->counter));
12762@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12763 */
12764 static inline void atomic64_dec(atomic64_t *v)
12765 {
12766- asm volatile(LOCK_PREFIX "decq %0"
12767+ asm volatile(LOCK_PREFIX "decq %0\n"
12768+
12769+#ifdef CONFIG_PAX_REFCOUNT
12770+ "jno 0f\n"
12771+ LOCK_PREFIX "incq %0\n"
12772+ "int $4\n0:\n"
12773+ _ASM_EXTABLE(0b, 0b)
12774+#endif
12775+
12776+ : "=m" (v->counter)
12777+ : "m" (v->counter));
12778+}
12779+
12780+/**
12781+ * atomic64_dec_unchecked - decrement atomic64 variable
12782+ * @v: pointer to type atomic64_t
12783+ *
12784+ * Atomically decrements @v by 1.
12785+ */
12786+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12787+{
12788+ asm volatile(LOCK_PREFIX "decq %0\n"
12789 : "=m" (v->counter)
12790 : "m" (v->counter));
12791 }
12792@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12793 {
12794 unsigned char c;
12795
12796- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12797+ asm volatile(LOCK_PREFIX "decq %0\n"
12798+
12799+#ifdef CONFIG_PAX_REFCOUNT
12800+ "jno 0f\n"
12801+ LOCK_PREFIX "incq %0\n"
12802+ "int $4\n0:\n"
12803+ _ASM_EXTABLE(0b, 0b)
12804+#endif
12805+
12806+ "sete %1\n"
12807 : "=m" (v->counter), "=qm" (c)
12808 : "m" (v->counter) : "memory");
12809 return c != 0;
12810@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12811 {
12812 unsigned char c;
12813
12814- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12815+ asm volatile(LOCK_PREFIX "incq %0\n"
12816+
12817+#ifdef CONFIG_PAX_REFCOUNT
12818+ "jno 0f\n"
12819+ LOCK_PREFIX "decq %0\n"
12820+ "int $4\n0:\n"
12821+ _ASM_EXTABLE(0b, 0b)
12822+#endif
12823+
12824+ "sete %1\n"
12825 : "=m" (v->counter), "=qm" (c)
12826 : "m" (v->counter) : "memory");
12827 return c != 0;
12828@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12829 {
12830 unsigned char c;
12831
12832- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12833+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12834+
12835+#ifdef CONFIG_PAX_REFCOUNT
12836+ "jno 0f\n"
12837+ LOCK_PREFIX "subq %2,%0\n"
12838+ "int $4\n0:\n"
12839+ _ASM_EXTABLE(0b, 0b)
12840+#endif
12841+
12842+ "sets %1\n"
12843 : "=m" (v->counter), "=qm" (c)
12844 : "er" (i), "m" (v->counter) : "memory");
12845 return c;
12846@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12847 */
12848 static inline long atomic64_add_return(long i, atomic64_t *v)
12849 {
12850+ return i + xadd_check_overflow(&v->counter, i);
12851+}
12852+
12853+/**
12854+ * atomic64_add_return_unchecked - add and return
12855+ * @i: integer value to add
12856+ * @v: pointer to type atomic64_unchecked_t
12857+ *
12858+ * Atomically adds @i to @v and returns @i + @v
12859+ */
12860+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12861+{
12862 return i + xadd(&v->counter, i);
12863 }
12864
12865@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12866 }
12867
12868 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12869+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12870+{
12871+ return atomic64_add_return_unchecked(1, v);
12872+}
12873 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12874
12875 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12876@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12877 return cmpxchg(&v->counter, old, new);
12878 }
12879
12880+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12881+{
12882+ return cmpxchg(&v->counter, old, new);
12883+}
12884+
12885 static inline long atomic64_xchg(atomic64_t *v, long new)
12886 {
12887 return xchg(&v->counter, new);
12888@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12889 */
12890 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12891 {
12892- long c, old;
12893+ long c, old, new;
12894 c = atomic64_read(v);
12895 for (;;) {
12896- if (unlikely(c == (u)))
12897+ if (unlikely(c == u))
12898 break;
12899- old = atomic64_cmpxchg((v), c, c + (a));
12900+
12901+ asm volatile("add %2,%0\n"
12902+
12903+#ifdef CONFIG_PAX_REFCOUNT
12904+ "jno 0f\n"
12905+ "sub %2,%0\n"
12906+ "int $4\n0:\n"
12907+ _ASM_EXTABLE(0b, 0b)
12908+#endif
12909+
12910+ : "=r" (new)
12911+ : "0" (c), "ir" (a));
12912+
12913+ old = atomic64_cmpxchg(v, c, new);
12914 if (likely(old == c))
12915 break;
12916 c = old;
12917 }
12918- return c != (u);
12919+ return c != u;
12920 }
12921
12922 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12923diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12924index 6dfd019..28e188d 100644
12925--- a/arch/x86/include/asm/bitops.h
12926+++ b/arch/x86/include/asm/bitops.h
12927@@ -40,7 +40,7 @@
12928 * a mask operation on a byte.
12929 */
12930 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12931-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12932+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12933 #define CONST_MASK(nr) (1 << ((nr) & 7))
12934
12935 /**
12936@@ -486,7 +486,7 @@ static inline int fls(int x)
12937 * at position 64.
12938 */
12939 #ifdef CONFIG_X86_64
12940-static __always_inline int fls64(__u64 x)
12941+static __always_inline long fls64(__u64 x)
12942 {
12943 int bitpos = -1;
12944 /*
12945diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12946index 4fa687a..60f2d39 100644
12947--- a/arch/x86/include/asm/boot.h
12948+++ b/arch/x86/include/asm/boot.h
12949@@ -6,10 +6,15 @@
12950 #include <uapi/asm/boot.h>
12951
12952 /* Physical address where kernel should be loaded. */
12953-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12954+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12955 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12956 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12957
12958+#ifndef __ASSEMBLY__
12959+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12960+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12961+#endif
12962+
12963 /* Minimum kernel alignment, as a power of two */
12964 #ifdef CONFIG_X86_64
12965 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12966diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12967index 48f99f1..d78ebf9 100644
12968--- a/arch/x86/include/asm/cache.h
12969+++ b/arch/x86/include/asm/cache.h
12970@@ -5,12 +5,13 @@
12971
12972 /* L1 cache line size */
12973 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12974-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12975+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12976
12977 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12978+#define __read_only __attribute__((__section__(".data..read_only")))
12979
12980 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12981-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12982+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12983
12984 #ifdef CONFIG_X86_VSMP
12985 #ifdef CONFIG_SMP
12986diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12987index 9863ee3..4a1f8e1 100644
12988--- a/arch/x86/include/asm/cacheflush.h
12989+++ b/arch/x86/include/asm/cacheflush.h
12990@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12991 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12992
12993 if (pg_flags == _PGMT_DEFAULT)
12994- return -1;
12995+ return ~0UL;
12996 else if (pg_flags == _PGMT_WC)
12997 return _PAGE_CACHE_WC;
12998 else if (pg_flags == _PGMT_UC_MINUS)
12999diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
13000index 46fc474..b02b0f9 100644
13001--- a/arch/x86/include/asm/checksum_32.h
13002+++ b/arch/x86/include/asm/checksum_32.h
13003@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
13004 int len, __wsum sum,
13005 int *src_err_ptr, int *dst_err_ptr);
13006
13007+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
13008+ int len, __wsum sum,
13009+ int *src_err_ptr, int *dst_err_ptr);
13010+
13011+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
13012+ int len, __wsum sum,
13013+ int *src_err_ptr, int *dst_err_ptr);
13014+
13015 /*
13016 * Note: when you get a NULL pointer exception here this means someone
13017 * passed in an incorrect kernel address to one of these functions.
13018@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
13019 int *err_ptr)
13020 {
13021 might_sleep();
13022- return csum_partial_copy_generic((__force void *)src, dst,
13023+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
13024 len, sum, err_ptr, NULL);
13025 }
13026
13027@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
13028 {
13029 might_sleep();
13030 if (access_ok(VERIFY_WRITE, dst, len))
13031- return csum_partial_copy_generic(src, (__force void *)dst,
13032+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13033 len, sum, NULL, err_ptr);
13034
13035 if (len)
13036diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13037index d47786a..ce1b05d 100644
13038--- a/arch/x86/include/asm/cmpxchg.h
13039+++ b/arch/x86/include/asm/cmpxchg.h
13040@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13041 __compiletime_error("Bad argument size for cmpxchg");
13042 extern void __xadd_wrong_size(void)
13043 __compiletime_error("Bad argument size for xadd");
13044+extern void __xadd_check_overflow_wrong_size(void)
13045+ __compiletime_error("Bad argument size for xadd_check_overflow");
13046 extern void __add_wrong_size(void)
13047 __compiletime_error("Bad argument size for add");
13048+extern void __add_check_overflow_wrong_size(void)
13049+ __compiletime_error("Bad argument size for add_check_overflow");
13050
13051 /*
13052 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13053@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13054 __ret; \
13055 })
13056
13057+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13058+ ({ \
13059+ __typeof__ (*(ptr)) __ret = (arg); \
13060+ switch (sizeof(*(ptr))) { \
13061+ case __X86_CASE_L: \
13062+ asm volatile (lock #op "l %0, %1\n" \
13063+ "jno 0f\n" \
13064+ "mov %0,%1\n" \
13065+ "int $4\n0:\n" \
13066+ _ASM_EXTABLE(0b, 0b) \
13067+ : "+r" (__ret), "+m" (*(ptr)) \
13068+ : : "memory", "cc"); \
13069+ break; \
13070+ case __X86_CASE_Q: \
13071+ asm volatile (lock #op "q %q0, %1\n" \
13072+ "jno 0f\n" \
13073+ "mov %0,%1\n" \
13074+ "int $4\n0:\n" \
13075+ _ASM_EXTABLE(0b, 0b) \
13076+ : "+r" (__ret), "+m" (*(ptr)) \
13077+ : : "memory", "cc"); \
13078+ break; \
13079+ default: \
13080+ __ ## op ## _check_overflow_wrong_size(); \
13081+ } \
13082+ __ret; \
13083+ })
13084+
13085 /*
13086 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13087 * Since this is generally used to protect other memory information, we
13088@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13089 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13090 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13091
13092+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13093+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13094+
13095 #define __add(ptr, inc, lock) \
13096 ({ \
13097 __typeof__ (*(ptr)) __ret = (inc); \
13098diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13099index 59c6c40..5e0b22c 100644
13100--- a/arch/x86/include/asm/compat.h
13101+++ b/arch/x86/include/asm/compat.h
13102@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13103 typedef u32 compat_uint_t;
13104 typedef u32 compat_ulong_t;
13105 typedef u64 __attribute__((aligned(4))) compat_u64;
13106-typedef u32 compat_uptr_t;
13107+typedef u32 __user compat_uptr_t;
13108
13109 struct compat_timespec {
13110 compat_time_t tv_sec;
13111diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13112index e99ac27..e89e28c 100644
13113--- a/arch/x86/include/asm/cpufeature.h
13114+++ b/arch/x86/include/asm/cpufeature.h
13115@@ -211,7 +211,7 @@
13116 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13117 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13118 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13119-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13120+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13121 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13122 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13123 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13124@@ -394,7 +394,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13125 ".section .discard,\"aw\",@progbits\n"
13126 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13127 ".previous\n"
13128- ".section .altinstr_replacement,\"ax\"\n"
13129+ ".section .altinstr_replacement,\"a\"\n"
13130 "3: movb $1,%0\n"
13131 "4:\n"
13132 ".previous\n"
13133diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13134index 8bf1c06..b6ae785 100644
13135--- a/arch/x86/include/asm/desc.h
13136+++ b/arch/x86/include/asm/desc.h
13137@@ -4,6 +4,7 @@
13138 #include <asm/desc_defs.h>
13139 #include <asm/ldt.h>
13140 #include <asm/mmu.h>
13141+#include <asm/pgtable.h>
13142
13143 #include <linux/smp.h>
13144 #include <linux/percpu.h>
13145@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13146
13147 desc->type = (info->read_exec_only ^ 1) << 1;
13148 desc->type |= info->contents << 2;
13149+ desc->type |= info->seg_not_present ^ 1;
13150
13151 desc->s = 1;
13152 desc->dpl = 0x3;
13153@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13154 }
13155
13156 extern struct desc_ptr idt_descr;
13157-extern gate_desc idt_table[];
13158 extern struct desc_ptr nmi_idt_descr;
13159-extern gate_desc nmi_idt_table[];
13160-
13161-struct gdt_page {
13162- struct desc_struct gdt[GDT_ENTRIES];
13163-} __attribute__((aligned(PAGE_SIZE)));
13164-
13165-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13166+extern gate_desc idt_table[256];
13167+extern gate_desc nmi_idt_table[256];
13168
13169+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13170 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13171 {
13172- return per_cpu(gdt_page, cpu).gdt;
13173+ return cpu_gdt_table[cpu];
13174 }
13175
13176 #ifdef CONFIG_X86_64
13177@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13178 unsigned long base, unsigned dpl, unsigned flags,
13179 unsigned short seg)
13180 {
13181- gate->a = (seg << 16) | (base & 0xffff);
13182- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13183+ gate->gate.offset_low = base;
13184+ gate->gate.seg = seg;
13185+ gate->gate.reserved = 0;
13186+ gate->gate.type = type;
13187+ gate->gate.s = 0;
13188+ gate->gate.dpl = dpl;
13189+ gate->gate.p = 1;
13190+ gate->gate.offset_high = base >> 16;
13191 }
13192
13193 #endif
13194@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13195
13196 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13197 {
13198+ pax_open_kernel();
13199 memcpy(&idt[entry], gate, sizeof(*gate));
13200+ pax_close_kernel();
13201 }
13202
13203 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13204 {
13205+ pax_open_kernel();
13206 memcpy(&ldt[entry], desc, 8);
13207+ pax_close_kernel();
13208 }
13209
13210 static inline void
13211@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13212 default: size = sizeof(*gdt); break;
13213 }
13214
13215+ pax_open_kernel();
13216 memcpy(&gdt[entry], desc, size);
13217+ pax_close_kernel();
13218 }
13219
13220 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13221@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13222
13223 static inline void native_load_tr_desc(void)
13224 {
13225+ pax_open_kernel();
13226 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13227+ pax_close_kernel();
13228 }
13229
13230 static inline void native_load_gdt(const struct desc_ptr *dtr)
13231@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13232 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13233 unsigned int i;
13234
13235+ pax_open_kernel();
13236 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13237 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13238+ pax_close_kernel();
13239 }
13240
13241 #define _LDT_empty(info) \
13242@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13243 preempt_enable();
13244 }
13245
13246-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13247+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13248 {
13249 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13250 }
13251@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13252 }
13253
13254 #ifdef CONFIG_X86_64
13255-static inline void set_nmi_gate(int gate, void *addr)
13256+static inline void set_nmi_gate(int gate, const void *addr)
13257 {
13258 gate_desc s;
13259
13260@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13261 }
13262 #endif
13263
13264-static inline void _set_gate(int gate, unsigned type, void *addr,
13265+static inline void _set_gate(int gate, unsigned type, const void *addr,
13266 unsigned dpl, unsigned ist, unsigned seg)
13267 {
13268 gate_desc s;
13269@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13270 * Pentium F0 0F bugfix can have resulted in the mapped
13271 * IDT being write-protected.
13272 */
13273-static inline void set_intr_gate(unsigned int n, void *addr)
13274+static inline void set_intr_gate(unsigned int n, const void *addr)
13275 {
13276 BUG_ON((unsigned)n > 0xFF);
13277 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13278@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13279 /*
13280 * This routine sets up an interrupt gate at directory privilege level 3.
13281 */
13282-static inline void set_system_intr_gate(unsigned int n, void *addr)
13283+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13284 {
13285 BUG_ON((unsigned)n > 0xFF);
13286 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13287 }
13288
13289-static inline void set_system_trap_gate(unsigned int n, void *addr)
13290+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13291 {
13292 BUG_ON((unsigned)n > 0xFF);
13293 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13294 }
13295
13296-static inline void set_trap_gate(unsigned int n, void *addr)
13297+static inline void set_trap_gate(unsigned int n, const void *addr)
13298 {
13299 BUG_ON((unsigned)n > 0xFF);
13300 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13301@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13302 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13303 {
13304 BUG_ON((unsigned)n > 0xFF);
13305- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13306+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13307 }
13308
13309-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13310+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13311 {
13312 BUG_ON((unsigned)n > 0xFF);
13313 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13314 }
13315
13316-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13317+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13318 {
13319 BUG_ON((unsigned)n > 0xFF);
13320 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13321 }
13322
13323+#ifdef CONFIG_X86_32
13324+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13325+{
13326+ struct desc_struct d;
13327+
13328+ if (likely(limit))
13329+ limit = (limit - 1UL) >> PAGE_SHIFT;
13330+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13331+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13332+}
13333+#endif
13334+
13335 #endif /* _ASM_X86_DESC_H */
13336diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13337index 278441f..b95a174 100644
13338--- a/arch/x86/include/asm/desc_defs.h
13339+++ b/arch/x86/include/asm/desc_defs.h
13340@@ -31,6 +31,12 @@ struct desc_struct {
13341 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13342 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13343 };
13344+ struct {
13345+ u16 offset_low;
13346+ u16 seg;
13347+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13348+ unsigned offset_high: 16;
13349+ } gate;
13350 };
13351 } __attribute__((packed));
13352
13353diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13354index ced283a..ffe04cc 100644
13355--- a/arch/x86/include/asm/div64.h
13356+++ b/arch/x86/include/asm/div64.h
13357@@ -39,7 +39,7 @@
13358 __mod; \
13359 })
13360
13361-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13362+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13363 {
13364 union {
13365 u64 v64;
13366diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13367index 9c999c1..3860cb8 100644
13368--- a/arch/x86/include/asm/elf.h
13369+++ b/arch/x86/include/asm/elf.h
13370@@ -243,7 +243,25 @@ extern int force_personality32;
13371 the loader. We need to make sure that it is out of the way of the program
13372 that it will "exec", and that there is sufficient room for the brk. */
13373
13374+#ifdef CONFIG_PAX_SEGMEXEC
13375+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13376+#else
13377 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13378+#endif
13379+
13380+#ifdef CONFIG_PAX_ASLR
13381+#ifdef CONFIG_X86_32
13382+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13383+
13384+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13385+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13386+#else
13387+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13388+
13389+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13390+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13391+#endif
13392+#endif
13393
13394 /* This yields a mask that user programs can use to figure out what
13395 instruction set this CPU supports. This could be done in user space,
13396@@ -296,16 +314,12 @@ do { \
13397
13398 #define ARCH_DLINFO \
13399 do { \
13400- if (vdso_enabled) \
13401- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13402- (unsigned long)current->mm->context.vdso); \
13403+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13404 } while (0)
13405
13406 #define ARCH_DLINFO_X32 \
13407 do { \
13408- if (vdso_enabled) \
13409- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13410- (unsigned long)current->mm->context.vdso); \
13411+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13412 } while (0)
13413
13414 #define AT_SYSINFO 32
13415@@ -320,7 +334,7 @@ else \
13416
13417 #endif /* !CONFIG_X86_32 */
13418
13419-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13420+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13421
13422 #define VDSO_ENTRY \
13423 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13424@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13425 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13426 #define compat_arch_setup_additional_pages syscall32_setup_pages
13427
13428-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13429-#define arch_randomize_brk arch_randomize_brk
13430-
13431 /*
13432 * True on X86_32 or when emulating IA32 on X86_64
13433 */
13434diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13435index 75ce3f4..882e801 100644
13436--- a/arch/x86/include/asm/emergency-restart.h
13437+++ b/arch/x86/include/asm/emergency-restart.h
13438@@ -13,6 +13,6 @@ enum reboot_type {
13439
13440 extern enum reboot_type reboot_type;
13441
13442-extern void machine_emergency_restart(void);
13443+extern void machine_emergency_restart(void) __noreturn;
13444
13445 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13446diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13447index e25cc33..425d099 100644
13448--- a/arch/x86/include/asm/fpu-internal.h
13449+++ b/arch/x86/include/asm/fpu-internal.h
13450@@ -127,7 +127,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13451 ({ \
13452 int err; \
13453 asm volatile(ASM_STAC "\n" \
13454- "1:" #insn "\n\t" \
13455+ "1:" \
13456+ __copyuser_seg \
13457+ #insn "\n\t" \
13458 "2: " ASM_CLAC "\n" \
13459 ".section .fixup,\"ax\"\n" \
13460 "3: movl $-1,%[err]\n" \
13461@@ -300,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13462 "emms\n\t" /* clear stack tags */
13463 "fildl %P[addr]", /* set F?P to defined value */
13464 X86_FEATURE_FXSAVE_LEAK,
13465- [addr] "m" (tsk->thread.fpu.has_fpu));
13466+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13467
13468 return fpu_restore_checking(&tsk->thread.fpu);
13469 }
13470diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13471index be27ba1..8f13ff9 100644
13472--- a/arch/x86/include/asm/futex.h
13473+++ b/arch/x86/include/asm/futex.h
13474@@ -12,6 +12,7 @@
13475 #include <asm/smap.h>
13476
13477 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13478+ typecheck(u32 __user *, uaddr); \
13479 asm volatile("\t" ASM_STAC "\n" \
13480 "1:\t" insn "\n" \
13481 "2:\t" ASM_CLAC "\n" \
13482@@ -20,15 +21,16 @@
13483 "\tjmp\t2b\n" \
13484 "\t.previous\n" \
13485 _ASM_EXTABLE(1b, 3b) \
13486- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13487+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13488 : "i" (-EFAULT), "0" (oparg), "1" (0))
13489
13490 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13491+ typecheck(u32 __user *, uaddr); \
13492 asm volatile("\t" ASM_STAC "\n" \
13493 "1:\tmovl %2, %0\n" \
13494 "\tmovl\t%0, %3\n" \
13495 "\t" insn "\n" \
13496- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13497+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13498 "\tjnz\t1b\n" \
13499 "3:\t" ASM_CLAC "\n" \
13500 "\t.section .fixup,\"ax\"\n" \
13501@@ -38,7 +40,7 @@
13502 _ASM_EXTABLE(1b, 4b) \
13503 _ASM_EXTABLE(2b, 4b) \
13504 : "=&a" (oldval), "=&r" (ret), \
13505- "+m" (*uaddr), "=&r" (tem) \
13506+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13507 : "r" (oparg), "i" (-EFAULT), "1" (0))
13508
13509 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13510@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13511
13512 switch (op) {
13513 case FUTEX_OP_SET:
13514- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13515+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13516 break;
13517 case FUTEX_OP_ADD:
13518- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13519+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13520 uaddr, oparg);
13521 break;
13522 case FUTEX_OP_OR:
13523@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13524 return -EFAULT;
13525
13526 asm volatile("\t" ASM_STAC "\n"
13527- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13528+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13529 "2:\t" ASM_CLAC "\n"
13530 "\t.section .fixup, \"ax\"\n"
13531 "3:\tmov %3, %0\n"
13532 "\tjmp 2b\n"
13533 "\t.previous\n"
13534 _ASM_EXTABLE(1b, 3b)
13535- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13536+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13537 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13538 : "memory"
13539 );
13540diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13541index 1da97ef..9c2ebff 100644
13542--- a/arch/x86/include/asm/hw_irq.h
13543+++ b/arch/x86/include/asm/hw_irq.h
13544@@ -148,8 +148,8 @@ extern void setup_ioapic_dest(void);
13545 extern void enable_IO_APIC(void);
13546
13547 /* Statistics */
13548-extern atomic_t irq_err_count;
13549-extern atomic_t irq_mis_count;
13550+extern atomic_unchecked_t irq_err_count;
13551+extern atomic_unchecked_t irq_mis_count;
13552
13553 /* EISA */
13554 extern void eisa_set_level_irq(unsigned int irq);
13555diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13556index a203659..9889f1c 100644
13557--- a/arch/x86/include/asm/i8259.h
13558+++ b/arch/x86/include/asm/i8259.h
13559@@ -62,7 +62,7 @@ struct legacy_pic {
13560 void (*init)(int auto_eoi);
13561 int (*irq_pending)(unsigned int irq);
13562 void (*make_irq)(unsigned int irq);
13563-};
13564+} __do_const;
13565
13566 extern struct legacy_pic *legacy_pic;
13567 extern struct legacy_pic null_legacy_pic;
13568diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13569index d8e8eef..1765f78 100644
13570--- a/arch/x86/include/asm/io.h
13571+++ b/arch/x86/include/asm/io.h
13572@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13573 "m" (*(volatile type __force *)addr) barrier); }
13574
13575 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13576-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13577-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13578+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13579+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13580
13581 build_mmio_read(__readb, "b", unsigned char, "=q", )
13582-build_mmio_read(__readw, "w", unsigned short, "=r", )
13583-build_mmio_read(__readl, "l", unsigned int, "=r", )
13584+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13585+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13586
13587 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13588 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13589@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13590 return ioremap_nocache(offset, size);
13591 }
13592
13593-extern void iounmap(volatile void __iomem *addr);
13594+extern void iounmap(const volatile void __iomem *addr);
13595
13596 extern void set_iounmap_nonlazy(void);
13597
13598@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13599
13600 #include <linux/vmalloc.h>
13601
13602+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13603+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13604+{
13605+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13606+}
13607+
13608+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13609+{
13610+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13611+}
13612+
13613 /*
13614 * Convert a virtual cached pointer to an uncached pointer
13615 */
13616diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13617index bba3cf8..06bc8da 100644
13618--- a/arch/x86/include/asm/irqflags.h
13619+++ b/arch/x86/include/asm/irqflags.h
13620@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13621 sti; \
13622 sysexit
13623
13624+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13625+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13626+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13627+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13628+
13629 #else
13630 #define INTERRUPT_RETURN iret
13631 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13632diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13633index 5a6d287..f815789 100644
13634--- a/arch/x86/include/asm/kprobes.h
13635+++ b/arch/x86/include/asm/kprobes.h
13636@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13637 #define RELATIVEJUMP_SIZE 5
13638 #define RELATIVECALL_OPCODE 0xe8
13639 #define RELATIVE_ADDR_SIZE 4
13640-#define MAX_STACK_SIZE 64
13641-#define MIN_STACK_SIZE(ADDR) \
13642- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13643- THREAD_SIZE - (unsigned long)(ADDR))) \
13644- ? (MAX_STACK_SIZE) \
13645- : (((unsigned long)current_thread_info()) + \
13646- THREAD_SIZE - (unsigned long)(ADDR)))
13647+#define MAX_STACK_SIZE 64UL
13648+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13649
13650 #define flush_insn_slot(p) do { } while (0)
13651
13652diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13653index 2d89e39..baee879 100644
13654--- a/arch/x86/include/asm/local.h
13655+++ b/arch/x86/include/asm/local.h
13656@@ -10,33 +10,97 @@ typedef struct {
13657 atomic_long_t a;
13658 } local_t;
13659
13660+typedef struct {
13661+ atomic_long_unchecked_t a;
13662+} local_unchecked_t;
13663+
13664 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13665
13666 #define local_read(l) atomic_long_read(&(l)->a)
13667+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13668 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13669+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13670
13671 static inline void local_inc(local_t *l)
13672 {
13673- asm volatile(_ASM_INC "%0"
13674+ asm volatile(_ASM_INC "%0\n"
13675+
13676+#ifdef CONFIG_PAX_REFCOUNT
13677+ "jno 0f\n"
13678+ _ASM_DEC "%0\n"
13679+ "int $4\n0:\n"
13680+ _ASM_EXTABLE(0b, 0b)
13681+#endif
13682+
13683+ : "+m" (l->a.counter));
13684+}
13685+
13686+static inline void local_inc_unchecked(local_unchecked_t *l)
13687+{
13688+ asm volatile(_ASM_INC "%0\n"
13689 : "+m" (l->a.counter));
13690 }
13691
13692 static inline void local_dec(local_t *l)
13693 {
13694- asm volatile(_ASM_DEC "%0"
13695+ asm volatile(_ASM_DEC "%0\n"
13696+
13697+#ifdef CONFIG_PAX_REFCOUNT
13698+ "jno 0f\n"
13699+ _ASM_INC "%0\n"
13700+ "int $4\n0:\n"
13701+ _ASM_EXTABLE(0b, 0b)
13702+#endif
13703+
13704+ : "+m" (l->a.counter));
13705+}
13706+
13707+static inline void local_dec_unchecked(local_unchecked_t *l)
13708+{
13709+ asm volatile(_ASM_DEC "%0\n"
13710 : "+m" (l->a.counter));
13711 }
13712
13713 static inline void local_add(long i, local_t *l)
13714 {
13715- asm volatile(_ASM_ADD "%1,%0"
13716+ asm volatile(_ASM_ADD "%1,%0\n"
13717+
13718+#ifdef CONFIG_PAX_REFCOUNT
13719+ "jno 0f\n"
13720+ _ASM_SUB "%1,%0\n"
13721+ "int $4\n0:\n"
13722+ _ASM_EXTABLE(0b, 0b)
13723+#endif
13724+
13725+ : "+m" (l->a.counter)
13726+ : "ir" (i));
13727+}
13728+
13729+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13730+{
13731+ asm volatile(_ASM_ADD "%1,%0\n"
13732 : "+m" (l->a.counter)
13733 : "ir" (i));
13734 }
13735
13736 static inline void local_sub(long i, local_t *l)
13737 {
13738- asm volatile(_ASM_SUB "%1,%0"
13739+ asm volatile(_ASM_SUB "%1,%0\n"
13740+
13741+#ifdef CONFIG_PAX_REFCOUNT
13742+ "jno 0f\n"
13743+ _ASM_ADD "%1,%0\n"
13744+ "int $4\n0:\n"
13745+ _ASM_EXTABLE(0b, 0b)
13746+#endif
13747+
13748+ : "+m" (l->a.counter)
13749+ : "ir" (i));
13750+}
13751+
13752+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13753+{
13754+ asm volatile(_ASM_SUB "%1,%0\n"
13755 : "+m" (l->a.counter)
13756 : "ir" (i));
13757 }
13758@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13759 {
13760 unsigned char c;
13761
13762- asm volatile(_ASM_SUB "%2,%0; sete %1"
13763+ asm volatile(_ASM_SUB "%2,%0\n"
13764+
13765+#ifdef CONFIG_PAX_REFCOUNT
13766+ "jno 0f\n"
13767+ _ASM_ADD "%2,%0\n"
13768+ "int $4\n0:\n"
13769+ _ASM_EXTABLE(0b, 0b)
13770+#endif
13771+
13772+ "sete %1\n"
13773 : "+m" (l->a.counter), "=qm" (c)
13774 : "ir" (i) : "memory");
13775 return c;
13776@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13777 {
13778 unsigned char c;
13779
13780- asm volatile(_ASM_DEC "%0; sete %1"
13781+ asm volatile(_ASM_DEC "%0\n"
13782+
13783+#ifdef CONFIG_PAX_REFCOUNT
13784+ "jno 0f\n"
13785+ _ASM_INC "%0\n"
13786+ "int $4\n0:\n"
13787+ _ASM_EXTABLE(0b, 0b)
13788+#endif
13789+
13790+ "sete %1\n"
13791 : "+m" (l->a.counter), "=qm" (c)
13792 : : "memory");
13793 return c != 0;
13794@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13795 {
13796 unsigned char c;
13797
13798- asm volatile(_ASM_INC "%0; sete %1"
13799+ asm volatile(_ASM_INC "%0\n"
13800+
13801+#ifdef CONFIG_PAX_REFCOUNT
13802+ "jno 0f\n"
13803+ _ASM_DEC "%0\n"
13804+ "int $4\n0:\n"
13805+ _ASM_EXTABLE(0b, 0b)
13806+#endif
13807+
13808+ "sete %1\n"
13809 : "+m" (l->a.counter), "=qm" (c)
13810 : : "memory");
13811 return c != 0;
13812@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13813 {
13814 unsigned char c;
13815
13816- asm volatile(_ASM_ADD "%2,%0; sets %1"
13817+ asm volatile(_ASM_ADD "%2,%0\n"
13818+
13819+#ifdef CONFIG_PAX_REFCOUNT
13820+ "jno 0f\n"
13821+ _ASM_SUB "%2,%0\n"
13822+ "int $4\n0:\n"
13823+ _ASM_EXTABLE(0b, 0b)
13824+#endif
13825+
13826+ "sets %1\n"
13827 : "+m" (l->a.counter), "=qm" (c)
13828 : "ir" (i) : "memory");
13829 return c;
13830@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13831 static inline long local_add_return(long i, local_t *l)
13832 {
13833 long __i = i;
13834+ asm volatile(_ASM_XADD "%0, %1\n"
13835+
13836+#ifdef CONFIG_PAX_REFCOUNT
13837+ "jno 0f\n"
13838+ _ASM_MOV "%0,%1\n"
13839+ "int $4\n0:\n"
13840+ _ASM_EXTABLE(0b, 0b)
13841+#endif
13842+
13843+ : "+r" (i), "+m" (l->a.counter)
13844+ : : "memory");
13845+ return i + __i;
13846+}
13847+
13848+/**
13849+ * local_add_return_unchecked - add and return
13850+ * @i: integer value to add
13851+ * @l: pointer to type local_unchecked_t
13852+ *
13853+ * Atomically adds @i to @l and returns @i + @l
13854+ */
13855+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13856+{
13857+ long __i = i;
13858 asm volatile(_ASM_XADD "%0, %1;"
13859 : "+r" (i), "+m" (l->a.counter)
13860 : : "memory");
13861@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13862
13863 #define local_cmpxchg(l, o, n) \
13864 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13865+#define local_cmpxchg_unchecked(l, o, n) \
13866+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13867 /* Always has a lock prefix */
13868 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13869
13870diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13871new file mode 100644
13872index 0000000..2bfd3ba
13873--- /dev/null
13874+++ b/arch/x86/include/asm/mman.h
13875@@ -0,0 +1,15 @@
13876+#ifndef _X86_MMAN_H
13877+#define _X86_MMAN_H
13878+
13879+#include <uapi/asm/mman.h>
13880+
13881+#ifdef __KERNEL__
13882+#ifndef __ASSEMBLY__
13883+#ifdef CONFIG_X86_32
13884+#define arch_mmap_check i386_mmap_check
13885+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13886+#endif
13887+#endif
13888+#endif
13889+
13890+#endif /* X86_MMAN_H */
13891diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13892index 5f55e69..e20bfb1 100644
13893--- a/arch/x86/include/asm/mmu.h
13894+++ b/arch/x86/include/asm/mmu.h
13895@@ -9,7 +9,7 @@
13896 * we put the segment information here.
13897 */
13898 typedef struct {
13899- void *ldt;
13900+ struct desc_struct *ldt;
13901 int size;
13902
13903 #ifdef CONFIG_X86_64
13904@@ -18,7 +18,19 @@ typedef struct {
13905 #endif
13906
13907 struct mutex lock;
13908- void *vdso;
13909+ unsigned long vdso;
13910+
13911+#ifdef CONFIG_X86_32
13912+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13913+ unsigned long user_cs_base;
13914+ unsigned long user_cs_limit;
13915+
13916+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13917+ cpumask_t cpu_user_cs_mask;
13918+#endif
13919+
13920+#endif
13921+#endif
13922 } mm_context_t;
13923
13924 #ifdef CONFIG_SMP
13925diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13926index cdbf367..adb37ac 100644
13927--- a/arch/x86/include/asm/mmu_context.h
13928+++ b/arch/x86/include/asm/mmu_context.h
13929@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13930
13931 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13932 {
13933+
13934+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13935+ unsigned int i;
13936+ pgd_t *pgd;
13937+
13938+ pax_open_kernel();
13939+ pgd = get_cpu_pgd(smp_processor_id());
13940+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13941+ set_pgd_batched(pgd+i, native_make_pgd(0));
13942+ pax_close_kernel();
13943+#endif
13944+
13945 #ifdef CONFIG_SMP
13946 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13947 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13948@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13949 struct task_struct *tsk)
13950 {
13951 unsigned cpu = smp_processor_id();
13952+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13953+ int tlbstate = TLBSTATE_OK;
13954+#endif
13955
13956 if (likely(prev != next)) {
13957 #ifdef CONFIG_SMP
13958+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13959+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13960+#endif
13961 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13962 this_cpu_write(cpu_tlbstate.active_mm, next);
13963 #endif
13964 cpumask_set_cpu(cpu, mm_cpumask(next));
13965
13966 /* Re-load page tables */
13967+#ifdef CONFIG_PAX_PER_CPU_PGD
13968+ pax_open_kernel();
13969+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13970+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13971+ pax_close_kernel();
13972+ load_cr3(get_cpu_pgd(cpu));
13973+#else
13974 load_cr3(next->pgd);
13975+#endif
13976
13977 /* stop flush ipis for the previous mm */
13978 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13979@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13980 */
13981 if (unlikely(prev->context.ldt != next->context.ldt))
13982 load_LDT_nolock(&next->context);
13983- }
13984+
13985+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13986+ if (!(__supported_pte_mask & _PAGE_NX)) {
13987+ smp_mb__before_clear_bit();
13988+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13989+ smp_mb__after_clear_bit();
13990+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13991+ }
13992+#endif
13993+
13994+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13995+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13996+ prev->context.user_cs_limit != next->context.user_cs_limit))
13997+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13998 #ifdef CONFIG_SMP
13999+ else if (unlikely(tlbstate != TLBSTATE_OK))
14000+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14001+#endif
14002+#endif
14003+
14004+ }
14005 else {
14006+
14007+#ifdef CONFIG_PAX_PER_CPU_PGD
14008+ pax_open_kernel();
14009+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
14010+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
14011+ pax_close_kernel();
14012+ load_cr3(get_cpu_pgd(cpu));
14013+#endif
14014+
14015+#ifdef CONFIG_SMP
14016 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14017 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
14018
14019@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14020 * tlb flush IPI delivery. We must reload CR3
14021 * to make sure to use no freed page tables.
14022 */
14023+
14024+#ifndef CONFIG_PAX_PER_CPU_PGD
14025 load_cr3(next->pgd);
14026+#endif
14027+
14028 load_LDT_nolock(&next->context);
14029+
14030+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14031+ if (!(__supported_pte_mask & _PAGE_NX))
14032+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14033+#endif
14034+
14035+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14036+#ifdef CONFIG_PAX_PAGEEXEC
14037+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14038+#endif
14039+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14040+#endif
14041+
14042 }
14043+#endif
14044 }
14045-#endif
14046 }
14047
14048 #define activate_mm(prev, next) \
14049diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14050index e3b7819..b257c64 100644
14051--- a/arch/x86/include/asm/module.h
14052+++ b/arch/x86/include/asm/module.h
14053@@ -5,6 +5,7 @@
14054
14055 #ifdef CONFIG_X86_64
14056 /* X86_64 does not define MODULE_PROC_FAMILY */
14057+#define MODULE_PROC_FAMILY ""
14058 #elif defined CONFIG_M486
14059 #define MODULE_PROC_FAMILY "486 "
14060 #elif defined CONFIG_M586
14061@@ -57,8 +58,20 @@
14062 #error unknown processor family
14063 #endif
14064
14065-#ifdef CONFIG_X86_32
14066-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14067+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14068+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14069+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14070+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14071+#else
14072+#define MODULE_PAX_KERNEXEC ""
14073 #endif
14074
14075+#ifdef CONFIG_PAX_MEMORY_UDEREF
14076+#define MODULE_PAX_UDEREF "UDEREF "
14077+#else
14078+#define MODULE_PAX_UDEREF ""
14079+#endif
14080+
14081+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14082+
14083 #endif /* _ASM_X86_MODULE_H */
14084diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14085index 86f9301..b365cda 100644
14086--- a/arch/x86/include/asm/nmi.h
14087+++ b/arch/x86/include/asm/nmi.h
14088@@ -40,11 +40,11 @@ struct nmiaction {
14089 nmi_handler_t handler;
14090 unsigned long flags;
14091 const char *name;
14092-};
14093+} __do_const;
14094
14095 #define register_nmi_handler(t, fn, fg, n, init...) \
14096 ({ \
14097- static struct nmiaction init fn##_na = { \
14098+ static const struct nmiaction init fn##_na = { \
14099 .handler = (fn), \
14100 .name = (n), \
14101 .flags = (fg), \
14102@@ -52,7 +52,7 @@ struct nmiaction {
14103 __register_nmi_handler((t), &fn##_na); \
14104 })
14105
14106-int __register_nmi_handler(unsigned int, struct nmiaction *);
14107+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14108
14109 void unregister_nmi_handler(unsigned int, const char *);
14110
14111diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
14112index c878924..21f4889 100644
14113--- a/arch/x86/include/asm/page.h
14114+++ b/arch/x86/include/asm/page.h
14115@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
14116 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
14117
14118 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
14119+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
14120
14121 #define __boot_va(x) __va(x)
14122 #define __boot_pa(x) __pa(x)
14123diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
14124index 0f1ddee..e2fc3d1 100644
14125--- a/arch/x86/include/asm/page_64.h
14126+++ b/arch/x86/include/asm/page_64.h
14127@@ -7,9 +7,9 @@
14128
14129 /* duplicated to the one in bootmem.h */
14130 extern unsigned long max_pfn;
14131-extern unsigned long phys_base;
14132+extern const unsigned long phys_base;
14133
14134-static inline unsigned long __phys_addr_nodebug(unsigned long x)
14135+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
14136 {
14137 unsigned long y = x - __START_KERNEL_map;
14138
14139diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14140index cfdc9ee..3f7b5d6 100644
14141--- a/arch/x86/include/asm/paravirt.h
14142+++ b/arch/x86/include/asm/paravirt.h
14143@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
14144 return (pmd_t) { ret };
14145 }
14146
14147-static inline pmdval_t pmd_val(pmd_t pmd)
14148+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14149 {
14150 pmdval_t ret;
14151
14152@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14153 val);
14154 }
14155
14156+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14157+{
14158+ pgdval_t val = native_pgd_val(pgd);
14159+
14160+ if (sizeof(pgdval_t) > sizeof(long))
14161+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14162+ val, (u64)val >> 32);
14163+ else
14164+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14165+ val);
14166+}
14167+
14168 static inline void pgd_clear(pgd_t *pgdp)
14169 {
14170 set_pgd(pgdp, __pgd(0));
14171@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14172 pv_mmu_ops.set_fixmap(idx, phys, flags);
14173 }
14174
14175+#ifdef CONFIG_PAX_KERNEXEC
14176+static inline unsigned long pax_open_kernel(void)
14177+{
14178+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14179+}
14180+
14181+static inline unsigned long pax_close_kernel(void)
14182+{
14183+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14184+}
14185+#else
14186+static inline unsigned long pax_open_kernel(void) { return 0; }
14187+static inline unsigned long pax_close_kernel(void) { return 0; }
14188+#endif
14189+
14190 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14191
14192 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14193@@ -926,7 +953,7 @@ extern void default_banner(void);
14194
14195 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14196 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14197-#define PARA_INDIRECT(addr) *%cs:addr
14198+#define PARA_INDIRECT(addr) *%ss:addr
14199 #endif
14200
14201 #define INTERRUPT_RETURN \
14202@@ -1001,6 +1028,21 @@ extern void default_banner(void);
14203 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14204 CLBR_NONE, \
14205 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14206+
14207+#define GET_CR0_INTO_RDI \
14208+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14209+ mov %rax,%rdi
14210+
14211+#define SET_RDI_INTO_CR0 \
14212+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14213+
14214+#define GET_CR3_INTO_RDI \
14215+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14216+ mov %rax,%rdi
14217+
14218+#define SET_RDI_INTO_CR3 \
14219+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14220+
14221 #endif /* CONFIG_X86_32 */
14222
14223 #endif /* __ASSEMBLY__ */
14224diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14225index 0db1fca..52310cc 100644
14226--- a/arch/x86/include/asm/paravirt_types.h
14227+++ b/arch/x86/include/asm/paravirt_types.h
14228@@ -84,7 +84,7 @@ struct pv_init_ops {
14229 */
14230 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14231 unsigned long addr, unsigned len);
14232-};
14233+} __no_const;
14234
14235
14236 struct pv_lazy_ops {
14237@@ -98,7 +98,7 @@ struct pv_time_ops {
14238 unsigned long long (*sched_clock)(void);
14239 unsigned long long (*steal_clock)(int cpu);
14240 unsigned long (*get_tsc_khz)(void);
14241-};
14242+} __no_const;
14243
14244 struct pv_cpu_ops {
14245 /* hooks for various privileged instructions */
14246@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14247
14248 void (*start_context_switch)(struct task_struct *prev);
14249 void (*end_context_switch)(struct task_struct *next);
14250-};
14251+} __no_const;
14252
14253 struct pv_irq_ops {
14254 /*
14255@@ -223,7 +223,7 @@ struct pv_apic_ops {
14256 unsigned long start_eip,
14257 unsigned long start_esp);
14258 #endif
14259-};
14260+} __no_const;
14261
14262 struct pv_mmu_ops {
14263 unsigned long (*read_cr2)(void);
14264@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14265 struct paravirt_callee_save make_pud;
14266
14267 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14268+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14269 #endif /* PAGETABLE_LEVELS == 4 */
14270 #endif /* PAGETABLE_LEVELS >= 3 */
14271
14272@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14273 an mfn. We can tell which is which from the index. */
14274 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14275 phys_addr_t phys, pgprot_t flags);
14276+
14277+#ifdef CONFIG_PAX_KERNEXEC
14278+ unsigned long (*pax_open_kernel)(void);
14279+ unsigned long (*pax_close_kernel)(void);
14280+#endif
14281+
14282 };
14283
14284 struct arch_spinlock;
14285@@ -334,7 +341,7 @@ struct pv_lock_ops {
14286 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14287 int (*spin_trylock)(struct arch_spinlock *lock);
14288 void (*spin_unlock)(struct arch_spinlock *lock);
14289-};
14290+} __no_const;
14291
14292 /* This contains all the paravirt structures: we get a convenient
14293 * number for each function using the offset which we use to indicate
14294diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14295index b4389a4..7024269 100644
14296--- a/arch/x86/include/asm/pgalloc.h
14297+++ b/arch/x86/include/asm/pgalloc.h
14298@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14299 pmd_t *pmd, pte_t *pte)
14300 {
14301 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14302+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14303+}
14304+
14305+static inline void pmd_populate_user(struct mm_struct *mm,
14306+ pmd_t *pmd, pte_t *pte)
14307+{
14308+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14309 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14310 }
14311
14312@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14313
14314 #ifdef CONFIG_X86_PAE
14315 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14316+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14317+{
14318+ pud_populate(mm, pudp, pmd);
14319+}
14320 #else /* !CONFIG_X86_PAE */
14321 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14322 {
14323 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14324 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14325 }
14326+
14327+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14328+{
14329+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14330+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14331+}
14332 #endif /* CONFIG_X86_PAE */
14333
14334 #if PAGETABLE_LEVELS > 3
14335@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14336 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14337 }
14338
14339+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14340+{
14341+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14342+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14343+}
14344+
14345 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14346 {
14347 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14348diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14349index f2b489c..4f7e2e5 100644
14350--- a/arch/x86/include/asm/pgtable-2level.h
14351+++ b/arch/x86/include/asm/pgtable-2level.h
14352@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14353
14354 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14355 {
14356+ pax_open_kernel();
14357 *pmdp = pmd;
14358+ pax_close_kernel();
14359 }
14360
14361 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14362diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14363index 4cc9f2b..5fd9226 100644
14364--- a/arch/x86/include/asm/pgtable-3level.h
14365+++ b/arch/x86/include/asm/pgtable-3level.h
14366@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14367
14368 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14369 {
14370+ pax_open_kernel();
14371 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14372+ pax_close_kernel();
14373 }
14374
14375 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14376 {
14377+ pax_open_kernel();
14378 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14379+ pax_close_kernel();
14380 }
14381
14382 /*
14383diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14384index 1e67223..dd6e7ea 100644
14385--- a/arch/x86/include/asm/pgtable.h
14386+++ b/arch/x86/include/asm/pgtable.h
14387@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14388
14389 #ifndef __PAGETABLE_PUD_FOLDED
14390 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14391+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14392 #define pgd_clear(pgd) native_pgd_clear(pgd)
14393 #endif
14394
14395@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14396
14397 #define arch_end_context_switch(prev) do {} while(0)
14398
14399+#define pax_open_kernel() native_pax_open_kernel()
14400+#define pax_close_kernel() native_pax_close_kernel()
14401 #endif /* CONFIG_PARAVIRT */
14402
14403+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14404+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14405+
14406+#ifdef CONFIG_PAX_KERNEXEC
14407+static inline unsigned long native_pax_open_kernel(void)
14408+{
14409+ unsigned long cr0;
14410+
14411+ preempt_disable();
14412+ barrier();
14413+ cr0 = read_cr0() ^ X86_CR0_WP;
14414+ BUG_ON(cr0 & X86_CR0_WP);
14415+ write_cr0(cr0);
14416+ return cr0 ^ X86_CR0_WP;
14417+}
14418+
14419+static inline unsigned long native_pax_close_kernel(void)
14420+{
14421+ unsigned long cr0;
14422+
14423+ cr0 = read_cr0() ^ X86_CR0_WP;
14424+ BUG_ON(!(cr0 & X86_CR0_WP));
14425+ write_cr0(cr0);
14426+ barrier();
14427+ preempt_enable_no_resched();
14428+ return cr0 ^ X86_CR0_WP;
14429+}
14430+#else
14431+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14432+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14433+#endif
14434+
14435 /*
14436 * The following only work if pte_present() is true.
14437 * Undefined behaviour if not..
14438 */
14439+static inline int pte_user(pte_t pte)
14440+{
14441+ return pte_val(pte) & _PAGE_USER;
14442+}
14443+
14444 static inline int pte_dirty(pte_t pte)
14445 {
14446 return pte_flags(pte) & _PAGE_DIRTY;
14447@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
14448 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
14449 }
14450
14451+static inline unsigned long pgd_pfn(pgd_t pgd)
14452+{
14453+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
14454+}
14455+
14456 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
14457
14458 static inline int pmd_large(pmd_t pte)
14459@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14460 return pte_clear_flags(pte, _PAGE_RW);
14461 }
14462
14463+static inline pte_t pte_mkread(pte_t pte)
14464+{
14465+ return __pte(pte_val(pte) | _PAGE_USER);
14466+}
14467+
14468 static inline pte_t pte_mkexec(pte_t pte)
14469 {
14470- return pte_clear_flags(pte, _PAGE_NX);
14471+#ifdef CONFIG_X86_PAE
14472+ if (__supported_pte_mask & _PAGE_NX)
14473+ return pte_clear_flags(pte, _PAGE_NX);
14474+ else
14475+#endif
14476+ return pte_set_flags(pte, _PAGE_USER);
14477+}
14478+
14479+static inline pte_t pte_exprotect(pte_t pte)
14480+{
14481+#ifdef CONFIG_X86_PAE
14482+ if (__supported_pte_mask & _PAGE_NX)
14483+ return pte_set_flags(pte, _PAGE_NX);
14484+ else
14485+#endif
14486+ return pte_clear_flags(pte, _PAGE_USER);
14487 }
14488
14489 static inline pte_t pte_mkdirty(pte_t pte)
14490@@ -394,6 +459,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14491 #endif
14492
14493 #ifndef __ASSEMBLY__
14494+
14495+#ifdef CONFIG_PAX_PER_CPU_PGD
14496+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14497+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14498+{
14499+ return cpu_pgd[cpu];
14500+}
14501+#endif
14502+
14503 #include <linux/mm_types.h>
14504 #include <linux/log2.h>
14505
14506@@ -529,7 +603,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
14507 * Currently stuck as a macro due to indirect forward reference to
14508 * linux/mmzone.h's __section_mem_map_addr() definition:
14509 */
14510-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
14511+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
14512
14513 /* Find an entry in the second-level page table.. */
14514 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
14515@@ -569,7 +643,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
14516 * Currently stuck as a macro due to indirect forward reference to
14517 * linux/mmzone.h's __section_mem_map_addr() definition:
14518 */
14519-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
14520+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
14521
14522 /* to find an entry in a page-table-directory. */
14523 static inline unsigned long pud_index(unsigned long address)
14524@@ -584,7 +658,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14525
14526 static inline int pgd_bad(pgd_t pgd)
14527 {
14528- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14529+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14530 }
14531
14532 static inline int pgd_none(pgd_t pgd)
14533@@ -607,7 +681,12 @@ static inline int pgd_none(pgd_t pgd)
14534 * pgd_offset() returns a (pgd_t *)
14535 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14536 */
14537-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14538+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14539+
14540+#ifdef CONFIG_PAX_PER_CPU_PGD
14541+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14542+#endif
14543+
14544 /*
14545 * a shortcut which implies the use of the kernel's pgd, instead
14546 * of a process's
14547@@ -618,6 +697,22 @@ static inline int pgd_none(pgd_t pgd)
14548 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14549 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14550
14551+#ifdef CONFIG_X86_32
14552+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14553+#else
14554+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14555+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14556+
14557+#ifdef CONFIG_PAX_MEMORY_UDEREF
14558+#ifdef __ASSEMBLY__
14559+#define pax_user_shadow_base pax_user_shadow_base(%rip)
14560+#else
14561+extern unsigned long pax_user_shadow_base;
14562+#endif
14563+#endif
14564+
14565+#endif
14566+
14567 #ifndef __ASSEMBLY__
14568
14569 extern int direct_gbpages;
14570@@ -784,11 +879,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14571 * dst and src can be on the same page, but the range must not overlap,
14572 * and must not cross a page boundary.
14573 */
14574-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14575+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14576 {
14577- memcpy(dst, src, count * sizeof(pgd_t));
14578+ pax_open_kernel();
14579+ while (count--)
14580+ *dst++ = *src++;
14581+ pax_close_kernel();
14582 }
14583
14584+#ifdef CONFIG_PAX_PER_CPU_PGD
14585+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14586+#endif
14587+
14588+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14589+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14590+#else
14591+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14592+#endif
14593+
14594 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
14595 static inline int page_level_shift(enum pg_level level)
14596 {
14597diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14598index 9ee3221..b979c6b 100644
14599--- a/arch/x86/include/asm/pgtable_32.h
14600+++ b/arch/x86/include/asm/pgtable_32.h
14601@@ -25,9 +25,6 @@
14602 struct mm_struct;
14603 struct vm_area_struct;
14604
14605-extern pgd_t swapper_pg_dir[1024];
14606-extern pgd_t initial_page_table[1024];
14607-
14608 static inline void pgtable_cache_init(void) { }
14609 static inline void check_pgt_cache(void) { }
14610 void paging_init(void);
14611@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14612 # include <asm/pgtable-2level.h>
14613 #endif
14614
14615+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14616+extern pgd_t initial_page_table[PTRS_PER_PGD];
14617+#ifdef CONFIG_X86_PAE
14618+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14619+#endif
14620+
14621 #if defined(CONFIG_HIGHPTE)
14622 #define pte_offset_map(dir, address) \
14623 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14624@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14625 /* Clear a kernel PTE and flush it from the TLB */
14626 #define kpte_clear_flush(ptep, vaddr) \
14627 do { \
14628+ pax_open_kernel(); \
14629 pte_clear(&init_mm, (vaddr), (ptep)); \
14630+ pax_close_kernel(); \
14631 __flush_tlb_one((vaddr)); \
14632 } while (0)
14633
14634 #endif /* !__ASSEMBLY__ */
14635
14636+#define HAVE_ARCH_UNMAPPED_AREA
14637+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14638+
14639 /*
14640 * kern_addr_valid() is (1) for FLATMEM and (0) for
14641 * SPARSEMEM and DISCONTIGMEM
14642diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14643index ed5903b..c7fe163 100644
14644--- a/arch/x86/include/asm/pgtable_32_types.h
14645+++ b/arch/x86/include/asm/pgtable_32_types.h
14646@@ -8,7 +8,7 @@
14647 */
14648 #ifdef CONFIG_X86_PAE
14649 # include <asm/pgtable-3level_types.h>
14650-# define PMD_SIZE (1UL << PMD_SHIFT)
14651+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14652 # define PMD_MASK (~(PMD_SIZE - 1))
14653 #else
14654 # include <asm/pgtable-2level_types.h>
14655@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14656 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14657 #endif
14658
14659+#ifdef CONFIG_PAX_KERNEXEC
14660+#ifndef __ASSEMBLY__
14661+extern unsigned char MODULES_EXEC_VADDR[];
14662+extern unsigned char MODULES_EXEC_END[];
14663+#endif
14664+#include <asm/boot.h>
14665+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14666+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14667+#else
14668+#define ktla_ktva(addr) (addr)
14669+#define ktva_ktla(addr) (addr)
14670+#endif
14671+
14672 #define MODULES_VADDR VMALLOC_START
14673 #define MODULES_END VMALLOC_END
14674 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14675diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14676index e22c1db..23a625a 100644
14677--- a/arch/x86/include/asm/pgtable_64.h
14678+++ b/arch/x86/include/asm/pgtable_64.h
14679@@ -16,10 +16,14 @@
14680
14681 extern pud_t level3_kernel_pgt[512];
14682 extern pud_t level3_ident_pgt[512];
14683+extern pud_t level3_vmalloc_start_pgt[512];
14684+extern pud_t level3_vmalloc_end_pgt[512];
14685+extern pud_t level3_vmemmap_pgt[512];
14686+extern pud_t level2_vmemmap_pgt[512];
14687 extern pmd_t level2_kernel_pgt[512];
14688 extern pmd_t level2_fixmap_pgt[512];
14689-extern pmd_t level2_ident_pgt[512];
14690-extern pgd_t init_level4_pgt[];
14691+extern pmd_t level2_ident_pgt[512*2];
14692+extern pgd_t init_level4_pgt[512];
14693
14694 #define swapper_pg_dir init_level4_pgt
14695
14696@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14697
14698 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14699 {
14700+ pax_open_kernel();
14701 *pmdp = pmd;
14702+ pax_close_kernel();
14703 }
14704
14705 static inline void native_pmd_clear(pmd_t *pmd)
14706@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14707
14708 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14709 {
14710+ pax_open_kernel();
14711 *pudp = pud;
14712+ pax_close_kernel();
14713 }
14714
14715 static inline void native_pud_clear(pud_t *pud)
14716@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14717
14718 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14719 {
14720+ pax_open_kernel();
14721+ *pgdp = pgd;
14722+ pax_close_kernel();
14723+}
14724+
14725+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14726+{
14727 *pgdp = pgd;
14728 }
14729
14730diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14731index 2d88344..4679fc3 100644
14732--- a/arch/x86/include/asm/pgtable_64_types.h
14733+++ b/arch/x86/include/asm/pgtable_64_types.h
14734@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
14735 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14736 #define MODULES_END _AC(0xffffffffff000000, UL)
14737 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14738+#define MODULES_EXEC_VADDR MODULES_VADDR
14739+#define MODULES_EXEC_END MODULES_END
14740+
14741+#define ktla_ktva(addr) (addr)
14742+#define ktva_ktla(addr) (addr)
14743
14744 #define EARLY_DYNAMIC_PAGE_TABLES 64
14745
14746diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14747index e642300..0ef8f31 100644
14748--- a/arch/x86/include/asm/pgtable_types.h
14749+++ b/arch/x86/include/asm/pgtable_types.h
14750@@ -16,13 +16,12 @@
14751 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14752 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14753 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14754-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14755+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14756 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14757 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14758 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14759-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14760-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14761-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14762+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14763+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14764 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14765
14766 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14767@@ -40,7 +39,6 @@
14768 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14769 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14770 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14771-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14772 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14773 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14774 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14775@@ -57,8 +55,10 @@
14776
14777 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14778 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14779-#else
14780+#elif defined(CONFIG_KMEMCHECK)
14781 #define _PAGE_NX (_AT(pteval_t, 0))
14782+#else
14783+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14784 #endif
14785
14786 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14787@@ -116,6 +116,9 @@
14788 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14789 _PAGE_ACCESSED)
14790
14791+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14792+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14793+
14794 #define __PAGE_KERNEL_EXEC \
14795 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14796 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14797@@ -126,7 +129,7 @@
14798 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14799 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14800 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14801-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14802+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14803 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14804 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14805 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14806@@ -188,8 +191,8 @@
14807 * bits are combined, this will alow user to access the high address mapped
14808 * VDSO in the presence of CONFIG_COMPAT_VDSO
14809 */
14810-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14811-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14812+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14813+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14814 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14815 #endif
14816
14817@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14818 {
14819 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14820 }
14821+#endif
14822
14823+#if PAGETABLE_LEVELS == 3
14824+#include <asm-generic/pgtable-nopud.h>
14825+#endif
14826+
14827+#if PAGETABLE_LEVELS == 2
14828+#include <asm-generic/pgtable-nopmd.h>
14829+#endif
14830+
14831+#ifndef __ASSEMBLY__
14832 #if PAGETABLE_LEVELS > 3
14833 typedef struct { pudval_t pud; } pud_t;
14834
14835@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14836 return pud.pud;
14837 }
14838 #else
14839-#include <asm-generic/pgtable-nopud.h>
14840-
14841 static inline pudval_t native_pud_val(pud_t pud)
14842 {
14843 return native_pgd_val(pud.pgd);
14844@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14845 return pmd.pmd;
14846 }
14847 #else
14848-#include <asm-generic/pgtable-nopmd.h>
14849-
14850 static inline pmdval_t native_pmd_val(pmd_t pmd)
14851 {
14852 return native_pgd_val(pmd.pud.pgd);
14853@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14854
14855 extern pteval_t __supported_pte_mask;
14856 extern void set_nx(void);
14857-extern int nx_enabled;
14858
14859 #define pgprot_writecombine pgprot_writecombine
14860 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14861diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14862index 22224b3..4080dab 100644
14863--- a/arch/x86/include/asm/processor.h
14864+++ b/arch/x86/include/asm/processor.h
14865@@ -282,7 +282,7 @@ struct tss_struct {
14866
14867 } ____cacheline_aligned;
14868
14869-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14870+extern struct tss_struct init_tss[NR_CPUS];
14871
14872 /*
14873 * Save the original ist values for checking stack pointers during debugging
14874@@ -823,11 +823,18 @@ static inline void spin_lock_prefetch(const void *x)
14875 */
14876 #define TASK_SIZE PAGE_OFFSET
14877 #define TASK_SIZE_MAX TASK_SIZE
14878+
14879+#ifdef CONFIG_PAX_SEGMEXEC
14880+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14881+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14882+#else
14883 #define STACK_TOP TASK_SIZE
14884-#define STACK_TOP_MAX STACK_TOP
14885+#endif
14886+
14887+#define STACK_TOP_MAX TASK_SIZE
14888
14889 #define INIT_THREAD { \
14890- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14891+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14892 .vm86_info = NULL, \
14893 .sysenter_cs = __KERNEL_CS, \
14894 .io_bitmap_ptr = NULL, \
14895@@ -841,7 +848,7 @@ static inline void spin_lock_prefetch(const void *x)
14896 */
14897 #define INIT_TSS { \
14898 .x86_tss = { \
14899- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14900+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14901 .ss0 = __KERNEL_DS, \
14902 .ss1 = __KERNEL_CS, \
14903 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14904@@ -852,11 +859,7 @@ static inline void spin_lock_prefetch(const void *x)
14905 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14906
14907 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14908-#define KSTK_TOP(info) \
14909-({ \
14910- unsigned long *__ptr = (unsigned long *)(info); \
14911- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14912-})
14913+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14914
14915 /*
14916 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14917@@ -871,7 +874,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14918 #define task_pt_regs(task) \
14919 ({ \
14920 struct pt_regs *__regs__; \
14921- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14922+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14923 __regs__ - 1; \
14924 })
14925
14926@@ -881,13 +884,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14927 /*
14928 * User space process size. 47bits minus one guard page.
14929 */
14930-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14931+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14932
14933 /* This decides where the kernel will search for a free chunk of vm
14934 * space during mmap's.
14935 */
14936 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14937- 0xc0000000 : 0xFFFFe000)
14938+ 0xc0000000 : 0xFFFFf000)
14939
14940 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14941 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14942@@ -898,11 +901,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14943 #define STACK_TOP_MAX TASK_SIZE_MAX
14944
14945 #define INIT_THREAD { \
14946- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14947+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14948 }
14949
14950 #define INIT_TSS { \
14951- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14952+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14953 }
14954
14955 /*
14956@@ -930,6 +933,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14957 */
14958 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14959
14960+#ifdef CONFIG_PAX_SEGMEXEC
14961+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14962+#endif
14963+
14964 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14965
14966 /* Get/set a process' ability to use the timestamp counter instruction */
14967@@ -970,7 +977,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
14968 return ratio;
14969 }
14970
14971-extern unsigned long arch_align_stack(unsigned long sp);
14972+#define arch_align_stack(x) ((x) & ~0xfUL)
14973 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14974
14975 void default_idle(void);
14976@@ -980,6 +987,6 @@ bool xen_set_default_idle(void);
14977 #define xen_set_default_idle 0
14978 #endif
14979
14980-void stop_this_cpu(void *dummy);
14981+void stop_this_cpu(void *dummy) __noreturn;
14982
14983 #endif /* _ASM_X86_PROCESSOR_H */
14984diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14985index 942a086..6c26446 100644
14986--- a/arch/x86/include/asm/ptrace.h
14987+++ b/arch/x86/include/asm/ptrace.h
14988@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14989 }
14990
14991 /*
14992- * user_mode_vm(regs) determines whether a register set came from user mode.
14993+ * user_mode(regs) determines whether a register set came from user mode.
14994 * This is true if V8086 mode was enabled OR if the register set was from
14995 * protected mode with RPL-3 CS value. This tricky test checks that with
14996 * one comparison. Many places in the kernel can bypass this full check
14997- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14998+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14999+ * be used.
15000 */
15001-static inline int user_mode(struct pt_regs *regs)
15002+static inline int user_mode_novm(struct pt_regs *regs)
15003 {
15004 #ifdef CONFIG_X86_32
15005 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
15006 #else
15007- return !!(regs->cs & 3);
15008+ return !!(regs->cs & SEGMENT_RPL_MASK);
15009 #endif
15010 }
15011
15012-static inline int user_mode_vm(struct pt_regs *regs)
15013+static inline int user_mode(struct pt_regs *regs)
15014 {
15015 #ifdef CONFIG_X86_32
15016 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
15017 USER_RPL;
15018 #else
15019- return user_mode(regs);
15020+ return user_mode_novm(regs);
15021 #endif
15022 }
15023
15024@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
15025 #ifdef CONFIG_X86_64
15026 static inline bool user_64bit_mode(struct pt_regs *regs)
15027 {
15028+ unsigned long cs = regs->cs & 0xffff;
15029 #ifndef CONFIG_PARAVIRT
15030 /*
15031 * On non-paravirt systems, this is the only long mode CPL 3
15032 * selector. We do not allow long mode selectors in the LDT.
15033 */
15034- return regs->cs == __USER_CS;
15035+ return cs == __USER_CS;
15036 #else
15037 /* Headers are too twisted for this to go in paravirt.h. */
15038- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15039+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15040 #endif
15041 }
15042
15043@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15044 * Traps from the kernel do not save sp and ss.
15045 * Use the helper function to retrieve sp.
15046 */
15047- if (offset == offsetof(struct pt_regs, sp) &&
15048- regs->cs == __KERNEL_CS)
15049- return kernel_stack_pointer(regs);
15050+ if (offset == offsetof(struct pt_regs, sp)) {
15051+ unsigned long cs = regs->cs & 0xffff;
15052+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15053+ return kernel_stack_pointer(regs);
15054+ }
15055 #endif
15056 return *(unsigned long *)((unsigned long)regs + offset);
15057 }
15058diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15059index 9c6b890..5305f53 100644
15060--- a/arch/x86/include/asm/realmode.h
15061+++ b/arch/x86/include/asm/realmode.h
15062@@ -22,16 +22,14 @@ struct real_mode_header {
15063 #endif
15064 /* APM/BIOS reboot */
15065 u32 machine_real_restart_asm;
15066-#ifdef CONFIG_X86_64
15067 u32 machine_real_restart_seg;
15068-#endif
15069 };
15070
15071 /* This must match data at trampoline_32/64.S */
15072 struct trampoline_header {
15073 #ifdef CONFIG_X86_32
15074 u32 start;
15075- u16 gdt_pad;
15076+ u16 boot_cs;
15077 u16 gdt_limit;
15078 u32 gdt_base;
15079 #else
15080diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15081index a82c4f1..ac45053 100644
15082--- a/arch/x86/include/asm/reboot.h
15083+++ b/arch/x86/include/asm/reboot.h
15084@@ -6,13 +6,13 @@
15085 struct pt_regs;
15086
15087 struct machine_ops {
15088- void (*restart)(char *cmd);
15089- void (*halt)(void);
15090- void (*power_off)(void);
15091+ void (* __noreturn restart)(char *cmd);
15092+ void (* __noreturn halt)(void);
15093+ void (* __noreturn power_off)(void);
15094 void (*shutdown)(void);
15095 void (*crash_shutdown)(struct pt_regs *);
15096- void (*emergency_restart)(void);
15097-};
15098+ void (* __noreturn emergency_restart)(void);
15099+} __no_const;
15100
15101 extern struct machine_ops machine_ops;
15102
15103diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15104index cad82c9..2e5c5c1 100644
15105--- a/arch/x86/include/asm/rwsem.h
15106+++ b/arch/x86/include/asm/rwsem.h
15107@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15108 {
15109 asm volatile("# beginning down_read\n\t"
15110 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15111+
15112+#ifdef CONFIG_PAX_REFCOUNT
15113+ "jno 0f\n"
15114+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15115+ "int $4\n0:\n"
15116+ _ASM_EXTABLE(0b, 0b)
15117+#endif
15118+
15119 /* adds 0x00000001 */
15120 " jns 1f\n"
15121 " call call_rwsem_down_read_failed\n"
15122@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15123 "1:\n\t"
15124 " mov %1,%2\n\t"
15125 " add %3,%2\n\t"
15126+
15127+#ifdef CONFIG_PAX_REFCOUNT
15128+ "jno 0f\n"
15129+ "sub %3,%2\n"
15130+ "int $4\n0:\n"
15131+ _ASM_EXTABLE(0b, 0b)
15132+#endif
15133+
15134 " jle 2f\n\t"
15135 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15136 " jnz 1b\n\t"
15137@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15138 long tmp;
15139 asm volatile("# beginning down_write\n\t"
15140 LOCK_PREFIX " xadd %1,(%2)\n\t"
15141+
15142+#ifdef CONFIG_PAX_REFCOUNT
15143+ "jno 0f\n"
15144+ "mov %1,(%2)\n"
15145+ "int $4\n0:\n"
15146+ _ASM_EXTABLE(0b, 0b)
15147+#endif
15148+
15149 /* adds 0xffff0001, returns the old value */
15150 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
15151 /* was the active mask 0 before? */
15152@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15153 long tmp;
15154 asm volatile("# beginning __up_read\n\t"
15155 LOCK_PREFIX " xadd %1,(%2)\n\t"
15156+
15157+#ifdef CONFIG_PAX_REFCOUNT
15158+ "jno 0f\n"
15159+ "mov %1,(%2)\n"
15160+ "int $4\n0:\n"
15161+ _ASM_EXTABLE(0b, 0b)
15162+#endif
15163+
15164 /* subtracts 1, returns the old value */
15165 " jns 1f\n\t"
15166 " call call_rwsem_wake\n" /* expects old value in %edx */
15167@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15168 long tmp;
15169 asm volatile("# beginning __up_write\n\t"
15170 LOCK_PREFIX " xadd %1,(%2)\n\t"
15171+
15172+#ifdef CONFIG_PAX_REFCOUNT
15173+ "jno 0f\n"
15174+ "mov %1,(%2)\n"
15175+ "int $4\n0:\n"
15176+ _ASM_EXTABLE(0b, 0b)
15177+#endif
15178+
15179 /* subtracts 0xffff0001, returns the old value */
15180 " jns 1f\n\t"
15181 " call call_rwsem_wake\n" /* expects old value in %edx */
15182@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15183 {
15184 asm volatile("# beginning __downgrade_write\n\t"
15185 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15186+
15187+#ifdef CONFIG_PAX_REFCOUNT
15188+ "jno 0f\n"
15189+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15190+ "int $4\n0:\n"
15191+ _ASM_EXTABLE(0b, 0b)
15192+#endif
15193+
15194 /*
15195 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15196 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15197@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15198 */
15199 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15200 {
15201- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15202+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15203+
15204+#ifdef CONFIG_PAX_REFCOUNT
15205+ "jno 0f\n"
15206+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15207+ "int $4\n0:\n"
15208+ _ASM_EXTABLE(0b, 0b)
15209+#endif
15210+
15211 : "+m" (sem->count)
15212 : "er" (delta));
15213 }
15214@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15215 */
15216 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15217 {
15218- return delta + xadd(&sem->count, delta);
15219+ return delta + xadd_check_overflow(&sem->count, delta);
15220 }
15221
15222 #endif /* __KERNEL__ */
15223diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15224index c48a950..c6d7468 100644
15225--- a/arch/x86/include/asm/segment.h
15226+++ b/arch/x86/include/asm/segment.h
15227@@ -64,10 +64,15 @@
15228 * 26 - ESPFIX small SS
15229 * 27 - per-cpu [ offset to per-cpu data area ]
15230 * 28 - stack_canary-20 [ for stack protector ]
15231- * 29 - unused
15232- * 30 - unused
15233+ * 29 - PCI BIOS CS
15234+ * 30 - PCI BIOS DS
15235 * 31 - TSS for double fault handler
15236 */
15237+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15238+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15239+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15240+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15241+
15242 #define GDT_ENTRY_TLS_MIN 6
15243 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15244
15245@@ -79,6 +84,8 @@
15246
15247 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15248
15249+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15250+
15251 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15252
15253 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15254@@ -104,6 +111,12 @@
15255 #define __KERNEL_STACK_CANARY 0
15256 #endif
15257
15258+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15259+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15260+
15261+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15262+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15263+
15264 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15265
15266 /*
15267@@ -141,7 +154,7 @@
15268 */
15269
15270 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15271-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15272+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15273
15274
15275 #else
15276@@ -165,6 +178,8 @@
15277 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15278 #define __USER32_DS __USER_DS
15279
15280+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15281+
15282 #define GDT_ENTRY_TSS 8 /* needs two entries */
15283 #define GDT_ENTRY_LDT 10 /* needs two entries */
15284 #define GDT_ENTRY_TLS_MIN 12
15285@@ -185,6 +200,7 @@
15286 #endif
15287
15288 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15289+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15290 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15291 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15292 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15293@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15294 {
15295 unsigned long __limit;
15296 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15297- return __limit + 1;
15298+ return __limit;
15299 }
15300
15301 #endif /* !__ASSEMBLY__ */
15302diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15303index b073aae..39f9bdd 100644
15304--- a/arch/x86/include/asm/smp.h
15305+++ b/arch/x86/include/asm/smp.h
15306@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15307 /* cpus sharing the last level cache: */
15308 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15309 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15310-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15311+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15312
15313 static inline struct cpumask *cpu_sibling_mask(int cpu)
15314 {
15315@@ -79,7 +79,7 @@ struct smp_ops {
15316
15317 void (*send_call_func_ipi)(const struct cpumask *mask);
15318 void (*send_call_func_single_ipi)(int cpu);
15319-};
15320+} __no_const;
15321
15322 /* Globals due to paravirt */
15323 extern void set_cpu_sibling_map(int cpu);
15324@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15325 extern int safe_smp_processor_id(void);
15326
15327 #elif defined(CONFIG_X86_64_SMP)
15328-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15329-
15330-#define stack_smp_processor_id() \
15331-({ \
15332- struct thread_info *ti; \
15333- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15334- ti->cpu; \
15335-})
15336+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15337+#define stack_smp_processor_id() raw_smp_processor_id()
15338 #define safe_smp_processor_id() smp_processor_id()
15339
15340 #endif
15341diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15342index 33692ea..350a534 100644
15343--- a/arch/x86/include/asm/spinlock.h
15344+++ b/arch/x86/include/asm/spinlock.h
15345@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15346 static inline void arch_read_lock(arch_rwlock_t *rw)
15347 {
15348 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15349+
15350+#ifdef CONFIG_PAX_REFCOUNT
15351+ "jno 0f\n"
15352+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15353+ "int $4\n0:\n"
15354+ _ASM_EXTABLE(0b, 0b)
15355+#endif
15356+
15357 "jns 1f\n"
15358 "call __read_lock_failed\n\t"
15359 "1:\n"
15360@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15361 static inline void arch_write_lock(arch_rwlock_t *rw)
15362 {
15363 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15364+
15365+#ifdef CONFIG_PAX_REFCOUNT
15366+ "jno 0f\n"
15367+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15368+ "int $4\n0:\n"
15369+ _ASM_EXTABLE(0b, 0b)
15370+#endif
15371+
15372 "jz 1f\n"
15373 "call __write_lock_failed\n\t"
15374 "1:\n"
15375@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15376
15377 static inline void arch_read_unlock(arch_rwlock_t *rw)
15378 {
15379- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15380+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15381+
15382+#ifdef CONFIG_PAX_REFCOUNT
15383+ "jno 0f\n"
15384+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15385+ "int $4\n0:\n"
15386+ _ASM_EXTABLE(0b, 0b)
15387+#endif
15388+
15389 :"+m" (rw->lock) : : "memory");
15390 }
15391
15392 static inline void arch_write_unlock(arch_rwlock_t *rw)
15393 {
15394- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15395+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15396+
15397+#ifdef CONFIG_PAX_REFCOUNT
15398+ "jno 0f\n"
15399+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15400+ "int $4\n0:\n"
15401+ _ASM_EXTABLE(0b, 0b)
15402+#endif
15403+
15404 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15405 }
15406
15407diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15408index 6a99859..03cb807 100644
15409--- a/arch/x86/include/asm/stackprotector.h
15410+++ b/arch/x86/include/asm/stackprotector.h
15411@@ -47,7 +47,7 @@
15412 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15413 */
15414 #define GDT_STACK_CANARY_INIT \
15415- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15416+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15417
15418 /*
15419 * Initialize the stackprotector canary value.
15420@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15421
15422 static inline void load_stack_canary_segment(void)
15423 {
15424-#ifdef CONFIG_X86_32
15425+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15426 asm volatile ("mov %0, %%gs" : : "r" (0));
15427 #endif
15428 }
15429diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15430index 70bbe39..4ae2bd4 100644
15431--- a/arch/x86/include/asm/stacktrace.h
15432+++ b/arch/x86/include/asm/stacktrace.h
15433@@ -11,28 +11,20 @@
15434
15435 extern int kstack_depth_to_print;
15436
15437-struct thread_info;
15438+struct task_struct;
15439 struct stacktrace_ops;
15440
15441-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15442- unsigned long *stack,
15443- unsigned long bp,
15444- const struct stacktrace_ops *ops,
15445- void *data,
15446- unsigned long *end,
15447- int *graph);
15448+typedef unsigned long walk_stack_t(struct task_struct *task,
15449+ void *stack_start,
15450+ unsigned long *stack,
15451+ unsigned long bp,
15452+ const struct stacktrace_ops *ops,
15453+ void *data,
15454+ unsigned long *end,
15455+ int *graph);
15456
15457-extern unsigned long
15458-print_context_stack(struct thread_info *tinfo,
15459- unsigned long *stack, unsigned long bp,
15460- const struct stacktrace_ops *ops, void *data,
15461- unsigned long *end, int *graph);
15462-
15463-extern unsigned long
15464-print_context_stack_bp(struct thread_info *tinfo,
15465- unsigned long *stack, unsigned long bp,
15466- const struct stacktrace_ops *ops, void *data,
15467- unsigned long *end, int *graph);
15468+extern walk_stack_t print_context_stack;
15469+extern walk_stack_t print_context_stack_bp;
15470
15471 /* Generic stack tracer with callbacks */
15472
15473@@ -40,7 +32,7 @@ struct stacktrace_ops {
15474 void (*address)(void *data, unsigned long address, int reliable);
15475 /* On negative return stop dumping */
15476 int (*stack)(void *data, char *name);
15477- walk_stack_t walk_stack;
15478+ walk_stack_t *walk_stack;
15479 };
15480
15481 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15482diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15483index 4ec45b3..a4f0a8a 100644
15484--- a/arch/x86/include/asm/switch_to.h
15485+++ b/arch/x86/include/asm/switch_to.h
15486@@ -108,7 +108,7 @@ do { \
15487 "call __switch_to\n\t" \
15488 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15489 __switch_canary \
15490- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15491+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15492 "movq %%rax,%%rdi\n\t" \
15493 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15494 "jnz ret_from_fork\n\t" \
15495@@ -119,7 +119,7 @@ do { \
15496 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15497 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15498 [_tif_fork] "i" (_TIF_FORK), \
15499- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15500+ [thread_info] "m" (current_tinfo), \
15501 [current_task] "m" (current_task) \
15502 __switch_canary_iparam \
15503 : "memory", "cc" __EXTRA_CLOBBER)
15504diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15505index a1df6e8..e002940 100644
15506--- a/arch/x86/include/asm/thread_info.h
15507+++ b/arch/x86/include/asm/thread_info.h
15508@@ -10,6 +10,7 @@
15509 #include <linux/compiler.h>
15510 #include <asm/page.h>
15511 #include <asm/types.h>
15512+#include <asm/percpu.h>
15513
15514 /*
15515 * low level task data that entry.S needs immediate access to
15516@@ -23,7 +24,6 @@ struct exec_domain;
15517 #include <linux/atomic.h>
15518
15519 struct thread_info {
15520- struct task_struct *task; /* main task structure */
15521 struct exec_domain *exec_domain; /* execution domain */
15522 __u32 flags; /* low level flags */
15523 __u32 status; /* thread synchronous flags */
15524@@ -33,19 +33,13 @@ struct thread_info {
15525 mm_segment_t addr_limit;
15526 struct restart_block restart_block;
15527 void __user *sysenter_return;
15528-#ifdef CONFIG_X86_32
15529- unsigned long previous_esp; /* ESP of the previous stack in
15530- case of nested (IRQ) stacks
15531- */
15532- __u8 supervisor_stack[0];
15533-#endif
15534+ unsigned long lowest_stack;
15535 unsigned int sig_on_uaccess_error:1;
15536 unsigned int uaccess_err:1; /* uaccess failed */
15537 };
15538
15539-#define INIT_THREAD_INFO(tsk) \
15540+#define INIT_THREAD_INFO \
15541 { \
15542- .task = &tsk, \
15543 .exec_domain = &default_exec_domain, \
15544 .flags = 0, \
15545 .cpu = 0, \
15546@@ -56,7 +50,7 @@ struct thread_info {
15547 }, \
15548 }
15549
15550-#define init_thread_info (init_thread_union.thread_info)
15551+#define init_thread_info (init_thread_union.stack)
15552 #define init_stack (init_thread_union.stack)
15553
15554 #else /* !__ASSEMBLY__ */
15555@@ -97,6 +91,7 @@ struct thread_info {
15556 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15557 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15558 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15559+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15560
15561 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15562 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15563@@ -121,17 +116,18 @@ struct thread_info {
15564 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15565 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15566 #define _TIF_X32 (1 << TIF_X32)
15567+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15568
15569 /* work to do in syscall_trace_enter() */
15570 #define _TIF_WORK_SYSCALL_ENTRY \
15571 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15572 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15573- _TIF_NOHZ)
15574+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15575
15576 /* work to do in syscall_trace_leave() */
15577 #define _TIF_WORK_SYSCALL_EXIT \
15578 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15579- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15580+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15581
15582 /* work to do on interrupt/exception return */
15583 #define _TIF_WORK_MASK \
15584@@ -142,7 +138,7 @@ struct thread_info {
15585 /* work to do on any return to user space */
15586 #define _TIF_ALLWORK_MASK \
15587 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15588- _TIF_NOHZ)
15589+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15590
15591 /* Only used for 64 bit */
15592 #define _TIF_DO_NOTIFY_MASK \
15593@@ -158,45 +154,40 @@ struct thread_info {
15594
15595 #define PREEMPT_ACTIVE 0x10000000
15596
15597-#ifdef CONFIG_X86_32
15598-
15599-#define STACK_WARN (THREAD_SIZE/8)
15600-/*
15601- * macros/functions for gaining access to the thread information structure
15602- *
15603- * preempt_count needs to be 1 initially, until the scheduler is functional.
15604- */
15605-#ifndef __ASSEMBLY__
15606-
15607-
15608-/* how to get the current stack pointer from C */
15609-register unsigned long current_stack_pointer asm("esp") __used;
15610-
15611-/* how to get the thread information struct from C */
15612-static inline struct thread_info *current_thread_info(void)
15613-{
15614- return (struct thread_info *)
15615- (current_stack_pointer & ~(THREAD_SIZE - 1));
15616-}
15617-
15618-#else /* !__ASSEMBLY__ */
15619-
15620+#ifdef __ASSEMBLY__
15621 /* how to get the thread information struct from ASM */
15622 #define GET_THREAD_INFO(reg) \
15623- movl $-THREAD_SIZE, reg; \
15624- andl %esp, reg
15625+ mov PER_CPU_VAR(current_tinfo), reg
15626
15627 /* use this one if reg already contains %esp */
15628-#define GET_THREAD_INFO_WITH_ESP(reg) \
15629- andl $-THREAD_SIZE, reg
15630+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15631+#else
15632+/* how to get the thread information struct from C */
15633+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15634+
15635+static __always_inline struct thread_info *current_thread_info(void)
15636+{
15637+ return this_cpu_read_stable(current_tinfo);
15638+}
15639+#endif
15640+
15641+#ifdef CONFIG_X86_32
15642+
15643+#define STACK_WARN (THREAD_SIZE/8)
15644+/*
15645+ * macros/functions for gaining access to the thread information structure
15646+ *
15647+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15648+ */
15649+#ifndef __ASSEMBLY__
15650+
15651+/* how to get the current stack pointer from C */
15652+register unsigned long current_stack_pointer asm("esp") __used;
15653
15654 #endif
15655
15656 #else /* X86_32 */
15657
15658-#include <asm/percpu.h>
15659-#define KERNEL_STACK_OFFSET (5*8)
15660-
15661 /*
15662 * macros/functions for gaining access to the thread information structure
15663 * preempt_count needs to be 1 initially, until the scheduler is functional.
15664@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
15665 #ifndef __ASSEMBLY__
15666 DECLARE_PER_CPU(unsigned long, kernel_stack);
15667
15668-static inline struct thread_info *current_thread_info(void)
15669-{
15670- struct thread_info *ti;
15671- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15672- KERNEL_STACK_OFFSET - THREAD_SIZE);
15673- return ti;
15674-}
15675-
15676-#else /* !__ASSEMBLY__ */
15677-
15678-/* how to get the thread information struct from ASM */
15679-#define GET_THREAD_INFO(reg) \
15680- movq PER_CPU_VAR(kernel_stack),reg ; \
15681- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15682-
15683-/*
15684- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15685- * a certain register (to be used in assembler memory operands).
15686- */
15687-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15688-
15689+/* how to get the current stack pointer from C */
15690+register unsigned long current_stack_pointer asm("rsp") __used;
15691 #endif
15692
15693 #endif /* !X86_32 */
15694@@ -283,5 +255,12 @@ static inline bool is_ia32_task(void)
15695 extern void arch_task_cache_init(void);
15696 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15697 extern void arch_release_task_struct(struct task_struct *tsk);
15698+
15699+#define __HAVE_THREAD_FUNCTIONS
15700+#define task_thread_info(task) (&(task)->tinfo)
15701+#define task_stack_page(task) ((task)->stack)
15702+#define setup_thread_stack(p, org) do {} while (0)
15703+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15704+
15705 #endif
15706 #endif /* _ASM_X86_THREAD_INFO_H */
15707diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15708index 5ee2687..70d5895 100644
15709--- a/arch/x86/include/asm/uaccess.h
15710+++ b/arch/x86/include/asm/uaccess.h
15711@@ -7,6 +7,7 @@
15712 #include <linux/compiler.h>
15713 #include <linux/thread_info.h>
15714 #include <linux/string.h>
15715+#include <linux/sched.h>
15716 #include <asm/asm.h>
15717 #include <asm/page.h>
15718 #include <asm/smap.h>
15719@@ -29,7 +30,12 @@
15720
15721 #define get_ds() (KERNEL_DS)
15722 #define get_fs() (current_thread_info()->addr_limit)
15723+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15724+void __set_fs(mm_segment_t x);
15725+void set_fs(mm_segment_t x);
15726+#else
15727 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15728+#endif
15729
15730 #define segment_eq(a, b) ((a).seg == (b).seg)
15731
15732@@ -77,8 +83,33 @@
15733 * checks that the pointer is in the user space range - after calling
15734 * this function, memory access functions may still return -EFAULT.
15735 */
15736-#define access_ok(type, addr, size) \
15737- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15738+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15739+#define access_ok(type, addr, size) \
15740+({ \
15741+ long __size = size; \
15742+ unsigned long __addr = (unsigned long)addr; \
15743+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15744+ unsigned long __end_ao = __addr + __size - 1; \
15745+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15746+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15747+ while(__addr_ao <= __end_ao) { \
15748+ char __c_ao; \
15749+ __addr_ao += PAGE_SIZE; \
15750+ if (__size > PAGE_SIZE) \
15751+ cond_resched(); \
15752+ if (__get_user(__c_ao, (char __user *)__addr)) \
15753+ break; \
15754+ if (type != VERIFY_WRITE) { \
15755+ __addr = __addr_ao; \
15756+ continue; \
15757+ } \
15758+ if (__put_user(__c_ao, (char __user *)__addr)) \
15759+ break; \
15760+ __addr = __addr_ao; \
15761+ } \
15762+ } \
15763+ __ret_ao; \
15764+})
15765
15766 /*
15767 * The exception table consists of pairs of addresses relative to the
15768@@ -176,13 +207,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15769 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15770 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15771
15772-
15773+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15774+#define __copyuser_seg "gs;"
15775+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15776+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15777+#else
15778+#define __copyuser_seg
15779+#define __COPYUSER_SET_ES
15780+#define __COPYUSER_RESTORE_ES
15781+#endif
15782
15783 #ifdef CONFIG_X86_32
15784 #define __put_user_asm_u64(x, addr, err, errret) \
15785 asm volatile(ASM_STAC "\n" \
15786- "1: movl %%eax,0(%2)\n" \
15787- "2: movl %%edx,4(%2)\n" \
15788+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15789+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15790 "3: " ASM_CLAC "\n" \
15791 ".section .fixup,\"ax\"\n" \
15792 "4: movl %3,%0\n" \
15793@@ -195,8 +234,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15794
15795 #define __put_user_asm_ex_u64(x, addr) \
15796 asm volatile(ASM_STAC "\n" \
15797- "1: movl %%eax,0(%1)\n" \
15798- "2: movl %%edx,4(%1)\n" \
15799+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15800+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15801 "3: " ASM_CLAC "\n" \
15802 _ASM_EXTABLE_EX(1b, 2b) \
15803 _ASM_EXTABLE_EX(2b, 3b) \
15804@@ -246,7 +285,7 @@ extern void __put_user_8(void);
15805 __typeof__(*(ptr)) __pu_val; \
15806 __chk_user_ptr(ptr); \
15807 might_fault(); \
15808- __pu_val = x; \
15809+ __pu_val = (x); \
15810 switch (sizeof(*(ptr))) { \
15811 case 1: \
15812 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15813@@ -345,7 +384,7 @@ do { \
15814
15815 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15816 asm volatile(ASM_STAC "\n" \
15817- "1: mov"itype" %2,%"rtype"1\n" \
15818+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15819 "2: " ASM_CLAC "\n" \
15820 ".section .fixup,\"ax\"\n" \
15821 "3: mov %3,%0\n" \
15822@@ -353,7 +392,7 @@ do { \
15823 " jmp 2b\n" \
15824 ".previous\n" \
15825 _ASM_EXTABLE(1b, 3b) \
15826- : "=r" (err), ltype(x) \
15827+ : "=r" (err), ltype (x) \
15828 : "m" (__m(addr)), "i" (errret), "0" (err))
15829
15830 #define __get_user_size_ex(x, ptr, size) \
15831@@ -378,7 +417,7 @@ do { \
15832 } while (0)
15833
15834 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15835- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15836+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15837 "2:\n" \
15838 _ASM_EXTABLE_EX(1b, 2b) \
15839 : ltype(x) : "m" (__m(addr)))
15840@@ -395,13 +434,24 @@ do { \
15841 int __gu_err; \
15842 unsigned long __gu_val; \
15843 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15844- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15845+ (x) = (__typeof__(*(ptr)))__gu_val; \
15846 __gu_err; \
15847 })
15848
15849 /* FIXME: this hack is definitely wrong -AK */
15850 struct __large_struct { unsigned long buf[100]; };
15851-#define __m(x) (*(struct __large_struct __user *)(x))
15852+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15853+#define ____m(x) \
15854+({ \
15855+ unsigned long ____x = (unsigned long)(x); \
15856+ if (____x < pax_user_shadow_base) \
15857+ ____x += pax_user_shadow_base; \
15858+ (typeof(x))____x; \
15859+})
15860+#else
15861+#define ____m(x) (x)
15862+#endif
15863+#define __m(x) (*(struct __large_struct __user *)____m(x))
15864
15865 /*
15866 * Tell gcc we read from memory instead of writing: this is because
15867@@ -410,7 +460,7 @@ struct __large_struct { unsigned long buf[100]; };
15868 */
15869 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15870 asm volatile(ASM_STAC "\n" \
15871- "1: mov"itype" %"rtype"1,%2\n" \
15872+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15873 "2: " ASM_CLAC "\n" \
15874 ".section .fixup,\"ax\"\n" \
15875 "3: mov %3,%0\n" \
15876@@ -418,10 +468,10 @@ struct __large_struct { unsigned long buf[100]; };
15877 ".previous\n" \
15878 _ASM_EXTABLE(1b, 3b) \
15879 : "=r"(err) \
15880- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15881+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15882
15883 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15884- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15885+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15886 "2:\n" \
15887 _ASM_EXTABLE_EX(1b, 2b) \
15888 : : ltype(x), "m" (__m(addr)))
15889@@ -460,8 +510,12 @@ struct __large_struct { unsigned long buf[100]; };
15890 * On error, the variable @x is set to zero.
15891 */
15892
15893+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15894+#define __get_user(x, ptr) get_user((x), (ptr))
15895+#else
15896 #define __get_user(x, ptr) \
15897 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15898+#endif
15899
15900 /**
15901 * __put_user: - Write a simple value into user space, with less checking.
15902@@ -483,8 +537,12 @@ struct __large_struct { unsigned long buf[100]; };
15903 * Returns zero on success, or -EFAULT on error.
15904 */
15905
15906+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15907+#define __put_user(x, ptr) put_user((x), (ptr))
15908+#else
15909 #define __put_user(x, ptr) \
15910 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15911+#endif
15912
15913 #define __get_user_unaligned __get_user
15914 #define __put_user_unaligned __put_user
15915@@ -502,7 +560,7 @@ struct __large_struct { unsigned long buf[100]; };
15916 #define get_user_ex(x, ptr) do { \
15917 unsigned long __gue_val; \
15918 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15919- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15920+ (x) = (__typeof__(*(ptr)))__gue_val; \
15921 } while (0)
15922
15923 #define put_user_try uaccess_try
15924@@ -519,8 +577,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15925 extern __must_check long strlen_user(const char __user *str);
15926 extern __must_check long strnlen_user(const char __user *str, long n);
15927
15928-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15929-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15930+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15931+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15932
15933 /*
15934 * movsl can be slow when source and dest are not both 8-byte aligned
15935diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15936index 7f760a9..04b1c65 100644
15937--- a/arch/x86/include/asm/uaccess_32.h
15938+++ b/arch/x86/include/asm/uaccess_32.h
15939@@ -11,15 +11,15 @@
15940 #include <asm/page.h>
15941
15942 unsigned long __must_check __copy_to_user_ll
15943- (void __user *to, const void *from, unsigned long n);
15944+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15945 unsigned long __must_check __copy_from_user_ll
15946- (void *to, const void __user *from, unsigned long n);
15947+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15948 unsigned long __must_check __copy_from_user_ll_nozero
15949- (void *to, const void __user *from, unsigned long n);
15950+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15951 unsigned long __must_check __copy_from_user_ll_nocache
15952- (void *to, const void __user *from, unsigned long n);
15953+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15954 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15955- (void *to, const void __user *from, unsigned long n);
15956+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15957
15958 /**
15959 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15960@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15961 static __always_inline unsigned long __must_check
15962 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15963 {
15964+ if ((long)n < 0)
15965+ return n;
15966+
15967+ check_object_size(from, n, true);
15968+
15969 if (__builtin_constant_p(n)) {
15970 unsigned long ret;
15971
15972@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15973 __copy_to_user(void __user *to, const void *from, unsigned long n)
15974 {
15975 might_fault();
15976+
15977 return __copy_to_user_inatomic(to, from, n);
15978 }
15979
15980 static __always_inline unsigned long
15981 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15982 {
15983+ if ((long)n < 0)
15984+ return n;
15985+
15986 /* Avoid zeroing the tail if the copy fails..
15987 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15988 * but as the zeroing behaviour is only significant when n is not
15989@@ -137,6 +146,12 @@ static __always_inline unsigned long
15990 __copy_from_user(void *to, const void __user *from, unsigned long n)
15991 {
15992 might_fault();
15993+
15994+ if ((long)n < 0)
15995+ return n;
15996+
15997+ check_object_size(to, n, false);
15998+
15999 if (__builtin_constant_p(n)) {
16000 unsigned long ret;
16001
16002@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
16003 const void __user *from, unsigned long n)
16004 {
16005 might_fault();
16006+
16007+ if ((long)n < 0)
16008+ return n;
16009+
16010 if (__builtin_constant_p(n)) {
16011 unsigned long ret;
16012
16013@@ -181,15 +200,19 @@ static __always_inline unsigned long
16014 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
16015 unsigned long n)
16016 {
16017- return __copy_from_user_ll_nocache_nozero(to, from, n);
16018+ if ((long)n < 0)
16019+ return n;
16020+
16021+ return __copy_from_user_ll_nocache_nozero(to, from, n);
16022 }
16023
16024-unsigned long __must_check copy_to_user(void __user *to,
16025- const void *from, unsigned long n);
16026-unsigned long __must_check _copy_from_user(void *to,
16027- const void __user *from,
16028- unsigned long n);
16029-
16030+extern void copy_to_user_overflow(void)
16031+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16032+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16033+#else
16034+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16035+#endif
16036+;
16037
16038 extern void copy_from_user_overflow(void)
16039 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16040@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16041 #endif
16042 ;
16043
16044-static inline unsigned long __must_check copy_from_user(void *to,
16045- const void __user *from,
16046- unsigned long n)
16047+/**
16048+ * copy_to_user: - Copy a block of data into user space.
16049+ * @to: Destination address, in user space.
16050+ * @from: Source address, in kernel space.
16051+ * @n: Number of bytes to copy.
16052+ *
16053+ * Context: User context only. This function may sleep.
16054+ *
16055+ * Copy data from kernel space to user space.
16056+ *
16057+ * Returns number of bytes that could not be copied.
16058+ * On success, this will be zero.
16059+ */
16060+static inline unsigned long __must_check
16061+copy_to_user(void __user *to, const void *from, unsigned long n)
16062 {
16063- int sz = __compiletime_object_size(to);
16064+ size_t sz = __compiletime_object_size(from);
16065
16066- if (likely(sz == -1 || sz >= n))
16067- n = _copy_from_user(to, from, n);
16068- else
16069+ if (unlikely(sz != (size_t)-1 && sz < n))
16070+ copy_to_user_overflow();
16071+ else if (access_ok(VERIFY_WRITE, to, n))
16072+ n = __copy_to_user(to, from, n);
16073+ return n;
16074+}
16075+
16076+/**
16077+ * copy_from_user: - Copy a block of data from user space.
16078+ * @to: Destination address, in kernel space.
16079+ * @from: Source address, in user space.
16080+ * @n: Number of bytes to copy.
16081+ *
16082+ * Context: User context only. This function may sleep.
16083+ *
16084+ * Copy data from user space to kernel space.
16085+ *
16086+ * Returns number of bytes that could not be copied.
16087+ * On success, this will be zero.
16088+ *
16089+ * If some data could not be copied, this function will pad the copied
16090+ * data to the requested size using zero bytes.
16091+ */
16092+static inline unsigned long __must_check
16093+copy_from_user(void *to, const void __user *from, unsigned long n)
16094+{
16095+ size_t sz = __compiletime_object_size(to);
16096+
16097+ check_object_size(to, n, false);
16098+
16099+ if (unlikely(sz != (size_t)-1 && sz < n))
16100 copy_from_user_overflow();
16101-
16102+ else if (access_ok(VERIFY_READ, from, n))
16103+ n = __copy_from_user(to, from, n);
16104+ else if ((long)n > 0)
16105+ memset(to, 0, n);
16106 return n;
16107 }
16108
16109diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16110index 142810c..1f2a0a7 100644
16111--- a/arch/x86/include/asm/uaccess_64.h
16112+++ b/arch/x86/include/asm/uaccess_64.h
16113@@ -10,6 +10,9 @@
16114 #include <asm/alternative.h>
16115 #include <asm/cpufeature.h>
16116 #include <asm/page.h>
16117+#include <asm/pgtable.h>
16118+
16119+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16120
16121 /*
16122 * Copy To/From Userspace
16123@@ -17,13 +20,13 @@
16124
16125 /* Handles exceptions in both to and from, but doesn't do access_ok */
16126 __must_check unsigned long
16127-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16128+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16129 __must_check unsigned long
16130-copy_user_generic_string(void *to, const void *from, unsigned len);
16131+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16132 __must_check unsigned long
16133-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16134+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16135
16136-static __always_inline __must_check unsigned long
16137+static __always_inline __must_check __size_overflow(3) unsigned long
16138 copy_user_generic(void *to, const void *from, unsigned len)
16139 {
16140 unsigned ret;
16141@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16142 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16143 "=d" (len)),
16144 "1" (to), "2" (from), "3" (len)
16145- : "memory", "rcx", "r8", "r9", "r10", "r11");
16146+ : "memory", "rcx", "r8", "r9", "r11");
16147 return ret;
16148 }
16149
16150+static __always_inline __must_check unsigned long
16151+__copy_to_user(void __user *to, const void *from, unsigned long len);
16152+static __always_inline __must_check unsigned long
16153+__copy_from_user(void *to, const void __user *from, unsigned long len);
16154 __must_check unsigned long
16155-_copy_to_user(void __user *to, const void *from, unsigned len);
16156-__must_check unsigned long
16157-_copy_from_user(void *to, const void __user *from, unsigned len);
16158-__must_check unsigned long
16159-copy_in_user(void __user *to, const void __user *from, unsigned len);
16160+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16161+
16162+extern void copy_to_user_overflow(void)
16163+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16164+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16165+#else
16166+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16167+#endif
16168+;
16169+
16170+extern void copy_from_user_overflow(void)
16171+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16172+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16173+#else
16174+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16175+#endif
16176+;
16177
16178 static inline unsigned long __must_check copy_from_user(void *to,
16179 const void __user *from,
16180 unsigned long n)
16181 {
16182- int sz = __compiletime_object_size(to);
16183-
16184 might_fault();
16185- if (likely(sz == -1 || sz >= n))
16186- n = _copy_from_user(to, from, n);
16187-#ifdef CONFIG_DEBUG_VM
16188- else
16189- WARN(1, "Buffer overflow detected!\n");
16190-#endif
16191+
16192+ check_object_size(to, n, false);
16193+
16194+ if (access_ok(VERIFY_READ, from, n))
16195+ n = __copy_from_user(to, from, n);
16196+ else if (n < INT_MAX)
16197+ memset(to, 0, n);
16198 return n;
16199 }
16200
16201 static __always_inline __must_check
16202-int copy_to_user(void __user *dst, const void *src, unsigned size)
16203+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16204 {
16205 might_fault();
16206
16207- return _copy_to_user(dst, src, size);
16208+ if (access_ok(VERIFY_WRITE, dst, size))
16209+ size = __copy_to_user(dst, src, size);
16210+ return size;
16211 }
16212
16213 static __always_inline __must_check
16214-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16215+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16216 {
16217- int ret = 0;
16218+ size_t sz = __compiletime_object_size(dst);
16219+ unsigned ret = 0;
16220
16221 might_fault();
16222+
16223+ if (size > INT_MAX)
16224+ return size;
16225+
16226+ check_object_size(dst, size, false);
16227+
16228+#ifdef CONFIG_PAX_MEMORY_UDEREF
16229+ if (!__access_ok(VERIFY_READ, src, size))
16230+ return size;
16231+#endif
16232+
16233+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16234+ copy_from_user_overflow();
16235+ return size;
16236+ }
16237+
16238 if (!__builtin_constant_p(size))
16239- return copy_user_generic(dst, (__force void *)src, size);
16240+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16241 switch (size) {
16242- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16243+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16244 ret, "b", "b", "=q", 1);
16245 return ret;
16246- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16247+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16248 ret, "w", "w", "=r", 2);
16249 return ret;
16250- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16251+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16252 ret, "l", "k", "=r", 4);
16253 return ret;
16254- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16255+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16256 ret, "q", "", "=r", 8);
16257 return ret;
16258 case 10:
16259- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16260+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16261 ret, "q", "", "=r", 10);
16262 if (unlikely(ret))
16263 return ret;
16264 __get_user_asm(*(u16 *)(8 + (char *)dst),
16265- (u16 __user *)(8 + (char __user *)src),
16266+ (const u16 __user *)(8 + (const char __user *)src),
16267 ret, "w", "w", "=r", 2);
16268 return ret;
16269 case 16:
16270- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16271+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16272 ret, "q", "", "=r", 16);
16273 if (unlikely(ret))
16274 return ret;
16275 __get_user_asm(*(u64 *)(8 + (char *)dst),
16276- (u64 __user *)(8 + (char __user *)src),
16277+ (const u64 __user *)(8 + (const char __user *)src),
16278 ret, "q", "", "=r", 8);
16279 return ret;
16280 default:
16281- return copy_user_generic(dst, (__force void *)src, size);
16282+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16283 }
16284 }
16285
16286 static __always_inline __must_check
16287-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16288+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16289 {
16290- int ret = 0;
16291+ size_t sz = __compiletime_object_size(src);
16292+ unsigned ret = 0;
16293
16294 might_fault();
16295+
16296+ if (size > INT_MAX)
16297+ return size;
16298+
16299+ check_object_size(src, size, true);
16300+
16301+#ifdef CONFIG_PAX_MEMORY_UDEREF
16302+ if (!__access_ok(VERIFY_WRITE, dst, size))
16303+ return size;
16304+#endif
16305+
16306+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16307+ copy_to_user_overflow();
16308+ return size;
16309+ }
16310+
16311 if (!__builtin_constant_p(size))
16312- return copy_user_generic((__force void *)dst, src, size);
16313+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16314 switch (size) {
16315- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16316+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16317 ret, "b", "b", "iq", 1);
16318 return ret;
16319- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16320+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16321 ret, "w", "w", "ir", 2);
16322 return ret;
16323- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16324+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16325 ret, "l", "k", "ir", 4);
16326 return ret;
16327- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16328+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16329 ret, "q", "", "er", 8);
16330 return ret;
16331 case 10:
16332- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16333+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16334 ret, "q", "", "er", 10);
16335 if (unlikely(ret))
16336 return ret;
16337 asm("":::"memory");
16338- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16339+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16340 ret, "w", "w", "ir", 2);
16341 return ret;
16342 case 16:
16343- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16344+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16345 ret, "q", "", "er", 16);
16346 if (unlikely(ret))
16347 return ret;
16348 asm("":::"memory");
16349- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16350+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16351 ret, "q", "", "er", 8);
16352 return ret;
16353 default:
16354- return copy_user_generic((__force void *)dst, src, size);
16355+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16356 }
16357 }
16358
16359 static __always_inline __must_check
16360-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16361+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16362 {
16363- int ret = 0;
16364+ unsigned ret = 0;
16365
16366 might_fault();
16367+
16368+ if (size > INT_MAX)
16369+ return size;
16370+
16371+#ifdef CONFIG_PAX_MEMORY_UDEREF
16372+ if (!__access_ok(VERIFY_READ, src, size))
16373+ return size;
16374+ if (!__access_ok(VERIFY_WRITE, dst, size))
16375+ return size;
16376+#endif
16377+
16378 if (!__builtin_constant_p(size))
16379- return copy_user_generic((__force void *)dst,
16380- (__force void *)src, size);
16381+ return copy_user_generic((__force_kernel void *)____m(dst),
16382+ (__force_kernel const void *)____m(src), size);
16383 switch (size) {
16384 case 1: {
16385 u8 tmp;
16386- __get_user_asm(tmp, (u8 __user *)src,
16387+ __get_user_asm(tmp, (const u8 __user *)src,
16388 ret, "b", "b", "=q", 1);
16389 if (likely(!ret))
16390 __put_user_asm(tmp, (u8 __user *)dst,
16391@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16392 }
16393 case 2: {
16394 u16 tmp;
16395- __get_user_asm(tmp, (u16 __user *)src,
16396+ __get_user_asm(tmp, (const u16 __user *)src,
16397 ret, "w", "w", "=r", 2);
16398 if (likely(!ret))
16399 __put_user_asm(tmp, (u16 __user *)dst,
16400@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16401
16402 case 4: {
16403 u32 tmp;
16404- __get_user_asm(tmp, (u32 __user *)src,
16405+ __get_user_asm(tmp, (const u32 __user *)src,
16406 ret, "l", "k", "=r", 4);
16407 if (likely(!ret))
16408 __put_user_asm(tmp, (u32 __user *)dst,
16409@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16410 }
16411 case 8: {
16412 u64 tmp;
16413- __get_user_asm(tmp, (u64 __user *)src,
16414+ __get_user_asm(tmp, (const u64 __user *)src,
16415 ret, "q", "", "=r", 8);
16416 if (likely(!ret))
16417 __put_user_asm(tmp, (u64 __user *)dst,
16418@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16419 return ret;
16420 }
16421 default:
16422- return copy_user_generic((__force void *)dst,
16423- (__force void *)src, size);
16424+ return copy_user_generic((__force_kernel void *)____m(dst),
16425+ (__force_kernel const void *)____m(src), size);
16426 }
16427 }
16428
16429 static __must_check __always_inline int
16430-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16431+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16432 {
16433- return copy_user_generic(dst, (__force const void *)src, size);
16434+ if (size > INT_MAX)
16435+ return size;
16436+
16437+#ifdef CONFIG_PAX_MEMORY_UDEREF
16438+ if (!__access_ok(VERIFY_READ, src, size))
16439+ return size;
16440+#endif
16441+
16442+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16443 }
16444
16445-static __must_check __always_inline int
16446-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16447+static __must_check __always_inline unsigned long
16448+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16449 {
16450- return copy_user_generic((__force void *)dst, src, size);
16451+ if (size > INT_MAX)
16452+ return size;
16453+
16454+#ifdef CONFIG_PAX_MEMORY_UDEREF
16455+ if (!__access_ok(VERIFY_WRITE, dst, size))
16456+ return size;
16457+#endif
16458+
16459+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16460 }
16461
16462-extern long __copy_user_nocache(void *dst, const void __user *src,
16463- unsigned size, int zerorest);
16464+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16465+ unsigned long size, int zerorest) __size_overflow(3);
16466
16467-static inline int
16468-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16469+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16470 {
16471 might_sleep();
16472+
16473+ if (size > INT_MAX)
16474+ return size;
16475+
16476+#ifdef CONFIG_PAX_MEMORY_UDEREF
16477+ if (!__access_ok(VERIFY_READ, src, size))
16478+ return size;
16479+#endif
16480+
16481 return __copy_user_nocache(dst, src, size, 1);
16482 }
16483
16484-static inline int
16485-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16486- unsigned size)
16487+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16488+ unsigned long size)
16489 {
16490+ if (size > INT_MAX)
16491+ return size;
16492+
16493+#ifdef CONFIG_PAX_MEMORY_UDEREF
16494+ if (!__access_ok(VERIFY_READ, src, size))
16495+ return size;
16496+#endif
16497+
16498 return __copy_user_nocache(dst, src, size, 0);
16499 }
16500
16501-unsigned long
16502-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16503+extern unsigned long
16504+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16505
16506 #endif /* _ASM_X86_UACCESS_64_H */
16507diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16508index 5b238981..77fdd78 100644
16509--- a/arch/x86/include/asm/word-at-a-time.h
16510+++ b/arch/x86/include/asm/word-at-a-time.h
16511@@ -11,7 +11,7 @@
16512 * and shift, for example.
16513 */
16514 struct word_at_a_time {
16515- const unsigned long one_bits, high_bits;
16516+ unsigned long one_bits, high_bits;
16517 };
16518
16519 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16520diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16521index d8d9922..bf6cecb 100644
16522--- a/arch/x86/include/asm/x86_init.h
16523+++ b/arch/x86/include/asm/x86_init.h
16524@@ -129,7 +129,7 @@ struct x86_init_ops {
16525 struct x86_init_timers timers;
16526 struct x86_init_iommu iommu;
16527 struct x86_init_pci pci;
16528-};
16529+} __no_const;
16530
16531 /**
16532 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16533@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
16534 void (*setup_percpu_clockev)(void);
16535 void (*early_percpu_clock_init)(void);
16536 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16537-};
16538+} __no_const;
16539
16540 /**
16541 * struct x86_platform_ops - platform specific runtime functions
16542@@ -166,7 +166,7 @@ struct x86_platform_ops {
16543 void (*save_sched_clock_state)(void);
16544 void (*restore_sched_clock_state)(void);
16545 void (*apic_post_init)(void);
16546-};
16547+} __no_const;
16548
16549 struct pci_dev;
16550 struct msi_msg;
16551@@ -180,7 +180,7 @@ struct x86_msi_ops {
16552 void (*teardown_msi_irqs)(struct pci_dev *dev);
16553 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16554 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
16555-};
16556+} __no_const;
16557
16558 struct IO_APIC_route_entry;
16559 struct io_apic_irq_attr;
16560@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
16561 unsigned int destination, int vector,
16562 struct io_apic_irq_attr *attr);
16563 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
16564-};
16565+} __no_const;
16566
16567 extern struct x86_init_ops x86_init;
16568 extern struct x86_cpuinit_ops x86_cpuinit;
16569diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16570index 0415cda..b43d877 100644
16571--- a/arch/x86/include/asm/xsave.h
16572+++ b/arch/x86/include/asm/xsave.h
16573@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16574 return -EFAULT;
16575
16576 __asm__ __volatile__(ASM_STAC "\n"
16577- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16578+ "1:"
16579+ __copyuser_seg
16580+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16581 "2: " ASM_CLAC "\n"
16582 ".section .fixup,\"ax\"\n"
16583 "3: movl $-1,%[err]\n"
16584@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16585 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16586 {
16587 int err;
16588- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16589+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16590 u32 lmask = mask;
16591 u32 hmask = mask >> 32;
16592
16593 __asm__ __volatile__(ASM_STAC "\n"
16594- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16595+ "1:"
16596+ __copyuser_seg
16597+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16598 "2: " ASM_CLAC "\n"
16599 ".section .fixup,\"ax\"\n"
16600 "3: movl $-1,%[err]\n"
16601diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16602index bbae024..e1528f9 100644
16603--- a/arch/x86/include/uapi/asm/e820.h
16604+++ b/arch/x86/include/uapi/asm/e820.h
16605@@ -63,7 +63,7 @@ struct e820map {
16606 #define ISA_START_ADDRESS 0xa0000
16607 #define ISA_END_ADDRESS 0x100000
16608
16609-#define BIOS_BEGIN 0x000a0000
16610+#define BIOS_BEGIN 0x000c0000
16611 #define BIOS_END 0x00100000
16612
16613 #define BIOS_ROM_BASE 0xffe00000
16614diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16615index 7bd3bd3..5dac791 100644
16616--- a/arch/x86/kernel/Makefile
16617+++ b/arch/x86/kernel/Makefile
16618@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16619 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16620 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16621 obj-y += probe_roms.o
16622-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16623+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16624 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16625 obj-y += syscall_$(BITS).o
16626 obj-$(CONFIG_X86_64) += vsyscall_64.o
16627diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16628index 230c8ea..f915130 100644
16629--- a/arch/x86/kernel/acpi/boot.c
16630+++ b/arch/x86/kernel/acpi/boot.c
16631@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16632 * If your system is blacklisted here, but you find that acpi=force
16633 * works for you, please contact linux-acpi@vger.kernel.org
16634 */
16635-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16636+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16637 /*
16638 * Boxes that need ACPI disabled
16639 */
16640@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16641 };
16642
16643 /* second table for DMI checks that should run after early-quirks */
16644-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16645+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16646 /*
16647 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16648 * which includes some code which overrides all temperature
16649diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16650index ec94e11..7fbbec0 100644
16651--- a/arch/x86/kernel/acpi/sleep.c
16652+++ b/arch/x86/kernel/acpi/sleep.c
16653@@ -88,8 +88,12 @@ int acpi_suspend_lowlevel(void)
16654 #else /* CONFIG_64BIT */
16655 #ifdef CONFIG_SMP
16656 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16657+
16658+ pax_open_kernel();
16659 early_gdt_descr.address =
16660 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16661+ pax_close_kernel();
16662+
16663 initial_gs = per_cpu_offset(smp_processor_id());
16664 #endif
16665 initial_code = (unsigned long)wakeup_long64;
16666diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16667index d1daa66..59fecba 100644
16668--- a/arch/x86/kernel/acpi/wakeup_32.S
16669+++ b/arch/x86/kernel/acpi/wakeup_32.S
16670@@ -29,13 +29,11 @@ wakeup_pmode_return:
16671 # and restore the stack ... but you need gdt for this to work
16672 movl saved_context_esp, %esp
16673
16674- movl %cs:saved_magic, %eax
16675- cmpl $0x12345678, %eax
16676+ cmpl $0x12345678, saved_magic
16677 jne bogus_magic
16678
16679 # jump to place where we left off
16680- movl saved_eip, %eax
16681- jmp *%eax
16682+ jmp *(saved_eip)
16683
16684 bogus_magic:
16685 jmp bogus_magic
16686diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16687index c15cf9a..0e63558 100644
16688--- a/arch/x86/kernel/alternative.c
16689+++ b/arch/x86/kernel/alternative.c
16690@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16691 */
16692 for (a = start; a < end; a++) {
16693 instr = (u8 *)&a->instr_offset + a->instr_offset;
16694+
16695+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16696+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16697+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16698+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16699+#endif
16700+
16701 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16702 BUG_ON(a->replacementlen > a->instrlen);
16703 BUG_ON(a->instrlen > sizeof(insnbuf));
16704@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16705 for (poff = start; poff < end; poff++) {
16706 u8 *ptr = (u8 *)poff + *poff;
16707
16708+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16709+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16710+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16711+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16712+#endif
16713+
16714 if (!*poff || ptr < text || ptr >= text_end)
16715 continue;
16716 /* turn DS segment override prefix into lock prefix */
16717- if (*ptr == 0x3e)
16718+ if (*ktla_ktva(ptr) == 0x3e)
16719 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16720 }
16721 mutex_unlock(&text_mutex);
16722@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16723 for (poff = start; poff < end; poff++) {
16724 u8 *ptr = (u8 *)poff + *poff;
16725
16726+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16727+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16728+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16729+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16730+#endif
16731+
16732 if (!*poff || ptr < text || ptr >= text_end)
16733 continue;
16734 /* turn lock prefix into DS segment override prefix */
16735- if (*ptr == 0xf0)
16736+ if (*ktla_ktva(ptr) == 0xf0)
16737 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16738 }
16739 mutex_unlock(&text_mutex);
16740@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16741
16742 BUG_ON(p->len > MAX_PATCH_LEN);
16743 /* prep the buffer with the original instructions */
16744- memcpy(insnbuf, p->instr, p->len);
16745+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16746 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16747 (unsigned long)p->instr, p->len);
16748
16749@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16750 if (!uniproc_patched || num_possible_cpus() == 1)
16751 free_init_pages("SMP alternatives",
16752 (unsigned long)__smp_locks,
16753- (unsigned long)__smp_locks_end);
16754+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16755 #endif
16756
16757 apply_paravirt(__parainstructions, __parainstructions_end);
16758@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16759 * instructions. And on the local CPU you need to be protected again NMI or MCE
16760 * handlers seeing an inconsistent instruction while you patch.
16761 */
16762-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16763+void *__kprobes text_poke_early(void *addr, const void *opcode,
16764 size_t len)
16765 {
16766 unsigned long flags;
16767 local_irq_save(flags);
16768- memcpy(addr, opcode, len);
16769+
16770+ pax_open_kernel();
16771+ memcpy(ktla_ktva(addr), opcode, len);
16772 sync_core();
16773+ pax_close_kernel();
16774+
16775 local_irq_restore(flags);
16776 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16777 that causes hangs on some VIA CPUs. */
16778@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16779 */
16780 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16781 {
16782- unsigned long flags;
16783- char *vaddr;
16784+ unsigned char *vaddr = ktla_ktva(addr);
16785 struct page *pages[2];
16786- int i;
16787+ size_t i;
16788
16789 if (!core_kernel_text((unsigned long)addr)) {
16790- pages[0] = vmalloc_to_page(addr);
16791- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16792+ pages[0] = vmalloc_to_page(vaddr);
16793+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16794 } else {
16795- pages[0] = virt_to_page(addr);
16796+ pages[0] = virt_to_page(vaddr);
16797 WARN_ON(!PageReserved(pages[0]));
16798- pages[1] = virt_to_page(addr + PAGE_SIZE);
16799+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16800 }
16801 BUG_ON(!pages[0]);
16802- local_irq_save(flags);
16803- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16804- if (pages[1])
16805- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16806- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16807- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16808- clear_fixmap(FIX_TEXT_POKE0);
16809- if (pages[1])
16810- clear_fixmap(FIX_TEXT_POKE1);
16811- local_flush_tlb();
16812- sync_core();
16813- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16814- that causes hangs on some VIA CPUs. */
16815+ text_poke_early(addr, opcode, len);
16816 for (i = 0; i < len; i++)
16817- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16818- local_irq_restore(flags);
16819+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16820 return addr;
16821 }
16822
16823diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16824index 904611b..004dde6 100644
16825--- a/arch/x86/kernel/apic/apic.c
16826+++ b/arch/x86/kernel/apic/apic.c
16827@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16828 /*
16829 * Debug level, exported for io_apic.c
16830 */
16831-unsigned int apic_verbosity;
16832+int apic_verbosity;
16833
16834 int pic_mode;
16835
16836@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16837 apic_write(APIC_ESR, 0);
16838 v1 = apic_read(APIC_ESR);
16839 ack_APIC_irq();
16840- atomic_inc(&irq_err_count);
16841+ atomic_inc_unchecked(&irq_err_count);
16842
16843 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16844 smp_processor_id(), v0 , v1);
16845diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16846index 00c77cf..2dc6a2d 100644
16847--- a/arch/x86/kernel/apic/apic_flat_64.c
16848+++ b/arch/x86/kernel/apic/apic_flat_64.c
16849@@ -157,7 +157,7 @@ static int flat_probe(void)
16850 return 1;
16851 }
16852
16853-static struct apic apic_flat = {
16854+static struct apic apic_flat __read_only = {
16855 .name = "flat",
16856 .probe = flat_probe,
16857 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16858@@ -271,7 +271,7 @@ static int physflat_probe(void)
16859 return 0;
16860 }
16861
16862-static struct apic apic_physflat = {
16863+static struct apic apic_physflat __read_only = {
16864
16865 .name = "physical flat",
16866 .probe = physflat_probe,
16867diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16868index e145f28..2752888 100644
16869--- a/arch/x86/kernel/apic/apic_noop.c
16870+++ b/arch/x86/kernel/apic/apic_noop.c
16871@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16872 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16873 }
16874
16875-struct apic apic_noop = {
16876+struct apic apic_noop __read_only = {
16877 .name = "noop",
16878 .probe = noop_probe,
16879 .acpi_madt_oem_check = NULL,
16880diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16881index d50e364..543bee3 100644
16882--- a/arch/x86/kernel/apic/bigsmp_32.c
16883+++ b/arch/x86/kernel/apic/bigsmp_32.c
16884@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16885 return dmi_bigsmp;
16886 }
16887
16888-static struct apic apic_bigsmp = {
16889+static struct apic apic_bigsmp __read_only = {
16890
16891 .name = "bigsmp",
16892 .probe = probe_bigsmp,
16893diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16894index 0874799..a7a7892 100644
16895--- a/arch/x86/kernel/apic/es7000_32.c
16896+++ b/arch/x86/kernel/apic/es7000_32.c
16897@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16898 return ret && es7000_apic_is_cluster();
16899 }
16900
16901-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16902-static struct apic __refdata apic_es7000_cluster = {
16903+static struct apic apic_es7000_cluster __read_only = {
16904
16905 .name = "es7000",
16906 .probe = probe_es7000,
16907@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16908 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16909 };
16910
16911-static struct apic __refdata apic_es7000 = {
16912+static struct apic apic_es7000 __read_only = {
16913
16914 .name = "es7000",
16915 .probe = probe_es7000,
16916diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16917index 9ed796c..e930fe4 100644
16918--- a/arch/x86/kernel/apic/io_apic.c
16919+++ b/arch/x86/kernel/apic/io_apic.c
16920@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16921 }
16922 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16923
16924-void lock_vector_lock(void)
16925+void lock_vector_lock(void) __acquires(vector_lock)
16926 {
16927 /* Used to the online set of cpus does not change
16928 * during assign_irq_vector.
16929@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
16930 raw_spin_lock(&vector_lock);
16931 }
16932
16933-void unlock_vector_lock(void)
16934+void unlock_vector_lock(void) __releases(vector_lock)
16935 {
16936 raw_spin_unlock(&vector_lock);
16937 }
16938@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
16939 ack_APIC_irq();
16940 }
16941
16942-atomic_t irq_mis_count;
16943+atomic_unchecked_t irq_mis_count;
16944
16945 #ifdef CONFIG_GENERIC_PENDING_IRQ
16946 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16947@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
16948 * at the cpu.
16949 */
16950 if (!(v & (1 << (i & 0x1f)))) {
16951- atomic_inc(&irq_mis_count);
16952+ atomic_inc_unchecked(&irq_mis_count);
16953
16954 eoi_ioapic_irq(irq, cfg);
16955 }
16956diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16957index d661ee9..791fd33 100644
16958--- a/arch/x86/kernel/apic/numaq_32.c
16959+++ b/arch/x86/kernel/apic/numaq_32.c
16960@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16961 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16962 }
16963
16964-/* Use __refdata to keep false positive warning calm. */
16965-static struct apic __refdata apic_numaq = {
16966+static struct apic apic_numaq __read_only = {
16967
16968 .name = "NUMAQ",
16969 .probe = probe_numaq,
16970diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16971index eb35ef9..f184a21 100644
16972--- a/arch/x86/kernel/apic/probe_32.c
16973+++ b/arch/x86/kernel/apic/probe_32.c
16974@@ -72,7 +72,7 @@ static int probe_default(void)
16975 return 1;
16976 }
16977
16978-static struct apic apic_default = {
16979+static struct apic apic_default __read_only = {
16980
16981 .name = "default",
16982 .probe = probe_default,
16983diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16984index 77c95c0..434f8a4 100644
16985--- a/arch/x86/kernel/apic/summit_32.c
16986+++ b/arch/x86/kernel/apic/summit_32.c
16987@@ -486,7 +486,7 @@ void setup_summit(void)
16988 }
16989 #endif
16990
16991-static struct apic apic_summit = {
16992+static struct apic apic_summit __read_only = {
16993
16994 .name = "summit",
16995 .probe = probe_summit,
16996diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16997index c88baa4..757aee1 100644
16998--- a/arch/x86/kernel/apic/x2apic_cluster.c
16999+++ b/arch/x86/kernel/apic/x2apic_cluster.c
17000@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
17001 return notifier_from_errno(err);
17002 }
17003
17004-static struct notifier_block __refdata x2apic_cpu_notifier = {
17005+static struct notifier_block x2apic_cpu_notifier = {
17006 .notifier_call = update_clusterinfo,
17007 };
17008
17009@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
17010 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
17011 }
17012
17013-static struct apic apic_x2apic_cluster = {
17014+static struct apic apic_x2apic_cluster __read_only = {
17015
17016 .name = "cluster x2apic",
17017 .probe = x2apic_cluster_probe,
17018diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
17019index 562a76d..a003c0f 100644
17020--- a/arch/x86/kernel/apic/x2apic_phys.c
17021+++ b/arch/x86/kernel/apic/x2apic_phys.c
17022@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
17023 return apic == &apic_x2apic_phys;
17024 }
17025
17026-static struct apic apic_x2apic_phys = {
17027+static struct apic apic_x2apic_phys __read_only = {
17028
17029 .name = "physical x2apic",
17030 .probe = x2apic_phys_probe,
17031diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17032index 794f6eb..67e1db2 100644
17033--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17034+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17035@@ -342,7 +342,7 @@ static int uv_probe(void)
17036 return apic == &apic_x2apic_uv_x;
17037 }
17038
17039-static struct apic __refdata apic_x2apic_uv_x = {
17040+static struct apic apic_x2apic_uv_x __read_only = {
17041
17042 .name = "UV large system",
17043 .probe = uv_probe,
17044diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17045index 53a4e27..038760a 100644
17046--- a/arch/x86/kernel/apm_32.c
17047+++ b/arch/x86/kernel/apm_32.c
17048@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
17049 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17050 * even though they are called in protected mode.
17051 */
17052-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17053+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17054 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17055
17056 static const char driver_version[] = "1.16ac"; /* no spaces */
17057@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
17058 BUG_ON(cpu != 0);
17059 gdt = get_cpu_gdt_table(cpu);
17060 save_desc_40 = gdt[0x40 / 8];
17061+
17062+ pax_open_kernel();
17063 gdt[0x40 / 8] = bad_bios_desc;
17064+ pax_close_kernel();
17065
17066 apm_irq_save(flags);
17067 APM_DO_SAVE_SEGS;
17068@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
17069 &call->esi);
17070 APM_DO_RESTORE_SEGS;
17071 apm_irq_restore(flags);
17072+
17073+ pax_open_kernel();
17074 gdt[0x40 / 8] = save_desc_40;
17075+ pax_close_kernel();
17076+
17077 put_cpu();
17078
17079 return call->eax & 0xff;
17080@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
17081 BUG_ON(cpu != 0);
17082 gdt = get_cpu_gdt_table(cpu);
17083 save_desc_40 = gdt[0x40 / 8];
17084+
17085+ pax_open_kernel();
17086 gdt[0x40 / 8] = bad_bios_desc;
17087+ pax_close_kernel();
17088
17089 apm_irq_save(flags);
17090 APM_DO_SAVE_SEGS;
17091@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
17092 &call->eax);
17093 APM_DO_RESTORE_SEGS;
17094 apm_irq_restore(flags);
17095+
17096+ pax_open_kernel();
17097 gdt[0x40 / 8] = save_desc_40;
17098+ pax_close_kernel();
17099+
17100 put_cpu();
17101 return error;
17102 }
17103@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
17104 * code to that CPU.
17105 */
17106 gdt = get_cpu_gdt_table(0);
17107+
17108+ pax_open_kernel();
17109 set_desc_base(&gdt[APM_CS >> 3],
17110 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17111 set_desc_base(&gdt[APM_CS_16 >> 3],
17112 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17113 set_desc_base(&gdt[APM_DS >> 3],
17114 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17115+ pax_close_kernel();
17116
17117 proc_create("apm", 0, NULL, &apm_file_ops);
17118
17119diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17120index 2861082..6d4718e 100644
17121--- a/arch/x86/kernel/asm-offsets.c
17122+++ b/arch/x86/kernel/asm-offsets.c
17123@@ -33,6 +33,8 @@ void common(void) {
17124 OFFSET(TI_status, thread_info, status);
17125 OFFSET(TI_addr_limit, thread_info, addr_limit);
17126 OFFSET(TI_preempt_count, thread_info, preempt_count);
17127+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17128+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17129
17130 BLANK();
17131 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17132@@ -53,8 +55,26 @@ void common(void) {
17133 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17134 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17135 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17136+
17137+#ifdef CONFIG_PAX_KERNEXEC
17138+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17139 #endif
17140
17141+#ifdef CONFIG_PAX_MEMORY_UDEREF
17142+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17143+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17144+#ifdef CONFIG_X86_64
17145+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17146+#endif
17147+#endif
17148+
17149+#endif
17150+
17151+ BLANK();
17152+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17153+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17154+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17155+
17156 #ifdef CONFIG_XEN
17157 BLANK();
17158 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17159diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17160index e7c798b..2b2019b 100644
17161--- a/arch/x86/kernel/asm-offsets_64.c
17162+++ b/arch/x86/kernel/asm-offsets_64.c
17163@@ -77,6 +77,7 @@ int main(void)
17164 BLANK();
17165 #undef ENTRY
17166
17167+ DEFINE(TSS_size, sizeof(struct tss_struct));
17168 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17169 BLANK();
17170
17171diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17172index b0684e4..22ccfd7 100644
17173--- a/arch/x86/kernel/cpu/Makefile
17174+++ b/arch/x86/kernel/cpu/Makefile
17175@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17176 CFLAGS_REMOVE_perf_event.o = -pg
17177 endif
17178
17179-# Make sure load_percpu_segment has no stackprotector
17180-nostackp := $(call cc-option, -fno-stack-protector)
17181-CFLAGS_common.o := $(nostackp)
17182-
17183 obj-y := intel_cacheinfo.o scattered.o topology.o
17184 obj-y += proc.o capflags.o powerflags.o common.o
17185 obj-y += rdrand.o
17186diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17187index 5013a48..0782c53 100644
17188--- a/arch/x86/kernel/cpu/amd.c
17189+++ b/arch/x86/kernel/cpu/amd.c
17190@@ -744,7 +744,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17191 unsigned int size)
17192 {
17193 /* AMD errata T13 (order #21922) */
17194- if ((c->x86 == 6)) {
17195+ if (c->x86 == 6) {
17196 /* Duron Rev A0 */
17197 if (c->x86_model == 3 && c->x86_mask == 0)
17198 size = 64;
17199diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17200index 22018f7..bc6f5e3 100644
17201--- a/arch/x86/kernel/cpu/common.c
17202+++ b/arch/x86/kernel/cpu/common.c
17203@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17204
17205 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17206
17207-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17208-#ifdef CONFIG_X86_64
17209- /*
17210- * We need valid kernel segments for data and code in long mode too
17211- * IRET will check the segment types kkeil 2000/10/28
17212- * Also sysret mandates a special GDT layout
17213- *
17214- * TLS descriptors are currently at a different place compared to i386.
17215- * Hopefully nobody expects them at a fixed place (Wine?)
17216- */
17217- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17218- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17219- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17220- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17221- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17222- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17223-#else
17224- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17225- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17226- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17227- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17228- /*
17229- * Segments used for calling PnP BIOS have byte granularity.
17230- * They code segments and data segments have fixed 64k limits,
17231- * the transfer segment sizes are set at run time.
17232- */
17233- /* 32-bit code */
17234- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17235- /* 16-bit code */
17236- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17237- /* 16-bit data */
17238- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17239- /* 16-bit data */
17240- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17241- /* 16-bit data */
17242- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17243- /*
17244- * The APM segments have byte granularity and their bases
17245- * are set at run time. All have 64k limits.
17246- */
17247- /* 32-bit code */
17248- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17249- /* 16-bit code */
17250- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17251- /* data */
17252- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17253-
17254- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17255- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17256- GDT_STACK_CANARY_INIT
17257-#endif
17258-} };
17259-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17260-
17261 static int __init x86_xsave_setup(char *s)
17262 {
17263 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17264@@ -386,7 +332,7 @@ void switch_to_new_gdt(int cpu)
17265 {
17266 struct desc_ptr gdt_descr;
17267
17268- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17269+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17270 gdt_descr.size = GDT_SIZE - 1;
17271 load_gdt(&gdt_descr);
17272 /* Reload the per-cpu base */
17273@@ -882,6 +828,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17274 /* Filter out anything that depends on CPUID levels we don't have */
17275 filter_cpuid_features(c, true);
17276
17277+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17278+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17279+#endif
17280+
17281 /* If the model name is still unset, do table lookup. */
17282 if (!c->x86_model_id[0]) {
17283 const char *p;
17284@@ -1069,10 +1019,12 @@ static __init int setup_disablecpuid(char *arg)
17285 }
17286 __setup("clearcpuid=", setup_disablecpuid);
17287
17288+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17289+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17290+
17291 #ifdef CONFIG_X86_64
17292 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17293-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17294- (unsigned long) nmi_idt_table };
17295+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17296
17297 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17298 irq_stack_union) __aligned(PAGE_SIZE);
17299@@ -1086,7 +1038,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17300 EXPORT_PER_CPU_SYMBOL(current_task);
17301
17302 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17303- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17304+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17305 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17306
17307 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17308@@ -1231,7 +1183,7 @@ void __cpuinit cpu_init(void)
17309 load_ucode_ap();
17310
17311 cpu = stack_smp_processor_id();
17312- t = &per_cpu(init_tss, cpu);
17313+ t = init_tss + cpu;
17314 oist = &per_cpu(orig_ist, cpu);
17315
17316 #ifdef CONFIG_NUMA
17317@@ -1257,7 +1209,7 @@ void __cpuinit cpu_init(void)
17318 switch_to_new_gdt(cpu);
17319 loadsegment(fs, 0);
17320
17321- load_idt((const struct desc_ptr *)&idt_descr);
17322+ load_idt(&idt_descr);
17323
17324 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17325 syscall_init();
17326@@ -1266,7 +1218,6 @@ void __cpuinit cpu_init(void)
17327 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17328 barrier();
17329
17330- x86_configure_nx();
17331 enable_x2apic();
17332
17333 /*
17334@@ -1318,7 +1269,7 @@ void __cpuinit cpu_init(void)
17335 {
17336 int cpu = smp_processor_id();
17337 struct task_struct *curr = current;
17338- struct tss_struct *t = &per_cpu(init_tss, cpu);
17339+ struct tss_struct *t = init_tss + cpu;
17340 struct thread_struct *thread = &curr->thread;
17341
17342 show_ucode_info_early();
17343diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17344index 7c6f7d5..8cac382 100644
17345--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17346+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17347@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17348 };
17349
17350 #ifdef CONFIG_AMD_NB
17351+static struct attribute *default_attrs_amd_nb[] = {
17352+ &type.attr,
17353+ &level.attr,
17354+ &coherency_line_size.attr,
17355+ &physical_line_partition.attr,
17356+ &ways_of_associativity.attr,
17357+ &number_of_sets.attr,
17358+ &size.attr,
17359+ &shared_cpu_map.attr,
17360+ &shared_cpu_list.attr,
17361+ NULL,
17362+ NULL,
17363+ NULL,
17364+ NULL
17365+};
17366+
17367 static struct attribute ** __cpuinit amd_l3_attrs(void)
17368 {
17369 static struct attribute **attrs;
17370@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17371
17372 n = ARRAY_SIZE(default_attrs);
17373
17374- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17375- n += 2;
17376-
17377- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17378- n += 1;
17379-
17380- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17381- if (attrs == NULL)
17382- return attrs = default_attrs;
17383-
17384- for (n = 0; default_attrs[n]; n++)
17385- attrs[n] = default_attrs[n];
17386+ attrs = default_attrs_amd_nb;
17387
17388 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17389 attrs[n++] = &cache_disable_0.attr;
17390@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17391 .default_attrs = default_attrs,
17392 };
17393
17394+#ifdef CONFIG_AMD_NB
17395+static struct kobj_type ktype_cache_amd_nb = {
17396+ .sysfs_ops = &sysfs_ops,
17397+ .default_attrs = default_attrs_amd_nb,
17398+};
17399+#endif
17400+
17401 static struct kobj_type ktype_percpu_entry = {
17402 .sysfs_ops = &sysfs_ops,
17403 };
17404@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17405 return retval;
17406 }
17407
17408+#ifdef CONFIG_AMD_NB
17409+ amd_l3_attrs();
17410+#endif
17411+
17412 for (i = 0; i < num_cache_leaves; i++) {
17413+ struct kobj_type *ktype;
17414+
17415 this_object = INDEX_KOBJECT_PTR(cpu, i);
17416 this_object->cpu = cpu;
17417 this_object->index = i;
17418
17419 this_leaf = CPUID4_INFO_IDX(cpu, i);
17420
17421- ktype_cache.default_attrs = default_attrs;
17422+ ktype = &ktype_cache;
17423 #ifdef CONFIG_AMD_NB
17424 if (this_leaf->base.nb)
17425- ktype_cache.default_attrs = amd_l3_attrs();
17426+ ktype = &ktype_cache_amd_nb;
17427 #endif
17428 retval = kobject_init_and_add(&(this_object->kobj),
17429- &ktype_cache,
17430+ ktype,
17431 per_cpu(ici_cache_kobject, cpu),
17432 "index%1lu", i);
17433 if (unlikely(retval)) {
17434@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17435 return NOTIFY_OK;
17436 }
17437
17438-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17439+static struct notifier_block cacheinfo_cpu_notifier = {
17440 .notifier_call = cacheinfo_cpu_callback,
17441 };
17442
17443diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17444index 9239504..b2471ce 100644
17445--- a/arch/x86/kernel/cpu/mcheck/mce.c
17446+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17447@@ -45,6 +45,7 @@
17448 #include <asm/processor.h>
17449 #include <asm/mce.h>
17450 #include <asm/msr.h>
17451+#include <asm/local.h>
17452
17453 #include "mce-internal.h"
17454
17455@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17456 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17457 m->cs, m->ip);
17458
17459- if (m->cs == __KERNEL_CS)
17460+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17461 print_symbol("{%s}", m->ip);
17462 pr_cont("\n");
17463 }
17464@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17465
17466 #define PANIC_TIMEOUT 5 /* 5 seconds */
17467
17468-static atomic_t mce_paniced;
17469+static atomic_unchecked_t mce_paniced;
17470
17471 static int fake_panic;
17472-static atomic_t mce_fake_paniced;
17473+static atomic_unchecked_t mce_fake_paniced;
17474
17475 /* Panic in progress. Enable interrupts and wait for final IPI */
17476 static void wait_for_panic(void)
17477@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17478 /*
17479 * Make sure only one CPU runs in machine check panic
17480 */
17481- if (atomic_inc_return(&mce_paniced) > 1)
17482+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17483 wait_for_panic();
17484 barrier();
17485
17486@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17487 console_verbose();
17488 } else {
17489 /* Don't log too much for fake panic */
17490- if (atomic_inc_return(&mce_fake_paniced) > 1)
17491+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17492 return;
17493 }
17494 /* First print corrected ones that are still unlogged */
17495@@ -353,7 +354,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17496 if (!fake_panic) {
17497 if (panic_timeout == 0)
17498 panic_timeout = mca_cfg.panic_timeout;
17499- panic(msg);
17500+ panic("%s", msg);
17501 } else
17502 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
17503 }
17504@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
17505 * might have been modified by someone else.
17506 */
17507 rmb();
17508- if (atomic_read(&mce_paniced))
17509+ if (atomic_read_unchecked(&mce_paniced))
17510 wait_for_panic();
17511 if (!mca_cfg.monarch_timeout)
17512 goto out;
17513@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17514 }
17515
17516 /* Call the installed machine check handler for this CPU setup. */
17517-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17518+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17519 unexpected_machine_check;
17520
17521 /*
17522@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17523 return;
17524 }
17525
17526+ pax_open_kernel();
17527 machine_check_vector = do_machine_check;
17528+ pax_close_kernel();
17529
17530 __mcheck_cpu_init_generic();
17531 __mcheck_cpu_init_vendor(c);
17532@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17533 */
17534
17535 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17536-static int mce_chrdev_open_count; /* #times opened */
17537+static local_t mce_chrdev_open_count; /* #times opened */
17538 static int mce_chrdev_open_exclu; /* already open exclusive? */
17539
17540 static int mce_chrdev_open(struct inode *inode, struct file *file)
17541@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17542 spin_lock(&mce_chrdev_state_lock);
17543
17544 if (mce_chrdev_open_exclu ||
17545- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17546+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17547 spin_unlock(&mce_chrdev_state_lock);
17548
17549 return -EBUSY;
17550@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17551
17552 if (file->f_flags & O_EXCL)
17553 mce_chrdev_open_exclu = 1;
17554- mce_chrdev_open_count++;
17555+ local_inc(&mce_chrdev_open_count);
17556
17557 spin_unlock(&mce_chrdev_state_lock);
17558
17559@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17560 {
17561 spin_lock(&mce_chrdev_state_lock);
17562
17563- mce_chrdev_open_count--;
17564+ local_dec(&mce_chrdev_open_count);
17565 mce_chrdev_open_exclu = 0;
17566
17567 spin_unlock(&mce_chrdev_state_lock);
17568@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17569 return NOTIFY_OK;
17570 }
17571
17572-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17573+static struct notifier_block mce_cpu_notifier = {
17574 .notifier_call = mce_cpu_callback,
17575 };
17576
17577@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
17578
17579 for (i = 0; i < mca_cfg.banks; i++) {
17580 struct mce_bank *b = &mce_banks[i];
17581- struct device_attribute *a = &b->attr;
17582+ device_attribute_no_const *a = &b->attr;
17583
17584 sysfs_attr_init(&a->attr);
17585 a->attr.name = b->attrname;
17586@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
17587 static void mce_reset(void)
17588 {
17589 cpu_missing = 0;
17590- atomic_set(&mce_fake_paniced, 0);
17591+ atomic_set_unchecked(&mce_fake_paniced, 0);
17592 atomic_set(&mce_executing, 0);
17593 atomic_set(&mce_callin, 0);
17594 atomic_set(&global_nwo, 0);
17595diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17596index 1c044b1..37a2a43 100644
17597--- a/arch/x86/kernel/cpu/mcheck/p5.c
17598+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17599@@ -11,6 +11,7 @@
17600 #include <asm/processor.h>
17601 #include <asm/mce.h>
17602 #include <asm/msr.h>
17603+#include <asm/pgtable.h>
17604
17605 /* By default disabled */
17606 int mce_p5_enabled __read_mostly;
17607@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17608 if (!cpu_has(c, X86_FEATURE_MCE))
17609 return;
17610
17611+ pax_open_kernel();
17612 machine_check_vector = pentium_machine_check;
17613+ pax_close_kernel();
17614 /* Make sure the vector pointer is visible before we enable MCEs: */
17615 wmb();
17616
17617diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17618index 47a1870..8c019a7 100644
17619--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17620+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17621@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17622 return notifier_from_errno(err);
17623 }
17624
17625-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17626+static struct notifier_block thermal_throttle_cpu_notifier =
17627 {
17628 .notifier_call = thermal_throttle_cpu_callback,
17629 };
17630diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17631index e9a701a..35317d6 100644
17632--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17633+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17634@@ -10,6 +10,7 @@
17635 #include <asm/processor.h>
17636 #include <asm/mce.h>
17637 #include <asm/msr.h>
17638+#include <asm/pgtable.h>
17639
17640 /* Machine check handler for WinChip C6: */
17641 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17642@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17643 {
17644 u32 lo, hi;
17645
17646+ pax_open_kernel();
17647 machine_check_vector = winchip_machine_check;
17648+ pax_close_kernel();
17649 /* Make sure the vector pointer is visible before we enable MCEs: */
17650 wmb();
17651
17652diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17653index ca22b73..9987afe 100644
17654--- a/arch/x86/kernel/cpu/mtrr/main.c
17655+++ b/arch/x86/kernel/cpu/mtrr/main.c
17656@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17657 u64 size_or_mask, size_and_mask;
17658 static bool mtrr_aps_delayed_init;
17659
17660-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17661+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17662
17663 const struct mtrr_ops *mtrr_if;
17664
17665diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17666index df5e41f..816c719 100644
17667--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17668+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17669@@ -25,7 +25,7 @@ struct mtrr_ops {
17670 int (*validate_add_page)(unsigned long base, unsigned long size,
17671 unsigned int type);
17672 int (*have_wrcomb)(void);
17673-};
17674+} __do_const;
17675
17676 extern int generic_get_free_region(unsigned long base, unsigned long size,
17677 int replace_reg);
17678diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17679index 1025f3c..824f677 100644
17680--- a/arch/x86/kernel/cpu/perf_event.c
17681+++ b/arch/x86/kernel/cpu/perf_event.c
17682@@ -1311,7 +1311,7 @@ static void __init pmu_check_apic(void)
17683 pr_info("no hardware sampling interrupt available.\n");
17684 }
17685
17686-static struct attribute_group x86_pmu_format_group = {
17687+static attribute_group_no_const x86_pmu_format_group = {
17688 .name = "format",
17689 .attrs = NULL,
17690 };
17691@@ -1410,7 +1410,7 @@ static struct attribute *events_attr[] = {
17692 NULL,
17693 };
17694
17695-static struct attribute_group x86_pmu_events_group = {
17696+static attribute_group_no_const x86_pmu_events_group = {
17697 .name = "events",
17698 .attrs = events_attr,
17699 };
17700@@ -1920,7 +1920,7 @@ static unsigned long get_segment_base(unsigned int segment)
17701 if (idx > GDT_ENTRIES)
17702 return 0;
17703
17704- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17705+ desc = get_cpu_gdt_table(smp_processor_id());
17706 }
17707
17708 return get_desc_base(desc + idx);
17709@@ -2010,7 +2010,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17710 break;
17711
17712 perf_callchain_store(entry, frame.return_address);
17713- fp = frame.next_frame;
17714+ fp = (const void __force_user *)frame.next_frame;
17715 }
17716 }
17717
17718diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17719index a9e2207..d70c83a 100644
17720--- a/arch/x86/kernel/cpu/perf_event_intel.c
17721+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17722@@ -2022,10 +2022,10 @@ __init int intel_pmu_init(void)
17723 * v2 and above have a perf capabilities MSR
17724 */
17725 if (version > 1) {
17726- u64 capabilities;
17727+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17728
17729- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17730- x86_pmu.intel_cap.capabilities = capabilities;
17731+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17732+ x86_pmu.intel_cap.capabilities = capabilities;
17733 }
17734
17735 intel_ds_init();
17736diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17737index 52441a2..f94fae8 100644
17738--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17739+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17740@@ -3093,7 +3093,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17741 static int __init uncore_type_init(struct intel_uncore_type *type)
17742 {
17743 struct intel_uncore_pmu *pmus;
17744- struct attribute_group *attr_group;
17745+ attribute_group_no_const *attr_group;
17746 struct attribute **attrs;
17747 int i, j;
17748
17749@@ -3518,7 +3518,7 @@ static int
17750 return NOTIFY_OK;
17751 }
17752
17753-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17754+static struct notifier_block uncore_cpu_nb = {
17755 .notifier_call = uncore_cpu_notifier,
17756 /*
17757 * to migrate uncore events, our notifier should be executed
17758diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17759index f952891..4722ad4 100644
17760--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17761+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17762@@ -488,7 +488,7 @@ struct intel_uncore_box {
17763 struct uncore_event_desc {
17764 struct kobj_attribute attr;
17765 const char *config;
17766-};
17767+} __do_const;
17768
17769 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17770 { \
17771diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17772index 1e4dbcf..b9a34c2 100644
17773--- a/arch/x86/kernel/cpuid.c
17774+++ b/arch/x86/kernel/cpuid.c
17775@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17776 return notifier_from_errno(err);
17777 }
17778
17779-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17780+static struct notifier_block cpuid_class_cpu_notifier =
17781 {
17782 .notifier_call = cpuid_class_cpu_callback,
17783 };
17784diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17785index 74467fe..18793d5 100644
17786--- a/arch/x86/kernel/crash.c
17787+++ b/arch/x86/kernel/crash.c
17788@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17789 {
17790 #ifdef CONFIG_X86_32
17791 struct pt_regs fixed_regs;
17792-#endif
17793
17794-#ifdef CONFIG_X86_32
17795- if (!user_mode_vm(regs)) {
17796+ if (!user_mode(regs)) {
17797 crash_fixup_ss_esp(&fixed_regs, regs);
17798 regs = &fixed_regs;
17799 }
17800diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
17801index afa64ad..dce67dd 100644
17802--- a/arch/x86/kernel/crash_dump_64.c
17803+++ b/arch/x86/kernel/crash_dump_64.c
17804@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
17805 return -ENOMEM;
17806
17807 if (userbuf) {
17808- if (copy_to_user(buf, vaddr + offset, csize)) {
17809+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
17810 iounmap(vaddr);
17811 return -EFAULT;
17812 }
17813diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17814index 155a13f..1672b9b 100644
17815--- a/arch/x86/kernel/doublefault_32.c
17816+++ b/arch/x86/kernel/doublefault_32.c
17817@@ -11,7 +11,7 @@
17818
17819 #define DOUBLEFAULT_STACKSIZE (1024)
17820 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17821-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17822+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17823
17824 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17825
17826@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17827 unsigned long gdt, tss;
17828
17829 native_store_gdt(&gdt_desc);
17830- gdt = gdt_desc.address;
17831+ gdt = (unsigned long)gdt_desc.address;
17832
17833 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17834
17835@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17836 /* 0x2 bit is always set */
17837 .flags = X86_EFLAGS_SF | 0x2,
17838 .sp = STACK_START,
17839- .es = __USER_DS,
17840+ .es = __KERNEL_DS,
17841 .cs = __KERNEL_CS,
17842 .ss = __KERNEL_DS,
17843- .ds = __USER_DS,
17844+ .ds = __KERNEL_DS,
17845 .fs = __KERNEL_PERCPU,
17846
17847 .__cr3 = __pa_nodebug(swapper_pg_dir),
17848diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17849index deb6421..76bbc12 100644
17850--- a/arch/x86/kernel/dumpstack.c
17851+++ b/arch/x86/kernel/dumpstack.c
17852@@ -2,6 +2,9 @@
17853 * Copyright (C) 1991, 1992 Linus Torvalds
17854 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17855 */
17856+#ifdef CONFIG_GRKERNSEC_HIDESYM
17857+#define __INCLUDED_BY_HIDESYM 1
17858+#endif
17859 #include <linux/kallsyms.h>
17860 #include <linux/kprobes.h>
17861 #include <linux/uaccess.h>
17862@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17863 static void
17864 print_ftrace_graph_addr(unsigned long addr, void *data,
17865 const struct stacktrace_ops *ops,
17866- struct thread_info *tinfo, int *graph)
17867+ struct task_struct *task, int *graph)
17868 {
17869- struct task_struct *task;
17870 unsigned long ret_addr;
17871 int index;
17872
17873 if (addr != (unsigned long)return_to_handler)
17874 return;
17875
17876- task = tinfo->task;
17877 index = task->curr_ret_stack;
17878
17879 if (!task->ret_stack || index < *graph)
17880@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17881 static inline void
17882 print_ftrace_graph_addr(unsigned long addr, void *data,
17883 const struct stacktrace_ops *ops,
17884- struct thread_info *tinfo, int *graph)
17885+ struct task_struct *task, int *graph)
17886 { }
17887 #endif
17888
17889@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17890 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17891 */
17892
17893-static inline int valid_stack_ptr(struct thread_info *tinfo,
17894- void *p, unsigned int size, void *end)
17895+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17896 {
17897- void *t = tinfo;
17898 if (end) {
17899 if (p < end && p >= (end-THREAD_SIZE))
17900 return 1;
17901@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17902 }
17903
17904 unsigned long
17905-print_context_stack(struct thread_info *tinfo,
17906+print_context_stack(struct task_struct *task, void *stack_start,
17907 unsigned long *stack, unsigned long bp,
17908 const struct stacktrace_ops *ops, void *data,
17909 unsigned long *end, int *graph)
17910 {
17911 struct stack_frame *frame = (struct stack_frame *)bp;
17912
17913- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17914+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17915 unsigned long addr;
17916
17917 addr = *stack;
17918@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17919 } else {
17920 ops->address(data, addr, 0);
17921 }
17922- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17923+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17924 }
17925 stack++;
17926 }
17927@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17928 EXPORT_SYMBOL_GPL(print_context_stack);
17929
17930 unsigned long
17931-print_context_stack_bp(struct thread_info *tinfo,
17932+print_context_stack_bp(struct task_struct *task, void *stack_start,
17933 unsigned long *stack, unsigned long bp,
17934 const struct stacktrace_ops *ops, void *data,
17935 unsigned long *end, int *graph)
17936@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17937 struct stack_frame *frame = (struct stack_frame *)bp;
17938 unsigned long *ret_addr = &frame->return_address;
17939
17940- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17941+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17942 unsigned long addr = *ret_addr;
17943
17944 if (!__kernel_text_address(addr))
17945@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17946 ops->address(data, addr, 1);
17947 frame = frame->next_frame;
17948 ret_addr = &frame->return_address;
17949- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17950+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17951 }
17952
17953 return (unsigned long)frame;
17954@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
17955 static void print_trace_address(void *data, unsigned long addr, int reliable)
17956 {
17957 touch_nmi_watchdog();
17958- printk(data);
17959+ printk("%s", (char *)data);
17960 printk_address(addr, reliable);
17961 }
17962
17963@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
17964 }
17965 EXPORT_SYMBOL_GPL(oops_begin);
17966
17967+extern void gr_handle_kernel_exploit(void);
17968+
17969 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17970 {
17971 if (regs && kexec_should_crash(current))
17972@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17973 panic("Fatal exception in interrupt");
17974 if (panic_on_oops)
17975 panic("Fatal exception");
17976- do_exit(signr);
17977+
17978+ gr_handle_kernel_exploit();
17979+
17980+ do_group_exit(signr);
17981 }
17982
17983 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17984@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17985 print_modules();
17986 show_regs(regs);
17987 #ifdef CONFIG_X86_32
17988- if (user_mode_vm(regs)) {
17989+ if (user_mode(regs)) {
17990 sp = regs->sp;
17991 ss = regs->ss & 0xffff;
17992 } else {
17993@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17994 unsigned long flags = oops_begin();
17995 int sig = SIGSEGV;
17996
17997- if (!user_mode_vm(regs))
17998+ if (!user_mode(regs))
17999 report_bug(regs->ip, regs);
18000
18001 if (__die(str, regs, err))
18002diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
18003index f2a1770..540657f 100644
18004--- a/arch/x86/kernel/dumpstack_32.c
18005+++ b/arch/x86/kernel/dumpstack_32.c
18006@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18007 bp = stack_frame(task, regs);
18008
18009 for (;;) {
18010- struct thread_info *context;
18011+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18012
18013- context = (struct thread_info *)
18014- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
18015- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
18016+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18017
18018- stack = (unsigned long *)context->previous_esp;
18019- if (!stack)
18020+ if (stack_start == task_stack_page(task))
18021 break;
18022+ stack = *(unsigned long **)stack_start;
18023 if (ops->stack(data, "IRQ") < 0)
18024 break;
18025 touch_nmi_watchdog();
18026@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
18027 int i;
18028
18029 show_regs_print_info(KERN_EMERG);
18030- __show_regs(regs, !user_mode_vm(regs));
18031+ __show_regs(regs, !user_mode(regs));
18032
18033 /*
18034 * When in-kernel, we also print out the stack and code at the
18035 * time of the fault..
18036 */
18037- if (!user_mode_vm(regs)) {
18038+ if (!user_mode(regs)) {
18039 unsigned int code_prologue = code_bytes * 43 / 64;
18040 unsigned int code_len = code_bytes;
18041 unsigned char c;
18042 u8 *ip;
18043+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18044
18045 pr_emerg("Stack:\n");
18046 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18047
18048 pr_emerg("Code:");
18049
18050- ip = (u8 *)regs->ip - code_prologue;
18051+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18052 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18053 /* try starting at IP */
18054- ip = (u8 *)regs->ip;
18055+ ip = (u8 *)regs->ip + cs_base;
18056 code_len = code_len - code_prologue + 1;
18057 }
18058 for (i = 0; i < code_len; i++, ip++) {
18059@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
18060 pr_cont(" Bad EIP value.");
18061 break;
18062 }
18063- if (ip == (u8 *)regs->ip)
18064+ if (ip == (u8 *)regs->ip + cs_base)
18065 pr_cont(" <%02x>", c);
18066 else
18067 pr_cont(" %02x", c);
18068@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
18069 {
18070 unsigned short ud2;
18071
18072+ ip = ktla_ktva(ip);
18073 if (ip < PAGE_OFFSET)
18074 return 0;
18075 if (probe_kernel_address((unsigned short *)ip, ud2))
18076@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
18077
18078 return ud2 == 0x0b0f;
18079 }
18080+
18081+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18082+void pax_check_alloca(unsigned long size)
18083+{
18084+ unsigned long sp = (unsigned long)&sp, stack_left;
18085+
18086+ /* all kernel stacks are of the same size */
18087+ stack_left = sp & (THREAD_SIZE - 1);
18088+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18089+}
18090+EXPORT_SYMBOL(pax_check_alloca);
18091+#endif
18092diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18093index addb207..99635fa 100644
18094--- a/arch/x86/kernel/dumpstack_64.c
18095+++ b/arch/x86/kernel/dumpstack_64.c
18096@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18097 unsigned long *irq_stack_end =
18098 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18099 unsigned used = 0;
18100- struct thread_info *tinfo;
18101 int graph = 0;
18102 unsigned long dummy;
18103+ void *stack_start;
18104
18105 if (!task)
18106 task = current;
18107@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18108 * current stack address. If the stacks consist of nested
18109 * exceptions
18110 */
18111- tinfo = task_thread_info(task);
18112 for (;;) {
18113 char *id;
18114 unsigned long *estack_end;
18115+
18116 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18117 &used, &id);
18118
18119@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18120 if (ops->stack(data, id) < 0)
18121 break;
18122
18123- bp = ops->walk_stack(tinfo, stack, bp, ops,
18124+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18125 data, estack_end, &graph);
18126 ops->stack(data, "<EOE>");
18127 /*
18128@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18129 * second-to-last pointer (index -2 to end) in the
18130 * exception stack:
18131 */
18132+ if ((u16)estack_end[-1] != __KERNEL_DS)
18133+ goto out;
18134 stack = (unsigned long *) estack_end[-2];
18135 continue;
18136 }
18137@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18138 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18139 if (ops->stack(data, "IRQ") < 0)
18140 break;
18141- bp = ops->walk_stack(tinfo, stack, bp,
18142+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18143 ops, data, irq_stack_end, &graph);
18144 /*
18145 * We link to the next stack (which would be
18146@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18147 /*
18148 * This handles the process stack:
18149 */
18150- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18151+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18152+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18153+out:
18154 put_cpu();
18155 }
18156 EXPORT_SYMBOL(dump_trace);
18157@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
18158
18159 return ud2 == 0x0b0f;
18160 }
18161+
18162+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18163+void pax_check_alloca(unsigned long size)
18164+{
18165+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18166+ unsigned cpu, used;
18167+ char *id;
18168+
18169+ /* check the process stack first */
18170+ stack_start = (unsigned long)task_stack_page(current);
18171+ stack_end = stack_start + THREAD_SIZE;
18172+ if (likely(stack_start <= sp && sp < stack_end)) {
18173+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18174+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18175+ return;
18176+ }
18177+
18178+ cpu = get_cpu();
18179+
18180+ /* check the irq stacks */
18181+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18182+ stack_start = stack_end - IRQ_STACK_SIZE;
18183+ if (stack_start <= sp && sp < stack_end) {
18184+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18185+ put_cpu();
18186+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18187+ return;
18188+ }
18189+
18190+ /* check the exception stacks */
18191+ used = 0;
18192+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18193+ stack_start = stack_end - EXCEPTION_STKSZ;
18194+ if (stack_end && stack_start <= sp && sp < stack_end) {
18195+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18196+ put_cpu();
18197+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18198+ return;
18199+ }
18200+
18201+ put_cpu();
18202+
18203+ /* unknown stack */
18204+ BUG();
18205+}
18206+EXPORT_SYMBOL(pax_check_alloca);
18207+#endif
18208diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
18209index d32abea..74daf4f 100644
18210--- a/arch/x86/kernel/e820.c
18211+++ b/arch/x86/kernel/e820.c
18212@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
18213
18214 static void early_panic(char *msg)
18215 {
18216- early_printk(msg);
18217- panic(msg);
18218+ early_printk("%s", msg);
18219+ panic("%s", msg);
18220 }
18221
18222 static int userdef __initdata;
18223diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18224index d15f575..d692043 100644
18225--- a/arch/x86/kernel/early_printk.c
18226+++ b/arch/x86/kernel/early_printk.c
18227@@ -7,6 +7,7 @@
18228 #include <linux/pci_regs.h>
18229 #include <linux/pci_ids.h>
18230 #include <linux/errno.h>
18231+#include <linux/sched.h>
18232 #include <asm/io.h>
18233 #include <asm/processor.h>
18234 #include <asm/fcntl.h>
18235diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18236index 8f3e2de..caecc4e 100644
18237--- a/arch/x86/kernel/entry_32.S
18238+++ b/arch/x86/kernel/entry_32.S
18239@@ -177,13 +177,153 @@
18240 /*CFI_REL_OFFSET gs, PT_GS*/
18241 .endm
18242 .macro SET_KERNEL_GS reg
18243+
18244+#ifdef CONFIG_CC_STACKPROTECTOR
18245 movl $(__KERNEL_STACK_CANARY), \reg
18246+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18247+ movl $(__USER_DS), \reg
18248+#else
18249+ xorl \reg, \reg
18250+#endif
18251+
18252 movl \reg, %gs
18253 .endm
18254
18255 #endif /* CONFIG_X86_32_LAZY_GS */
18256
18257-.macro SAVE_ALL
18258+.macro pax_enter_kernel
18259+#ifdef CONFIG_PAX_KERNEXEC
18260+ call pax_enter_kernel
18261+#endif
18262+.endm
18263+
18264+.macro pax_exit_kernel
18265+#ifdef CONFIG_PAX_KERNEXEC
18266+ call pax_exit_kernel
18267+#endif
18268+.endm
18269+
18270+#ifdef CONFIG_PAX_KERNEXEC
18271+ENTRY(pax_enter_kernel)
18272+#ifdef CONFIG_PARAVIRT
18273+ pushl %eax
18274+ pushl %ecx
18275+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18276+ mov %eax, %esi
18277+#else
18278+ mov %cr0, %esi
18279+#endif
18280+ bts $16, %esi
18281+ jnc 1f
18282+ mov %cs, %esi
18283+ cmp $__KERNEL_CS, %esi
18284+ jz 3f
18285+ ljmp $__KERNEL_CS, $3f
18286+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18287+2:
18288+#ifdef CONFIG_PARAVIRT
18289+ mov %esi, %eax
18290+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18291+#else
18292+ mov %esi, %cr0
18293+#endif
18294+3:
18295+#ifdef CONFIG_PARAVIRT
18296+ popl %ecx
18297+ popl %eax
18298+#endif
18299+ ret
18300+ENDPROC(pax_enter_kernel)
18301+
18302+ENTRY(pax_exit_kernel)
18303+#ifdef CONFIG_PARAVIRT
18304+ pushl %eax
18305+ pushl %ecx
18306+#endif
18307+ mov %cs, %esi
18308+ cmp $__KERNEXEC_KERNEL_CS, %esi
18309+ jnz 2f
18310+#ifdef CONFIG_PARAVIRT
18311+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18312+ mov %eax, %esi
18313+#else
18314+ mov %cr0, %esi
18315+#endif
18316+ btr $16, %esi
18317+ ljmp $__KERNEL_CS, $1f
18318+1:
18319+#ifdef CONFIG_PARAVIRT
18320+ mov %esi, %eax
18321+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18322+#else
18323+ mov %esi, %cr0
18324+#endif
18325+2:
18326+#ifdef CONFIG_PARAVIRT
18327+ popl %ecx
18328+ popl %eax
18329+#endif
18330+ ret
18331+ENDPROC(pax_exit_kernel)
18332+#endif
18333+
18334+ .macro pax_erase_kstack
18335+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18336+ call pax_erase_kstack
18337+#endif
18338+ .endm
18339+
18340+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18341+/*
18342+ * ebp: thread_info
18343+ */
18344+ENTRY(pax_erase_kstack)
18345+ pushl %edi
18346+ pushl %ecx
18347+ pushl %eax
18348+
18349+ mov TI_lowest_stack(%ebp), %edi
18350+ mov $-0xBEEF, %eax
18351+ std
18352+
18353+1: mov %edi, %ecx
18354+ and $THREAD_SIZE_asm - 1, %ecx
18355+ shr $2, %ecx
18356+ repne scasl
18357+ jecxz 2f
18358+
18359+ cmp $2*16, %ecx
18360+ jc 2f
18361+
18362+ mov $2*16, %ecx
18363+ repe scasl
18364+ jecxz 2f
18365+ jne 1b
18366+
18367+2: cld
18368+ mov %esp, %ecx
18369+ sub %edi, %ecx
18370+
18371+ cmp $THREAD_SIZE_asm, %ecx
18372+ jb 3f
18373+ ud2
18374+3:
18375+
18376+ shr $2, %ecx
18377+ rep stosl
18378+
18379+ mov TI_task_thread_sp0(%ebp), %edi
18380+ sub $128, %edi
18381+ mov %edi, TI_lowest_stack(%ebp)
18382+
18383+ popl %eax
18384+ popl %ecx
18385+ popl %edi
18386+ ret
18387+ENDPROC(pax_erase_kstack)
18388+#endif
18389+
18390+.macro __SAVE_ALL _DS
18391 cld
18392 PUSH_GS
18393 pushl_cfi %fs
18394@@ -206,7 +346,7 @@
18395 CFI_REL_OFFSET ecx, 0
18396 pushl_cfi %ebx
18397 CFI_REL_OFFSET ebx, 0
18398- movl $(__USER_DS), %edx
18399+ movl $\_DS, %edx
18400 movl %edx, %ds
18401 movl %edx, %es
18402 movl $(__KERNEL_PERCPU), %edx
18403@@ -214,6 +354,15 @@
18404 SET_KERNEL_GS %edx
18405 .endm
18406
18407+.macro SAVE_ALL
18408+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18409+ __SAVE_ALL __KERNEL_DS
18410+ pax_enter_kernel
18411+#else
18412+ __SAVE_ALL __USER_DS
18413+#endif
18414+.endm
18415+
18416 .macro RESTORE_INT_REGS
18417 popl_cfi %ebx
18418 CFI_RESTORE ebx
18419@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18420 popfl_cfi
18421 jmp syscall_exit
18422 CFI_ENDPROC
18423-END(ret_from_fork)
18424+ENDPROC(ret_from_fork)
18425
18426 ENTRY(ret_from_kernel_thread)
18427 CFI_STARTPROC
18428@@ -344,7 +493,15 @@ ret_from_intr:
18429 andl $SEGMENT_RPL_MASK, %eax
18430 #endif
18431 cmpl $USER_RPL, %eax
18432+
18433+#ifdef CONFIG_PAX_KERNEXEC
18434+ jae resume_userspace
18435+
18436+ pax_exit_kernel
18437+ jmp resume_kernel
18438+#else
18439 jb resume_kernel # not returning to v8086 or userspace
18440+#endif
18441
18442 ENTRY(resume_userspace)
18443 LOCKDEP_SYS_EXIT
18444@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18445 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18446 # int/exception return?
18447 jne work_pending
18448- jmp restore_all
18449-END(ret_from_exception)
18450+ jmp restore_all_pax
18451+ENDPROC(ret_from_exception)
18452
18453 #ifdef CONFIG_PREEMPT
18454 ENTRY(resume_kernel)
18455@@ -372,7 +529,7 @@ need_resched:
18456 jz restore_all
18457 call preempt_schedule_irq
18458 jmp need_resched
18459-END(resume_kernel)
18460+ENDPROC(resume_kernel)
18461 #endif
18462 CFI_ENDPROC
18463 /*
18464@@ -406,30 +563,45 @@ sysenter_past_esp:
18465 /*CFI_REL_OFFSET cs, 0*/
18466 /*
18467 * Push current_thread_info()->sysenter_return to the stack.
18468- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18469- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18470 */
18471- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18472+ pushl_cfi $0
18473 CFI_REL_OFFSET eip, 0
18474
18475 pushl_cfi %eax
18476 SAVE_ALL
18477+ GET_THREAD_INFO(%ebp)
18478+ movl TI_sysenter_return(%ebp),%ebp
18479+ movl %ebp,PT_EIP(%esp)
18480 ENABLE_INTERRUPTS(CLBR_NONE)
18481
18482 /*
18483 * Load the potential sixth argument from user stack.
18484 * Careful about security.
18485 */
18486+ movl PT_OLDESP(%esp),%ebp
18487+
18488+#ifdef CONFIG_PAX_MEMORY_UDEREF
18489+ mov PT_OLDSS(%esp),%ds
18490+1: movl %ds:(%ebp),%ebp
18491+ push %ss
18492+ pop %ds
18493+#else
18494 cmpl $__PAGE_OFFSET-3,%ebp
18495 jae syscall_fault
18496 ASM_STAC
18497 1: movl (%ebp),%ebp
18498 ASM_CLAC
18499+#endif
18500+
18501 movl %ebp,PT_EBP(%esp)
18502 _ASM_EXTABLE(1b,syscall_fault)
18503
18504 GET_THREAD_INFO(%ebp)
18505
18506+#ifdef CONFIG_PAX_RANDKSTACK
18507+ pax_erase_kstack
18508+#endif
18509+
18510 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18511 jnz sysenter_audit
18512 sysenter_do_call:
18513@@ -444,12 +616,24 @@ sysenter_do_call:
18514 testl $_TIF_ALLWORK_MASK, %ecx
18515 jne sysexit_audit
18516 sysenter_exit:
18517+
18518+#ifdef CONFIG_PAX_RANDKSTACK
18519+ pushl_cfi %eax
18520+ movl %esp, %eax
18521+ call pax_randomize_kstack
18522+ popl_cfi %eax
18523+#endif
18524+
18525+ pax_erase_kstack
18526+
18527 /* if something modifies registers it must also disable sysexit */
18528 movl PT_EIP(%esp), %edx
18529 movl PT_OLDESP(%esp), %ecx
18530 xorl %ebp,%ebp
18531 TRACE_IRQS_ON
18532 1: mov PT_FS(%esp), %fs
18533+2: mov PT_DS(%esp), %ds
18534+3: mov PT_ES(%esp), %es
18535 PTGS_TO_GS
18536 ENABLE_INTERRUPTS_SYSEXIT
18537
18538@@ -466,6 +650,9 @@ sysenter_audit:
18539 movl %eax,%edx /* 2nd arg: syscall number */
18540 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18541 call __audit_syscall_entry
18542+
18543+ pax_erase_kstack
18544+
18545 pushl_cfi %ebx
18546 movl PT_EAX(%esp),%eax /* reload syscall number */
18547 jmp sysenter_do_call
18548@@ -491,10 +678,16 @@ sysexit_audit:
18549
18550 CFI_ENDPROC
18551 .pushsection .fixup,"ax"
18552-2: movl $0,PT_FS(%esp)
18553+4: movl $0,PT_FS(%esp)
18554+ jmp 1b
18555+5: movl $0,PT_DS(%esp)
18556+ jmp 1b
18557+6: movl $0,PT_ES(%esp)
18558 jmp 1b
18559 .popsection
18560- _ASM_EXTABLE(1b,2b)
18561+ _ASM_EXTABLE(1b,4b)
18562+ _ASM_EXTABLE(2b,5b)
18563+ _ASM_EXTABLE(3b,6b)
18564 PTGS_TO_GS_EX
18565 ENDPROC(ia32_sysenter_target)
18566
18567@@ -509,6 +702,11 @@ ENTRY(system_call)
18568 pushl_cfi %eax # save orig_eax
18569 SAVE_ALL
18570 GET_THREAD_INFO(%ebp)
18571+
18572+#ifdef CONFIG_PAX_RANDKSTACK
18573+ pax_erase_kstack
18574+#endif
18575+
18576 # system call tracing in operation / emulation
18577 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18578 jnz syscall_trace_entry
18579@@ -527,6 +725,15 @@ syscall_exit:
18580 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18581 jne syscall_exit_work
18582
18583+restore_all_pax:
18584+
18585+#ifdef CONFIG_PAX_RANDKSTACK
18586+ movl %esp, %eax
18587+ call pax_randomize_kstack
18588+#endif
18589+
18590+ pax_erase_kstack
18591+
18592 restore_all:
18593 TRACE_IRQS_IRET
18594 restore_all_notrace:
18595@@ -583,14 +790,34 @@ ldt_ss:
18596 * compensating for the offset by changing to the ESPFIX segment with
18597 * a base address that matches for the difference.
18598 */
18599-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18600+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18601 mov %esp, %edx /* load kernel esp */
18602 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18603 mov %dx, %ax /* eax: new kernel esp */
18604 sub %eax, %edx /* offset (low word is 0) */
18605+#ifdef CONFIG_SMP
18606+ movl PER_CPU_VAR(cpu_number), %ebx
18607+ shll $PAGE_SHIFT_asm, %ebx
18608+ addl $cpu_gdt_table, %ebx
18609+#else
18610+ movl $cpu_gdt_table, %ebx
18611+#endif
18612 shr $16, %edx
18613- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18614- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18615+
18616+#ifdef CONFIG_PAX_KERNEXEC
18617+ mov %cr0, %esi
18618+ btr $16, %esi
18619+ mov %esi, %cr0
18620+#endif
18621+
18622+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18623+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18624+
18625+#ifdef CONFIG_PAX_KERNEXEC
18626+ bts $16, %esi
18627+ mov %esi, %cr0
18628+#endif
18629+
18630 pushl_cfi $__ESPFIX_SS
18631 pushl_cfi %eax /* new kernel esp */
18632 /* Disable interrupts, but do not irqtrace this section: we
18633@@ -619,20 +846,18 @@ work_resched:
18634 movl TI_flags(%ebp), %ecx
18635 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18636 # than syscall tracing?
18637- jz restore_all
18638+ jz restore_all_pax
18639 testb $_TIF_NEED_RESCHED, %cl
18640 jnz work_resched
18641
18642 work_notifysig: # deal with pending signals and
18643 # notify-resume requests
18644+ movl %esp, %eax
18645 #ifdef CONFIG_VM86
18646 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18647- movl %esp, %eax
18648 jne work_notifysig_v86 # returning to kernel-space or
18649 # vm86-space
18650 1:
18651-#else
18652- movl %esp, %eax
18653 #endif
18654 TRACE_IRQS_ON
18655 ENABLE_INTERRUPTS(CLBR_NONE)
18656@@ -653,7 +878,7 @@ work_notifysig_v86:
18657 movl %eax, %esp
18658 jmp 1b
18659 #endif
18660-END(work_pending)
18661+ENDPROC(work_pending)
18662
18663 # perform syscall exit tracing
18664 ALIGN
18665@@ -661,11 +886,14 @@ syscall_trace_entry:
18666 movl $-ENOSYS,PT_EAX(%esp)
18667 movl %esp, %eax
18668 call syscall_trace_enter
18669+
18670+ pax_erase_kstack
18671+
18672 /* What it returned is what we'll actually use. */
18673 cmpl $(NR_syscalls), %eax
18674 jnae syscall_call
18675 jmp syscall_exit
18676-END(syscall_trace_entry)
18677+ENDPROC(syscall_trace_entry)
18678
18679 # perform syscall exit tracing
18680 ALIGN
18681@@ -678,21 +906,25 @@ syscall_exit_work:
18682 movl %esp, %eax
18683 call syscall_trace_leave
18684 jmp resume_userspace
18685-END(syscall_exit_work)
18686+ENDPROC(syscall_exit_work)
18687 CFI_ENDPROC
18688
18689 RING0_INT_FRAME # can't unwind into user space anyway
18690 syscall_fault:
18691+#ifdef CONFIG_PAX_MEMORY_UDEREF
18692+ push %ss
18693+ pop %ds
18694+#endif
18695 ASM_CLAC
18696 GET_THREAD_INFO(%ebp)
18697 movl $-EFAULT,PT_EAX(%esp)
18698 jmp resume_userspace
18699-END(syscall_fault)
18700+ENDPROC(syscall_fault)
18701
18702 syscall_badsys:
18703 movl $-ENOSYS,PT_EAX(%esp)
18704 jmp resume_userspace
18705-END(syscall_badsys)
18706+ENDPROC(syscall_badsys)
18707 CFI_ENDPROC
18708 /*
18709 * End of kprobes section
18710@@ -708,8 +940,15 @@ END(syscall_badsys)
18711 * normal stack and adjusts ESP with the matching offset.
18712 */
18713 /* fixup the stack */
18714- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18715- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18716+#ifdef CONFIG_SMP
18717+ movl PER_CPU_VAR(cpu_number), %ebx
18718+ shll $PAGE_SHIFT_asm, %ebx
18719+ addl $cpu_gdt_table, %ebx
18720+#else
18721+ movl $cpu_gdt_table, %ebx
18722+#endif
18723+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18724+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18725 shl $16, %eax
18726 addl %esp, %eax /* the adjusted stack pointer */
18727 pushl_cfi $__KERNEL_DS
18728@@ -762,7 +1001,7 @@ vector=vector+1
18729 .endr
18730 2: jmp common_interrupt
18731 .endr
18732-END(irq_entries_start)
18733+ENDPROC(irq_entries_start)
18734
18735 .previous
18736 END(interrupt)
18737@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
18738 pushl_cfi $do_coprocessor_error
18739 jmp error_code
18740 CFI_ENDPROC
18741-END(coprocessor_error)
18742+ENDPROC(coprocessor_error)
18743
18744 ENTRY(simd_coprocessor_error)
18745 RING0_INT_FRAME
18746@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
18747 #endif
18748 jmp error_code
18749 CFI_ENDPROC
18750-END(simd_coprocessor_error)
18751+ENDPROC(simd_coprocessor_error)
18752
18753 ENTRY(device_not_available)
18754 RING0_INT_FRAME
18755@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
18756 pushl_cfi $do_device_not_available
18757 jmp error_code
18758 CFI_ENDPROC
18759-END(device_not_available)
18760+ENDPROC(device_not_available)
18761
18762 #ifdef CONFIG_PARAVIRT
18763 ENTRY(native_iret)
18764 iret
18765 _ASM_EXTABLE(native_iret, iret_exc)
18766-END(native_iret)
18767+ENDPROC(native_iret)
18768
18769 ENTRY(native_irq_enable_sysexit)
18770 sti
18771 sysexit
18772-END(native_irq_enable_sysexit)
18773+ENDPROC(native_irq_enable_sysexit)
18774 #endif
18775
18776 ENTRY(overflow)
18777@@ -865,7 +1104,7 @@ ENTRY(overflow)
18778 pushl_cfi $do_overflow
18779 jmp error_code
18780 CFI_ENDPROC
18781-END(overflow)
18782+ENDPROC(overflow)
18783
18784 ENTRY(bounds)
18785 RING0_INT_FRAME
18786@@ -874,7 +1113,7 @@ ENTRY(bounds)
18787 pushl_cfi $do_bounds
18788 jmp error_code
18789 CFI_ENDPROC
18790-END(bounds)
18791+ENDPROC(bounds)
18792
18793 ENTRY(invalid_op)
18794 RING0_INT_FRAME
18795@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
18796 pushl_cfi $do_invalid_op
18797 jmp error_code
18798 CFI_ENDPROC
18799-END(invalid_op)
18800+ENDPROC(invalid_op)
18801
18802 ENTRY(coprocessor_segment_overrun)
18803 RING0_INT_FRAME
18804@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
18805 pushl_cfi $do_coprocessor_segment_overrun
18806 jmp error_code
18807 CFI_ENDPROC
18808-END(coprocessor_segment_overrun)
18809+ENDPROC(coprocessor_segment_overrun)
18810
18811 ENTRY(invalid_TSS)
18812 RING0_EC_FRAME
18813@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
18814 pushl_cfi $do_invalid_TSS
18815 jmp error_code
18816 CFI_ENDPROC
18817-END(invalid_TSS)
18818+ENDPROC(invalid_TSS)
18819
18820 ENTRY(segment_not_present)
18821 RING0_EC_FRAME
18822@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
18823 pushl_cfi $do_segment_not_present
18824 jmp error_code
18825 CFI_ENDPROC
18826-END(segment_not_present)
18827+ENDPROC(segment_not_present)
18828
18829 ENTRY(stack_segment)
18830 RING0_EC_FRAME
18831@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
18832 pushl_cfi $do_stack_segment
18833 jmp error_code
18834 CFI_ENDPROC
18835-END(stack_segment)
18836+ENDPROC(stack_segment)
18837
18838 ENTRY(alignment_check)
18839 RING0_EC_FRAME
18840@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
18841 pushl_cfi $do_alignment_check
18842 jmp error_code
18843 CFI_ENDPROC
18844-END(alignment_check)
18845+ENDPROC(alignment_check)
18846
18847 ENTRY(divide_error)
18848 RING0_INT_FRAME
18849@@ -933,7 +1172,7 @@ ENTRY(divide_error)
18850 pushl_cfi $do_divide_error
18851 jmp error_code
18852 CFI_ENDPROC
18853-END(divide_error)
18854+ENDPROC(divide_error)
18855
18856 #ifdef CONFIG_X86_MCE
18857 ENTRY(machine_check)
18858@@ -943,7 +1182,7 @@ ENTRY(machine_check)
18859 pushl_cfi machine_check_vector
18860 jmp error_code
18861 CFI_ENDPROC
18862-END(machine_check)
18863+ENDPROC(machine_check)
18864 #endif
18865
18866 ENTRY(spurious_interrupt_bug)
18867@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
18868 pushl_cfi $do_spurious_interrupt_bug
18869 jmp error_code
18870 CFI_ENDPROC
18871-END(spurious_interrupt_bug)
18872+ENDPROC(spurious_interrupt_bug)
18873 /*
18874 * End of kprobes section
18875 */
18876@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
18877
18878 ENTRY(mcount)
18879 ret
18880-END(mcount)
18881+ENDPROC(mcount)
18882
18883 ENTRY(ftrace_caller)
18884 cmpl $0, function_trace_stop
18885@@ -1096,7 +1335,7 @@ ftrace_graph_call:
18886 .globl ftrace_stub
18887 ftrace_stub:
18888 ret
18889-END(ftrace_caller)
18890+ENDPROC(ftrace_caller)
18891
18892 ENTRY(ftrace_regs_caller)
18893 pushf /* push flags before compare (in cs location) */
18894@@ -1197,7 +1436,7 @@ trace:
18895 popl %ecx
18896 popl %eax
18897 jmp ftrace_stub
18898-END(mcount)
18899+ENDPROC(mcount)
18900 #endif /* CONFIG_DYNAMIC_FTRACE */
18901 #endif /* CONFIG_FUNCTION_TRACER */
18902
18903@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
18904 popl %ecx
18905 popl %eax
18906 ret
18907-END(ftrace_graph_caller)
18908+ENDPROC(ftrace_graph_caller)
18909
18910 .globl return_to_handler
18911 return_to_handler:
18912@@ -1271,15 +1510,18 @@ error_code:
18913 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18914 REG_TO_PTGS %ecx
18915 SET_KERNEL_GS %ecx
18916- movl $(__USER_DS), %ecx
18917+ movl $(__KERNEL_DS), %ecx
18918 movl %ecx, %ds
18919 movl %ecx, %es
18920+
18921+ pax_enter_kernel
18922+
18923 TRACE_IRQS_OFF
18924 movl %esp,%eax # pt_regs pointer
18925 call *%edi
18926 jmp ret_from_exception
18927 CFI_ENDPROC
18928-END(page_fault)
18929+ENDPROC(page_fault)
18930
18931 /*
18932 * Debug traps and NMI can happen at the one SYSENTER instruction
18933@@ -1322,7 +1564,7 @@ debug_stack_correct:
18934 call do_debug
18935 jmp ret_from_exception
18936 CFI_ENDPROC
18937-END(debug)
18938+ENDPROC(debug)
18939
18940 /*
18941 * NMI is doubly nasty. It can happen _while_ we're handling
18942@@ -1360,6 +1602,9 @@ nmi_stack_correct:
18943 xorl %edx,%edx # zero error code
18944 movl %esp,%eax # pt_regs pointer
18945 call do_nmi
18946+
18947+ pax_exit_kernel
18948+
18949 jmp restore_all_notrace
18950 CFI_ENDPROC
18951
18952@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
18953 FIXUP_ESPFIX_STACK # %eax == %esp
18954 xorl %edx,%edx # zero error code
18955 call do_nmi
18956+
18957+ pax_exit_kernel
18958+
18959 RESTORE_REGS
18960 lss 12+4(%esp), %esp # back to espfix stack
18961 CFI_ADJUST_CFA_OFFSET -24
18962 jmp irq_return
18963 CFI_ENDPROC
18964-END(nmi)
18965+ENDPROC(nmi)
18966
18967 ENTRY(int3)
18968 RING0_INT_FRAME
18969@@ -1414,14 +1662,14 @@ ENTRY(int3)
18970 call do_int3
18971 jmp ret_from_exception
18972 CFI_ENDPROC
18973-END(int3)
18974+ENDPROC(int3)
18975
18976 ENTRY(general_protection)
18977 RING0_EC_FRAME
18978 pushl_cfi $do_general_protection
18979 jmp error_code
18980 CFI_ENDPROC
18981-END(general_protection)
18982+ENDPROC(general_protection)
18983
18984 #ifdef CONFIG_KVM_GUEST
18985 ENTRY(async_page_fault)
18986@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
18987 pushl_cfi $do_async_page_fault
18988 jmp error_code
18989 CFI_ENDPROC
18990-END(async_page_fault)
18991+ENDPROC(async_page_fault)
18992 #endif
18993
18994 /*
18995diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18996index 7272089..6204f9c5 100644
18997--- a/arch/x86/kernel/entry_64.S
18998+++ b/arch/x86/kernel/entry_64.S
18999@@ -59,6 +59,8 @@
19000 #include <asm/context_tracking.h>
19001 #include <asm/smap.h>
19002 #include <linux/err.h>
19003+#include <asm/pgtable.h>
19004+#include <asm/alternative-asm.h>
19005
19006 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
19007 #include <linux/elf-em.h>
19008@@ -80,8 +82,9 @@
19009 #ifdef CONFIG_DYNAMIC_FTRACE
19010
19011 ENTRY(function_hook)
19012+ pax_force_retaddr
19013 retq
19014-END(function_hook)
19015+ENDPROC(function_hook)
19016
19017 /* skip is set if stack has been adjusted */
19018 .macro ftrace_caller_setup skip=0
19019@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
19020 #endif
19021
19022 GLOBAL(ftrace_stub)
19023+ pax_force_retaddr
19024 retq
19025-END(ftrace_caller)
19026+ENDPROC(ftrace_caller)
19027
19028 ENTRY(ftrace_regs_caller)
19029 /* Save the current flags before compare (in SS location)*/
19030@@ -191,7 +195,7 @@ ftrace_restore_flags:
19031 popfq
19032 jmp ftrace_stub
19033
19034-END(ftrace_regs_caller)
19035+ENDPROC(ftrace_regs_caller)
19036
19037
19038 #else /* ! CONFIG_DYNAMIC_FTRACE */
19039@@ -212,6 +216,7 @@ ENTRY(function_hook)
19040 #endif
19041
19042 GLOBAL(ftrace_stub)
19043+ pax_force_retaddr
19044 retq
19045
19046 trace:
19047@@ -225,12 +230,13 @@ trace:
19048 #endif
19049 subq $MCOUNT_INSN_SIZE, %rdi
19050
19051+ pax_force_fptr ftrace_trace_function
19052 call *ftrace_trace_function
19053
19054 MCOUNT_RESTORE_FRAME
19055
19056 jmp ftrace_stub
19057-END(function_hook)
19058+ENDPROC(function_hook)
19059 #endif /* CONFIG_DYNAMIC_FTRACE */
19060 #endif /* CONFIG_FUNCTION_TRACER */
19061
19062@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19063
19064 MCOUNT_RESTORE_FRAME
19065
19066+ pax_force_retaddr
19067 retq
19068-END(ftrace_graph_caller)
19069+ENDPROC(ftrace_graph_caller)
19070
19071 GLOBAL(return_to_handler)
19072 subq $24, %rsp
19073@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19074 movq 8(%rsp), %rdx
19075 movq (%rsp), %rax
19076 addq $24, %rsp
19077+ pax_force_fptr %rdi
19078 jmp *%rdi
19079+ENDPROC(return_to_handler)
19080 #endif
19081
19082
19083@@ -284,6 +293,309 @@ ENTRY(native_usergs_sysret64)
19084 ENDPROC(native_usergs_sysret64)
19085 #endif /* CONFIG_PARAVIRT */
19086
19087+ .macro ljmpq sel, off
19088+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19089+ .byte 0x48; ljmp *1234f(%rip)
19090+ .pushsection .rodata
19091+ .align 16
19092+ 1234: .quad \off; .word \sel
19093+ .popsection
19094+#else
19095+ pushq $\sel
19096+ pushq $\off
19097+ lretq
19098+#endif
19099+ .endm
19100+
19101+ .macro pax_enter_kernel
19102+ pax_set_fptr_mask
19103+#ifdef CONFIG_PAX_KERNEXEC
19104+ call pax_enter_kernel
19105+#endif
19106+ .endm
19107+
19108+ .macro pax_exit_kernel
19109+#ifdef CONFIG_PAX_KERNEXEC
19110+ call pax_exit_kernel
19111+#endif
19112+ .endm
19113+
19114+#ifdef CONFIG_PAX_KERNEXEC
19115+ENTRY(pax_enter_kernel)
19116+ pushq %rdi
19117+
19118+#ifdef CONFIG_PARAVIRT
19119+ PV_SAVE_REGS(CLBR_RDI)
19120+#endif
19121+
19122+ GET_CR0_INTO_RDI
19123+ bts $16,%rdi
19124+ jnc 3f
19125+ mov %cs,%edi
19126+ cmp $__KERNEL_CS,%edi
19127+ jnz 2f
19128+1:
19129+
19130+#ifdef CONFIG_PARAVIRT
19131+ PV_RESTORE_REGS(CLBR_RDI)
19132+#endif
19133+
19134+ popq %rdi
19135+ pax_force_retaddr
19136+ retq
19137+
19138+2: ljmpq __KERNEL_CS,1b
19139+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19140+4: SET_RDI_INTO_CR0
19141+ jmp 1b
19142+ENDPROC(pax_enter_kernel)
19143+
19144+ENTRY(pax_exit_kernel)
19145+ pushq %rdi
19146+
19147+#ifdef CONFIG_PARAVIRT
19148+ PV_SAVE_REGS(CLBR_RDI)
19149+#endif
19150+
19151+ mov %cs,%rdi
19152+ cmp $__KERNEXEC_KERNEL_CS,%edi
19153+ jz 2f
19154+ GET_CR0_INTO_RDI
19155+ bts $16,%rdi
19156+ jnc 4f
19157+1:
19158+
19159+#ifdef CONFIG_PARAVIRT
19160+ PV_RESTORE_REGS(CLBR_RDI);
19161+#endif
19162+
19163+ popq %rdi
19164+ pax_force_retaddr
19165+ retq
19166+
19167+2: GET_CR0_INTO_RDI
19168+ btr $16,%rdi
19169+ jnc 4f
19170+ ljmpq __KERNEL_CS,3f
19171+3: SET_RDI_INTO_CR0
19172+ jmp 1b
19173+4: ud2
19174+ jmp 4b
19175+ENDPROC(pax_exit_kernel)
19176+#endif
19177+
19178+ .macro pax_enter_kernel_user
19179+ pax_set_fptr_mask
19180+#ifdef CONFIG_PAX_MEMORY_UDEREF
19181+ call pax_enter_kernel_user
19182+#endif
19183+ .endm
19184+
19185+ .macro pax_exit_kernel_user
19186+#ifdef CONFIG_PAX_MEMORY_UDEREF
19187+ call pax_exit_kernel_user
19188+#endif
19189+#ifdef CONFIG_PAX_RANDKSTACK
19190+ pushq %rax
19191+ pushq %r11
19192+ call pax_randomize_kstack
19193+ popq %r11
19194+ popq %rax
19195+#endif
19196+ .endm
19197+
19198+#ifdef CONFIG_PAX_MEMORY_UDEREF
19199+ENTRY(pax_enter_kernel_user)
19200+ pushq %rdi
19201+ pushq %rbx
19202+
19203+#ifdef CONFIG_PARAVIRT
19204+ PV_SAVE_REGS(CLBR_RDI)
19205+#endif
19206+
19207+ GET_CR3_INTO_RDI
19208+ mov %rdi,%rbx
19209+ add $__START_KERNEL_map,%rbx
19210+ sub phys_base(%rip),%rbx
19211+
19212+#ifdef CONFIG_PARAVIRT
19213+ cmpl $0, pv_info+PARAVIRT_enabled
19214+ jz 1f
19215+ pushq %rdi
19216+ i = 0
19217+ .rept USER_PGD_PTRS
19218+ mov i*8(%rbx),%rsi
19219+ mov $0,%sil
19220+ lea i*8(%rbx),%rdi
19221+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19222+ i = i + 1
19223+ .endr
19224+ popq %rdi
19225+ jmp 2f
19226+1:
19227+#endif
19228+
19229+ i = 0
19230+ .rept USER_PGD_PTRS
19231+ movb $0,i*8(%rbx)
19232+ i = i + 1
19233+ .endr
19234+
19235+#ifdef CONFIG_PARAVIRT
19236+2:
19237+#endif
19238+ SET_RDI_INTO_CR3
19239+
19240+#ifdef CONFIG_PAX_KERNEXEC
19241+ GET_CR0_INTO_RDI
19242+ bts $16,%rdi
19243+ SET_RDI_INTO_CR0
19244+#endif
19245+
19246+#ifdef CONFIG_PARAVIRT
19247+ PV_RESTORE_REGS(CLBR_RDI)
19248+#endif
19249+
19250+ popq %rbx
19251+ popq %rdi
19252+ pax_force_retaddr
19253+ retq
19254+ENDPROC(pax_enter_kernel_user)
19255+
19256+ENTRY(pax_exit_kernel_user)
19257+ pushq %rdi
19258+ pushq %rbx
19259+
19260+#ifdef CONFIG_PARAVIRT
19261+ PV_SAVE_REGS(CLBR_RDI)
19262+#endif
19263+
19264+#ifdef CONFIG_PAX_KERNEXEC
19265+ GET_CR0_INTO_RDI
19266+ btr $16,%rdi
19267+ jnc 3f
19268+ SET_RDI_INTO_CR0
19269+#endif
19270+
19271+ GET_CR3_INTO_RDI
19272+ mov %rdi,%rbx
19273+ add $__START_KERNEL_map,%rbx
19274+ sub phys_base(%rip),%rbx
19275+
19276+#ifdef CONFIG_PARAVIRT
19277+ cmpl $0, pv_info+PARAVIRT_enabled
19278+ jz 1f
19279+ i = 0
19280+ .rept USER_PGD_PTRS
19281+ mov i*8(%rbx),%rsi
19282+ mov $0x67,%sil
19283+ lea i*8(%rbx),%rdi
19284+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19285+ i = i + 1
19286+ .endr
19287+ jmp 2f
19288+1:
19289+#endif
19290+
19291+ i = 0
19292+ .rept USER_PGD_PTRS
19293+ movb $0x67,i*8(%rbx)
19294+ i = i + 1
19295+ .endr
19296+
19297+#ifdef CONFIG_PARAVIRT
19298+2: PV_RESTORE_REGS(CLBR_RDI)
19299+#endif
19300+
19301+ popq %rbx
19302+ popq %rdi
19303+ pax_force_retaddr
19304+ retq
19305+3: ud2
19306+ jmp 3b
19307+ENDPROC(pax_exit_kernel_user)
19308+#endif
19309+
19310+ .macro pax_enter_kernel_nmi
19311+ pax_set_fptr_mask
19312+
19313+#ifdef CONFIG_PAX_KERNEXEC
19314+ GET_CR0_INTO_RDI
19315+ bts $16,%rdi
19316+ jc 110f
19317+ SET_RDI_INTO_CR0
19318+ or $2,%ebx
19319+110:
19320+#endif
19321+ .endm
19322+
19323+ .macro pax_exit_kernel_nmi
19324+#ifdef CONFIG_PAX_KERNEXEC
19325+ btr $1,%ebx
19326+ jnc 110f
19327+ GET_CR0_INTO_RDI
19328+ btr $16,%rdi
19329+ SET_RDI_INTO_CR0
19330+110:
19331+#endif
19332+ .endm
19333+
19334+ .macro pax_erase_kstack
19335+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19336+ call pax_erase_kstack
19337+#endif
19338+ .endm
19339+
19340+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19341+ENTRY(pax_erase_kstack)
19342+ pushq %rdi
19343+ pushq %rcx
19344+ pushq %rax
19345+ pushq %r11
19346+
19347+ GET_THREAD_INFO(%r11)
19348+ mov TI_lowest_stack(%r11), %rdi
19349+ mov $-0xBEEF, %rax
19350+ std
19351+
19352+1: mov %edi, %ecx
19353+ and $THREAD_SIZE_asm - 1, %ecx
19354+ shr $3, %ecx
19355+ repne scasq
19356+ jecxz 2f
19357+
19358+ cmp $2*8, %ecx
19359+ jc 2f
19360+
19361+ mov $2*8, %ecx
19362+ repe scasq
19363+ jecxz 2f
19364+ jne 1b
19365+
19366+2: cld
19367+ mov %esp, %ecx
19368+ sub %edi, %ecx
19369+
19370+ cmp $THREAD_SIZE_asm, %rcx
19371+ jb 3f
19372+ ud2
19373+3:
19374+
19375+ shr $3, %ecx
19376+ rep stosq
19377+
19378+ mov TI_task_thread_sp0(%r11), %rdi
19379+ sub $256, %rdi
19380+ mov %rdi, TI_lowest_stack(%r11)
19381+
19382+ popq %r11
19383+ popq %rax
19384+ popq %rcx
19385+ popq %rdi
19386+ pax_force_retaddr
19387+ ret
19388+ENDPROC(pax_erase_kstack)
19389+#endif
19390
19391 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19392 #ifdef CONFIG_TRACE_IRQFLAGS
19393@@ -375,8 +687,8 @@ ENDPROC(native_usergs_sysret64)
19394 .endm
19395
19396 .macro UNFAKE_STACK_FRAME
19397- addq $8*6, %rsp
19398- CFI_ADJUST_CFA_OFFSET -(6*8)
19399+ addq $8*6 + ARG_SKIP, %rsp
19400+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19401 .endm
19402
19403 /*
19404@@ -463,7 +775,7 @@ ENDPROC(native_usergs_sysret64)
19405 movq %rsp, %rsi
19406
19407 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19408- testl $3, CS-RBP(%rsi)
19409+ testb $3, CS-RBP(%rsi)
19410 je 1f
19411 SWAPGS
19412 /*
19413@@ -498,9 +810,10 @@ ENTRY(save_rest)
19414 movq_cfi r15, R15+16
19415 movq %r11, 8(%rsp) /* return address */
19416 FIXUP_TOP_OF_STACK %r11, 16
19417+ pax_force_retaddr
19418 ret
19419 CFI_ENDPROC
19420-END(save_rest)
19421+ENDPROC(save_rest)
19422
19423 /* save complete stack frame */
19424 .pushsection .kprobes.text, "ax"
19425@@ -529,9 +842,10 @@ ENTRY(save_paranoid)
19426 js 1f /* negative -> in kernel */
19427 SWAPGS
19428 xorl %ebx,%ebx
19429-1: ret
19430+1: pax_force_retaddr_bts
19431+ ret
19432 CFI_ENDPROC
19433-END(save_paranoid)
19434+ENDPROC(save_paranoid)
19435 .popsection
19436
19437 /*
19438@@ -553,7 +867,7 @@ ENTRY(ret_from_fork)
19439
19440 RESTORE_REST
19441
19442- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19443+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19444 jz 1f
19445
19446 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19447@@ -571,7 +885,7 @@ ENTRY(ret_from_fork)
19448 RESTORE_REST
19449 jmp int_ret_from_sys_call
19450 CFI_ENDPROC
19451-END(ret_from_fork)
19452+ENDPROC(ret_from_fork)
19453
19454 /*
19455 * System call entry. Up to 6 arguments in registers are supported.
19456@@ -608,7 +922,7 @@ END(ret_from_fork)
19457 ENTRY(system_call)
19458 CFI_STARTPROC simple
19459 CFI_SIGNAL_FRAME
19460- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19461+ CFI_DEF_CFA rsp,0
19462 CFI_REGISTER rip,rcx
19463 /*CFI_REGISTER rflags,r11*/
19464 SWAPGS_UNSAFE_STACK
19465@@ -621,16 +935,23 @@ GLOBAL(system_call_after_swapgs)
19466
19467 movq %rsp,PER_CPU_VAR(old_rsp)
19468 movq PER_CPU_VAR(kernel_stack),%rsp
19469+ SAVE_ARGS 8*6,0
19470+ pax_enter_kernel_user
19471+
19472+#ifdef CONFIG_PAX_RANDKSTACK
19473+ pax_erase_kstack
19474+#endif
19475+
19476 /*
19477 * No need to follow this irqs off/on section - it's straight
19478 * and short:
19479 */
19480 ENABLE_INTERRUPTS(CLBR_NONE)
19481- SAVE_ARGS 8,0
19482 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19483 movq %rcx,RIP-ARGOFFSET(%rsp)
19484 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19485- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19486+ GET_THREAD_INFO(%rcx)
19487+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19488 jnz tracesys
19489 system_call_fastpath:
19490 #if __SYSCALL_MASK == ~0
19491@@ -640,7 +961,7 @@ system_call_fastpath:
19492 cmpl $__NR_syscall_max,%eax
19493 #endif
19494 ja badsys
19495- movq %r10,%rcx
19496+ movq R10-ARGOFFSET(%rsp),%rcx
19497 call *sys_call_table(,%rax,8) # XXX: rip relative
19498 movq %rax,RAX-ARGOFFSET(%rsp)
19499 /*
19500@@ -654,10 +975,13 @@ sysret_check:
19501 LOCKDEP_SYS_EXIT
19502 DISABLE_INTERRUPTS(CLBR_NONE)
19503 TRACE_IRQS_OFF
19504- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19505+ GET_THREAD_INFO(%rcx)
19506+ movl TI_flags(%rcx),%edx
19507 andl %edi,%edx
19508 jnz sysret_careful
19509 CFI_REMEMBER_STATE
19510+ pax_exit_kernel_user
19511+ pax_erase_kstack
19512 /*
19513 * sysretq will re-enable interrupts:
19514 */
19515@@ -709,14 +1033,18 @@ badsys:
19516 * jump back to the normal fast path.
19517 */
19518 auditsys:
19519- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19520+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19521 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19522 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19523 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19524 movq %rax,%rsi /* 2nd arg: syscall number */
19525 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19526 call __audit_syscall_entry
19527+
19528+ pax_erase_kstack
19529+
19530 LOAD_ARGS 0 /* reload call-clobbered registers */
19531+ pax_set_fptr_mask
19532 jmp system_call_fastpath
19533
19534 /*
19535@@ -737,7 +1065,7 @@ sysret_audit:
19536 /* Do syscall tracing */
19537 tracesys:
19538 #ifdef CONFIG_AUDITSYSCALL
19539- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19540+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19541 jz auditsys
19542 #endif
19543 SAVE_REST
19544@@ -745,12 +1073,16 @@ tracesys:
19545 FIXUP_TOP_OF_STACK %rdi
19546 movq %rsp,%rdi
19547 call syscall_trace_enter
19548+
19549+ pax_erase_kstack
19550+
19551 /*
19552 * Reload arg registers from stack in case ptrace changed them.
19553 * We don't reload %rax because syscall_trace_enter() returned
19554 * the value it wants us to use in the table lookup.
19555 */
19556 LOAD_ARGS ARGOFFSET, 1
19557+ pax_set_fptr_mask
19558 RESTORE_REST
19559 #if __SYSCALL_MASK == ~0
19560 cmpq $__NR_syscall_max,%rax
19561@@ -759,7 +1091,7 @@ tracesys:
19562 cmpl $__NR_syscall_max,%eax
19563 #endif
19564 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19565- movq %r10,%rcx /* fixup for C */
19566+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19567 call *sys_call_table(,%rax,8)
19568 movq %rax,RAX-ARGOFFSET(%rsp)
19569 /* Use IRET because user could have changed frame */
19570@@ -780,7 +1112,9 @@ GLOBAL(int_with_check)
19571 andl %edi,%edx
19572 jnz int_careful
19573 andl $~TS_COMPAT,TI_status(%rcx)
19574- jmp retint_swapgs
19575+ pax_exit_kernel_user
19576+ pax_erase_kstack
19577+ jmp retint_swapgs_pax
19578
19579 /* Either reschedule or signal or syscall exit tracking needed. */
19580 /* First do a reschedule test. */
19581@@ -826,7 +1160,7 @@ int_restore_rest:
19582 TRACE_IRQS_OFF
19583 jmp int_with_check
19584 CFI_ENDPROC
19585-END(system_call)
19586+ENDPROC(system_call)
19587
19588 .macro FORK_LIKE func
19589 ENTRY(stub_\func)
19590@@ -839,9 +1173,10 @@ ENTRY(stub_\func)
19591 DEFAULT_FRAME 0 8 /* offset 8: return address */
19592 call sys_\func
19593 RESTORE_TOP_OF_STACK %r11, 8
19594+ pax_force_retaddr
19595 ret $REST_SKIP /* pop extended registers */
19596 CFI_ENDPROC
19597-END(stub_\func)
19598+ENDPROC(stub_\func)
19599 .endm
19600
19601 .macro FIXED_FRAME label,func
19602@@ -851,9 +1186,10 @@ ENTRY(\label)
19603 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
19604 call \func
19605 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
19606+ pax_force_retaddr
19607 ret
19608 CFI_ENDPROC
19609-END(\label)
19610+ENDPROC(\label)
19611 .endm
19612
19613 FORK_LIKE clone
19614@@ -870,9 +1206,10 @@ ENTRY(ptregscall_common)
19615 movq_cfi_restore R12+8, r12
19616 movq_cfi_restore RBP+8, rbp
19617 movq_cfi_restore RBX+8, rbx
19618+ pax_force_retaddr
19619 ret $REST_SKIP /* pop extended registers */
19620 CFI_ENDPROC
19621-END(ptregscall_common)
19622+ENDPROC(ptregscall_common)
19623
19624 ENTRY(stub_execve)
19625 CFI_STARTPROC
19626@@ -885,7 +1222,7 @@ ENTRY(stub_execve)
19627 RESTORE_REST
19628 jmp int_ret_from_sys_call
19629 CFI_ENDPROC
19630-END(stub_execve)
19631+ENDPROC(stub_execve)
19632
19633 /*
19634 * sigreturn is special because it needs to restore all registers on return.
19635@@ -902,7 +1239,7 @@ ENTRY(stub_rt_sigreturn)
19636 RESTORE_REST
19637 jmp int_ret_from_sys_call
19638 CFI_ENDPROC
19639-END(stub_rt_sigreturn)
19640+ENDPROC(stub_rt_sigreturn)
19641
19642 #ifdef CONFIG_X86_X32_ABI
19643 ENTRY(stub_x32_rt_sigreturn)
19644@@ -916,7 +1253,7 @@ ENTRY(stub_x32_rt_sigreturn)
19645 RESTORE_REST
19646 jmp int_ret_from_sys_call
19647 CFI_ENDPROC
19648-END(stub_x32_rt_sigreturn)
19649+ENDPROC(stub_x32_rt_sigreturn)
19650
19651 ENTRY(stub_x32_execve)
19652 CFI_STARTPROC
19653@@ -930,7 +1267,7 @@ ENTRY(stub_x32_execve)
19654 RESTORE_REST
19655 jmp int_ret_from_sys_call
19656 CFI_ENDPROC
19657-END(stub_x32_execve)
19658+ENDPROC(stub_x32_execve)
19659
19660 #endif
19661
19662@@ -967,7 +1304,7 @@ vector=vector+1
19663 2: jmp common_interrupt
19664 .endr
19665 CFI_ENDPROC
19666-END(irq_entries_start)
19667+ENDPROC(irq_entries_start)
19668
19669 .previous
19670 END(interrupt)
19671@@ -987,6 +1324,16 @@ END(interrupt)
19672 subq $ORIG_RAX-RBP, %rsp
19673 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19674 SAVE_ARGS_IRQ
19675+#ifdef CONFIG_PAX_MEMORY_UDEREF
19676+ testb $3, CS(%rdi)
19677+ jnz 1f
19678+ pax_enter_kernel
19679+ jmp 2f
19680+1: pax_enter_kernel_user
19681+2:
19682+#else
19683+ pax_enter_kernel
19684+#endif
19685 call \func
19686 .endm
19687
19688@@ -1019,7 +1366,7 @@ ret_from_intr:
19689
19690 exit_intr:
19691 GET_THREAD_INFO(%rcx)
19692- testl $3,CS-ARGOFFSET(%rsp)
19693+ testb $3,CS-ARGOFFSET(%rsp)
19694 je retint_kernel
19695
19696 /* Interrupt came from user space */
19697@@ -1041,12 +1388,16 @@ retint_swapgs: /* return to user-space */
19698 * The iretq could re-enable interrupts:
19699 */
19700 DISABLE_INTERRUPTS(CLBR_ANY)
19701+ pax_exit_kernel_user
19702+retint_swapgs_pax:
19703 TRACE_IRQS_IRETQ
19704 SWAPGS
19705 jmp restore_args
19706
19707 retint_restore_args: /* return to kernel space */
19708 DISABLE_INTERRUPTS(CLBR_ANY)
19709+ pax_exit_kernel
19710+ pax_force_retaddr (RIP-ARGOFFSET)
19711 /*
19712 * The iretq could re-enable interrupts:
19713 */
19714@@ -1129,7 +1480,7 @@ ENTRY(retint_kernel)
19715 #endif
19716
19717 CFI_ENDPROC
19718-END(common_interrupt)
19719+ENDPROC(common_interrupt)
19720 /*
19721 * End of kprobes section
19722 */
19723@@ -1147,7 +1498,7 @@ ENTRY(\sym)
19724 interrupt \do_sym
19725 jmp ret_from_intr
19726 CFI_ENDPROC
19727-END(\sym)
19728+ENDPROC(\sym)
19729 .endm
19730
19731 #ifdef CONFIG_SMP
19732@@ -1208,12 +1559,22 @@ ENTRY(\sym)
19733 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19734 call error_entry
19735 DEFAULT_FRAME 0
19736+#ifdef CONFIG_PAX_MEMORY_UDEREF
19737+ testb $3, CS(%rsp)
19738+ jnz 1f
19739+ pax_enter_kernel
19740+ jmp 2f
19741+1: pax_enter_kernel_user
19742+2:
19743+#else
19744+ pax_enter_kernel
19745+#endif
19746 movq %rsp,%rdi /* pt_regs pointer */
19747 xorl %esi,%esi /* no error code */
19748 call \do_sym
19749 jmp error_exit /* %ebx: no swapgs flag */
19750 CFI_ENDPROC
19751-END(\sym)
19752+ENDPROC(\sym)
19753 .endm
19754
19755 .macro paranoidzeroentry sym do_sym
19756@@ -1226,15 +1587,25 @@ ENTRY(\sym)
19757 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19758 call save_paranoid
19759 TRACE_IRQS_OFF
19760+#ifdef CONFIG_PAX_MEMORY_UDEREF
19761+ testb $3, CS(%rsp)
19762+ jnz 1f
19763+ pax_enter_kernel
19764+ jmp 2f
19765+1: pax_enter_kernel_user
19766+2:
19767+#else
19768+ pax_enter_kernel
19769+#endif
19770 movq %rsp,%rdi /* pt_regs pointer */
19771 xorl %esi,%esi /* no error code */
19772 call \do_sym
19773 jmp paranoid_exit /* %ebx: no swapgs flag */
19774 CFI_ENDPROC
19775-END(\sym)
19776+ENDPROC(\sym)
19777 .endm
19778
19779-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19780+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19781 .macro paranoidzeroentry_ist sym do_sym ist
19782 ENTRY(\sym)
19783 INTR_FRAME
19784@@ -1245,14 +1616,30 @@ ENTRY(\sym)
19785 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19786 call save_paranoid
19787 TRACE_IRQS_OFF_DEBUG
19788+#ifdef CONFIG_PAX_MEMORY_UDEREF
19789+ testb $3, CS(%rsp)
19790+ jnz 1f
19791+ pax_enter_kernel
19792+ jmp 2f
19793+1: pax_enter_kernel_user
19794+2:
19795+#else
19796+ pax_enter_kernel
19797+#endif
19798 movq %rsp,%rdi /* pt_regs pointer */
19799 xorl %esi,%esi /* no error code */
19800+#ifdef CONFIG_SMP
19801+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19802+ lea init_tss(%r12), %r12
19803+#else
19804+ lea init_tss(%rip), %r12
19805+#endif
19806 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19807 call \do_sym
19808 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19809 jmp paranoid_exit /* %ebx: no swapgs flag */
19810 CFI_ENDPROC
19811-END(\sym)
19812+ENDPROC(\sym)
19813 .endm
19814
19815 .macro errorentry sym do_sym
19816@@ -1264,13 +1651,23 @@ ENTRY(\sym)
19817 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19818 call error_entry
19819 DEFAULT_FRAME 0
19820+#ifdef CONFIG_PAX_MEMORY_UDEREF
19821+ testb $3, CS(%rsp)
19822+ jnz 1f
19823+ pax_enter_kernel
19824+ jmp 2f
19825+1: pax_enter_kernel_user
19826+2:
19827+#else
19828+ pax_enter_kernel
19829+#endif
19830 movq %rsp,%rdi /* pt_regs pointer */
19831 movq ORIG_RAX(%rsp),%rsi /* get error code */
19832 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19833 call \do_sym
19834 jmp error_exit /* %ebx: no swapgs flag */
19835 CFI_ENDPROC
19836-END(\sym)
19837+ENDPROC(\sym)
19838 .endm
19839
19840 /* error code is on the stack already */
19841@@ -1284,13 +1681,23 @@ ENTRY(\sym)
19842 call save_paranoid
19843 DEFAULT_FRAME 0
19844 TRACE_IRQS_OFF
19845+#ifdef CONFIG_PAX_MEMORY_UDEREF
19846+ testb $3, CS(%rsp)
19847+ jnz 1f
19848+ pax_enter_kernel
19849+ jmp 2f
19850+1: pax_enter_kernel_user
19851+2:
19852+#else
19853+ pax_enter_kernel
19854+#endif
19855 movq %rsp,%rdi /* pt_regs pointer */
19856 movq ORIG_RAX(%rsp),%rsi /* get error code */
19857 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19858 call \do_sym
19859 jmp paranoid_exit /* %ebx: no swapgs flag */
19860 CFI_ENDPROC
19861-END(\sym)
19862+ENDPROC(\sym)
19863 .endm
19864
19865 zeroentry divide_error do_divide_error
19866@@ -1320,9 +1727,10 @@ gs_change:
19867 2: mfence /* workaround */
19868 SWAPGS
19869 popfq_cfi
19870+ pax_force_retaddr
19871 ret
19872 CFI_ENDPROC
19873-END(native_load_gs_index)
19874+ENDPROC(native_load_gs_index)
19875
19876 _ASM_EXTABLE(gs_change,bad_gs)
19877 .section .fixup,"ax"
19878@@ -1350,9 +1758,10 @@ ENTRY(call_softirq)
19879 CFI_DEF_CFA_REGISTER rsp
19880 CFI_ADJUST_CFA_OFFSET -8
19881 decl PER_CPU_VAR(irq_count)
19882+ pax_force_retaddr
19883 ret
19884 CFI_ENDPROC
19885-END(call_softirq)
19886+ENDPROC(call_softirq)
19887
19888 #ifdef CONFIG_XEN
19889 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19890@@ -1390,7 +1799,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19891 decl PER_CPU_VAR(irq_count)
19892 jmp error_exit
19893 CFI_ENDPROC
19894-END(xen_do_hypervisor_callback)
19895+ENDPROC(xen_do_hypervisor_callback)
19896
19897 /*
19898 * Hypervisor uses this for application faults while it executes.
19899@@ -1449,7 +1858,7 @@ ENTRY(xen_failsafe_callback)
19900 SAVE_ALL
19901 jmp error_exit
19902 CFI_ENDPROC
19903-END(xen_failsafe_callback)
19904+ENDPROC(xen_failsafe_callback)
19905
19906 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
19907 xen_hvm_callback_vector xen_evtchn_do_upcall
19908@@ -1501,18 +1910,33 @@ ENTRY(paranoid_exit)
19909 DEFAULT_FRAME
19910 DISABLE_INTERRUPTS(CLBR_NONE)
19911 TRACE_IRQS_OFF_DEBUG
19912- testl %ebx,%ebx /* swapgs needed? */
19913+ testl $1,%ebx /* swapgs needed? */
19914 jnz paranoid_restore
19915- testl $3,CS(%rsp)
19916+ testb $3,CS(%rsp)
19917 jnz paranoid_userspace
19918+#ifdef CONFIG_PAX_MEMORY_UDEREF
19919+ pax_exit_kernel
19920+ TRACE_IRQS_IRETQ 0
19921+ SWAPGS_UNSAFE_STACK
19922+ RESTORE_ALL 8
19923+ pax_force_retaddr_bts
19924+ jmp irq_return
19925+#endif
19926 paranoid_swapgs:
19927+#ifdef CONFIG_PAX_MEMORY_UDEREF
19928+ pax_exit_kernel_user
19929+#else
19930+ pax_exit_kernel
19931+#endif
19932 TRACE_IRQS_IRETQ 0
19933 SWAPGS_UNSAFE_STACK
19934 RESTORE_ALL 8
19935 jmp irq_return
19936 paranoid_restore:
19937+ pax_exit_kernel
19938 TRACE_IRQS_IRETQ_DEBUG 0
19939 RESTORE_ALL 8
19940+ pax_force_retaddr_bts
19941 jmp irq_return
19942 paranoid_userspace:
19943 GET_THREAD_INFO(%rcx)
19944@@ -1541,7 +1965,7 @@ paranoid_schedule:
19945 TRACE_IRQS_OFF
19946 jmp paranoid_userspace
19947 CFI_ENDPROC
19948-END(paranoid_exit)
19949+ENDPROC(paranoid_exit)
19950
19951 /*
19952 * Exception entry point. This expects an error code/orig_rax on the stack.
19953@@ -1568,12 +1992,13 @@ ENTRY(error_entry)
19954 movq_cfi r14, R14+8
19955 movq_cfi r15, R15+8
19956 xorl %ebx,%ebx
19957- testl $3,CS+8(%rsp)
19958+ testb $3,CS+8(%rsp)
19959 je error_kernelspace
19960 error_swapgs:
19961 SWAPGS
19962 error_sti:
19963 TRACE_IRQS_OFF
19964+ pax_force_retaddr_bts
19965 ret
19966
19967 /*
19968@@ -1600,7 +2025,7 @@ bstep_iret:
19969 movq %rcx,RIP+8(%rsp)
19970 jmp error_swapgs
19971 CFI_ENDPROC
19972-END(error_entry)
19973+ENDPROC(error_entry)
19974
19975
19976 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19977@@ -1611,7 +2036,7 @@ ENTRY(error_exit)
19978 DISABLE_INTERRUPTS(CLBR_NONE)
19979 TRACE_IRQS_OFF
19980 GET_THREAD_INFO(%rcx)
19981- testl %eax,%eax
19982+ testl $1,%eax
19983 jne retint_kernel
19984 LOCKDEP_SYS_EXIT_IRQ
19985 movl TI_flags(%rcx),%edx
19986@@ -1620,7 +2045,7 @@ ENTRY(error_exit)
19987 jnz retint_careful
19988 jmp retint_swapgs
19989 CFI_ENDPROC
19990-END(error_exit)
19991+ENDPROC(error_exit)
19992
19993 /*
19994 * Test if a given stack is an NMI stack or not.
19995@@ -1678,9 +2103,11 @@ ENTRY(nmi)
19996 * If %cs was not the kernel segment, then the NMI triggered in user
19997 * space, which means it is definitely not nested.
19998 */
19999+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
20000+ je 1f
20001 cmpl $__KERNEL_CS, 16(%rsp)
20002 jne first_nmi
20003-
20004+1:
20005 /*
20006 * Check the special variable on the stack to see if NMIs are
20007 * executing.
20008@@ -1714,8 +2141,7 @@ nested_nmi:
20009
20010 1:
20011 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
20012- leaq -1*8(%rsp), %rdx
20013- movq %rdx, %rsp
20014+ subq $8, %rsp
20015 CFI_ADJUST_CFA_OFFSET 1*8
20016 leaq -10*8(%rsp), %rdx
20017 pushq_cfi $__KERNEL_DS
20018@@ -1733,6 +2159,7 @@ nested_nmi_out:
20019 CFI_RESTORE rdx
20020
20021 /* No need to check faults here */
20022+# pax_force_retaddr_bts
20023 INTERRUPT_RETURN
20024
20025 CFI_RESTORE_STATE
20026@@ -1849,6 +2276,8 @@ end_repeat_nmi:
20027 */
20028 movq %cr2, %r12
20029
20030+ pax_enter_kernel_nmi
20031+
20032 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20033 movq %rsp,%rdi
20034 movq $-1,%rsi
20035@@ -1861,26 +2290,31 @@ end_repeat_nmi:
20036 movq %r12, %cr2
20037 1:
20038
20039- testl %ebx,%ebx /* swapgs needed? */
20040+ testl $1,%ebx /* swapgs needed? */
20041 jnz nmi_restore
20042 nmi_swapgs:
20043 SWAPGS_UNSAFE_STACK
20044 nmi_restore:
20045+ pax_exit_kernel_nmi
20046 /* Pop the extra iret frame at once */
20047 RESTORE_ALL 6*8
20048+ testb $3, 8(%rsp)
20049+ jnz 1f
20050+ pax_force_retaddr_bts
20051+1:
20052
20053 /* Clear the NMI executing stack variable */
20054 movq $0, 5*8(%rsp)
20055 jmp irq_return
20056 CFI_ENDPROC
20057-END(nmi)
20058+ENDPROC(nmi)
20059
20060 ENTRY(ignore_sysret)
20061 CFI_STARTPROC
20062 mov $-ENOSYS,%eax
20063 sysret
20064 CFI_ENDPROC
20065-END(ignore_sysret)
20066+ENDPROC(ignore_sysret)
20067
20068 /*
20069 * End of kprobes section
20070diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20071index 42a392a..fbbd930 100644
20072--- a/arch/x86/kernel/ftrace.c
20073+++ b/arch/x86/kernel/ftrace.c
20074@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20075 {
20076 unsigned char replaced[MCOUNT_INSN_SIZE];
20077
20078+ ip = ktla_ktva(ip);
20079+
20080 /*
20081 * Note: Due to modules and __init, code can
20082 * disappear and change, we need to protect against faulting
20083@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20084 unsigned char old[MCOUNT_INSN_SIZE], *new;
20085 int ret;
20086
20087- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20088+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20089 new = ftrace_call_replace(ip, (unsigned long)func);
20090
20091 /* See comment above by declaration of modifying_ftrace_code */
20092@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20093 /* Also update the regs callback function */
20094 if (!ret) {
20095 ip = (unsigned long)(&ftrace_regs_call);
20096- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20097+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20098 new = ftrace_call_replace(ip, (unsigned long)func);
20099 ret = ftrace_modify_code(ip, old, new);
20100 }
20101@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20102 * kernel identity mapping to modify code.
20103 */
20104 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20105- ip = (unsigned long)__va(__pa_symbol(ip));
20106+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
20107
20108 return probe_kernel_write((void *)ip, val, size);
20109 }
20110@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20111 unsigned char replaced[MCOUNT_INSN_SIZE];
20112 unsigned char brk = BREAKPOINT_INSTRUCTION;
20113
20114- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20115+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20116 return -EFAULT;
20117
20118 /* Make sure it is what we expect it to be */
20119@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20120 return ret;
20121
20122 fail_update:
20123- probe_kernel_write((void *)ip, &old_code[0], 1);
20124+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20125 goto out;
20126 }
20127
20128@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20129 {
20130 unsigned char code[MCOUNT_INSN_SIZE];
20131
20132+ ip = ktla_ktva(ip);
20133+
20134 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20135 return -EFAULT;
20136
20137diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
20138index 55b6761..a6456fc 100644
20139--- a/arch/x86/kernel/head64.c
20140+++ b/arch/x86/kernel/head64.c
20141@@ -67,12 +67,12 @@ again:
20142 pgd = *pgd_p;
20143
20144 /*
20145- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
20146- * critical -- __PAGE_OFFSET would point us back into the dynamic
20147+ * The use of __early_va rather than __va here is critical:
20148+ * __va would point us back into the dynamic
20149 * range and we might end up looping forever...
20150 */
20151 if (pgd)
20152- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20153+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
20154 else {
20155 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20156 reset_early_page_tables();
20157@@ -82,13 +82,13 @@ again:
20158 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
20159 for (i = 0; i < PTRS_PER_PUD; i++)
20160 pud_p[i] = 0;
20161- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20162+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
20163 }
20164 pud_p += pud_index(address);
20165 pud = *pud_p;
20166
20167 if (pud)
20168- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20169+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
20170 else {
20171 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20172 reset_early_page_tables();
20173@@ -98,7 +98,7 @@ again:
20174 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
20175 for (i = 0; i < PTRS_PER_PMD; i++)
20176 pmd_p[i] = 0;
20177- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20178+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
20179 }
20180 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
20181 pmd_p[pmd_index(address)] = pmd;
20182@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
20183 if (console_loglevel == 10)
20184 early_printk("Kernel alive\n");
20185
20186- clear_page(init_level4_pgt);
20187 /* set init_level4_pgt kernel high mapping*/
20188 init_level4_pgt[511] = early_level4_pgt[511];
20189
20190diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20191index 73afd11..d1670f5 100644
20192--- a/arch/x86/kernel/head_32.S
20193+++ b/arch/x86/kernel/head_32.S
20194@@ -26,6 +26,12 @@
20195 /* Physical address */
20196 #define pa(X) ((X) - __PAGE_OFFSET)
20197
20198+#ifdef CONFIG_PAX_KERNEXEC
20199+#define ta(X) (X)
20200+#else
20201+#define ta(X) ((X) - __PAGE_OFFSET)
20202+#endif
20203+
20204 /*
20205 * References to members of the new_cpu_data structure.
20206 */
20207@@ -55,11 +61,7 @@
20208 * and small than max_low_pfn, otherwise will waste some page table entries
20209 */
20210
20211-#if PTRS_PER_PMD > 1
20212-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20213-#else
20214-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20215-#endif
20216+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20217
20218 /* Number of possible pages in the lowmem region */
20219 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20220@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20221 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20222
20223 /*
20224+ * Real beginning of normal "text" segment
20225+ */
20226+ENTRY(stext)
20227+ENTRY(_stext)
20228+
20229+/*
20230 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20231 * %esi points to the real-mode code as a 32-bit pointer.
20232 * CS and DS must be 4 GB flat segments, but we don't depend on
20233@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20234 * can.
20235 */
20236 __HEAD
20237+
20238+#ifdef CONFIG_PAX_KERNEXEC
20239+ jmp startup_32
20240+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20241+.fill PAGE_SIZE-5,1,0xcc
20242+#endif
20243+
20244 ENTRY(startup_32)
20245 movl pa(stack_start),%ecx
20246
20247@@ -106,6 +121,59 @@ ENTRY(startup_32)
20248 2:
20249 leal -__PAGE_OFFSET(%ecx),%esp
20250
20251+#ifdef CONFIG_SMP
20252+ movl $pa(cpu_gdt_table),%edi
20253+ movl $__per_cpu_load,%eax
20254+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20255+ rorl $16,%eax
20256+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20257+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20258+ movl $__per_cpu_end - 1,%eax
20259+ subl $__per_cpu_start,%eax
20260+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20261+#endif
20262+
20263+#ifdef CONFIG_PAX_MEMORY_UDEREF
20264+ movl $NR_CPUS,%ecx
20265+ movl $pa(cpu_gdt_table),%edi
20266+1:
20267+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20268+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20269+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20270+ addl $PAGE_SIZE_asm,%edi
20271+ loop 1b
20272+#endif
20273+
20274+#ifdef CONFIG_PAX_KERNEXEC
20275+ movl $pa(boot_gdt),%edi
20276+ movl $__LOAD_PHYSICAL_ADDR,%eax
20277+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20278+ rorl $16,%eax
20279+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20280+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20281+ rorl $16,%eax
20282+
20283+ ljmp $(__BOOT_CS),$1f
20284+1:
20285+
20286+ movl $NR_CPUS,%ecx
20287+ movl $pa(cpu_gdt_table),%edi
20288+ addl $__PAGE_OFFSET,%eax
20289+1:
20290+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20291+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20292+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20293+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20294+ rorl $16,%eax
20295+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20296+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20297+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20298+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20299+ rorl $16,%eax
20300+ addl $PAGE_SIZE_asm,%edi
20301+ loop 1b
20302+#endif
20303+
20304 /*
20305 * Clear BSS first so that there are no surprises...
20306 */
20307@@ -201,8 +269,11 @@ ENTRY(startup_32)
20308 movl %eax, pa(max_pfn_mapped)
20309
20310 /* Do early initialization of the fixmap area */
20311- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20312- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20313+#ifdef CONFIG_COMPAT_VDSO
20314+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20315+#else
20316+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20317+#endif
20318 #else /* Not PAE */
20319
20320 page_pde_offset = (__PAGE_OFFSET >> 20);
20321@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20322 movl %eax, pa(max_pfn_mapped)
20323
20324 /* Do early initialization of the fixmap area */
20325- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20326- movl %eax,pa(initial_page_table+0xffc)
20327+#ifdef CONFIG_COMPAT_VDSO
20328+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20329+#else
20330+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20331+#endif
20332 #endif
20333
20334 #ifdef CONFIG_PARAVIRT
20335@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20336 cmpl $num_subarch_entries, %eax
20337 jae bad_subarch
20338
20339- movl pa(subarch_entries)(,%eax,4), %eax
20340- subl $__PAGE_OFFSET, %eax
20341- jmp *%eax
20342+ jmp *pa(subarch_entries)(,%eax,4)
20343
20344 bad_subarch:
20345 WEAK(lguest_entry)
20346@@ -261,10 +333,10 @@ WEAK(xen_entry)
20347 __INITDATA
20348
20349 subarch_entries:
20350- .long default_entry /* normal x86/PC */
20351- .long lguest_entry /* lguest hypervisor */
20352- .long xen_entry /* Xen hypervisor */
20353- .long default_entry /* Moorestown MID */
20354+ .long ta(default_entry) /* normal x86/PC */
20355+ .long ta(lguest_entry) /* lguest hypervisor */
20356+ .long ta(xen_entry) /* Xen hypervisor */
20357+ .long ta(default_entry) /* Moorestown MID */
20358 num_subarch_entries = (. - subarch_entries) / 4
20359 .previous
20360 #else
20361@@ -355,6 +427,7 @@ default_entry:
20362 movl pa(mmu_cr4_features),%eax
20363 movl %eax,%cr4
20364
20365+#ifdef CONFIG_X86_PAE
20366 testb $X86_CR4_PAE, %al # check if PAE is enabled
20367 jz enable_paging
20368
20369@@ -383,6 +456,9 @@ default_entry:
20370 /* Make changes effective */
20371 wrmsr
20372
20373+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20374+#endif
20375+
20376 enable_paging:
20377
20378 /*
20379@@ -451,14 +527,20 @@ is486:
20380 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20381 movl %eax,%ss # after changing gdt.
20382
20383- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20384+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20385 movl %eax,%ds
20386 movl %eax,%es
20387
20388 movl $(__KERNEL_PERCPU), %eax
20389 movl %eax,%fs # set this cpu's percpu
20390
20391+#ifdef CONFIG_CC_STACKPROTECTOR
20392 movl $(__KERNEL_STACK_CANARY),%eax
20393+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20394+ movl $(__USER_DS),%eax
20395+#else
20396+ xorl %eax,%eax
20397+#endif
20398 movl %eax,%gs
20399
20400 xorl %eax,%eax # Clear LDT
20401@@ -534,8 +616,11 @@ setup_once:
20402 * relocation. Manually set base address in stack canary
20403 * segment descriptor.
20404 */
20405- movl $gdt_page,%eax
20406+ movl $cpu_gdt_table,%eax
20407 movl $stack_canary,%ecx
20408+#ifdef CONFIG_SMP
20409+ addl $__per_cpu_load,%ecx
20410+#endif
20411 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20412 shrl $16, %ecx
20413 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20414@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
20415 /* This is global to keep gas from relaxing the jumps */
20416 ENTRY(early_idt_handler)
20417 cld
20418- cmpl $2,%ss:early_recursion_flag
20419+ cmpl $1,%ss:early_recursion_flag
20420 je hlt_loop
20421 incl %ss:early_recursion_flag
20422
20423@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
20424 pushl (20+6*4)(%esp) /* trapno */
20425 pushl $fault_msg
20426 call printk
20427-#endif
20428 call dump_stack
20429+#endif
20430 hlt_loop:
20431 hlt
20432 jmp hlt_loop
20433@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
20434 /* This is the default interrupt "handler" :-) */
20435 ALIGN
20436 ignore_int:
20437- cld
20438 #ifdef CONFIG_PRINTK
20439+ cmpl $2,%ss:early_recursion_flag
20440+ je hlt_loop
20441+ incl %ss:early_recursion_flag
20442+ cld
20443 pushl %eax
20444 pushl %ecx
20445 pushl %edx
20446@@ -634,9 +722,6 @@ ignore_int:
20447 movl $(__KERNEL_DS),%eax
20448 movl %eax,%ds
20449 movl %eax,%es
20450- cmpl $2,early_recursion_flag
20451- je hlt_loop
20452- incl early_recursion_flag
20453 pushl 16(%esp)
20454 pushl 24(%esp)
20455 pushl 32(%esp)
20456@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
20457 /*
20458 * BSS section
20459 */
20460-__PAGE_ALIGNED_BSS
20461- .align PAGE_SIZE
20462 #ifdef CONFIG_X86_PAE
20463+.section .initial_pg_pmd,"a",@progbits
20464 initial_pg_pmd:
20465 .fill 1024*KPMDS,4,0
20466 #else
20467+.section .initial_page_table,"a",@progbits
20468 ENTRY(initial_page_table)
20469 .fill 1024,4,0
20470 #endif
20471+.section .initial_pg_fixmap,"a",@progbits
20472 initial_pg_fixmap:
20473 .fill 1024,4,0
20474+.section .empty_zero_page,"a",@progbits
20475 ENTRY(empty_zero_page)
20476 .fill 4096,1,0
20477+.section .swapper_pg_dir,"a",@progbits
20478 ENTRY(swapper_pg_dir)
20479+#ifdef CONFIG_X86_PAE
20480+ .fill 4,8,0
20481+#else
20482 .fill 1024,4,0
20483+#endif
20484+
20485+/*
20486+ * The IDT has to be page-aligned to simplify the Pentium
20487+ * F0 0F bug workaround.. We have a special link segment
20488+ * for this.
20489+ */
20490+.section .idt,"a",@progbits
20491+ENTRY(idt_table)
20492+ .fill 256,8,0
20493
20494 /*
20495 * This starts the data section.
20496 */
20497 #ifdef CONFIG_X86_PAE
20498-__PAGE_ALIGNED_DATA
20499- /* Page-aligned for the benefit of paravirt? */
20500- .align PAGE_SIZE
20501+.section .initial_page_table,"a",@progbits
20502 ENTRY(initial_page_table)
20503 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20504 # if KPMDS == 3
20505@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
20506 # error "Kernel PMDs should be 1, 2 or 3"
20507 # endif
20508 .align PAGE_SIZE /* needs to be page-sized too */
20509+
20510+#ifdef CONFIG_PAX_PER_CPU_PGD
20511+ENTRY(cpu_pgd)
20512+ .rept NR_CPUS
20513+ .fill 4,8,0
20514+ .endr
20515+#endif
20516+
20517 #endif
20518
20519 .data
20520 .balign 4
20521 ENTRY(stack_start)
20522- .long init_thread_union+THREAD_SIZE
20523+ .long init_thread_union+THREAD_SIZE-8
20524
20525 __INITRODATA
20526 int_msg:
20527@@ -744,7 +851,7 @@ fault_msg:
20528 * segment size, and 32-bit linear address value:
20529 */
20530
20531- .data
20532+.section .rodata,"a",@progbits
20533 .globl boot_gdt_descr
20534 .globl idt_descr
20535
20536@@ -753,7 +860,7 @@ fault_msg:
20537 .word 0 # 32 bit align gdt_desc.address
20538 boot_gdt_descr:
20539 .word __BOOT_DS+7
20540- .long boot_gdt - __PAGE_OFFSET
20541+ .long pa(boot_gdt)
20542
20543 .word 0 # 32-bit align idt_desc.address
20544 idt_descr:
20545@@ -764,7 +871,7 @@ idt_descr:
20546 .word 0 # 32 bit align gdt_desc.address
20547 ENTRY(early_gdt_descr)
20548 .word GDT_ENTRIES*8-1
20549- .long gdt_page /* Overwritten for secondary CPUs */
20550+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20551
20552 /*
20553 * The boot_gdt must mirror the equivalent in setup.S and is
20554@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
20555 .align L1_CACHE_BYTES
20556 ENTRY(boot_gdt)
20557 .fill GDT_ENTRY_BOOT_CS,8,0
20558- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20559- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20560+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20561+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20562+
20563+ .align PAGE_SIZE_asm
20564+ENTRY(cpu_gdt_table)
20565+ .rept NR_CPUS
20566+ .quad 0x0000000000000000 /* NULL descriptor */
20567+ .quad 0x0000000000000000 /* 0x0b reserved */
20568+ .quad 0x0000000000000000 /* 0x13 reserved */
20569+ .quad 0x0000000000000000 /* 0x1b reserved */
20570+
20571+#ifdef CONFIG_PAX_KERNEXEC
20572+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20573+#else
20574+ .quad 0x0000000000000000 /* 0x20 unused */
20575+#endif
20576+
20577+ .quad 0x0000000000000000 /* 0x28 unused */
20578+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20579+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20580+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20581+ .quad 0x0000000000000000 /* 0x4b reserved */
20582+ .quad 0x0000000000000000 /* 0x53 reserved */
20583+ .quad 0x0000000000000000 /* 0x5b reserved */
20584+
20585+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20586+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20587+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20588+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20589+
20590+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20591+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20592+
20593+ /*
20594+ * Segments used for calling PnP BIOS have byte granularity.
20595+ * The code segments and data segments have fixed 64k limits,
20596+ * the transfer segment sizes are set at run time.
20597+ */
20598+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20599+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20600+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20601+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20602+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20603+
20604+ /*
20605+ * The APM segments have byte granularity and their bases
20606+ * are set at run time. All have 64k limits.
20607+ */
20608+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20609+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20610+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20611+
20612+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20613+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20614+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20615+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20616+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20617+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20618+
20619+ /* Be sure this is zeroed to avoid false validations in Xen */
20620+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20621+ .endr
20622diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20623index a836860..bdeb7a5 100644
20624--- a/arch/x86/kernel/head_64.S
20625+++ b/arch/x86/kernel/head_64.S
20626@@ -20,6 +20,8 @@
20627 #include <asm/processor-flags.h>
20628 #include <asm/percpu.h>
20629 #include <asm/nops.h>
20630+#include <asm/cpufeature.h>
20631+#include <asm/alternative-asm.h>
20632
20633 #ifdef CONFIG_PARAVIRT
20634 #include <asm/asm-offsets.h>
20635@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20636 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20637 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20638 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20639+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20640+L3_VMALLOC_START = pud_index(VMALLOC_START)
20641+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20642+L3_VMALLOC_END = pud_index(VMALLOC_END)
20643+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20644+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20645
20646 .text
20647 __HEAD
20648@@ -89,11 +97,23 @@ startup_64:
20649 * Fixup the physical addresses in the page table
20650 */
20651 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
20652+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20653+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20654+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20655+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20656+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20657
20658- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20659- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20660+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
20661+#ifndef CONFIG_XEN
20662+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
20663+#endif
20664
20665- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20666+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20667+
20668+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20669+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
20670+
20671+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20672
20673 /*
20674 * Set up the identity mapping for the switchover. These
20675@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
20676 movq $(init_level4_pgt - __START_KERNEL_map), %rax
20677 1:
20678
20679- /* Enable PAE mode and PGE */
20680- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
20681+ /* Enable PAE mode and PSE/PGE */
20682+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
20683 movq %rcx, %cr4
20684
20685 /* Setup early boot stage 4 level pagetables. */
20686@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
20687 movl $MSR_EFER, %ecx
20688 rdmsr
20689 btsl $_EFER_SCE, %eax /* Enable System Call */
20690- btl $20,%edi /* No Execute supported? */
20691+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20692 jnc 1f
20693 btsl $_EFER_NX, %eax
20694 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
20695+ leaq init_level4_pgt(%rip), %rdi
20696+#ifndef CONFIG_EFI
20697+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20698+#endif
20699+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20700+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20701+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20702+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20703 1: wrmsr /* Make changes effective */
20704
20705 /* Setup cr0 */
20706@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
20707 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
20708 * address given in m16:64.
20709 */
20710+ pax_set_fptr_mask
20711 movq initial_code(%rip),%rax
20712 pushq $0 # fake return address to stop unwinder
20713 pushq $__KERNEL_CS # set correct cs
20714@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
20715 call dump_stack
20716 #ifdef CONFIG_KALLSYMS
20717 leaq early_idt_ripmsg(%rip),%rdi
20718- movq 40(%rsp),%rsi # %rip again
20719+ movq 88(%rsp),%rsi # %rip again
20720 call __print_symbol
20721 #endif
20722 #endif /* EARLY_PRINTK */
20723@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
20724 early_recursion_flag:
20725 .long 0
20726
20727+ .section .rodata,"a",@progbits
20728 #ifdef CONFIG_EARLY_PRINTK
20729 early_idt_msg:
20730 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20731@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
20732 NEXT_PAGE(early_dynamic_pgts)
20733 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
20734
20735- .data
20736+ .section .rodata,"a",@progbits
20737
20738-#ifndef CONFIG_XEN
20739 NEXT_PAGE(init_level4_pgt)
20740- .fill 512,8,0
20741-#else
20742-NEXT_PAGE(init_level4_pgt)
20743- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20744 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20745 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20746+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20747+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20748+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20749+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20750+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20751+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20752 .org init_level4_pgt + L4_START_KERNEL*8, 0
20753 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20754 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20755
20756+#ifdef CONFIG_PAX_PER_CPU_PGD
20757+NEXT_PAGE(cpu_pgd)
20758+ .rept NR_CPUS
20759+ .fill 512,8,0
20760+ .endr
20761+#endif
20762+
20763 NEXT_PAGE(level3_ident_pgt)
20764 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20765+#ifdef CONFIG_XEN
20766 .fill 511, 8, 0
20767+#else
20768+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20769+ .fill 510,8,0
20770+#endif
20771+
20772+NEXT_PAGE(level3_vmalloc_start_pgt)
20773+ .fill 512,8,0
20774+
20775+NEXT_PAGE(level3_vmalloc_end_pgt)
20776+ .fill 512,8,0
20777+
20778+NEXT_PAGE(level3_vmemmap_pgt)
20779+ .fill L3_VMEMMAP_START,8,0
20780+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20781+
20782 NEXT_PAGE(level2_ident_pgt)
20783- /* Since I easily can, map the first 1G.
20784+ /* Since I easily can, map the first 2G.
20785 * Don't set NX because code runs from these pages.
20786 */
20787- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20788-#endif
20789+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20790
20791 NEXT_PAGE(level3_kernel_pgt)
20792 .fill L3_START_KERNEL,8,0
20793@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
20794 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20795 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20796
20797+NEXT_PAGE(level2_vmemmap_pgt)
20798+ .fill 512,8,0
20799+
20800 NEXT_PAGE(level2_kernel_pgt)
20801 /*
20802 * 512 MB kernel mapping. We spend a full page on this pagetable
20803@@ -488,39 +544,64 @@ NEXT_PAGE(level2_kernel_pgt)
20804 KERNEL_IMAGE_SIZE/PMD_SIZE)
20805
20806 NEXT_PAGE(level2_fixmap_pgt)
20807- .fill 506,8,0
20808- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20809- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20810- .fill 5,8,0
20811+ .fill 507,8,0
20812+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20813+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20814+ .fill 4,8,0
20815
20816-NEXT_PAGE(level1_fixmap_pgt)
20817+NEXT_PAGE(level1_vsyscall_pgt)
20818 .fill 512,8,0
20819
20820 #undef PMDS
20821
20822- .data
20823+ .align PAGE_SIZE
20824+ENTRY(cpu_gdt_table)
20825+ .rept NR_CPUS
20826+ .quad 0x0000000000000000 /* NULL descriptor */
20827+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20828+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20829+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20830+ .quad 0x00cffb000000ffff /* __USER32_CS */
20831+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20832+ .quad 0x00affb000000ffff /* __USER_CS */
20833+
20834+#ifdef CONFIG_PAX_KERNEXEC
20835+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20836+#else
20837+ .quad 0x0 /* unused */
20838+#endif
20839+
20840+ .quad 0,0 /* TSS */
20841+ .quad 0,0 /* LDT */
20842+ .quad 0,0,0 /* three TLS descriptors */
20843+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20844+ /* asm/segment.h:GDT_ENTRIES must match this */
20845+
20846+ /* zero the remaining page */
20847+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20848+ .endr
20849+
20850 .align 16
20851 .globl early_gdt_descr
20852 early_gdt_descr:
20853 .word GDT_ENTRIES*8-1
20854 early_gdt_descr_base:
20855- .quad INIT_PER_CPU_VAR(gdt_page)
20856+ .quad cpu_gdt_table
20857
20858 ENTRY(phys_base)
20859 /* This must match the first entry in level2_kernel_pgt */
20860 .quad 0x0000000000000000
20861
20862 #include "../../x86/xen/xen-head.S"
20863-
20864- .section .bss, "aw", @nobits
20865+
20866+ .section .rodata,"a",@progbits
20867+NEXT_PAGE(empty_zero_page)
20868+ .skip PAGE_SIZE
20869+
20870 .align PAGE_SIZE
20871 ENTRY(idt_table)
20872- .skip IDT_ENTRIES * 16
20873+ .fill 512,8,0
20874
20875 .align L1_CACHE_BYTES
20876 ENTRY(nmi_idt_table)
20877- .skip IDT_ENTRIES * 16
20878-
20879- __PAGE_ALIGNED_BSS
20880-NEXT_PAGE(empty_zero_page)
20881- .skip PAGE_SIZE
20882+ .fill 512,8,0
20883diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20884index 0fa6912..37fce70 100644
20885--- a/arch/x86/kernel/i386_ksyms_32.c
20886+++ b/arch/x86/kernel/i386_ksyms_32.c
20887@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20888 EXPORT_SYMBOL(cmpxchg8b_emu);
20889 #endif
20890
20891+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20892+
20893 /* Networking helper routines. */
20894 EXPORT_SYMBOL(csum_partial_copy_generic);
20895+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20896+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20897
20898 EXPORT_SYMBOL(__get_user_1);
20899 EXPORT_SYMBOL(__get_user_2);
20900@@ -37,3 +41,7 @@ EXPORT_SYMBOL(strstr);
20901
20902 EXPORT_SYMBOL(csum_partial);
20903 EXPORT_SYMBOL(empty_zero_page);
20904+
20905+#ifdef CONFIG_PAX_KERNEXEC
20906+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20907+#endif
20908diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20909index cb33909..1163b40 100644
20910--- a/arch/x86/kernel/i387.c
20911+++ b/arch/x86/kernel/i387.c
20912@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20913 static inline bool interrupted_user_mode(void)
20914 {
20915 struct pt_regs *regs = get_irq_regs();
20916- return regs && user_mode_vm(regs);
20917+ return regs && user_mode(regs);
20918 }
20919
20920 /*
20921diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20922index 9a5c460..84868423 100644
20923--- a/arch/x86/kernel/i8259.c
20924+++ b/arch/x86/kernel/i8259.c
20925@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
20926 static void make_8259A_irq(unsigned int irq)
20927 {
20928 disable_irq_nosync(irq);
20929- io_apic_irqs &= ~(1<<irq);
20930+ io_apic_irqs &= ~(1UL<<irq);
20931 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
20932 i8259A_chip.name);
20933 enable_irq(irq);
20934@@ -209,7 +209,7 @@ spurious_8259A_irq:
20935 "spurious 8259A interrupt: IRQ%d.\n", irq);
20936 spurious_irq_mask |= irqmask;
20937 }
20938- atomic_inc(&irq_err_count);
20939+ atomic_inc_unchecked(&irq_err_count);
20940 /*
20941 * Theoretically we do not have to handle this IRQ,
20942 * but in Linux this does not cause problems and is
20943@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20944 /* (slave's support for AEOI in flat mode is to be investigated) */
20945 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20946
20947+ pax_open_kernel();
20948 if (auto_eoi)
20949 /*
20950 * In AEOI mode we just have to mask the interrupt
20951 * when acking.
20952 */
20953- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20954+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20955 else
20956- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20957+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20958+ pax_close_kernel();
20959
20960 udelay(100); /* wait for 8259A to initialize */
20961
20962diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20963index a979b5b..1d6db75 100644
20964--- a/arch/x86/kernel/io_delay.c
20965+++ b/arch/x86/kernel/io_delay.c
20966@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20967 * Quirk table for systems that misbehave (lock up, etc.) if port
20968 * 0x80 is used:
20969 */
20970-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20971+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20972 {
20973 .callback = dmi_io_delay_0xed_port,
20974 .ident = "Compaq Presario V6000",
20975diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20976index 4ddaf66..6292f4e 100644
20977--- a/arch/x86/kernel/ioport.c
20978+++ b/arch/x86/kernel/ioport.c
20979@@ -6,6 +6,7 @@
20980 #include <linux/sched.h>
20981 #include <linux/kernel.h>
20982 #include <linux/capability.h>
20983+#include <linux/security.h>
20984 #include <linux/errno.h>
20985 #include <linux/types.h>
20986 #include <linux/ioport.h>
20987@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20988
20989 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20990 return -EINVAL;
20991+#ifdef CONFIG_GRKERNSEC_IO
20992+ if (turn_on && grsec_disable_privio) {
20993+ gr_handle_ioperm();
20994+ return -EPERM;
20995+ }
20996+#endif
20997 if (turn_on && !capable(CAP_SYS_RAWIO))
20998 return -EPERM;
20999
21000@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
21001 * because the ->io_bitmap_max value must match the bitmap
21002 * contents:
21003 */
21004- tss = &per_cpu(init_tss, get_cpu());
21005+ tss = init_tss + get_cpu();
21006
21007 if (turn_on)
21008 bitmap_clear(t->io_bitmap_ptr, from, num);
21009@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
21010 return -EINVAL;
21011 /* Trying to gain more privileges? */
21012 if (level > old) {
21013+#ifdef CONFIG_GRKERNSEC_IO
21014+ if (grsec_disable_privio) {
21015+ gr_handle_iopl();
21016+ return -EPERM;
21017+ }
21018+#endif
21019 if (!capable(CAP_SYS_RAWIO))
21020 return -EPERM;
21021 }
21022diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
21023index ac0631d..ff7cb62 100644
21024--- a/arch/x86/kernel/irq.c
21025+++ b/arch/x86/kernel/irq.c
21026@@ -18,7 +18,7 @@
21027 #include <asm/mce.h>
21028 #include <asm/hw_irq.h>
21029
21030-atomic_t irq_err_count;
21031+atomic_unchecked_t irq_err_count;
21032
21033 /* Function pointer for generic interrupt vector handling */
21034 void (*x86_platform_ipi_callback)(void) = NULL;
21035@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
21036 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
21037 seq_printf(p, " Machine check polls\n");
21038 #endif
21039- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21040+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21041 #if defined(CONFIG_X86_IO_APIC)
21042- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21043+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21044 #endif
21045 return 0;
21046 }
21047@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21048
21049 u64 arch_irq_stat(void)
21050 {
21051- u64 sum = atomic_read(&irq_err_count);
21052+ u64 sum = atomic_read_unchecked(&irq_err_count);
21053 return sum;
21054 }
21055
21056diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21057index 344faf8..355f60d 100644
21058--- a/arch/x86/kernel/irq_32.c
21059+++ b/arch/x86/kernel/irq_32.c
21060@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21061 __asm__ __volatile__("andl %%esp,%0" :
21062 "=r" (sp) : "0" (THREAD_SIZE - 1));
21063
21064- return sp < (sizeof(struct thread_info) + STACK_WARN);
21065+ return sp < STACK_WARN;
21066 }
21067
21068 static void print_stack_overflow(void)
21069@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21070 * per-CPU IRQ handling contexts (thread information and stack)
21071 */
21072 union irq_ctx {
21073- struct thread_info tinfo;
21074- u32 stack[THREAD_SIZE/sizeof(u32)];
21075+ unsigned long previous_esp;
21076+ u32 stack[THREAD_SIZE/sizeof(u32)];
21077 } __attribute__((aligned(THREAD_SIZE)));
21078
21079 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21080@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21081 static inline int
21082 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21083 {
21084- union irq_ctx *curctx, *irqctx;
21085+ union irq_ctx *irqctx;
21086 u32 *isp, arg1, arg2;
21087
21088- curctx = (union irq_ctx *) current_thread_info();
21089 irqctx = __this_cpu_read(hardirq_ctx);
21090
21091 /*
21092@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21093 * handler) we can't do that and just have to keep using the
21094 * current stack (which is the irq stack already after all)
21095 */
21096- if (unlikely(curctx == irqctx))
21097+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21098 return 0;
21099
21100 /* build the stack frame on the IRQ stack */
21101- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21102- irqctx->tinfo.task = curctx->tinfo.task;
21103- irqctx->tinfo.previous_esp = current_stack_pointer;
21104+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21105+ irqctx->previous_esp = current_stack_pointer;
21106
21107- /* Copy the preempt_count so that the [soft]irq checks work. */
21108- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21109+#ifdef CONFIG_PAX_MEMORY_UDEREF
21110+ __set_fs(MAKE_MM_SEG(0));
21111+#endif
21112
21113 if (unlikely(overflow))
21114 call_on_stack(print_stack_overflow, isp);
21115@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21116 : "0" (irq), "1" (desc), "2" (isp),
21117 "D" (desc->handle_irq)
21118 : "memory", "cc", "ecx");
21119+
21120+#ifdef CONFIG_PAX_MEMORY_UDEREF
21121+ __set_fs(current_thread_info()->addr_limit);
21122+#endif
21123+
21124 return 1;
21125 }
21126
21127@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21128 */
21129 void __cpuinit irq_ctx_init(int cpu)
21130 {
21131- union irq_ctx *irqctx;
21132-
21133 if (per_cpu(hardirq_ctx, cpu))
21134 return;
21135
21136- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21137- THREADINFO_GFP,
21138- THREAD_SIZE_ORDER));
21139- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21140- irqctx->tinfo.cpu = cpu;
21141- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21142- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21143-
21144- per_cpu(hardirq_ctx, cpu) = irqctx;
21145-
21146- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21147- THREADINFO_GFP,
21148- THREAD_SIZE_ORDER));
21149- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21150- irqctx->tinfo.cpu = cpu;
21151- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21152-
21153- per_cpu(softirq_ctx, cpu) = irqctx;
21154+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21155+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21156+
21157+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21158+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21159
21160 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21161 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21162@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21163 asmlinkage void do_softirq(void)
21164 {
21165 unsigned long flags;
21166- struct thread_info *curctx;
21167 union irq_ctx *irqctx;
21168 u32 *isp;
21169
21170@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21171 local_irq_save(flags);
21172
21173 if (local_softirq_pending()) {
21174- curctx = current_thread_info();
21175 irqctx = __this_cpu_read(softirq_ctx);
21176- irqctx->tinfo.task = curctx->task;
21177- irqctx->tinfo.previous_esp = current_stack_pointer;
21178+ irqctx->previous_esp = current_stack_pointer;
21179
21180 /* build the stack frame on the softirq stack */
21181- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21182+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21183+
21184+#ifdef CONFIG_PAX_MEMORY_UDEREF
21185+ __set_fs(MAKE_MM_SEG(0));
21186+#endif
21187
21188 call_on_stack(__do_softirq, isp);
21189+
21190+#ifdef CONFIG_PAX_MEMORY_UDEREF
21191+ __set_fs(current_thread_info()->addr_limit);
21192+#endif
21193+
21194 /*
21195 * Shouldn't happen, we returned above if in_interrupt():
21196 */
21197@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21198 if (unlikely(!desc))
21199 return false;
21200
21201- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21202+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21203 if (unlikely(overflow))
21204 print_stack_overflow();
21205 desc->handle_irq(irq, desc);
21206diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21207index d04d3ec..ea4b374 100644
21208--- a/arch/x86/kernel/irq_64.c
21209+++ b/arch/x86/kernel/irq_64.c
21210@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21211 u64 estack_top, estack_bottom;
21212 u64 curbase = (u64)task_stack_page(current);
21213
21214- if (user_mode_vm(regs))
21215+ if (user_mode(regs))
21216 return;
21217
21218 if (regs->sp >= curbase + sizeof(struct thread_info) +
21219diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21220index dc1404b..bbc43e7 100644
21221--- a/arch/x86/kernel/kdebugfs.c
21222+++ b/arch/x86/kernel/kdebugfs.c
21223@@ -27,7 +27,7 @@ struct setup_data_node {
21224 u32 len;
21225 };
21226
21227-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21228+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21229 size_t count, loff_t *ppos)
21230 {
21231 struct setup_data_node *node = file->private_data;
21232diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21233index 836f832..a8bda67 100644
21234--- a/arch/x86/kernel/kgdb.c
21235+++ b/arch/x86/kernel/kgdb.c
21236@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21237 #ifdef CONFIG_X86_32
21238 switch (regno) {
21239 case GDB_SS:
21240- if (!user_mode_vm(regs))
21241+ if (!user_mode(regs))
21242 *(unsigned long *)mem = __KERNEL_DS;
21243 break;
21244 case GDB_SP:
21245- if (!user_mode_vm(regs))
21246+ if (!user_mode(regs))
21247 *(unsigned long *)mem = kernel_stack_pointer(regs);
21248 break;
21249 case GDB_GS:
21250@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21251 bp->attr.bp_addr = breakinfo[breakno].addr;
21252 bp->attr.bp_len = breakinfo[breakno].len;
21253 bp->attr.bp_type = breakinfo[breakno].type;
21254- info->address = breakinfo[breakno].addr;
21255+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21256+ info->address = ktla_ktva(breakinfo[breakno].addr);
21257+ else
21258+ info->address = breakinfo[breakno].addr;
21259 info->len = breakinfo[breakno].len;
21260 info->type = breakinfo[breakno].type;
21261 val = arch_install_hw_breakpoint(bp);
21262@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21263 case 'k':
21264 /* clear the trace bit */
21265 linux_regs->flags &= ~X86_EFLAGS_TF;
21266- atomic_set(&kgdb_cpu_doing_single_step, -1);
21267+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21268
21269 /* set the trace bit if we're stepping */
21270 if (remcomInBuffer[0] == 's') {
21271 linux_regs->flags |= X86_EFLAGS_TF;
21272- atomic_set(&kgdb_cpu_doing_single_step,
21273+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21274 raw_smp_processor_id());
21275 }
21276
21277@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21278
21279 switch (cmd) {
21280 case DIE_DEBUG:
21281- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21282+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21283 if (user_mode(regs))
21284 return single_step_cont(regs, args);
21285 break;
21286@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21287 #endif /* CONFIG_DEBUG_RODATA */
21288
21289 bpt->type = BP_BREAKPOINT;
21290- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21291+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21292 BREAK_INSTR_SIZE);
21293 if (err)
21294 return err;
21295- err = probe_kernel_write((char *)bpt->bpt_addr,
21296+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21297 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21298 #ifdef CONFIG_DEBUG_RODATA
21299 if (!err)
21300@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21301 return -EBUSY;
21302 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21303 BREAK_INSTR_SIZE);
21304- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21305+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21306 if (err)
21307 return err;
21308 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21309@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21310 if (mutex_is_locked(&text_mutex))
21311 goto knl_write;
21312 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21313- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21314+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21315 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21316 goto knl_write;
21317 return err;
21318 knl_write:
21319 #endif /* CONFIG_DEBUG_RODATA */
21320- return probe_kernel_write((char *)bpt->bpt_addr,
21321+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21322 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21323 }
21324
21325diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
21326index 211bce4..6e2580a 100644
21327--- a/arch/x86/kernel/kprobes/core.c
21328+++ b/arch/x86/kernel/kprobes/core.c
21329@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21330 s32 raddr;
21331 } __packed *insn;
21332
21333- insn = (struct __arch_relative_insn *)from;
21334+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21335+
21336+ pax_open_kernel();
21337 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21338 insn->op = op;
21339+ pax_close_kernel();
21340 }
21341
21342 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21343@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21344 kprobe_opcode_t opcode;
21345 kprobe_opcode_t *orig_opcodes = opcodes;
21346
21347- if (search_exception_tables((unsigned long)opcodes))
21348+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21349 return 0; /* Page fault may occur on this address. */
21350
21351 retry:
21352@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21353 * for the first byte, we can recover the original instruction
21354 * from it and kp->opcode.
21355 */
21356- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21357+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21358 buf[0] = kp->opcode;
21359- return (unsigned long)buf;
21360+ return ktva_ktla((unsigned long)buf);
21361 }
21362
21363 /*
21364@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21365 /* Another subsystem puts a breakpoint, failed to recover */
21366 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21367 return 0;
21368+ pax_open_kernel();
21369 memcpy(dest, insn.kaddr, insn.length);
21370+ pax_close_kernel();
21371
21372 #ifdef CONFIG_X86_64
21373 if (insn_rip_relative(&insn)) {
21374@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21375 return 0;
21376 }
21377 disp = (u8 *) dest + insn_offset_displacement(&insn);
21378+ pax_open_kernel();
21379 *(s32 *) disp = (s32) newdisp;
21380+ pax_close_kernel();
21381 }
21382 #endif
21383 return insn.length;
21384@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21385 * nor set current_kprobe, because it doesn't use single
21386 * stepping.
21387 */
21388- regs->ip = (unsigned long)p->ainsn.insn;
21389+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21390 preempt_enable_no_resched();
21391 return;
21392 }
21393@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21394 regs->flags &= ~X86_EFLAGS_IF;
21395 /* single step inline if the instruction is an int3 */
21396 if (p->opcode == BREAKPOINT_INSTRUCTION)
21397- regs->ip = (unsigned long)p->addr;
21398+ regs->ip = ktla_ktva((unsigned long)p->addr);
21399 else
21400- regs->ip = (unsigned long)p->ainsn.insn;
21401+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21402 }
21403
21404 /*
21405@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21406 setup_singlestep(p, regs, kcb, 0);
21407 return 1;
21408 }
21409- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21410+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21411 /*
21412 * The breakpoint instruction was removed right
21413 * after we hit it. Another cpu has removed
21414@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21415 " movq %rax, 152(%rsp)\n"
21416 RESTORE_REGS_STRING
21417 " popfq\n"
21418+#ifdef KERNEXEC_PLUGIN
21419+ " btsq $63,(%rsp)\n"
21420+#endif
21421 #else
21422 " pushf\n"
21423 SAVE_REGS_STRING
21424@@ -779,7 +789,7 @@ static void __kprobes
21425 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21426 {
21427 unsigned long *tos = stack_addr(regs);
21428- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21429+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21430 unsigned long orig_ip = (unsigned long)p->addr;
21431 kprobe_opcode_t *insn = p->ainsn.insn;
21432
21433@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21434 struct die_args *args = data;
21435 int ret = NOTIFY_DONE;
21436
21437- if (args->regs && user_mode_vm(args->regs))
21438+ if (args->regs && user_mode(args->regs))
21439 return ret;
21440
21441 switch (val) {
21442diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
21443index 76dc6f0..66bdfc3 100644
21444--- a/arch/x86/kernel/kprobes/opt.c
21445+++ b/arch/x86/kernel/kprobes/opt.c
21446@@ -79,6 +79,7 @@ found:
21447 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
21448 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
21449 {
21450+ pax_open_kernel();
21451 #ifdef CONFIG_X86_64
21452 *addr++ = 0x48;
21453 *addr++ = 0xbf;
21454@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
21455 *addr++ = 0xb8;
21456 #endif
21457 *(unsigned long *)addr = val;
21458+ pax_close_kernel();
21459 }
21460
21461 static void __used __kprobes kprobes_optinsn_template_holder(void)
21462@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21463 * Verify if the address gap is in 2GB range, because this uses
21464 * a relative jump.
21465 */
21466- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21467+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21468 if (abs(rel) > 0x7fffffff)
21469 return -ERANGE;
21470
21471@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21472 op->optinsn.size = ret;
21473
21474 /* Copy arch-dep-instance from template */
21475- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21476+ pax_open_kernel();
21477+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21478+ pax_close_kernel();
21479
21480 /* Set probe information */
21481 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21482
21483 /* Set probe function call */
21484- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21485+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21486
21487 /* Set returning jmp instruction at the tail of out-of-line buffer */
21488- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21489+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21490 (u8 *)op->kp.addr + op->optinsn.size);
21491
21492 flush_icache_range((unsigned long) buf,
21493@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21494 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21495
21496 /* Backup instructions which will be replaced by jump address */
21497- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21498+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21499 RELATIVE_ADDR_SIZE);
21500
21501 insn_buf[0] = RELATIVEJUMP_OPCODE;
21502@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21503 /* This kprobe is really able to run optimized path. */
21504 op = container_of(p, struct optimized_kprobe, kp);
21505 /* Detour through copied instructions */
21506- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21507+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21508 if (!reenter)
21509 reset_current_kprobe();
21510 preempt_enable_no_resched();
21511diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21512index cd6d9a5..16245a4 100644
21513--- a/arch/x86/kernel/kvm.c
21514+++ b/arch/x86/kernel/kvm.c
21515@@ -455,7 +455,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21516 return NOTIFY_OK;
21517 }
21518
21519-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21520+static struct notifier_block kvm_cpu_notifier = {
21521 .notifier_call = kvm_cpu_notify,
21522 };
21523 #endif
21524diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21525index ebc9873..1b9724b 100644
21526--- a/arch/x86/kernel/ldt.c
21527+++ b/arch/x86/kernel/ldt.c
21528@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21529 if (reload) {
21530 #ifdef CONFIG_SMP
21531 preempt_disable();
21532- load_LDT(pc);
21533+ load_LDT_nolock(pc);
21534 if (!cpumask_equal(mm_cpumask(current->mm),
21535 cpumask_of(smp_processor_id())))
21536 smp_call_function(flush_ldt, current->mm, 1);
21537 preempt_enable();
21538 #else
21539- load_LDT(pc);
21540+ load_LDT_nolock(pc);
21541 #endif
21542 }
21543 if (oldsize) {
21544@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21545 return err;
21546
21547 for (i = 0; i < old->size; i++)
21548- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21549+ write_ldt_entry(new->ldt, i, old->ldt + i);
21550 return 0;
21551 }
21552
21553@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21554 retval = copy_ldt(&mm->context, &old_mm->context);
21555 mutex_unlock(&old_mm->context.lock);
21556 }
21557+
21558+ if (tsk == current) {
21559+ mm->context.vdso = 0;
21560+
21561+#ifdef CONFIG_X86_32
21562+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21563+ mm->context.user_cs_base = 0UL;
21564+ mm->context.user_cs_limit = ~0UL;
21565+
21566+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21567+ cpus_clear(mm->context.cpu_user_cs_mask);
21568+#endif
21569+
21570+#endif
21571+#endif
21572+
21573+ }
21574+
21575 return retval;
21576 }
21577
21578@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21579 }
21580 }
21581
21582+#ifdef CONFIG_PAX_SEGMEXEC
21583+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21584+ error = -EINVAL;
21585+ goto out_unlock;
21586+ }
21587+#endif
21588+
21589 fill_ldt(&ldt, &ldt_info);
21590 if (oldmode)
21591 ldt.avl = 0;
21592diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21593index 5b19e4d..6476a76 100644
21594--- a/arch/x86/kernel/machine_kexec_32.c
21595+++ b/arch/x86/kernel/machine_kexec_32.c
21596@@ -26,7 +26,7 @@
21597 #include <asm/cacheflush.h>
21598 #include <asm/debugreg.h>
21599
21600-static void set_idt(void *newidt, __u16 limit)
21601+static void set_idt(struct desc_struct *newidt, __u16 limit)
21602 {
21603 struct desc_ptr curidt;
21604
21605@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21606 }
21607
21608
21609-static void set_gdt(void *newgdt, __u16 limit)
21610+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21611 {
21612 struct desc_ptr curgdt;
21613
21614@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21615 }
21616
21617 control_page = page_address(image->control_code_page);
21618- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21619+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21620
21621 relocate_kernel_ptr = control_page;
21622 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21623diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21624index 22db92b..d546bec 100644
21625--- a/arch/x86/kernel/microcode_core.c
21626+++ b/arch/x86/kernel/microcode_core.c
21627@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21628 return NOTIFY_OK;
21629 }
21630
21631-static struct notifier_block __refdata mc_cpu_notifier = {
21632+static struct notifier_block mc_cpu_notifier = {
21633 .notifier_call = mc_cpu_callback,
21634 };
21635
21636diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21637index 5fb2ceb..3ae90bb 100644
21638--- a/arch/x86/kernel/microcode_intel.c
21639+++ b/arch/x86/kernel/microcode_intel.c
21640@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21641
21642 static int get_ucode_user(void *to, const void *from, size_t n)
21643 {
21644- return copy_from_user(to, from, n);
21645+ return copy_from_user(to, (const void __force_user *)from, n);
21646 }
21647
21648 static enum ucode_state
21649 request_microcode_user(int cpu, const void __user *buf, size_t size)
21650 {
21651- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21652+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21653 }
21654
21655 static void microcode_fini_cpu(int cpu)
21656diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21657index 216a4d7..228255a 100644
21658--- a/arch/x86/kernel/module.c
21659+++ b/arch/x86/kernel/module.c
21660@@ -43,15 +43,60 @@ do { \
21661 } while (0)
21662 #endif
21663
21664-void *module_alloc(unsigned long size)
21665+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21666 {
21667- if (PAGE_ALIGN(size) > MODULES_LEN)
21668+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21669 return NULL;
21670 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21671- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21672+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21673 -1, __builtin_return_address(0));
21674 }
21675
21676+void *module_alloc(unsigned long size)
21677+{
21678+
21679+#ifdef CONFIG_PAX_KERNEXEC
21680+ return __module_alloc(size, PAGE_KERNEL);
21681+#else
21682+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21683+#endif
21684+
21685+}
21686+
21687+#ifdef CONFIG_PAX_KERNEXEC
21688+#ifdef CONFIG_X86_32
21689+void *module_alloc_exec(unsigned long size)
21690+{
21691+ struct vm_struct *area;
21692+
21693+ if (size == 0)
21694+ return NULL;
21695+
21696+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21697+ return area ? area->addr : NULL;
21698+}
21699+EXPORT_SYMBOL(module_alloc_exec);
21700+
21701+void module_free_exec(struct module *mod, void *module_region)
21702+{
21703+ vunmap(module_region);
21704+}
21705+EXPORT_SYMBOL(module_free_exec);
21706+#else
21707+void module_free_exec(struct module *mod, void *module_region)
21708+{
21709+ module_free(mod, module_region);
21710+}
21711+EXPORT_SYMBOL(module_free_exec);
21712+
21713+void *module_alloc_exec(unsigned long size)
21714+{
21715+ return __module_alloc(size, PAGE_KERNEL_RX);
21716+}
21717+EXPORT_SYMBOL(module_alloc_exec);
21718+#endif
21719+#endif
21720+
21721 #ifdef CONFIG_X86_32
21722 int apply_relocate(Elf32_Shdr *sechdrs,
21723 const char *strtab,
21724@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21725 unsigned int i;
21726 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21727 Elf32_Sym *sym;
21728- uint32_t *location;
21729+ uint32_t *plocation, location;
21730
21731 DEBUGP("Applying relocate section %u to %u\n",
21732 relsec, sechdrs[relsec].sh_info);
21733 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21734 /* This is where to make the change */
21735- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21736- + rel[i].r_offset;
21737+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21738+ location = (uint32_t)plocation;
21739+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21740+ plocation = ktla_ktva((void *)plocation);
21741 /* This is the symbol it is referring to. Note that all
21742 undefined symbols have been resolved. */
21743 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21744@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21745 switch (ELF32_R_TYPE(rel[i].r_info)) {
21746 case R_386_32:
21747 /* We add the value into the location given */
21748- *location += sym->st_value;
21749+ pax_open_kernel();
21750+ *plocation += sym->st_value;
21751+ pax_close_kernel();
21752 break;
21753 case R_386_PC32:
21754 /* Add the value, subtract its position */
21755- *location += sym->st_value - (uint32_t)location;
21756+ pax_open_kernel();
21757+ *plocation += sym->st_value - location;
21758+ pax_close_kernel();
21759 break;
21760 default:
21761 pr_err("%s: Unknown relocation: %u\n",
21762@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21763 case R_X86_64_NONE:
21764 break;
21765 case R_X86_64_64:
21766+ pax_open_kernel();
21767 *(u64 *)loc = val;
21768+ pax_close_kernel();
21769 break;
21770 case R_X86_64_32:
21771+ pax_open_kernel();
21772 *(u32 *)loc = val;
21773+ pax_close_kernel();
21774 if (val != *(u32 *)loc)
21775 goto overflow;
21776 break;
21777 case R_X86_64_32S:
21778+ pax_open_kernel();
21779 *(s32 *)loc = val;
21780+ pax_close_kernel();
21781 if ((s64)val != *(s32 *)loc)
21782 goto overflow;
21783 break;
21784 case R_X86_64_PC32:
21785 val -= (u64)loc;
21786+ pax_open_kernel();
21787 *(u32 *)loc = val;
21788+ pax_close_kernel();
21789+
21790 #if 0
21791 if ((s64)val != *(s32 *)loc)
21792 goto overflow;
21793diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21794index ce13049..e2e9c3c 100644
21795--- a/arch/x86/kernel/msr.c
21796+++ b/arch/x86/kernel/msr.c
21797@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21798 return notifier_from_errno(err);
21799 }
21800
21801-static struct notifier_block __refdata msr_class_cpu_notifier = {
21802+static struct notifier_block msr_class_cpu_notifier = {
21803 .notifier_call = msr_class_cpu_callback,
21804 };
21805
21806diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21807index 6030805..2d33f21 100644
21808--- a/arch/x86/kernel/nmi.c
21809+++ b/arch/x86/kernel/nmi.c
21810@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21811 return handled;
21812 }
21813
21814-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21815+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21816 {
21817 struct nmi_desc *desc = nmi_to_desc(type);
21818 unsigned long flags;
21819@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21820 * event confuses some handlers (kdump uses this flag)
21821 */
21822 if (action->flags & NMI_FLAG_FIRST)
21823- list_add_rcu(&action->list, &desc->head);
21824+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21825 else
21826- list_add_tail_rcu(&action->list, &desc->head);
21827+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21828
21829 spin_unlock_irqrestore(&desc->lock, flags);
21830 return 0;
21831@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21832 if (!strcmp(n->name, name)) {
21833 WARN(in_nmi(),
21834 "Trying to free NMI (%s) from NMI context!\n", n->name);
21835- list_del_rcu(&n->list);
21836+ pax_list_del_rcu((struct list_head *)&n->list);
21837 break;
21838 }
21839 }
21840@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21841 dotraplinkage notrace __kprobes void
21842 do_nmi(struct pt_regs *regs, long error_code)
21843 {
21844+
21845+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21846+ if (!user_mode(regs)) {
21847+ unsigned long cs = regs->cs & 0xFFFF;
21848+ unsigned long ip = ktva_ktla(regs->ip);
21849+
21850+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21851+ regs->ip = ip;
21852+ }
21853+#endif
21854+
21855 nmi_nesting_preprocess(regs);
21856
21857 nmi_enter();
21858diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21859index 6d9582e..f746287 100644
21860--- a/arch/x86/kernel/nmi_selftest.c
21861+++ b/arch/x86/kernel/nmi_selftest.c
21862@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21863 {
21864 /* trap all the unknown NMIs we may generate */
21865 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21866- __initdata);
21867+ __initconst);
21868 }
21869
21870 static void __init cleanup_nmi_testsuite(void)
21871@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21872 unsigned long timeout;
21873
21874 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21875- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21876+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21877 nmi_fail = FAILURE;
21878 return;
21879 }
21880diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21881index 676b8c7..870ba04 100644
21882--- a/arch/x86/kernel/paravirt-spinlocks.c
21883+++ b/arch/x86/kernel/paravirt-spinlocks.c
21884@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21885 arch_spin_lock(lock);
21886 }
21887
21888-struct pv_lock_ops pv_lock_ops = {
21889+struct pv_lock_ops pv_lock_ops __read_only = {
21890 #ifdef CONFIG_SMP
21891 .spin_is_locked = __ticket_spin_is_locked,
21892 .spin_is_contended = __ticket_spin_is_contended,
21893diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21894index cd6de64..27c6af0 100644
21895--- a/arch/x86/kernel/paravirt.c
21896+++ b/arch/x86/kernel/paravirt.c
21897@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21898 {
21899 return x;
21900 }
21901+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21902+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21903+#endif
21904
21905 void __init default_banner(void)
21906 {
21907@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21908 if (opfunc == NULL)
21909 /* If there's no function, patch it with a ud2a (BUG) */
21910 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21911- else if (opfunc == _paravirt_nop)
21912+ else if (opfunc == (void *)_paravirt_nop)
21913 /* If the operation is a nop, then nop the callsite */
21914 ret = paravirt_patch_nop();
21915
21916 /* identity functions just return their single argument */
21917- else if (opfunc == _paravirt_ident_32)
21918+ else if (opfunc == (void *)_paravirt_ident_32)
21919 ret = paravirt_patch_ident_32(insnbuf, len);
21920- else if (opfunc == _paravirt_ident_64)
21921+ else if (opfunc == (void *)_paravirt_ident_64)
21922 ret = paravirt_patch_ident_64(insnbuf, len);
21923+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21924+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21925+ ret = paravirt_patch_ident_64(insnbuf, len);
21926+#endif
21927
21928 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21929 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21930@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21931 if (insn_len > len || start == NULL)
21932 insn_len = len;
21933 else
21934- memcpy(insnbuf, start, insn_len);
21935+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21936
21937 return insn_len;
21938 }
21939@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
21940 return this_cpu_read(paravirt_lazy_mode);
21941 }
21942
21943-struct pv_info pv_info = {
21944+struct pv_info pv_info __read_only = {
21945 .name = "bare hardware",
21946 .paravirt_enabled = 0,
21947 .kernel_rpl = 0,
21948@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21949 #endif
21950 };
21951
21952-struct pv_init_ops pv_init_ops = {
21953+struct pv_init_ops pv_init_ops __read_only = {
21954 .patch = native_patch,
21955 };
21956
21957-struct pv_time_ops pv_time_ops = {
21958+struct pv_time_ops pv_time_ops __read_only = {
21959 .sched_clock = native_sched_clock,
21960 .steal_clock = native_steal_clock,
21961 };
21962
21963-struct pv_irq_ops pv_irq_ops = {
21964+struct pv_irq_ops pv_irq_ops __read_only = {
21965 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21966 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21967 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21968@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21969 #endif
21970 };
21971
21972-struct pv_cpu_ops pv_cpu_ops = {
21973+struct pv_cpu_ops pv_cpu_ops __read_only = {
21974 .cpuid = native_cpuid,
21975 .get_debugreg = native_get_debugreg,
21976 .set_debugreg = native_set_debugreg,
21977@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21978 .end_context_switch = paravirt_nop,
21979 };
21980
21981-struct pv_apic_ops pv_apic_ops = {
21982+struct pv_apic_ops pv_apic_ops __read_only= {
21983 #ifdef CONFIG_X86_LOCAL_APIC
21984 .startup_ipi_hook = paravirt_nop,
21985 #endif
21986 };
21987
21988-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21989+#ifdef CONFIG_X86_32
21990+#ifdef CONFIG_X86_PAE
21991+/* 64-bit pagetable entries */
21992+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21993+#else
21994 /* 32-bit pagetable entries */
21995 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21996+#endif
21997 #else
21998 /* 64-bit pagetable entries */
21999 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
22000 #endif
22001
22002-struct pv_mmu_ops pv_mmu_ops = {
22003+struct pv_mmu_ops pv_mmu_ops __read_only = {
22004
22005 .read_cr2 = native_read_cr2,
22006 .write_cr2 = native_write_cr2,
22007@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
22008 .make_pud = PTE_IDENT,
22009
22010 .set_pgd = native_set_pgd,
22011+ .set_pgd_batched = native_set_pgd_batched,
22012 #endif
22013 #endif /* PAGETABLE_LEVELS >= 3 */
22014
22015@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
22016 },
22017
22018 .set_fixmap = native_set_fixmap,
22019+
22020+#ifdef CONFIG_PAX_KERNEXEC
22021+ .pax_open_kernel = native_pax_open_kernel,
22022+ .pax_close_kernel = native_pax_close_kernel,
22023+#endif
22024+
22025 };
22026
22027 EXPORT_SYMBOL_GPL(pv_time_ops);
22028diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
22029index 299d493..2ccb0ee 100644
22030--- a/arch/x86/kernel/pci-calgary_64.c
22031+++ b/arch/x86/kernel/pci-calgary_64.c
22032@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
22033 tce_space = be64_to_cpu(readq(target));
22034 tce_space = tce_space & TAR_SW_BITS;
22035
22036- tce_space = tce_space & (~specified_table_size);
22037+ tce_space = tce_space & (~(unsigned long)specified_table_size);
22038 info->tce_space = (u64 *)__va(tce_space);
22039 }
22040 }
22041diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22042index 35ccf75..7a15747 100644
22043--- a/arch/x86/kernel/pci-iommu_table.c
22044+++ b/arch/x86/kernel/pci-iommu_table.c
22045@@ -2,7 +2,7 @@
22046 #include <asm/iommu_table.h>
22047 #include <linux/string.h>
22048 #include <linux/kallsyms.h>
22049-
22050+#include <linux/sched.h>
22051
22052 #define DEBUG 1
22053
22054diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22055index 6c483ba..d10ce2f 100644
22056--- a/arch/x86/kernel/pci-swiotlb.c
22057+++ b/arch/x86/kernel/pci-swiotlb.c
22058@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22059 void *vaddr, dma_addr_t dma_addr,
22060 struct dma_attrs *attrs)
22061 {
22062- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22063+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22064 }
22065
22066 static struct dma_map_ops swiotlb_dma_ops = {
22067diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22068index 81a5f5e..20f8b58 100644
22069--- a/arch/x86/kernel/process.c
22070+++ b/arch/x86/kernel/process.c
22071@@ -36,7 +36,8 @@
22072 * section. Since TSS's are completely CPU-local, we want them
22073 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22074 */
22075-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22076+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22077+EXPORT_SYMBOL(init_tss);
22078
22079 #ifdef CONFIG_X86_64
22080 static DEFINE_PER_CPU(unsigned char, is_idle);
22081@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22082 task_xstate_cachep =
22083 kmem_cache_create("task_xstate", xstate_size,
22084 __alignof__(union thread_xstate),
22085- SLAB_PANIC | SLAB_NOTRACK, NULL);
22086+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22087 }
22088
22089 /*
22090@@ -105,7 +106,7 @@ void exit_thread(void)
22091 unsigned long *bp = t->io_bitmap_ptr;
22092
22093 if (bp) {
22094- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22095+ struct tss_struct *tss = init_tss + get_cpu();
22096
22097 t->io_bitmap_ptr = NULL;
22098 clear_thread_flag(TIF_IO_BITMAP);
22099@@ -125,6 +126,9 @@ void flush_thread(void)
22100 {
22101 struct task_struct *tsk = current;
22102
22103+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22104+ loadsegment(gs, 0);
22105+#endif
22106 flush_ptrace_hw_breakpoint(tsk);
22107 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22108 drop_init_fpu(tsk);
22109@@ -271,7 +275,7 @@ static void __exit_idle(void)
22110 void exit_idle(void)
22111 {
22112 /* idle loop has pid 0 */
22113- if (current->pid)
22114+ if (task_pid_nr(current))
22115 return;
22116 __exit_idle();
22117 }
22118@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
22119 return ret;
22120 }
22121 #endif
22122-void stop_this_cpu(void *dummy)
22123+__noreturn void stop_this_cpu(void *dummy)
22124 {
22125 local_irq_disable();
22126 /*
22127@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
22128 }
22129 early_param("idle", idle_setup);
22130
22131-unsigned long arch_align_stack(unsigned long sp)
22132+#ifdef CONFIG_PAX_RANDKSTACK
22133+void pax_randomize_kstack(struct pt_regs *regs)
22134 {
22135- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22136- sp -= get_random_int() % 8192;
22137- return sp & ~0xf;
22138-}
22139+ struct thread_struct *thread = &current->thread;
22140+ unsigned long time;
22141
22142-unsigned long arch_randomize_brk(struct mm_struct *mm)
22143-{
22144- unsigned long range_end = mm->brk + 0x02000000;
22145- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22146-}
22147+ if (!randomize_va_space)
22148+ return;
22149+
22150+ if (v8086_mode(regs))
22151+ return;
22152
22153+ rdtscl(time);
22154+
22155+ /* P4 seems to return a 0 LSB, ignore it */
22156+#ifdef CONFIG_MPENTIUM4
22157+ time &= 0x3EUL;
22158+ time <<= 2;
22159+#elif defined(CONFIG_X86_64)
22160+ time &= 0xFUL;
22161+ time <<= 4;
22162+#else
22163+ time &= 0x1FUL;
22164+ time <<= 3;
22165+#endif
22166+
22167+ thread->sp0 ^= time;
22168+ load_sp0(init_tss + smp_processor_id(), thread);
22169+
22170+#ifdef CONFIG_X86_64
22171+ this_cpu_write(kernel_stack, thread->sp0);
22172+#endif
22173+}
22174+#endif
22175diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22176index 7305f7d..22f73d6 100644
22177--- a/arch/x86/kernel/process_32.c
22178+++ b/arch/x86/kernel/process_32.c
22179@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22180 unsigned long thread_saved_pc(struct task_struct *tsk)
22181 {
22182 return ((unsigned long *)tsk->thread.sp)[3];
22183+//XXX return tsk->thread.eip;
22184 }
22185
22186 void __show_regs(struct pt_regs *regs, int all)
22187@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
22188 unsigned long sp;
22189 unsigned short ss, gs;
22190
22191- if (user_mode_vm(regs)) {
22192+ if (user_mode(regs)) {
22193 sp = regs->sp;
22194 ss = regs->ss & 0xffff;
22195- gs = get_user_gs(regs);
22196 } else {
22197 sp = kernel_stack_pointer(regs);
22198 savesegment(ss, ss);
22199- savesegment(gs, gs);
22200 }
22201+ gs = get_user_gs(regs);
22202
22203 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22204 (u16)regs->cs, regs->ip, regs->flags,
22205- smp_processor_id());
22206+ raw_smp_processor_id());
22207 print_symbol("EIP is at %s\n", regs->ip);
22208
22209 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22210@@ -128,20 +128,21 @@ void release_thread(struct task_struct *dead_task)
22211 int copy_thread(unsigned long clone_flags, unsigned long sp,
22212 unsigned long arg, struct task_struct *p)
22213 {
22214- struct pt_regs *childregs = task_pt_regs(p);
22215+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22216 struct task_struct *tsk;
22217 int err;
22218
22219 p->thread.sp = (unsigned long) childregs;
22220 p->thread.sp0 = (unsigned long) (childregs+1);
22221+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22222
22223 if (unlikely(p->flags & PF_KTHREAD)) {
22224 /* kernel thread */
22225 memset(childregs, 0, sizeof(struct pt_regs));
22226 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22227- task_user_gs(p) = __KERNEL_STACK_CANARY;
22228- childregs->ds = __USER_DS;
22229- childregs->es = __USER_DS;
22230+ savesegment(gs, childregs->gs);
22231+ childregs->ds = __KERNEL_DS;
22232+ childregs->es = __KERNEL_DS;
22233 childregs->fs = __KERNEL_PERCPU;
22234 childregs->bx = sp; /* function */
22235 childregs->bp = arg;
22236@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22237 struct thread_struct *prev = &prev_p->thread,
22238 *next = &next_p->thread;
22239 int cpu = smp_processor_id();
22240- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22241+ struct tss_struct *tss = init_tss + cpu;
22242 fpu_switch_t fpu;
22243
22244 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22245@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22246 */
22247 lazy_save_gs(prev->gs);
22248
22249+#ifdef CONFIG_PAX_MEMORY_UDEREF
22250+ __set_fs(task_thread_info(next_p)->addr_limit);
22251+#endif
22252+
22253 /*
22254 * Load the per-thread Thread-Local Storage descriptor.
22255 */
22256@@ -302,6 +307,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22257 */
22258 arch_end_context_switch(next_p);
22259
22260+ this_cpu_write(current_task, next_p);
22261+ this_cpu_write(current_tinfo, &next_p->tinfo);
22262+
22263 /*
22264 * Restore %gs if needed (which is common)
22265 */
22266@@ -310,8 +318,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22267
22268 switch_fpu_finish(next_p, fpu);
22269
22270- this_cpu_write(current_task, next_p);
22271-
22272 return prev_p;
22273 }
22274
22275@@ -341,4 +347,3 @@ unsigned long get_wchan(struct task_struct *p)
22276 } while (count++ < 16);
22277 return 0;
22278 }
22279-
22280diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22281index 355ae06..4530766 100644
22282--- a/arch/x86/kernel/process_64.c
22283+++ b/arch/x86/kernel/process_64.c
22284@@ -151,10 +151,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22285 struct pt_regs *childregs;
22286 struct task_struct *me = current;
22287
22288- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22289+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22290 childregs = task_pt_regs(p);
22291 p->thread.sp = (unsigned long) childregs;
22292 p->thread.usersp = me->thread.usersp;
22293+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22294 set_tsk_thread_flag(p, TIF_FORK);
22295 p->fpu_counter = 0;
22296 p->thread.io_bitmap_ptr = NULL;
22297@@ -273,7 +274,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22298 struct thread_struct *prev = &prev_p->thread;
22299 struct thread_struct *next = &next_p->thread;
22300 int cpu = smp_processor_id();
22301- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22302+ struct tss_struct *tss = init_tss + cpu;
22303 unsigned fsindex, gsindex;
22304 fpu_switch_t fpu;
22305
22306@@ -355,10 +356,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22307 prev->usersp = this_cpu_read(old_rsp);
22308 this_cpu_write(old_rsp, next->usersp);
22309 this_cpu_write(current_task, next_p);
22310+ this_cpu_write(current_tinfo, &next_p->tinfo);
22311
22312- this_cpu_write(kernel_stack,
22313- (unsigned long)task_stack_page(next_p) +
22314- THREAD_SIZE - KERNEL_STACK_OFFSET);
22315+ this_cpu_write(kernel_stack, next->sp0);
22316
22317 /*
22318 * Now maybe reload the debug registers and handle I/O bitmaps
22319@@ -427,12 +427,11 @@ unsigned long get_wchan(struct task_struct *p)
22320 if (!p || p == current || p->state == TASK_RUNNING)
22321 return 0;
22322 stack = (unsigned long)task_stack_page(p);
22323- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22324+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22325 return 0;
22326 fp = *(u64 *)(p->thread.sp);
22327 do {
22328- if (fp < (unsigned long)stack ||
22329- fp >= (unsigned long)stack+THREAD_SIZE)
22330+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22331 return 0;
22332 ip = *(u64 *)(fp+8);
22333 if (!in_sched_functions(ip))
22334diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22335index 29a8120..a50b5ee 100644
22336--- a/arch/x86/kernel/ptrace.c
22337+++ b/arch/x86/kernel/ptrace.c
22338@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22339 {
22340 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22341 unsigned long sp = (unsigned long)&regs->sp;
22342- struct thread_info *tinfo;
22343
22344- if (context == (sp & ~(THREAD_SIZE - 1)))
22345+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22346 return sp;
22347
22348- tinfo = (struct thread_info *)context;
22349- if (tinfo->previous_esp)
22350- return tinfo->previous_esp;
22351+ sp = *(unsigned long *)context;
22352+ if (sp)
22353+ return sp;
22354
22355 return (unsigned long)regs;
22356 }
22357@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22358 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22359 {
22360 int i;
22361- int dr7 = 0;
22362+ unsigned long dr7 = 0;
22363 struct arch_hw_breakpoint *info;
22364
22365 for (i = 0; i < HBP_NUM; i++) {
22366@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22367 unsigned long addr, unsigned long data)
22368 {
22369 int ret;
22370- unsigned long __user *datap = (unsigned long __user *)data;
22371+ unsigned long __user *datap = (__force unsigned long __user *)data;
22372
22373 switch (request) {
22374 /* read the word at location addr in the USER area. */
22375@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22376 if ((int) addr < 0)
22377 return -EIO;
22378 ret = do_get_thread_area(child, addr,
22379- (struct user_desc __user *)data);
22380+ (__force struct user_desc __user *) data);
22381 break;
22382
22383 case PTRACE_SET_THREAD_AREA:
22384 if ((int) addr < 0)
22385 return -EIO;
22386 ret = do_set_thread_area(child, addr,
22387- (struct user_desc __user *)data, 0);
22388+ (__force struct user_desc __user *) data, 0);
22389 break;
22390 #endif
22391
22392@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22393
22394 #ifdef CONFIG_X86_64
22395
22396-static struct user_regset x86_64_regsets[] __read_mostly = {
22397+static user_regset_no_const x86_64_regsets[] __read_only = {
22398 [REGSET_GENERAL] = {
22399 .core_note_type = NT_PRSTATUS,
22400 .n = sizeof(struct user_regs_struct) / sizeof(long),
22401@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22402 #endif /* CONFIG_X86_64 */
22403
22404 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22405-static struct user_regset x86_32_regsets[] __read_mostly = {
22406+static user_regset_no_const x86_32_regsets[] __read_only = {
22407 [REGSET_GENERAL] = {
22408 .core_note_type = NT_PRSTATUS,
22409 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22410@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22411 */
22412 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22413
22414-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22415+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22416 {
22417 #ifdef CONFIG_X86_64
22418 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22419@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22420 memset(info, 0, sizeof(*info));
22421 info->si_signo = SIGTRAP;
22422 info->si_code = si_code;
22423- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22424+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22425 }
22426
22427 void user_single_step_siginfo(struct task_struct *tsk,
22428@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22429 # define IS_IA32 0
22430 #endif
22431
22432+#ifdef CONFIG_GRKERNSEC_SETXID
22433+extern void gr_delayed_cred_worker(void);
22434+#endif
22435+
22436 /*
22437 * We must return the syscall number to actually look up in the table.
22438 * This can be -1L to skip running any syscall at all.
22439@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22440
22441 user_exit();
22442
22443+#ifdef CONFIG_GRKERNSEC_SETXID
22444+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22445+ gr_delayed_cred_worker();
22446+#endif
22447+
22448 /*
22449 * If we stepped into a sysenter/syscall insn, it trapped in
22450 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22451@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22452 */
22453 user_exit();
22454
22455+#ifdef CONFIG_GRKERNSEC_SETXID
22456+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22457+ gr_delayed_cred_worker();
22458+#endif
22459+
22460 audit_syscall_exit(regs);
22461
22462 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22463diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22464index 2cb9470..ff1fd80 100644
22465--- a/arch/x86/kernel/pvclock.c
22466+++ b/arch/x86/kernel/pvclock.c
22467@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22468 return pv_tsc_khz;
22469 }
22470
22471-static atomic64_t last_value = ATOMIC64_INIT(0);
22472+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22473
22474 void pvclock_resume(void)
22475 {
22476- atomic64_set(&last_value, 0);
22477+ atomic64_set_unchecked(&last_value, 0);
22478 }
22479
22480 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22481@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22482 * updating at the same time, and one of them could be slightly behind,
22483 * making the assumption that last_value always go forward fail to hold.
22484 */
22485- last = atomic64_read(&last_value);
22486+ last = atomic64_read_unchecked(&last_value);
22487 do {
22488 if (ret < last)
22489 return last;
22490- last = atomic64_cmpxchg(&last_value, last, ret);
22491+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22492 } while (unlikely(last != ret));
22493
22494 return ret;
22495diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22496index 76fa1e9..abf09ea 100644
22497--- a/arch/x86/kernel/reboot.c
22498+++ b/arch/x86/kernel/reboot.c
22499@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22500 EXPORT_SYMBOL(pm_power_off);
22501
22502 static const struct desc_ptr no_idt = {};
22503-static int reboot_mode;
22504+static unsigned short reboot_mode;
22505 enum reboot_type reboot_type = BOOT_ACPI;
22506 int reboot_force;
22507
22508@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22509
22510 void __noreturn machine_real_restart(unsigned int type)
22511 {
22512+
22513+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22514+ struct desc_struct *gdt;
22515+#endif
22516+
22517 local_irq_disable();
22518
22519 /*
22520@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22521
22522 /* Jump to the identity-mapped low memory code */
22523 #ifdef CONFIG_X86_32
22524- asm volatile("jmpl *%0" : :
22525+
22526+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22527+ gdt = get_cpu_gdt_table(smp_processor_id());
22528+ pax_open_kernel();
22529+#ifdef CONFIG_PAX_MEMORY_UDEREF
22530+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22531+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22532+ loadsegment(ds, __KERNEL_DS);
22533+ loadsegment(es, __KERNEL_DS);
22534+ loadsegment(ss, __KERNEL_DS);
22535+#endif
22536+#ifdef CONFIG_PAX_KERNEXEC
22537+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22538+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22539+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22540+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22541+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22542+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22543+#endif
22544+ pax_close_kernel();
22545+#endif
22546+
22547+ asm volatile("ljmpl *%0" : :
22548 "rm" (real_mode_header->machine_real_restart_asm),
22549 "a" (type));
22550 #else
22551@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22552 * try to force a triple fault and then cycle between hitting the keyboard
22553 * controller and doing that
22554 */
22555-static void native_machine_emergency_restart(void)
22556+static void __noreturn native_machine_emergency_restart(void)
22557 {
22558 int i;
22559 int attempt = 0;
22560@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22561 #endif
22562 }
22563
22564-static void __machine_emergency_restart(int emergency)
22565+static void __noreturn __machine_emergency_restart(int emergency)
22566 {
22567 reboot_emergency = emergency;
22568 machine_ops.emergency_restart();
22569 }
22570
22571-static void native_machine_restart(char *__unused)
22572+static void __noreturn native_machine_restart(char *__unused)
22573 {
22574 pr_notice("machine restart\n");
22575
22576@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22577 __machine_emergency_restart(0);
22578 }
22579
22580-static void native_machine_halt(void)
22581+static void __noreturn native_machine_halt(void)
22582 {
22583 /* Stop other cpus and apics */
22584 machine_shutdown();
22585@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22586 stop_this_cpu(NULL);
22587 }
22588
22589-static void native_machine_power_off(void)
22590+static void __noreturn native_machine_power_off(void)
22591 {
22592 if (pm_power_off) {
22593 if (!reboot_force)
22594@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22595 }
22596 /* A fallback in case there is no PM info available */
22597 tboot_shutdown(TB_SHUTDOWN_HALT);
22598+ unreachable();
22599 }
22600
22601-struct machine_ops machine_ops = {
22602+struct machine_ops machine_ops __read_only = {
22603 .power_off = native_machine_power_off,
22604 .shutdown = native_machine_shutdown,
22605 .emergency_restart = native_machine_emergency_restart,
22606diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
22607index c8e41e9..64049ef 100644
22608--- a/arch/x86/kernel/reboot_fixups_32.c
22609+++ b/arch/x86/kernel/reboot_fixups_32.c
22610@@ -57,7 +57,7 @@ struct device_fixup {
22611 unsigned int vendor;
22612 unsigned int device;
22613 void (*reboot_fixup)(struct pci_dev *);
22614-};
22615+} __do_const;
22616
22617 /*
22618 * PCI ids solely used for fixups_table go here
22619diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22620index f2bb9c9..bed145d7 100644
22621--- a/arch/x86/kernel/relocate_kernel_64.S
22622+++ b/arch/x86/kernel/relocate_kernel_64.S
22623@@ -11,6 +11,7 @@
22624 #include <asm/kexec.h>
22625 #include <asm/processor-flags.h>
22626 #include <asm/pgtable_types.h>
22627+#include <asm/alternative-asm.h>
22628
22629 /*
22630 * Must be relocatable PIC code callable as a C function
22631@@ -167,6 +168,7 @@ identity_mapped:
22632 xorq %r14, %r14
22633 xorq %r15, %r15
22634
22635+ pax_force_retaddr 0, 1
22636 ret
22637
22638 1:
22639diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22640index 56f7fcf..fa229f4 100644
22641--- a/arch/x86/kernel/setup.c
22642+++ b/arch/x86/kernel/setup.c
22643@@ -110,6 +110,7 @@
22644 #include <asm/mce.h>
22645 #include <asm/alternative.h>
22646 #include <asm/prom.h>
22647+#include <asm/boot.h>
22648
22649 /*
22650 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
22651@@ -444,7 +445,7 @@ static void __init parse_setup_data(void)
22652
22653 switch (data->type) {
22654 case SETUP_E820_EXT:
22655- parse_e820_ext(data);
22656+ parse_e820_ext((struct setup_data __force_kernel *)data);
22657 break;
22658 case SETUP_DTB:
22659 add_dtb(pa_data);
22660@@ -771,7 +772,7 @@ static void __init trim_bios_range(void)
22661 * area (640->1Mb) as ram even though it is not.
22662 * take them out.
22663 */
22664- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22665+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22666
22667 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22668 }
22669@@ -779,7 +780,7 @@ static void __init trim_bios_range(void)
22670 /* called before trim_bios_range() to spare extra sanitize */
22671 static void __init e820_add_kernel_range(void)
22672 {
22673- u64 start = __pa_symbol(_text);
22674+ u64 start = __pa_symbol(ktla_ktva(_text));
22675 u64 size = __pa_symbol(_end) - start;
22676
22677 /*
22678@@ -841,8 +842,12 @@ static void __init trim_low_memory_range(void)
22679
22680 void __init setup_arch(char **cmdline_p)
22681 {
22682+#ifdef CONFIG_X86_32
22683+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
22684+#else
22685 memblock_reserve(__pa_symbol(_text),
22686 (unsigned long)__bss_stop - (unsigned long)_text);
22687+#endif
22688
22689 early_reserve_initrd();
22690
22691@@ -934,14 +939,14 @@ void __init setup_arch(char **cmdline_p)
22692
22693 if (!boot_params.hdr.root_flags)
22694 root_mountflags &= ~MS_RDONLY;
22695- init_mm.start_code = (unsigned long) _text;
22696- init_mm.end_code = (unsigned long) _etext;
22697+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22698+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22699 init_mm.end_data = (unsigned long) _edata;
22700 init_mm.brk = _brk_end;
22701
22702- code_resource.start = __pa_symbol(_text);
22703- code_resource.end = __pa_symbol(_etext)-1;
22704- data_resource.start = __pa_symbol(_etext);
22705+ code_resource.start = __pa_symbol(ktla_ktva(_text));
22706+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
22707+ data_resource.start = __pa_symbol(_sdata);
22708 data_resource.end = __pa_symbol(_edata)-1;
22709 bss_resource.start = __pa_symbol(__bss_start);
22710 bss_resource.end = __pa_symbol(__bss_stop)-1;
22711diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22712index 5cdff03..80fa283 100644
22713--- a/arch/x86/kernel/setup_percpu.c
22714+++ b/arch/x86/kernel/setup_percpu.c
22715@@ -21,19 +21,17 @@
22716 #include <asm/cpu.h>
22717 #include <asm/stackprotector.h>
22718
22719-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22720+#ifdef CONFIG_SMP
22721+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22722 EXPORT_PER_CPU_SYMBOL(cpu_number);
22723+#endif
22724
22725-#ifdef CONFIG_X86_64
22726 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22727-#else
22728-#define BOOT_PERCPU_OFFSET 0
22729-#endif
22730
22731 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22732 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22733
22734-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22735+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22736 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22737 };
22738 EXPORT_SYMBOL(__per_cpu_offset);
22739@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22740 {
22741 #ifdef CONFIG_NEED_MULTIPLE_NODES
22742 pg_data_t *last = NULL;
22743- unsigned int cpu;
22744+ int cpu;
22745
22746 for_each_possible_cpu(cpu) {
22747 int node = early_cpu_to_node(cpu);
22748@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22749 {
22750 #ifdef CONFIG_X86_32
22751 struct desc_struct gdt;
22752+ unsigned long base = per_cpu_offset(cpu);
22753
22754- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22755- 0x2 | DESCTYPE_S, 0x8);
22756- gdt.s = 1;
22757+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22758+ 0x83 | DESCTYPE_S, 0xC);
22759 write_gdt_entry(get_cpu_gdt_table(cpu),
22760 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22761 #endif
22762@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22763 /* alrighty, percpu areas up and running */
22764 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22765 for_each_possible_cpu(cpu) {
22766+#ifdef CONFIG_CC_STACKPROTECTOR
22767+#ifdef CONFIG_X86_32
22768+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22769+#endif
22770+#endif
22771 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22772 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22773 per_cpu(cpu_number, cpu) = cpu;
22774@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22775 */
22776 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22777 #endif
22778+#ifdef CONFIG_CC_STACKPROTECTOR
22779+#ifdef CONFIG_X86_32
22780+ if (!cpu)
22781+ per_cpu(stack_canary.canary, cpu) = canary;
22782+#endif
22783+#endif
22784 /*
22785 * Up to this point, the boot CPU has been using .init.data
22786 * area. Reload any changed state for the boot CPU.
22787diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22788index 6956299..f20beae 100644
22789--- a/arch/x86/kernel/signal.c
22790+++ b/arch/x86/kernel/signal.c
22791@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22792 * Align the stack pointer according to the i386 ABI,
22793 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22794 */
22795- sp = ((sp + 4) & -16ul) - 4;
22796+ sp = ((sp - 12) & -16ul) - 4;
22797 #else /* !CONFIG_X86_32 */
22798 sp = round_down(sp, 16) - 8;
22799 #endif
22800@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22801 }
22802
22803 if (current->mm->context.vdso)
22804- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22805+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22806 else
22807- restorer = &frame->retcode;
22808+ restorer = (void __user *)&frame->retcode;
22809 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22810 restorer = ksig->ka.sa.sa_restorer;
22811
22812@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22813 * reasons and because gdb uses it as a signature to notice
22814 * signal handler stack frames.
22815 */
22816- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22817+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22818
22819 if (err)
22820 return -EFAULT;
22821@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22822 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22823
22824 /* Set up to return from userspace. */
22825- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22826+ if (current->mm->context.vdso)
22827+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22828+ else
22829+ restorer = (void __user *)&frame->retcode;
22830 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22831 restorer = ksig->ka.sa.sa_restorer;
22832 put_user_ex(restorer, &frame->pretcode);
22833@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22834 * reasons and because gdb uses it as a signature to notice
22835 * signal handler stack frames.
22836 */
22837- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22838+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22839 } put_user_catch(err);
22840
22841 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
22842@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22843 {
22844 int usig = signr_convert(ksig->sig);
22845 sigset_t *set = sigmask_to_save();
22846- compat_sigset_t *cset = (compat_sigset_t *) set;
22847+ sigset_t sigcopy;
22848+ compat_sigset_t *cset;
22849+
22850+ sigcopy = *set;
22851+
22852+ cset = (compat_sigset_t *) &sigcopy;
22853
22854 /* Set up the stack frame */
22855 if (is_ia32_frame()) {
22856@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22857 } else if (is_x32_frame()) {
22858 return x32_setup_rt_frame(ksig, cset, regs);
22859 } else {
22860- return __setup_rt_frame(ksig->sig, ksig, set, regs);
22861+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
22862 }
22863 }
22864
22865diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22866index 48d2b7d..90d328a 100644
22867--- a/arch/x86/kernel/smp.c
22868+++ b/arch/x86/kernel/smp.c
22869@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22870
22871 __setup("nonmi_ipi", nonmi_ipi_setup);
22872
22873-struct smp_ops smp_ops = {
22874+struct smp_ops smp_ops __read_only = {
22875 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22876 .smp_prepare_cpus = native_smp_prepare_cpus,
22877 .smp_cpus_done = native_smp_cpus_done,
22878diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22879index bfd348e..4816ad8 100644
22880--- a/arch/x86/kernel/smpboot.c
22881+++ b/arch/x86/kernel/smpboot.c
22882@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22883 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22884 (THREAD_SIZE + task_stack_page(idle))) - 1);
22885 per_cpu(current_task, cpu) = idle;
22886+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22887
22888 #ifdef CONFIG_X86_32
22889 /* Stack for startup_32 can be just as for start_secondary onwards */
22890@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22891 #else
22892 clear_tsk_thread_flag(idle, TIF_FORK);
22893 initial_gs = per_cpu_offset(cpu);
22894- per_cpu(kernel_stack, cpu) =
22895- (unsigned long)task_stack_page(idle) -
22896- KERNEL_STACK_OFFSET + THREAD_SIZE;
22897+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22898 #endif
22899+
22900+ pax_open_kernel();
22901 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22902+ pax_close_kernel();
22903+
22904 initial_code = (unsigned long)start_secondary;
22905 stack_start = idle->thread.sp;
22906
22907@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22908 /* the FPU context is blank, nobody can own it */
22909 __cpu_disable_lazy_restore(cpu);
22910
22911+#ifdef CONFIG_PAX_PER_CPU_PGD
22912+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22913+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22914+ KERNEL_PGD_PTRS);
22915+#endif
22916+
22917+ /* the FPU context is blank, nobody can own it */
22918+ __cpu_disable_lazy_restore(cpu);
22919+
22920 err = do_boot_cpu(apicid, cpu, tidle);
22921 if (err) {
22922 pr_debug("do_boot_cpu failed %d\n", err);
22923diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22924index 9b4d51d..5d28b58 100644
22925--- a/arch/x86/kernel/step.c
22926+++ b/arch/x86/kernel/step.c
22927@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22928 struct desc_struct *desc;
22929 unsigned long base;
22930
22931- seg &= ~7UL;
22932+ seg >>= 3;
22933
22934 mutex_lock(&child->mm->context.lock);
22935- if (unlikely((seg >> 3) >= child->mm->context.size))
22936+ if (unlikely(seg >= child->mm->context.size))
22937 addr = -1L; /* bogus selector, access would fault */
22938 else {
22939 desc = child->mm->context.ldt + seg;
22940@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22941 addr += base;
22942 }
22943 mutex_unlock(&child->mm->context.lock);
22944- }
22945+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22946+ addr = ktla_ktva(addr);
22947
22948 return addr;
22949 }
22950@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22951 unsigned char opcode[15];
22952 unsigned long addr = convert_ip_to_linear(child, regs);
22953
22954+ if (addr == -EINVAL)
22955+ return 0;
22956+
22957 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22958 for (i = 0; i < copied; i++) {
22959 switch (opcode[i]) {
22960diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22961new file mode 100644
22962index 0000000..5877189
22963--- /dev/null
22964+++ b/arch/x86/kernel/sys_i386_32.c
22965@@ -0,0 +1,189 @@
22966+/*
22967+ * This file contains various random system calls that
22968+ * have a non-standard calling sequence on the Linux/i386
22969+ * platform.
22970+ */
22971+
22972+#include <linux/errno.h>
22973+#include <linux/sched.h>
22974+#include <linux/mm.h>
22975+#include <linux/fs.h>
22976+#include <linux/smp.h>
22977+#include <linux/sem.h>
22978+#include <linux/msg.h>
22979+#include <linux/shm.h>
22980+#include <linux/stat.h>
22981+#include <linux/syscalls.h>
22982+#include <linux/mman.h>
22983+#include <linux/file.h>
22984+#include <linux/utsname.h>
22985+#include <linux/ipc.h>
22986+#include <linux/elf.h>
22987+
22988+#include <linux/uaccess.h>
22989+#include <linux/unistd.h>
22990+
22991+#include <asm/syscalls.h>
22992+
22993+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22994+{
22995+ unsigned long pax_task_size = TASK_SIZE;
22996+
22997+#ifdef CONFIG_PAX_SEGMEXEC
22998+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22999+ pax_task_size = SEGMEXEC_TASK_SIZE;
23000+#endif
23001+
23002+ if (flags & MAP_FIXED)
23003+ if (len > pax_task_size || addr > pax_task_size - len)
23004+ return -EINVAL;
23005+
23006+ return 0;
23007+}
23008+
23009+/*
23010+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
23011+ */
23012+static unsigned long get_align_mask(void)
23013+{
23014+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
23015+ return 0;
23016+
23017+ if (!(current->flags & PF_RANDOMIZE))
23018+ return 0;
23019+
23020+ return va_align.mask;
23021+}
23022+
23023+unsigned long
23024+arch_get_unmapped_area(struct file *filp, unsigned long addr,
23025+ unsigned long len, unsigned long pgoff, unsigned long flags)
23026+{
23027+ struct mm_struct *mm = current->mm;
23028+ struct vm_area_struct *vma;
23029+ unsigned long pax_task_size = TASK_SIZE;
23030+ struct vm_unmapped_area_info info;
23031+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23032+
23033+#ifdef CONFIG_PAX_SEGMEXEC
23034+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23035+ pax_task_size = SEGMEXEC_TASK_SIZE;
23036+#endif
23037+
23038+ pax_task_size -= PAGE_SIZE;
23039+
23040+ if (len > pax_task_size)
23041+ return -ENOMEM;
23042+
23043+ if (flags & MAP_FIXED)
23044+ return addr;
23045+
23046+#ifdef CONFIG_PAX_RANDMMAP
23047+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23048+#endif
23049+
23050+ if (addr) {
23051+ addr = PAGE_ALIGN(addr);
23052+ if (pax_task_size - len >= addr) {
23053+ vma = find_vma(mm, addr);
23054+ if (check_heap_stack_gap(vma, addr, len, offset))
23055+ return addr;
23056+ }
23057+ }
23058+
23059+ info.flags = 0;
23060+ info.length = len;
23061+ info.align_mask = filp ? get_align_mask() : 0;
23062+ info.align_offset = pgoff << PAGE_SHIFT;
23063+ info.threadstack_offset = offset;
23064+
23065+#ifdef CONFIG_PAX_PAGEEXEC
23066+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
23067+ info.low_limit = 0x00110000UL;
23068+ info.high_limit = mm->start_code;
23069+
23070+#ifdef CONFIG_PAX_RANDMMAP
23071+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23072+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
23073+#endif
23074+
23075+ if (info.low_limit < info.high_limit) {
23076+ addr = vm_unmapped_area(&info);
23077+ if (!IS_ERR_VALUE(addr))
23078+ return addr;
23079+ }
23080+ } else
23081+#endif
23082+
23083+ info.low_limit = mm->mmap_base;
23084+ info.high_limit = pax_task_size;
23085+
23086+ return vm_unmapped_area(&info);
23087+}
23088+
23089+unsigned long
23090+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23091+ const unsigned long len, const unsigned long pgoff,
23092+ const unsigned long flags)
23093+{
23094+ struct vm_area_struct *vma;
23095+ struct mm_struct *mm = current->mm;
23096+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
23097+ struct vm_unmapped_area_info info;
23098+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23099+
23100+#ifdef CONFIG_PAX_SEGMEXEC
23101+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23102+ pax_task_size = SEGMEXEC_TASK_SIZE;
23103+#endif
23104+
23105+ pax_task_size -= PAGE_SIZE;
23106+
23107+ /* requested length too big for entire address space */
23108+ if (len > pax_task_size)
23109+ return -ENOMEM;
23110+
23111+ if (flags & MAP_FIXED)
23112+ return addr;
23113+
23114+#ifdef CONFIG_PAX_PAGEEXEC
23115+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23116+ goto bottomup;
23117+#endif
23118+
23119+#ifdef CONFIG_PAX_RANDMMAP
23120+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23121+#endif
23122+
23123+ /* requesting a specific address */
23124+ if (addr) {
23125+ addr = PAGE_ALIGN(addr);
23126+ if (pax_task_size - len >= addr) {
23127+ vma = find_vma(mm, addr);
23128+ if (check_heap_stack_gap(vma, addr, len, offset))
23129+ return addr;
23130+ }
23131+ }
23132+
23133+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
23134+ info.length = len;
23135+ info.low_limit = PAGE_SIZE;
23136+ info.high_limit = mm->mmap_base;
23137+ info.align_mask = filp ? get_align_mask() : 0;
23138+ info.align_offset = pgoff << PAGE_SHIFT;
23139+ info.threadstack_offset = offset;
23140+
23141+ addr = vm_unmapped_area(&info);
23142+ if (!(addr & ~PAGE_MASK))
23143+ return addr;
23144+ VM_BUG_ON(addr != -ENOMEM);
23145+
23146+bottomup:
23147+ /*
23148+ * A failed mmap() very likely causes application failure,
23149+ * so fall back to the bottom-up function here. This scenario
23150+ * can happen with large stack limits and large mmap()
23151+ * allocations.
23152+ */
23153+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23154+}
23155diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23156index dbded5a..ace2781 100644
23157--- a/arch/x86/kernel/sys_x86_64.c
23158+++ b/arch/x86/kernel/sys_x86_64.c
23159@@ -81,8 +81,8 @@ out:
23160 return error;
23161 }
23162
23163-static void find_start_end(unsigned long flags, unsigned long *begin,
23164- unsigned long *end)
23165+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23166+ unsigned long *begin, unsigned long *end)
23167 {
23168 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23169 unsigned long new_begin;
23170@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23171 *begin = new_begin;
23172 }
23173 } else {
23174- *begin = TASK_UNMAPPED_BASE;
23175+ *begin = mm->mmap_base;
23176 *end = TASK_SIZE;
23177 }
23178 }
23179@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23180 struct vm_area_struct *vma;
23181 struct vm_unmapped_area_info info;
23182 unsigned long begin, end;
23183+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23184
23185 if (flags & MAP_FIXED)
23186 return addr;
23187
23188- find_start_end(flags, &begin, &end);
23189+ find_start_end(mm, flags, &begin, &end);
23190
23191 if (len > end)
23192 return -ENOMEM;
23193
23194+#ifdef CONFIG_PAX_RANDMMAP
23195+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23196+#endif
23197+
23198 if (addr) {
23199 addr = PAGE_ALIGN(addr);
23200 vma = find_vma(mm, addr);
23201- if (end - len >= addr &&
23202- (!vma || addr + len <= vma->vm_start))
23203+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23204 return addr;
23205 }
23206
23207@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23208 info.high_limit = end;
23209 info.align_mask = filp ? get_align_mask() : 0;
23210 info.align_offset = pgoff << PAGE_SHIFT;
23211+ info.threadstack_offset = offset;
23212 return vm_unmapped_area(&info);
23213 }
23214
23215@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23216 struct mm_struct *mm = current->mm;
23217 unsigned long addr = addr0;
23218 struct vm_unmapped_area_info info;
23219+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23220
23221 /* requested length too big for entire address space */
23222 if (len > TASK_SIZE)
23223@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23224 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23225 goto bottomup;
23226
23227+#ifdef CONFIG_PAX_RANDMMAP
23228+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23229+#endif
23230+
23231 /* requesting a specific address */
23232 if (addr) {
23233 addr = PAGE_ALIGN(addr);
23234 vma = find_vma(mm, addr);
23235- if (TASK_SIZE - len >= addr &&
23236- (!vma || addr + len <= vma->vm_start))
23237+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23238 return addr;
23239 }
23240
23241@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23242 info.high_limit = mm->mmap_base;
23243 info.align_mask = filp ? get_align_mask() : 0;
23244 info.align_offset = pgoff << PAGE_SHIFT;
23245+ info.threadstack_offset = offset;
23246 addr = vm_unmapped_area(&info);
23247 if (!(addr & ~PAGE_MASK))
23248 return addr;
23249diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23250index f84fe00..f41d9f1 100644
23251--- a/arch/x86/kernel/tboot.c
23252+++ b/arch/x86/kernel/tboot.c
23253@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23254
23255 void tboot_shutdown(u32 shutdown_type)
23256 {
23257- void (*shutdown)(void);
23258+ void (* __noreturn shutdown)(void);
23259
23260 if (!tboot_enabled())
23261 return;
23262@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23263
23264 switch_to_tboot_pt();
23265
23266- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23267+ shutdown = (void *)tboot->shutdown_entry;
23268 shutdown();
23269
23270 /* should not reach here */
23271@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23272 return 0;
23273 }
23274
23275-static atomic_t ap_wfs_count;
23276+static atomic_unchecked_t ap_wfs_count;
23277
23278 static int tboot_wait_for_aps(int num_aps)
23279 {
23280@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23281 {
23282 switch (action) {
23283 case CPU_DYING:
23284- atomic_inc(&ap_wfs_count);
23285+ atomic_inc_unchecked(&ap_wfs_count);
23286 if (num_online_cpus() == 1)
23287- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23288+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23289 return NOTIFY_BAD;
23290 break;
23291 }
23292 return NOTIFY_OK;
23293 }
23294
23295-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23296+static struct notifier_block tboot_cpu_notifier =
23297 {
23298 .notifier_call = tboot_cpu_callback,
23299 };
23300@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23301
23302 tboot_create_trampoline();
23303
23304- atomic_set(&ap_wfs_count, 0);
23305+ atomic_set_unchecked(&ap_wfs_count, 0);
23306 register_hotcpu_notifier(&tboot_cpu_notifier);
23307
23308 acpi_os_set_prepare_sleep(&tboot_sleep);
23309diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23310index 24d3c91..d06b473 100644
23311--- a/arch/x86/kernel/time.c
23312+++ b/arch/x86/kernel/time.c
23313@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23314 {
23315 unsigned long pc = instruction_pointer(regs);
23316
23317- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23318+ if (!user_mode(regs) && in_lock_functions(pc)) {
23319 #ifdef CONFIG_FRAME_POINTER
23320- return *(unsigned long *)(regs->bp + sizeof(long));
23321+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23322 #else
23323 unsigned long *sp =
23324 (unsigned long *)kernel_stack_pointer(regs);
23325@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23326 * or above a saved flags. Eflags has bits 22-31 zero,
23327 * kernel addresses don't.
23328 */
23329+
23330+#ifdef CONFIG_PAX_KERNEXEC
23331+ return ktla_ktva(sp[0]);
23332+#else
23333 if (sp[0] >> 22)
23334 return sp[0];
23335 if (sp[1] >> 22)
23336 return sp[1];
23337 #endif
23338+
23339+#endif
23340 }
23341 return pc;
23342 }
23343diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23344index f7fec09..9991981 100644
23345--- a/arch/x86/kernel/tls.c
23346+++ b/arch/x86/kernel/tls.c
23347@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23348 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23349 return -EINVAL;
23350
23351+#ifdef CONFIG_PAX_SEGMEXEC
23352+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23353+ return -EINVAL;
23354+#endif
23355+
23356 set_tls_desc(p, idx, &info, 1);
23357
23358 return 0;
23359@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23360
23361 if (kbuf)
23362 info = kbuf;
23363- else if (__copy_from_user(infobuf, ubuf, count))
23364+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23365 return -EFAULT;
23366 else
23367 info = infobuf;
23368diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23369index 772e2a8..bad5bf6 100644
23370--- a/arch/x86/kernel/traps.c
23371+++ b/arch/x86/kernel/traps.c
23372@@ -68,12 +68,6 @@
23373 #include <asm/setup.h>
23374
23375 asmlinkage int system_call(void);
23376-
23377-/*
23378- * The IDT has to be page-aligned to simplify the Pentium
23379- * F0 0F bug workaround.
23380- */
23381-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23382 #endif
23383
23384 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23385@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23386 }
23387
23388 static int __kprobes
23389-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23390+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23391 struct pt_regs *regs, long error_code)
23392 {
23393 #ifdef CONFIG_X86_32
23394- if (regs->flags & X86_VM_MASK) {
23395+ if (v8086_mode(regs)) {
23396 /*
23397 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23398 * On nmi (interrupt 2), do_trap should not be called.
23399@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23400 return -1;
23401 }
23402 #endif
23403- if (!user_mode(regs)) {
23404+ if (!user_mode_novm(regs)) {
23405 if (!fixup_exception(regs)) {
23406 tsk->thread.error_code = error_code;
23407 tsk->thread.trap_nr = trapnr;
23408+
23409+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23410+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23411+ str = "PAX: suspicious stack segment fault";
23412+#endif
23413+
23414 die(str, regs, error_code);
23415 }
23416+
23417+#ifdef CONFIG_PAX_REFCOUNT
23418+ if (trapnr == 4)
23419+ pax_report_refcount_overflow(regs);
23420+#endif
23421+
23422 return 0;
23423 }
23424
23425@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23426 }
23427
23428 static void __kprobes
23429-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23430+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23431 long error_code, siginfo_t *info)
23432 {
23433 struct task_struct *tsk = current;
23434@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23435 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23436 printk_ratelimit()) {
23437 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23438- tsk->comm, tsk->pid, str,
23439+ tsk->comm, task_pid_nr(tsk), str,
23440 regs->ip, regs->sp, error_code);
23441 print_vma_addr(" in ", regs->ip);
23442 pr_cont("\n");
23443@@ -273,7 +279,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23444 conditional_sti(regs);
23445
23446 #ifdef CONFIG_X86_32
23447- if (regs->flags & X86_VM_MASK) {
23448+ if (v8086_mode(regs)) {
23449 local_irq_enable();
23450 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23451 goto exit;
23452@@ -281,18 +287,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23453 #endif
23454
23455 tsk = current;
23456- if (!user_mode(regs)) {
23457+ if (!user_mode_novm(regs)) {
23458 if (fixup_exception(regs))
23459 goto exit;
23460
23461 tsk->thread.error_code = error_code;
23462 tsk->thread.trap_nr = X86_TRAP_GP;
23463 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23464- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23465+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23466+
23467+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23468+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23469+ die("PAX: suspicious general protection fault", regs, error_code);
23470+ else
23471+#endif
23472+
23473 die("general protection fault", regs, error_code);
23474+ }
23475 goto exit;
23476 }
23477
23478+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23479+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23480+ struct mm_struct *mm = tsk->mm;
23481+ unsigned long limit;
23482+
23483+ down_write(&mm->mmap_sem);
23484+ limit = mm->context.user_cs_limit;
23485+ if (limit < TASK_SIZE) {
23486+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23487+ up_write(&mm->mmap_sem);
23488+ return;
23489+ }
23490+ up_write(&mm->mmap_sem);
23491+ }
23492+#endif
23493+
23494 tsk->thread.error_code = error_code;
23495 tsk->thread.trap_nr = X86_TRAP_GP;
23496
23497@@ -450,7 +480,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23498 /* It's safe to allow irq's after DR6 has been saved */
23499 preempt_conditional_sti(regs);
23500
23501- if (regs->flags & X86_VM_MASK) {
23502+ if (v8086_mode(regs)) {
23503 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23504 X86_TRAP_DB);
23505 preempt_conditional_cli(regs);
23506@@ -465,7 +495,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23507 * We already checked v86 mode above, so we can check for kernel mode
23508 * by just checking the CPL of CS.
23509 */
23510- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23511+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23512 tsk->thread.debugreg6 &= ~DR_STEP;
23513 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23514 regs->flags &= ~X86_EFLAGS_TF;
23515@@ -497,7 +527,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23516 return;
23517 conditional_sti(regs);
23518
23519- if (!user_mode_vm(regs))
23520+ if (!user_mode(regs))
23521 {
23522 if (!fixup_exception(regs)) {
23523 task->thread.error_code = error_code;
23524diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23525index 2ed8459..7cf329f 100644
23526--- a/arch/x86/kernel/uprobes.c
23527+++ b/arch/x86/kernel/uprobes.c
23528@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23529 int ret = NOTIFY_DONE;
23530
23531 /* We are only interested in userspace traps */
23532- if (regs && !user_mode_vm(regs))
23533+ if (regs && !user_mode(regs))
23534 return NOTIFY_DONE;
23535
23536 switch (val) {
23537@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
23538
23539 if (ncopied != rasize) {
23540 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
23541- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
23542+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
23543
23544 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
23545 }
23546diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23547index b9242ba..50c5edd 100644
23548--- a/arch/x86/kernel/verify_cpu.S
23549+++ b/arch/x86/kernel/verify_cpu.S
23550@@ -20,6 +20,7 @@
23551 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23552 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23553 * arch/x86/kernel/head_32.S: processor startup
23554+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23555 *
23556 * verify_cpu, returns the status of longmode and SSE in register %eax.
23557 * 0: Success 1: Failure
23558diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23559index e8edcf5..27f9344 100644
23560--- a/arch/x86/kernel/vm86_32.c
23561+++ b/arch/x86/kernel/vm86_32.c
23562@@ -44,6 +44,7 @@
23563 #include <linux/ptrace.h>
23564 #include <linux/audit.h>
23565 #include <linux/stddef.h>
23566+#include <linux/grsecurity.h>
23567
23568 #include <asm/uaccess.h>
23569 #include <asm/io.h>
23570@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23571 do_exit(SIGSEGV);
23572 }
23573
23574- tss = &per_cpu(init_tss, get_cpu());
23575+ tss = init_tss + get_cpu();
23576 current->thread.sp0 = current->thread.saved_sp0;
23577 current->thread.sysenter_cs = __KERNEL_CS;
23578 load_sp0(tss, &current->thread);
23579@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
23580
23581 if (tsk->thread.saved_sp0)
23582 return -EPERM;
23583+
23584+#ifdef CONFIG_GRKERNSEC_VM86
23585+ if (!capable(CAP_SYS_RAWIO)) {
23586+ gr_handle_vm86();
23587+ return -EPERM;
23588+ }
23589+#endif
23590+
23591 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
23592 offsetof(struct kernel_vm86_struct, vm86plus) -
23593 sizeof(info.regs));
23594@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
23595 int tmp;
23596 struct vm86plus_struct __user *v86;
23597
23598+#ifdef CONFIG_GRKERNSEC_VM86
23599+ if (!capable(CAP_SYS_RAWIO)) {
23600+ gr_handle_vm86();
23601+ return -EPERM;
23602+ }
23603+#endif
23604+
23605 tsk = current;
23606 switch (cmd) {
23607 case VM86_REQUEST_IRQ:
23608@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23609 tsk->thread.saved_fs = info->regs32->fs;
23610 tsk->thread.saved_gs = get_user_gs(info->regs32);
23611
23612- tss = &per_cpu(init_tss, get_cpu());
23613+ tss = init_tss + get_cpu();
23614 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23615 if (cpu_has_sep)
23616 tsk->thread.sysenter_cs = 0;
23617@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23618 goto cannot_handle;
23619 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23620 goto cannot_handle;
23621- intr_ptr = (unsigned long __user *) (i << 2);
23622+ intr_ptr = (__force unsigned long __user *) (i << 2);
23623 if (get_user(segoffs, intr_ptr))
23624 goto cannot_handle;
23625 if ((segoffs >> 16) == BIOSSEG)
23626diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23627index 10c4f30..57377c2 100644
23628--- a/arch/x86/kernel/vmlinux.lds.S
23629+++ b/arch/x86/kernel/vmlinux.lds.S
23630@@ -26,6 +26,13 @@
23631 #include <asm/page_types.h>
23632 #include <asm/cache.h>
23633 #include <asm/boot.h>
23634+#include <asm/segment.h>
23635+
23636+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23637+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23638+#else
23639+#define __KERNEL_TEXT_OFFSET 0
23640+#endif
23641
23642 #undef i386 /* in case the preprocessor is a 32bit one */
23643
23644@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23645
23646 PHDRS {
23647 text PT_LOAD FLAGS(5); /* R_E */
23648+#ifdef CONFIG_X86_32
23649+ module PT_LOAD FLAGS(5); /* R_E */
23650+#endif
23651+#ifdef CONFIG_XEN
23652+ rodata PT_LOAD FLAGS(5); /* R_E */
23653+#else
23654+ rodata PT_LOAD FLAGS(4); /* R__ */
23655+#endif
23656 data PT_LOAD FLAGS(6); /* RW_ */
23657-#ifdef CONFIG_X86_64
23658+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23659 #ifdef CONFIG_SMP
23660 percpu PT_LOAD FLAGS(6); /* RW_ */
23661 #endif
23662+ text.init PT_LOAD FLAGS(5); /* R_E */
23663+ text.exit PT_LOAD FLAGS(5); /* R_E */
23664 init PT_LOAD FLAGS(7); /* RWE */
23665-#endif
23666 note PT_NOTE FLAGS(0); /* ___ */
23667 }
23668
23669 SECTIONS
23670 {
23671 #ifdef CONFIG_X86_32
23672- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23673- phys_startup_32 = startup_32 - LOAD_OFFSET;
23674+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23675 #else
23676- . = __START_KERNEL;
23677- phys_startup_64 = startup_64 - LOAD_OFFSET;
23678+ . = __START_KERNEL;
23679 #endif
23680
23681 /* Text and read-only data */
23682- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23683- _text = .;
23684+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23685 /* bootstrapping code */
23686+#ifdef CONFIG_X86_32
23687+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23688+#else
23689+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23690+#endif
23691+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23692+ _text = .;
23693 HEAD_TEXT
23694 . = ALIGN(8);
23695 _stext = .;
23696@@ -104,13 +124,48 @@ SECTIONS
23697 IRQENTRY_TEXT
23698 *(.fixup)
23699 *(.gnu.warning)
23700- /* End of text section */
23701- _etext = .;
23702 } :text = 0x9090
23703
23704- NOTES :text :note
23705+ . += __KERNEL_TEXT_OFFSET;
23706
23707- EXCEPTION_TABLE(16) :text = 0x9090
23708+#ifdef CONFIG_X86_32
23709+ . = ALIGN(PAGE_SIZE);
23710+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23711+
23712+#ifdef CONFIG_PAX_KERNEXEC
23713+ MODULES_EXEC_VADDR = .;
23714+ BYTE(0)
23715+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23716+ . = ALIGN(HPAGE_SIZE) - 1;
23717+ MODULES_EXEC_END = .;
23718+#endif
23719+
23720+ } :module
23721+#endif
23722+
23723+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23724+ /* End of text section */
23725+ BYTE(0)
23726+ _etext = . - __KERNEL_TEXT_OFFSET;
23727+ }
23728+
23729+#ifdef CONFIG_X86_32
23730+ . = ALIGN(PAGE_SIZE);
23731+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23732+ *(.idt)
23733+ . = ALIGN(PAGE_SIZE);
23734+ *(.empty_zero_page)
23735+ *(.initial_pg_fixmap)
23736+ *(.initial_pg_pmd)
23737+ *(.initial_page_table)
23738+ *(.swapper_pg_dir)
23739+ } :rodata
23740+#endif
23741+
23742+ . = ALIGN(PAGE_SIZE);
23743+ NOTES :rodata :note
23744+
23745+ EXCEPTION_TABLE(16) :rodata
23746
23747 #if defined(CONFIG_DEBUG_RODATA)
23748 /* .text should occupy whole number of pages */
23749@@ -122,16 +177,20 @@ SECTIONS
23750
23751 /* Data */
23752 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23753+
23754+#ifdef CONFIG_PAX_KERNEXEC
23755+ . = ALIGN(HPAGE_SIZE);
23756+#else
23757+ . = ALIGN(PAGE_SIZE);
23758+#endif
23759+
23760 /* Start of data section */
23761 _sdata = .;
23762
23763 /* init_task */
23764 INIT_TASK_DATA(THREAD_SIZE)
23765
23766-#ifdef CONFIG_X86_32
23767- /* 32 bit has nosave before _edata */
23768 NOSAVE_DATA
23769-#endif
23770
23771 PAGE_ALIGNED_DATA(PAGE_SIZE)
23772
23773@@ -172,12 +231,19 @@ SECTIONS
23774 #endif /* CONFIG_X86_64 */
23775
23776 /* Init code and data - will be freed after init */
23777- . = ALIGN(PAGE_SIZE);
23778 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23779+ BYTE(0)
23780+
23781+#ifdef CONFIG_PAX_KERNEXEC
23782+ . = ALIGN(HPAGE_SIZE);
23783+#else
23784+ . = ALIGN(PAGE_SIZE);
23785+#endif
23786+
23787 __init_begin = .; /* paired with __init_end */
23788- }
23789+ } :init.begin
23790
23791-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23792+#ifdef CONFIG_SMP
23793 /*
23794 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23795 * output PHDR, so the next output section - .init.text - should
23796@@ -186,12 +252,27 @@ SECTIONS
23797 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23798 #endif
23799
23800- INIT_TEXT_SECTION(PAGE_SIZE)
23801-#ifdef CONFIG_X86_64
23802- :init
23803-#endif
23804+ . = ALIGN(PAGE_SIZE);
23805+ init_begin = .;
23806+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23807+ VMLINUX_SYMBOL(_sinittext) = .;
23808+ INIT_TEXT
23809+ VMLINUX_SYMBOL(_einittext) = .;
23810+ . = ALIGN(PAGE_SIZE);
23811+ } :text.init
23812
23813- INIT_DATA_SECTION(16)
23814+ /*
23815+ * .exit.text is discard at runtime, not link time, to deal with
23816+ * references from .altinstructions and .eh_frame
23817+ */
23818+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23819+ EXIT_TEXT
23820+ . = ALIGN(16);
23821+ } :text.exit
23822+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23823+
23824+ . = ALIGN(PAGE_SIZE);
23825+ INIT_DATA_SECTION(16) :init
23826
23827 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23828 __x86_cpu_dev_start = .;
23829@@ -253,19 +334,12 @@ SECTIONS
23830 }
23831
23832 . = ALIGN(8);
23833- /*
23834- * .exit.text is discard at runtime, not link time, to deal with
23835- * references from .altinstructions and .eh_frame
23836- */
23837- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23838- EXIT_TEXT
23839- }
23840
23841 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23842 EXIT_DATA
23843 }
23844
23845-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23846+#ifndef CONFIG_SMP
23847 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23848 #endif
23849
23850@@ -284,16 +358,10 @@ SECTIONS
23851 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23852 __smp_locks = .;
23853 *(.smp_locks)
23854- . = ALIGN(PAGE_SIZE);
23855 __smp_locks_end = .;
23856+ . = ALIGN(PAGE_SIZE);
23857 }
23858
23859-#ifdef CONFIG_X86_64
23860- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23861- NOSAVE_DATA
23862- }
23863-#endif
23864-
23865 /* BSS */
23866 . = ALIGN(PAGE_SIZE);
23867 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23868@@ -309,6 +377,7 @@ SECTIONS
23869 __brk_base = .;
23870 . += 64 * 1024; /* 64k alignment slop space */
23871 *(.brk_reservation) /* areas brk users have reserved */
23872+ . = ALIGN(HPAGE_SIZE);
23873 __brk_limit = .;
23874 }
23875
23876@@ -335,13 +404,12 @@ SECTIONS
23877 * for the boot processor.
23878 */
23879 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23880-INIT_PER_CPU(gdt_page);
23881 INIT_PER_CPU(irq_stack_union);
23882
23883 /*
23884 * Build-time check on the image size:
23885 */
23886-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23887+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23888 "kernel image bigger than KERNEL_IMAGE_SIZE");
23889
23890 #ifdef CONFIG_SMP
23891diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23892index 9a907a6..f83f921 100644
23893--- a/arch/x86/kernel/vsyscall_64.c
23894+++ b/arch/x86/kernel/vsyscall_64.c
23895@@ -56,15 +56,13 @@
23896 DEFINE_VVAR(int, vgetcpu_mode);
23897 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23898
23899-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23900+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23901
23902 static int __init vsyscall_setup(char *str)
23903 {
23904 if (str) {
23905 if (!strcmp("emulate", str))
23906 vsyscall_mode = EMULATE;
23907- else if (!strcmp("native", str))
23908- vsyscall_mode = NATIVE;
23909 else if (!strcmp("none", str))
23910 vsyscall_mode = NONE;
23911 else
23912@@ -323,8 +321,7 @@ do_ret:
23913 return true;
23914
23915 sigsegv:
23916- force_sig(SIGSEGV, current);
23917- return true;
23918+ do_group_exit(SIGKILL);
23919 }
23920
23921 /*
23922@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23923 extern char __vvar_page;
23924 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23925
23926- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23927- vsyscall_mode == NATIVE
23928- ? PAGE_KERNEL_VSYSCALL
23929- : PAGE_KERNEL_VVAR);
23930+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23931 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23932 (unsigned long)VSYSCALL_START);
23933
23934diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23935index b014d94..6d6ca7b 100644
23936--- a/arch/x86/kernel/x8664_ksyms_64.c
23937+++ b/arch/x86/kernel/x8664_ksyms_64.c
23938@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23939 EXPORT_SYMBOL(copy_user_generic_unrolled);
23940 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23941 EXPORT_SYMBOL(__copy_user_nocache);
23942-EXPORT_SYMBOL(_copy_from_user);
23943-EXPORT_SYMBOL(_copy_to_user);
23944
23945 EXPORT_SYMBOL(copy_page);
23946 EXPORT_SYMBOL(clear_page);
23947diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23948index 45a14db..075bb9b 100644
23949--- a/arch/x86/kernel/x86_init.c
23950+++ b/arch/x86/kernel/x86_init.c
23951@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
23952 },
23953 };
23954
23955-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23956+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23957 .early_percpu_clock_init = x86_init_noop,
23958 .setup_percpu_clockev = setup_secondary_APIC_clock,
23959 };
23960@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23961 static void default_nmi_init(void) { };
23962 static int default_i8042_detect(void) { return 1; };
23963
23964-struct x86_platform_ops x86_platform = {
23965+struct x86_platform_ops x86_platform __read_only = {
23966 .calibrate_tsc = native_calibrate_tsc,
23967 .get_wallclock = mach_get_cmos_time,
23968 .set_wallclock = mach_set_rtc_mmss,
23969@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
23970 };
23971
23972 EXPORT_SYMBOL_GPL(x86_platform);
23973-struct x86_msi_ops x86_msi = {
23974+struct x86_msi_ops x86_msi __read_only = {
23975 .setup_msi_irqs = native_setup_msi_irqs,
23976 .compose_msi_msg = native_compose_msi_msg,
23977 .teardown_msi_irq = native_teardown_msi_irq,
23978@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
23979 .setup_hpet_msi = default_setup_hpet_msi,
23980 };
23981
23982-struct x86_io_apic_ops x86_io_apic_ops = {
23983+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23984 .init = native_io_apic_init_mappings,
23985 .read = native_io_apic_read,
23986 .write = native_io_apic_write,
23987diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23988index ada87a3..afea76d 100644
23989--- a/arch/x86/kernel/xsave.c
23990+++ b/arch/x86/kernel/xsave.c
23991@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23992 {
23993 int err;
23994
23995+ buf = (struct xsave_struct __user *)____m(buf);
23996 if (use_xsave())
23997 err = xsave_user(buf);
23998 else if (use_fxsr())
23999@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
24000 */
24001 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
24002 {
24003+ buf = (void __user *)____m(buf);
24004 if (use_xsave()) {
24005 if ((unsigned long)buf % 64 || fx_only) {
24006 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
24007diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
24008index a20ecb5..d0e2194 100644
24009--- a/arch/x86/kvm/cpuid.c
24010+++ b/arch/x86/kvm/cpuid.c
24011@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
24012 struct kvm_cpuid2 *cpuid,
24013 struct kvm_cpuid_entry2 __user *entries)
24014 {
24015- int r;
24016+ int r, i;
24017
24018 r = -E2BIG;
24019 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
24020 goto out;
24021 r = -EFAULT;
24022- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
24023- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24024+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
24025 goto out;
24026+ for (i = 0; i < cpuid->nent; ++i) {
24027+ struct kvm_cpuid_entry2 cpuid_entry;
24028+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
24029+ goto out;
24030+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
24031+ }
24032 vcpu->arch.cpuid_nent = cpuid->nent;
24033 kvm_apic_set_version(vcpu);
24034 kvm_x86_ops->cpuid_update(vcpu);
24035@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24036 struct kvm_cpuid2 *cpuid,
24037 struct kvm_cpuid_entry2 __user *entries)
24038 {
24039- int r;
24040+ int r, i;
24041
24042 r = -E2BIG;
24043 if (cpuid->nent < vcpu->arch.cpuid_nent)
24044 goto out;
24045 r = -EFAULT;
24046- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24047- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24048+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24049 goto out;
24050+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24051+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24052+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24053+ goto out;
24054+ }
24055 return 0;
24056
24057 out:
24058diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24059index 5953dce..f11a7d2 100644
24060--- a/arch/x86/kvm/emulate.c
24061+++ b/arch/x86/kvm/emulate.c
24062@@ -329,6 +329,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24063
24064 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24065 do { \
24066+ unsigned long _tmp; \
24067 __asm__ __volatile__ ( \
24068 _PRE_EFLAGS("0", "4", "2") \
24069 _op _suffix " %"_x"3,%1; " \
24070@@ -343,8 +344,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24071 /* Raw emulation: instruction has two explicit operands. */
24072 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24073 do { \
24074- unsigned long _tmp; \
24075- \
24076 switch ((ctxt)->dst.bytes) { \
24077 case 2: \
24078 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24079@@ -360,7 +359,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24080
24081 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24082 do { \
24083- unsigned long _tmp; \
24084 switch ((ctxt)->dst.bytes) { \
24085 case 1: \
24086 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24087diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24088index 0eee2c8..94a32c3 100644
24089--- a/arch/x86/kvm/lapic.c
24090+++ b/arch/x86/kvm/lapic.c
24091@@ -55,7 +55,7 @@
24092 #define APIC_BUS_CYCLE_NS 1
24093
24094 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24095-#define apic_debug(fmt, arg...)
24096+#define apic_debug(fmt, arg...) do {} while (0)
24097
24098 #define APIC_LVT_NUM 6
24099 /* 14 is the version for Xeon and Pentium 8.4.8*/
24100diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24101index da20860..d19fdf5 100644
24102--- a/arch/x86/kvm/paging_tmpl.h
24103+++ b/arch/x86/kvm/paging_tmpl.h
24104@@ -208,7 +208,7 @@ retry_walk:
24105 if (unlikely(kvm_is_error_hva(host_addr)))
24106 goto error;
24107
24108- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24109+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24110 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24111 goto error;
24112 walker->ptep_user[walker->level - 1] = ptep_user;
24113diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24114index a14a6ea..dc86cf0 100644
24115--- a/arch/x86/kvm/svm.c
24116+++ b/arch/x86/kvm/svm.c
24117@@ -3493,7 +3493,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24118 int cpu = raw_smp_processor_id();
24119
24120 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24121+
24122+ pax_open_kernel();
24123 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24124+ pax_close_kernel();
24125+
24126 load_TR_desc();
24127 }
24128
24129@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24130 #endif
24131 #endif
24132
24133+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24134+ __set_fs(current_thread_info()->addr_limit);
24135+#endif
24136+
24137 reload_tss(vcpu);
24138
24139 local_irq_disable();
24140diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24141index 5402c94..c3bdeee 100644
24142--- a/arch/x86/kvm/vmx.c
24143+++ b/arch/x86/kvm/vmx.c
24144@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24145 #endif
24146 }
24147
24148-static void vmcs_clear_bits(unsigned long field, u32 mask)
24149+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24150 {
24151 vmcs_writel(field, vmcs_readl(field) & ~mask);
24152 }
24153
24154-static void vmcs_set_bits(unsigned long field, u32 mask)
24155+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24156 {
24157 vmcs_writel(field, vmcs_readl(field) | mask);
24158 }
24159@@ -1517,7 +1517,11 @@ static void reload_tss(void)
24160 struct desc_struct *descs;
24161
24162 descs = (void *)gdt->address;
24163+
24164+ pax_open_kernel();
24165 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24166+ pax_close_kernel();
24167+
24168 load_TR_desc();
24169 }
24170
24171@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24172 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24173 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24174
24175+#ifdef CONFIG_PAX_PER_CPU_PGD
24176+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24177+#endif
24178+
24179 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24180 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24181 vmx->loaded_vmcs->cpu = cpu;
24182@@ -2935,8 +2943,11 @@ static __init int hardware_setup(void)
24183 if (!cpu_has_vmx_flexpriority())
24184 flexpriority_enabled = 0;
24185
24186- if (!cpu_has_vmx_tpr_shadow())
24187- kvm_x86_ops->update_cr8_intercept = NULL;
24188+ if (!cpu_has_vmx_tpr_shadow()) {
24189+ pax_open_kernel();
24190+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24191+ pax_close_kernel();
24192+ }
24193
24194 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24195 kvm_disable_largepages();
24196@@ -2947,13 +2958,15 @@ static __init int hardware_setup(void)
24197 if (!cpu_has_vmx_apicv())
24198 enable_apicv = 0;
24199
24200+ pax_open_kernel();
24201 if (enable_apicv)
24202- kvm_x86_ops->update_cr8_intercept = NULL;
24203+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24204 else {
24205- kvm_x86_ops->hwapic_irr_update = NULL;
24206- kvm_x86_ops->deliver_posted_interrupt = NULL;
24207- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
24208+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
24209+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
24210+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
24211 }
24212+ pax_close_kernel();
24213
24214 if (nested)
24215 nested_vmx_setup_ctls_msrs();
24216@@ -4076,7 +4089,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
24217
24218 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24219 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24220+
24221+#ifndef CONFIG_PAX_PER_CPU_PGD
24222 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24223+#endif
24224
24225 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24226 #ifdef CONFIG_X86_64
24227@@ -4098,7 +4114,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
24228 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24229 vmx->host_idt_base = dt.address;
24230
24231- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24232+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24233
24234 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24235 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24236@@ -7030,6 +7046,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24237 "jmp 2f \n\t"
24238 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24239 "2: "
24240+
24241+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24242+ "ljmp %[cs],$3f\n\t"
24243+ "3: "
24244+#endif
24245+
24246 /* Save guest registers, load host registers, keep flags */
24247 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24248 "pop %0 \n\t"
24249@@ -7082,6 +7104,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24250 #endif
24251 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24252 [wordsize]"i"(sizeof(ulong))
24253+
24254+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24255+ ,[cs]"i"(__KERNEL_CS)
24256+#endif
24257+
24258 : "cc", "memory"
24259 #ifdef CONFIG_X86_64
24260 , "rax", "rbx", "rdi", "rsi"
24261@@ -7095,7 +7122,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24262 if (debugctlmsr)
24263 update_debugctlmsr(debugctlmsr);
24264
24265-#ifndef CONFIG_X86_64
24266+#ifdef CONFIG_X86_32
24267 /*
24268 * The sysexit path does not restore ds/es, so we must set them to
24269 * a reasonable value ourselves.
24270@@ -7104,8 +7131,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24271 * may be executed in interrupt context, which saves and restore segments
24272 * around it, nullifying its effect.
24273 */
24274- loadsegment(ds, __USER_DS);
24275- loadsegment(es, __USER_DS);
24276+ loadsegment(ds, __KERNEL_DS);
24277+ loadsegment(es, __KERNEL_DS);
24278+ loadsegment(ss, __KERNEL_DS);
24279+
24280+#ifdef CONFIG_PAX_KERNEXEC
24281+ loadsegment(fs, __KERNEL_PERCPU);
24282+#endif
24283+
24284+#ifdef CONFIG_PAX_MEMORY_UDEREF
24285+ __set_fs(current_thread_info()->addr_limit);
24286+#endif
24287+
24288 #endif
24289
24290 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24291diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24292index e8ba99c..ee9d7d9 100644
24293--- a/arch/x86/kvm/x86.c
24294+++ b/arch/x86/kvm/x86.c
24295@@ -1725,8 +1725,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24296 {
24297 struct kvm *kvm = vcpu->kvm;
24298 int lm = is_long_mode(vcpu);
24299- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24300- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24301+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24302+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24303 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24304 : kvm->arch.xen_hvm_config.blob_size_32;
24305 u32 page_num = data & ~PAGE_MASK;
24306@@ -2609,6 +2609,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24307 if (n < msr_list.nmsrs)
24308 goto out;
24309 r = -EFAULT;
24310+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24311+ goto out;
24312 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24313 num_msrs_to_save * sizeof(u32)))
24314 goto out;
24315@@ -5297,7 +5299,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24316 };
24317 #endif
24318
24319-int kvm_arch_init(void *opaque)
24320+int kvm_arch_init(const void *opaque)
24321 {
24322 int r;
24323 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24324diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24325index 7114c63..a1018fc 100644
24326--- a/arch/x86/lguest/boot.c
24327+++ b/arch/x86/lguest/boot.c
24328@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24329 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24330 * Launcher to reboot us.
24331 */
24332-static void lguest_restart(char *reason)
24333+static __noreturn void lguest_restart(char *reason)
24334 {
24335 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24336+ BUG();
24337 }
24338
24339 /*G:050
24340diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24341index 00933d5..3a64af9 100644
24342--- a/arch/x86/lib/atomic64_386_32.S
24343+++ b/arch/x86/lib/atomic64_386_32.S
24344@@ -48,6 +48,10 @@ BEGIN(read)
24345 movl (v), %eax
24346 movl 4(v), %edx
24347 RET_ENDP
24348+BEGIN(read_unchecked)
24349+ movl (v), %eax
24350+ movl 4(v), %edx
24351+RET_ENDP
24352 #undef v
24353
24354 #define v %esi
24355@@ -55,6 +59,10 @@ BEGIN(set)
24356 movl %ebx, (v)
24357 movl %ecx, 4(v)
24358 RET_ENDP
24359+BEGIN(set_unchecked)
24360+ movl %ebx, (v)
24361+ movl %ecx, 4(v)
24362+RET_ENDP
24363 #undef v
24364
24365 #define v %esi
24366@@ -70,6 +78,20 @@ RET_ENDP
24367 BEGIN(add)
24368 addl %eax, (v)
24369 adcl %edx, 4(v)
24370+
24371+#ifdef CONFIG_PAX_REFCOUNT
24372+ jno 0f
24373+ subl %eax, (v)
24374+ sbbl %edx, 4(v)
24375+ int $4
24376+0:
24377+ _ASM_EXTABLE(0b, 0b)
24378+#endif
24379+
24380+RET_ENDP
24381+BEGIN(add_unchecked)
24382+ addl %eax, (v)
24383+ adcl %edx, 4(v)
24384 RET_ENDP
24385 #undef v
24386
24387@@ -77,6 +99,24 @@ RET_ENDP
24388 BEGIN(add_return)
24389 addl (v), %eax
24390 adcl 4(v), %edx
24391+
24392+#ifdef CONFIG_PAX_REFCOUNT
24393+ into
24394+1234:
24395+ _ASM_EXTABLE(1234b, 2f)
24396+#endif
24397+
24398+ movl %eax, (v)
24399+ movl %edx, 4(v)
24400+
24401+#ifdef CONFIG_PAX_REFCOUNT
24402+2:
24403+#endif
24404+
24405+RET_ENDP
24406+BEGIN(add_return_unchecked)
24407+ addl (v), %eax
24408+ adcl 4(v), %edx
24409 movl %eax, (v)
24410 movl %edx, 4(v)
24411 RET_ENDP
24412@@ -86,6 +126,20 @@ RET_ENDP
24413 BEGIN(sub)
24414 subl %eax, (v)
24415 sbbl %edx, 4(v)
24416+
24417+#ifdef CONFIG_PAX_REFCOUNT
24418+ jno 0f
24419+ addl %eax, (v)
24420+ adcl %edx, 4(v)
24421+ int $4
24422+0:
24423+ _ASM_EXTABLE(0b, 0b)
24424+#endif
24425+
24426+RET_ENDP
24427+BEGIN(sub_unchecked)
24428+ subl %eax, (v)
24429+ sbbl %edx, 4(v)
24430 RET_ENDP
24431 #undef v
24432
24433@@ -96,6 +150,27 @@ BEGIN(sub_return)
24434 sbbl $0, %edx
24435 addl (v), %eax
24436 adcl 4(v), %edx
24437+
24438+#ifdef CONFIG_PAX_REFCOUNT
24439+ into
24440+1234:
24441+ _ASM_EXTABLE(1234b, 2f)
24442+#endif
24443+
24444+ movl %eax, (v)
24445+ movl %edx, 4(v)
24446+
24447+#ifdef CONFIG_PAX_REFCOUNT
24448+2:
24449+#endif
24450+
24451+RET_ENDP
24452+BEGIN(sub_return_unchecked)
24453+ negl %edx
24454+ negl %eax
24455+ sbbl $0, %edx
24456+ addl (v), %eax
24457+ adcl 4(v), %edx
24458 movl %eax, (v)
24459 movl %edx, 4(v)
24460 RET_ENDP
24461@@ -105,6 +180,20 @@ RET_ENDP
24462 BEGIN(inc)
24463 addl $1, (v)
24464 adcl $0, 4(v)
24465+
24466+#ifdef CONFIG_PAX_REFCOUNT
24467+ jno 0f
24468+ subl $1, (v)
24469+ sbbl $0, 4(v)
24470+ int $4
24471+0:
24472+ _ASM_EXTABLE(0b, 0b)
24473+#endif
24474+
24475+RET_ENDP
24476+BEGIN(inc_unchecked)
24477+ addl $1, (v)
24478+ adcl $0, 4(v)
24479 RET_ENDP
24480 #undef v
24481
24482@@ -114,6 +203,26 @@ BEGIN(inc_return)
24483 movl 4(v), %edx
24484 addl $1, %eax
24485 adcl $0, %edx
24486+
24487+#ifdef CONFIG_PAX_REFCOUNT
24488+ into
24489+1234:
24490+ _ASM_EXTABLE(1234b, 2f)
24491+#endif
24492+
24493+ movl %eax, (v)
24494+ movl %edx, 4(v)
24495+
24496+#ifdef CONFIG_PAX_REFCOUNT
24497+2:
24498+#endif
24499+
24500+RET_ENDP
24501+BEGIN(inc_return_unchecked)
24502+ movl (v), %eax
24503+ movl 4(v), %edx
24504+ addl $1, %eax
24505+ adcl $0, %edx
24506 movl %eax, (v)
24507 movl %edx, 4(v)
24508 RET_ENDP
24509@@ -123,6 +232,20 @@ RET_ENDP
24510 BEGIN(dec)
24511 subl $1, (v)
24512 sbbl $0, 4(v)
24513+
24514+#ifdef CONFIG_PAX_REFCOUNT
24515+ jno 0f
24516+ addl $1, (v)
24517+ adcl $0, 4(v)
24518+ int $4
24519+0:
24520+ _ASM_EXTABLE(0b, 0b)
24521+#endif
24522+
24523+RET_ENDP
24524+BEGIN(dec_unchecked)
24525+ subl $1, (v)
24526+ sbbl $0, 4(v)
24527 RET_ENDP
24528 #undef v
24529
24530@@ -132,6 +255,26 @@ BEGIN(dec_return)
24531 movl 4(v), %edx
24532 subl $1, %eax
24533 sbbl $0, %edx
24534+
24535+#ifdef CONFIG_PAX_REFCOUNT
24536+ into
24537+1234:
24538+ _ASM_EXTABLE(1234b, 2f)
24539+#endif
24540+
24541+ movl %eax, (v)
24542+ movl %edx, 4(v)
24543+
24544+#ifdef CONFIG_PAX_REFCOUNT
24545+2:
24546+#endif
24547+
24548+RET_ENDP
24549+BEGIN(dec_return_unchecked)
24550+ movl (v), %eax
24551+ movl 4(v), %edx
24552+ subl $1, %eax
24553+ sbbl $0, %edx
24554 movl %eax, (v)
24555 movl %edx, 4(v)
24556 RET_ENDP
24557@@ -143,6 +286,13 @@ BEGIN(add_unless)
24558 adcl %edx, %edi
24559 addl (v), %eax
24560 adcl 4(v), %edx
24561+
24562+#ifdef CONFIG_PAX_REFCOUNT
24563+ into
24564+1234:
24565+ _ASM_EXTABLE(1234b, 2f)
24566+#endif
24567+
24568 cmpl %eax, %ecx
24569 je 3f
24570 1:
24571@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24572 1:
24573 addl $1, %eax
24574 adcl $0, %edx
24575+
24576+#ifdef CONFIG_PAX_REFCOUNT
24577+ into
24578+1234:
24579+ _ASM_EXTABLE(1234b, 2f)
24580+#endif
24581+
24582 movl %eax, (v)
24583 movl %edx, 4(v)
24584 movl $1, %eax
24585@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24586 movl 4(v), %edx
24587 subl $1, %eax
24588 sbbl $0, %edx
24589+
24590+#ifdef CONFIG_PAX_REFCOUNT
24591+ into
24592+1234:
24593+ _ASM_EXTABLE(1234b, 1f)
24594+#endif
24595+
24596 js 1f
24597 movl %eax, (v)
24598 movl %edx, 4(v)
24599diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24600index f5cc9eb..51fa319 100644
24601--- a/arch/x86/lib/atomic64_cx8_32.S
24602+++ b/arch/x86/lib/atomic64_cx8_32.S
24603@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24604 CFI_STARTPROC
24605
24606 read64 %ecx
24607+ pax_force_retaddr
24608 ret
24609 CFI_ENDPROC
24610 ENDPROC(atomic64_read_cx8)
24611
24612+ENTRY(atomic64_read_unchecked_cx8)
24613+ CFI_STARTPROC
24614+
24615+ read64 %ecx
24616+ pax_force_retaddr
24617+ ret
24618+ CFI_ENDPROC
24619+ENDPROC(atomic64_read_unchecked_cx8)
24620+
24621 ENTRY(atomic64_set_cx8)
24622 CFI_STARTPROC
24623
24624@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24625 cmpxchg8b (%esi)
24626 jne 1b
24627
24628+ pax_force_retaddr
24629 ret
24630 CFI_ENDPROC
24631 ENDPROC(atomic64_set_cx8)
24632
24633+ENTRY(atomic64_set_unchecked_cx8)
24634+ CFI_STARTPROC
24635+
24636+1:
24637+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24638+ * are atomic on 586 and newer */
24639+ cmpxchg8b (%esi)
24640+ jne 1b
24641+
24642+ pax_force_retaddr
24643+ ret
24644+ CFI_ENDPROC
24645+ENDPROC(atomic64_set_unchecked_cx8)
24646+
24647 ENTRY(atomic64_xchg_cx8)
24648 CFI_STARTPROC
24649
24650@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24651 cmpxchg8b (%esi)
24652 jne 1b
24653
24654+ pax_force_retaddr
24655 ret
24656 CFI_ENDPROC
24657 ENDPROC(atomic64_xchg_cx8)
24658
24659-.macro addsub_return func ins insc
24660-ENTRY(atomic64_\func\()_return_cx8)
24661+.macro addsub_return func ins insc unchecked=""
24662+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24663 CFI_STARTPROC
24664 SAVE ebp
24665 SAVE ebx
24666@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24667 movl %edx, %ecx
24668 \ins\()l %esi, %ebx
24669 \insc\()l %edi, %ecx
24670+
24671+.ifb \unchecked
24672+#ifdef CONFIG_PAX_REFCOUNT
24673+ into
24674+2:
24675+ _ASM_EXTABLE(2b, 3f)
24676+#endif
24677+.endif
24678+
24679 LOCK_PREFIX
24680 cmpxchg8b (%ebp)
24681 jne 1b
24682-
24683-10:
24684 movl %ebx, %eax
24685 movl %ecx, %edx
24686+
24687+.ifb \unchecked
24688+#ifdef CONFIG_PAX_REFCOUNT
24689+3:
24690+#endif
24691+.endif
24692+
24693 RESTORE edi
24694 RESTORE esi
24695 RESTORE ebx
24696 RESTORE ebp
24697+ pax_force_retaddr
24698 ret
24699 CFI_ENDPROC
24700-ENDPROC(atomic64_\func\()_return_cx8)
24701+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24702 .endm
24703
24704 addsub_return add add adc
24705 addsub_return sub sub sbb
24706+addsub_return add add adc _unchecked
24707+addsub_return sub sub sbb _unchecked
24708
24709-.macro incdec_return func ins insc
24710-ENTRY(atomic64_\func\()_return_cx8)
24711+.macro incdec_return func ins insc unchecked=""
24712+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24713 CFI_STARTPROC
24714 SAVE ebx
24715
24716@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24717 movl %edx, %ecx
24718 \ins\()l $1, %ebx
24719 \insc\()l $0, %ecx
24720+
24721+.ifb \unchecked
24722+#ifdef CONFIG_PAX_REFCOUNT
24723+ into
24724+2:
24725+ _ASM_EXTABLE(2b, 3f)
24726+#endif
24727+.endif
24728+
24729 LOCK_PREFIX
24730 cmpxchg8b (%esi)
24731 jne 1b
24732
24733-10:
24734 movl %ebx, %eax
24735 movl %ecx, %edx
24736+
24737+.ifb \unchecked
24738+#ifdef CONFIG_PAX_REFCOUNT
24739+3:
24740+#endif
24741+.endif
24742+
24743 RESTORE ebx
24744+ pax_force_retaddr
24745 ret
24746 CFI_ENDPROC
24747-ENDPROC(atomic64_\func\()_return_cx8)
24748+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24749 .endm
24750
24751 incdec_return inc add adc
24752 incdec_return dec sub sbb
24753+incdec_return inc add adc _unchecked
24754+incdec_return dec sub sbb _unchecked
24755
24756 ENTRY(atomic64_dec_if_positive_cx8)
24757 CFI_STARTPROC
24758@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24759 movl %edx, %ecx
24760 subl $1, %ebx
24761 sbb $0, %ecx
24762+
24763+#ifdef CONFIG_PAX_REFCOUNT
24764+ into
24765+1234:
24766+ _ASM_EXTABLE(1234b, 2f)
24767+#endif
24768+
24769 js 2f
24770 LOCK_PREFIX
24771 cmpxchg8b (%esi)
24772@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24773 movl %ebx, %eax
24774 movl %ecx, %edx
24775 RESTORE ebx
24776+ pax_force_retaddr
24777 ret
24778 CFI_ENDPROC
24779 ENDPROC(atomic64_dec_if_positive_cx8)
24780@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24781 movl %edx, %ecx
24782 addl %ebp, %ebx
24783 adcl %edi, %ecx
24784+
24785+#ifdef CONFIG_PAX_REFCOUNT
24786+ into
24787+1234:
24788+ _ASM_EXTABLE(1234b, 3f)
24789+#endif
24790+
24791 LOCK_PREFIX
24792 cmpxchg8b (%esi)
24793 jne 1b
24794@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24795 CFI_ADJUST_CFA_OFFSET -8
24796 RESTORE ebx
24797 RESTORE ebp
24798+ pax_force_retaddr
24799 ret
24800 4:
24801 cmpl %edx, 4(%esp)
24802@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24803 xorl %ecx, %ecx
24804 addl $1, %ebx
24805 adcl %edx, %ecx
24806+
24807+#ifdef CONFIG_PAX_REFCOUNT
24808+ into
24809+1234:
24810+ _ASM_EXTABLE(1234b, 3f)
24811+#endif
24812+
24813 LOCK_PREFIX
24814 cmpxchg8b (%esi)
24815 jne 1b
24816@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24817 movl $1, %eax
24818 3:
24819 RESTORE ebx
24820+ pax_force_retaddr
24821 ret
24822 CFI_ENDPROC
24823 ENDPROC(atomic64_inc_not_zero_cx8)
24824diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24825index e78b8ee..7e173a8 100644
24826--- a/arch/x86/lib/checksum_32.S
24827+++ b/arch/x86/lib/checksum_32.S
24828@@ -29,7 +29,8 @@
24829 #include <asm/dwarf2.h>
24830 #include <asm/errno.h>
24831 #include <asm/asm.h>
24832-
24833+#include <asm/segment.h>
24834+
24835 /*
24836 * computes a partial checksum, e.g. for TCP/UDP fragments
24837 */
24838@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24839
24840 #define ARGBASE 16
24841 #define FP 12
24842-
24843-ENTRY(csum_partial_copy_generic)
24844+
24845+ENTRY(csum_partial_copy_generic_to_user)
24846 CFI_STARTPROC
24847+
24848+#ifdef CONFIG_PAX_MEMORY_UDEREF
24849+ pushl_cfi %gs
24850+ popl_cfi %es
24851+ jmp csum_partial_copy_generic
24852+#endif
24853+
24854+ENTRY(csum_partial_copy_generic_from_user)
24855+
24856+#ifdef CONFIG_PAX_MEMORY_UDEREF
24857+ pushl_cfi %gs
24858+ popl_cfi %ds
24859+#endif
24860+
24861+ENTRY(csum_partial_copy_generic)
24862 subl $4,%esp
24863 CFI_ADJUST_CFA_OFFSET 4
24864 pushl_cfi %edi
24865@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24866 jmp 4f
24867 SRC(1: movw (%esi), %bx )
24868 addl $2, %esi
24869-DST( movw %bx, (%edi) )
24870+DST( movw %bx, %es:(%edi) )
24871 addl $2, %edi
24872 addw %bx, %ax
24873 adcl $0, %eax
24874@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24875 SRC(1: movl (%esi), %ebx )
24876 SRC( movl 4(%esi), %edx )
24877 adcl %ebx, %eax
24878-DST( movl %ebx, (%edi) )
24879+DST( movl %ebx, %es:(%edi) )
24880 adcl %edx, %eax
24881-DST( movl %edx, 4(%edi) )
24882+DST( movl %edx, %es:4(%edi) )
24883
24884 SRC( movl 8(%esi), %ebx )
24885 SRC( movl 12(%esi), %edx )
24886 adcl %ebx, %eax
24887-DST( movl %ebx, 8(%edi) )
24888+DST( movl %ebx, %es:8(%edi) )
24889 adcl %edx, %eax
24890-DST( movl %edx, 12(%edi) )
24891+DST( movl %edx, %es:12(%edi) )
24892
24893 SRC( movl 16(%esi), %ebx )
24894 SRC( movl 20(%esi), %edx )
24895 adcl %ebx, %eax
24896-DST( movl %ebx, 16(%edi) )
24897+DST( movl %ebx, %es:16(%edi) )
24898 adcl %edx, %eax
24899-DST( movl %edx, 20(%edi) )
24900+DST( movl %edx, %es:20(%edi) )
24901
24902 SRC( movl 24(%esi), %ebx )
24903 SRC( movl 28(%esi), %edx )
24904 adcl %ebx, %eax
24905-DST( movl %ebx, 24(%edi) )
24906+DST( movl %ebx, %es:24(%edi) )
24907 adcl %edx, %eax
24908-DST( movl %edx, 28(%edi) )
24909+DST( movl %edx, %es:28(%edi) )
24910
24911 lea 32(%esi), %esi
24912 lea 32(%edi), %edi
24913@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24914 shrl $2, %edx # This clears CF
24915 SRC(3: movl (%esi), %ebx )
24916 adcl %ebx, %eax
24917-DST( movl %ebx, (%edi) )
24918+DST( movl %ebx, %es:(%edi) )
24919 lea 4(%esi), %esi
24920 lea 4(%edi), %edi
24921 dec %edx
24922@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24923 jb 5f
24924 SRC( movw (%esi), %cx )
24925 leal 2(%esi), %esi
24926-DST( movw %cx, (%edi) )
24927+DST( movw %cx, %es:(%edi) )
24928 leal 2(%edi), %edi
24929 je 6f
24930 shll $16,%ecx
24931 SRC(5: movb (%esi), %cl )
24932-DST( movb %cl, (%edi) )
24933+DST( movb %cl, %es:(%edi) )
24934 6: addl %ecx, %eax
24935 adcl $0, %eax
24936 7:
24937@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24938
24939 6001:
24940 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24941- movl $-EFAULT, (%ebx)
24942+ movl $-EFAULT, %ss:(%ebx)
24943
24944 # zero the complete destination - computing the rest
24945 # is too much work
24946@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24947
24948 6002:
24949 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24950- movl $-EFAULT,(%ebx)
24951+ movl $-EFAULT,%ss:(%ebx)
24952 jmp 5000b
24953
24954 .previous
24955
24956+ pushl_cfi %ss
24957+ popl_cfi %ds
24958+ pushl_cfi %ss
24959+ popl_cfi %es
24960 popl_cfi %ebx
24961 CFI_RESTORE ebx
24962 popl_cfi %esi
24963@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24964 popl_cfi %ecx # equivalent to addl $4,%esp
24965 ret
24966 CFI_ENDPROC
24967-ENDPROC(csum_partial_copy_generic)
24968+ENDPROC(csum_partial_copy_generic_to_user)
24969
24970 #else
24971
24972 /* Version for PentiumII/PPro */
24973
24974 #define ROUND1(x) \
24975+ nop; nop; nop; \
24976 SRC(movl x(%esi), %ebx ) ; \
24977 addl %ebx, %eax ; \
24978- DST(movl %ebx, x(%edi) ) ;
24979+ DST(movl %ebx, %es:x(%edi)) ;
24980
24981 #define ROUND(x) \
24982+ nop; nop; nop; \
24983 SRC(movl x(%esi), %ebx ) ; \
24984 adcl %ebx, %eax ; \
24985- DST(movl %ebx, x(%edi) ) ;
24986+ DST(movl %ebx, %es:x(%edi)) ;
24987
24988 #define ARGBASE 12
24989-
24990-ENTRY(csum_partial_copy_generic)
24991+
24992+ENTRY(csum_partial_copy_generic_to_user)
24993 CFI_STARTPROC
24994+
24995+#ifdef CONFIG_PAX_MEMORY_UDEREF
24996+ pushl_cfi %gs
24997+ popl_cfi %es
24998+ jmp csum_partial_copy_generic
24999+#endif
25000+
25001+ENTRY(csum_partial_copy_generic_from_user)
25002+
25003+#ifdef CONFIG_PAX_MEMORY_UDEREF
25004+ pushl_cfi %gs
25005+ popl_cfi %ds
25006+#endif
25007+
25008+ENTRY(csum_partial_copy_generic)
25009 pushl_cfi %ebx
25010 CFI_REL_OFFSET ebx, 0
25011 pushl_cfi %edi
25012@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
25013 subl %ebx, %edi
25014 lea -1(%esi),%edx
25015 andl $-32,%edx
25016- lea 3f(%ebx,%ebx), %ebx
25017+ lea 3f(%ebx,%ebx,2), %ebx
25018 testl %esi, %esi
25019 jmp *%ebx
25020 1: addl $64,%esi
25021@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
25022 jb 5f
25023 SRC( movw (%esi), %dx )
25024 leal 2(%esi), %esi
25025-DST( movw %dx, (%edi) )
25026+DST( movw %dx, %es:(%edi) )
25027 leal 2(%edi), %edi
25028 je 6f
25029 shll $16,%edx
25030 5:
25031 SRC( movb (%esi), %dl )
25032-DST( movb %dl, (%edi) )
25033+DST( movb %dl, %es:(%edi) )
25034 6: addl %edx, %eax
25035 adcl $0, %eax
25036 7:
25037 .section .fixup, "ax"
25038 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25039- movl $-EFAULT, (%ebx)
25040+ movl $-EFAULT, %ss:(%ebx)
25041 # zero the complete destination (computing the rest is too much work)
25042 movl ARGBASE+8(%esp),%edi # dst
25043 movl ARGBASE+12(%esp),%ecx # len
25044@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25045 rep; stosb
25046 jmp 7b
25047 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25048- movl $-EFAULT, (%ebx)
25049+ movl $-EFAULT, %ss:(%ebx)
25050 jmp 7b
25051 .previous
25052
25053+#ifdef CONFIG_PAX_MEMORY_UDEREF
25054+ pushl_cfi %ss
25055+ popl_cfi %ds
25056+ pushl_cfi %ss
25057+ popl_cfi %es
25058+#endif
25059+
25060 popl_cfi %esi
25061 CFI_RESTORE esi
25062 popl_cfi %edi
25063@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25064 CFI_RESTORE ebx
25065 ret
25066 CFI_ENDPROC
25067-ENDPROC(csum_partial_copy_generic)
25068+ENDPROC(csum_partial_copy_generic_to_user)
25069
25070 #undef ROUND
25071 #undef ROUND1
25072diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25073index f2145cf..cea889d 100644
25074--- a/arch/x86/lib/clear_page_64.S
25075+++ b/arch/x86/lib/clear_page_64.S
25076@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25077 movl $4096/8,%ecx
25078 xorl %eax,%eax
25079 rep stosq
25080+ pax_force_retaddr
25081 ret
25082 CFI_ENDPROC
25083 ENDPROC(clear_page_c)
25084@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25085 movl $4096,%ecx
25086 xorl %eax,%eax
25087 rep stosb
25088+ pax_force_retaddr
25089 ret
25090 CFI_ENDPROC
25091 ENDPROC(clear_page_c_e)
25092@@ -43,6 +45,7 @@ ENTRY(clear_page)
25093 leaq 64(%rdi),%rdi
25094 jnz .Lloop
25095 nop
25096+ pax_force_retaddr
25097 ret
25098 CFI_ENDPROC
25099 .Lclear_page_end:
25100@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25101
25102 #include <asm/cpufeature.h>
25103
25104- .section .altinstr_replacement,"ax"
25105+ .section .altinstr_replacement,"a"
25106 1: .byte 0xeb /* jmp <disp8> */
25107 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25108 2: .byte 0xeb /* jmp <disp8> */
25109diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25110index 1e572c5..2a162cd 100644
25111--- a/arch/x86/lib/cmpxchg16b_emu.S
25112+++ b/arch/x86/lib/cmpxchg16b_emu.S
25113@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25114
25115 popf
25116 mov $1, %al
25117+ pax_force_retaddr
25118 ret
25119
25120 not_same:
25121 popf
25122 xor %al,%al
25123+ pax_force_retaddr
25124 ret
25125
25126 CFI_ENDPROC
25127diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25128index 176cca6..1166c50 100644
25129--- a/arch/x86/lib/copy_page_64.S
25130+++ b/arch/x86/lib/copy_page_64.S
25131@@ -9,6 +9,7 @@ copy_page_rep:
25132 CFI_STARTPROC
25133 movl $4096/8, %ecx
25134 rep movsq
25135+ pax_force_retaddr
25136 ret
25137 CFI_ENDPROC
25138 ENDPROC(copy_page_rep)
25139@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25140
25141 ENTRY(copy_page)
25142 CFI_STARTPROC
25143- subq $2*8, %rsp
25144- CFI_ADJUST_CFA_OFFSET 2*8
25145+ subq $3*8, %rsp
25146+ CFI_ADJUST_CFA_OFFSET 3*8
25147 movq %rbx, (%rsp)
25148 CFI_REL_OFFSET rbx, 0
25149 movq %r12, 1*8(%rsp)
25150 CFI_REL_OFFSET r12, 1*8
25151+ movq %r13, 2*8(%rsp)
25152+ CFI_REL_OFFSET r13, 2*8
25153
25154 movl $(4096/64)-5, %ecx
25155 .p2align 4
25156@@ -36,7 +39,7 @@ ENTRY(copy_page)
25157 movq 0x8*2(%rsi), %rdx
25158 movq 0x8*3(%rsi), %r8
25159 movq 0x8*4(%rsi), %r9
25160- movq 0x8*5(%rsi), %r10
25161+ movq 0x8*5(%rsi), %r13
25162 movq 0x8*6(%rsi), %r11
25163 movq 0x8*7(%rsi), %r12
25164
25165@@ -47,7 +50,7 @@ ENTRY(copy_page)
25166 movq %rdx, 0x8*2(%rdi)
25167 movq %r8, 0x8*3(%rdi)
25168 movq %r9, 0x8*4(%rdi)
25169- movq %r10, 0x8*5(%rdi)
25170+ movq %r13, 0x8*5(%rdi)
25171 movq %r11, 0x8*6(%rdi)
25172 movq %r12, 0x8*7(%rdi)
25173
25174@@ -66,7 +69,7 @@ ENTRY(copy_page)
25175 movq 0x8*2(%rsi), %rdx
25176 movq 0x8*3(%rsi), %r8
25177 movq 0x8*4(%rsi), %r9
25178- movq 0x8*5(%rsi), %r10
25179+ movq 0x8*5(%rsi), %r13
25180 movq 0x8*6(%rsi), %r11
25181 movq 0x8*7(%rsi), %r12
25182
25183@@ -75,7 +78,7 @@ ENTRY(copy_page)
25184 movq %rdx, 0x8*2(%rdi)
25185 movq %r8, 0x8*3(%rdi)
25186 movq %r9, 0x8*4(%rdi)
25187- movq %r10, 0x8*5(%rdi)
25188+ movq %r13, 0x8*5(%rdi)
25189 movq %r11, 0x8*6(%rdi)
25190 movq %r12, 0x8*7(%rdi)
25191
25192@@ -87,8 +90,11 @@ ENTRY(copy_page)
25193 CFI_RESTORE rbx
25194 movq 1*8(%rsp), %r12
25195 CFI_RESTORE r12
25196- addq $2*8, %rsp
25197- CFI_ADJUST_CFA_OFFSET -2*8
25198+ movq 2*8(%rsp), %r13
25199+ CFI_RESTORE r13
25200+ addq $3*8, %rsp
25201+ CFI_ADJUST_CFA_OFFSET -3*8
25202+ pax_force_retaddr
25203 ret
25204 .Lcopy_page_end:
25205 CFI_ENDPROC
25206@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25207
25208 #include <asm/cpufeature.h>
25209
25210- .section .altinstr_replacement,"ax"
25211+ .section .altinstr_replacement,"a"
25212 1: .byte 0xeb /* jmp <disp8> */
25213 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25214 2:
25215diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25216index a30ca15..d25fab6 100644
25217--- a/arch/x86/lib/copy_user_64.S
25218+++ b/arch/x86/lib/copy_user_64.S
25219@@ -18,6 +18,7 @@
25220 #include <asm/alternative-asm.h>
25221 #include <asm/asm.h>
25222 #include <asm/smap.h>
25223+#include <asm/pgtable.h>
25224
25225 /*
25226 * By placing feature2 after feature1 in altinstructions section, we logically
25227@@ -31,7 +32,7 @@
25228 .byte 0xe9 /* 32bit jump */
25229 .long \orig-1f /* by default jump to orig */
25230 1:
25231- .section .altinstr_replacement,"ax"
25232+ .section .altinstr_replacement,"a"
25233 2: .byte 0xe9 /* near jump with 32bit immediate */
25234 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25235 3: .byte 0xe9 /* near jump with 32bit immediate */
25236@@ -70,47 +71,20 @@
25237 #endif
25238 .endm
25239
25240-/* Standard copy_to_user with segment limit checking */
25241-ENTRY(_copy_to_user)
25242- CFI_STARTPROC
25243- GET_THREAD_INFO(%rax)
25244- movq %rdi,%rcx
25245- addq %rdx,%rcx
25246- jc bad_to_user
25247- cmpq TI_addr_limit(%rax),%rcx
25248- ja bad_to_user
25249- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25250- copy_user_generic_unrolled,copy_user_generic_string, \
25251- copy_user_enhanced_fast_string
25252- CFI_ENDPROC
25253-ENDPROC(_copy_to_user)
25254-
25255-/* Standard copy_from_user with segment limit checking */
25256-ENTRY(_copy_from_user)
25257- CFI_STARTPROC
25258- GET_THREAD_INFO(%rax)
25259- movq %rsi,%rcx
25260- addq %rdx,%rcx
25261- jc bad_from_user
25262- cmpq TI_addr_limit(%rax),%rcx
25263- ja bad_from_user
25264- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25265- copy_user_generic_unrolled,copy_user_generic_string, \
25266- copy_user_enhanced_fast_string
25267- CFI_ENDPROC
25268-ENDPROC(_copy_from_user)
25269-
25270 .section .fixup,"ax"
25271 /* must zero dest */
25272 ENTRY(bad_from_user)
25273 bad_from_user:
25274 CFI_STARTPROC
25275+ testl %edx,%edx
25276+ js bad_to_user
25277 movl %edx,%ecx
25278 xorl %eax,%eax
25279 rep
25280 stosb
25281 bad_to_user:
25282 movl %edx,%eax
25283+ pax_force_retaddr
25284 ret
25285 CFI_ENDPROC
25286 ENDPROC(bad_from_user)
25287@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25288 jz 17f
25289 1: movq (%rsi),%r8
25290 2: movq 1*8(%rsi),%r9
25291-3: movq 2*8(%rsi),%r10
25292+3: movq 2*8(%rsi),%rax
25293 4: movq 3*8(%rsi),%r11
25294 5: movq %r8,(%rdi)
25295 6: movq %r9,1*8(%rdi)
25296-7: movq %r10,2*8(%rdi)
25297+7: movq %rax,2*8(%rdi)
25298 8: movq %r11,3*8(%rdi)
25299 9: movq 4*8(%rsi),%r8
25300 10: movq 5*8(%rsi),%r9
25301-11: movq 6*8(%rsi),%r10
25302+11: movq 6*8(%rsi),%rax
25303 12: movq 7*8(%rsi),%r11
25304 13: movq %r8,4*8(%rdi)
25305 14: movq %r9,5*8(%rdi)
25306-15: movq %r10,6*8(%rdi)
25307+15: movq %rax,6*8(%rdi)
25308 16: movq %r11,7*8(%rdi)
25309 leaq 64(%rsi),%rsi
25310 leaq 64(%rdi),%rdi
25311@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25312 jnz 21b
25313 23: xor %eax,%eax
25314 ASM_CLAC
25315+ pax_force_retaddr
25316 ret
25317
25318 .section .fixup,"ax"
25319@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25320 movsb
25321 4: xorl %eax,%eax
25322 ASM_CLAC
25323+ pax_force_retaddr
25324 ret
25325
25326 .section .fixup,"ax"
25327@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25328 movsb
25329 2: xorl %eax,%eax
25330 ASM_CLAC
25331+ pax_force_retaddr
25332 ret
25333
25334 .section .fixup,"ax"
25335diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25336index 6a4f43c..f08b4a2 100644
25337--- a/arch/x86/lib/copy_user_nocache_64.S
25338+++ b/arch/x86/lib/copy_user_nocache_64.S
25339@@ -8,6 +8,7 @@
25340
25341 #include <linux/linkage.h>
25342 #include <asm/dwarf2.h>
25343+#include <asm/alternative-asm.h>
25344
25345 #define FIX_ALIGNMENT 1
25346
25347@@ -16,6 +17,7 @@
25348 #include <asm/thread_info.h>
25349 #include <asm/asm.h>
25350 #include <asm/smap.h>
25351+#include <asm/pgtable.h>
25352
25353 .macro ALIGN_DESTINATION
25354 #ifdef FIX_ALIGNMENT
25355@@ -49,6 +51,15 @@
25356 */
25357 ENTRY(__copy_user_nocache)
25358 CFI_STARTPROC
25359+
25360+#ifdef CONFIG_PAX_MEMORY_UDEREF
25361+ mov pax_user_shadow_base,%rcx
25362+ cmp %rcx,%rsi
25363+ jae 1f
25364+ add %rcx,%rsi
25365+1:
25366+#endif
25367+
25368 ASM_STAC
25369 cmpl $8,%edx
25370 jb 20f /* less then 8 bytes, go to byte copy loop */
25371@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25372 jz 17f
25373 1: movq (%rsi),%r8
25374 2: movq 1*8(%rsi),%r9
25375-3: movq 2*8(%rsi),%r10
25376+3: movq 2*8(%rsi),%rax
25377 4: movq 3*8(%rsi),%r11
25378 5: movnti %r8,(%rdi)
25379 6: movnti %r9,1*8(%rdi)
25380-7: movnti %r10,2*8(%rdi)
25381+7: movnti %rax,2*8(%rdi)
25382 8: movnti %r11,3*8(%rdi)
25383 9: movq 4*8(%rsi),%r8
25384 10: movq 5*8(%rsi),%r9
25385-11: movq 6*8(%rsi),%r10
25386+11: movq 6*8(%rsi),%rax
25387 12: movq 7*8(%rsi),%r11
25388 13: movnti %r8,4*8(%rdi)
25389 14: movnti %r9,5*8(%rdi)
25390-15: movnti %r10,6*8(%rdi)
25391+15: movnti %rax,6*8(%rdi)
25392 16: movnti %r11,7*8(%rdi)
25393 leaq 64(%rsi),%rsi
25394 leaq 64(%rdi),%rdi
25395@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25396 23: xorl %eax,%eax
25397 ASM_CLAC
25398 sfence
25399+ pax_force_retaddr
25400 ret
25401
25402 .section .fixup,"ax"
25403diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25404index 2419d5f..953ee51 100644
25405--- a/arch/x86/lib/csum-copy_64.S
25406+++ b/arch/x86/lib/csum-copy_64.S
25407@@ -9,6 +9,7 @@
25408 #include <asm/dwarf2.h>
25409 #include <asm/errno.h>
25410 #include <asm/asm.h>
25411+#include <asm/alternative-asm.h>
25412
25413 /*
25414 * Checksum copy with exception handling.
25415@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25416 CFI_RESTORE rbp
25417 addq $7*8, %rsp
25418 CFI_ADJUST_CFA_OFFSET -7*8
25419+ pax_force_retaddr 0, 1
25420 ret
25421 CFI_RESTORE_STATE
25422
25423diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25424index 25b7ae8..169fafc 100644
25425--- a/arch/x86/lib/csum-wrappers_64.c
25426+++ b/arch/x86/lib/csum-wrappers_64.c
25427@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25428 len -= 2;
25429 }
25430 }
25431- isum = csum_partial_copy_generic((__force const void *)src,
25432+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25433 dst, len, isum, errp, NULL);
25434 if (unlikely(*errp))
25435 goto out_err;
25436@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25437 }
25438
25439 *errp = 0;
25440- return csum_partial_copy_generic(src, (void __force *)dst,
25441+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25442 len, isum, NULL, errp);
25443 }
25444 EXPORT_SYMBOL(csum_partial_copy_to_user);
25445diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25446index a451235..1daa956 100644
25447--- a/arch/x86/lib/getuser.S
25448+++ b/arch/x86/lib/getuser.S
25449@@ -33,17 +33,40 @@
25450 #include <asm/thread_info.h>
25451 #include <asm/asm.h>
25452 #include <asm/smap.h>
25453+#include <asm/segment.h>
25454+#include <asm/pgtable.h>
25455+#include <asm/alternative-asm.h>
25456+
25457+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25458+#define __copyuser_seg gs;
25459+#else
25460+#define __copyuser_seg
25461+#endif
25462
25463 .text
25464 ENTRY(__get_user_1)
25465 CFI_STARTPROC
25466+
25467+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25468 GET_THREAD_INFO(%_ASM_DX)
25469 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25470 jae bad_get_user
25471 ASM_STAC
25472-1: movzbl (%_ASM_AX),%edx
25473+
25474+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25475+ mov pax_user_shadow_base,%_ASM_DX
25476+ cmp %_ASM_DX,%_ASM_AX
25477+ jae 1234f
25478+ add %_ASM_DX,%_ASM_AX
25479+1234:
25480+#endif
25481+
25482+#endif
25483+
25484+1: __copyuser_seg movzbl (%_ASM_AX),%edx
25485 xor %eax,%eax
25486 ASM_CLAC
25487+ pax_force_retaddr
25488 ret
25489 CFI_ENDPROC
25490 ENDPROC(__get_user_1)
25491@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
25492 ENTRY(__get_user_2)
25493 CFI_STARTPROC
25494 add $1,%_ASM_AX
25495+
25496+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25497 jc bad_get_user
25498 GET_THREAD_INFO(%_ASM_DX)
25499 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25500 jae bad_get_user
25501 ASM_STAC
25502-2: movzwl -1(%_ASM_AX),%edx
25503+
25504+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25505+ mov pax_user_shadow_base,%_ASM_DX
25506+ cmp %_ASM_DX,%_ASM_AX
25507+ jae 1234f
25508+ add %_ASM_DX,%_ASM_AX
25509+1234:
25510+#endif
25511+
25512+#endif
25513+
25514+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25515 xor %eax,%eax
25516 ASM_CLAC
25517+ pax_force_retaddr
25518 ret
25519 CFI_ENDPROC
25520 ENDPROC(__get_user_2)
25521@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
25522 ENTRY(__get_user_4)
25523 CFI_STARTPROC
25524 add $3,%_ASM_AX
25525+
25526+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25527 jc bad_get_user
25528 GET_THREAD_INFO(%_ASM_DX)
25529 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25530 jae bad_get_user
25531 ASM_STAC
25532-3: movl -3(%_ASM_AX),%edx
25533+
25534+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25535+ mov pax_user_shadow_base,%_ASM_DX
25536+ cmp %_ASM_DX,%_ASM_AX
25537+ jae 1234f
25538+ add %_ASM_DX,%_ASM_AX
25539+1234:
25540+#endif
25541+
25542+#endif
25543+
25544+3: __copyuser_seg movl -3(%_ASM_AX),%edx
25545 xor %eax,%eax
25546 ASM_CLAC
25547+ pax_force_retaddr
25548 ret
25549 CFI_ENDPROC
25550 ENDPROC(__get_user_4)
25551@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
25552 GET_THREAD_INFO(%_ASM_DX)
25553 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25554 jae bad_get_user
25555+
25556+#ifdef CONFIG_PAX_MEMORY_UDEREF
25557+ mov pax_user_shadow_base,%_ASM_DX
25558+ cmp %_ASM_DX,%_ASM_AX
25559+ jae 1234f
25560+ add %_ASM_DX,%_ASM_AX
25561+1234:
25562+#endif
25563+
25564 ASM_STAC
25565 4: movq -7(%_ASM_AX),%rdx
25566 xor %eax,%eax
25567 ASM_CLAC
25568+ pax_force_retaddr
25569 ret
25570 #else
25571 add $7,%_ASM_AX
25572@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
25573 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25574 jae bad_get_user_8
25575 ASM_STAC
25576-4: movl -7(%_ASM_AX),%edx
25577-5: movl -3(%_ASM_AX),%ecx
25578+4: __copyuser_seg movl -7(%_ASM_AX),%edx
25579+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
25580 xor %eax,%eax
25581 ASM_CLAC
25582+ pax_force_retaddr
25583 ret
25584 #endif
25585 CFI_ENDPROC
25586@@ -113,6 +175,7 @@ bad_get_user:
25587 xor %edx,%edx
25588 mov $(-EFAULT),%_ASM_AX
25589 ASM_CLAC
25590+ pax_force_retaddr
25591 ret
25592 CFI_ENDPROC
25593 END(bad_get_user)
25594@@ -124,6 +187,7 @@ bad_get_user_8:
25595 xor %ecx,%ecx
25596 mov $(-EFAULT),%_ASM_AX
25597 ASM_CLAC
25598+ pax_force_retaddr
25599 ret
25600 CFI_ENDPROC
25601 END(bad_get_user_8)
25602diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25603index 54fcffe..7be149e 100644
25604--- a/arch/x86/lib/insn.c
25605+++ b/arch/x86/lib/insn.c
25606@@ -20,8 +20,10 @@
25607
25608 #ifdef __KERNEL__
25609 #include <linux/string.h>
25610+#include <asm/pgtable_types.h>
25611 #else
25612 #include <string.h>
25613+#define ktla_ktva(addr) addr
25614 #endif
25615 #include <asm/inat.h>
25616 #include <asm/insn.h>
25617@@ -53,8 +55,8 @@
25618 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25619 {
25620 memset(insn, 0, sizeof(*insn));
25621- insn->kaddr = kaddr;
25622- insn->next_byte = kaddr;
25623+ insn->kaddr = ktla_ktva(kaddr);
25624+ insn->next_byte = ktla_ktva(kaddr);
25625 insn->x86_64 = x86_64 ? 1 : 0;
25626 insn->opnd_bytes = 4;
25627 if (x86_64)
25628diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25629index 05a95e7..326f2fa 100644
25630--- a/arch/x86/lib/iomap_copy_64.S
25631+++ b/arch/x86/lib/iomap_copy_64.S
25632@@ -17,6 +17,7 @@
25633
25634 #include <linux/linkage.h>
25635 #include <asm/dwarf2.h>
25636+#include <asm/alternative-asm.h>
25637
25638 /*
25639 * override generic version in lib/iomap_copy.c
25640@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25641 CFI_STARTPROC
25642 movl %edx,%ecx
25643 rep movsd
25644+ pax_force_retaddr
25645 ret
25646 CFI_ENDPROC
25647 ENDPROC(__iowrite32_copy)
25648diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25649index 56313a3..aa84a79 100644
25650--- a/arch/x86/lib/memcpy_64.S
25651+++ b/arch/x86/lib/memcpy_64.S
25652@@ -33,6 +33,7 @@
25653 rep movsq
25654 movl %edx, %ecx
25655 rep movsb
25656+ pax_force_retaddr
25657 ret
25658 .Lmemcpy_e:
25659 .previous
25660@@ -49,6 +50,7 @@
25661 movq %rdi, %rax
25662 movq %rdx, %rcx
25663 rep movsb
25664+ pax_force_retaddr
25665 ret
25666 .Lmemcpy_e_e:
25667 .previous
25668@@ -76,13 +78,13 @@ ENTRY(memcpy)
25669 */
25670 movq 0*8(%rsi), %r8
25671 movq 1*8(%rsi), %r9
25672- movq 2*8(%rsi), %r10
25673+ movq 2*8(%rsi), %rcx
25674 movq 3*8(%rsi), %r11
25675 leaq 4*8(%rsi), %rsi
25676
25677 movq %r8, 0*8(%rdi)
25678 movq %r9, 1*8(%rdi)
25679- movq %r10, 2*8(%rdi)
25680+ movq %rcx, 2*8(%rdi)
25681 movq %r11, 3*8(%rdi)
25682 leaq 4*8(%rdi), %rdi
25683 jae .Lcopy_forward_loop
25684@@ -105,12 +107,12 @@ ENTRY(memcpy)
25685 subq $0x20, %rdx
25686 movq -1*8(%rsi), %r8
25687 movq -2*8(%rsi), %r9
25688- movq -3*8(%rsi), %r10
25689+ movq -3*8(%rsi), %rcx
25690 movq -4*8(%rsi), %r11
25691 leaq -4*8(%rsi), %rsi
25692 movq %r8, -1*8(%rdi)
25693 movq %r9, -2*8(%rdi)
25694- movq %r10, -3*8(%rdi)
25695+ movq %rcx, -3*8(%rdi)
25696 movq %r11, -4*8(%rdi)
25697 leaq -4*8(%rdi), %rdi
25698 jae .Lcopy_backward_loop
25699@@ -130,12 +132,13 @@ ENTRY(memcpy)
25700 */
25701 movq 0*8(%rsi), %r8
25702 movq 1*8(%rsi), %r9
25703- movq -2*8(%rsi, %rdx), %r10
25704+ movq -2*8(%rsi, %rdx), %rcx
25705 movq -1*8(%rsi, %rdx), %r11
25706 movq %r8, 0*8(%rdi)
25707 movq %r9, 1*8(%rdi)
25708- movq %r10, -2*8(%rdi, %rdx)
25709+ movq %rcx, -2*8(%rdi, %rdx)
25710 movq %r11, -1*8(%rdi, %rdx)
25711+ pax_force_retaddr
25712 retq
25713 .p2align 4
25714 .Lless_16bytes:
25715@@ -148,6 +151,7 @@ ENTRY(memcpy)
25716 movq -1*8(%rsi, %rdx), %r9
25717 movq %r8, 0*8(%rdi)
25718 movq %r9, -1*8(%rdi, %rdx)
25719+ pax_force_retaddr
25720 retq
25721 .p2align 4
25722 .Lless_8bytes:
25723@@ -161,6 +165,7 @@ ENTRY(memcpy)
25724 movl -4(%rsi, %rdx), %r8d
25725 movl %ecx, (%rdi)
25726 movl %r8d, -4(%rdi, %rdx)
25727+ pax_force_retaddr
25728 retq
25729 .p2align 4
25730 .Lless_3bytes:
25731@@ -179,6 +184,7 @@ ENTRY(memcpy)
25732 movb %cl, (%rdi)
25733
25734 .Lend:
25735+ pax_force_retaddr
25736 retq
25737 CFI_ENDPROC
25738 ENDPROC(memcpy)
25739diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25740index 65268a6..c9518d1 100644
25741--- a/arch/x86/lib/memmove_64.S
25742+++ b/arch/x86/lib/memmove_64.S
25743@@ -61,13 +61,13 @@ ENTRY(memmove)
25744 5:
25745 sub $0x20, %rdx
25746 movq 0*8(%rsi), %r11
25747- movq 1*8(%rsi), %r10
25748+ movq 1*8(%rsi), %rcx
25749 movq 2*8(%rsi), %r9
25750 movq 3*8(%rsi), %r8
25751 leaq 4*8(%rsi), %rsi
25752
25753 movq %r11, 0*8(%rdi)
25754- movq %r10, 1*8(%rdi)
25755+ movq %rcx, 1*8(%rdi)
25756 movq %r9, 2*8(%rdi)
25757 movq %r8, 3*8(%rdi)
25758 leaq 4*8(%rdi), %rdi
25759@@ -81,10 +81,10 @@ ENTRY(memmove)
25760 4:
25761 movq %rdx, %rcx
25762 movq -8(%rsi, %rdx), %r11
25763- lea -8(%rdi, %rdx), %r10
25764+ lea -8(%rdi, %rdx), %r9
25765 shrq $3, %rcx
25766 rep movsq
25767- movq %r11, (%r10)
25768+ movq %r11, (%r9)
25769 jmp 13f
25770 .Lmemmove_end_forward:
25771
25772@@ -95,14 +95,14 @@ ENTRY(memmove)
25773 7:
25774 movq %rdx, %rcx
25775 movq (%rsi), %r11
25776- movq %rdi, %r10
25777+ movq %rdi, %r9
25778 leaq -8(%rsi, %rdx), %rsi
25779 leaq -8(%rdi, %rdx), %rdi
25780 shrq $3, %rcx
25781 std
25782 rep movsq
25783 cld
25784- movq %r11, (%r10)
25785+ movq %r11, (%r9)
25786 jmp 13f
25787
25788 /*
25789@@ -127,13 +127,13 @@ ENTRY(memmove)
25790 8:
25791 subq $0x20, %rdx
25792 movq -1*8(%rsi), %r11
25793- movq -2*8(%rsi), %r10
25794+ movq -2*8(%rsi), %rcx
25795 movq -3*8(%rsi), %r9
25796 movq -4*8(%rsi), %r8
25797 leaq -4*8(%rsi), %rsi
25798
25799 movq %r11, -1*8(%rdi)
25800- movq %r10, -2*8(%rdi)
25801+ movq %rcx, -2*8(%rdi)
25802 movq %r9, -3*8(%rdi)
25803 movq %r8, -4*8(%rdi)
25804 leaq -4*8(%rdi), %rdi
25805@@ -151,11 +151,11 @@ ENTRY(memmove)
25806 * Move data from 16 bytes to 31 bytes.
25807 */
25808 movq 0*8(%rsi), %r11
25809- movq 1*8(%rsi), %r10
25810+ movq 1*8(%rsi), %rcx
25811 movq -2*8(%rsi, %rdx), %r9
25812 movq -1*8(%rsi, %rdx), %r8
25813 movq %r11, 0*8(%rdi)
25814- movq %r10, 1*8(%rdi)
25815+ movq %rcx, 1*8(%rdi)
25816 movq %r9, -2*8(%rdi, %rdx)
25817 movq %r8, -1*8(%rdi, %rdx)
25818 jmp 13f
25819@@ -167,9 +167,9 @@ ENTRY(memmove)
25820 * Move data from 8 bytes to 15 bytes.
25821 */
25822 movq 0*8(%rsi), %r11
25823- movq -1*8(%rsi, %rdx), %r10
25824+ movq -1*8(%rsi, %rdx), %r9
25825 movq %r11, 0*8(%rdi)
25826- movq %r10, -1*8(%rdi, %rdx)
25827+ movq %r9, -1*8(%rdi, %rdx)
25828 jmp 13f
25829 10:
25830 cmpq $4, %rdx
25831@@ -178,9 +178,9 @@ ENTRY(memmove)
25832 * Move data from 4 bytes to 7 bytes.
25833 */
25834 movl (%rsi), %r11d
25835- movl -4(%rsi, %rdx), %r10d
25836+ movl -4(%rsi, %rdx), %r9d
25837 movl %r11d, (%rdi)
25838- movl %r10d, -4(%rdi, %rdx)
25839+ movl %r9d, -4(%rdi, %rdx)
25840 jmp 13f
25841 11:
25842 cmp $2, %rdx
25843@@ -189,9 +189,9 @@ ENTRY(memmove)
25844 * Move data from 2 bytes to 3 bytes.
25845 */
25846 movw (%rsi), %r11w
25847- movw -2(%rsi, %rdx), %r10w
25848+ movw -2(%rsi, %rdx), %r9w
25849 movw %r11w, (%rdi)
25850- movw %r10w, -2(%rdi, %rdx)
25851+ movw %r9w, -2(%rdi, %rdx)
25852 jmp 13f
25853 12:
25854 cmp $1, %rdx
25855@@ -202,6 +202,7 @@ ENTRY(memmove)
25856 movb (%rsi), %r11b
25857 movb %r11b, (%rdi)
25858 13:
25859+ pax_force_retaddr
25860 retq
25861 CFI_ENDPROC
25862
25863@@ -210,6 +211,7 @@ ENTRY(memmove)
25864 /* Forward moving data. */
25865 movq %rdx, %rcx
25866 rep movsb
25867+ pax_force_retaddr
25868 retq
25869 .Lmemmove_end_forward_efs:
25870 .previous
25871diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25872index 2dcb380..963660a 100644
25873--- a/arch/x86/lib/memset_64.S
25874+++ b/arch/x86/lib/memset_64.S
25875@@ -30,6 +30,7 @@
25876 movl %edx,%ecx
25877 rep stosb
25878 movq %r9,%rax
25879+ pax_force_retaddr
25880 ret
25881 .Lmemset_e:
25882 .previous
25883@@ -52,6 +53,7 @@
25884 movq %rdx,%rcx
25885 rep stosb
25886 movq %r9,%rax
25887+ pax_force_retaddr
25888 ret
25889 .Lmemset_e_e:
25890 .previous
25891@@ -59,7 +61,7 @@
25892 ENTRY(memset)
25893 ENTRY(__memset)
25894 CFI_STARTPROC
25895- movq %rdi,%r10
25896+ movq %rdi,%r11
25897
25898 /* expand byte value */
25899 movzbl %sil,%ecx
25900@@ -117,7 +119,8 @@ ENTRY(__memset)
25901 jnz .Lloop_1
25902
25903 .Lende:
25904- movq %r10,%rax
25905+ movq %r11,%rax
25906+ pax_force_retaddr
25907 ret
25908
25909 CFI_RESTORE_STATE
25910diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25911index c9f2d9b..e7fd2c0 100644
25912--- a/arch/x86/lib/mmx_32.c
25913+++ b/arch/x86/lib/mmx_32.c
25914@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25915 {
25916 void *p;
25917 int i;
25918+ unsigned long cr0;
25919
25920 if (unlikely(in_interrupt()))
25921 return __memcpy(to, from, len);
25922@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25923 kernel_fpu_begin();
25924
25925 __asm__ __volatile__ (
25926- "1: prefetch (%0)\n" /* This set is 28 bytes */
25927- " prefetch 64(%0)\n"
25928- " prefetch 128(%0)\n"
25929- " prefetch 192(%0)\n"
25930- " prefetch 256(%0)\n"
25931+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25932+ " prefetch 64(%1)\n"
25933+ " prefetch 128(%1)\n"
25934+ " prefetch 192(%1)\n"
25935+ " prefetch 256(%1)\n"
25936 "2: \n"
25937 ".section .fixup, \"ax\"\n"
25938- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25939+ "3: \n"
25940+
25941+#ifdef CONFIG_PAX_KERNEXEC
25942+ " movl %%cr0, %0\n"
25943+ " movl %0, %%eax\n"
25944+ " andl $0xFFFEFFFF, %%eax\n"
25945+ " movl %%eax, %%cr0\n"
25946+#endif
25947+
25948+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25949+
25950+#ifdef CONFIG_PAX_KERNEXEC
25951+ " movl %0, %%cr0\n"
25952+#endif
25953+
25954 " jmp 2b\n"
25955 ".previous\n"
25956 _ASM_EXTABLE(1b, 3b)
25957- : : "r" (from));
25958+ : "=&r" (cr0) : "r" (from) : "ax");
25959
25960 for ( ; i > 5; i--) {
25961 __asm__ __volatile__ (
25962- "1: prefetch 320(%0)\n"
25963- "2: movq (%0), %%mm0\n"
25964- " movq 8(%0), %%mm1\n"
25965- " movq 16(%0), %%mm2\n"
25966- " movq 24(%0), %%mm3\n"
25967- " movq %%mm0, (%1)\n"
25968- " movq %%mm1, 8(%1)\n"
25969- " movq %%mm2, 16(%1)\n"
25970- " movq %%mm3, 24(%1)\n"
25971- " movq 32(%0), %%mm0\n"
25972- " movq 40(%0), %%mm1\n"
25973- " movq 48(%0), %%mm2\n"
25974- " movq 56(%0), %%mm3\n"
25975- " movq %%mm0, 32(%1)\n"
25976- " movq %%mm1, 40(%1)\n"
25977- " movq %%mm2, 48(%1)\n"
25978- " movq %%mm3, 56(%1)\n"
25979+ "1: prefetch 320(%1)\n"
25980+ "2: movq (%1), %%mm0\n"
25981+ " movq 8(%1), %%mm1\n"
25982+ " movq 16(%1), %%mm2\n"
25983+ " movq 24(%1), %%mm3\n"
25984+ " movq %%mm0, (%2)\n"
25985+ " movq %%mm1, 8(%2)\n"
25986+ " movq %%mm2, 16(%2)\n"
25987+ " movq %%mm3, 24(%2)\n"
25988+ " movq 32(%1), %%mm0\n"
25989+ " movq 40(%1), %%mm1\n"
25990+ " movq 48(%1), %%mm2\n"
25991+ " movq 56(%1), %%mm3\n"
25992+ " movq %%mm0, 32(%2)\n"
25993+ " movq %%mm1, 40(%2)\n"
25994+ " movq %%mm2, 48(%2)\n"
25995+ " movq %%mm3, 56(%2)\n"
25996 ".section .fixup, \"ax\"\n"
25997- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25998+ "3:\n"
25999+
26000+#ifdef CONFIG_PAX_KERNEXEC
26001+ " movl %%cr0, %0\n"
26002+ " movl %0, %%eax\n"
26003+ " andl $0xFFFEFFFF, %%eax\n"
26004+ " movl %%eax, %%cr0\n"
26005+#endif
26006+
26007+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26008+
26009+#ifdef CONFIG_PAX_KERNEXEC
26010+ " movl %0, %%cr0\n"
26011+#endif
26012+
26013 " jmp 2b\n"
26014 ".previous\n"
26015 _ASM_EXTABLE(1b, 3b)
26016- : : "r" (from), "r" (to) : "memory");
26017+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26018
26019 from += 64;
26020 to += 64;
26021@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
26022 static void fast_copy_page(void *to, void *from)
26023 {
26024 int i;
26025+ unsigned long cr0;
26026
26027 kernel_fpu_begin();
26028
26029@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
26030 * but that is for later. -AV
26031 */
26032 __asm__ __volatile__(
26033- "1: prefetch (%0)\n"
26034- " prefetch 64(%0)\n"
26035- " prefetch 128(%0)\n"
26036- " prefetch 192(%0)\n"
26037- " prefetch 256(%0)\n"
26038+ "1: prefetch (%1)\n"
26039+ " prefetch 64(%1)\n"
26040+ " prefetch 128(%1)\n"
26041+ " prefetch 192(%1)\n"
26042+ " prefetch 256(%1)\n"
26043 "2: \n"
26044 ".section .fixup, \"ax\"\n"
26045- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26046+ "3: \n"
26047+
26048+#ifdef CONFIG_PAX_KERNEXEC
26049+ " movl %%cr0, %0\n"
26050+ " movl %0, %%eax\n"
26051+ " andl $0xFFFEFFFF, %%eax\n"
26052+ " movl %%eax, %%cr0\n"
26053+#endif
26054+
26055+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26056+
26057+#ifdef CONFIG_PAX_KERNEXEC
26058+ " movl %0, %%cr0\n"
26059+#endif
26060+
26061 " jmp 2b\n"
26062 ".previous\n"
26063- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26064+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26065
26066 for (i = 0; i < (4096-320)/64; i++) {
26067 __asm__ __volatile__ (
26068- "1: prefetch 320(%0)\n"
26069- "2: movq (%0), %%mm0\n"
26070- " movntq %%mm0, (%1)\n"
26071- " movq 8(%0), %%mm1\n"
26072- " movntq %%mm1, 8(%1)\n"
26073- " movq 16(%0), %%mm2\n"
26074- " movntq %%mm2, 16(%1)\n"
26075- " movq 24(%0), %%mm3\n"
26076- " movntq %%mm3, 24(%1)\n"
26077- " movq 32(%0), %%mm4\n"
26078- " movntq %%mm4, 32(%1)\n"
26079- " movq 40(%0), %%mm5\n"
26080- " movntq %%mm5, 40(%1)\n"
26081- " movq 48(%0), %%mm6\n"
26082- " movntq %%mm6, 48(%1)\n"
26083- " movq 56(%0), %%mm7\n"
26084- " movntq %%mm7, 56(%1)\n"
26085+ "1: prefetch 320(%1)\n"
26086+ "2: movq (%1), %%mm0\n"
26087+ " movntq %%mm0, (%2)\n"
26088+ " movq 8(%1), %%mm1\n"
26089+ " movntq %%mm1, 8(%2)\n"
26090+ " movq 16(%1), %%mm2\n"
26091+ " movntq %%mm2, 16(%2)\n"
26092+ " movq 24(%1), %%mm3\n"
26093+ " movntq %%mm3, 24(%2)\n"
26094+ " movq 32(%1), %%mm4\n"
26095+ " movntq %%mm4, 32(%2)\n"
26096+ " movq 40(%1), %%mm5\n"
26097+ " movntq %%mm5, 40(%2)\n"
26098+ " movq 48(%1), %%mm6\n"
26099+ " movntq %%mm6, 48(%2)\n"
26100+ " movq 56(%1), %%mm7\n"
26101+ " movntq %%mm7, 56(%2)\n"
26102 ".section .fixup, \"ax\"\n"
26103- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26104+ "3:\n"
26105+
26106+#ifdef CONFIG_PAX_KERNEXEC
26107+ " movl %%cr0, %0\n"
26108+ " movl %0, %%eax\n"
26109+ " andl $0xFFFEFFFF, %%eax\n"
26110+ " movl %%eax, %%cr0\n"
26111+#endif
26112+
26113+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26114+
26115+#ifdef CONFIG_PAX_KERNEXEC
26116+ " movl %0, %%cr0\n"
26117+#endif
26118+
26119 " jmp 2b\n"
26120 ".previous\n"
26121- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26122+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26123
26124 from += 64;
26125 to += 64;
26126@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26127 static void fast_copy_page(void *to, void *from)
26128 {
26129 int i;
26130+ unsigned long cr0;
26131
26132 kernel_fpu_begin();
26133
26134 __asm__ __volatile__ (
26135- "1: prefetch (%0)\n"
26136- " prefetch 64(%0)\n"
26137- " prefetch 128(%0)\n"
26138- " prefetch 192(%0)\n"
26139- " prefetch 256(%0)\n"
26140+ "1: prefetch (%1)\n"
26141+ " prefetch 64(%1)\n"
26142+ " prefetch 128(%1)\n"
26143+ " prefetch 192(%1)\n"
26144+ " prefetch 256(%1)\n"
26145 "2: \n"
26146 ".section .fixup, \"ax\"\n"
26147- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26148+ "3: \n"
26149+
26150+#ifdef CONFIG_PAX_KERNEXEC
26151+ " movl %%cr0, %0\n"
26152+ " movl %0, %%eax\n"
26153+ " andl $0xFFFEFFFF, %%eax\n"
26154+ " movl %%eax, %%cr0\n"
26155+#endif
26156+
26157+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26158+
26159+#ifdef CONFIG_PAX_KERNEXEC
26160+ " movl %0, %%cr0\n"
26161+#endif
26162+
26163 " jmp 2b\n"
26164 ".previous\n"
26165- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26166+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26167
26168 for (i = 0; i < 4096/64; i++) {
26169 __asm__ __volatile__ (
26170- "1: prefetch 320(%0)\n"
26171- "2: movq (%0), %%mm0\n"
26172- " movq 8(%0), %%mm1\n"
26173- " movq 16(%0), %%mm2\n"
26174- " movq 24(%0), %%mm3\n"
26175- " movq %%mm0, (%1)\n"
26176- " movq %%mm1, 8(%1)\n"
26177- " movq %%mm2, 16(%1)\n"
26178- " movq %%mm3, 24(%1)\n"
26179- " movq 32(%0), %%mm0\n"
26180- " movq 40(%0), %%mm1\n"
26181- " movq 48(%0), %%mm2\n"
26182- " movq 56(%0), %%mm3\n"
26183- " movq %%mm0, 32(%1)\n"
26184- " movq %%mm1, 40(%1)\n"
26185- " movq %%mm2, 48(%1)\n"
26186- " movq %%mm3, 56(%1)\n"
26187+ "1: prefetch 320(%1)\n"
26188+ "2: movq (%1), %%mm0\n"
26189+ " movq 8(%1), %%mm1\n"
26190+ " movq 16(%1), %%mm2\n"
26191+ " movq 24(%1), %%mm3\n"
26192+ " movq %%mm0, (%2)\n"
26193+ " movq %%mm1, 8(%2)\n"
26194+ " movq %%mm2, 16(%2)\n"
26195+ " movq %%mm3, 24(%2)\n"
26196+ " movq 32(%1), %%mm0\n"
26197+ " movq 40(%1), %%mm1\n"
26198+ " movq 48(%1), %%mm2\n"
26199+ " movq 56(%1), %%mm3\n"
26200+ " movq %%mm0, 32(%2)\n"
26201+ " movq %%mm1, 40(%2)\n"
26202+ " movq %%mm2, 48(%2)\n"
26203+ " movq %%mm3, 56(%2)\n"
26204 ".section .fixup, \"ax\"\n"
26205- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26206+ "3:\n"
26207+
26208+#ifdef CONFIG_PAX_KERNEXEC
26209+ " movl %%cr0, %0\n"
26210+ " movl %0, %%eax\n"
26211+ " andl $0xFFFEFFFF, %%eax\n"
26212+ " movl %%eax, %%cr0\n"
26213+#endif
26214+
26215+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26216+
26217+#ifdef CONFIG_PAX_KERNEXEC
26218+ " movl %0, %%cr0\n"
26219+#endif
26220+
26221 " jmp 2b\n"
26222 ".previous\n"
26223 _ASM_EXTABLE(1b, 3b)
26224- : : "r" (from), "r" (to) : "memory");
26225+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26226
26227 from += 64;
26228 to += 64;
26229diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26230index f6d13ee..aca5f0b 100644
26231--- a/arch/x86/lib/msr-reg.S
26232+++ b/arch/x86/lib/msr-reg.S
26233@@ -3,6 +3,7 @@
26234 #include <asm/dwarf2.h>
26235 #include <asm/asm.h>
26236 #include <asm/msr.h>
26237+#include <asm/alternative-asm.h>
26238
26239 #ifdef CONFIG_X86_64
26240 /*
26241@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26242 CFI_STARTPROC
26243 pushq_cfi %rbx
26244 pushq_cfi %rbp
26245- movq %rdi, %r10 /* Save pointer */
26246+ movq %rdi, %r9 /* Save pointer */
26247 xorl %r11d, %r11d /* Return value */
26248 movl (%rdi), %eax
26249 movl 4(%rdi), %ecx
26250@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26251 movl 28(%rdi), %edi
26252 CFI_REMEMBER_STATE
26253 1: \op
26254-2: movl %eax, (%r10)
26255+2: movl %eax, (%r9)
26256 movl %r11d, %eax /* Return value */
26257- movl %ecx, 4(%r10)
26258- movl %edx, 8(%r10)
26259- movl %ebx, 12(%r10)
26260- movl %ebp, 20(%r10)
26261- movl %esi, 24(%r10)
26262- movl %edi, 28(%r10)
26263+ movl %ecx, 4(%r9)
26264+ movl %edx, 8(%r9)
26265+ movl %ebx, 12(%r9)
26266+ movl %ebp, 20(%r9)
26267+ movl %esi, 24(%r9)
26268+ movl %edi, 28(%r9)
26269 popq_cfi %rbp
26270 popq_cfi %rbx
26271+ pax_force_retaddr
26272 ret
26273 3:
26274 CFI_RESTORE_STATE
26275diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26276index fc6ba17..d4d989d 100644
26277--- a/arch/x86/lib/putuser.S
26278+++ b/arch/x86/lib/putuser.S
26279@@ -16,7 +16,9 @@
26280 #include <asm/errno.h>
26281 #include <asm/asm.h>
26282 #include <asm/smap.h>
26283-
26284+#include <asm/segment.h>
26285+#include <asm/pgtable.h>
26286+#include <asm/alternative-asm.h>
26287
26288 /*
26289 * __put_user_X
26290@@ -30,57 +32,125 @@
26291 * as they get called from within inline assembly.
26292 */
26293
26294-#define ENTER CFI_STARTPROC ; \
26295- GET_THREAD_INFO(%_ASM_BX)
26296-#define EXIT ASM_CLAC ; \
26297- ret ; \
26298+#define ENTER CFI_STARTPROC
26299+#define EXIT ASM_CLAC ; \
26300+ pax_force_retaddr ; \
26301+ ret ; \
26302 CFI_ENDPROC
26303
26304+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26305+#define _DEST %_ASM_CX,%_ASM_BX
26306+#else
26307+#define _DEST %_ASM_CX
26308+#endif
26309+
26310+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26311+#define __copyuser_seg gs;
26312+#else
26313+#define __copyuser_seg
26314+#endif
26315+
26316 .text
26317 ENTRY(__put_user_1)
26318 ENTER
26319+
26320+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26321+ GET_THREAD_INFO(%_ASM_BX)
26322 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26323 jae bad_put_user
26324 ASM_STAC
26325-1: movb %al,(%_ASM_CX)
26326+
26327+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26328+ mov pax_user_shadow_base,%_ASM_BX
26329+ cmp %_ASM_BX,%_ASM_CX
26330+ jb 1234f
26331+ xor %ebx,%ebx
26332+1234:
26333+#endif
26334+
26335+#endif
26336+
26337+1: __copyuser_seg movb %al,(_DEST)
26338 xor %eax,%eax
26339 EXIT
26340 ENDPROC(__put_user_1)
26341
26342 ENTRY(__put_user_2)
26343 ENTER
26344+
26345+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26346+ GET_THREAD_INFO(%_ASM_BX)
26347 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26348 sub $1,%_ASM_BX
26349 cmp %_ASM_BX,%_ASM_CX
26350 jae bad_put_user
26351 ASM_STAC
26352-2: movw %ax,(%_ASM_CX)
26353+
26354+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26355+ mov pax_user_shadow_base,%_ASM_BX
26356+ cmp %_ASM_BX,%_ASM_CX
26357+ jb 1234f
26358+ xor %ebx,%ebx
26359+1234:
26360+#endif
26361+
26362+#endif
26363+
26364+2: __copyuser_seg movw %ax,(_DEST)
26365 xor %eax,%eax
26366 EXIT
26367 ENDPROC(__put_user_2)
26368
26369 ENTRY(__put_user_4)
26370 ENTER
26371+
26372+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26373+ GET_THREAD_INFO(%_ASM_BX)
26374 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26375 sub $3,%_ASM_BX
26376 cmp %_ASM_BX,%_ASM_CX
26377 jae bad_put_user
26378 ASM_STAC
26379-3: movl %eax,(%_ASM_CX)
26380+
26381+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26382+ mov pax_user_shadow_base,%_ASM_BX
26383+ cmp %_ASM_BX,%_ASM_CX
26384+ jb 1234f
26385+ xor %ebx,%ebx
26386+1234:
26387+#endif
26388+
26389+#endif
26390+
26391+3: __copyuser_seg movl %eax,(_DEST)
26392 xor %eax,%eax
26393 EXIT
26394 ENDPROC(__put_user_4)
26395
26396 ENTRY(__put_user_8)
26397 ENTER
26398+
26399+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26400+ GET_THREAD_INFO(%_ASM_BX)
26401 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26402 sub $7,%_ASM_BX
26403 cmp %_ASM_BX,%_ASM_CX
26404 jae bad_put_user
26405 ASM_STAC
26406-4: mov %_ASM_AX,(%_ASM_CX)
26407+
26408+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26409+ mov pax_user_shadow_base,%_ASM_BX
26410+ cmp %_ASM_BX,%_ASM_CX
26411+ jb 1234f
26412+ xor %ebx,%ebx
26413+1234:
26414+#endif
26415+
26416+#endif
26417+
26418+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26419 #ifdef CONFIG_X86_32
26420-5: movl %edx,4(%_ASM_CX)
26421+5: __copyuser_seg movl %edx,4(_DEST)
26422 #endif
26423 xor %eax,%eax
26424 EXIT
26425diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26426index 1cad221..de671ee 100644
26427--- a/arch/x86/lib/rwlock.S
26428+++ b/arch/x86/lib/rwlock.S
26429@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26430 FRAME
26431 0: LOCK_PREFIX
26432 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26433+
26434+#ifdef CONFIG_PAX_REFCOUNT
26435+ jno 1234f
26436+ LOCK_PREFIX
26437+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26438+ int $4
26439+1234:
26440+ _ASM_EXTABLE(1234b, 1234b)
26441+#endif
26442+
26443 1: rep; nop
26444 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26445 jne 1b
26446 LOCK_PREFIX
26447 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26448+
26449+#ifdef CONFIG_PAX_REFCOUNT
26450+ jno 1234f
26451+ LOCK_PREFIX
26452+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26453+ int $4
26454+1234:
26455+ _ASM_EXTABLE(1234b, 1234b)
26456+#endif
26457+
26458 jnz 0b
26459 ENDFRAME
26460+ pax_force_retaddr
26461 ret
26462 CFI_ENDPROC
26463 END(__write_lock_failed)
26464@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26465 FRAME
26466 0: LOCK_PREFIX
26467 READ_LOCK_SIZE(inc) (%__lock_ptr)
26468+
26469+#ifdef CONFIG_PAX_REFCOUNT
26470+ jno 1234f
26471+ LOCK_PREFIX
26472+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26473+ int $4
26474+1234:
26475+ _ASM_EXTABLE(1234b, 1234b)
26476+#endif
26477+
26478 1: rep; nop
26479 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26480 js 1b
26481 LOCK_PREFIX
26482 READ_LOCK_SIZE(dec) (%__lock_ptr)
26483+
26484+#ifdef CONFIG_PAX_REFCOUNT
26485+ jno 1234f
26486+ LOCK_PREFIX
26487+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26488+ int $4
26489+1234:
26490+ _ASM_EXTABLE(1234b, 1234b)
26491+#endif
26492+
26493 js 0b
26494 ENDFRAME
26495+ pax_force_retaddr
26496 ret
26497 CFI_ENDPROC
26498 END(__read_lock_failed)
26499diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26500index 5dff5f0..cadebf4 100644
26501--- a/arch/x86/lib/rwsem.S
26502+++ b/arch/x86/lib/rwsem.S
26503@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26504 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26505 CFI_RESTORE __ASM_REG(dx)
26506 restore_common_regs
26507+ pax_force_retaddr
26508 ret
26509 CFI_ENDPROC
26510 ENDPROC(call_rwsem_down_read_failed)
26511@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26512 movq %rax,%rdi
26513 call rwsem_down_write_failed
26514 restore_common_regs
26515+ pax_force_retaddr
26516 ret
26517 CFI_ENDPROC
26518 ENDPROC(call_rwsem_down_write_failed)
26519@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26520 movq %rax,%rdi
26521 call rwsem_wake
26522 restore_common_regs
26523-1: ret
26524+1: pax_force_retaddr
26525+ ret
26526 CFI_ENDPROC
26527 ENDPROC(call_rwsem_wake)
26528
26529@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26530 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26531 CFI_RESTORE __ASM_REG(dx)
26532 restore_common_regs
26533+ pax_force_retaddr
26534 ret
26535 CFI_ENDPROC
26536 ENDPROC(call_rwsem_downgrade_wake)
26537diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26538index a63efd6..ccecad8 100644
26539--- a/arch/x86/lib/thunk_64.S
26540+++ b/arch/x86/lib/thunk_64.S
26541@@ -8,6 +8,7 @@
26542 #include <linux/linkage.h>
26543 #include <asm/dwarf2.h>
26544 #include <asm/calling.h>
26545+#include <asm/alternative-asm.h>
26546
26547 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26548 .macro THUNK name, func, put_ret_addr_in_rdi=0
26549@@ -41,5 +42,6 @@
26550 SAVE_ARGS
26551 restore:
26552 RESTORE_ARGS
26553+ pax_force_retaddr
26554 ret
26555 CFI_ENDPROC
26556diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26557index 3eb18ac..6890bc3 100644
26558--- a/arch/x86/lib/usercopy_32.c
26559+++ b/arch/x86/lib/usercopy_32.c
26560@@ -42,11 +42,13 @@ do { \
26561 int __d0; \
26562 might_fault(); \
26563 __asm__ __volatile__( \
26564+ __COPYUSER_SET_ES \
26565 ASM_STAC "\n" \
26566 "0: rep; stosl\n" \
26567 " movl %2,%0\n" \
26568 "1: rep; stosb\n" \
26569 "2: " ASM_CLAC "\n" \
26570+ __COPYUSER_RESTORE_ES \
26571 ".section .fixup,\"ax\"\n" \
26572 "3: lea 0(%2,%0,4),%0\n" \
26573 " jmp 2b\n" \
26574@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26575
26576 #ifdef CONFIG_X86_INTEL_USERCOPY
26577 static unsigned long
26578-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26579+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26580 {
26581 int d0, d1;
26582 __asm__ __volatile__(
26583@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26584 " .align 2,0x90\n"
26585 "3: movl 0(%4), %%eax\n"
26586 "4: movl 4(%4), %%edx\n"
26587- "5: movl %%eax, 0(%3)\n"
26588- "6: movl %%edx, 4(%3)\n"
26589+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26590+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26591 "7: movl 8(%4), %%eax\n"
26592 "8: movl 12(%4),%%edx\n"
26593- "9: movl %%eax, 8(%3)\n"
26594- "10: movl %%edx, 12(%3)\n"
26595+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26596+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26597 "11: movl 16(%4), %%eax\n"
26598 "12: movl 20(%4), %%edx\n"
26599- "13: movl %%eax, 16(%3)\n"
26600- "14: movl %%edx, 20(%3)\n"
26601+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26602+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26603 "15: movl 24(%4), %%eax\n"
26604 "16: movl 28(%4), %%edx\n"
26605- "17: movl %%eax, 24(%3)\n"
26606- "18: movl %%edx, 28(%3)\n"
26607+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26608+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26609 "19: movl 32(%4), %%eax\n"
26610 "20: movl 36(%4), %%edx\n"
26611- "21: movl %%eax, 32(%3)\n"
26612- "22: movl %%edx, 36(%3)\n"
26613+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26614+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26615 "23: movl 40(%4), %%eax\n"
26616 "24: movl 44(%4), %%edx\n"
26617- "25: movl %%eax, 40(%3)\n"
26618- "26: movl %%edx, 44(%3)\n"
26619+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26620+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26621 "27: movl 48(%4), %%eax\n"
26622 "28: movl 52(%4), %%edx\n"
26623- "29: movl %%eax, 48(%3)\n"
26624- "30: movl %%edx, 52(%3)\n"
26625+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26626+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26627 "31: movl 56(%4), %%eax\n"
26628 "32: movl 60(%4), %%edx\n"
26629- "33: movl %%eax, 56(%3)\n"
26630- "34: movl %%edx, 60(%3)\n"
26631+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26632+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26633 " addl $-64, %0\n"
26634 " addl $64, %4\n"
26635 " addl $64, %3\n"
26636@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26637 " shrl $2, %0\n"
26638 " andl $3, %%eax\n"
26639 " cld\n"
26640+ __COPYUSER_SET_ES
26641 "99: rep; movsl\n"
26642 "36: movl %%eax, %0\n"
26643 "37: rep; movsb\n"
26644 "100:\n"
26645+ __COPYUSER_RESTORE_ES
26646 ".section .fixup,\"ax\"\n"
26647 "101: lea 0(%%eax,%0,4),%0\n"
26648 " jmp 100b\n"
26649@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26650 }
26651
26652 static unsigned long
26653+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26654+{
26655+ int d0, d1;
26656+ __asm__ __volatile__(
26657+ " .align 2,0x90\n"
26658+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26659+ " cmpl $67, %0\n"
26660+ " jbe 3f\n"
26661+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26662+ " .align 2,0x90\n"
26663+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26664+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26665+ "5: movl %%eax, 0(%3)\n"
26666+ "6: movl %%edx, 4(%3)\n"
26667+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26668+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26669+ "9: movl %%eax, 8(%3)\n"
26670+ "10: movl %%edx, 12(%3)\n"
26671+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26672+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26673+ "13: movl %%eax, 16(%3)\n"
26674+ "14: movl %%edx, 20(%3)\n"
26675+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26676+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26677+ "17: movl %%eax, 24(%3)\n"
26678+ "18: movl %%edx, 28(%3)\n"
26679+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26680+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26681+ "21: movl %%eax, 32(%3)\n"
26682+ "22: movl %%edx, 36(%3)\n"
26683+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26684+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26685+ "25: movl %%eax, 40(%3)\n"
26686+ "26: movl %%edx, 44(%3)\n"
26687+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26688+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26689+ "29: movl %%eax, 48(%3)\n"
26690+ "30: movl %%edx, 52(%3)\n"
26691+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26692+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26693+ "33: movl %%eax, 56(%3)\n"
26694+ "34: movl %%edx, 60(%3)\n"
26695+ " addl $-64, %0\n"
26696+ " addl $64, %4\n"
26697+ " addl $64, %3\n"
26698+ " cmpl $63, %0\n"
26699+ " ja 1b\n"
26700+ "35: movl %0, %%eax\n"
26701+ " shrl $2, %0\n"
26702+ " andl $3, %%eax\n"
26703+ " cld\n"
26704+ "99: rep; "__copyuser_seg" movsl\n"
26705+ "36: movl %%eax, %0\n"
26706+ "37: rep; "__copyuser_seg" movsb\n"
26707+ "100:\n"
26708+ ".section .fixup,\"ax\"\n"
26709+ "101: lea 0(%%eax,%0,4),%0\n"
26710+ " jmp 100b\n"
26711+ ".previous\n"
26712+ _ASM_EXTABLE(1b,100b)
26713+ _ASM_EXTABLE(2b,100b)
26714+ _ASM_EXTABLE(3b,100b)
26715+ _ASM_EXTABLE(4b,100b)
26716+ _ASM_EXTABLE(5b,100b)
26717+ _ASM_EXTABLE(6b,100b)
26718+ _ASM_EXTABLE(7b,100b)
26719+ _ASM_EXTABLE(8b,100b)
26720+ _ASM_EXTABLE(9b,100b)
26721+ _ASM_EXTABLE(10b,100b)
26722+ _ASM_EXTABLE(11b,100b)
26723+ _ASM_EXTABLE(12b,100b)
26724+ _ASM_EXTABLE(13b,100b)
26725+ _ASM_EXTABLE(14b,100b)
26726+ _ASM_EXTABLE(15b,100b)
26727+ _ASM_EXTABLE(16b,100b)
26728+ _ASM_EXTABLE(17b,100b)
26729+ _ASM_EXTABLE(18b,100b)
26730+ _ASM_EXTABLE(19b,100b)
26731+ _ASM_EXTABLE(20b,100b)
26732+ _ASM_EXTABLE(21b,100b)
26733+ _ASM_EXTABLE(22b,100b)
26734+ _ASM_EXTABLE(23b,100b)
26735+ _ASM_EXTABLE(24b,100b)
26736+ _ASM_EXTABLE(25b,100b)
26737+ _ASM_EXTABLE(26b,100b)
26738+ _ASM_EXTABLE(27b,100b)
26739+ _ASM_EXTABLE(28b,100b)
26740+ _ASM_EXTABLE(29b,100b)
26741+ _ASM_EXTABLE(30b,100b)
26742+ _ASM_EXTABLE(31b,100b)
26743+ _ASM_EXTABLE(32b,100b)
26744+ _ASM_EXTABLE(33b,100b)
26745+ _ASM_EXTABLE(34b,100b)
26746+ _ASM_EXTABLE(35b,100b)
26747+ _ASM_EXTABLE(36b,100b)
26748+ _ASM_EXTABLE(37b,100b)
26749+ _ASM_EXTABLE(99b,101b)
26750+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26751+ : "1"(to), "2"(from), "0"(size)
26752+ : "eax", "edx", "memory");
26753+ return size;
26754+}
26755+
26756+static unsigned long __size_overflow(3)
26757 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26758 {
26759 int d0, d1;
26760 __asm__ __volatile__(
26761 " .align 2,0x90\n"
26762- "0: movl 32(%4), %%eax\n"
26763+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26764 " cmpl $67, %0\n"
26765 " jbe 2f\n"
26766- "1: movl 64(%4), %%eax\n"
26767+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26768 " .align 2,0x90\n"
26769- "2: movl 0(%4), %%eax\n"
26770- "21: movl 4(%4), %%edx\n"
26771+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26772+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26773 " movl %%eax, 0(%3)\n"
26774 " movl %%edx, 4(%3)\n"
26775- "3: movl 8(%4), %%eax\n"
26776- "31: movl 12(%4),%%edx\n"
26777+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26778+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26779 " movl %%eax, 8(%3)\n"
26780 " movl %%edx, 12(%3)\n"
26781- "4: movl 16(%4), %%eax\n"
26782- "41: movl 20(%4), %%edx\n"
26783+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26784+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26785 " movl %%eax, 16(%3)\n"
26786 " movl %%edx, 20(%3)\n"
26787- "10: movl 24(%4), %%eax\n"
26788- "51: movl 28(%4), %%edx\n"
26789+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26790+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26791 " movl %%eax, 24(%3)\n"
26792 " movl %%edx, 28(%3)\n"
26793- "11: movl 32(%4), %%eax\n"
26794- "61: movl 36(%4), %%edx\n"
26795+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26796+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26797 " movl %%eax, 32(%3)\n"
26798 " movl %%edx, 36(%3)\n"
26799- "12: movl 40(%4), %%eax\n"
26800- "71: movl 44(%4), %%edx\n"
26801+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26802+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26803 " movl %%eax, 40(%3)\n"
26804 " movl %%edx, 44(%3)\n"
26805- "13: movl 48(%4), %%eax\n"
26806- "81: movl 52(%4), %%edx\n"
26807+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26808+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26809 " movl %%eax, 48(%3)\n"
26810 " movl %%edx, 52(%3)\n"
26811- "14: movl 56(%4), %%eax\n"
26812- "91: movl 60(%4), %%edx\n"
26813+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26814+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26815 " movl %%eax, 56(%3)\n"
26816 " movl %%edx, 60(%3)\n"
26817 " addl $-64, %0\n"
26818@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26819 " shrl $2, %0\n"
26820 " andl $3, %%eax\n"
26821 " cld\n"
26822- "6: rep; movsl\n"
26823+ "6: rep; "__copyuser_seg" movsl\n"
26824 " movl %%eax,%0\n"
26825- "7: rep; movsb\n"
26826+ "7: rep; "__copyuser_seg" movsb\n"
26827 "8:\n"
26828 ".section .fixup,\"ax\"\n"
26829 "9: lea 0(%%eax,%0,4),%0\n"
26830@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26831 * hyoshiok@miraclelinux.com
26832 */
26833
26834-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26835+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26836 const void __user *from, unsigned long size)
26837 {
26838 int d0, d1;
26839
26840 __asm__ __volatile__(
26841 " .align 2,0x90\n"
26842- "0: movl 32(%4), %%eax\n"
26843+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26844 " cmpl $67, %0\n"
26845 " jbe 2f\n"
26846- "1: movl 64(%4), %%eax\n"
26847+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26848 " .align 2,0x90\n"
26849- "2: movl 0(%4), %%eax\n"
26850- "21: movl 4(%4), %%edx\n"
26851+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26852+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26853 " movnti %%eax, 0(%3)\n"
26854 " movnti %%edx, 4(%3)\n"
26855- "3: movl 8(%4), %%eax\n"
26856- "31: movl 12(%4),%%edx\n"
26857+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26858+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26859 " movnti %%eax, 8(%3)\n"
26860 " movnti %%edx, 12(%3)\n"
26861- "4: movl 16(%4), %%eax\n"
26862- "41: movl 20(%4), %%edx\n"
26863+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26864+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26865 " movnti %%eax, 16(%3)\n"
26866 " movnti %%edx, 20(%3)\n"
26867- "10: movl 24(%4), %%eax\n"
26868- "51: movl 28(%4), %%edx\n"
26869+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26870+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26871 " movnti %%eax, 24(%3)\n"
26872 " movnti %%edx, 28(%3)\n"
26873- "11: movl 32(%4), %%eax\n"
26874- "61: movl 36(%4), %%edx\n"
26875+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26876+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26877 " movnti %%eax, 32(%3)\n"
26878 " movnti %%edx, 36(%3)\n"
26879- "12: movl 40(%4), %%eax\n"
26880- "71: movl 44(%4), %%edx\n"
26881+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26882+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26883 " movnti %%eax, 40(%3)\n"
26884 " movnti %%edx, 44(%3)\n"
26885- "13: movl 48(%4), %%eax\n"
26886- "81: movl 52(%4), %%edx\n"
26887+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26888+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26889 " movnti %%eax, 48(%3)\n"
26890 " movnti %%edx, 52(%3)\n"
26891- "14: movl 56(%4), %%eax\n"
26892- "91: movl 60(%4), %%edx\n"
26893+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26894+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26895 " movnti %%eax, 56(%3)\n"
26896 " movnti %%edx, 60(%3)\n"
26897 " addl $-64, %0\n"
26898@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26899 " shrl $2, %0\n"
26900 " andl $3, %%eax\n"
26901 " cld\n"
26902- "6: rep; movsl\n"
26903+ "6: rep; "__copyuser_seg" movsl\n"
26904 " movl %%eax,%0\n"
26905- "7: rep; movsb\n"
26906+ "7: rep; "__copyuser_seg" movsb\n"
26907 "8:\n"
26908 ".section .fixup,\"ax\"\n"
26909 "9: lea 0(%%eax,%0,4),%0\n"
26910@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26911 return size;
26912 }
26913
26914-static unsigned long __copy_user_intel_nocache(void *to,
26915+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26916 const void __user *from, unsigned long size)
26917 {
26918 int d0, d1;
26919
26920 __asm__ __volatile__(
26921 " .align 2,0x90\n"
26922- "0: movl 32(%4), %%eax\n"
26923+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26924 " cmpl $67, %0\n"
26925 " jbe 2f\n"
26926- "1: movl 64(%4), %%eax\n"
26927+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26928 " .align 2,0x90\n"
26929- "2: movl 0(%4), %%eax\n"
26930- "21: movl 4(%4), %%edx\n"
26931+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26932+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26933 " movnti %%eax, 0(%3)\n"
26934 " movnti %%edx, 4(%3)\n"
26935- "3: movl 8(%4), %%eax\n"
26936- "31: movl 12(%4),%%edx\n"
26937+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26938+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26939 " movnti %%eax, 8(%3)\n"
26940 " movnti %%edx, 12(%3)\n"
26941- "4: movl 16(%4), %%eax\n"
26942- "41: movl 20(%4), %%edx\n"
26943+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26944+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26945 " movnti %%eax, 16(%3)\n"
26946 " movnti %%edx, 20(%3)\n"
26947- "10: movl 24(%4), %%eax\n"
26948- "51: movl 28(%4), %%edx\n"
26949+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26950+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26951 " movnti %%eax, 24(%3)\n"
26952 " movnti %%edx, 28(%3)\n"
26953- "11: movl 32(%4), %%eax\n"
26954- "61: movl 36(%4), %%edx\n"
26955+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26956+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26957 " movnti %%eax, 32(%3)\n"
26958 " movnti %%edx, 36(%3)\n"
26959- "12: movl 40(%4), %%eax\n"
26960- "71: movl 44(%4), %%edx\n"
26961+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26962+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26963 " movnti %%eax, 40(%3)\n"
26964 " movnti %%edx, 44(%3)\n"
26965- "13: movl 48(%4), %%eax\n"
26966- "81: movl 52(%4), %%edx\n"
26967+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26968+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26969 " movnti %%eax, 48(%3)\n"
26970 " movnti %%edx, 52(%3)\n"
26971- "14: movl 56(%4), %%eax\n"
26972- "91: movl 60(%4), %%edx\n"
26973+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26974+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26975 " movnti %%eax, 56(%3)\n"
26976 " movnti %%edx, 60(%3)\n"
26977 " addl $-64, %0\n"
26978@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26979 " shrl $2, %0\n"
26980 " andl $3, %%eax\n"
26981 " cld\n"
26982- "6: rep; movsl\n"
26983+ "6: rep; "__copyuser_seg" movsl\n"
26984 " movl %%eax,%0\n"
26985- "7: rep; movsb\n"
26986+ "7: rep; "__copyuser_seg" movsb\n"
26987 "8:\n"
26988 ".section .fixup,\"ax\"\n"
26989 "9: lea 0(%%eax,%0,4),%0\n"
26990@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26991 */
26992 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26993 unsigned long size);
26994-unsigned long __copy_user_intel(void __user *to, const void *from,
26995+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26996+ unsigned long size);
26997+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26998 unsigned long size);
26999 unsigned long __copy_user_zeroing_intel_nocache(void *to,
27000 const void __user *from, unsigned long size);
27001 #endif /* CONFIG_X86_INTEL_USERCOPY */
27002
27003 /* Generic arbitrary sized copy. */
27004-#define __copy_user(to, from, size) \
27005+#define __copy_user(to, from, size, prefix, set, restore) \
27006 do { \
27007 int __d0, __d1, __d2; \
27008 __asm__ __volatile__( \
27009+ set \
27010 " cmp $7,%0\n" \
27011 " jbe 1f\n" \
27012 " movl %1,%0\n" \
27013 " negl %0\n" \
27014 " andl $7,%0\n" \
27015 " subl %0,%3\n" \
27016- "4: rep; movsb\n" \
27017+ "4: rep; "prefix"movsb\n" \
27018 " movl %3,%0\n" \
27019 " shrl $2,%0\n" \
27020 " andl $3,%3\n" \
27021 " .align 2,0x90\n" \
27022- "0: rep; movsl\n" \
27023+ "0: rep; "prefix"movsl\n" \
27024 " movl %3,%0\n" \
27025- "1: rep; movsb\n" \
27026+ "1: rep; "prefix"movsb\n" \
27027 "2:\n" \
27028+ restore \
27029 ".section .fixup,\"ax\"\n" \
27030 "5: addl %3,%0\n" \
27031 " jmp 2b\n" \
27032@@ -538,14 +650,14 @@ do { \
27033 " negl %0\n" \
27034 " andl $7,%0\n" \
27035 " subl %0,%3\n" \
27036- "4: rep; movsb\n" \
27037+ "4: rep; "__copyuser_seg"movsb\n" \
27038 " movl %3,%0\n" \
27039 " shrl $2,%0\n" \
27040 " andl $3,%3\n" \
27041 " .align 2,0x90\n" \
27042- "0: rep; movsl\n" \
27043+ "0: rep; "__copyuser_seg"movsl\n" \
27044 " movl %3,%0\n" \
27045- "1: rep; movsb\n" \
27046+ "1: rep; "__copyuser_seg"movsb\n" \
27047 "2:\n" \
27048 ".section .fixup,\"ax\"\n" \
27049 "5: addl %3,%0\n" \
27050@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27051 {
27052 stac();
27053 if (movsl_is_ok(to, from, n))
27054- __copy_user(to, from, n);
27055+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27056 else
27057- n = __copy_user_intel(to, from, n);
27058+ n = __generic_copy_to_user_intel(to, from, n);
27059 clac();
27060 return n;
27061 }
27062@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27063 {
27064 stac();
27065 if (movsl_is_ok(to, from, n))
27066- __copy_user(to, from, n);
27067+ __copy_user(to, from, n, __copyuser_seg, "", "");
27068 else
27069- n = __copy_user_intel((void __user *)to,
27070- (const void *)from, n);
27071+ n = __generic_copy_from_user_intel(to, from, n);
27072 clac();
27073 return n;
27074 }
27075@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27076 if (n > 64 && cpu_has_xmm2)
27077 n = __copy_user_intel_nocache(to, from, n);
27078 else
27079- __copy_user(to, from, n);
27080+ __copy_user(to, from, n, __copyuser_seg, "", "");
27081 #else
27082- __copy_user(to, from, n);
27083+ __copy_user(to, from, n, __copyuser_seg, "", "");
27084 #endif
27085 clac();
27086 return n;
27087 }
27088 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27089
27090-/**
27091- * copy_to_user: - Copy a block of data into user space.
27092- * @to: Destination address, in user space.
27093- * @from: Source address, in kernel space.
27094- * @n: Number of bytes to copy.
27095- *
27096- * Context: User context only. This function may sleep.
27097- *
27098- * Copy data from kernel space to user space.
27099- *
27100- * Returns number of bytes that could not be copied.
27101- * On success, this will be zero.
27102- */
27103-unsigned long
27104-copy_to_user(void __user *to, const void *from, unsigned long n)
27105+#ifdef CONFIG_PAX_MEMORY_UDEREF
27106+void __set_fs(mm_segment_t x)
27107 {
27108- if (access_ok(VERIFY_WRITE, to, n))
27109- n = __copy_to_user(to, from, n);
27110- return n;
27111+ switch (x.seg) {
27112+ case 0:
27113+ loadsegment(gs, 0);
27114+ break;
27115+ case TASK_SIZE_MAX:
27116+ loadsegment(gs, __USER_DS);
27117+ break;
27118+ case -1UL:
27119+ loadsegment(gs, __KERNEL_DS);
27120+ break;
27121+ default:
27122+ BUG();
27123+ }
27124 }
27125-EXPORT_SYMBOL(copy_to_user);
27126+EXPORT_SYMBOL(__set_fs);
27127
27128-/**
27129- * copy_from_user: - Copy a block of data from user space.
27130- * @to: Destination address, in kernel space.
27131- * @from: Source address, in user space.
27132- * @n: Number of bytes to copy.
27133- *
27134- * Context: User context only. This function may sleep.
27135- *
27136- * Copy data from user space to kernel space.
27137- *
27138- * Returns number of bytes that could not be copied.
27139- * On success, this will be zero.
27140- *
27141- * If some data could not be copied, this function will pad the copied
27142- * data to the requested size using zero bytes.
27143- */
27144-unsigned long
27145-_copy_from_user(void *to, const void __user *from, unsigned long n)
27146+void set_fs(mm_segment_t x)
27147 {
27148- if (access_ok(VERIFY_READ, from, n))
27149- n = __copy_from_user(to, from, n);
27150- else
27151- memset(to, 0, n);
27152- return n;
27153+ current_thread_info()->addr_limit = x;
27154+ __set_fs(x);
27155 }
27156-EXPORT_SYMBOL(_copy_from_user);
27157+EXPORT_SYMBOL(set_fs);
27158+#endif
27159diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27160index 906fea3..5646695 100644
27161--- a/arch/x86/lib/usercopy_64.c
27162+++ b/arch/x86/lib/usercopy_64.c
27163@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27164 _ASM_EXTABLE(0b,3b)
27165 _ASM_EXTABLE(1b,2b)
27166 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27167- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27168+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27169 [zero] "r" (0UL), [eight] "r" (8UL));
27170 clac();
27171 return size;
27172@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27173 }
27174 EXPORT_SYMBOL(clear_user);
27175
27176-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27177+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27178 {
27179- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27180- return copy_user_generic((__force void *)to, (__force void *)from, len);
27181- }
27182- return len;
27183+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27184+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27185+ return len;
27186 }
27187 EXPORT_SYMBOL(copy_in_user);
27188
27189@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27190 * it is not necessary to optimize tail handling.
27191 */
27192 unsigned long
27193-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27194+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27195 {
27196 char c;
27197 unsigned zero_len;
27198diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27199index 903ec1e..c4166b2 100644
27200--- a/arch/x86/mm/extable.c
27201+++ b/arch/x86/mm/extable.c
27202@@ -6,12 +6,24 @@
27203 static inline unsigned long
27204 ex_insn_addr(const struct exception_table_entry *x)
27205 {
27206- return (unsigned long)&x->insn + x->insn;
27207+ unsigned long reloc = 0;
27208+
27209+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27210+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27211+#endif
27212+
27213+ return (unsigned long)&x->insn + x->insn + reloc;
27214 }
27215 static inline unsigned long
27216 ex_fixup_addr(const struct exception_table_entry *x)
27217 {
27218- return (unsigned long)&x->fixup + x->fixup;
27219+ unsigned long reloc = 0;
27220+
27221+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27222+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27223+#endif
27224+
27225+ return (unsigned long)&x->fixup + x->fixup + reloc;
27226 }
27227
27228 int fixup_exception(struct pt_regs *regs)
27229@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27230 unsigned long new_ip;
27231
27232 #ifdef CONFIG_PNPBIOS
27233- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27234+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27235 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27236 extern u32 pnp_bios_is_utter_crap;
27237 pnp_bios_is_utter_crap = 1;
27238@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27239 i += 4;
27240 p->fixup -= i;
27241 i += 4;
27242+
27243+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27244+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27245+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27246+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27247+#endif
27248+
27249 }
27250 }
27251
27252diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27253index 654be4a..d36985f 100644
27254--- a/arch/x86/mm/fault.c
27255+++ b/arch/x86/mm/fault.c
27256@@ -14,11 +14,18 @@
27257 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27258 #include <linux/prefetch.h> /* prefetchw */
27259 #include <linux/context_tracking.h> /* exception_enter(), ... */
27260+#include <linux/unistd.h>
27261+#include <linux/compiler.h>
27262
27263 #include <asm/traps.h> /* dotraplinkage, ... */
27264 #include <asm/pgalloc.h> /* pgd_*(), ... */
27265 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27266 #include <asm/fixmap.h> /* VSYSCALL_START */
27267+#include <asm/tlbflush.h>
27268+
27269+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27270+#include <asm/stacktrace.h>
27271+#endif
27272
27273 /*
27274 * Page fault error code bits:
27275@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27276 int ret = 0;
27277
27278 /* kprobe_running() needs smp_processor_id() */
27279- if (kprobes_built_in() && !user_mode_vm(regs)) {
27280+ if (kprobes_built_in() && !user_mode(regs)) {
27281 preempt_disable();
27282 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27283 ret = 1;
27284@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27285 return !instr_lo || (instr_lo>>1) == 1;
27286 case 0x00:
27287 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27288- if (probe_kernel_address(instr, opcode))
27289+ if (user_mode(regs)) {
27290+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27291+ return 0;
27292+ } else if (probe_kernel_address(instr, opcode))
27293 return 0;
27294
27295 *prefetch = (instr_lo == 0xF) &&
27296@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27297 while (instr < max_instr) {
27298 unsigned char opcode;
27299
27300- if (probe_kernel_address(instr, opcode))
27301+ if (user_mode(regs)) {
27302+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27303+ break;
27304+ } else if (probe_kernel_address(instr, opcode))
27305 break;
27306
27307 instr++;
27308@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27309 force_sig_info(si_signo, &info, tsk);
27310 }
27311
27312+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27313+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27314+#endif
27315+
27316+#ifdef CONFIG_PAX_EMUTRAMP
27317+static int pax_handle_fetch_fault(struct pt_regs *regs);
27318+#endif
27319+
27320+#ifdef CONFIG_PAX_PAGEEXEC
27321+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27322+{
27323+ pgd_t *pgd;
27324+ pud_t *pud;
27325+ pmd_t *pmd;
27326+
27327+ pgd = pgd_offset(mm, address);
27328+ if (!pgd_present(*pgd))
27329+ return NULL;
27330+ pud = pud_offset(pgd, address);
27331+ if (!pud_present(*pud))
27332+ return NULL;
27333+ pmd = pmd_offset(pud, address);
27334+ if (!pmd_present(*pmd))
27335+ return NULL;
27336+ return pmd;
27337+}
27338+#endif
27339+
27340 DEFINE_SPINLOCK(pgd_lock);
27341 LIST_HEAD(pgd_list);
27342
27343@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27344 for (address = VMALLOC_START & PMD_MASK;
27345 address >= TASK_SIZE && address < FIXADDR_TOP;
27346 address += PMD_SIZE) {
27347+
27348+#ifdef CONFIG_PAX_PER_CPU_PGD
27349+ unsigned long cpu;
27350+#else
27351 struct page *page;
27352+#endif
27353
27354 spin_lock(&pgd_lock);
27355+
27356+#ifdef CONFIG_PAX_PER_CPU_PGD
27357+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27358+ pgd_t *pgd = get_cpu_pgd(cpu);
27359+ pmd_t *ret;
27360+#else
27361 list_for_each_entry(page, &pgd_list, lru) {
27362+ pgd_t *pgd;
27363 spinlock_t *pgt_lock;
27364 pmd_t *ret;
27365
27366@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27367 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27368
27369 spin_lock(pgt_lock);
27370- ret = vmalloc_sync_one(page_address(page), address);
27371+ pgd = page_address(page);
27372+#endif
27373+
27374+ ret = vmalloc_sync_one(pgd, address);
27375+
27376+#ifndef CONFIG_PAX_PER_CPU_PGD
27377 spin_unlock(pgt_lock);
27378+#endif
27379
27380 if (!ret)
27381 break;
27382@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27383 * an interrupt in the middle of a task switch..
27384 */
27385 pgd_paddr = read_cr3();
27386+
27387+#ifdef CONFIG_PAX_PER_CPU_PGD
27388+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27389+#endif
27390+
27391 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27392 if (!pmd_k)
27393 return -1;
27394@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27395 * happen within a race in page table update. In the later
27396 * case just flush:
27397 */
27398+
27399+#ifdef CONFIG_PAX_PER_CPU_PGD
27400+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27401+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27402+#else
27403 pgd = pgd_offset(current->active_mm, address);
27404+#endif
27405+
27406 pgd_ref = pgd_offset_k(address);
27407 if (pgd_none(*pgd_ref))
27408 return -1;
27409@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27410 static int is_errata100(struct pt_regs *regs, unsigned long address)
27411 {
27412 #ifdef CONFIG_X86_64
27413- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27414+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27415 return 1;
27416 #endif
27417 return 0;
27418@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27419 }
27420
27421 static const char nx_warning[] = KERN_CRIT
27422-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27423+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27424
27425 static void
27426 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27427@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27428 if (!oops_may_print())
27429 return;
27430
27431- if (error_code & PF_INSTR) {
27432+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27433 unsigned int level;
27434
27435 pte_t *pte = lookup_address(address, &level);
27436
27437 if (pte && pte_present(*pte) && !pte_exec(*pte))
27438- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27439+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27440 }
27441
27442+#ifdef CONFIG_PAX_KERNEXEC
27443+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27444+ if (current->signal->curr_ip)
27445+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27446+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27447+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27448+ else
27449+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27450+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27451+ }
27452+#endif
27453+
27454 printk(KERN_ALERT "BUG: unable to handle kernel ");
27455 if (address < PAGE_SIZE)
27456 printk(KERN_CONT "NULL pointer dereference");
27457@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27458 return;
27459 }
27460 #endif
27461+
27462+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27463+ if (pax_is_fetch_fault(regs, error_code, address)) {
27464+
27465+#ifdef CONFIG_PAX_EMUTRAMP
27466+ switch (pax_handle_fetch_fault(regs)) {
27467+ case 2:
27468+ return;
27469+ }
27470+#endif
27471+
27472+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27473+ do_group_exit(SIGKILL);
27474+ }
27475+#endif
27476+
27477 /* Kernel addresses are always protection faults: */
27478 if (address >= TASK_SIZE)
27479 error_code |= PF_PROT;
27480@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27481 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27482 printk(KERN_ERR
27483 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27484- tsk->comm, tsk->pid, address);
27485+ tsk->comm, task_pid_nr(tsk), address);
27486 code = BUS_MCEERR_AR;
27487 }
27488 #endif
27489@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27490 return 1;
27491 }
27492
27493+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27494+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27495+{
27496+ pte_t *pte;
27497+ pmd_t *pmd;
27498+ spinlock_t *ptl;
27499+ unsigned char pte_mask;
27500+
27501+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27502+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27503+ return 0;
27504+
27505+ /* PaX: it's our fault, let's handle it if we can */
27506+
27507+ /* PaX: take a look at read faults before acquiring any locks */
27508+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27509+ /* instruction fetch attempt from a protected page in user mode */
27510+ up_read(&mm->mmap_sem);
27511+
27512+#ifdef CONFIG_PAX_EMUTRAMP
27513+ switch (pax_handle_fetch_fault(regs)) {
27514+ case 2:
27515+ return 1;
27516+ }
27517+#endif
27518+
27519+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27520+ do_group_exit(SIGKILL);
27521+ }
27522+
27523+ pmd = pax_get_pmd(mm, address);
27524+ if (unlikely(!pmd))
27525+ return 0;
27526+
27527+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27528+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27529+ pte_unmap_unlock(pte, ptl);
27530+ return 0;
27531+ }
27532+
27533+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27534+ /* write attempt to a protected page in user mode */
27535+ pte_unmap_unlock(pte, ptl);
27536+ return 0;
27537+ }
27538+
27539+#ifdef CONFIG_SMP
27540+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27541+#else
27542+ if (likely(address > get_limit(regs->cs)))
27543+#endif
27544+ {
27545+ set_pte(pte, pte_mkread(*pte));
27546+ __flush_tlb_one(address);
27547+ pte_unmap_unlock(pte, ptl);
27548+ up_read(&mm->mmap_sem);
27549+ return 1;
27550+ }
27551+
27552+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27553+
27554+ /*
27555+ * PaX: fill DTLB with user rights and retry
27556+ */
27557+ __asm__ __volatile__ (
27558+ "orb %2,(%1)\n"
27559+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27560+/*
27561+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27562+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27563+ * page fault when examined during a TLB load attempt. this is true not only
27564+ * for PTEs holding a non-present entry but also present entries that will
27565+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27566+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27567+ * for our target pages since their PTEs are simply not in the TLBs at all.
27568+
27569+ * the best thing in omitting it is that we gain around 15-20% speed in the
27570+ * fast path of the page fault handler and can get rid of tracing since we
27571+ * can no longer flush unintended entries.
27572+ */
27573+ "invlpg (%0)\n"
27574+#endif
27575+ __copyuser_seg"testb $0,(%0)\n"
27576+ "xorb %3,(%1)\n"
27577+ :
27578+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27579+ : "memory", "cc");
27580+ pte_unmap_unlock(pte, ptl);
27581+ up_read(&mm->mmap_sem);
27582+ return 1;
27583+}
27584+#endif
27585+
27586 /*
27587 * Handle a spurious fault caused by a stale TLB entry.
27588 *
27589@@ -964,6 +1156,9 @@ int show_unhandled_signals = 1;
27590 static inline int
27591 access_error(unsigned long error_code, struct vm_area_struct *vma)
27592 {
27593+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27594+ return 1;
27595+
27596 if (error_code & PF_WRITE) {
27597 /* write, present and write, not present: */
27598 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27599@@ -992,7 +1187,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27600 if (error_code & PF_USER)
27601 return false;
27602
27603- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27604+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27605 return false;
27606
27607 return true;
27608@@ -1008,18 +1203,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27609 {
27610 struct vm_area_struct *vma;
27611 struct task_struct *tsk;
27612- unsigned long address;
27613 struct mm_struct *mm;
27614 int fault;
27615 int write = error_code & PF_WRITE;
27616 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27617 (write ? FAULT_FLAG_WRITE : 0);
27618
27619- tsk = current;
27620- mm = tsk->mm;
27621-
27622 /* Get the faulting address: */
27623- address = read_cr2();
27624+ unsigned long address = read_cr2();
27625+
27626+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27627+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
27628+ if (!search_exception_tables(regs->ip)) {
27629+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27630+ bad_area_nosemaphore(regs, error_code, address);
27631+ return;
27632+ }
27633+ if (address < pax_user_shadow_base) {
27634+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27635+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27636+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27637+ } else
27638+ address -= pax_user_shadow_base;
27639+ }
27640+#endif
27641+
27642+ tsk = current;
27643+ mm = tsk->mm;
27644
27645 /*
27646 * Detect and handle instructions that would cause a page fault for
27647@@ -1080,7 +1290,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27648 * User-mode registers count as a user access even for any
27649 * potential system fault or CPU buglet:
27650 */
27651- if (user_mode_vm(regs)) {
27652+ if (user_mode(regs)) {
27653 local_irq_enable();
27654 error_code |= PF_USER;
27655 } else {
27656@@ -1142,6 +1352,11 @@ retry:
27657 might_sleep();
27658 }
27659
27660+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27661+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27662+ return;
27663+#endif
27664+
27665 vma = find_vma(mm, address);
27666 if (unlikely(!vma)) {
27667 bad_area(regs, error_code, address);
27668@@ -1153,18 +1368,24 @@ retry:
27669 bad_area(regs, error_code, address);
27670 return;
27671 }
27672- if (error_code & PF_USER) {
27673- /*
27674- * Accessing the stack below %sp is always a bug.
27675- * The large cushion allows instructions like enter
27676- * and pusha to work. ("enter $65535, $31" pushes
27677- * 32 pointers and then decrements %sp by 65535.)
27678- */
27679- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27680- bad_area(regs, error_code, address);
27681- return;
27682- }
27683+ /*
27684+ * Accessing the stack below %sp is always a bug.
27685+ * The large cushion allows instructions like enter
27686+ * and pusha to work. ("enter $65535, $31" pushes
27687+ * 32 pointers and then decrements %sp by 65535.)
27688+ */
27689+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27690+ bad_area(regs, error_code, address);
27691+ return;
27692 }
27693+
27694+#ifdef CONFIG_PAX_SEGMEXEC
27695+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27696+ bad_area(regs, error_code, address);
27697+ return;
27698+ }
27699+#endif
27700+
27701 if (unlikely(expand_stack(vma, address))) {
27702 bad_area(regs, error_code, address);
27703 return;
27704@@ -1230,3 +1451,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27705 __do_page_fault(regs, error_code);
27706 exception_exit(prev_state);
27707 }
27708+
27709+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27710+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27711+{
27712+ struct mm_struct *mm = current->mm;
27713+ unsigned long ip = regs->ip;
27714+
27715+ if (v8086_mode(regs))
27716+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27717+
27718+#ifdef CONFIG_PAX_PAGEEXEC
27719+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27720+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27721+ return true;
27722+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27723+ return true;
27724+ return false;
27725+ }
27726+#endif
27727+
27728+#ifdef CONFIG_PAX_SEGMEXEC
27729+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27730+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27731+ return true;
27732+ return false;
27733+ }
27734+#endif
27735+
27736+ return false;
27737+}
27738+#endif
27739+
27740+#ifdef CONFIG_PAX_EMUTRAMP
27741+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27742+{
27743+ int err;
27744+
27745+ do { /* PaX: libffi trampoline emulation */
27746+ unsigned char mov, jmp;
27747+ unsigned int addr1, addr2;
27748+
27749+#ifdef CONFIG_X86_64
27750+ if ((regs->ip + 9) >> 32)
27751+ break;
27752+#endif
27753+
27754+ err = get_user(mov, (unsigned char __user *)regs->ip);
27755+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27756+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27757+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27758+
27759+ if (err)
27760+ break;
27761+
27762+ if (mov == 0xB8 && jmp == 0xE9) {
27763+ regs->ax = addr1;
27764+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27765+ return 2;
27766+ }
27767+ } while (0);
27768+
27769+ do { /* PaX: gcc trampoline emulation #1 */
27770+ unsigned char mov1, mov2;
27771+ unsigned short jmp;
27772+ unsigned int addr1, addr2;
27773+
27774+#ifdef CONFIG_X86_64
27775+ if ((regs->ip + 11) >> 32)
27776+ break;
27777+#endif
27778+
27779+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27780+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27781+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27782+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27783+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27784+
27785+ if (err)
27786+ break;
27787+
27788+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27789+ regs->cx = addr1;
27790+ regs->ax = addr2;
27791+ regs->ip = addr2;
27792+ return 2;
27793+ }
27794+ } while (0);
27795+
27796+ do { /* PaX: gcc trampoline emulation #2 */
27797+ unsigned char mov, jmp;
27798+ unsigned int addr1, addr2;
27799+
27800+#ifdef CONFIG_X86_64
27801+ if ((regs->ip + 9) >> 32)
27802+ break;
27803+#endif
27804+
27805+ err = get_user(mov, (unsigned char __user *)regs->ip);
27806+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27807+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27808+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27809+
27810+ if (err)
27811+ break;
27812+
27813+ if (mov == 0xB9 && jmp == 0xE9) {
27814+ regs->cx = addr1;
27815+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27816+ return 2;
27817+ }
27818+ } while (0);
27819+
27820+ return 1; /* PaX in action */
27821+}
27822+
27823+#ifdef CONFIG_X86_64
27824+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27825+{
27826+ int err;
27827+
27828+ do { /* PaX: libffi trampoline emulation */
27829+ unsigned short mov1, mov2, jmp1;
27830+ unsigned char stcclc, jmp2;
27831+ unsigned long addr1, addr2;
27832+
27833+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27834+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27835+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27836+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27837+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27838+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27839+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27840+
27841+ if (err)
27842+ break;
27843+
27844+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27845+ regs->r11 = addr1;
27846+ regs->r10 = addr2;
27847+ if (stcclc == 0xF8)
27848+ regs->flags &= ~X86_EFLAGS_CF;
27849+ else
27850+ regs->flags |= X86_EFLAGS_CF;
27851+ regs->ip = addr1;
27852+ return 2;
27853+ }
27854+ } while (0);
27855+
27856+ do { /* PaX: gcc trampoline emulation #1 */
27857+ unsigned short mov1, mov2, jmp1;
27858+ unsigned char jmp2;
27859+ unsigned int addr1;
27860+ unsigned long addr2;
27861+
27862+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27863+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27864+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27865+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27866+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27867+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27868+
27869+ if (err)
27870+ break;
27871+
27872+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27873+ regs->r11 = addr1;
27874+ regs->r10 = addr2;
27875+ regs->ip = addr1;
27876+ return 2;
27877+ }
27878+ } while (0);
27879+
27880+ do { /* PaX: gcc trampoline emulation #2 */
27881+ unsigned short mov1, mov2, jmp1;
27882+ unsigned char jmp2;
27883+ unsigned long addr1, addr2;
27884+
27885+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27886+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27887+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27888+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27889+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27890+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27891+
27892+ if (err)
27893+ break;
27894+
27895+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27896+ regs->r11 = addr1;
27897+ regs->r10 = addr2;
27898+ regs->ip = addr1;
27899+ return 2;
27900+ }
27901+ } while (0);
27902+
27903+ return 1; /* PaX in action */
27904+}
27905+#endif
27906+
27907+/*
27908+ * PaX: decide what to do with offenders (regs->ip = fault address)
27909+ *
27910+ * returns 1 when task should be killed
27911+ * 2 when gcc trampoline was detected
27912+ */
27913+static int pax_handle_fetch_fault(struct pt_regs *regs)
27914+{
27915+ if (v8086_mode(regs))
27916+ return 1;
27917+
27918+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27919+ return 1;
27920+
27921+#ifdef CONFIG_X86_32
27922+ return pax_handle_fetch_fault_32(regs);
27923+#else
27924+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27925+ return pax_handle_fetch_fault_32(regs);
27926+ else
27927+ return pax_handle_fetch_fault_64(regs);
27928+#endif
27929+}
27930+#endif
27931+
27932+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27933+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27934+{
27935+ long i;
27936+
27937+ printk(KERN_ERR "PAX: bytes at PC: ");
27938+ for (i = 0; i < 20; i++) {
27939+ unsigned char c;
27940+ if (get_user(c, (unsigned char __force_user *)pc+i))
27941+ printk(KERN_CONT "?? ");
27942+ else
27943+ printk(KERN_CONT "%02x ", c);
27944+ }
27945+ printk("\n");
27946+
27947+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27948+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27949+ unsigned long c;
27950+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27951+#ifdef CONFIG_X86_32
27952+ printk(KERN_CONT "???????? ");
27953+#else
27954+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27955+ printk(KERN_CONT "???????? ???????? ");
27956+ else
27957+ printk(KERN_CONT "???????????????? ");
27958+#endif
27959+ } else {
27960+#ifdef CONFIG_X86_64
27961+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27962+ printk(KERN_CONT "%08x ", (unsigned int)c);
27963+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27964+ } else
27965+#endif
27966+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27967+ }
27968+ }
27969+ printk("\n");
27970+}
27971+#endif
27972+
27973+/**
27974+ * probe_kernel_write(): safely attempt to write to a location
27975+ * @dst: address to write to
27976+ * @src: pointer to the data that shall be written
27977+ * @size: size of the data chunk
27978+ *
27979+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27980+ * happens, handle that and return -EFAULT.
27981+ */
27982+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27983+{
27984+ long ret;
27985+ mm_segment_t old_fs = get_fs();
27986+
27987+ set_fs(KERNEL_DS);
27988+ pagefault_disable();
27989+ pax_open_kernel();
27990+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27991+ pax_close_kernel();
27992+ pagefault_enable();
27993+ set_fs(old_fs);
27994+
27995+ return ret ? -EFAULT : 0;
27996+}
27997diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27998index dd74e46..7d26398 100644
27999--- a/arch/x86/mm/gup.c
28000+++ b/arch/x86/mm/gup.c
28001@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
28002 addr = start;
28003 len = (unsigned long) nr_pages << PAGE_SHIFT;
28004 end = start + len;
28005- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28006+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
28007 (void __user *)start, len)))
28008 return 0;
28009
28010diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
28011index 252b8f5..4dcfdc1 100644
28012--- a/arch/x86/mm/highmem_32.c
28013+++ b/arch/x86/mm/highmem_32.c
28014@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
28015 idx = type + KM_TYPE_NR*smp_processor_id();
28016 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28017 BUG_ON(!pte_none(*(kmap_pte-idx)));
28018+
28019+ pax_open_kernel();
28020 set_pte(kmap_pte-idx, mk_pte(page, prot));
28021+ pax_close_kernel();
28022+
28023 arch_flush_lazy_mmu_mode();
28024
28025 return (void *)vaddr;
28026diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
28027index ae1aa71..d9bea75 100644
28028--- a/arch/x86/mm/hugetlbpage.c
28029+++ b/arch/x86/mm/hugetlbpage.c
28030@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
28031 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
28032 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
28033 unsigned long addr, unsigned long len,
28034- unsigned long pgoff, unsigned long flags)
28035+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28036 {
28037 struct hstate *h = hstate_file(file);
28038 struct vm_unmapped_area_info info;
28039-
28040+
28041 info.flags = 0;
28042 info.length = len;
28043 info.low_limit = TASK_UNMAPPED_BASE;
28044+
28045+#ifdef CONFIG_PAX_RANDMMAP
28046+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28047+ info.low_limit += current->mm->delta_mmap;
28048+#endif
28049+
28050 info.high_limit = TASK_SIZE;
28051 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28052 info.align_offset = 0;
28053+ info.threadstack_offset = offset;
28054 return vm_unmapped_area(&info);
28055 }
28056
28057 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28058 unsigned long addr0, unsigned long len,
28059- unsigned long pgoff, unsigned long flags)
28060+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28061 {
28062 struct hstate *h = hstate_file(file);
28063 struct vm_unmapped_area_info info;
28064@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28065 info.high_limit = current->mm->mmap_base;
28066 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28067 info.align_offset = 0;
28068+ info.threadstack_offset = offset;
28069 addr = vm_unmapped_area(&info);
28070
28071 /*
28072@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28073 VM_BUG_ON(addr != -ENOMEM);
28074 info.flags = 0;
28075 info.low_limit = TASK_UNMAPPED_BASE;
28076+
28077+#ifdef CONFIG_PAX_RANDMMAP
28078+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28079+ info.low_limit += current->mm->delta_mmap;
28080+#endif
28081+
28082 info.high_limit = TASK_SIZE;
28083 addr = vm_unmapped_area(&info);
28084 }
28085@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28086 struct hstate *h = hstate_file(file);
28087 struct mm_struct *mm = current->mm;
28088 struct vm_area_struct *vma;
28089+ unsigned long pax_task_size = TASK_SIZE;
28090+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28091
28092 if (len & ~huge_page_mask(h))
28093 return -EINVAL;
28094- if (len > TASK_SIZE)
28095+
28096+#ifdef CONFIG_PAX_SEGMEXEC
28097+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28098+ pax_task_size = SEGMEXEC_TASK_SIZE;
28099+#endif
28100+
28101+ pax_task_size -= PAGE_SIZE;
28102+
28103+ if (len > pax_task_size)
28104 return -ENOMEM;
28105
28106 if (flags & MAP_FIXED) {
28107@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28108 return addr;
28109 }
28110
28111+#ifdef CONFIG_PAX_RANDMMAP
28112+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28113+#endif
28114+
28115 if (addr) {
28116 addr = ALIGN(addr, huge_page_size(h));
28117 vma = find_vma(mm, addr);
28118- if (TASK_SIZE - len >= addr &&
28119- (!vma || addr + len <= vma->vm_start))
28120+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28121 return addr;
28122 }
28123 if (mm->get_unmapped_area == arch_get_unmapped_area)
28124 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
28125- pgoff, flags);
28126+ pgoff, flags, offset);
28127 else
28128 return hugetlb_get_unmapped_area_topdown(file, addr, len,
28129- pgoff, flags);
28130+ pgoff, flags, offset);
28131 }
28132
28133 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
28134diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28135index 1f34e92..d252637 100644
28136--- a/arch/x86/mm/init.c
28137+++ b/arch/x86/mm/init.c
28138@@ -4,6 +4,7 @@
28139 #include <linux/swap.h>
28140 #include <linux/memblock.h>
28141 #include <linux/bootmem.h> /* for max_low_pfn */
28142+#include <linux/tboot.h>
28143
28144 #include <asm/cacheflush.h>
28145 #include <asm/e820.h>
28146@@ -17,6 +18,8 @@
28147 #include <asm/proto.h>
28148 #include <asm/dma.h> /* for MAX_DMA_PFN */
28149 #include <asm/microcode.h>
28150+#include <asm/desc.h>
28151+#include <asm/bios_ebda.h>
28152
28153 #include "mm_internal.h"
28154
28155@@ -465,7 +468,15 @@ void __init init_mem_mapping(void)
28156 early_ioremap_page_table_range_init();
28157 #endif
28158
28159+#ifdef CONFIG_PAX_PER_CPU_PGD
28160+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28161+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28162+ KERNEL_PGD_PTRS);
28163+ load_cr3(get_cpu_pgd(0));
28164+#else
28165 load_cr3(swapper_pg_dir);
28166+#endif
28167+
28168 __flush_tlb_all();
28169
28170 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
28171@@ -481,10 +492,40 @@ void __init init_mem_mapping(void)
28172 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28173 * mmio resources as well as potential bios/acpi data regions.
28174 */
28175+
28176+#ifdef CONFIG_GRKERNSEC_KMEM
28177+static unsigned int ebda_start __read_only;
28178+static unsigned int ebda_end __read_only;
28179+#endif
28180+
28181 int devmem_is_allowed(unsigned long pagenr)
28182 {
28183- if (pagenr < 256)
28184+#ifdef CONFIG_GRKERNSEC_KMEM
28185+ /* allow BDA */
28186+ if (!pagenr)
28187 return 1;
28188+ /* allow EBDA */
28189+ if (pagenr >= ebda_start && pagenr < ebda_end)
28190+ return 1;
28191+ /* if tboot is in use, allow access to its hardcoded serial log range */
28192+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28193+ return 1;
28194+#else
28195+ if (!pagenr)
28196+ return 1;
28197+#ifdef CONFIG_VM86
28198+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28199+ return 1;
28200+#endif
28201+#endif
28202+
28203+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28204+ return 1;
28205+#ifdef CONFIG_GRKERNSEC_KMEM
28206+ /* throw out everything else below 1MB */
28207+ if (pagenr <= 256)
28208+ return 0;
28209+#endif
28210 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28211 return 0;
28212 if (!page_is_ram(pagenr))
28213@@ -538,8 +579,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28214 #endif
28215 }
28216
28217+#ifdef CONFIG_GRKERNSEC_KMEM
28218+static inline void gr_init_ebda(void)
28219+{
28220+ unsigned int ebda_addr;
28221+ unsigned int ebda_size = 0;
28222+
28223+ ebda_addr = get_bios_ebda();
28224+ if (ebda_addr) {
28225+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28226+ ebda_size <<= 10;
28227+ }
28228+ if (ebda_addr && ebda_size) {
28229+ ebda_start = ebda_addr >> PAGE_SHIFT;
28230+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28231+ } else {
28232+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28233+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28234+ }
28235+}
28236+#else
28237+static inline void gr_init_ebda(void) { }
28238+#endif
28239+
28240 void free_initmem(void)
28241 {
28242+#ifdef CONFIG_PAX_KERNEXEC
28243+#ifdef CONFIG_X86_32
28244+ /* PaX: limit KERNEL_CS to actual size */
28245+ unsigned long addr, limit;
28246+ struct desc_struct d;
28247+ int cpu;
28248+#else
28249+ pgd_t *pgd;
28250+ pud_t *pud;
28251+ pmd_t *pmd;
28252+ unsigned long addr, end;
28253+#endif
28254+#endif
28255+
28256+ gr_init_ebda();
28257+
28258+#ifdef CONFIG_PAX_KERNEXEC
28259+#ifdef CONFIG_X86_32
28260+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28261+ limit = (limit - 1UL) >> PAGE_SHIFT;
28262+
28263+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28264+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28265+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28266+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28267+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28268+ }
28269+
28270+ /* PaX: make KERNEL_CS read-only */
28271+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28272+ if (!paravirt_enabled())
28273+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28274+/*
28275+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28276+ pgd = pgd_offset_k(addr);
28277+ pud = pud_offset(pgd, addr);
28278+ pmd = pmd_offset(pud, addr);
28279+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28280+ }
28281+*/
28282+#ifdef CONFIG_X86_PAE
28283+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28284+/*
28285+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28286+ pgd = pgd_offset_k(addr);
28287+ pud = pud_offset(pgd, addr);
28288+ pmd = pmd_offset(pud, addr);
28289+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28290+ }
28291+*/
28292+#endif
28293+
28294+#ifdef CONFIG_MODULES
28295+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28296+#endif
28297+
28298+#else
28299+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28300+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28301+ pgd = pgd_offset_k(addr);
28302+ pud = pud_offset(pgd, addr);
28303+ pmd = pmd_offset(pud, addr);
28304+ if (!pmd_present(*pmd))
28305+ continue;
28306+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28307+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28308+ else
28309+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28310+ }
28311+
28312+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28313+ end = addr + KERNEL_IMAGE_SIZE;
28314+ for (; addr < end; addr += PMD_SIZE) {
28315+ pgd = pgd_offset_k(addr);
28316+ pud = pud_offset(pgd, addr);
28317+ pmd = pmd_offset(pud, addr);
28318+ if (!pmd_present(*pmd))
28319+ continue;
28320+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28321+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28322+ }
28323+#endif
28324+
28325+ flush_tlb_all();
28326+#endif
28327+
28328 free_init_pages("unused kernel memory",
28329 (unsigned long)(&__init_begin),
28330 (unsigned long)(&__init_end));
28331diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28332index 3ac7e31..89611b7 100644
28333--- a/arch/x86/mm/init_32.c
28334+++ b/arch/x86/mm/init_32.c
28335@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
28336 bool __read_mostly __vmalloc_start_set = false;
28337
28338 /*
28339- * Creates a middle page table and puts a pointer to it in the
28340- * given global directory entry. This only returns the gd entry
28341- * in non-PAE compilation mode, since the middle layer is folded.
28342- */
28343-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28344-{
28345- pud_t *pud;
28346- pmd_t *pmd_table;
28347-
28348-#ifdef CONFIG_X86_PAE
28349- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28350- pmd_table = (pmd_t *)alloc_low_page();
28351- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28352- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28353- pud = pud_offset(pgd, 0);
28354- BUG_ON(pmd_table != pmd_offset(pud, 0));
28355-
28356- return pmd_table;
28357- }
28358-#endif
28359- pud = pud_offset(pgd, 0);
28360- pmd_table = pmd_offset(pud, 0);
28361-
28362- return pmd_table;
28363-}
28364-
28365-/*
28366 * Create a page table and place a pointer to it in a middle page
28367 * directory entry:
28368 */
28369@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28370 pte_t *page_table = (pte_t *)alloc_low_page();
28371
28372 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28373+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28374+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28375+#else
28376 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28377+#endif
28378 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28379 }
28380
28381 return pte_offset_kernel(pmd, 0);
28382 }
28383
28384+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28385+{
28386+ pud_t *pud;
28387+ pmd_t *pmd_table;
28388+
28389+ pud = pud_offset(pgd, 0);
28390+ pmd_table = pmd_offset(pud, 0);
28391+
28392+ return pmd_table;
28393+}
28394+
28395 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28396 {
28397 int pgd_idx = pgd_index(vaddr);
28398@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28399 int pgd_idx, pmd_idx;
28400 unsigned long vaddr;
28401 pgd_t *pgd;
28402+ pud_t *pud;
28403 pmd_t *pmd;
28404 pte_t *pte = NULL;
28405 unsigned long count = page_table_range_init_count(start, end);
28406@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28407 pgd = pgd_base + pgd_idx;
28408
28409 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28410- pmd = one_md_table_init(pgd);
28411- pmd = pmd + pmd_index(vaddr);
28412+ pud = pud_offset(pgd, vaddr);
28413+ pmd = pmd_offset(pud, vaddr);
28414+
28415+#ifdef CONFIG_X86_PAE
28416+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28417+#endif
28418+
28419 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28420 pmd++, pmd_idx++) {
28421 pte = page_table_kmap_check(one_page_table_init(pmd),
28422@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28423 }
28424 }
28425
28426-static inline int is_kernel_text(unsigned long addr)
28427+static inline int is_kernel_text(unsigned long start, unsigned long end)
28428 {
28429- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28430- return 1;
28431- return 0;
28432+ if ((start > ktla_ktva((unsigned long)_etext) ||
28433+ end <= ktla_ktva((unsigned long)_stext)) &&
28434+ (start > ktla_ktva((unsigned long)_einittext) ||
28435+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28436+
28437+#ifdef CONFIG_ACPI_SLEEP
28438+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28439+#endif
28440+
28441+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28442+ return 0;
28443+ return 1;
28444 }
28445
28446 /*
28447@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
28448 unsigned long last_map_addr = end;
28449 unsigned long start_pfn, end_pfn;
28450 pgd_t *pgd_base = swapper_pg_dir;
28451- int pgd_idx, pmd_idx, pte_ofs;
28452+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28453 unsigned long pfn;
28454 pgd_t *pgd;
28455+ pud_t *pud;
28456 pmd_t *pmd;
28457 pte_t *pte;
28458 unsigned pages_2m, pages_4k;
28459@@ -291,8 +295,13 @@ repeat:
28460 pfn = start_pfn;
28461 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28462 pgd = pgd_base + pgd_idx;
28463- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28464- pmd = one_md_table_init(pgd);
28465+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28466+ pud = pud_offset(pgd, 0);
28467+ pmd = pmd_offset(pud, 0);
28468+
28469+#ifdef CONFIG_X86_PAE
28470+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28471+#endif
28472
28473 if (pfn >= end_pfn)
28474 continue;
28475@@ -304,14 +313,13 @@ repeat:
28476 #endif
28477 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28478 pmd++, pmd_idx++) {
28479- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28480+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28481
28482 /*
28483 * Map with big pages if possible, otherwise
28484 * create normal page tables:
28485 */
28486 if (use_pse) {
28487- unsigned int addr2;
28488 pgprot_t prot = PAGE_KERNEL_LARGE;
28489 /*
28490 * first pass will use the same initial
28491@@ -322,11 +330,7 @@ repeat:
28492 _PAGE_PSE);
28493
28494 pfn &= PMD_MASK >> PAGE_SHIFT;
28495- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28496- PAGE_OFFSET + PAGE_SIZE-1;
28497-
28498- if (is_kernel_text(addr) ||
28499- is_kernel_text(addr2))
28500+ if (is_kernel_text(address, address + PMD_SIZE))
28501 prot = PAGE_KERNEL_LARGE_EXEC;
28502
28503 pages_2m++;
28504@@ -343,7 +347,7 @@ repeat:
28505 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28506 pte += pte_ofs;
28507 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28508- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28509+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28510 pgprot_t prot = PAGE_KERNEL;
28511 /*
28512 * first pass will use the same initial
28513@@ -351,7 +355,7 @@ repeat:
28514 */
28515 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28516
28517- if (is_kernel_text(addr))
28518+ if (is_kernel_text(address, address + PAGE_SIZE))
28519 prot = PAGE_KERNEL_EXEC;
28520
28521 pages_4k++;
28522@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
28523
28524 pud = pud_offset(pgd, va);
28525 pmd = pmd_offset(pud, va);
28526- if (!pmd_present(*pmd))
28527+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
28528 break;
28529
28530 /* should not be large page here */
28531@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
28532
28533 static void __init pagetable_init(void)
28534 {
28535- pgd_t *pgd_base = swapper_pg_dir;
28536-
28537- permanent_kmaps_init(pgd_base);
28538+ permanent_kmaps_init(swapper_pg_dir);
28539 }
28540
28541-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28542+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28543 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28544
28545 /* user-defined highmem size */
28546@@ -772,7 +774,7 @@ void __init mem_init(void)
28547 after_bootmem = 1;
28548
28549 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28550- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28551+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28552 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28553
28554 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28555@@ -813,10 +815,10 @@ void __init mem_init(void)
28556 ((unsigned long)&__init_end -
28557 (unsigned long)&__init_begin) >> 10,
28558
28559- (unsigned long)&_etext, (unsigned long)&_edata,
28560- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28561+ (unsigned long)&_sdata, (unsigned long)&_edata,
28562+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28563
28564- (unsigned long)&_text, (unsigned long)&_etext,
28565+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28566 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28567
28568 /*
28569@@ -906,6 +908,7 @@ void set_kernel_text_rw(void)
28570 if (!kernel_set_to_readonly)
28571 return;
28572
28573+ start = ktla_ktva(start);
28574 pr_debug("Set kernel text: %lx - %lx for read write\n",
28575 start, start+size);
28576
28577@@ -920,6 +923,7 @@ void set_kernel_text_ro(void)
28578 if (!kernel_set_to_readonly)
28579 return;
28580
28581+ start = ktla_ktva(start);
28582 pr_debug("Set kernel text: %lx - %lx for read only\n",
28583 start, start+size);
28584
28585@@ -948,6 +952,7 @@ void mark_rodata_ro(void)
28586 unsigned long start = PFN_ALIGN(_text);
28587 unsigned long size = PFN_ALIGN(_etext) - start;
28588
28589+ start = ktla_ktva(start);
28590 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28591 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28592 size >> 10);
28593diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28594index bb00c46..f31d2f0 100644
28595--- a/arch/x86/mm/init_64.c
28596+++ b/arch/x86/mm/init_64.c
28597@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28598 * around without checking the pgd every time.
28599 */
28600
28601-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28602+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28603 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28604
28605 int force_personality32;
28606@@ -184,12 +184,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28607
28608 for (address = start; address <= end; address += PGDIR_SIZE) {
28609 const pgd_t *pgd_ref = pgd_offset_k(address);
28610+
28611+#ifdef CONFIG_PAX_PER_CPU_PGD
28612+ unsigned long cpu;
28613+#else
28614 struct page *page;
28615+#endif
28616
28617 if (pgd_none(*pgd_ref))
28618 continue;
28619
28620 spin_lock(&pgd_lock);
28621+
28622+#ifdef CONFIG_PAX_PER_CPU_PGD
28623+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28624+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28625+#else
28626 list_for_each_entry(page, &pgd_list, lru) {
28627 pgd_t *pgd;
28628 spinlock_t *pgt_lock;
28629@@ -198,6 +208,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28630 /* the pgt_lock only for Xen */
28631 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28632 spin_lock(pgt_lock);
28633+#endif
28634
28635 if (pgd_none(*pgd))
28636 set_pgd(pgd, *pgd_ref);
28637@@ -205,7 +216,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28638 BUG_ON(pgd_page_vaddr(*pgd)
28639 != pgd_page_vaddr(*pgd_ref));
28640
28641+#ifndef CONFIG_PAX_PER_CPU_PGD
28642 spin_unlock(pgt_lock);
28643+#endif
28644+
28645 }
28646 spin_unlock(&pgd_lock);
28647 }
28648@@ -238,7 +252,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28649 {
28650 if (pgd_none(*pgd)) {
28651 pud_t *pud = (pud_t *)spp_getpage();
28652- pgd_populate(&init_mm, pgd, pud);
28653+ pgd_populate_kernel(&init_mm, pgd, pud);
28654 if (pud != pud_offset(pgd, 0))
28655 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28656 pud, pud_offset(pgd, 0));
28657@@ -250,7 +264,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28658 {
28659 if (pud_none(*pud)) {
28660 pmd_t *pmd = (pmd_t *) spp_getpage();
28661- pud_populate(&init_mm, pud, pmd);
28662+ pud_populate_kernel(&init_mm, pud, pmd);
28663 if (pmd != pmd_offset(pud, 0))
28664 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28665 pmd, pmd_offset(pud, 0));
28666@@ -279,7 +293,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28667 pmd = fill_pmd(pud, vaddr);
28668 pte = fill_pte(pmd, vaddr);
28669
28670+ pax_open_kernel();
28671 set_pte(pte, new_pte);
28672+ pax_close_kernel();
28673
28674 /*
28675 * It's enough to flush this one mapping.
28676@@ -338,14 +354,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28677 pgd = pgd_offset_k((unsigned long)__va(phys));
28678 if (pgd_none(*pgd)) {
28679 pud = (pud_t *) spp_getpage();
28680- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28681- _PAGE_USER));
28682+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28683 }
28684 pud = pud_offset(pgd, (unsigned long)__va(phys));
28685 if (pud_none(*pud)) {
28686 pmd = (pmd_t *) spp_getpage();
28687- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28688- _PAGE_USER));
28689+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28690 }
28691 pmd = pmd_offset(pud, phys);
28692 BUG_ON(!pmd_none(*pmd));
28693@@ -586,7 +600,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28694 prot);
28695
28696 spin_lock(&init_mm.page_table_lock);
28697- pud_populate(&init_mm, pud, pmd);
28698+ pud_populate_kernel(&init_mm, pud, pmd);
28699 spin_unlock(&init_mm.page_table_lock);
28700 }
28701 __flush_tlb_all();
28702@@ -627,7 +641,7 @@ kernel_physical_mapping_init(unsigned long start,
28703 page_size_mask);
28704
28705 spin_lock(&init_mm.page_table_lock);
28706- pgd_populate(&init_mm, pgd, pud);
28707+ pgd_populate_kernel(&init_mm, pgd, pud);
28708 spin_unlock(&init_mm.page_table_lock);
28709 pgd_changed = true;
28710 }
28711@@ -1221,8 +1235,8 @@ int kern_addr_valid(unsigned long addr)
28712 static struct vm_area_struct gate_vma = {
28713 .vm_start = VSYSCALL_START,
28714 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28715- .vm_page_prot = PAGE_READONLY_EXEC,
28716- .vm_flags = VM_READ | VM_EXEC
28717+ .vm_page_prot = PAGE_READONLY,
28718+ .vm_flags = VM_READ
28719 };
28720
28721 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28722@@ -1256,7 +1270,7 @@ int in_gate_area_no_mm(unsigned long addr)
28723
28724 const char *arch_vma_name(struct vm_area_struct *vma)
28725 {
28726- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28727+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28728 return "[vdso]";
28729 if (vma == &gate_vma)
28730 return "[vsyscall]";
28731diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28732index 7b179b4..6bd17777 100644
28733--- a/arch/x86/mm/iomap_32.c
28734+++ b/arch/x86/mm/iomap_32.c
28735@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28736 type = kmap_atomic_idx_push();
28737 idx = type + KM_TYPE_NR * smp_processor_id();
28738 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28739+
28740+ pax_open_kernel();
28741 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28742+ pax_close_kernel();
28743+
28744 arch_flush_lazy_mmu_mode();
28745
28746 return (void *)vaddr;
28747diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28748index 9a1e658..da003f3 100644
28749--- a/arch/x86/mm/ioremap.c
28750+++ b/arch/x86/mm/ioremap.c
28751@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28752 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28753 int is_ram = page_is_ram(pfn);
28754
28755- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28756+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28757 return NULL;
28758 WARN_ON_ONCE(is_ram);
28759 }
28760@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28761 *
28762 * Caller must ensure there is only one unmapping for the same pointer.
28763 */
28764-void iounmap(volatile void __iomem *addr)
28765+void iounmap(const volatile void __iomem *addr)
28766 {
28767 struct vm_struct *p, *o;
28768
28769@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28770
28771 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28772 if (page_is_ram(start >> PAGE_SHIFT))
28773+#ifdef CONFIG_HIGHMEM
28774+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28775+#endif
28776 return __va(phys);
28777
28778 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28779@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28780 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
28781 {
28782 if (page_is_ram(phys >> PAGE_SHIFT))
28783+#ifdef CONFIG_HIGHMEM
28784+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
28785+#endif
28786 return;
28787
28788 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
28789@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
28790 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28791
28792 static __initdata int after_paging_init;
28793-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28794+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28795
28796 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28797 {
28798@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
28799 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28800
28801 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28802- memset(bm_pte, 0, sizeof(bm_pte));
28803- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28804+ pmd_populate_user(&init_mm, pmd, bm_pte);
28805
28806 /*
28807 * The boot-ioremap range spans multiple pmds, for which
28808diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28809index d87dd6d..bf3fa66 100644
28810--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28811+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28812@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28813 * memory (e.g. tracked pages)? For now, we need this to avoid
28814 * invoking kmemcheck for PnP BIOS calls.
28815 */
28816- if (regs->flags & X86_VM_MASK)
28817+ if (v8086_mode(regs))
28818 return false;
28819- if (regs->cs != __KERNEL_CS)
28820+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28821 return false;
28822
28823 pte = kmemcheck_pte_lookup(address);
28824diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28825index 845df68..1d8d29f 100644
28826--- a/arch/x86/mm/mmap.c
28827+++ b/arch/x86/mm/mmap.c
28828@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28829 * Leave an at least ~128 MB hole with possible stack randomization.
28830 */
28831 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28832-#define MAX_GAP (TASK_SIZE/6*5)
28833+#define MAX_GAP (pax_task_size/6*5)
28834
28835 static int mmap_is_legacy(void)
28836 {
28837@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28838 return rnd << PAGE_SHIFT;
28839 }
28840
28841-static unsigned long mmap_base(void)
28842+static unsigned long mmap_base(struct mm_struct *mm)
28843 {
28844 unsigned long gap = rlimit(RLIMIT_STACK);
28845+ unsigned long pax_task_size = TASK_SIZE;
28846+
28847+#ifdef CONFIG_PAX_SEGMEXEC
28848+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28849+ pax_task_size = SEGMEXEC_TASK_SIZE;
28850+#endif
28851
28852 if (gap < MIN_GAP)
28853 gap = MIN_GAP;
28854 else if (gap > MAX_GAP)
28855 gap = MAX_GAP;
28856
28857- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28858+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28859 }
28860
28861 /*
28862 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28863 * does, but not when emulating X86_32
28864 */
28865-static unsigned long mmap_legacy_base(void)
28866+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28867 {
28868- if (mmap_is_ia32())
28869+ if (mmap_is_ia32()) {
28870+
28871+#ifdef CONFIG_PAX_SEGMEXEC
28872+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28873+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28874+ else
28875+#endif
28876+
28877 return TASK_UNMAPPED_BASE;
28878- else
28879+ } else
28880 return TASK_UNMAPPED_BASE + mmap_rnd();
28881 }
28882
28883@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28884 void arch_pick_mmap_layout(struct mm_struct *mm)
28885 {
28886 if (mmap_is_legacy()) {
28887- mm->mmap_base = mmap_legacy_base();
28888+ mm->mmap_base = mmap_legacy_base(mm);
28889+
28890+#ifdef CONFIG_PAX_RANDMMAP
28891+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28892+ mm->mmap_base += mm->delta_mmap;
28893+#endif
28894+
28895 mm->get_unmapped_area = arch_get_unmapped_area;
28896 mm->unmap_area = arch_unmap_area;
28897 } else {
28898- mm->mmap_base = mmap_base();
28899+ mm->mmap_base = mmap_base(mm);
28900+
28901+#ifdef CONFIG_PAX_RANDMMAP
28902+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28903+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28904+#endif
28905+
28906 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28907 mm->unmap_area = arch_unmap_area_topdown;
28908 }
28909diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28910index dc0b727..f612039 100644
28911--- a/arch/x86/mm/mmio-mod.c
28912+++ b/arch/x86/mm/mmio-mod.c
28913@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28914 break;
28915 default:
28916 {
28917- unsigned char *ip = (unsigned char *)instptr;
28918+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28919 my_trace->opcode = MMIO_UNKNOWN_OP;
28920 my_trace->width = 0;
28921 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28922@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28923 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28924 void __iomem *addr)
28925 {
28926- static atomic_t next_id;
28927+ static atomic_unchecked_t next_id;
28928 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28929 /* These are page-unaligned. */
28930 struct mmiotrace_map map = {
28931@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28932 .private = trace
28933 },
28934 .phys = offset,
28935- .id = atomic_inc_return(&next_id)
28936+ .id = atomic_inc_return_unchecked(&next_id)
28937 };
28938 map.map_id = trace->id;
28939
28940@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28941 ioremap_trace_core(offset, size, addr);
28942 }
28943
28944-static void iounmap_trace_core(volatile void __iomem *addr)
28945+static void iounmap_trace_core(const volatile void __iomem *addr)
28946 {
28947 struct mmiotrace_map map = {
28948 .phys = 0,
28949@@ -328,7 +328,7 @@ not_enabled:
28950 }
28951 }
28952
28953-void mmiotrace_iounmap(volatile void __iomem *addr)
28954+void mmiotrace_iounmap(const volatile void __iomem *addr)
28955 {
28956 might_sleep();
28957 if (is_enabled()) /* recheck and proper locking in *_core() */
28958diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28959index a71c4e2..301ae44 100644
28960--- a/arch/x86/mm/numa.c
28961+++ b/arch/x86/mm/numa.c
28962@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28963 return true;
28964 }
28965
28966-static int __init numa_register_memblks(struct numa_meminfo *mi)
28967+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28968 {
28969 unsigned long uninitialized_var(pfn_align);
28970 int i, nid;
28971diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28972index d0b1773..4c3327c 100644
28973--- a/arch/x86/mm/pageattr-test.c
28974+++ b/arch/x86/mm/pageattr-test.c
28975@@ -36,7 +36,7 @@ enum {
28976
28977 static int pte_testbit(pte_t pte)
28978 {
28979- return pte_flags(pte) & _PAGE_UNUSED1;
28980+ return pte_flags(pte) & _PAGE_CPA_TEST;
28981 }
28982
28983 struct split_state {
28984diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28985index bb32480..aef8278 100644
28986--- a/arch/x86/mm/pageattr.c
28987+++ b/arch/x86/mm/pageattr.c
28988@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28989 */
28990 #ifdef CONFIG_PCI_BIOS
28991 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28992- pgprot_val(forbidden) |= _PAGE_NX;
28993+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28994 #endif
28995
28996 /*
28997@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28998 * Does not cover __inittext since that is gone later on. On
28999 * 64bit we do not enforce !NX on the low mapping
29000 */
29001- if (within(address, (unsigned long)_text, (unsigned long)_etext))
29002- pgprot_val(forbidden) |= _PAGE_NX;
29003+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
29004+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29005
29006+#ifdef CONFIG_DEBUG_RODATA
29007 /*
29008 * The .rodata section needs to be read-only. Using the pfn
29009 * catches all aliases.
29010@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29011 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
29012 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
29013 pgprot_val(forbidden) |= _PAGE_RW;
29014+#endif
29015
29016 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
29017 /*
29018@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
29019 }
29020 #endif
29021
29022+#ifdef CONFIG_PAX_KERNEXEC
29023+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
29024+ pgprot_val(forbidden) |= _PAGE_RW;
29025+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
29026+ }
29027+#endif
29028+
29029 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
29030
29031 return prot;
29032@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
29033 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
29034 {
29035 /* change init_mm */
29036+ pax_open_kernel();
29037 set_pte_atomic(kpte, pte);
29038+
29039 #ifdef CONFIG_X86_32
29040 if (!SHARED_KERNEL_PMD) {
29041+
29042+#ifdef CONFIG_PAX_PER_CPU_PGD
29043+ unsigned long cpu;
29044+#else
29045 struct page *page;
29046+#endif
29047
29048+#ifdef CONFIG_PAX_PER_CPU_PGD
29049+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29050+ pgd_t *pgd = get_cpu_pgd(cpu);
29051+#else
29052 list_for_each_entry(page, &pgd_list, lru) {
29053- pgd_t *pgd;
29054+ pgd_t *pgd = (pgd_t *)page_address(page);
29055+#endif
29056+
29057 pud_t *pud;
29058 pmd_t *pmd;
29059
29060- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29061+ pgd += pgd_index(address);
29062 pud = pud_offset(pgd, address);
29063 pmd = pmd_offset(pud, address);
29064 set_pte_atomic((pte_t *)pmd, pte);
29065 }
29066 }
29067 #endif
29068+ pax_close_kernel();
29069 }
29070
29071 static int
29072diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29073index 6574388..87e9bef 100644
29074--- a/arch/x86/mm/pat.c
29075+++ b/arch/x86/mm/pat.c
29076@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29077
29078 if (!entry) {
29079 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29080- current->comm, current->pid, start, end - 1);
29081+ current->comm, task_pid_nr(current), start, end - 1);
29082 return -EINVAL;
29083 }
29084
29085@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29086
29087 while (cursor < to) {
29088 if (!devmem_is_allowed(pfn)) {
29089- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29090- current->comm, from, to - 1);
29091+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29092+ current->comm, from, to - 1, cursor);
29093 return 0;
29094 }
29095 cursor += PAGE_SIZE;
29096@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29097 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29098 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29099 "for [mem %#010Lx-%#010Lx]\n",
29100- current->comm, current->pid,
29101+ current->comm, task_pid_nr(current),
29102 cattr_name(flags),
29103 base, (unsigned long long)(base + size-1));
29104 return -EINVAL;
29105@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29106 flags = lookup_memtype(paddr);
29107 if (want_flags != flags) {
29108 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29109- current->comm, current->pid,
29110+ current->comm, task_pid_nr(current),
29111 cattr_name(want_flags),
29112 (unsigned long long)paddr,
29113 (unsigned long long)(paddr + size - 1),
29114@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29115 free_memtype(paddr, paddr + size);
29116 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29117 " for [mem %#010Lx-%#010Lx], got %s\n",
29118- current->comm, current->pid,
29119+ current->comm, task_pid_nr(current),
29120 cattr_name(want_flags),
29121 (unsigned long long)paddr,
29122 (unsigned long long)(paddr + size - 1),
29123diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
29124index 415f6c4..d319983 100644
29125--- a/arch/x86/mm/pat_rbtree.c
29126+++ b/arch/x86/mm/pat_rbtree.c
29127@@ -160,7 +160,7 @@ success:
29128
29129 failure:
29130 printk(KERN_INFO "%s:%d conflicting memory types "
29131- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
29132+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
29133 end, cattr_name(found_type), cattr_name(match->type));
29134 return -EBUSY;
29135 }
29136diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29137index 9f0614d..92ae64a 100644
29138--- a/arch/x86/mm/pf_in.c
29139+++ b/arch/x86/mm/pf_in.c
29140@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29141 int i;
29142 enum reason_type rv = OTHERS;
29143
29144- p = (unsigned char *)ins_addr;
29145+ p = (unsigned char *)ktla_ktva(ins_addr);
29146 p += skip_prefix(p, &prf);
29147 p += get_opcode(p, &opcode);
29148
29149@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29150 struct prefix_bits prf;
29151 int i;
29152
29153- p = (unsigned char *)ins_addr;
29154+ p = (unsigned char *)ktla_ktva(ins_addr);
29155 p += skip_prefix(p, &prf);
29156 p += get_opcode(p, &opcode);
29157
29158@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29159 struct prefix_bits prf;
29160 int i;
29161
29162- p = (unsigned char *)ins_addr;
29163+ p = (unsigned char *)ktla_ktva(ins_addr);
29164 p += skip_prefix(p, &prf);
29165 p += get_opcode(p, &opcode);
29166
29167@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29168 struct prefix_bits prf;
29169 int i;
29170
29171- p = (unsigned char *)ins_addr;
29172+ p = (unsigned char *)ktla_ktva(ins_addr);
29173 p += skip_prefix(p, &prf);
29174 p += get_opcode(p, &opcode);
29175 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29176@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29177 struct prefix_bits prf;
29178 int i;
29179
29180- p = (unsigned char *)ins_addr;
29181+ p = (unsigned char *)ktla_ktva(ins_addr);
29182 p += skip_prefix(p, &prf);
29183 p += get_opcode(p, &opcode);
29184 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29185diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29186index 17fda6a..489c74a 100644
29187--- a/arch/x86/mm/pgtable.c
29188+++ b/arch/x86/mm/pgtable.c
29189@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29190 list_del(&page->lru);
29191 }
29192
29193-#define UNSHARED_PTRS_PER_PGD \
29194- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29195+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29196+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29197
29198+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29199+{
29200+ unsigned int count = USER_PGD_PTRS;
29201
29202+ while (count--)
29203+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29204+}
29205+#endif
29206+
29207+#ifdef CONFIG_PAX_PER_CPU_PGD
29208+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29209+{
29210+ unsigned int count = USER_PGD_PTRS;
29211+
29212+ while (count--) {
29213+ pgd_t pgd;
29214+
29215+#ifdef CONFIG_X86_64
29216+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29217+#else
29218+ pgd = *src++;
29219+#endif
29220+
29221+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29222+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29223+#endif
29224+
29225+ *dst++ = pgd;
29226+ }
29227+
29228+}
29229+#endif
29230+
29231+#ifdef CONFIG_X86_64
29232+#define pxd_t pud_t
29233+#define pyd_t pgd_t
29234+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29235+#define pxd_free(mm, pud) pud_free((mm), (pud))
29236+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29237+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29238+#define PYD_SIZE PGDIR_SIZE
29239+#else
29240+#define pxd_t pmd_t
29241+#define pyd_t pud_t
29242+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29243+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29244+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29245+#define pyd_offset(mm, address) pud_offset((mm), (address))
29246+#define PYD_SIZE PUD_SIZE
29247+#endif
29248+
29249+#ifdef CONFIG_PAX_PER_CPU_PGD
29250+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29251+static inline void pgd_dtor(pgd_t *pgd) {}
29252+#else
29253 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29254 {
29255 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29256@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29257 pgd_list_del(pgd);
29258 spin_unlock(&pgd_lock);
29259 }
29260+#endif
29261
29262 /*
29263 * List of all pgd's needed for non-PAE so it can invalidate entries
29264@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29265 * -- nyc
29266 */
29267
29268-#ifdef CONFIG_X86_PAE
29269+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29270 /*
29271 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29272 * updating the top-level pagetable entries to guarantee the
29273@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29274 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29275 * and initialize the kernel pmds here.
29276 */
29277-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29278+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29279
29280 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29281 {
29282@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29283 */
29284 flush_tlb_mm(mm);
29285 }
29286+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29287+#define PREALLOCATED_PXDS USER_PGD_PTRS
29288 #else /* !CONFIG_X86_PAE */
29289
29290 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29291-#define PREALLOCATED_PMDS 0
29292+#define PREALLOCATED_PXDS 0
29293
29294 #endif /* CONFIG_X86_PAE */
29295
29296-static void free_pmds(pmd_t *pmds[])
29297+static void free_pxds(pxd_t *pxds[])
29298 {
29299 int i;
29300
29301- for(i = 0; i < PREALLOCATED_PMDS; i++)
29302- if (pmds[i])
29303- free_page((unsigned long)pmds[i]);
29304+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29305+ if (pxds[i])
29306+ free_page((unsigned long)pxds[i]);
29307 }
29308
29309-static int preallocate_pmds(pmd_t *pmds[])
29310+static int preallocate_pxds(pxd_t *pxds[])
29311 {
29312 int i;
29313 bool failed = false;
29314
29315- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29316- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29317- if (pmd == NULL)
29318+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29319+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29320+ if (pxd == NULL)
29321 failed = true;
29322- pmds[i] = pmd;
29323+ pxds[i] = pxd;
29324 }
29325
29326 if (failed) {
29327- free_pmds(pmds);
29328+ free_pxds(pxds);
29329 return -ENOMEM;
29330 }
29331
29332@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29333 * preallocate which never got a corresponding vma will need to be
29334 * freed manually.
29335 */
29336-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29337+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29338 {
29339 int i;
29340
29341- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29342+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29343 pgd_t pgd = pgdp[i];
29344
29345 if (pgd_val(pgd) != 0) {
29346- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29347+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29348
29349- pgdp[i] = native_make_pgd(0);
29350+ set_pgd(pgdp + i, native_make_pgd(0));
29351
29352- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29353- pmd_free(mm, pmd);
29354+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29355+ pxd_free(mm, pxd);
29356 }
29357 }
29358 }
29359
29360-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29361+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29362 {
29363- pud_t *pud;
29364+ pyd_t *pyd;
29365 unsigned long addr;
29366 int i;
29367
29368- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29369+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29370 return;
29371
29372- pud = pud_offset(pgd, 0);
29373+#ifdef CONFIG_X86_64
29374+ pyd = pyd_offset(mm, 0L);
29375+#else
29376+ pyd = pyd_offset(pgd, 0L);
29377+#endif
29378
29379- for (addr = i = 0; i < PREALLOCATED_PMDS;
29380- i++, pud++, addr += PUD_SIZE) {
29381- pmd_t *pmd = pmds[i];
29382+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29383+ i++, pyd++, addr += PYD_SIZE) {
29384+ pxd_t *pxd = pxds[i];
29385
29386 if (i >= KERNEL_PGD_BOUNDARY)
29387- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29388- sizeof(pmd_t) * PTRS_PER_PMD);
29389+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29390+ sizeof(pxd_t) * PTRS_PER_PMD);
29391
29392- pud_populate(mm, pud, pmd);
29393+ pyd_populate(mm, pyd, pxd);
29394 }
29395 }
29396
29397 pgd_t *pgd_alloc(struct mm_struct *mm)
29398 {
29399 pgd_t *pgd;
29400- pmd_t *pmds[PREALLOCATED_PMDS];
29401+ pxd_t *pxds[PREALLOCATED_PXDS];
29402
29403 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29404
29405@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29406
29407 mm->pgd = pgd;
29408
29409- if (preallocate_pmds(pmds) != 0)
29410+ if (preallocate_pxds(pxds) != 0)
29411 goto out_free_pgd;
29412
29413 if (paravirt_pgd_alloc(mm) != 0)
29414- goto out_free_pmds;
29415+ goto out_free_pxds;
29416
29417 /*
29418 * Make sure that pre-populating the pmds is atomic with
29419@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29420 spin_lock(&pgd_lock);
29421
29422 pgd_ctor(mm, pgd);
29423- pgd_prepopulate_pmd(mm, pgd, pmds);
29424+ pgd_prepopulate_pxd(mm, pgd, pxds);
29425
29426 spin_unlock(&pgd_lock);
29427
29428 return pgd;
29429
29430-out_free_pmds:
29431- free_pmds(pmds);
29432+out_free_pxds:
29433+ free_pxds(pxds);
29434 out_free_pgd:
29435 free_page((unsigned long)pgd);
29436 out:
29437@@ -302,7 +363,7 @@ out:
29438
29439 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29440 {
29441- pgd_mop_up_pmds(mm, pgd);
29442+ pgd_mop_up_pxds(mm, pgd);
29443 pgd_dtor(pgd);
29444 paravirt_pgd_free(mm, pgd);
29445 free_page((unsigned long)pgd);
29446diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29447index a69bcb8..19068ab 100644
29448--- a/arch/x86/mm/pgtable_32.c
29449+++ b/arch/x86/mm/pgtable_32.c
29450@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29451 return;
29452 }
29453 pte = pte_offset_kernel(pmd, vaddr);
29454+
29455+ pax_open_kernel();
29456 if (pte_val(pteval))
29457 set_pte_at(&init_mm, vaddr, pte, pteval);
29458 else
29459 pte_clear(&init_mm, vaddr, pte);
29460+ pax_close_kernel();
29461
29462 /*
29463 * It's enough to flush this one mapping.
29464diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29465index e666cbb..61788c45 100644
29466--- a/arch/x86/mm/physaddr.c
29467+++ b/arch/x86/mm/physaddr.c
29468@@ -10,7 +10,7 @@
29469 #ifdef CONFIG_X86_64
29470
29471 #ifdef CONFIG_DEBUG_VIRTUAL
29472-unsigned long __phys_addr(unsigned long x)
29473+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29474 {
29475 unsigned long y = x - __START_KERNEL_map;
29476
29477@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29478 #else
29479
29480 #ifdef CONFIG_DEBUG_VIRTUAL
29481-unsigned long __phys_addr(unsigned long x)
29482+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29483 {
29484 unsigned long phys_addr = x - PAGE_OFFSET;
29485 /* VMALLOC_* aren't constants */
29486diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29487index 410531d..0f16030 100644
29488--- a/arch/x86/mm/setup_nx.c
29489+++ b/arch/x86/mm/setup_nx.c
29490@@ -5,8 +5,10 @@
29491 #include <asm/pgtable.h>
29492 #include <asm/proto.h>
29493
29494+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29495 static int disable_nx __cpuinitdata;
29496
29497+#ifndef CONFIG_PAX_PAGEEXEC
29498 /*
29499 * noexec = on|off
29500 *
29501@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29502 return 0;
29503 }
29504 early_param("noexec", noexec_setup);
29505+#endif
29506+
29507+#endif
29508
29509 void __cpuinit x86_configure_nx(void)
29510 {
29511+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29512 if (cpu_has_nx && !disable_nx)
29513 __supported_pte_mask |= _PAGE_NX;
29514 else
29515+#endif
29516 __supported_pte_mask &= ~_PAGE_NX;
29517 }
29518
29519diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29520index 282375f..e03a98f 100644
29521--- a/arch/x86/mm/tlb.c
29522+++ b/arch/x86/mm/tlb.c
29523@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29524 BUG();
29525 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29526 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29527+
29528+#ifndef CONFIG_PAX_PER_CPU_PGD
29529 load_cr3(swapper_pg_dir);
29530+#endif
29531+
29532 }
29533 }
29534 EXPORT_SYMBOL_GPL(leave_mm);
29535diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29536index 877b9a1..a8ecf42 100644
29537--- a/arch/x86/net/bpf_jit.S
29538+++ b/arch/x86/net/bpf_jit.S
29539@@ -9,6 +9,7 @@
29540 */
29541 #include <linux/linkage.h>
29542 #include <asm/dwarf2.h>
29543+#include <asm/alternative-asm.h>
29544
29545 /*
29546 * Calling convention :
29547@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29548 jle bpf_slow_path_word
29549 mov (SKBDATA,%rsi),%eax
29550 bswap %eax /* ntohl() */
29551+ pax_force_retaddr
29552 ret
29553
29554 sk_load_half:
29555@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29556 jle bpf_slow_path_half
29557 movzwl (SKBDATA,%rsi),%eax
29558 rol $8,%ax # ntohs()
29559+ pax_force_retaddr
29560 ret
29561
29562 sk_load_byte:
29563@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29564 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29565 jle bpf_slow_path_byte
29566 movzbl (SKBDATA,%rsi),%eax
29567+ pax_force_retaddr
29568 ret
29569
29570 /**
29571@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29572 movzbl (SKBDATA,%rsi),%ebx
29573 and $15,%bl
29574 shl $2,%bl
29575+ pax_force_retaddr
29576 ret
29577
29578 /* rsi contains offset and can be scratched */
29579@@ -109,6 +114,7 @@ bpf_slow_path_word:
29580 js bpf_error
29581 mov -12(%rbp),%eax
29582 bswap %eax
29583+ pax_force_retaddr
29584 ret
29585
29586 bpf_slow_path_half:
29587@@ -117,12 +123,14 @@ bpf_slow_path_half:
29588 mov -12(%rbp),%ax
29589 rol $8,%ax
29590 movzwl %ax,%eax
29591+ pax_force_retaddr
29592 ret
29593
29594 bpf_slow_path_byte:
29595 bpf_slow_path_common(1)
29596 js bpf_error
29597 movzbl -12(%rbp),%eax
29598+ pax_force_retaddr
29599 ret
29600
29601 bpf_slow_path_byte_msh:
29602@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29603 and $15,%al
29604 shl $2,%al
29605 xchg %eax,%ebx
29606+ pax_force_retaddr
29607 ret
29608
29609 #define sk_negative_common(SIZE) \
29610@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29611 sk_negative_common(4)
29612 mov (%rax), %eax
29613 bswap %eax
29614+ pax_force_retaddr
29615 ret
29616
29617 bpf_slow_path_half_neg:
29618@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29619 mov (%rax),%ax
29620 rol $8,%ax
29621 movzwl %ax,%eax
29622+ pax_force_retaddr
29623 ret
29624
29625 bpf_slow_path_byte_neg:
29626@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29627 .globl sk_load_byte_negative_offset
29628 sk_negative_common(1)
29629 movzbl (%rax), %eax
29630+ pax_force_retaddr
29631 ret
29632
29633 bpf_slow_path_byte_msh_neg:
29634@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29635 and $15,%al
29636 shl $2,%al
29637 xchg %eax,%ebx
29638+ pax_force_retaddr
29639 ret
29640
29641 bpf_error:
29642@@ -197,4 +210,5 @@ bpf_error:
29643 xor %eax,%eax
29644 mov -8(%rbp),%rbx
29645 leaveq
29646+ pax_force_retaddr
29647 ret
29648diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29649index f66b540..3e88dfb 100644
29650--- a/arch/x86/net/bpf_jit_comp.c
29651+++ b/arch/x86/net/bpf_jit_comp.c
29652@@ -12,6 +12,7 @@
29653 #include <linux/netdevice.h>
29654 #include <linux/filter.h>
29655 #include <linux/if_vlan.h>
29656+#include <linux/random.h>
29657
29658 /*
29659 * Conventions :
29660@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29661 return ptr + len;
29662 }
29663
29664+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29665+#define MAX_INSTR_CODE_SIZE 96
29666+#else
29667+#define MAX_INSTR_CODE_SIZE 64
29668+#endif
29669+
29670 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29671
29672 #define EMIT1(b1) EMIT(b1, 1)
29673 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29674 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29675 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29676+
29677+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29678+/* original constant will appear in ecx */
29679+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29680+do { \
29681+ /* mov ecx, randkey */ \
29682+ EMIT1(0xb9); \
29683+ EMIT(_key, 4); \
29684+ /* xor ecx, randkey ^ off */ \
29685+ EMIT2(0x81, 0xf1); \
29686+ EMIT((_key) ^ (_off), 4); \
29687+} while (0)
29688+
29689+#define EMIT1_off32(b1, _off) \
29690+do { \
29691+ switch (b1) { \
29692+ case 0x05: /* add eax, imm32 */ \
29693+ case 0x2d: /* sub eax, imm32 */ \
29694+ case 0x25: /* and eax, imm32 */ \
29695+ case 0x0d: /* or eax, imm32 */ \
29696+ case 0xb8: /* mov eax, imm32 */ \
29697+ case 0x35: /* xor eax, imm32 */ \
29698+ case 0x3d: /* cmp eax, imm32 */ \
29699+ case 0xa9: /* test eax, imm32 */ \
29700+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29701+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29702+ break; \
29703+ case 0xbb: /* mov ebx, imm32 */ \
29704+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29705+ /* mov ebx, ecx */ \
29706+ EMIT2(0x89, 0xcb); \
29707+ break; \
29708+ case 0xbe: /* mov esi, imm32 */ \
29709+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29710+ /* mov esi, ecx */ \
29711+ EMIT2(0x89, 0xce); \
29712+ break; \
29713+ case 0xe8: /* call rel imm32, always to known funcs */ \
29714+ EMIT1(b1); \
29715+ EMIT(_off, 4); \
29716+ break; \
29717+ case 0xe9: /* jmp rel imm32 */ \
29718+ EMIT1(b1); \
29719+ EMIT(_off, 4); \
29720+ /* prevent fall-through, we're not called if off = 0 */ \
29721+ EMIT(0xcccccccc, 4); \
29722+ EMIT(0xcccccccc, 4); \
29723+ break; \
29724+ default: \
29725+ BUILD_BUG(); \
29726+ } \
29727+} while (0)
29728+
29729+#define EMIT2_off32(b1, b2, _off) \
29730+do { \
29731+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29732+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29733+ EMIT(randkey, 4); \
29734+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29735+ EMIT((_off) - randkey, 4); \
29736+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29737+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29738+ /* imul eax, ecx */ \
29739+ EMIT3(0x0f, 0xaf, 0xc1); \
29740+ } else { \
29741+ BUILD_BUG(); \
29742+ } \
29743+} while (0)
29744+#else
29745 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29746+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29747+#endif
29748
29749 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29750 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29751@@ -90,6 +168,24 @@ do { \
29752 #define X86_JBE 0x76
29753 #define X86_JA 0x77
29754
29755+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29756+#define APPEND_FLOW_VERIFY() \
29757+do { \
29758+ /* mov ecx, randkey */ \
29759+ EMIT1(0xb9); \
29760+ EMIT(randkey, 4); \
29761+ /* cmp ecx, randkey */ \
29762+ EMIT2(0x81, 0xf9); \
29763+ EMIT(randkey, 4); \
29764+ /* jz after 8 int 3s */ \
29765+ EMIT2(0x74, 0x08); \
29766+ EMIT(0xcccccccc, 4); \
29767+ EMIT(0xcccccccc, 4); \
29768+} while (0)
29769+#else
29770+#define APPEND_FLOW_VERIFY() do { } while (0)
29771+#endif
29772+
29773 #define EMIT_COND_JMP(op, offset) \
29774 do { \
29775 if (is_near(offset)) \
29776@@ -97,6 +193,7 @@ do { \
29777 else { \
29778 EMIT2(0x0f, op + 0x10); \
29779 EMIT(offset, 4); /* jxx .+off32 */ \
29780+ APPEND_FLOW_VERIFY(); \
29781 } \
29782 } while (0)
29783
29784@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
29785 set_fs(old_fs);
29786 }
29787
29788+struct bpf_jit_work {
29789+ struct work_struct work;
29790+ void *image;
29791+};
29792+
29793 #define CHOOSE_LOAD_FUNC(K, func) \
29794 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29795
29796@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
29797
29798 void bpf_jit_compile(struct sk_filter *fp)
29799 {
29800- u8 temp[64];
29801+ u8 temp[MAX_INSTR_CODE_SIZE];
29802 u8 *prog;
29803 unsigned int proglen, oldproglen = 0;
29804 int ilen, i;
29805@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29806 unsigned int *addrs;
29807 const struct sock_filter *filter = fp->insns;
29808 int flen = fp->len;
29809+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29810+ unsigned int randkey;
29811+#endif
29812
29813 if (!bpf_jit_enable)
29814 return;
29815@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29816 if (addrs == NULL)
29817 return;
29818
29819+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29820+ if (!fp->work)
29821+ goto out;
29822+
29823+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29824+ randkey = get_random_int();
29825+#endif
29826+
29827 /* Before first pass, make a rough estimation of addrs[]
29828- * each bpf instruction is translated to less than 64 bytes
29829+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29830 */
29831 for (proglen = 0, i = 0; i < flen; i++) {
29832- proglen += 64;
29833+ proglen += MAX_INSTR_CODE_SIZE;
29834 addrs[i] = proglen;
29835 }
29836 cleanup_addr = proglen; /* epilogue address */
29837@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29838 case BPF_S_ALU_MUL_K: /* A *= K */
29839 if (is_imm8(K))
29840 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29841- else {
29842- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29843- EMIT(K, 4);
29844- }
29845+ else
29846+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29847 break;
29848 case BPF_S_ALU_DIV_X: /* A /= X; */
29849 seen |= SEEN_XREG;
29850@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29851 break;
29852 case BPF_S_ALU_MOD_K: /* A %= K; */
29853 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29854+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29855+ DILUTE_CONST_SEQUENCE(K, randkey);
29856+#else
29857 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29858+#endif
29859 EMIT2(0xf7, 0xf1); /* div %ecx */
29860 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29861 break;
29862 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29863+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29864+ DILUTE_CONST_SEQUENCE(K, randkey);
29865+ // imul rax, rcx
29866+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29867+#else
29868 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29869 EMIT(K, 4);
29870+#endif
29871 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29872 break;
29873 case BPF_S_ALU_AND_X:
29874@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29875 if (is_imm8(K)) {
29876 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29877 } else {
29878- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29879- EMIT(K, 4);
29880+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29881 }
29882 } else {
29883 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29884@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29885 break;
29886 default:
29887 /* hmm, too complex filter, give up with jit compiler */
29888- goto out;
29889+ goto error;
29890 }
29891 ilen = prog - temp;
29892 if (image) {
29893 if (unlikely(proglen + ilen > oldproglen)) {
29894 pr_err("bpb_jit_compile fatal error\n");
29895- kfree(addrs);
29896- module_free(NULL, image);
29897- return;
29898+ module_free_exec(NULL, image);
29899+ goto error;
29900 }
29901+ pax_open_kernel();
29902 memcpy(image + proglen, temp, ilen);
29903+ pax_close_kernel();
29904 }
29905 proglen += ilen;
29906 addrs[i] = proglen;
29907@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29908 break;
29909 }
29910 if (proglen == oldproglen) {
29911- image = module_alloc(max_t(unsigned int,
29912- proglen,
29913- sizeof(struct work_struct)));
29914+ image = module_alloc_exec(proglen);
29915 if (!image)
29916- goto out;
29917+ goto error;
29918 }
29919 oldproglen = proglen;
29920 }
29921@@ -732,7 +851,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29922 if (image) {
29923 bpf_flush_icache(image, image + proglen);
29924 fp->bpf_func = (void *)image;
29925- }
29926+ } else
29927+error:
29928+ kfree(fp->work);
29929+
29930 out:
29931 kfree(addrs);
29932 return;
29933@@ -740,18 +862,20 @@ out:
29934
29935 static void jit_free_defer(struct work_struct *arg)
29936 {
29937- module_free(NULL, arg);
29938+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29939+ kfree(arg);
29940 }
29941
29942 /* run from softirq, we must use a work_struct to call
29943- * module_free() from process context
29944+ * module_free_exec() from process context
29945 */
29946 void bpf_jit_free(struct sk_filter *fp)
29947 {
29948 if (fp->bpf_func != sk_run_filter) {
29949- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29950+ struct work_struct *work = &fp->work->work;
29951
29952 INIT_WORK(work, jit_free_defer);
29953+ fp->work->image = fp->bpf_func;
29954 schedule_work(work);
29955 }
29956 }
29957diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29958index d6aa6e8..266395a 100644
29959--- a/arch/x86/oprofile/backtrace.c
29960+++ b/arch/x86/oprofile/backtrace.c
29961@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29962 struct stack_frame_ia32 *fp;
29963 unsigned long bytes;
29964
29965- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29966+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29967 if (bytes != sizeof(bufhead))
29968 return NULL;
29969
29970- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29971+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29972
29973 oprofile_add_trace(bufhead[0].return_address);
29974
29975@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29976 struct stack_frame bufhead[2];
29977 unsigned long bytes;
29978
29979- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29980+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29981 if (bytes != sizeof(bufhead))
29982 return NULL;
29983
29984@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29985 {
29986 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29987
29988- if (!user_mode_vm(regs)) {
29989+ if (!user_mode(regs)) {
29990 unsigned long stack = kernel_stack_pointer(regs);
29991 if (depth)
29992 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29993diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29994index 48768df..ba9143c 100644
29995--- a/arch/x86/oprofile/nmi_int.c
29996+++ b/arch/x86/oprofile/nmi_int.c
29997@@ -23,6 +23,7 @@
29998 #include <asm/nmi.h>
29999 #include <asm/msr.h>
30000 #include <asm/apic.h>
30001+#include <asm/pgtable.h>
30002
30003 #include "op_counter.h"
30004 #include "op_x86_model.h"
30005@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
30006 if (ret)
30007 return ret;
30008
30009- if (!model->num_virt_counters)
30010- model->num_virt_counters = model->num_counters;
30011+ if (!model->num_virt_counters) {
30012+ pax_open_kernel();
30013+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
30014+ pax_close_kernel();
30015+ }
30016
30017 mux_init(ops);
30018
30019diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
30020index b2b9443..be58856 100644
30021--- a/arch/x86/oprofile/op_model_amd.c
30022+++ b/arch/x86/oprofile/op_model_amd.c
30023@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
30024 num_counters = AMD64_NUM_COUNTERS;
30025 }
30026
30027- op_amd_spec.num_counters = num_counters;
30028- op_amd_spec.num_controls = num_counters;
30029- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30030+ pax_open_kernel();
30031+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
30032+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
30033+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
30034+ pax_close_kernel();
30035
30036 return 0;
30037 }
30038diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
30039index d90528e..0127e2b 100644
30040--- a/arch/x86/oprofile/op_model_ppro.c
30041+++ b/arch/x86/oprofile/op_model_ppro.c
30042@@ -19,6 +19,7 @@
30043 #include <asm/msr.h>
30044 #include <asm/apic.h>
30045 #include <asm/nmi.h>
30046+#include <asm/pgtable.h>
30047
30048 #include "op_x86_model.h"
30049 #include "op_counter.h"
30050@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30051
30052 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30053
30054- op_arch_perfmon_spec.num_counters = num_counters;
30055- op_arch_perfmon_spec.num_controls = num_counters;
30056+ pax_open_kernel();
30057+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30058+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30059+ pax_close_kernel();
30060 }
30061
30062 static int arch_perfmon_init(struct oprofile_operations *ignore)
30063diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30064index 71e8a67..6a313bb 100644
30065--- a/arch/x86/oprofile/op_x86_model.h
30066+++ b/arch/x86/oprofile/op_x86_model.h
30067@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30068 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30069 struct op_msrs const * const msrs);
30070 #endif
30071-};
30072+} __do_const;
30073
30074 struct op_counter_config;
30075
30076diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30077index e9e6ed5..e47ae67 100644
30078--- a/arch/x86/pci/amd_bus.c
30079+++ b/arch/x86/pci/amd_bus.c
30080@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30081 return NOTIFY_OK;
30082 }
30083
30084-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30085+static struct notifier_block amd_cpu_notifier = {
30086 .notifier_call = amd_cpu_notify,
30087 };
30088
30089diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30090index 372e9b8..e775a6c 100644
30091--- a/arch/x86/pci/irq.c
30092+++ b/arch/x86/pci/irq.c
30093@@ -50,7 +50,7 @@ struct irq_router {
30094 struct irq_router_handler {
30095 u16 vendor;
30096 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30097-};
30098+} __do_const;
30099
30100 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30101 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30102@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30103 return 0;
30104 }
30105
30106-static __initdata struct irq_router_handler pirq_routers[] = {
30107+static __initconst const struct irq_router_handler pirq_routers[] = {
30108 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30109 { PCI_VENDOR_ID_AL, ali_router_probe },
30110 { PCI_VENDOR_ID_ITE, ite_router_probe },
30111@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30112 static void __init pirq_find_router(struct irq_router *r)
30113 {
30114 struct irq_routing_table *rt = pirq_table;
30115- struct irq_router_handler *h;
30116+ const struct irq_router_handler *h;
30117
30118 #ifdef CONFIG_PCI_BIOS
30119 if (!rt->signature) {
30120@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30121 return 0;
30122 }
30123
30124-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30125+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30126 {
30127 .callback = fix_broken_hp_bios_irq9,
30128 .ident = "HP Pavilion N5400 Series Laptop",
30129diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30130index 6eb18c4..20d83de 100644
30131--- a/arch/x86/pci/mrst.c
30132+++ b/arch/x86/pci/mrst.c
30133@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30134 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30135 pci_mmcfg_late_init();
30136 pcibios_enable_irq = mrst_pci_irq_enable;
30137- pci_root_ops = pci_mrst_ops;
30138+ pax_open_kernel();
30139+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30140+ pax_close_kernel();
30141 pci_soc_mode = 1;
30142 /* Continue with standard init */
30143 return 1;
30144diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30145index c77b24a..c979855 100644
30146--- a/arch/x86/pci/pcbios.c
30147+++ b/arch/x86/pci/pcbios.c
30148@@ -79,7 +79,7 @@ union bios32 {
30149 static struct {
30150 unsigned long address;
30151 unsigned short segment;
30152-} bios32_indirect = { 0, __KERNEL_CS };
30153+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30154
30155 /*
30156 * Returns the entry point for the given service, NULL on error
30157@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30158 unsigned long length; /* %ecx */
30159 unsigned long entry; /* %edx */
30160 unsigned long flags;
30161+ struct desc_struct d, *gdt;
30162
30163 local_irq_save(flags);
30164- __asm__("lcall *(%%edi); cld"
30165+
30166+ gdt = get_cpu_gdt_table(smp_processor_id());
30167+
30168+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30169+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30170+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30171+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30172+
30173+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30174 : "=a" (return_code),
30175 "=b" (address),
30176 "=c" (length),
30177 "=d" (entry)
30178 : "0" (service),
30179 "1" (0),
30180- "D" (&bios32_indirect));
30181+ "D" (&bios32_indirect),
30182+ "r"(__PCIBIOS_DS)
30183+ : "memory");
30184+
30185+ pax_open_kernel();
30186+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30187+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30188+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30189+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30190+ pax_close_kernel();
30191+
30192 local_irq_restore(flags);
30193
30194 switch (return_code) {
30195- case 0:
30196- return address + entry;
30197- case 0x80: /* Not present */
30198- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30199- return 0;
30200- default: /* Shouldn't happen */
30201- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30202- service, return_code);
30203+ case 0: {
30204+ int cpu;
30205+ unsigned char flags;
30206+
30207+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30208+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30209+ printk(KERN_WARNING "bios32_service: not valid\n");
30210 return 0;
30211+ }
30212+ address = address + PAGE_OFFSET;
30213+ length += 16UL; /* some BIOSs underreport this... */
30214+ flags = 4;
30215+ if (length >= 64*1024*1024) {
30216+ length >>= PAGE_SHIFT;
30217+ flags |= 8;
30218+ }
30219+
30220+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30221+ gdt = get_cpu_gdt_table(cpu);
30222+ pack_descriptor(&d, address, length, 0x9b, flags);
30223+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30224+ pack_descriptor(&d, address, length, 0x93, flags);
30225+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30226+ }
30227+ return entry;
30228+ }
30229+ case 0x80: /* Not present */
30230+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30231+ return 0;
30232+ default: /* Shouldn't happen */
30233+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30234+ service, return_code);
30235+ return 0;
30236 }
30237 }
30238
30239 static struct {
30240 unsigned long address;
30241 unsigned short segment;
30242-} pci_indirect = { 0, __KERNEL_CS };
30243+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30244
30245-static int pci_bios_present;
30246+static int pci_bios_present __read_only;
30247
30248 static int check_pcibios(void)
30249 {
30250@@ -131,11 +174,13 @@ static int check_pcibios(void)
30251 unsigned long flags, pcibios_entry;
30252
30253 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30254- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30255+ pci_indirect.address = pcibios_entry;
30256
30257 local_irq_save(flags);
30258- __asm__(
30259- "lcall *(%%edi); cld\n\t"
30260+ __asm__("movw %w6, %%ds\n\t"
30261+ "lcall *%%ss:(%%edi); cld\n\t"
30262+ "push %%ss\n\t"
30263+ "pop %%ds\n\t"
30264 "jc 1f\n\t"
30265 "xor %%ah, %%ah\n"
30266 "1:"
30267@@ -144,7 +189,8 @@ static int check_pcibios(void)
30268 "=b" (ebx),
30269 "=c" (ecx)
30270 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30271- "D" (&pci_indirect)
30272+ "D" (&pci_indirect),
30273+ "r" (__PCIBIOS_DS)
30274 : "memory");
30275 local_irq_restore(flags);
30276
30277@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30278
30279 switch (len) {
30280 case 1:
30281- __asm__("lcall *(%%esi); cld\n\t"
30282+ __asm__("movw %w6, %%ds\n\t"
30283+ "lcall *%%ss:(%%esi); cld\n\t"
30284+ "push %%ss\n\t"
30285+ "pop %%ds\n\t"
30286 "jc 1f\n\t"
30287 "xor %%ah, %%ah\n"
30288 "1:"
30289@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30290 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30291 "b" (bx),
30292 "D" ((long)reg),
30293- "S" (&pci_indirect));
30294+ "S" (&pci_indirect),
30295+ "r" (__PCIBIOS_DS));
30296 /*
30297 * Zero-extend the result beyond 8 bits, do not trust the
30298 * BIOS having done it:
30299@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30300 *value &= 0xff;
30301 break;
30302 case 2:
30303- __asm__("lcall *(%%esi); cld\n\t"
30304+ __asm__("movw %w6, %%ds\n\t"
30305+ "lcall *%%ss:(%%esi); cld\n\t"
30306+ "push %%ss\n\t"
30307+ "pop %%ds\n\t"
30308 "jc 1f\n\t"
30309 "xor %%ah, %%ah\n"
30310 "1:"
30311@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30312 : "1" (PCIBIOS_READ_CONFIG_WORD),
30313 "b" (bx),
30314 "D" ((long)reg),
30315- "S" (&pci_indirect));
30316+ "S" (&pci_indirect),
30317+ "r" (__PCIBIOS_DS));
30318 /*
30319 * Zero-extend the result beyond 16 bits, do not trust the
30320 * BIOS having done it:
30321@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30322 *value &= 0xffff;
30323 break;
30324 case 4:
30325- __asm__("lcall *(%%esi); cld\n\t"
30326+ __asm__("movw %w6, %%ds\n\t"
30327+ "lcall *%%ss:(%%esi); cld\n\t"
30328+ "push %%ss\n\t"
30329+ "pop %%ds\n\t"
30330 "jc 1f\n\t"
30331 "xor %%ah, %%ah\n"
30332 "1:"
30333@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30334 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30335 "b" (bx),
30336 "D" ((long)reg),
30337- "S" (&pci_indirect));
30338+ "S" (&pci_indirect),
30339+ "r" (__PCIBIOS_DS));
30340 break;
30341 }
30342
30343@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30344
30345 switch (len) {
30346 case 1:
30347- __asm__("lcall *(%%esi); cld\n\t"
30348+ __asm__("movw %w6, %%ds\n\t"
30349+ "lcall *%%ss:(%%esi); cld\n\t"
30350+ "push %%ss\n\t"
30351+ "pop %%ds\n\t"
30352 "jc 1f\n\t"
30353 "xor %%ah, %%ah\n"
30354 "1:"
30355@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30356 "c" (value),
30357 "b" (bx),
30358 "D" ((long)reg),
30359- "S" (&pci_indirect));
30360+ "S" (&pci_indirect),
30361+ "r" (__PCIBIOS_DS));
30362 break;
30363 case 2:
30364- __asm__("lcall *(%%esi); cld\n\t"
30365+ __asm__("movw %w6, %%ds\n\t"
30366+ "lcall *%%ss:(%%esi); cld\n\t"
30367+ "push %%ss\n\t"
30368+ "pop %%ds\n\t"
30369 "jc 1f\n\t"
30370 "xor %%ah, %%ah\n"
30371 "1:"
30372@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30373 "c" (value),
30374 "b" (bx),
30375 "D" ((long)reg),
30376- "S" (&pci_indirect));
30377+ "S" (&pci_indirect),
30378+ "r" (__PCIBIOS_DS));
30379 break;
30380 case 4:
30381- __asm__("lcall *(%%esi); cld\n\t"
30382+ __asm__("movw %w6, %%ds\n\t"
30383+ "lcall *%%ss:(%%esi); cld\n\t"
30384+ "push %%ss\n\t"
30385+ "pop %%ds\n\t"
30386 "jc 1f\n\t"
30387 "xor %%ah, %%ah\n"
30388 "1:"
30389@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30390 "c" (value),
30391 "b" (bx),
30392 "D" ((long)reg),
30393- "S" (&pci_indirect));
30394+ "S" (&pci_indirect),
30395+ "r" (__PCIBIOS_DS));
30396 break;
30397 }
30398
30399@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30400
30401 DBG("PCI: Fetching IRQ routing table... ");
30402 __asm__("push %%es\n\t"
30403+ "movw %w8, %%ds\n\t"
30404 "push %%ds\n\t"
30405 "pop %%es\n\t"
30406- "lcall *(%%esi); cld\n\t"
30407+ "lcall *%%ss:(%%esi); cld\n\t"
30408 "pop %%es\n\t"
30409+ "push %%ss\n\t"
30410+ "pop %%ds\n"
30411 "jc 1f\n\t"
30412 "xor %%ah, %%ah\n"
30413 "1:"
30414@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30415 "1" (0),
30416 "D" ((long) &opt),
30417 "S" (&pci_indirect),
30418- "m" (opt)
30419+ "m" (opt),
30420+ "r" (__PCIBIOS_DS)
30421 : "memory");
30422 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30423 if (ret & 0xff00)
30424@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30425 {
30426 int ret;
30427
30428- __asm__("lcall *(%%esi); cld\n\t"
30429+ __asm__("movw %w5, %%ds\n\t"
30430+ "lcall *%%ss:(%%esi); cld\n\t"
30431+ "push %%ss\n\t"
30432+ "pop %%ds\n"
30433 "jc 1f\n\t"
30434 "xor %%ah, %%ah\n"
30435 "1:"
30436@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30437 : "0" (PCIBIOS_SET_PCI_HW_INT),
30438 "b" ((dev->bus->number << 8) | dev->devfn),
30439 "c" ((irq << 8) | (pin + 10)),
30440- "S" (&pci_indirect));
30441+ "S" (&pci_indirect),
30442+ "r" (__PCIBIOS_DS));
30443 return !(ret & 0xff00);
30444 }
30445 EXPORT_SYMBOL(pcibios_set_irq_routing);
30446diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30447index 40e4469..0592924 100644
30448--- a/arch/x86/platform/efi/efi_32.c
30449+++ b/arch/x86/platform/efi/efi_32.c
30450@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30451 {
30452 struct desc_ptr gdt_descr;
30453
30454+#ifdef CONFIG_PAX_KERNEXEC
30455+ struct desc_struct d;
30456+#endif
30457+
30458 local_irq_save(efi_rt_eflags);
30459
30460 load_cr3(initial_page_table);
30461 __flush_tlb_all();
30462
30463+#ifdef CONFIG_PAX_KERNEXEC
30464+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30465+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30466+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30467+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30468+#endif
30469+
30470 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30471 gdt_descr.size = GDT_SIZE - 1;
30472 load_gdt(&gdt_descr);
30473@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
30474 {
30475 struct desc_ptr gdt_descr;
30476
30477+#ifdef CONFIG_PAX_KERNEXEC
30478+ struct desc_struct d;
30479+
30480+ memset(&d, 0, sizeof d);
30481+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30482+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30483+#endif
30484+
30485 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30486 gdt_descr.size = GDT_SIZE - 1;
30487 load_gdt(&gdt_descr);
30488
30489+#ifdef CONFIG_PAX_PER_CPU_PGD
30490+ load_cr3(get_cpu_pgd(smp_processor_id()));
30491+#else
30492 load_cr3(swapper_pg_dir);
30493+#endif
30494+
30495 __flush_tlb_all();
30496
30497 local_irq_restore(efi_rt_eflags);
30498diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
30499index 39a0e7f1..ecc2f1e 100644
30500--- a/arch/x86/platform/efi/efi_64.c
30501+++ b/arch/x86/platform/efi/efi_64.c
30502@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
30503 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
30504 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
30505 }
30506+
30507+#ifdef CONFIG_PAX_PER_CPU_PGD
30508+ load_cr3(swapper_pg_dir);
30509+#endif
30510+
30511 __flush_tlb_all();
30512 }
30513
30514@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
30515 for (pgd = 0; pgd < n_pgds; pgd++)
30516 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
30517 kfree(save_pgd);
30518+
30519+#ifdef CONFIG_PAX_PER_CPU_PGD
30520+ load_cr3(get_cpu_pgd(smp_processor_id()));
30521+#endif
30522+
30523 __flush_tlb_all();
30524 local_irq_restore(efi_flags);
30525 early_code_mapping_set_exec(0);
30526diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30527index fbe66e6..eae5e38 100644
30528--- a/arch/x86/platform/efi/efi_stub_32.S
30529+++ b/arch/x86/platform/efi/efi_stub_32.S
30530@@ -6,7 +6,9 @@
30531 */
30532
30533 #include <linux/linkage.h>
30534+#include <linux/init.h>
30535 #include <asm/page_types.h>
30536+#include <asm/segment.h>
30537
30538 /*
30539 * efi_call_phys(void *, ...) is a function with variable parameters.
30540@@ -20,7 +22,7 @@
30541 * service functions will comply with gcc calling convention, too.
30542 */
30543
30544-.text
30545+__INIT
30546 ENTRY(efi_call_phys)
30547 /*
30548 * 0. The function can only be called in Linux kernel. So CS has been
30549@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30550 * The mapping of lower virtual memory has been created in prelog and
30551 * epilog.
30552 */
30553- movl $1f, %edx
30554- subl $__PAGE_OFFSET, %edx
30555- jmp *%edx
30556+#ifdef CONFIG_PAX_KERNEXEC
30557+ movl $(__KERNEXEC_EFI_DS), %edx
30558+ mov %edx, %ds
30559+ mov %edx, %es
30560+ mov %edx, %ss
30561+ addl $2f,(1f)
30562+ ljmp *(1f)
30563+
30564+__INITDATA
30565+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30566+.previous
30567+
30568+2:
30569+ subl $2b,(1b)
30570+#else
30571+ jmp 1f-__PAGE_OFFSET
30572 1:
30573+#endif
30574
30575 /*
30576 * 2. Now on the top of stack is the return
30577@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30578 * parameter 2, ..., param n. To make things easy, we save the return
30579 * address of efi_call_phys in a global variable.
30580 */
30581- popl %edx
30582- movl %edx, saved_return_addr
30583- /* get the function pointer into ECX*/
30584- popl %ecx
30585- movl %ecx, efi_rt_function_ptr
30586- movl $2f, %edx
30587- subl $__PAGE_OFFSET, %edx
30588- pushl %edx
30589+ popl (saved_return_addr)
30590+ popl (efi_rt_function_ptr)
30591
30592 /*
30593 * 3. Clear PG bit in %CR0.
30594@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30595 /*
30596 * 5. Call the physical function.
30597 */
30598- jmp *%ecx
30599+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30600
30601-2:
30602 /*
30603 * 6. After EFI runtime service returns, control will return to
30604 * following instruction. We'd better readjust stack pointer first.
30605@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30606 movl %cr0, %edx
30607 orl $0x80000000, %edx
30608 movl %edx, %cr0
30609- jmp 1f
30610-1:
30611+
30612 /*
30613 * 8. Now restore the virtual mode from flat mode by
30614 * adding EIP with PAGE_OFFSET.
30615 */
30616- movl $1f, %edx
30617- jmp *%edx
30618+#ifdef CONFIG_PAX_KERNEXEC
30619+ movl $(__KERNEL_DS), %edx
30620+ mov %edx, %ds
30621+ mov %edx, %es
30622+ mov %edx, %ss
30623+ ljmp $(__KERNEL_CS),$1f
30624+#else
30625+ jmp 1f+__PAGE_OFFSET
30626+#endif
30627 1:
30628
30629 /*
30630 * 9. Balance the stack. And because EAX contain the return value,
30631 * we'd better not clobber it.
30632 */
30633- leal efi_rt_function_ptr, %edx
30634- movl (%edx), %ecx
30635- pushl %ecx
30636+ pushl (efi_rt_function_ptr)
30637
30638 /*
30639- * 10. Push the saved return address onto the stack and return.
30640+ * 10. Return to the saved return address.
30641 */
30642- leal saved_return_addr, %edx
30643- movl (%edx), %ecx
30644- pushl %ecx
30645- ret
30646+ jmpl *(saved_return_addr)
30647 ENDPROC(efi_call_phys)
30648 .previous
30649
30650-.data
30651+__INITDATA
30652 saved_return_addr:
30653 .long 0
30654 efi_rt_function_ptr:
30655diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30656index 4c07cca..2c8427d 100644
30657--- a/arch/x86/platform/efi/efi_stub_64.S
30658+++ b/arch/x86/platform/efi/efi_stub_64.S
30659@@ -7,6 +7,7 @@
30660 */
30661
30662 #include <linux/linkage.h>
30663+#include <asm/alternative-asm.h>
30664
30665 #define SAVE_XMM \
30666 mov %rsp, %rax; \
30667@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30668 call *%rdi
30669 addq $32, %rsp
30670 RESTORE_XMM
30671+ pax_force_retaddr 0, 1
30672 ret
30673 ENDPROC(efi_call0)
30674
30675@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30676 call *%rdi
30677 addq $32, %rsp
30678 RESTORE_XMM
30679+ pax_force_retaddr 0, 1
30680 ret
30681 ENDPROC(efi_call1)
30682
30683@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30684 call *%rdi
30685 addq $32, %rsp
30686 RESTORE_XMM
30687+ pax_force_retaddr 0, 1
30688 ret
30689 ENDPROC(efi_call2)
30690
30691@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30692 call *%rdi
30693 addq $32, %rsp
30694 RESTORE_XMM
30695+ pax_force_retaddr 0, 1
30696 ret
30697 ENDPROC(efi_call3)
30698
30699@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30700 call *%rdi
30701 addq $32, %rsp
30702 RESTORE_XMM
30703+ pax_force_retaddr 0, 1
30704 ret
30705 ENDPROC(efi_call4)
30706
30707@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30708 call *%rdi
30709 addq $48, %rsp
30710 RESTORE_XMM
30711+ pax_force_retaddr 0, 1
30712 ret
30713 ENDPROC(efi_call5)
30714
30715@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30716 call *%rdi
30717 addq $48, %rsp
30718 RESTORE_XMM
30719+ pax_force_retaddr 0, 1
30720 ret
30721 ENDPROC(efi_call6)
30722diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30723index a0a0a43..a48e233 100644
30724--- a/arch/x86/platform/mrst/mrst.c
30725+++ b/arch/x86/platform/mrst/mrst.c
30726@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30727 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30728 int sfi_mrtc_num;
30729
30730-static void mrst_power_off(void)
30731+static __noreturn void mrst_power_off(void)
30732 {
30733+ BUG();
30734 }
30735
30736-static void mrst_reboot(void)
30737+static __noreturn void mrst_reboot(void)
30738 {
30739 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30740+ BUG();
30741 }
30742
30743 /* parse all the mtimer info to a static mtimer array */
30744diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30745index d6ee929..3637cb5 100644
30746--- a/arch/x86/platform/olpc/olpc_dt.c
30747+++ b/arch/x86/platform/olpc/olpc_dt.c
30748@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30749 return res;
30750 }
30751
30752-static struct of_pdt_ops prom_olpc_ops __initdata = {
30753+static struct of_pdt_ops prom_olpc_ops __initconst = {
30754 .nextprop = olpc_dt_nextprop,
30755 .getproplen = olpc_dt_getproplen,
30756 .getproperty = olpc_dt_getproperty,
30757diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30758index 1cf5b30..fd45732 100644
30759--- a/arch/x86/power/cpu.c
30760+++ b/arch/x86/power/cpu.c
30761@@ -137,11 +137,8 @@ static void do_fpu_end(void)
30762 static void fix_processor_context(void)
30763 {
30764 int cpu = smp_processor_id();
30765- struct tss_struct *t = &per_cpu(init_tss, cpu);
30766-#ifdef CONFIG_X86_64
30767- struct desc_struct *desc = get_cpu_gdt_table(cpu);
30768- tss_desc tss;
30769-#endif
30770+ struct tss_struct *t = init_tss + cpu;
30771+
30772 set_tss_desc(cpu, t); /*
30773 * This just modifies memory; should not be
30774 * necessary. But... This is necessary, because
30775@@ -150,10 +147,6 @@ static void fix_processor_context(void)
30776 */
30777
30778 #ifdef CONFIG_X86_64
30779- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
30780- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
30781- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
30782-
30783 syscall_init(); /* This sets MSR_*STAR and related */
30784 #endif
30785 load_TR_desc(); /* This does ltr */
30786diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30787index a44f457..9140171 100644
30788--- a/arch/x86/realmode/init.c
30789+++ b/arch/x86/realmode/init.c
30790@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
30791 __va(real_mode_header->trampoline_header);
30792
30793 #ifdef CONFIG_X86_32
30794- trampoline_header->start = __pa_symbol(startup_32_smp);
30795+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
30796+
30797+#ifdef CONFIG_PAX_KERNEXEC
30798+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30799+#endif
30800+
30801+ trampoline_header->boot_cs = __BOOT_CS;
30802 trampoline_header->gdt_limit = __BOOT_DS + 7;
30803 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
30804 #else
30805@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
30806 *trampoline_cr4_features = read_cr4();
30807
30808 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
30809- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
30810+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
30811 trampoline_pgd[511] = init_level4_pgt[511].pgd;
30812 #endif
30813 }
30814diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30815index 8869287..d577672 100644
30816--- a/arch/x86/realmode/rm/Makefile
30817+++ b/arch/x86/realmode/rm/Makefile
30818@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30819 $(call cc-option, -fno-unit-at-a-time)) \
30820 $(call cc-option, -fno-stack-protector) \
30821 $(call cc-option, -mpreferred-stack-boundary=2)
30822+ifdef CONSTIFY_PLUGIN
30823+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30824+endif
30825 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30826 GCOV_PROFILE := n
30827diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30828index a28221d..93c40f1 100644
30829--- a/arch/x86/realmode/rm/header.S
30830+++ b/arch/x86/realmode/rm/header.S
30831@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30832 #endif
30833 /* APM/BIOS reboot */
30834 .long pa_machine_real_restart_asm
30835-#ifdef CONFIG_X86_64
30836+#ifdef CONFIG_X86_32
30837+ .long __KERNEL_CS
30838+#else
30839 .long __KERNEL32_CS
30840 #endif
30841 END(real_mode_header)
30842diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30843index c1b2791..f9e31c7 100644
30844--- a/arch/x86/realmode/rm/trampoline_32.S
30845+++ b/arch/x86/realmode/rm/trampoline_32.S
30846@@ -25,6 +25,12 @@
30847 #include <asm/page_types.h>
30848 #include "realmode.h"
30849
30850+#ifdef CONFIG_PAX_KERNEXEC
30851+#define ta(X) (X)
30852+#else
30853+#define ta(X) (pa_ ## X)
30854+#endif
30855+
30856 .text
30857 .code16
30858
30859@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30860
30861 cli # We should be safe anyway
30862
30863- movl tr_start, %eax # where we need to go
30864-
30865 movl $0xA5A5A5A5, trampoline_status
30866 # write marker for master knows we're running
30867
30868@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30869 movw $1, %dx # protected mode (PE) bit
30870 lmsw %dx # into protected mode
30871
30872- ljmpl $__BOOT_CS, $pa_startup_32
30873+ ljmpl *(trampoline_header)
30874
30875 .section ".text32","ax"
30876 .code32
30877@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30878 .balign 8
30879 GLOBAL(trampoline_header)
30880 tr_start: .space 4
30881- tr_gdt_pad: .space 2
30882+ tr_boot_cs: .space 2
30883 tr_gdt: .space 6
30884 END(trampoline_header)
30885
30886diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30887index bb360dc..3e5945f 100644
30888--- a/arch/x86/realmode/rm/trampoline_64.S
30889+++ b/arch/x86/realmode/rm/trampoline_64.S
30890@@ -107,7 +107,7 @@ ENTRY(startup_32)
30891 wrmsr
30892
30893 # Enable paging and in turn activate Long Mode
30894- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30895+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30896 movl %eax, %cr0
30897
30898 /*
30899diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
30900index e812034..c747134 100644
30901--- a/arch/x86/tools/Makefile
30902+++ b/arch/x86/tools/Makefile
30903@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
30904
30905 $(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c
30906
30907-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
30908+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
30909 hostprogs-y += relocs
30910 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
30911 relocs: $(obj)/relocs
30912diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30913index f7bab68..b6d9886 100644
30914--- a/arch/x86/tools/relocs.c
30915+++ b/arch/x86/tools/relocs.c
30916@@ -1,5 +1,7 @@
30917 /* This is included from relocs_32/64.c */
30918
30919+#include "../../../include/generated/autoconf.h"
30920+
30921 #define ElfW(type) _ElfW(ELF_BITS, type)
30922 #define _ElfW(bits, type) __ElfW(bits, type)
30923 #define __ElfW(bits, type) Elf##bits##_##type
30924@@ -11,6 +13,7 @@
30925 #define Elf_Sym ElfW(Sym)
30926
30927 static Elf_Ehdr ehdr;
30928+static Elf_Phdr *phdr;
30929
30930 struct relocs {
30931 uint32_t *offset;
30932@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
30933 }
30934 }
30935
30936+static void read_phdrs(FILE *fp)
30937+{
30938+ unsigned int i;
30939+
30940+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
30941+ if (!phdr) {
30942+ die("Unable to allocate %d program headers\n",
30943+ ehdr.e_phnum);
30944+ }
30945+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30946+ die("Seek to %d failed: %s\n",
30947+ ehdr.e_phoff, strerror(errno));
30948+ }
30949+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30950+ die("Cannot read ELF program headers: %s\n",
30951+ strerror(errno));
30952+ }
30953+ for(i = 0; i < ehdr.e_phnum; i++) {
30954+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
30955+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
30956+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
30957+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
30958+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
30959+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
30960+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
30961+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
30962+ }
30963+
30964+}
30965+
30966 static void read_shdrs(FILE *fp)
30967 {
30968- int i;
30969+ unsigned int i;
30970 Elf_Shdr shdr;
30971
30972 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30973@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
30974
30975 static void read_strtabs(FILE *fp)
30976 {
30977- int i;
30978+ unsigned int i;
30979 for (i = 0; i < ehdr.e_shnum; i++) {
30980 struct section *sec = &secs[i];
30981 if (sec->shdr.sh_type != SHT_STRTAB) {
30982@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
30983
30984 static void read_symtabs(FILE *fp)
30985 {
30986- int i,j;
30987+ unsigned int i,j;
30988 for (i = 0; i < ehdr.e_shnum; i++) {
30989 struct section *sec = &secs[i];
30990 if (sec->shdr.sh_type != SHT_SYMTAB) {
30991@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
30992 }
30993
30994
30995-static void read_relocs(FILE *fp)
30996+static void read_relocs(FILE *fp, int use_real_mode)
30997 {
30998- int i,j;
30999+ unsigned int i,j;
31000+ uint32_t base;
31001+
31002 for (i = 0; i < ehdr.e_shnum; i++) {
31003 struct section *sec = &secs[i];
31004 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31005@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
31006 die("Cannot read symbol table: %s\n",
31007 strerror(errno));
31008 }
31009+ base = 0;
31010+
31011+#ifdef CONFIG_X86_32
31012+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
31013+ if (phdr[j].p_type != PT_LOAD )
31014+ continue;
31015+ 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)
31016+ continue;
31017+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
31018+ break;
31019+ }
31020+#endif
31021+
31022 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
31023 Elf_Rel *rel = &sec->reltab[j];
31024- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
31025+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
31026 rel->r_info = elf_xword_to_cpu(rel->r_info);
31027 #if (SHT_REL_TYPE == SHT_RELA)
31028 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
31029@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
31030
31031 static void print_absolute_symbols(void)
31032 {
31033- int i;
31034+ unsigned int i;
31035 const char *format;
31036
31037 if (ELF_BITS == 64)
31038@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
31039 for (i = 0; i < ehdr.e_shnum; i++) {
31040 struct section *sec = &secs[i];
31041 char *sym_strtab;
31042- int j;
31043+ unsigned int j;
31044
31045 if (sec->shdr.sh_type != SHT_SYMTAB) {
31046 continue;
31047@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
31048
31049 static void print_absolute_relocs(void)
31050 {
31051- int i, printed = 0;
31052+ unsigned int i, printed = 0;
31053 const char *format;
31054
31055 if (ELF_BITS == 64)
31056@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
31057 struct section *sec_applies, *sec_symtab;
31058 char *sym_strtab;
31059 Elf_Sym *sh_symtab;
31060- int j;
31061+ unsigned int j;
31062 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31063 continue;
31064 }
31065@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
31066 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
31067 Elf_Sym *sym, const char *symname))
31068 {
31069- int i;
31070+ unsigned int i;
31071 /* Walk through the relocations */
31072 for (i = 0; i < ehdr.e_shnum; i++) {
31073 char *sym_strtab;
31074 Elf_Sym *sh_symtab;
31075 struct section *sec_applies, *sec_symtab;
31076- int j;
31077+ unsigned int j;
31078 struct section *sec = &secs[i];
31079
31080 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31081@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
31082 {
31083 unsigned r_type = ELF32_R_TYPE(rel->r_info);
31084 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
31085+ char *sym_strtab = sec->link->link->strtab;
31086+
31087+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31088+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31089+ return 0;
31090+
31091+#ifdef CONFIG_PAX_KERNEXEC
31092+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31093+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31094+ return 0;
31095+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31096+ return 0;
31097+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31098+ return 0;
31099+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31100+ return 0;
31101+#endif
31102
31103 switch (r_type) {
31104 case R_386_NONE:
31105@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
31106
31107 static void emit_relocs(int as_text, int use_real_mode)
31108 {
31109- int i;
31110+ unsigned int i;
31111 int (*write_reloc)(uint32_t, FILE *) = write32;
31112 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
31113 const char *symname);
31114@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
31115 {
31116 regex_init(use_real_mode);
31117 read_ehdr(fp);
31118+ read_phdrs(fp);
31119 read_shdrs(fp);
31120 read_strtabs(fp);
31121 read_symtabs(fp);
31122- read_relocs(fp);
31123+ read_relocs(fp, use_real_mode);
31124 if (ELF_BITS == 64)
31125 percpu_init();
31126 if (show_absolute_syms) {
31127diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
31128index 80ffa5b..a33bd15 100644
31129--- a/arch/x86/um/tls_32.c
31130+++ b/arch/x86/um/tls_32.c
31131@@ -260,7 +260,7 @@ out:
31132 if (unlikely(task == current &&
31133 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
31134 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
31135- "without flushed TLS.", current->pid);
31136+ "without flushed TLS.", task_pid_nr(current));
31137 }
31138
31139 return 0;
31140diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31141index fd14be1..e3c79c0 100644
31142--- a/arch/x86/vdso/Makefile
31143+++ b/arch/x86/vdso/Makefile
31144@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31145 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31146 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31147
31148-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31149+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31150 GCOV_PROFILE := n
31151
31152 #
31153diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31154index 0faad64..39ef157 100644
31155--- a/arch/x86/vdso/vdso32-setup.c
31156+++ b/arch/x86/vdso/vdso32-setup.c
31157@@ -25,6 +25,7 @@
31158 #include <asm/tlbflush.h>
31159 #include <asm/vdso.h>
31160 #include <asm/proto.h>
31161+#include <asm/mman.h>
31162
31163 enum {
31164 VDSO_DISABLED = 0,
31165@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31166 void enable_sep_cpu(void)
31167 {
31168 int cpu = get_cpu();
31169- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31170+ struct tss_struct *tss = init_tss + cpu;
31171
31172 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31173 put_cpu();
31174@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31175 gate_vma.vm_start = FIXADDR_USER_START;
31176 gate_vma.vm_end = FIXADDR_USER_END;
31177 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31178- gate_vma.vm_page_prot = __P101;
31179+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31180
31181 return 0;
31182 }
31183@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31184 if (compat)
31185 addr = VDSO_HIGH_BASE;
31186 else {
31187- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31188+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31189 if (IS_ERR_VALUE(addr)) {
31190 ret = addr;
31191 goto up_fail;
31192 }
31193 }
31194
31195- current->mm->context.vdso = (void *)addr;
31196+ current->mm->context.vdso = addr;
31197
31198 if (compat_uses_vma || !compat) {
31199 /*
31200@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31201 }
31202
31203 current_thread_info()->sysenter_return =
31204- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31205+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31206
31207 up_fail:
31208 if (ret)
31209- current->mm->context.vdso = NULL;
31210+ current->mm->context.vdso = 0;
31211
31212 up_write(&mm->mmap_sem);
31213
31214@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31215
31216 const char *arch_vma_name(struct vm_area_struct *vma)
31217 {
31218- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31219+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31220 return "[vdso]";
31221+
31222+#ifdef CONFIG_PAX_SEGMEXEC
31223+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31224+ return "[vdso]";
31225+#endif
31226+
31227 return NULL;
31228 }
31229
31230@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31231 * Check to see if the corresponding task was created in compat vdso
31232 * mode.
31233 */
31234- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31235+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31236 return &gate_vma;
31237 return NULL;
31238 }
31239diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31240index 431e875..cbb23f3 100644
31241--- a/arch/x86/vdso/vma.c
31242+++ b/arch/x86/vdso/vma.c
31243@@ -16,8 +16,6 @@
31244 #include <asm/vdso.h>
31245 #include <asm/page.h>
31246
31247-unsigned int __read_mostly vdso_enabled = 1;
31248-
31249 extern char vdso_start[], vdso_end[];
31250 extern unsigned short vdso_sync_cpuid;
31251
31252@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31253 * unaligned here as a result of stack start randomization.
31254 */
31255 addr = PAGE_ALIGN(addr);
31256- addr = align_vdso_addr(addr);
31257
31258 return addr;
31259 }
31260@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31261 unsigned size)
31262 {
31263 struct mm_struct *mm = current->mm;
31264- unsigned long addr;
31265+ unsigned long addr = 0;
31266 int ret;
31267
31268- if (!vdso_enabled)
31269- return 0;
31270-
31271 down_write(&mm->mmap_sem);
31272+
31273+#ifdef CONFIG_PAX_RANDMMAP
31274+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31275+#endif
31276+
31277 addr = vdso_addr(mm->start_stack, size);
31278+ addr = align_vdso_addr(addr);
31279 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31280 if (IS_ERR_VALUE(addr)) {
31281 ret = addr;
31282 goto up_fail;
31283 }
31284
31285- current->mm->context.vdso = (void *)addr;
31286+ mm->context.vdso = addr;
31287
31288 ret = install_special_mapping(mm, addr, size,
31289 VM_READ|VM_EXEC|
31290 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31291 pages);
31292- if (ret) {
31293- current->mm->context.vdso = NULL;
31294- goto up_fail;
31295- }
31296+ if (ret)
31297+ mm->context.vdso = 0;
31298
31299 up_fail:
31300 up_write(&mm->mmap_sem);
31301@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31302 vdsox32_size);
31303 }
31304 #endif
31305-
31306-static __init int vdso_setup(char *s)
31307-{
31308- vdso_enabled = simple_strtoul(s, NULL, 0);
31309- return 0;
31310-}
31311-__setup("vdso=", vdso_setup);
31312diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31313index a492be2..08678da 100644
31314--- a/arch/x86/xen/enlighten.c
31315+++ b/arch/x86/xen/enlighten.c
31316@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31317
31318 struct shared_info xen_dummy_shared_info;
31319
31320-void *xen_initial_gdt;
31321-
31322 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31323 __read_mostly int xen_have_vector_callback;
31324 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31325@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31326 {
31327 unsigned long va = dtr->address;
31328 unsigned int size = dtr->size + 1;
31329- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31330- unsigned long frames[pages];
31331+ unsigned long frames[65536 / PAGE_SIZE];
31332 int f;
31333
31334 /*
31335@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31336 {
31337 unsigned long va = dtr->address;
31338 unsigned int size = dtr->size + 1;
31339- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31340- unsigned long frames[pages];
31341+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31342 int f;
31343
31344 /*
31345@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31346 * 8-byte entries, or 16 4k pages..
31347 */
31348
31349- BUG_ON(size > 65536);
31350+ BUG_ON(size > GDT_SIZE);
31351 BUG_ON(va & ~PAGE_MASK);
31352
31353 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31354@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31355 return 0;
31356 }
31357
31358-static void set_xen_basic_apic_ops(void)
31359+static void __init set_xen_basic_apic_ops(void)
31360 {
31361 apic->read = xen_apic_read;
31362 apic->write = xen_apic_write;
31363@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31364 #endif
31365 };
31366
31367-static void xen_reboot(int reason)
31368+static __noreturn void xen_reboot(int reason)
31369 {
31370 struct sched_shutdown r = { .reason = reason };
31371
31372- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31373- BUG();
31374+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31375+ BUG();
31376 }
31377
31378-static void xen_restart(char *msg)
31379+static __noreturn void xen_restart(char *msg)
31380 {
31381 xen_reboot(SHUTDOWN_reboot);
31382 }
31383
31384-static void xen_emergency_restart(void)
31385+static __noreturn void xen_emergency_restart(void)
31386 {
31387 xen_reboot(SHUTDOWN_reboot);
31388 }
31389
31390-static void xen_machine_halt(void)
31391+static __noreturn void xen_machine_halt(void)
31392 {
31393 xen_reboot(SHUTDOWN_poweroff);
31394 }
31395
31396-static void xen_machine_power_off(void)
31397+static __noreturn void xen_machine_power_off(void)
31398 {
31399 if (pm_power_off)
31400 pm_power_off();
31401@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
31402 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31403
31404 /* Work out if we support NX */
31405- x86_configure_nx();
31406+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31407+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31408+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31409+ unsigned l, h;
31410+
31411+ __supported_pte_mask |= _PAGE_NX;
31412+ rdmsr(MSR_EFER, l, h);
31413+ l |= EFER_NX;
31414+ wrmsr(MSR_EFER, l, h);
31415+ }
31416+#endif
31417
31418 xen_setup_features();
31419
31420@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
31421
31422 machine_ops = xen_machine_ops;
31423
31424- /*
31425- * The only reliable way to retain the initial address of the
31426- * percpu gdt_page is to remember it here, so we can go and
31427- * mark it RW later, when the initial percpu area is freed.
31428- */
31429- xen_initial_gdt = &per_cpu(gdt_page, 0);
31430-
31431 xen_smp_init();
31432
31433 #ifdef CONFIG_ACPI_NUMA
31434@@ -1700,7 +1699,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31435 return NOTIFY_OK;
31436 }
31437
31438-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31439+static struct notifier_block xen_hvm_cpu_notifier = {
31440 .notifier_call = xen_hvm_cpu_notify,
31441 };
31442
31443diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31444index fdc3ba2..3daee39 100644
31445--- a/arch/x86/xen/mmu.c
31446+++ b/arch/x86/xen/mmu.c
31447@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31448 /* L3_k[510] -> level2_kernel_pgt
31449 * L3_i[511] -> level2_fixmap_pgt */
31450 convert_pfn_mfn(level3_kernel_pgt);
31451+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31452+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31453+ convert_pfn_mfn(level3_vmemmap_pgt);
31454
31455 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31456 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31457@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31458 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31459 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31460 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31461+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31462+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31463+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31464 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31465 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31466+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31467 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31468 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31469
31470@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
31471 pv_mmu_ops.set_pud = xen_set_pud;
31472 #if PAGETABLE_LEVELS == 4
31473 pv_mmu_ops.set_pgd = xen_set_pgd;
31474+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31475 #endif
31476
31477 /* This will work as long as patching hasn't happened yet
31478@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31479 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31480 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31481 .set_pgd = xen_set_pgd_hyper,
31482+ .set_pgd_batched = xen_set_pgd_hyper,
31483
31484 .alloc_pud = xen_alloc_pmd_init,
31485 .release_pud = xen_release_pmd_init,
31486diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31487index d99cae8..18401e1 100644
31488--- a/arch/x86/xen/smp.c
31489+++ b/arch/x86/xen/smp.c
31490@@ -240,11 +240,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31491 {
31492 BUG_ON(smp_processor_id() != 0);
31493 native_smp_prepare_boot_cpu();
31494-
31495- /* We've switched to the "real" per-cpu gdt, so make sure the
31496- old memory can be recycled */
31497- make_lowmem_page_readwrite(xen_initial_gdt);
31498-
31499 xen_filter_cpu_maps();
31500 xen_setup_vcpu_info_placement();
31501 }
31502@@ -314,7 +309,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31503 ctxt->user_regs.ss = __KERNEL_DS;
31504 #ifdef CONFIG_X86_32
31505 ctxt->user_regs.fs = __KERNEL_PERCPU;
31506- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31507+ savesegment(gs, ctxt->user_regs.gs);
31508 #else
31509 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31510 #endif
31511@@ -324,8 +319,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31512
31513 {
31514 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
31515- ctxt->user_regs.ds = __USER_DS;
31516- ctxt->user_regs.es = __USER_DS;
31517+ ctxt->user_regs.ds = __KERNEL_DS;
31518+ ctxt->user_regs.es = __KERNEL_DS;
31519
31520 xen_copy_trap_info(ctxt->trap_ctxt);
31521
31522@@ -370,13 +365,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31523 int rc;
31524
31525 per_cpu(current_task, cpu) = idle;
31526+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31527 #ifdef CONFIG_X86_32
31528 irq_ctx_init(cpu);
31529 #else
31530 clear_tsk_thread_flag(idle, TIF_FORK);
31531- per_cpu(kernel_stack, cpu) =
31532- (unsigned long)task_stack_page(idle) -
31533- KERNEL_STACK_OFFSET + THREAD_SIZE;
31534+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31535 #endif
31536 xen_setup_runstate_info(cpu);
31537 xen_setup_timer(cpu);
31538@@ -651,7 +645,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31539
31540 void __init xen_smp_init(void)
31541 {
31542- smp_ops = xen_smp_ops;
31543+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31544 xen_fill_possible_map();
31545 xen_init_spinlocks();
31546 }
31547diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31548index 33ca6e4..0ded929 100644
31549--- a/arch/x86/xen/xen-asm_32.S
31550+++ b/arch/x86/xen/xen-asm_32.S
31551@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31552 ESP_OFFSET=4 # bytes pushed onto stack
31553
31554 /*
31555- * Store vcpu_info pointer for easy access. Do it this way to
31556- * avoid having to reload %fs
31557+ * Store vcpu_info pointer for easy access.
31558 */
31559 #ifdef CONFIG_SMP
31560- GET_THREAD_INFO(%eax)
31561- movl %ss:TI_cpu(%eax), %eax
31562- movl %ss:__per_cpu_offset(,%eax,4), %eax
31563- mov %ss:xen_vcpu(%eax), %eax
31564+ push %fs
31565+ mov $(__KERNEL_PERCPU), %eax
31566+ mov %eax, %fs
31567+ mov PER_CPU_VAR(xen_vcpu), %eax
31568+ pop %fs
31569 #else
31570 movl %ss:xen_vcpu, %eax
31571 #endif
31572diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31573index 7faed58..ba4427c 100644
31574--- a/arch/x86/xen/xen-head.S
31575+++ b/arch/x86/xen/xen-head.S
31576@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31577 #ifdef CONFIG_X86_32
31578 mov %esi,xen_start_info
31579 mov $init_thread_union+THREAD_SIZE,%esp
31580+#ifdef CONFIG_SMP
31581+ movl $cpu_gdt_table,%edi
31582+ movl $__per_cpu_load,%eax
31583+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31584+ rorl $16,%eax
31585+ movb %al,__KERNEL_PERCPU + 4(%edi)
31586+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31587+ movl $__per_cpu_end - 1,%eax
31588+ subl $__per_cpu_start,%eax
31589+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31590+#endif
31591 #else
31592 mov %rsi,xen_start_info
31593 mov $init_thread_union+THREAD_SIZE,%rsp
31594diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31595index a95b417..b6dbd0b 100644
31596--- a/arch/x86/xen/xen-ops.h
31597+++ b/arch/x86/xen/xen-ops.h
31598@@ -10,8 +10,6 @@
31599 extern const char xen_hypervisor_callback[];
31600 extern const char xen_failsafe_callback[];
31601
31602-extern void *xen_initial_gdt;
31603-
31604 struct trap_info;
31605 void xen_copy_trap_info(struct trap_info *traps);
31606
31607diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31608index 525bd3d..ef888b1 100644
31609--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31610+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31611@@ -119,9 +119,9 @@
31612 ----------------------------------------------------------------------*/
31613
31614 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31615-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31616 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31617 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31618+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31619
31620 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31621 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31622diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31623index 2f33760..835e50a 100644
31624--- a/arch/xtensa/variants/fsf/include/variant/core.h
31625+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31626@@ -11,6 +11,7 @@
31627 #ifndef _XTENSA_CORE_H
31628 #define _XTENSA_CORE_H
31629
31630+#include <linux/const.h>
31631
31632 /****************************************************************************
31633 Parameters Useful for Any Code, USER or PRIVILEGED
31634@@ -112,9 +113,9 @@
31635 ----------------------------------------------------------------------*/
31636
31637 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31638-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31639 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31640 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31641+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31642
31643 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31644 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31645diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31646index af00795..2bb8105 100644
31647--- a/arch/xtensa/variants/s6000/include/variant/core.h
31648+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31649@@ -11,6 +11,7 @@
31650 #ifndef _XTENSA_CORE_CONFIGURATION_H
31651 #define _XTENSA_CORE_CONFIGURATION_H
31652
31653+#include <linux/const.h>
31654
31655 /****************************************************************************
31656 Parameters Useful for Any Code, USER or PRIVILEGED
31657@@ -118,9 +119,9 @@
31658 ----------------------------------------------------------------------*/
31659
31660 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31661-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31662 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31663 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31664+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31665
31666 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31667 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31668diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31669index 58916af..eb9dbcf6 100644
31670--- a/block/blk-iopoll.c
31671+++ b/block/blk-iopoll.c
31672@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31673 }
31674 EXPORT_SYMBOL(blk_iopoll_complete);
31675
31676-static void blk_iopoll_softirq(struct softirq_action *h)
31677+static void blk_iopoll_softirq(void)
31678 {
31679 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31680 int rearm = 0, budget = blk_iopoll_budget;
31681@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31682 return NOTIFY_OK;
31683 }
31684
31685-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31686+static struct notifier_block blk_iopoll_cpu_notifier = {
31687 .notifier_call = blk_iopoll_cpu_notify,
31688 };
31689
31690diff --git a/block/blk-map.c b/block/blk-map.c
31691index 623e1cd..ca1e109 100644
31692--- a/block/blk-map.c
31693+++ b/block/blk-map.c
31694@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31695 if (!len || !kbuf)
31696 return -EINVAL;
31697
31698- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31699+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31700 if (do_copy)
31701 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31702 else
31703diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31704index 467c8de..f3628c5 100644
31705--- a/block/blk-softirq.c
31706+++ b/block/blk-softirq.c
31707@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31708 * Softirq action handler - move entries to local list and loop over them
31709 * while passing them to the queue registered handler.
31710 */
31711-static void blk_done_softirq(struct softirq_action *h)
31712+static void blk_done_softirq(void)
31713 {
31714 struct list_head *cpu_list, local_list;
31715
31716@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31717 return NOTIFY_OK;
31718 }
31719
31720-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31721+static struct notifier_block blk_cpu_notifier = {
31722 .notifier_call = blk_cpu_notify,
31723 };
31724
31725diff --git a/block/bsg.c b/block/bsg.c
31726index 420a5a9..23834aa 100644
31727--- a/block/bsg.c
31728+++ b/block/bsg.c
31729@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31730 struct sg_io_v4 *hdr, struct bsg_device *bd,
31731 fmode_t has_write_perm)
31732 {
31733+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31734+ unsigned char *cmdptr;
31735+
31736 if (hdr->request_len > BLK_MAX_CDB) {
31737 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31738 if (!rq->cmd)
31739 return -ENOMEM;
31740- }
31741+ cmdptr = rq->cmd;
31742+ } else
31743+ cmdptr = tmpcmd;
31744
31745- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31746+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31747 hdr->request_len))
31748 return -EFAULT;
31749
31750+ if (cmdptr != rq->cmd)
31751+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31752+
31753 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31754 if (blk_verify_command(rq->cmd, has_write_perm))
31755 return -EPERM;
31756diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31757index 7c668c8..db3521c 100644
31758--- a/block/compat_ioctl.c
31759+++ b/block/compat_ioctl.c
31760@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31761 err |= __get_user(f->spec1, &uf->spec1);
31762 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31763 err |= __get_user(name, &uf->name);
31764- f->name = compat_ptr(name);
31765+ f->name = (void __force_kernel *)compat_ptr(name);
31766 if (err) {
31767 err = -EFAULT;
31768 goto out;
31769diff --git a/block/genhd.c b/block/genhd.c
31770index cdeb527..10aa34db 100644
31771--- a/block/genhd.c
31772+++ b/block/genhd.c
31773@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
31774
31775 /*
31776 * Register device numbers dev..(dev+range-1)
31777- * range must be nonzero
31778+ * Noop if @range is zero.
31779 * The hash chain is sorted on range, so that subranges can override.
31780 */
31781 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
31782 struct kobject *(*probe)(dev_t, int *, void *),
31783 int (*lock)(dev_t, void *), void *data)
31784 {
31785- kobj_map(bdev_map, devt, range, module, probe, lock, data);
31786+ if (range)
31787+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
31788 }
31789
31790 EXPORT_SYMBOL(blk_register_region);
31791
31792+/* undo blk_register_region(), noop if @range is zero */
31793 void blk_unregister_region(dev_t devt, unsigned long range)
31794 {
31795- kobj_unmap(bdev_map, devt, range);
31796+ if (range)
31797+ kobj_unmap(bdev_map, devt, range);
31798 }
31799
31800 EXPORT_SYMBOL(blk_unregister_region);
31801diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31802index c85fc89..51e690b 100644
31803--- a/block/partitions/efi.c
31804+++ b/block/partitions/efi.c
31805@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31806 if (!gpt)
31807 return NULL;
31808
31809+ if (!le32_to_cpu(gpt->num_partition_entries))
31810+ return NULL;
31811+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31812+ if (!pte)
31813+ return NULL;
31814+
31815 count = le32_to_cpu(gpt->num_partition_entries) *
31816 le32_to_cpu(gpt->sizeof_partition_entry);
31817- if (!count)
31818- return NULL;
31819- pte = kmalloc(count, GFP_KERNEL);
31820- if (!pte)
31821- return NULL;
31822-
31823 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31824 (u8 *) pte,
31825 count) < count) {
31826diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31827index a5ffcc9..3cedc9c 100644
31828--- a/block/scsi_ioctl.c
31829+++ b/block/scsi_ioctl.c
31830@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
31831 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31832 struct sg_io_hdr *hdr, fmode_t mode)
31833 {
31834- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31835+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31836+ unsigned char *cmdptr;
31837+
31838+ if (rq->cmd != rq->__cmd)
31839+ cmdptr = rq->cmd;
31840+ else
31841+ cmdptr = tmpcmd;
31842+
31843+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31844 return -EFAULT;
31845+
31846+ if (cmdptr != rq->cmd)
31847+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31848+
31849 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31850 return -EPERM;
31851
31852@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31853 int err;
31854 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31855 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31856+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31857+ unsigned char *cmdptr;
31858
31859 if (!sic)
31860 return -EINVAL;
31861@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31862 */
31863 err = -EFAULT;
31864 rq->cmd_len = cmdlen;
31865- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31866+
31867+ if (rq->cmd != rq->__cmd)
31868+ cmdptr = rq->cmd;
31869+ else
31870+ cmdptr = tmpcmd;
31871+
31872+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31873 goto error;
31874
31875+ if (rq->cmd != cmdptr)
31876+ memcpy(rq->cmd, cmdptr, cmdlen);
31877+
31878 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31879 goto error;
31880
31881diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31882index 7bdd61b..afec999 100644
31883--- a/crypto/cryptd.c
31884+++ b/crypto/cryptd.c
31885@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31886
31887 struct cryptd_blkcipher_request_ctx {
31888 crypto_completion_t complete;
31889-};
31890+} __no_const;
31891
31892 struct cryptd_hash_ctx {
31893 struct crypto_shash *child;
31894@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31895
31896 struct cryptd_aead_request_ctx {
31897 crypto_completion_t complete;
31898-};
31899+} __no_const;
31900
31901 static void cryptd_queue_worker(struct work_struct *work);
31902
31903diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
31904index b2c99dc..476c9fb 100644
31905--- a/crypto/pcrypt.c
31906+++ b/crypto/pcrypt.c
31907@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
31908 int ret;
31909
31910 pinst->kobj.kset = pcrypt_kset;
31911- ret = kobject_add(&pinst->kobj, NULL, name);
31912+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
31913 if (!ret)
31914 kobject_uevent(&pinst->kobj, KOBJ_ADD);
31915
31916@@ -455,8 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
31917
31918 get_online_cpus();
31919
31920- pcrypt->wq = alloc_workqueue(name,
31921- WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
31922+ pcrypt->wq = alloc_workqueue("%s",
31923+ WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1, name);
31924 if (!pcrypt->wq)
31925 goto err;
31926
31927diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31928index f220d64..d359ad6 100644
31929--- a/drivers/acpi/apei/apei-internal.h
31930+++ b/drivers/acpi/apei/apei-internal.h
31931@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31932 struct apei_exec_ins_type {
31933 u32 flags;
31934 apei_exec_ins_func_t run;
31935-};
31936+} __do_const;
31937
31938 struct apei_exec_context {
31939 u32 ip;
31940diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31941index 33dc6a0..4b24b47 100644
31942--- a/drivers/acpi/apei/cper.c
31943+++ b/drivers/acpi/apei/cper.c
31944@@ -39,12 +39,12 @@
31945 */
31946 u64 cper_next_record_id(void)
31947 {
31948- static atomic64_t seq;
31949+ static atomic64_unchecked_t seq;
31950
31951- if (!atomic64_read(&seq))
31952- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31953+ if (!atomic64_read_unchecked(&seq))
31954+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31955
31956- return atomic64_inc_return(&seq);
31957+ return atomic64_inc_return_unchecked(&seq);
31958 }
31959 EXPORT_SYMBOL_GPL(cper_next_record_id);
31960
31961diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31962index be60399..778b33e8 100644
31963--- a/drivers/acpi/bgrt.c
31964+++ b/drivers/acpi/bgrt.c
31965@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31966 return -ENODEV;
31967
31968 sysfs_bin_attr_init(&image_attr);
31969- image_attr.private = bgrt_image;
31970- image_attr.size = bgrt_image_size;
31971+ pax_open_kernel();
31972+ *(void **)&image_attr.private = bgrt_image;
31973+ *(size_t *)&image_attr.size = bgrt_image_size;
31974+ pax_close_kernel();
31975
31976 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31977 if (!bgrt_kobj)
31978diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31979index cb96296..b81293b 100644
31980--- a/drivers/acpi/blacklist.c
31981+++ b/drivers/acpi/blacklist.c
31982@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31983 u32 is_critical_error;
31984 };
31985
31986-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31987+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31988
31989 /*
31990 * POLICY: If *anything* doesn't work, put it on the blacklist.
31991@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31992 return 0;
31993 }
31994
31995-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31996+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31997 {
31998 .callback = dmi_disable_osi_vista,
31999 .ident = "Fujitsu Siemens",
32000diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
32001index 7586544..636a2f0 100644
32002--- a/drivers/acpi/ec_sys.c
32003+++ b/drivers/acpi/ec_sys.c
32004@@ -12,6 +12,7 @@
32005 #include <linux/acpi.h>
32006 #include <linux/debugfs.h>
32007 #include <linux/module.h>
32008+#include <linux/uaccess.h>
32009 #include "internal.h"
32010
32011 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
32012@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32013 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
32014 */
32015 unsigned int size = EC_SPACE_SIZE;
32016- u8 *data = (u8 *) buf;
32017+ u8 data;
32018 loff_t init_off = *off;
32019 int err = 0;
32020
32021@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
32022 size = count;
32023
32024 while (size) {
32025- err = ec_read(*off, &data[*off - init_off]);
32026+ err = ec_read(*off, &data);
32027 if (err)
32028 return err;
32029+ if (put_user(data, &buf[*off - init_off]))
32030+ return -EFAULT;
32031 *off += 1;
32032 size--;
32033 }
32034@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32035
32036 unsigned int size = count;
32037 loff_t init_off = *off;
32038- u8 *data = (u8 *) buf;
32039 int err = 0;
32040
32041 if (*off >= EC_SPACE_SIZE)
32042@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32043 }
32044
32045 while (size) {
32046- u8 byte_write = data[*off - init_off];
32047+ u8 byte_write;
32048+ if (get_user(byte_write, &buf[*off - init_off]))
32049+ return -EFAULT;
32050 err = ec_write(*off, byte_write);
32051 if (err)
32052 return err;
32053diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32054index eb133c7..f571552 100644
32055--- a/drivers/acpi/processor_idle.c
32056+++ b/drivers/acpi/processor_idle.c
32057@@ -994,7 +994,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32058 {
32059 int i, count = CPUIDLE_DRIVER_STATE_START;
32060 struct acpi_processor_cx *cx;
32061- struct cpuidle_state *state;
32062+ cpuidle_state_no_const *state;
32063 struct cpuidle_driver *drv = &acpi_idle_driver;
32064
32065 if (!pr->flags.power_setup_done)
32066diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32067index fcae5fa..e9f71ea 100644
32068--- a/drivers/acpi/sysfs.c
32069+++ b/drivers/acpi/sysfs.c
32070@@ -423,11 +423,11 @@ static u32 num_counters;
32071 static struct attribute **all_attrs;
32072 static u32 acpi_gpe_count;
32073
32074-static struct attribute_group interrupt_stats_attr_group = {
32075+static attribute_group_no_const interrupt_stats_attr_group = {
32076 .name = "interrupts",
32077 };
32078
32079-static struct kobj_attribute *counter_attrs;
32080+static kobj_attribute_no_const *counter_attrs;
32081
32082 static void delete_gpe_attr_array(void)
32083 {
32084diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32085index 7b9bdd8..37638ca 100644
32086--- a/drivers/ata/libahci.c
32087+++ b/drivers/ata/libahci.c
32088@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32089 }
32090 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32091
32092-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32093+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32094 struct ata_taskfile *tf, int is_cmd, u16 flags,
32095 unsigned long timeout_msec)
32096 {
32097diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32098index adf002a..39bb8f9 100644
32099--- a/drivers/ata/libata-core.c
32100+++ b/drivers/ata/libata-core.c
32101@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32102 struct ata_port *ap;
32103 unsigned int tag;
32104
32105- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32106+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32107 ap = qc->ap;
32108
32109 qc->flags = 0;
32110@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32111 struct ata_port *ap;
32112 struct ata_link *link;
32113
32114- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32115+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32116 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32117 ap = qc->ap;
32118 link = qc->dev->link;
32119@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32120 return;
32121
32122 spin_lock(&lock);
32123+ pax_open_kernel();
32124
32125 for (cur = ops->inherits; cur; cur = cur->inherits) {
32126 void **inherit = (void **)cur;
32127@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32128 if (IS_ERR(*pp))
32129 *pp = NULL;
32130
32131- ops->inherits = NULL;
32132+ *(struct ata_port_operations **)&ops->inherits = NULL;
32133
32134+ pax_close_kernel();
32135 spin_unlock(&lock);
32136 }
32137
32138diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32139index 7638121..357a965 100644
32140--- a/drivers/ata/pata_arasan_cf.c
32141+++ b/drivers/ata/pata_arasan_cf.c
32142@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32143 /* Handle platform specific quirks */
32144 if (quirk) {
32145 if (quirk & CF_BROKEN_PIO) {
32146- ap->ops->set_piomode = NULL;
32147+ pax_open_kernel();
32148+ *(void **)&ap->ops->set_piomode = NULL;
32149+ pax_close_kernel();
32150 ap->pio_mask = 0;
32151 }
32152 if (quirk & CF_BROKEN_MWDMA)
32153diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32154index f9b983a..887b9d8 100644
32155--- a/drivers/atm/adummy.c
32156+++ b/drivers/atm/adummy.c
32157@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32158 vcc->pop(vcc, skb);
32159 else
32160 dev_kfree_skb_any(skb);
32161- atomic_inc(&vcc->stats->tx);
32162+ atomic_inc_unchecked(&vcc->stats->tx);
32163
32164 return 0;
32165 }
32166diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32167index 77a7480d..05cde58 100644
32168--- a/drivers/atm/ambassador.c
32169+++ b/drivers/atm/ambassador.c
32170@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32171 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32172
32173 // VC layer stats
32174- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32175+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32176
32177 // free the descriptor
32178 kfree (tx_descr);
32179@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32180 dump_skb ("<<<", vc, skb);
32181
32182 // VC layer stats
32183- atomic_inc(&atm_vcc->stats->rx);
32184+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32185 __net_timestamp(skb);
32186 // end of our responsibility
32187 atm_vcc->push (atm_vcc, skb);
32188@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32189 } else {
32190 PRINTK (KERN_INFO, "dropped over-size frame");
32191 // should we count this?
32192- atomic_inc(&atm_vcc->stats->rx_drop);
32193+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32194 }
32195
32196 } else {
32197@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32198 }
32199
32200 if (check_area (skb->data, skb->len)) {
32201- atomic_inc(&atm_vcc->stats->tx_err);
32202+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32203 return -ENOMEM; // ?
32204 }
32205
32206diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32207index 0e3f8f9..765a7a5 100644
32208--- a/drivers/atm/atmtcp.c
32209+++ b/drivers/atm/atmtcp.c
32210@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32211 if (vcc->pop) vcc->pop(vcc,skb);
32212 else dev_kfree_skb(skb);
32213 if (dev_data) return 0;
32214- atomic_inc(&vcc->stats->tx_err);
32215+ atomic_inc_unchecked(&vcc->stats->tx_err);
32216 return -ENOLINK;
32217 }
32218 size = skb->len+sizeof(struct atmtcp_hdr);
32219@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32220 if (!new_skb) {
32221 if (vcc->pop) vcc->pop(vcc,skb);
32222 else dev_kfree_skb(skb);
32223- atomic_inc(&vcc->stats->tx_err);
32224+ atomic_inc_unchecked(&vcc->stats->tx_err);
32225 return -ENOBUFS;
32226 }
32227 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32228@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32229 if (vcc->pop) vcc->pop(vcc,skb);
32230 else dev_kfree_skb(skb);
32231 out_vcc->push(out_vcc,new_skb);
32232- atomic_inc(&vcc->stats->tx);
32233- atomic_inc(&out_vcc->stats->rx);
32234+ atomic_inc_unchecked(&vcc->stats->tx);
32235+ atomic_inc_unchecked(&out_vcc->stats->rx);
32236 return 0;
32237 }
32238
32239@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32240 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32241 read_unlock(&vcc_sklist_lock);
32242 if (!out_vcc) {
32243- atomic_inc(&vcc->stats->tx_err);
32244+ atomic_inc_unchecked(&vcc->stats->tx_err);
32245 goto done;
32246 }
32247 skb_pull(skb,sizeof(struct atmtcp_hdr));
32248@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32249 __net_timestamp(new_skb);
32250 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32251 out_vcc->push(out_vcc,new_skb);
32252- atomic_inc(&vcc->stats->tx);
32253- atomic_inc(&out_vcc->stats->rx);
32254+ atomic_inc_unchecked(&vcc->stats->tx);
32255+ atomic_inc_unchecked(&out_vcc->stats->rx);
32256 done:
32257 if (vcc->pop) vcc->pop(vcc,skb);
32258 else dev_kfree_skb(skb);
32259diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32260index b1955ba..b179940 100644
32261--- a/drivers/atm/eni.c
32262+++ b/drivers/atm/eni.c
32263@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32264 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32265 vcc->dev->number);
32266 length = 0;
32267- atomic_inc(&vcc->stats->rx_err);
32268+ atomic_inc_unchecked(&vcc->stats->rx_err);
32269 }
32270 else {
32271 length = ATM_CELL_SIZE-1; /* no HEC */
32272@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32273 size);
32274 }
32275 eff = length = 0;
32276- atomic_inc(&vcc->stats->rx_err);
32277+ atomic_inc_unchecked(&vcc->stats->rx_err);
32278 }
32279 else {
32280 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32281@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32282 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32283 vcc->dev->number,vcc->vci,length,size << 2,descr);
32284 length = eff = 0;
32285- atomic_inc(&vcc->stats->rx_err);
32286+ atomic_inc_unchecked(&vcc->stats->rx_err);
32287 }
32288 }
32289 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32290@@ -767,7 +767,7 @@ rx_dequeued++;
32291 vcc->push(vcc,skb);
32292 pushed++;
32293 }
32294- atomic_inc(&vcc->stats->rx);
32295+ atomic_inc_unchecked(&vcc->stats->rx);
32296 }
32297 wake_up(&eni_dev->rx_wait);
32298 }
32299@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32300 PCI_DMA_TODEVICE);
32301 if (vcc->pop) vcc->pop(vcc,skb);
32302 else dev_kfree_skb_irq(skb);
32303- atomic_inc(&vcc->stats->tx);
32304+ atomic_inc_unchecked(&vcc->stats->tx);
32305 wake_up(&eni_dev->tx_wait);
32306 dma_complete++;
32307 }
32308diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32309index b41c948..a002b17 100644
32310--- a/drivers/atm/firestream.c
32311+++ b/drivers/atm/firestream.c
32312@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32313 }
32314 }
32315
32316- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32317+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32318
32319 fs_dprintk (FS_DEBUG_TXMEM, "i");
32320 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32321@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32322 #endif
32323 skb_put (skb, qe->p1 & 0xffff);
32324 ATM_SKB(skb)->vcc = atm_vcc;
32325- atomic_inc(&atm_vcc->stats->rx);
32326+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32327 __net_timestamp(skb);
32328 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32329 atm_vcc->push (atm_vcc, skb);
32330@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32331 kfree (pe);
32332 }
32333 if (atm_vcc)
32334- atomic_inc(&atm_vcc->stats->rx_drop);
32335+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32336 break;
32337 case 0x1f: /* Reassembly abort: no buffers. */
32338 /* Silently increment error counter. */
32339 if (atm_vcc)
32340- atomic_inc(&atm_vcc->stats->rx_drop);
32341+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32342 break;
32343 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32344 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32345diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32346index 204814e..cede831 100644
32347--- a/drivers/atm/fore200e.c
32348+++ b/drivers/atm/fore200e.c
32349@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32350 #endif
32351 /* check error condition */
32352 if (*entry->status & STATUS_ERROR)
32353- atomic_inc(&vcc->stats->tx_err);
32354+ atomic_inc_unchecked(&vcc->stats->tx_err);
32355 else
32356- atomic_inc(&vcc->stats->tx);
32357+ atomic_inc_unchecked(&vcc->stats->tx);
32358 }
32359 }
32360
32361@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32362 if (skb == NULL) {
32363 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32364
32365- atomic_inc(&vcc->stats->rx_drop);
32366+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32367 return -ENOMEM;
32368 }
32369
32370@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32371
32372 dev_kfree_skb_any(skb);
32373
32374- atomic_inc(&vcc->stats->rx_drop);
32375+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32376 return -ENOMEM;
32377 }
32378
32379 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32380
32381 vcc->push(vcc, skb);
32382- atomic_inc(&vcc->stats->rx);
32383+ atomic_inc_unchecked(&vcc->stats->rx);
32384
32385 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32386
32387@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32388 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32389 fore200e->atm_dev->number,
32390 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32391- atomic_inc(&vcc->stats->rx_err);
32392+ atomic_inc_unchecked(&vcc->stats->rx_err);
32393 }
32394 }
32395
32396@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32397 goto retry_here;
32398 }
32399
32400- atomic_inc(&vcc->stats->tx_err);
32401+ atomic_inc_unchecked(&vcc->stats->tx_err);
32402
32403 fore200e->tx_sat++;
32404 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32405diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32406index 507362a..a845e57 100644
32407--- a/drivers/atm/he.c
32408+++ b/drivers/atm/he.c
32409@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32410
32411 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32412 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32413- atomic_inc(&vcc->stats->rx_drop);
32414+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32415 goto return_host_buffers;
32416 }
32417
32418@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32419 RBRQ_LEN_ERR(he_dev->rbrq_head)
32420 ? "LEN_ERR" : "",
32421 vcc->vpi, vcc->vci);
32422- atomic_inc(&vcc->stats->rx_err);
32423+ atomic_inc_unchecked(&vcc->stats->rx_err);
32424 goto return_host_buffers;
32425 }
32426
32427@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32428 vcc->push(vcc, skb);
32429 spin_lock(&he_dev->global_lock);
32430
32431- atomic_inc(&vcc->stats->rx);
32432+ atomic_inc_unchecked(&vcc->stats->rx);
32433
32434 return_host_buffers:
32435 ++pdus_assembled;
32436@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32437 tpd->vcc->pop(tpd->vcc, tpd->skb);
32438 else
32439 dev_kfree_skb_any(tpd->skb);
32440- atomic_inc(&tpd->vcc->stats->tx_err);
32441+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32442 }
32443 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32444 return;
32445@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32446 vcc->pop(vcc, skb);
32447 else
32448 dev_kfree_skb_any(skb);
32449- atomic_inc(&vcc->stats->tx_err);
32450+ atomic_inc_unchecked(&vcc->stats->tx_err);
32451 return -EINVAL;
32452 }
32453
32454@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32455 vcc->pop(vcc, skb);
32456 else
32457 dev_kfree_skb_any(skb);
32458- atomic_inc(&vcc->stats->tx_err);
32459+ atomic_inc_unchecked(&vcc->stats->tx_err);
32460 return -EINVAL;
32461 }
32462 #endif
32463@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32464 vcc->pop(vcc, skb);
32465 else
32466 dev_kfree_skb_any(skb);
32467- atomic_inc(&vcc->stats->tx_err);
32468+ atomic_inc_unchecked(&vcc->stats->tx_err);
32469 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32470 return -ENOMEM;
32471 }
32472@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32473 vcc->pop(vcc, skb);
32474 else
32475 dev_kfree_skb_any(skb);
32476- atomic_inc(&vcc->stats->tx_err);
32477+ atomic_inc_unchecked(&vcc->stats->tx_err);
32478 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32479 return -ENOMEM;
32480 }
32481@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32482 __enqueue_tpd(he_dev, tpd, cid);
32483 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32484
32485- atomic_inc(&vcc->stats->tx);
32486+ atomic_inc_unchecked(&vcc->stats->tx);
32487
32488 return 0;
32489 }
32490diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32491index 1dc0519..1aadaf7 100644
32492--- a/drivers/atm/horizon.c
32493+++ b/drivers/atm/horizon.c
32494@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32495 {
32496 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32497 // VC layer stats
32498- atomic_inc(&vcc->stats->rx);
32499+ atomic_inc_unchecked(&vcc->stats->rx);
32500 __net_timestamp(skb);
32501 // end of our responsibility
32502 vcc->push (vcc, skb);
32503@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32504 dev->tx_iovec = NULL;
32505
32506 // VC layer stats
32507- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32508+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32509
32510 // free the skb
32511 hrz_kfree_skb (skb);
32512diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32513index 272f009..a18ba55 100644
32514--- a/drivers/atm/idt77252.c
32515+++ b/drivers/atm/idt77252.c
32516@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32517 else
32518 dev_kfree_skb(skb);
32519
32520- atomic_inc(&vcc->stats->tx);
32521+ atomic_inc_unchecked(&vcc->stats->tx);
32522 }
32523
32524 atomic_dec(&scq->used);
32525@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32526 if ((sb = dev_alloc_skb(64)) == NULL) {
32527 printk("%s: Can't allocate buffers for aal0.\n",
32528 card->name);
32529- atomic_add(i, &vcc->stats->rx_drop);
32530+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32531 break;
32532 }
32533 if (!atm_charge(vcc, sb->truesize)) {
32534 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32535 card->name);
32536- atomic_add(i - 1, &vcc->stats->rx_drop);
32537+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32538 dev_kfree_skb(sb);
32539 break;
32540 }
32541@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32542 ATM_SKB(sb)->vcc = vcc;
32543 __net_timestamp(sb);
32544 vcc->push(vcc, sb);
32545- atomic_inc(&vcc->stats->rx);
32546+ atomic_inc_unchecked(&vcc->stats->rx);
32547
32548 cell += ATM_CELL_PAYLOAD;
32549 }
32550@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32551 "(CDC: %08x)\n",
32552 card->name, len, rpp->len, readl(SAR_REG_CDC));
32553 recycle_rx_pool_skb(card, rpp);
32554- atomic_inc(&vcc->stats->rx_err);
32555+ atomic_inc_unchecked(&vcc->stats->rx_err);
32556 return;
32557 }
32558 if (stat & SAR_RSQE_CRC) {
32559 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32560 recycle_rx_pool_skb(card, rpp);
32561- atomic_inc(&vcc->stats->rx_err);
32562+ atomic_inc_unchecked(&vcc->stats->rx_err);
32563 return;
32564 }
32565 if (skb_queue_len(&rpp->queue) > 1) {
32566@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32567 RXPRINTK("%s: Can't alloc RX skb.\n",
32568 card->name);
32569 recycle_rx_pool_skb(card, rpp);
32570- atomic_inc(&vcc->stats->rx_err);
32571+ atomic_inc_unchecked(&vcc->stats->rx_err);
32572 return;
32573 }
32574 if (!atm_charge(vcc, skb->truesize)) {
32575@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32576 __net_timestamp(skb);
32577
32578 vcc->push(vcc, skb);
32579- atomic_inc(&vcc->stats->rx);
32580+ atomic_inc_unchecked(&vcc->stats->rx);
32581
32582 return;
32583 }
32584@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32585 __net_timestamp(skb);
32586
32587 vcc->push(vcc, skb);
32588- atomic_inc(&vcc->stats->rx);
32589+ atomic_inc_unchecked(&vcc->stats->rx);
32590
32591 if (skb->truesize > SAR_FB_SIZE_3)
32592 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32593@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32594 if (vcc->qos.aal != ATM_AAL0) {
32595 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32596 card->name, vpi, vci);
32597- atomic_inc(&vcc->stats->rx_drop);
32598+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32599 goto drop;
32600 }
32601
32602 if ((sb = dev_alloc_skb(64)) == NULL) {
32603 printk("%s: Can't allocate buffers for AAL0.\n",
32604 card->name);
32605- atomic_inc(&vcc->stats->rx_err);
32606+ atomic_inc_unchecked(&vcc->stats->rx_err);
32607 goto drop;
32608 }
32609
32610@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32611 ATM_SKB(sb)->vcc = vcc;
32612 __net_timestamp(sb);
32613 vcc->push(vcc, sb);
32614- atomic_inc(&vcc->stats->rx);
32615+ atomic_inc_unchecked(&vcc->stats->rx);
32616
32617 drop:
32618 skb_pull(queue, 64);
32619@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32620
32621 if (vc == NULL) {
32622 printk("%s: NULL connection in send().\n", card->name);
32623- atomic_inc(&vcc->stats->tx_err);
32624+ atomic_inc_unchecked(&vcc->stats->tx_err);
32625 dev_kfree_skb(skb);
32626 return -EINVAL;
32627 }
32628 if (!test_bit(VCF_TX, &vc->flags)) {
32629 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32630- atomic_inc(&vcc->stats->tx_err);
32631+ atomic_inc_unchecked(&vcc->stats->tx_err);
32632 dev_kfree_skb(skb);
32633 return -EINVAL;
32634 }
32635@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32636 break;
32637 default:
32638 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32639- atomic_inc(&vcc->stats->tx_err);
32640+ atomic_inc_unchecked(&vcc->stats->tx_err);
32641 dev_kfree_skb(skb);
32642 return -EINVAL;
32643 }
32644
32645 if (skb_shinfo(skb)->nr_frags != 0) {
32646 printk("%s: No scatter-gather yet.\n", card->name);
32647- atomic_inc(&vcc->stats->tx_err);
32648+ atomic_inc_unchecked(&vcc->stats->tx_err);
32649 dev_kfree_skb(skb);
32650 return -EINVAL;
32651 }
32652@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32653
32654 err = queue_skb(card, vc, skb, oam);
32655 if (err) {
32656- atomic_inc(&vcc->stats->tx_err);
32657+ atomic_inc_unchecked(&vcc->stats->tx_err);
32658 dev_kfree_skb(skb);
32659 return err;
32660 }
32661@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32662 skb = dev_alloc_skb(64);
32663 if (!skb) {
32664 printk("%s: Out of memory in send_oam().\n", card->name);
32665- atomic_inc(&vcc->stats->tx_err);
32666+ atomic_inc_unchecked(&vcc->stats->tx_err);
32667 return -ENOMEM;
32668 }
32669 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32670diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32671index 4217f29..88f547a 100644
32672--- a/drivers/atm/iphase.c
32673+++ b/drivers/atm/iphase.c
32674@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32675 status = (u_short) (buf_desc_ptr->desc_mode);
32676 if (status & (RX_CER | RX_PTE | RX_OFL))
32677 {
32678- atomic_inc(&vcc->stats->rx_err);
32679+ atomic_inc_unchecked(&vcc->stats->rx_err);
32680 IF_ERR(printk("IA: bad packet, dropping it");)
32681 if (status & RX_CER) {
32682 IF_ERR(printk(" cause: packet CRC error\n");)
32683@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32684 len = dma_addr - buf_addr;
32685 if (len > iadev->rx_buf_sz) {
32686 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32687- atomic_inc(&vcc->stats->rx_err);
32688+ atomic_inc_unchecked(&vcc->stats->rx_err);
32689 goto out_free_desc;
32690 }
32691
32692@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32693 ia_vcc = INPH_IA_VCC(vcc);
32694 if (ia_vcc == NULL)
32695 {
32696- atomic_inc(&vcc->stats->rx_err);
32697+ atomic_inc_unchecked(&vcc->stats->rx_err);
32698 atm_return(vcc, skb->truesize);
32699 dev_kfree_skb_any(skb);
32700 goto INCR_DLE;
32701@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32702 if ((length > iadev->rx_buf_sz) || (length >
32703 (skb->len - sizeof(struct cpcs_trailer))))
32704 {
32705- atomic_inc(&vcc->stats->rx_err);
32706+ atomic_inc_unchecked(&vcc->stats->rx_err);
32707 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32708 length, skb->len);)
32709 atm_return(vcc, skb->truesize);
32710@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32711
32712 IF_RX(printk("rx_dle_intr: skb push");)
32713 vcc->push(vcc,skb);
32714- atomic_inc(&vcc->stats->rx);
32715+ atomic_inc_unchecked(&vcc->stats->rx);
32716 iadev->rx_pkt_cnt++;
32717 }
32718 INCR_DLE:
32719@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32720 {
32721 struct k_sonet_stats *stats;
32722 stats = &PRIV(_ia_dev[board])->sonet_stats;
32723- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32724- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32725- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32726- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32727- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32728- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32729- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32730- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32731- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32732+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32733+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32734+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32735+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32736+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32737+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32738+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32739+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32740+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32741 }
32742 ia_cmds.status = 0;
32743 break;
32744@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32745 if ((desc == 0) || (desc > iadev->num_tx_desc))
32746 {
32747 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32748- atomic_inc(&vcc->stats->tx);
32749+ atomic_inc_unchecked(&vcc->stats->tx);
32750 if (vcc->pop)
32751 vcc->pop(vcc, skb);
32752 else
32753@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32754 ATM_DESC(skb) = vcc->vci;
32755 skb_queue_tail(&iadev->tx_dma_q, skb);
32756
32757- atomic_inc(&vcc->stats->tx);
32758+ atomic_inc_unchecked(&vcc->stats->tx);
32759 iadev->tx_pkt_cnt++;
32760 /* Increment transaction counter */
32761 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32762
32763 #if 0
32764 /* add flow control logic */
32765- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32766+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32767 if (iavcc->vc_desc_cnt > 10) {
32768 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32769 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32770diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32771index fa7d701..1e404c7 100644
32772--- a/drivers/atm/lanai.c
32773+++ b/drivers/atm/lanai.c
32774@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32775 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32776 lanai_endtx(lanai, lvcc);
32777 lanai_free_skb(lvcc->tx.atmvcc, skb);
32778- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32779+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32780 }
32781
32782 /* Try to fill the buffer - don't call unless there is backlog */
32783@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32784 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32785 __net_timestamp(skb);
32786 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32787- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32788+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32789 out:
32790 lvcc->rx.buf.ptr = end;
32791 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32792@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32793 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32794 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32795 lanai->stats.service_rxnotaal5++;
32796- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32797+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32798 return 0;
32799 }
32800 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32801@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32802 int bytes;
32803 read_unlock(&vcc_sklist_lock);
32804 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32805- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32806+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32807 lvcc->stats.x.aal5.service_trash++;
32808 bytes = (SERVICE_GET_END(s) * 16) -
32809 (((unsigned long) lvcc->rx.buf.ptr) -
32810@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32811 }
32812 if (s & SERVICE_STREAM) {
32813 read_unlock(&vcc_sklist_lock);
32814- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32815+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32816 lvcc->stats.x.aal5.service_stream++;
32817 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32818 "PDU on VCI %d!\n", lanai->number, vci);
32819@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32820 return 0;
32821 }
32822 DPRINTK("got rx crc error on vci %d\n", vci);
32823- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32824+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32825 lvcc->stats.x.aal5.service_rxcrc++;
32826 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32827 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32828diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32829index 6587dc2..149833d 100644
32830--- a/drivers/atm/nicstar.c
32831+++ b/drivers/atm/nicstar.c
32832@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32833 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32834 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32835 card->index);
32836- atomic_inc(&vcc->stats->tx_err);
32837+ atomic_inc_unchecked(&vcc->stats->tx_err);
32838 dev_kfree_skb_any(skb);
32839 return -EINVAL;
32840 }
32841@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32842 if (!vc->tx) {
32843 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32844 card->index);
32845- atomic_inc(&vcc->stats->tx_err);
32846+ atomic_inc_unchecked(&vcc->stats->tx_err);
32847 dev_kfree_skb_any(skb);
32848 return -EINVAL;
32849 }
32850@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32851 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32852 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32853 card->index);
32854- atomic_inc(&vcc->stats->tx_err);
32855+ atomic_inc_unchecked(&vcc->stats->tx_err);
32856 dev_kfree_skb_any(skb);
32857 return -EINVAL;
32858 }
32859
32860 if (skb_shinfo(skb)->nr_frags != 0) {
32861 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32862- atomic_inc(&vcc->stats->tx_err);
32863+ atomic_inc_unchecked(&vcc->stats->tx_err);
32864 dev_kfree_skb_any(skb);
32865 return -EINVAL;
32866 }
32867@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32868 }
32869
32870 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32871- atomic_inc(&vcc->stats->tx_err);
32872+ atomic_inc_unchecked(&vcc->stats->tx_err);
32873 dev_kfree_skb_any(skb);
32874 return -EIO;
32875 }
32876- atomic_inc(&vcc->stats->tx);
32877+ atomic_inc_unchecked(&vcc->stats->tx);
32878
32879 return 0;
32880 }
32881@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32882 printk
32883 ("nicstar%d: Can't allocate buffers for aal0.\n",
32884 card->index);
32885- atomic_add(i, &vcc->stats->rx_drop);
32886+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32887 break;
32888 }
32889 if (!atm_charge(vcc, sb->truesize)) {
32890 RXPRINTK
32891 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32892 card->index);
32893- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32894+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32895 dev_kfree_skb_any(sb);
32896 break;
32897 }
32898@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32899 ATM_SKB(sb)->vcc = vcc;
32900 __net_timestamp(sb);
32901 vcc->push(vcc, sb);
32902- atomic_inc(&vcc->stats->rx);
32903+ atomic_inc_unchecked(&vcc->stats->rx);
32904 cell += ATM_CELL_PAYLOAD;
32905 }
32906
32907@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32908 if (iovb == NULL) {
32909 printk("nicstar%d: Out of iovec buffers.\n",
32910 card->index);
32911- atomic_inc(&vcc->stats->rx_drop);
32912+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32913 recycle_rx_buf(card, skb);
32914 return;
32915 }
32916@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32917 small or large buffer itself. */
32918 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32919 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32920- atomic_inc(&vcc->stats->rx_err);
32921+ atomic_inc_unchecked(&vcc->stats->rx_err);
32922 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32923 NS_MAX_IOVECS);
32924 NS_PRV_IOVCNT(iovb) = 0;
32925@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32926 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32927 card->index);
32928 which_list(card, skb);
32929- atomic_inc(&vcc->stats->rx_err);
32930+ atomic_inc_unchecked(&vcc->stats->rx_err);
32931 recycle_rx_buf(card, skb);
32932 vc->rx_iov = NULL;
32933 recycle_iov_buf(card, iovb);
32934@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32935 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32936 card->index);
32937 which_list(card, skb);
32938- atomic_inc(&vcc->stats->rx_err);
32939+ atomic_inc_unchecked(&vcc->stats->rx_err);
32940 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32941 NS_PRV_IOVCNT(iovb));
32942 vc->rx_iov = NULL;
32943@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32944 printk(" - PDU size mismatch.\n");
32945 else
32946 printk(".\n");
32947- atomic_inc(&vcc->stats->rx_err);
32948+ atomic_inc_unchecked(&vcc->stats->rx_err);
32949 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32950 NS_PRV_IOVCNT(iovb));
32951 vc->rx_iov = NULL;
32952@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32953 /* skb points to a small buffer */
32954 if (!atm_charge(vcc, skb->truesize)) {
32955 push_rxbufs(card, skb);
32956- atomic_inc(&vcc->stats->rx_drop);
32957+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32958 } else {
32959 skb_put(skb, len);
32960 dequeue_sm_buf(card, skb);
32961@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32962 ATM_SKB(skb)->vcc = vcc;
32963 __net_timestamp(skb);
32964 vcc->push(vcc, skb);
32965- atomic_inc(&vcc->stats->rx);
32966+ atomic_inc_unchecked(&vcc->stats->rx);
32967 }
32968 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32969 struct sk_buff *sb;
32970@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32971 if (len <= NS_SMBUFSIZE) {
32972 if (!atm_charge(vcc, sb->truesize)) {
32973 push_rxbufs(card, sb);
32974- atomic_inc(&vcc->stats->rx_drop);
32975+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32976 } else {
32977 skb_put(sb, len);
32978 dequeue_sm_buf(card, sb);
32979@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32980 ATM_SKB(sb)->vcc = vcc;
32981 __net_timestamp(sb);
32982 vcc->push(vcc, sb);
32983- atomic_inc(&vcc->stats->rx);
32984+ atomic_inc_unchecked(&vcc->stats->rx);
32985 }
32986
32987 push_rxbufs(card, skb);
32988@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32989
32990 if (!atm_charge(vcc, skb->truesize)) {
32991 push_rxbufs(card, skb);
32992- atomic_inc(&vcc->stats->rx_drop);
32993+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32994 } else {
32995 dequeue_lg_buf(card, skb);
32996 #ifdef NS_USE_DESTRUCTORS
32997@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32998 ATM_SKB(skb)->vcc = vcc;
32999 __net_timestamp(skb);
33000 vcc->push(vcc, skb);
33001- atomic_inc(&vcc->stats->rx);
33002+ atomic_inc_unchecked(&vcc->stats->rx);
33003 }
33004
33005 push_rxbufs(card, sb);
33006@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33007 printk
33008 ("nicstar%d: Out of huge buffers.\n",
33009 card->index);
33010- atomic_inc(&vcc->stats->rx_drop);
33011+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33012 recycle_iovec_rx_bufs(card,
33013 (struct iovec *)
33014 iovb->data,
33015@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33016 card->hbpool.count++;
33017 } else
33018 dev_kfree_skb_any(hb);
33019- atomic_inc(&vcc->stats->rx_drop);
33020+ atomic_inc_unchecked(&vcc->stats->rx_drop);
33021 } else {
33022 /* Copy the small buffer to the huge buffer */
33023 sb = (struct sk_buff *)iov->iov_base;
33024@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
33025 #endif /* NS_USE_DESTRUCTORS */
33026 __net_timestamp(hb);
33027 vcc->push(vcc, hb);
33028- atomic_inc(&vcc->stats->rx);
33029+ atomic_inc_unchecked(&vcc->stats->rx);
33030 }
33031 }
33032
33033diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
33034index 32784d1..4a8434a 100644
33035--- a/drivers/atm/solos-pci.c
33036+++ b/drivers/atm/solos-pci.c
33037@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
33038 }
33039 atm_charge(vcc, skb->truesize);
33040 vcc->push(vcc, skb);
33041- atomic_inc(&vcc->stats->rx);
33042+ atomic_inc_unchecked(&vcc->stats->rx);
33043 break;
33044
33045 case PKT_STATUS:
33046@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33047 vcc = SKB_CB(oldskb)->vcc;
33048
33049 if (vcc) {
33050- atomic_inc(&vcc->stats->tx);
33051+ atomic_inc_unchecked(&vcc->stats->tx);
33052 solos_pop(vcc, oldskb);
33053 } else {
33054 dev_kfree_skb_irq(oldskb);
33055diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33056index 0215934..ce9f5b1 100644
33057--- a/drivers/atm/suni.c
33058+++ b/drivers/atm/suni.c
33059@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33060
33061
33062 #define ADD_LIMITED(s,v) \
33063- atomic_add((v),&stats->s); \
33064- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33065+ atomic_add_unchecked((v),&stats->s); \
33066+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33067
33068
33069 static void suni_hz(unsigned long from_timer)
33070diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33071index 5120a96..e2572bd 100644
33072--- a/drivers/atm/uPD98402.c
33073+++ b/drivers/atm/uPD98402.c
33074@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33075 struct sonet_stats tmp;
33076 int error = 0;
33077
33078- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33079+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33080 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33081 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33082 if (zero && !error) {
33083@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33084
33085
33086 #define ADD_LIMITED(s,v) \
33087- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33088- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33089- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33090+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33091+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33092+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33093
33094
33095 static void stat_event(struct atm_dev *dev)
33096@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33097 if (reason & uPD98402_INT_PFM) stat_event(dev);
33098 if (reason & uPD98402_INT_PCO) {
33099 (void) GET(PCOCR); /* clear interrupt cause */
33100- atomic_add(GET(HECCT),
33101+ atomic_add_unchecked(GET(HECCT),
33102 &PRIV(dev)->sonet_stats.uncorr_hcs);
33103 }
33104 if ((reason & uPD98402_INT_RFO) &&
33105@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33106 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33107 uPD98402_INT_LOS),PIMR); /* enable them */
33108 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33109- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33110- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33111- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33112+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33113+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33114+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33115 return 0;
33116 }
33117
33118diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33119index 969c3c2..9b72956 100644
33120--- a/drivers/atm/zatm.c
33121+++ b/drivers/atm/zatm.c
33122@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33123 }
33124 if (!size) {
33125 dev_kfree_skb_irq(skb);
33126- if (vcc) atomic_inc(&vcc->stats->rx_err);
33127+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33128 continue;
33129 }
33130 if (!atm_charge(vcc,skb->truesize)) {
33131@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33132 skb->len = size;
33133 ATM_SKB(skb)->vcc = vcc;
33134 vcc->push(vcc,skb);
33135- atomic_inc(&vcc->stats->rx);
33136+ atomic_inc_unchecked(&vcc->stats->rx);
33137 }
33138 zout(pos & 0xffff,MTA(mbx));
33139 #if 0 /* probably a stupid idea */
33140@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33141 skb_queue_head(&zatm_vcc->backlog,skb);
33142 break;
33143 }
33144- atomic_inc(&vcc->stats->tx);
33145+ atomic_inc_unchecked(&vcc->stats->tx);
33146 wake_up(&zatm_vcc->tx_wait);
33147 }
33148
33149diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
33150index d78b204..ecc1929 100644
33151--- a/drivers/base/attribute_container.c
33152+++ b/drivers/base/attribute_container.c
33153@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
33154 ic->classdev.parent = get_device(dev);
33155 ic->classdev.class = cont->class;
33156 cont->class->dev_release = attribute_container_release;
33157- dev_set_name(&ic->classdev, dev_name(dev));
33158+ dev_set_name(&ic->classdev, "%s", dev_name(dev));
33159 if (fn)
33160 fn(cont, dev, &ic->classdev);
33161 else
33162diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33163index d414331..b4dd4ba 100644
33164--- a/drivers/base/bus.c
33165+++ b/drivers/base/bus.c
33166@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33167 return -EINVAL;
33168
33169 mutex_lock(&subsys->p->mutex);
33170- list_add_tail(&sif->node, &subsys->p->interfaces);
33171+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33172 if (sif->add_dev) {
33173 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33174 while ((dev = subsys_dev_iter_next(&iter)))
33175@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33176 subsys = sif->subsys;
33177
33178 mutex_lock(&subsys->p->mutex);
33179- list_del_init(&sif->node);
33180+ pax_list_del_init((struct list_head *)&sif->node);
33181 if (sif->remove_dev) {
33182 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33183 while ((dev = subsys_dev_iter_next(&iter)))
33184diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33185index 7413d06..79155fa 100644
33186--- a/drivers/base/devtmpfs.c
33187+++ b/drivers/base/devtmpfs.c
33188@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
33189 if (!thread)
33190 return 0;
33191
33192- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33193+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33194 if (err)
33195 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33196 else
33197@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
33198 *err = sys_unshare(CLONE_NEWNS);
33199 if (*err)
33200 goto out;
33201- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
33202+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
33203 if (*err)
33204 goto out;
33205- sys_chdir("/.."); /* will traverse into overmounted root */
33206- sys_chroot(".");
33207+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
33208+ sys_chroot((char __force_user *)".");
33209 complete(&setup_done);
33210 while (1) {
33211 spin_lock(&req_lock);
33212diff --git a/drivers/base/node.c b/drivers/base/node.c
33213index 7616a77c..8f57f51 100644
33214--- a/drivers/base/node.c
33215+++ b/drivers/base/node.c
33216@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33217 struct node_attr {
33218 struct device_attribute attr;
33219 enum node_states state;
33220-};
33221+} __do_const;
33222
33223 static ssize_t show_node_state(struct device *dev,
33224 struct device_attribute *attr, char *buf)
33225diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33226index 7072404..76dcebd 100644
33227--- a/drivers/base/power/domain.c
33228+++ b/drivers/base/power/domain.c
33229@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33230 {
33231 struct cpuidle_driver *cpuidle_drv;
33232 struct gpd_cpu_data *cpu_data;
33233- struct cpuidle_state *idle_state;
33234+ cpuidle_state_no_const *idle_state;
33235 int ret = 0;
33236
33237 if (IS_ERR_OR_NULL(genpd) || state < 0)
33238@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33239 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33240 {
33241 struct gpd_cpu_data *cpu_data;
33242- struct cpuidle_state *idle_state;
33243+ cpuidle_state_no_const *idle_state;
33244 int ret = 0;
33245
33246 if (IS_ERR_OR_NULL(genpd))
33247diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
33248index a53ebd2..8f73eeb 100644
33249--- a/drivers/base/power/sysfs.c
33250+++ b/drivers/base/power/sysfs.c
33251@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
33252 return -EIO;
33253 }
33254 }
33255- return sprintf(buf, p);
33256+ return sprintf(buf, "%s", p);
33257 }
33258
33259 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
33260diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33261index 79715e7..df06b3b 100644
33262--- a/drivers/base/power/wakeup.c
33263+++ b/drivers/base/power/wakeup.c
33264@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33265 * They need to be modified together atomically, so it's better to use one
33266 * atomic variable to hold them both.
33267 */
33268-static atomic_t combined_event_count = ATOMIC_INIT(0);
33269+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33270
33271 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33272 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33273
33274 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33275 {
33276- unsigned int comb = atomic_read(&combined_event_count);
33277+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33278
33279 *cnt = (comb >> IN_PROGRESS_BITS);
33280 *inpr = comb & MAX_IN_PROGRESS;
33281@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33282 ws->start_prevent_time = ws->last_time;
33283
33284 /* Increment the counter of events in progress. */
33285- cec = atomic_inc_return(&combined_event_count);
33286+ cec = atomic_inc_return_unchecked(&combined_event_count);
33287
33288 trace_wakeup_source_activate(ws->name, cec);
33289 }
33290@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33291 * Increment the counter of registered wakeup events and decrement the
33292 * couter of wakeup events in progress simultaneously.
33293 */
33294- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33295+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33296 trace_wakeup_source_deactivate(ws->name, cec);
33297
33298 split_counters(&cnt, &inpr);
33299diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33300index e8d11b6..7b1b36f 100644
33301--- a/drivers/base/syscore.c
33302+++ b/drivers/base/syscore.c
33303@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33304 void register_syscore_ops(struct syscore_ops *ops)
33305 {
33306 mutex_lock(&syscore_ops_lock);
33307- list_add_tail(&ops->node, &syscore_ops_list);
33308+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33309 mutex_unlock(&syscore_ops_lock);
33310 }
33311 EXPORT_SYMBOL_GPL(register_syscore_ops);
33312@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33313 void unregister_syscore_ops(struct syscore_ops *ops)
33314 {
33315 mutex_lock(&syscore_ops_lock);
33316- list_del(&ops->node);
33317+ pax_list_del((struct list_head *)&ops->node);
33318 mutex_unlock(&syscore_ops_lock);
33319 }
33320 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33321diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33322index 62b6c2c..4a11354 100644
33323--- a/drivers/block/cciss.c
33324+++ b/drivers/block/cciss.c
33325@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33326 int err;
33327 u32 cp;
33328
33329+ memset(&arg64, 0, sizeof(arg64));
33330+
33331 err = 0;
33332 err |=
33333 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33334@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
33335 while (!list_empty(&h->reqQ)) {
33336 c = list_entry(h->reqQ.next, CommandList_struct, list);
33337 /* can't do anything if fifo is full */
33338- if ((h->access.fifo_full(h))) {
33339+ if ((h->access->fifo_full(h))) {
33340 dev_warn(&h->pdev->dev, "fifo full\n");
33341 break;
33342 }
33343@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
33344 h->Qdepth--;
33345
33346 /* Tell the controller execute command */
33347- h->access.submit_command(h, c);
33348+ h->access->submit_command(h, c);
33349
33350 /* Put job onto the completed Q */
33351 addQ(&h->cmpQ, c);
33352@@ -3446,17 +3448,17 @@ startio:
33353
33354 static inline unsigned long get_next_completion(ctlr_info_t *h)
33355 {
33356- return h->access.command_completed(h);
33357+ return h->access->command_completed(h);
33358 }
33359
33360 static inline int interrupt_pending(ctlr_info_t *h)
33361 {
33362- return h->access.intr_pending(h);
33363+ return h->access->intr_pending(h);
33364 }
33365
33366 static inline long interrupt_not_for_us(ctlr_info_t *h)
33367 {
33368- return ((h->access.intr_pending(h) == 0) ||
33369+ return ((h->access->intr_pending(h) == 0) ||
33370 (h->interrupts_enabled == 0));
33371 }
33372
33373@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
33374 u32 a;
33375
33376 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33377- return h->access.command_completed(h);
33378+ return h->access->command_completed(h);
33379
33380 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33381 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33382@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33383 trans_support & CFGTBL_Trans_use_short_tags);
33384
33385 /* Change the access methods to the performant access methods */
33386- h->access = SA5_performant_access;
33387+ h->access = &SA5_performant_access;
33388 h->transMethod = CFGTBL_Trans_Performant;
33389
33390 return;
33391@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33392 if (prod_index < 0)
33393 return -ENODEV;
33394 h->product_name = products[prod_index].product_name;
33395- h->access = *(products[prod_index].access);
33396+ h->access = products[prod_index].access;
33397
33398 if (cciss_board_disabled(h)) {
33399 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33400@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
33401 }
33402
33403 /* make sure the board interrupts are off */
33404- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33405+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33406 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33407 if (rc)
33408 goto clean2;
33409@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
33410 * fake ones to scoop up any residual completions.
33411 */
33412 spin_lock_irqsave(&h->lock, flags);
33413- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33414+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33415 spin_unlock_irqrestore(&h->lock, flags);
33416 free_irq(h->intr[h->intr_mode], h);
33417 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33418@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
33419 dev_info(&h->pdev->dev, "Board READY.\n");
33420 dev_info(&h->pdev->dev,
33421 "Waiting for stale completions to drain.\n");
33422- h->access.set_intr_mask(h, CCISS_INTR_ON);
33423+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33424 msleep(10000);
33425- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33426+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33427
33428 rc = controller_reset_failed(h->cfgtable);
33429 if (rc)
33430@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
33431 cciss_scsi_setup(h);
33432
33433 /* Turn the interrupts on so we can service requests */
33434- h->access.set_intr_mask(h, CCISS_INTR_ON);
33435+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33436
33437 /* Get the firmware version */
33438 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33439@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33440 kfree(flush_buf);
33441 if (return_code != IO_OK)
33442 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33443- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33444+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33445 free_irq(h->intr[h->intr_mode], h);
33446 }
33447
33448diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33449index 7fda30e..eb5dfe0 100644
33450--- a/drivers/block/cciss.h
33451+++ b/drivers/block/cciss.h
33452@@ -101,7 +101,7 @@ struct ctlr_info
33453 /* information about each logical volume */
33454 drive_info_struct *drv[CISS_MAX_LUN];
33455
33456- struct access_method access;
33457+ struct access_method *access;
33458
33459 /* queue and queue Info */
33460 struct list_head reqQ;
33461diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33462index 639d26b..fd6ad1f 100644
33463--- a/drivers/block/cpqarray.c
33464+++ b/drivers/block/cpqarray.c
33465@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33466 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33467 goto Enomem4;
33468 }
33469- hba[i]->access.set_intr_mask(hba[i], 0);
33470+ hba[i]->access->set_intr_mask(hba[i], 0);
33471 if (request_irq(hba[i]->intr, do_ida_intr,
33472 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33473 {
33474@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33475 add_timer(&hba[i]->timer);
33476
33477 /* Enable IRQ now that spinlock and rate limit timer are set up */
33478- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33479+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33480
33481 for(j=0; j<NWD; j++) {
33482 struct gendisk *disk = ida_gendisk[i][j];
33483@@ -694,7 +694,7 @@ DBGINFO(
33484 for(i=0; i<NR_PRODUCTS; i++) {
33485 if (board_id == products[i].board_id) {
33486 c->product_name = products[i].product_name;
33487- c->access = *(products[i].access);
33488+ c->access = products[i].access;
33489 break;
33490 }
33491 }
33492@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33493 hba[ctlr]->intr = intr;
33494 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33495 hba[ctlr]->product_name = products[j].product_name;
33496- hba[ctlr]->access = *(products[j].access);
33497+ hba[ctlr]->access = products[j].access;
33498 hba[ctlr]->ctlr = ctlr;
33499 hba[ctlr]->board_id = board_id;
33500 hba[ctlr]->pci_dev = NULL; /* not PCI */
33501@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
33502
33503 while((c = h->reqQ) != NULL) {
33504 /* Can't do anything if we're busy */
33505- if (h->access.fifo_full(h) == 0)
33506+ if (h->access->fifo_full(h) == 0)
33507 return;
33508
33509 /* Get the first entry from the request Q */
33510@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
33511 h->Qdepth--;
33512
33513 /* Tell the controller to do our bidding */
33514- h->access.submit_command(h, c);
33515+ h->access->submit_command(h, c);
33516
33517 /* Get onto the completion Q */
33518 addQ(&h->cmpQ, c);
33519@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33520 unsigned long flags;
33521 __u32 a,a1;
33522
33523- istat = h->access.intr_pending(h);
33524+ istat = h->access->intr_pending(h);
33525 /* Is this interrupt for us? */
33526 if (istat == 0)
33527 return IRQ_NONE;
33528@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33529 */
33530 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33531 if (istat & FIFO_NOT_EMPTY) {
33532- while((a = h->access.command_completed(h))) {
33533+ while((a = h->access->command_completed(h))) {
33534 a1 = a; a &= ~3;
33535 if ((c = h->cmpQ) == NULL)
33536 {
33537@@ -1193,6 +1193,7 @@ out_passthru:
33538 ida_pci_info_struct pciinfo;
33539
33540 if (!arg) return -EINVAL;
33541+ memset(&pciinfo, 0, sizeof(pciinfo));
33542 pciinfo.bus = host->pci_dev->bus->number;
33543 pciinfo.dev_fn = host->pci_dev->devfn;
33544 pciinfo.board_id = host->board_id;
33545@@ -1447,11 +1448,11 @@ static int sendcmd(
33546 /*
33547 * Disable interrupt
33548 */
33549- info_p->access.set_intr_mask(info_p, 0);
33550+ info_p->access->set_intr_mask(info_p, 0);
33551 /* Make sure there is room in the command FIFO */
33552 /* Actually it should be completely empty at this time. */
33553 for (i = 200000; i > 0; i--) {
33554- temp = info_p->access.fifo_full(info_p);
33555+ temp = info_p->access->fifo_full(info_p);
33556 if (temp != 0) {
33557 break;
33558 }
33559@@ -1464,7 +1465,7 @@ DBG(
33560 /*
33561 * Send the cmd
33562 */
33563- info_p->access.submit_command(info_p, c);
33564+ info_p->access->submit_command(info_p, c);
33565 complete = pollcomplete(ctlr);
33566
33567 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33568@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33569 * we check the new geometry. Then turn interrupts back on when
33570 * we're done.
33571 */
33572- host->access.set_intr_mask(host, 0);
33573+ host->access->set_intr_mask(host, 0);
33574 getgeometry(ctlr);
33575- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33576+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33577
33578 for(i=0; i<NWD; i++) {
33579 struct gendisk *disk = ida_gendisk[ctlr][i];
33580@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
33581 /* Wait (up to 2 seconds) for a command to complete */
33582
33583 for (i = 200000; i > 0; i--) {
33584- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33585+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33586 if (done == 0) {
33587 udelay(10); /* a short fixed delay */
33588 } else
33589diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33590index be73e9d..7fbf140 100644
33591--- a/drivers/block/cpqarray.h
33592+++ b/drivers/block/cpqarray.h
33593@@ -99,7 +99,7 @@ struct ctlr_info {
33594 drv_info_t drv[NWD];
33595 struct proc_dir_entry *proc;
33596
33597- struct access_method access;
33598+ struct access_method *access;
33599
33600 cmdlist_t *reqQ;
33601 cmdlist_t *cmpQ;
33602diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33603index f943aac..99bfd19 100644
33604--- a/drivers/block/drbd/drbd_int.h
33605+++ b/drivers/block/drbd/drbd_int.h
33606@@ -582,7 +582,7 @@ struct drbd_epoch {
33607 struct drbd_tconn *tconn;
33608 struct list_head list;
33609 unsigned int barrier_nr;
33610- atomic_t epoch_size; /* increased on every request added. */
33611+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33612 atomic_t active; /* increased on every req. added, and dec on every finished. */
33613 unsigned long flags;
33614 };
33615@@ -1021,7 +1021,7 @@ struct drbd_conf {
33616 unsigned int al_tr_number;
33617 int al_tr_cycle;
33618 wait_queue_head_t seq_wait;
33619- atomic_t packet_seq;
33620+ atomic_unchecked_t packet_seq;
33621 unsigned int peer_seq;
33622 spinlock_t peer_seq_lock;
33623 unsigned int minor;
33624@@ -1562,7 +1562,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33625 char __user *uoptval;
33626 int err;
33627
33628- uoptval = (char __user __force *)optval;
33629+ uoptval = (char __force_user *)optval;
33630
33631 set_fs(KERNEL_DS);
33632 if (level == SOL_SOCKET)
33633diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33634index a5dca6a..bb27967 100644
33635--- a/drivers/block/drbd/drbd_main.c
33636+++ b/drivers/block/drbd/drbd_main.c
33637@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33638 p->sector = sector;
33639 p->block_id = block_id;
33640 p->blksize = blksize;
33641- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33642+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33643 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33644 }
33645
33646@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33647 return -EIO;
33648 p->sector = cpu_to_be64(req->i.sector);
33649 p->block_id = (unsigned long)req;
33650- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33651+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33652 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33653 if (mdev->state.conn >= C_SYNC_SOURCE &&
33654 mdev->state.conn <= C_PAUSED_SYNC_T)
33655@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33656 {
33657 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33658
33659- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33660- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33661+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33662+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33663 kfree(tconn->current_epoch);
33664
33665 idr_destroy(&tconn->volumes);
33666diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33667index 4222aff..1f79506 100644
33668--- a/drivers/block/drbd/drbd_receiver.c
33669+++ b/drivers/block/drbd/drbd_receiver.c
33670@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
33671 {
33672 int err;
33673
33674- atomic_set(&mdev->packet_seq, 0);
33675+ atomic_set_unchecked(&mdev->packet_seq, 0);
33676 mdev->peer_seq = 0;
33677
33678 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33679@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33680 do {
33681 next_epoch = NULL;
33682
33683- epoch_size = atomic_read(&epoch->epoch_size);
33684+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33685
33686 switch (ev & ~EV_CLEANUP) {
33687 case EV_PUT:
33688@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33689 rv = FE_DESTROYED;
33690 } else {
33691 epoch->flags = 0;
33692- atomic_set(&epoch->epoch_size, 0);
33693+ atomic_set_unchecked(&epoch->epoch_size, 0);
33694 /* atomic_set(&epoch->active, 0); is already zero */
33695 if (rv == FE_STILL_LIVE)
33696 rv = FE_RECYCLED;
33697@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33698 conn_wait_active_ee_empty(tconn);
33699 drbd_flush(tconn);
33700
33701- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33702+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33703 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33704 if (epoch)
33705 break;
33706@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33707 }
33708
33709 epoch->flags = 0;
33710- atomic_set(&epoch->epoch_size, 0);
33711+ atomic_set_unchecked(&epoch->epoch_size, 0);
33712 atomic_set(&epoch->active, 0);
33713
33714 spin_lock(&tconn->epoch_lock);
33715- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33716+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33717 list_add(&epoch->list, &tconn->current_epoch->list);
33718 tconn->current_epoch = epoch;
33719 tconn->epochs++;
33720@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33721
33722 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33723 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33724- atomic_inc(&tconn->current_epoch->epoch_size);
33725+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33726 err2 = drbd_drain_block(mdev, pi->size);
33727 if (!err)
33728 err = err2;
33729@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33730
33731 spin_lock(&tconn->epoch_lock);
33732 peer_req->epoch = tconn->current_epoch;
33733- atomic_inc(&peer_req->epoch->epoch_size);
33734+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33735 atomic_inc(&peer_req->epoch->active);
33736 spin_unlock(&tconn->epoch_lock);
33737
33738@@ -4347,7 +4347,7 @@ struct data_cmd {
33739 int expect_payload;
33740 size_t pkt_size;
33741 int (*fn)(struct drbd_tconn *, struct packet_info *);
33742-};
33743+} __do_const;
33744
33745 static struct data_cmd drbd_cmd_handler[] = {
33746 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33747@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33748 if (!list_empty(&tconn->current_epoch->list))
33749 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33750 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33751- atomic_set(&tconn->current_epoch->epoch_size, 0);
33752+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33753 tconn->send.seen_any_write_yet = false;
33754
33755 conn_info(tconn, "Connection closed\n");
33756@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33757 struct asender_cmd {
33758 size_t pkt_size;
33759 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33760-};
33761+} __do_const;
33762
33763 static struct asender_cmd asender_tbl[] = {
33764 [P_PING] = { 0, got_Ping },
33765diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33766index d92d50f..a7e9d97 100644
33767--- a/drivers/block/loop.c
33768+++ b/drivers/block/loop.c
33769@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
33770
33771 file_start_write(file);
33772 set_fs(get_ds());
33773- bw = file->f_op->write(file, buf, len, &pos);
33774+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33775 set_fs(old_fs);
33776 file_end_write(file);
33777 if (likely(bw == len))
33778diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33779index f5d0ea1..c62380a 100644
33780--- a/drivers/block/pktcdvd.c
33781+++ b/drivers/block/pktcdvd.c
33782@@ -84,7 +84,7 @@
33783 #define MAX_SPEED 0xffff
33784
33785 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
33786- ~(sector_t)((pd)->settings.size - 1))
33787+ ~(sector_t)((pd)->settings.size - 1UL))
33788
33789 static DEFINE_MUTEX(pktcdvd_mutex);
33790 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33791diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33792index 8a3aff7..d7538c2 100644
33793--- a/drivers/cdrom/cdrom.c
33794+++ b/drivers/cdrom/cdrom.c
33795@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33796 ENSURE(reset, CDC_RESET);
33797 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33798 cdi->mc_flags = 0;
33799- cdo->n_minors = 0;
33800 cdi->options = CDO_USE_FFLAGS;
33801
33802 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33803@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33804 else
33805 cdi->cdda_method = CDDA_OLD;
33806
33807- if (!cdo->generic_packet)
33808- cdo->generic_packet = cdrom_dummy_generic_packet;
33809+ if (!cdo->generic_packet) {
33810+ pax_open_kernel();
33811+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33812+ pax_close_kernel();
33813+ }
33814
33815 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33816 mutex_lock(&cdrom_mutex);
33817@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33818 if (cdi->exit)
33819 cdi->exit(cdi);
33820
33821- cdi->ops->n_minors--;
33822 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33823 }
33824
33825@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
33826 */
33827 nr = nframes;
33828 do {
33829- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33830+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33831 if (cgc.buffer)
33832 break;
33833
33834@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
33835 struct cdrom_device_info *cdi;
33836 int ret;
33837
33838- ret = scnprintf(info + *pos, max_size - *pos, header);
33839+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
33840 if (!ret)
33841 return 1;
33842
33843diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33844index 4afcb65..a68a32d 100644
33845--- a/drivers/cdrom/gdrom.c
33846+++ b/drivers/cdrom/gdrom.c
33847@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33848 .audio_ioctl = gdrom_audio_ioctl,
33849 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33850 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33851- .n_minors = 1,
33852 };
33853
33854 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33855diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33856index 3bb6fa3..34013fb 100644
33857--- a/drivers/char/Kconfig
33858+++ b/drivers/char/Kconfig
33859@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33860
33861 config DEVKMEM
33862 bool "/dev/kmem virtual device support"
33863- default y
33864+ default n
33865+ depends on !GRKERNSEC_KMEM
33866 help
33867 Say Y here if you want to support the /dev/kmem device. The
33868 /dev/kmem device is rarely used, but can be used for certain
33869@@ -582,6 +583,7 @@ config DEVPORT
33870 bool
33871 depends on !M68K
33872 depends on ISA || PCI
33873+ depends on !GRKERNSEC_KMEM
33874 default y
33875
33876 source "drivers/s390/char/Kconfig"
33877diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
33878index a48e05b..6bac831 100644
33879--- a/drivers/char/agp/compat_ioctl.c
33880+++ b/drivers/char/agp/compat_ioctl.c
33881@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
33882 return -ENOMEM;
33883 }
33884
33885- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
33886+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
33887 sizeof(*usegment) * ureserve.seg_count)) {
33888 kfree(usegment);
33889 kfree(ksegment);
33890diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33891index 2e04433..771f2cc 100644
33892--- a/drivers/char/agp/frontend.c
33893+++ b/drivers/char/agp/frontend.c
33894@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33895 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33896 return -EFAULT;
33897
33898- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33899+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33900 return -EFAULT;
33901
33902 client = agp_find_client_by_pid(reserve.pid);
33903@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33904 if (segment == NULL)
33905 return -ENOMEM;
33906
33907- if (copy_from_user(segment, (void __user *) reserve.seg_list,
33908+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
33909 sizeof(struct agp_segment) * reserve.seg_count)) {
33910 kfree(segment);
33911 return -EFAULT;
33912diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33913index 4f94375..413694e 100644
33914--- a/drivers/char/genrtc.c
33915+++ b/drivers/char/genrtc.c
33916@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
33917 switch (cmd) {
33918
33919 case RTC_PLL_GET:
33920+ memset(&pll, 0, sizeof(pll));
33921 if (get_rtc_pll(&pll))
33922 return -EINVAL;
33923 else
33924diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33925index d784650..e8bfd69 100644
33926--- a/drivers/char/hpet.c
33927+++ b/drivers/char/hpet.c
33928@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33929 }
33930
33931 static int
33932-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33933+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33934 struct hpet_info *info)
33935 {
33936 struct hpet_timer __iomem *timer;
33937diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
33938index 86fe45c..c0ea948 100644
33939--- a/drivers/char/hw_random/intel-rng.c
33940+++ b/drivers/char/hw_random/intel-rng.c
33941@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
33942
33943 if (no_fwh_detect)
33944 return -ENODEV;
33945- printk(warning);
33946+ printk("%s", warning);
33947 return -EBUSY;
33948 }
33949
33950diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33951index 4445fa1..7c6de37 100644
33952--- a/drivers/char/ipmi/ipmi_msghandler.c
33953+++ b/drivers/char/ipmi/ipmi_msghandler.c
33954@@ -420,7 +420,7 @@ struct ipmi_smi {
33955 struct proc_dir_entry *proc_dir;
33956 char proc_dir_name[10];
33957
33958- atomic_t stats[IPMI_NUM_STATS];
33959+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33960
33961 /*
33962 * run_to_completion duplicate of smb_info, smi_info
33963@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33964
33965
33966 #define ipmi_inc_stat(intf, stat) \
33967- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33968+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33969 #define ipmi_get_stat(intf, stat) \
33970- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33971+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33972
33973 static int is_lan_addr(struct ipmi_addr *addr)
33974 {
33975@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33976 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33977 init_waitqueue_head(&intf->waitq);
33978 for (i = 0; i < IPMI_NUM_STATS; i++)
33979- atomic_set(&intf->stats[i], 0);
33980+ atomic_set_unchecked(&intf->stats[i], 0);
33981
33982 intf->proc_dir = NULL;
33983
33984diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33985index af4b23f..79806fc 100644
33986--- a/drivers/char/ipmi/ipmi_si_intf.c
33987+++ b/drivers/char/ipmi/ipmi_si_intf.c
33988@@ -275,7 +275,7 @@ struct smi_info {
33989 unsigned char slave_addr;
33990
33991 /* Counters and things for the proc filesystem. */
33992- atomic_t stats[SI_NUM_STATS];
33993+ atomic_unchecked_t stats[SI_NUM_STATS];
33994
33995 struct task_struct *thread;
33996
33997@@ -284,9 +284,9 @@ struct smi_info {
33998 };
33999
34000 #define smi_inc_stat(smi, stat) \
34001- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
34002+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
34003 #define smi_get_stat(smi, stat) \
34004- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
34005+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
34006
34007 #define SI_MAX_PARMS 4
34008
34009@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
34010 atomic_set(&new_smi->req_events, 0);
34011 new_smi->run_to_completion = 0;
34012 for (i = 0; i < SI_NUM_STATS; i++)
34013- atomic_set(&new_smi->stats[i], 0);
34014+ atomic_set_unchecked(&new_smi->stats[i], 0);
34015
34016 new_smi->interrupt_disabled = 1;
34017 atomic_set(&new_smi->stop_operation, 0);
34018diff --git a/drivers/char/mem.c b/drivers/char/mem.c
34019index 1ccbe94..6ad651a 100644
34020--- a/drivers/char/mem.c
34021+++ b/drivers/char/mem.c
34022@@ -18,6 +18,7 @@
34023 #include <linux/raw.h>
34024 #include <linux/tty.h>
34025 #include <linux/capability.h>
34026+#include <linux/security.h>
34027 #include <linux/ptrace.h>
34028 #include <linux/device.h>
34029 #include <linux/highmem.h>
34030@@ -38,6 +39,10 @@
34031
34032 #define DEVPORT_MINOR 4
34033
34034+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34035+extern const struct file_operations grsec_fops;
34036+#endif
34037+
34038 static inline unsigned long size_inside_page(unsigned long start,
34039 unsigned long size)
34040 {
34041@@ -69,9 +74,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34042
34043 while (cursor < to) {
34044 if (!devmem_is_allowed(pfn)) {
34045+#ifdef CONFIG_GRKERNSEC_KMEM
34046+ gr_handle_mem_readwrite(from, to);
34047+#else
34048 printk(KERN_INFO
34049 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34050 current->comm, from, to);
34051+#endif
34052 return 0;
34053 }
34054 cursor += PAGE_SIZE;
34055@@ -79,6 +88,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34056 }
34057 return 1;
34058 }
34059+#elif defined(CONFIG_GRKERNSEC_KMEM)
34060+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34061+{
34062+ return 0;
34063+}
34064 #else
34065 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34066 {
34067@@ -121,6 +135,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34068
34069 while (count > 0) {
34070 unsigned long remaining;
34071+ char *temp;
34072
34073 sz = size_inside_page(p, count);
34074
34075@@ -136,7 +151,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34076 if (!ptr)
34077 return -EFAULT;
34078
34079- remaining = copy_to_user(buf, ptr, sz);
34080+#ifdef CONFIG_PAX_USERCOPY
34081+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34082+ if (!temp) {
34083+ unxlate_dev_mem_ptr(p, ptr);
34084+ return -ENOMEM;
34085+ }
34086+ memcpy(temp, ptr, sz);
34087+#else
34088+ temp = ptr;
34089+#endif
34090+
34091+ remaining = copy_to_user(buf, temp, sz);
34092+
34093+#ifdef CONFIG_PAX_USERCOPY
34094+ kfree(temp);
34095+#endif
34096+
34097 unxlate_dev_mem_ptr(p, ptr);
34098 if (remaining)
34099 return -EFAULT;
34100@@ -379,7 +410,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
34101 else
34102 csize = count;
34103
34104- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
34105+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
34106 if (rc < 0)
34107 return rc;
34108 buf += csize;
34109@@ -399,9 +430,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34110 size_t count, loff_t *ppos)
34111 {
34112 unsigned long p = *ppos;
34113- ssize_t low_count, read, sz;
34114+ ssize_t low_count, read, sz, err = 0;
34115 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34116- int err = 0;
34117
34118 read = 0;
34119 if (p < (unsigned long) high_memory) {
34120@@ -423,6 +453,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34121 }
34122 #endif
34123 while (low_count > 0) {
34124+ char *temp;
34125+
34126 sz = size_inside_page(p, low_count);
34127
34128 /*
34129@@ -432,7 +464,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34130 */
34131 kbuf = xlate_dev_kmem_ptr((char *)p);
34132
34133- if (copy_to_user(buf, kbuf, sz))
34134+#ifdef CONFIG_PAX_USERCOPY
34135+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34136+ if (!temp)
34137+ return -ENOMEM;
34138+ memcpy(temp, kbuf, sz);
34139+#else
34140+ temp = kbuf;
34141+#endif
34142+
34143+ err = copy_to_user(buf, temp, sz);
34144+
34145+#ifdef CONFIG_PAX_USERCOPY
34146+ kfree(temp);
34147+#endif
34148+
34149+ if (err)
34150 return -EFAULT;
34151 buf += sz;
34152 p += sz;
34153@@ -869,6 +916,9 @@ static const struct memdev {
34154 #ifdef CONFIG_CRASH_DUMP
34155 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34156 #endif
34157+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34158+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34159+#endif
34160 };
34161
34162 static int memory_open(struct inode *inode, struct file *filp)
34163@@ -940,7 +990,7 @@ static int __init chr_dev_init(void)
34164 continue;
34165
34166 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
34167- NULL, devlist[minor].name);
34168+ NULL, "%s", devlist[minor].name);
34169 }
34170
34171 return tty_init();
34172diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
34173index c689697..04e6d6a2 100644
34174--- a/drivers/char/mwave/tp3780i.c
34175+++ b/drivers/char/mwave/tp3780i.c
34176@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
34177 PRINTK_2(TRACE_TP3780I,
34178 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
34179
34180+ memset(pAbilities, 0, sizeof(*pAbilities));
34181 /* fill out standard constant fields */
34182 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
34183 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
34184diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34185index 9df78e2..01ba9ae 100644
34186--- a/drivers/char/nvram.c
34187+++ b/drivers/char/nvram.c
34188@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34189
34190 spin_unlock_irq(&rtc_lock);
34191
34192- if (copy_to_user(buf, contents, tmp - contents))
34193+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34194 return -EFAULT;
34195
34196 *ppos = i;
34197diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34198index 5c5cc00..ac9edb7 100644
34199--- a/drivers/char/pcmcia/synclink_cs.c
34200+++ b/drivers/char/pcmcia/synclink_cs.c
34201@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34202
34203 if (debug_level >= DEBUG_LEVEL_INFO)
34204 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34205- __FILE__, __LINE__, info->device_name, port->count);
34206+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
34207
34208- WARN_ON(!port->count);
34209+ WARN_ON(!atomic_read(&port->count));
34210
34211 if (tty_port_close_start(port, tty, filp) == 0)
34212 goto cleanup;
34213@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34214 cleanup:
34215 if (debug_level >= DEBUG_LEVEL_INFO)
34216 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
34217- tty->driver->name, port->count);
34218+ tty->driver->name, atomic_read(&port->count));
34219 }
34220
34221 /* Wait until the transmitter is empty.
34222@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34223
34224 if (debug_level >= DEBUG_LEVEL_INFO)
34225 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34226- __FILE__, __LINE__, tty->driver->name, port->count);
34227+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
34228
34229 /* If port is closing, signal caller to try again */
34230 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34231@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34232 goto cleanup;
34233 }
34234 spin_lock(&port->lock);
34235- port->count++;
34236+ atomic_inc(&port->count);
34237 spin_unlock(&port->lock);
34238 spin_unlock_irqrestore(&info->netlock, flags);
34239
34240- if (port->count == 1) {
34241+ if (atomic_read(&port->count) == 1) {
34242 /* 1st open on this device, init hardware */
34243 retval = startup(info, tty);
34244 if (retval < 0)
34245@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34246 unsigned short new_crctype;
34247
34248 /* return error if TTY interface open */
34249- if (info->port.count)
34250+ if (atomic_read(&info->port.count))
34251 return -EBUSY;
34252
34253 switch (encoding)
34254@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
34255
34256 /* arbitrate between network and tty opens */
34257 spin_lock_irqsave(&info->netlock, flags);
34258- if (info->port.count != 0 || info->netcount != 0) {
34259+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34260 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34261 spin_unlock_irqrestore(&info->netlock, flags);
34262 return -EBUSY;
34263@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34264 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
34265
34266 /* return error if TTY interface open */
34267- if (info->port.count)
34268+ if (atomic_read(&info->port.count))
34269 return -EBUSY;
34270
34271 if (cmd != SIOCWANDEV)
34272diff --git a/drivers/char/random.c b/drivers/char/random.c
34273index 35487e8..dac8bd1 100644
34274--- a/drivers/char/random.c
34275+++ b/drivers/char/random.c
34276@@ -272,8 +272,13 @@
34277 /*
34278 * Configuration information
34279 */
34280+#ifdef CONFIG_GRKERNSEC_RANDNET
34281+#define INPUT_POOL_WORDS 512
34282+#define OUTPUT_POOL_WORDS 128
34283+#else
34284 #define INPUT_POOL_WORDS 128
34285 #define OUTPUT_POOL_WORDS 32
34286+#endif
34287 #define SEC_XFER_SIZE 512
34288 #define EXTRACT_SIZE 10
34289
34290@@ -313,10 +318,17 @@ static struct poolinfo {
34291 int poolwords;
34292 int tap1, tap2, tap3, tap4, tap5;
34293 } poolinfo_table[] = {
34294+#ifdef CONFIG_GRKERNSEC_RANDNET
34295+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34296+ { 512, 411, 308, 208, 104, 1 },
34297+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34298+ { 128, 103, 76, 51, 25, 1 },
34299+#else
34300 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34301 { 128, 103, 76, 51, 25, 1 },
34302 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34303 { 32, 26, 20, 14, 7, 1 },
34304+#endif
34305 #if 0
34306 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34307 { 2048, 1638, 1231, 819, 411, 1 },
34308@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34309 input_rotate += i ? 7 : 14;
34310 }
34311
34312- ACCESS_ONCE(r->input_rotate) = input_rotate;
34313- ACCESS_ONCE(r->add_ptr) = i;
34314+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34315+ ACCESS_ONCE_RW(r->add_ptr) = i;
34316 smp_wmb();
34317
34318 if (out)
34319@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34320
34321 extract_buf(r, tmp);
34322 i = min_t(int, nbytes, EXTRACT_SIZE);
34323- if (copy_to_user(buf, tmp, i)) {
34324+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34325 ret = -EFAULT;
34326 break;
34327 }
34328@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34329 #include <linux/sysctl.h>
34330
34331 static int min_read_thresh = 8, min_write_thresh;
34332-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34333+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34334 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34335 static char sysctl_bootid[16];
34336
34337@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
34338 static int proc_do_uuid(ctl_table *table, int write,
34339 void __user *buffer, size_t *lenp, loff_t *ppos)
34340 {
34341- ctl_table fake_table;
34342+ ctl_table_no_const fake_table;
34343 unsigned char buf[64], tmp_uuid[16], *uuid;
34344
34345 uuid = table->data;
34346diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34347index bf2349db..5456d53 100644
34348--- a/drivers/char/sonypi.c
34349+++ b/drivers/char/sonypi.c
34350@@ -54,6 +54,7 @@
34351
34352 #include <asm/uaccess.h>
34353 #include <asm/io.h>
34354+#include <asm/local.h>
34355
34356 #include <linux/sonypi.h>
34357
34358@@ -490,7 +491,7 @@ static struct sonypi_device {
34359 spinlock_t fifo_lock;
34360 wait_queue_head_t fifo_proc_list;
34361 struct fasync_struct *fifo_async;
34362- int open_count;
34363+ local_t open_count;
34364 int model;
34365 struct input_dev *input_jog_dev;
34366 struct input_dev *input_key_dev;
34367@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34368 static int sonypi_misc_release(struct inode *inode, struct file *file)
34369 {
34370 mutex_lock(&sonypi_device.lock);
34371- sonypi_device.open_count--;
34372+ local_dec(&sonypi_device.open_count);
34373 mutex_unlock(&sonypi_device.lock);
34374 return 0;
34375 }
34376@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34377 {
34378 mutex_lock(&sonypi_device.lock);
34379 /* Flush input queue on first open */
34380- if (!sonypi_device.open_count)
34381+ if (!local_read(&sonypi_device.open_count))
34382 kfifo_reset(&sonypi_device.fifo);
34383- sonypi_device.open_count++;
34384+ local_inc(&sonypi_device.open_count);
34385 mutex_unlock(&sonypi_device.lock);
34386
34387 return 0;
34388diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34389index 64420b3..5c40b56 100644
34390--- a/drivers/char/tpm/tpm_acpi.c
34391+++ b/drivers/char/tpm/tpm_acpi.c
34392@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34393 virt = acpi_os_map_memory(start, len);
34394 if (!virt) {
34395 kfree(log->bios_event_log);
34396+ log->bios_event_log = NULL;
34397 printk("%s: ERROR - Unable to map memory\n", __func__);
34398 return -EIO;
34399 }
34400
34401- memcpy_fromio(log->bios_event_log, virt, len);
34402+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34403
34404 acpi_os_unmap_memory(virt, len);
34405 return 0;
34406diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34407index 84ddc55..1d32f1e 100644
34408--- a/drivers/char/tpm/tpm_eventlog.c
34409+++ b/drivers/char/tpm/tpm_eventlog.c
34410@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34411 event = addr;
34412
34413 if ((event->event_type == 0 && event->event_size == 0) ||
34414- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34415+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34416 return NULL;
34417
34418 return addr;
34419@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34420 return NULL;
34421
34422 if ((event->event_type == 0 && event->event_size == 0) ||
34423- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34424+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34425 return NULL;
34426
34427 (*pos)++;
34428@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34429 int i;
34430
34431 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34432- seq_putc(m, data[i]);
34433+ if (!seq_putc(m, data[i]))
34434+ return -EFAULT;
34435
34436 return 0;
34437 }
34438diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34439index 1b456fe..2510242 100644
34440--- a/drivers/char/virtio_console.c
34441+++ b/drivers/char/virtio_console.c
34442@@ -679,7 +679,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34443 if (to_user) {
34444 ssize_t ret;
34445
34446- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34447+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34448 if (ret)
34449 return -EFAULT;
34450 } else {
34451@@ -778,7 +778,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34452 if (!port_has_data(port) && !port->host_connected)
34453 return 0;
34454
34455- return fill_readbuf(port, ubuf, count, true);
34456+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34457 }
34458
34459 static int wait_port_writable(struct port *port, bool nonblock)
34460diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
34461index a33f46f..a720eed 100644
34462--- a/drivers/clk/clk-composite.c
34463+++ b/drivers/clk/clk-composite.c
34464@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
34465 struct clk *clk;
34466 struct clk_init_data init;
34467 struct clk_composite *composite;
34468- struct clk_ops *clk_composite_ops;
34469+ clk_ops_no_const *clk_composite_ops;
34470
34471 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
34472 if (!composite) {
34473diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
34474index bd11315..7f87098 100644
34475--- a/drivers/clk/socfpga/clk.c
34476+++ b/drivers/clk/socfpga/clk.c
34477@@ -22,6 +22,7 @@
34478 #include <linux/clk-provider.h>
34479 #include <linux/io.h>
34480 #include <linux/of.h>
34481+#include <asm/pgtable.h>
34482
34483 /* Clock Manager offsets */
34484 #define CLKMGR_CTRL 0x0
34485@@ -135,8 +136,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
34486 if (strcmp(clk_name, "main_pll") || strcmp(clk_name, "periph_pll") ||
34487 strcmp(clk_name, "sdram_pll")) {
34488 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
34489- clk_pll_ops.enable = clk_gate_ops.enable;
34490- clk_pll_ops.disable = clk_gate_ops.disable;
34491+ pax_open_kernel();
34492+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
34493+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
34494+ pax_close_kernel();
34495 }
34496
34497 clk = clk_register(NULL, &socfpga_clk->hw.hw);
34498diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
34499index a2b2541..bc1e7ff 100644
34500--- a/drivers/clocksource/arm_arch_timer.c
34501+++ b/drivers/clocksource/arm_arch_timer.c
34502@@ -264,7 +264,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34503 return NOTIFY_OK;
34504 }
34505
34506-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
34507+static struct notifier_block arch_timer_cpu_nb = {
34508 .notifier_call = arch_timer_cpu_notify,
34509 };
34510
34511diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
34512index ade7513..069445f 100644
34513--- a/drivers/clocksource/metag_generic.c
34514+++ b/drivers/clocksource/metag_generic.c
34515@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34516 return NOTIFY_OK;
34517 }
34518
34519-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34520+static struct notifier_block arch_timer_cpu_nb = {
34521 .notifier_call = arch_timer_cpu_notify,
34522 };
34523
34524diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34525index edc089e..bc7c0bc 100644
34526--- a/drivers/cpufreq/acpi-cpufreq.c
34527+++ b/drivers/cpufreq/acpi-cpufreq.c
34528@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34529 return sprintf(buf, "%u\n", boost_enabled);
34530 }
34531
34532-static struct global_attr global_boost = __ATTR(boost, 0644,
34533+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34534 show_global_boost,
34535 store_global_boost);
34536
34537@@ -705,8 +705,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34538 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34539 per_cpu(acfreq_data, cpu) = data;
34540
34541- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34542- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34543+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34544+ pax_open_kernel();
34545+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34546+ pax_close_kernel();
34547+ }
34548
34549 result = acpi_processor_register_performance(data->acpi_data, cpu);
34550 if (result)
34551@@ -832,7 +835,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34552 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34553 break;
34554 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34555- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34556+ pax_open_kernel();
34557+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34558+ pax_close_kernel();
34559 policy->cur = get_cur_freq_on_cpu(cpu);
34560 break;
34561 default:
34562@@ -843,8 +848,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34563 acpi_processor_notify_smm(THIS_MODULE);
34564
34565 /* Check for APERF/MPERF support in hardware */
34566- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34567- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34568+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34569+ pax_open_kernel();
34570+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34571+ pax_close_kernel();
34572+ }
34573
34574 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34575 for (i = 0; i < perf->state_count; i++)
34576diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34577index 178fe7a..5ee8501 100644
34578--- a/drivers/cpufreq/cpufreq.c
34579+++ b/drivers/cpufreq/cpufreq.c
34580@@ -1853,7 +1853,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34581 return NOTIFY_OK;
34582 }
34583
34584-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34585+static struct notifier_block cpufreq_cpu_notifier = {
34586 .notifier_call = cpufreq_cpu_callback,
34587 };
34588
34589@@ -1885,8 +1885,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34590
34591 pr_debug("trying to register driver %s\n", driver_data->name);
34592
34593- if (driver_data->setpolicy)
34594- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34595+ if (driver_data->setpolicy) {
34596+ pax_open_kernel();
34597+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34598+ pax_close_kernel();
34599+ }
34600
34601 write_lock_irqsave(&cpufreq_driver_lock, flags);
34602 if (cpufreq_driver) {
34603diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34604index 5af40ad..ddf907b 100644
34605--- a/drivers/cpufreq/cpufreq_governor.c
34606+++ b/drivers/cpufreq/cpufreq_governor.c
34607@@ -235,7 +235,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34608 struct dbs_data *dbs_data;
34609 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
34610 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
34611- struct od_ops *od_ops = NULL;
34612+ const struct od_ops *od_ops = NULL;
34613 struct od_dbs_tuners *od_tuners = NULL;
34614 struct cs_dbs_tuners *cs_tuners = NULL;
34615 struct cpu_dbs_common_info *cpu_cdbs;
34616@@ -298,7 +298,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34617
34618 if ((cdata->governor == GOV_CONSERVATIVE) &&
34619 (!policy->governor->initialized)) {
34620- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34621+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34622
34623 cpufreq_register_notifier(cs_ops->notifier_block,
34624 CPUFREQ_TRANSITION_NOTIFIER);
34625@@ -315,7 +315,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34626
34627 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
34628 (policy->governor->initialized == 1)) {
34629- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34630+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34631
34632 cpufreq_unregister_notifier(cs_ops->notifier_block,
34633 CPUFREQ_TRANSITION_NOTIFIER);
34634diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34635index e16a961..0e68927 100644
34636--- a/drivers/cpufreq/cpufreq_governor.h
34637+++ b/drivers/cpufreq/cpufreq_governor.h
34638@@ -204,7 +204,7 @@ struct common_dbs_data {
34639 void (*exit)(struct dbs_data *dbs_data);
34640
34641 /* Governor specific ops, see below */
34642- void *gov_ops;
34643+ const void *gov_ops;
34644 };
34645
34646 /* Governer Per policy data */
34647diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
34648index 93eb5cb..f8ab572 100644
34649--- a/drivers/cpufreq/cpufreq_ondemand.c
34650+++ b/drivers/cpufreq/cpufreq_ondemand.c
34651@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
34652 (struct cpufreq_policy *, unsigned int, unsigned int),
34653 unsigned int powersave_bias)
34654 {
34655- od_ops.powersave_bias_target = f;
34656+ pax_open_kernel();
34657+ *(void **)&od_ops.powersave_bias_target = f;
34658+ pax_close_kernel();
34659 od_set_powersave_bias(powersave_bias);
34660 }
34661 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
34662
34663 void od_unregister_powersave_bias_handler(void)
34664 {
34665- od_ops.powersave_bias_target = generic_powersave_bias_target;
34666+ pax_open_kernel();
34667+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
34668+ pax_close_kernel();
34669 od_set_powersave_bias(0);
34670 }
34671 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
34672diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34673index bfd6273..e39dd63 100644
34674--- a/drivers/cpufreq/cpufreq_stats.c
34675+++ b/drivers/cpufreq/cpufreq_stats.c
34676@@ -365,7 +365,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34677 }
34678
34679 /* priority=1 so this will get called before cpufreq_remove_dev */
34680-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34681+static struct notifier_block cpufreq_stat_cpu_notifier = {
34682 .notifier_call = cpufreq_stat_cpu_callback,
34683 .priority = 1,
34684 };
34685diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34686index 421ef37..e708530c 100644
34687--- a/drivers/cpufreq/p4-clockmod.c
34688+++ b/drivers/cpufreq/p4-clockmod.c
34689@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34690 case 0x0F: /* Core Duo */
34691 case 0x16: /* Celeron Core */
34692 case 0x1C: /* Atom */
34693- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34694+ pax_open_kernel();
34695+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34696+ pax_close_kernel();
34697 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34698 case 0x0D: /* Pentium M (Dothan) */
34699- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34700+ pax_open_kernel();
34701+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34702+ pax_close_kernel();
34703 /* fall through */
34704 case 0x09: /* Pentium M (Banias) */
34705 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34706@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34707
34708 /* on P-4s, the TSC runs with constant frequency independent whether
34709 * throttling is active or not. */
34710- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34711+ pax_open_kernel();
34712+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34713+ pax_close_kernel();
34714
34715 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34716 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34717diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
34718index c71ee14..7c2e183 100644
34719--- a/drivers/cpufreq/sparc-us3-cpufreq.c
34720+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
34721@@ -18,14 +18,12 @@
34722 #include <asm/head.h>
34723 #include <asm/timer.h>
34724
34725-static struct cpufreq_driver *cpufreq_us3_driver;
34726-
34727 struct us3_freq_percpu_info {
34728 struct cpufreq_frequency_table table[4];
34729 };
34730
34731 /* Indexed by cpu number. */
34732-static struct us3_freq_percpu_info *us3_freq_table;
34733+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
34734
34735 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
34736 * in the Safari config register.
34737@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
34738
34739 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
34740 {
34741- if (cpufreq_us3_driver)
34742- us3_set_cpu_divider_index(policy, 0);
34743+ us3_set_cpu_divider_index(policy->cpu, 0);
34744
34745 return 0;
34746 }
34747
34748+static int __init us3_freq_init(void);
34749+static void __exit us3_freq_exit(void);
34750+
34751+static struct cpufreq_driver cpufreq_us3_driver = {
34752+ .init = us3_freq_cpu_init,
34753+ .verify = us3_freq_verify,
34754+ .target = us3_freq_target,
34755+ .get = us3_freq_get,
34756+ .exit = us3_freq_cpu_exit,
34757+ .owner = THIS_MODULE,
34758+ .name = "UltraSPARC-III",
34759+
34760+};
34761+
34762 static int __init us3_freq_init(void)
34763 {
34764 unsigned long manuf, impl, ver;
34765@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
34766 (impl == CHEETAH_IMPL ||
34767 impl == CHEETAH_PLUS_IMPL ||
34768 impl == JAGUAR_IMPL ||
34769- impl == PANTHER_IMPL)) {
34770- struct cpufreq_driver *driver;
34771-
34772- ret = -ENOMEM;
34773- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
34774- if (!driver)
34775- goto err_out;
34776-
34777- us3_freq_table = kzalloc(
34778- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
34779- GFP_KERNEL);
34780- if (!us3_freq_table)
34781- goto err_out;
34782-
34783- driver->init = us3_freq_cpu_init;
34784- driver->verify = us3_freq_verify;
34785- driver->target = us3_freq_target;
34786- driver->get = us3_freq_get;
34787- driver->exit = us3_freq_cpu_exit;
34788- driver->owner = THIS_MODULE,
34789- strcpy(driver->name, "UltraSPARC-III");
34790-
34791- cpufreq_us3_driver = driver;
34792- ret = cpufreq_register_driver(driver);
34793- if (ret)
34794- goto err_out;
34795-
34796- return 0;
34797-
34798-err_out:
34799- if (driver) {
34800- kfree(driver);
34801- cpufreq_us3_driver = NULL;
34802- }
34803- kfree(us3_freq_table);
34804- us3_freq_table = NULL;
34805- return ret;
34806- }
34807+ impl == PANTHER_IMPL))
34808+ return cpufreq_register_driver(&cpufreq_us3_driver);
34809
34810 return -ENODEV;
34811 }
34812
34813 static void __exit us3_freq_exit(void)
34814 {
34815- if (cpufreq_us3_driver) {
34816- cpufreq_unregister_driver(cpufreq_us3_driver);
34817- kfree(cpufreq_us3_driver);
34818- cpufreq_us3_driver = NULL;
34819- kfree(us3_freq_table);
34820- us3_freq_table = NULL;
34821- }
34822+ cpufreq_unregister_driver(&cpufreq_us3_driver);
34823 }
34824
34825 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
34826diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34827index 618e6f4..e89d915 100644
34828--- a/drivers/cpufreq/speedstep-centrino.c
34829+++ b/drivers/cpufreq/speedstep-centrino.c
34830@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34831 !cpu_has(cpu, X86_FEATURE_EST))
34832 return -ENODEV;
34833
34834- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34835- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34836+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34837+ pax_open_kernel();
34838+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34839+ pax_close_kernel();
34840+ }
34841
34842 if (policy->cpu != 0)
34843 return -ENODEV;
34844diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34845index c3a93fe..e808f24 100644
34846--- a/drivers/cpuidle/cpuidle.c
34847+++ b/drivers/cpuidle/cpuidle.c
34848@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
34849
34850 static void poll_idle_init(struct cpuidle_driver *drv)
34851 {
34852- struct cpuidle_state *state = &drv->states[0];
34853+ cpuidle_state_no_const *state = &drv->states[0];
34854
34855 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34856 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34857diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34858index ea2f8e7..70ac501 100644
34859--- a/drivers/cpuidle/governor.c
34860+++ b/drivers/cpuidle/governor.c
34861@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34862 mutex_lock(&cpuidle_lock);
34863 if (__cpuidle_find_governor(gov->name) == NULL) {
34864 ret = 0;
34865- list_add_tail(&gov->governor_list, &cpuidle_governors);
34866+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34867 if (!cpuidle_curr_governor ||
34868 cpuidle_curr_governor->rating < gov->rating)
34869 cpuidle_switch_governor(gov);
34870@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34871 new_gov = cpuidle_replace_governor(gov->rating);
34872 cpuidle_switch_governor(new_gov);
34873 }
34874- list_del(&gov->governor_list);
34875+ pax_list_del((struct list_head *)&gov->governor_list);
34876 mutex_unlock(&cpuidle_lock);
34877 }
34878
34879diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34880index 428754a..8bdf9cc 100644
34881--- a/drivers/cpuidle/sysfs.c
34882+++ b/drivers/cpuidle/sysfs.c
34883@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34884 NULL
34885 };
34886
34887-static struct attribute_group cpuidle_attr_group = {
34888+static attribute_group_no_const cpuidle_attr_group = {
34889 .attrs = cpuidle_default_attrs,
34890 .name = "cpuidle",
34891 };
34892diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34893index 3b36797..db0b0c0 100644
34894--- a/drivers/devfreq/devfreq.c
34895+++ b/drivers/devfreq/devfreq.c
34896@@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
34897 GFP_KERNEL);
34898 devfreq->last_stat_updated = jiffies;
34899
34900- dev_set_name(&devfreq->dev, dev_name(dev));
34901+ dev_set_name(&devfreq->dev, "%s", dev_name(dev));
34902 err = device_register(&devfreq->dev);
34903 if (err) {
34904 put_device(&devfreq->dev);
34905@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34906 goto err_out;
34907 }
34908
34909- list_add(&governor->node, &devfreq_governor_list);
34910+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34911
34912 list_for_each_entry(devfreq, &devfreq_list, node) {
34913 int ret = 0;
34914@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34915 }
34916 }
34917
34918- list_del(&governor->node);
34919+ pax_list_del((struct list_head *)&governor->node);
34920 err_out:
34921 mutex_unlock(&devfreq_list_lock);
34922
34923diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34924index b70709b..1d8d02a 100644
34925--- a/drivers/dma/sh/shdma.c
34926+++ b/drivers/dma/sh/shdma.c
34927@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34928 return ret;
34929 }
34930
34931-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34932+static struct notifier_block sh_dmae_nmi_notifier = {
34933 .notifier_call = sh_dmae_nmi_handler,
34934
34935 /* Run before NMI debug handler and KGDB */
34936diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34937index c4d700a..0b57abd 100644
34938--- a/drivers/edac/edac_mc_sysfs.c
34939+++ b/drivers/edac/edac_mc_sysfs.c
34940@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
34941 struct dev_ch_attribute {
34942 struct device_attribute attr;
34943 int channel;
34944-};
34945+} __do_const;
34946
34947 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34948 struct dev_ch_attribute dev_attr_legacy_##_name = \
34949@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
34950 }
34951
34952 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
34953+ pax_open_kernel();
34954 if (mci->get_sdram_scrub_rate) {
34955- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34956- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34957+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34958+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34959 }
34960 if (mci->set_sdram_scrub_rate) {
34961- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34962- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34963+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34964+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34965 }
34966+ pax_close_kernel();
34967 err = device_create_file(&mci->dev,
34968 &dev_attr_sdram_scrub_rate);
34969 if (err) {
34970diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34971index e8658e4..22746d6 100644
34972--- a/drivers/edac/edac_pci_sysfs.c
34973+++ b/drivers/edac/edac_pci_sysfs.c
34974@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34975 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34976 static int edac_pci_poll_msec = 1000; /* one second workq period */
34977
34978-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34979-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34980+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34981+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34982
34983 static struct kobject *edac_pci_top_main_kobj;
34984 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34985@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34986 void *value;
34987 ssize_t(*show) (void *, char *);
34988 ssize_t(*store) (void *, const char *, size_t);
34989-};
34990+} __do_const;
34991
34992 /* Set of show/store abstract level functions for PCI Parity object */
34993 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34994@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34995 edac_printk(KERN_CRIT, EDAC_PCI,
34996 "Signaled System Error on %s\n",
34997 pci_name(dev));
34998- atomic_inc(&pci_nonparity_count);
34999+ atomic_inc_unchecked(&pci_nonparity_count);
35000 }
35001
35002 if (status & (PCI_STATUS_PARITY)) {
35003@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35004 "Master Data Parity Error on %s\n",
35005 pci_name(dev));
35006
35007- atomic_inc(&pci_parity_count);
35008+ atomic_inc_unchecked(&pci_parity_count);
35009 }
35010
35011 if (status & (PCI_STATUS_DETECTED_PARITY)) {
35012@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35013 "Detected Parity Error on %s\n",
35014 pci_name(dev));
35015
35016- atomic_inc(&pci_parity_count);
35017+ atomic_inc_unchecked(&pci_parity_count);
35018 }
35019 }
35020
35021@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35022 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
35023 "Signaled System Error on %s\n",
35024 pci_name(dev));
35025- atomic_inc(&pci_nonparity_count);
35026+ atomic_inc_unchecked(&pci_nonparity_count);
35027 }
35028
35029 if (status & (PCI_STATUS_PARITY)) {
35030@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35031 "Master Data Parity Error on "
35032 "%s\n", pci_name(dev));
35033
35034- atomic_inc(&pci_parity_count);
35035+ atomic_inc_unchecked(&pci_parity_count);
35036 }
35037
35038 if (status & (PCI_STATUS_DETECTED_PARITY)) {
35039@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
35040 "Detected Parity Error on %s\n",
35041 pci_name(dev));
35042
35043- atomic_inc(&pci_parity_count);
35044+ atomic_inc_unchecked(&pci_parity_count);
35045 }
35046 }
35047 }
35048@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
35049 if (!check_pci_errors)
35050 return;
35051
35052- before_count = atomic_read(&pci_parity_count);
35053+ before_count = atomic_read_unchecked(&pci_parity_count);
35054
35055 /* scan all PCI devices looking for a Parity Error on devices and
35056 * bridges.
35057@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
35058 /* Only if operator has selected panic on PCI Error */
35059 if (edac_pci_get_panic_on_pe()) {
35060 /* If the count is different 'after' from 'before' */
35061- if (before_count != atomic_read(&pci_parity_count))
35062+ if (before_count != atomic_read_unchecked(&pci_parity_count))
35063 panic("EDAC: PCI Parity Error");
35064 }
35065 }
35066diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
35067index 51b7e3a..aa8a3e8 100644
35068--- a/drivers/edac/mce_amd.h
35069+++ b/drivers/edac/mce_amd.h
35070@@ -77,7 +77,7 @@ struct amd_decoder_ops {
35071 bool (*mc0_mce)(u16, u8);
35072 bool (*mc1_mce)(u16, u8);
35073 bool (*mc2_mce)(u16, u8);
35074-};
35075+} __no_const;
35076
35077 void amd_report_gart_errors(bool);
35078 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
35079diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
35080index 57ea7f4..789e3c3 100644
35081--- a/drivers/firewire/core-card.c
35082+++ b/drivers/firewire/core-card.c
35083@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
35084
35085 void fw_core_remove_card(struct fw_card *card)
35086 {
35087- struct fw_card_driver dummy_driver = dummy_driver_template;
35088+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
35089
35090 card->driver->update_phy_reg(card, 4,
35091 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
35092diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
35093index 664a6ff..af13580 100644
35094--- a/drivers/firewire/core-device.c
35095+++ b/drivers/firewire/core-device.c
35096@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
35097 struct config_rom_attribute {
35098 struct device_attribute attr;
35099 u32 key;
35100-};
35101+} __do_const;
35102
35103 static ssize_t show_immediate(struct device *dev,
35104 struct device_attribute *dattr, char *buf)
35105diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
35106index 28a94c7..58da63a 100644
35107--- a/drivers/firewire/core-transaction.c
35108+++ b/drivers/firewire/core-transaction.c
35109@@ -38,6 +38,7 @@
35110 #include <linux/timer.h>
35111 #include <linux/types.h>
35112 #include <linux/workqueue.h>
35113+#include <linux/sched.h>
35114
35115 #include <asm/byteorder.h>
35116
35117diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
35118index 515a42c..5ecf3ba 100644
35119--- a/drivers/firewire/core.h
35120+++ b/drivers/firewire/core.h
35121@@ -111,6 +111,7 @@ struct fw_card_driver {
35122
35123 int (*stop_iso)(struct fw_iso_context *ctx);
35124 };
35125+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
35126
35127 void fw_card_initialize(struct fw_card *card,
35128 const struct fw_card_driver *driver, struct device *device);
35129diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
35130index 94a58a0..f5eba42 100644
35131--- a/drivers/firmware/dmi-id.c
35132+++ b/drivers/firmware/dmi-id.c
35133@@ -16,7 +16,7 @@
35134 struct dmi_device_attribute{
35135 struct device_attribute dev_attr;
35136 int field;
35137-};
35138+} __do_const;
35139 #define to_dmi_dev_attr(_dev_attr) \
35140 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
35141
35142diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35143index b95159b..841ae55 100644
35144--- a/drivers/firmware/dmi_scan.c
35145+++ b/drivers/firmware/dmi_scan.c
35146@@ -497,11 +497,6 @@ void __init dmi_scan_machine(void)
35147 }
35148 }
35149 else {
35150- /*
35151- * no iounmap() for that ioremap(); it would be a no-op, but
35152- * it's so early in setup that sucker gets confused into doing
35153- * what it shouldn't if we actually call it.
35154- */
35155 p = dmi_ioremap(0xF0000, 0x10000);
35156 if (p == NULL)
35157 goto error;
35158@@ -786,7 +781,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35159 if (buf == NULL)
35160 return -1;
35161
35162- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35163+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35164
35165 iounmap(buf);
35166 return 0;
35167diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
35168index 5145fa3..0d3babd 100644
35169--- a/drivers/firmware/efi/efi.c
35170+++ b/drivers/firmware/efi/efi.c
35171@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
35172 };
35173
35174 static struct efivars generic_efivars;
35175-static struct efivar_operations generic_ops;
35176+static efivar_operations_no_const generic_ops __read_only;
35177
35178 static int generic_ops_register(void)
35179 {
35180- generic_ops.get_variable = efi.get_variable;
35181- generic_ops.set_variable = efi.set_variable;
35182- generic_ops.get_next_variable = efi.get_next_variable;
35183- generic_ops.query_variable_store = efi_query_variable_store;
35184+ pax_open_kernel();
35185+ *(void **)&generic_ops.get_variable = efi.get_variable;
35186+ *(void **)&generic_ops.set_variable = efi.set_variable;
35187+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
35188+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
35189+ pax_close_kernel();
35190
35191 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
35192 }
35193diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
35194index 8bd1bb6..c48b0c6 100644
35195--- a/drivers/firmware/efi/efivars.c
35196+++ b/drivers/firmware/efi/efivars.c
35197@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
35198 static int
35199 create_efivars_bin_attributes(void)
35200 {
35201- struct bin_attribute *attr;
35202+ bin_attribute_no_const *attr;
35203 int error;
35204
35205 /* new_var */
35206diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35207index 2a90ba6..07f3733 100644
35208--- a/drivers/firmware/google/memconsole.c
35209+++ b/drivers/firmware/google/memconsole.c
35210@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35211 if (!found_memconsole())
35212 return -ENODEV;
35213
35214- memconsole_bin_attr.size = memconsole_length;
35215+ pax_open_kernel();
35216+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35217+ pax_close_kernel();
35218
35219 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35220
35221diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35222index e16d932..f0206ef 100644
35223--- a/drivers/gpio/gpio-ich.c
35224+++ b/drivers/gpio/gpio-ich.c
35225@@ -69,7 +69,7 @@ struct ichx_desc {
35226 /* Some chipsets have quirks, let these use their own request/get */
35227 int (*request)(struct gpio_chip *chip, unsigned offset);
35228 int (*get)(struct gpio_chip *chip, unsigned offset);
35229-};
35230+} __do_const;
35231
35232 static struct {
35233 spinlock_t lock;
35234diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35235index 9902732..64b62dd 100644
35236--- a/drivers/gpio/gpio-vr41xx.c
35237+++ b/drivers/gpio/gpio-vr41xx.c
35238@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35239 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35240 maskl, pendl, maskh, pendh);
35241
35242- atomic_inc(&irq_err_count);
35243+ atomic_inc_unchecked(&irq_err_count);
35244
35245 return -EINVAL;
35246 }
35247diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35248index ed1334e..ee0dd42 100644
35249--- a/drivers/gpu/drm/drm_crtc_helper.c
35250+++ b/drivers/gpu/drm/drm_crtc_helper.c
35251@@ -321,7 +321,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35252 struct drm_crtc *tmp;
35253 int crtc_mask = 1;
35254
35255- WARN(!crtc, "checking null crtc?\n");
35256+ BUG_ON(!crtc);
35257
35258 dev = crtc->dev;
35259
35260diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35261index 9cc247f..36aa285 100644
35262--- a/drivers/gpu/drm/drm_drv.c
35263+++ b/drivers/gpu/drm/drm_drv.c
35264@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
35265 /**
35266 * Copy and IOCTL return string to user space
35267 */
35268-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35269+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35270 {
35271 int len;
35272
35273@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
35274 struct drm_file *file_priv = filp->private_data;
35275 struct drm_device *dev;
35276 const struct drm_ioctl_desc *ioctl = NULL;
35277- drm_ioctl_t *func;
35278+ drm_ioctl_no_const_t func;
35279 unsigned int nr = DRM_IOCTL_NR(cmd);
35280 int retcode = -EINVAL;
35281 char stack_kdata[128];
35282@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
35283 return -ENODEV;
35284
35285 atomic_inc(&dev->ioctl_count);
35286- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35287+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35288 ++file_priv->ioctl_count;
35289
35290 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
35291diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35292index 429e07d..e681a2c 100644
35293--- a/drivers/gpu/drm/drm_fops.c
35294+++ b/drivers/gpu/drm/drm_fops.c
35295@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35296 }
35297
35298 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35299- atomic_set(&dev->counts[i], 0);
35300+ atomic_set_unchecked(&dev->counts[i], 0);
35301
35302 dev->sigdata.lock = NULL;
35303
35304@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35305 if (drm_device_is_unplugged(dev))
35306 return -ENODEV;
35307
35308- if (!dev->open_count++)
35309+ if (local_inc_return(&dev->open_count) == 1)
35310 need_setup = 1;
35311 mutex_lock(&dev->struct_mutex);
35312 old_imapping = inode->i_mapping;
35313@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35314 retcode = drm_open_helper(inode, filp, dev);
35315 if (retcode)
35316 goto err_undo;
35317- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35318+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35319 if (need_setup) {
35320 retcode = drm_setup(dev);
35321 if (retcode)
35322@@ -166,7 +166,7 @@ err_undo:
35323 iput(container_of(dev->dev_mapping, struct inode, i_data));
35324 dev->dev_mapping = old_mapping;
35325 mutex_unlock(&dev->struct_mutex);
35326- dev->open_count--;
35327+ local_dec(&dev->open_count);
35328 return retcode;
35329 }
35330 EXPORT_SYMBOL(drm_open);
35331@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
35332
35333 mutex_lock(&drm_global_mutex);
35334
35335- DRM_DEBUG("open_count = %d\n", dev->open_count);
35336+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35337
35338 if (dev->driver->preclose)
35339 dev->driver->preclose(dev, file_priv);
35340@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
35341 * Begin inline drm_release
35342 */
35343
35344- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35345+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35346 task_pid_nr(current),
35347 (long)old_encode_dev(file_priv->minor->device),
35348- dev->open_count);
35349+ local_read(&dev->open_count));
35350
35351 /* Release any auth tokens that might point to this file_priv,
35352 (do that under the drm_global_mutex) */
35353@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
35354 * End inline drm_release
35355 */
35356
35357- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35358- if (!--dev->open_count) {
35359+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35360+ if (local_dec_and_test(&dev->open_count)) {
35361 if (atomic_read(&dev->ioctl_count)) {
35362 DRM_ERROR("Device busy: %d\n",
35363 atomic_read(&dev->ioctl_count));
35364diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35365index f731116..629842c 100644
35366--- a/drivers/gpu/drm/drm_global.c
35367+++ b/drivers/gpu/drm/drm_global.c
35368@@ -36,7 +36,7 @@
35369 struct drm_global_item {
35370 struct mutex mutex;
35371 void *object;
35372- int refcount;
35373+ atomic_t refcount;
35374 };
35375
35376 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35377@@ -49,7 +49,7 @@ void drm_global_init(void)
35378 struct drm_global_item *item = &glob[i];
35379 mutex_init(&item->mutex);
35380 item->object = NULL;
35381- item->refcount = 0;
35382+ atomic_set(&item->refcount, 0);
35383 }
35384 }
35385
35386@@ -59,7 +59,7 @@ void drm_global_release(void)
35387 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35388 struct drm_global_item *item = &glob[i];
35389 BUG_ON(item->object != NULL);
35390- BUG_ON(item->refcount != 0);
35391+ BUG_ON(atomic_read(&item->refcount) != 0);
35392 }
35393 }
35394
35395@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35396 void *object;
35397
35398 mutex_lock(&item->mutex);
35399- if (item->refcount == 0) {
35400+ if (atomic_read(&item->refcount) == 0) {
35401 item->object = kzalloc(ref->size, GFP_KERNEL);
35402 if (unlikely(item->object == NULL)) {
35403 ret = -ENOMEM;
35404@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35405 goto out_err;
35406
35407 }
35408- ++item->refcount;
35409+ atomic_inc(&item->refcount);
35410 ref->object = item->object;
35411 object = item->object;
35412 mutex_unlock(&item->mutex);
35413@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35414 struct drm_global_item *item = &glob[ref->global_type];
35415
35416 mutex_lock(&item->mutex);
35417- BUG_ON(item->refcount == 0);
35418+ BUG_ON(atomic_read(&item->refcount) == 0);
35419 BUG_ON(ref->object != item->object);
35420- if (--item->refcount == 0) {
35421+ if (atomic_dec_and_test(&item->refcount)) {
35422 ref->release(ref);
35423 item->object = NULL;
35424 }
35425diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35426index d4b20ce..77a8d41 100644
35427--- a/drivers/gpu/drm/drm_info.c
35428+++ b/drivers/gpu/drm/drm_info.c
35429@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35430 struct drm_local_map *map;
35431 struct drm_map_list *r_list;
35432
35433- /* Hardcoded from _DRM_FRAME_BUFFER,
35434- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35435- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35436- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35437+ static const char * const types[] = {
35438+ [_DRM_FRAME_BUFFER] = "FB",
35439+ [_DRM_REGISTERS] = "REG",
35440+ [_DRM_SHM] = "SHM",
35441+ [_DRM_AGP] = "AGP",
35442+ [_DRM_SCATTER_GATHER] = "SG",
35443+ [_DRM_CONSISTENT] = "PCI",
35444+ [_DRM_GEM] = "GEM" };
35445 const char *type;
35446 int i;
35447
35448@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35449 map = r_list->map;
35450 if (!map)
35451 continue;
35452- if (map->type < 0 || map->type > 5)
35453+ if (map->type >= ARRAY_SIZE(types))
35454 type = "??";
35455 else
35456 type = types[map->type];
35457@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35458 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35459 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35460 vma->vm_flags & VM_IO ? 'i' : '-',
35461+#ifdef CONFIG_GRKERNSEC_HIDESYM
35462+ 0);
35463+#else
35464 vma->vm_pgoff);
35465+#endif
35466
35467 #if defined(__i386__)
35468 pgprot = pgprot_val(vma->vm_page_prot);
35469diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35470index 2f4c434..dd12cd2 100644
35471--- a/drivers/gpu/drm/drm_ioc32.c
35472+++ b/drivers/gpu/drm/drm_ioc32.c
35473@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35474 request = compat_alloc_user_space(nbytes);
35475 if (!access_ok(VERIFY_WRITE, request, nbytes))
35476 return -EFAULT;
35477- list = (struct drm_buf_desc *) (request + 1);
35478+ list = (struct drm_buf_desc __user *) (request + 1);
35479
35480 if (__put_user(count, &request->count)
35481 || __put_user(list, &request->list))
35482@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35483 request = compat_alloc_user_space(nbytes);
35484 if (!access_ok(VERIFY_WRITE, request, nbytes))
35485 return -EFAULT;
35486- list = (struct drm_buf_pub *) (request + 1);
35487+ list = (struct drm_buf_pub __user *) (request + 1);
35488
35489 if (__put_user(count, &request->count)
35490 || __put_user(list, &request->list))
35491@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35492 return 0;
35493 }
35494
35495-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35496+drm_ioctl_compat_t drm_compat_ioctls[] = {
35497 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35498 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35499 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35500@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35501 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35502 {
35503 unsigned int nr = DRM_IOCTL_NR(cmd);
35504- drm_ioctl_compat_t *fn;
35505 int ret;
35506
35507 /* Assume that ioctls without an explicit compat routine will just
35508@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35509 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35510 return drm_ioctl(filp, cmd, arg);
35511
35512- fn = drm_compat_ioctls[nr];
35513-
35514- if (fn != NULL)
35515- ret = (*fn) (filp, cmd, arg);
35516+ if (drm_compat_ioctls[nr] != NULL)
35517+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35518 else
35519 ret = drm_ioctl(filp, cmd, arg);
35520
35521diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35522index e77bd8b..1571b85 100644
35523--- a/drivers/gpu/drm/drm_ioctl.c
35524+++ b/drivers/gpu/drm/drm_ioctl.c
35525@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35526 stats->data[i].value =
35527 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35528 else
35529- stats->data[i].value = atomic_read(&dev->counts[i]);
35530+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35531 stats->data[i].type = dev->types[i];
35532 }
35533
35534diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35535index d752c96..fe08455 100644
35536--- a/drivers/gpu/drm/drm_lock.c
35537+++ b/drivers/gpu/drm/drm_lock.c
35538@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35539 if (drm_lock_take(&master->lock, lock->context)) {
35540 master->lock.file_priv = file_priv;
35541 master->lock.lock_time = jiffies;
35542- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35543+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35544 break; /* Got lock */
35545 }
35546
35547@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35548 return -EINVAL;
35549 }
35550
35551- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35552+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35553
35554 if (drm_lock_free(&master->lock, lock->context)) {
35555 /* FIXME: Should really bail out here. */
35556diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35557index 16f3ec5..b28f9ca 100644
35558--- a/drivers/gpu/drm/drm_stub.c
35559+++ b/drivers/gpu/drm/drm_stub.c
35560@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
35561
35562 drm_device_set_unplugged(dev);
35563
35564- if (dev->open_count == 0) {
35565+ if (local_read(&dev->open_count) == 0) {
35566 drm_put_dev(dev);
35567 }
35568 mutex_unlock(&drm_global_mutex);
35569diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
35570index 0229665..f61329c 100644
35571--- a/drivers/gpu/drm/drm_sysfs.c
35572+++ b/drivers/gpu/drm/drm_sysfs.c
35573@@ -499,7 +499,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
35574 int drm_sysfs_device_add(struct drm_minor *minor)
35575 {
35576 int err;
35577- char *minor_str;
35578+ const char *minor_str;
35579
35580 minor->kdev.parent = minor->dev->dev;
35581
35582diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35583index 004ecdf..db1f6e0 100644
35584--- a/drivers/gpu/drm/i810/i810_dma.c
35585+++ b/drivers/gpu/drm/i810/i810_dma.c
35586@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35587 dma->buflist[vertex->idx],
35588 vertex->discard, vertex->used);
35589
35590- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35591- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35592+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35593+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35594 sarea_priv->last_enqueue = dev_priv->counter - 1;
35595 sarea_priv->last_dispatch = (int)hw_status[5];
35596
35597@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35598 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35599 mc->last_render);
35600
35601- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35602- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35603+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35604+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35605 sarea_priv->last_enqueue = dev_priv->counter - 1;
35606 sarea_priv->last_dispatch = (int)hw_status[5];
35607
35608diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35609index 6e0acad..93c8289 100644
35610--- a/drivers/gpu/drm/i810/i810_drv.h
35611+++ b/drivers/gpu/drm/i810/i810_drv.h
35612@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35613 int page_flipping;
35614
35615 wait_queue_head_t irq_queue;
35616- atomic_t irq_received;
35617- atomic_t irq_emitted;
35618+ atomic_unchecked_t irq_received;
35619+ atomic_unchecked_t irq_emitted;
35620
35621 int front_offset;
35622 } drm_i810_private_t;
35623diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35624index e913d32..4d9b351 100644
35625--- a/drivers/gpu/drm/i915/i915_debugfs.c
35626+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35627@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35628 I915_READ(GTIMR));
35629 }
35630 seq_printf(m, "Interrupts received: %d\n",
35631- atomic_read(&dev_priv->irq_received));
35632+ atomic_read_unchecked(&dev_priv->irq_received));
35633 for_each_ring(ring, dev_priv, i) {
35634 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35635 seq_printf(m,
35636diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35637index f968590..19115e35 100644
35638--- a/drivers/gpu/drm/i915/i915_dma.c
35639+++ b/drivers/gpu/drm/i915/i915_dma.c
35640@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35641 bool can_switch;
35642
35643 spin_lock(&dev->count_lock);
35644- can_switch = (dev->open_count == 0);
35645+ can_switch = (local_read(&dev->open_count) == 0);
35646 spin_unlock(&dev->count_lock);
35647 return can_switch;
35648 }
35649diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35650index 47d8b68..52f5d8d 100644
35651--- a/drivers/gpu/drm/i915/i915_drv.h
35652+++ b/drivers/gpu/drm/i915/i915_drv.h
35653@@ -916,7 +916,7 @@ typedef struct drm_i915_private {
35654 drm_dma_handle_t *status_page_dmah;
35655 struct resource mch_res;
35656
35657- atomic_t irq_received;
35658+ atomic_unchecked_t irq_received;
35659
35660 /* protects the irq masks */
35661 spinlock_t irq_lock;
35662@@ -1813,7 +1813,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35663 struct drm_i915_private *dev_priv, unsigned port);
35664 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35665 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35666-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35667+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35668 {
35669 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35670 }
35671diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35672index 117ce38..eefd237 100644
35673--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35674+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35675@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35676
35677 static int
35678 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35679- int count)
35680+ unsigned int count)
35681 {
35682- int i;
35683+ unsigned int i;
35684 int relocs_total = 0;
35685 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35686
35687diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35688index 3c59584..500f2e9 100644
35689--- a/drivers/gpu/drm/i915/i915_ioc32.c
35690+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35691@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35692 (unsigned long)request);
35693 }
35694
35695-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35696+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35697 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35698 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35699 [DRM_I915_GETPARAM] = compat_i915_getparam,
35700@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35701 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35702 {
35703 unsigned int nr = DRM_IOCTL_NR(cmd);
35704- drm_ioctl_compat_t *fn = NULL;
35705 int ret;
35706
35707 if (nr < DRM_COMMAND_BASE)
35708 return drm_compat_ioctl(filp, cmd, arg);
35709
35710- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35711- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35712-
35713- if (fn != NULL)
35714+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35715+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35716 ret = (*fn) (filp, cmd, arg);
35717- else
35718+ } else
35719 ret = drm_ioctl(filp, cmd, arg);
35720
35721 return ret;
35722diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35723index e5e32869..1678f36 100644
35724--- a/drivers/gpu/drm/i915/i915_irq.c
35725+++ b/drivers/gpu/drm/i915/i915_irq.c
35726@@ -670,7 +670,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35727 int pipe;
35728 u32 pipe_stats[I915_MAX_PIPES];
35729
35730- atomic_inc(&dev_priv->irq_received);
35731+ atomic_inc_unchecked(&dev_priv->irq_received);
35732
35733 while (true) {
35734 iir = I915_READ(VLV_IIR);
35735@@ -835,7 +835,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35736 irqreturn_t ret = IRQ_NONE;
35737 int i;
35738
35739- atomic_inc(&dev_priv->irq_received);
35740+ atomic_inc_unchecked(&dev_priv->irq_received);
35741
35742 /* disable master interrupt before clearing iir */
35743 de_ier = I915_READ(DEIER);
35744@@ -925,7 +925,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35745 int ret = IRQ_NONE;
35746 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
35747
35748- atomic_inc(&dev_priv->irq_received);
35749+ atomic_inc_unchecked(&dev_priv->irq_received);
35750
35751 /* disable master interrupt before clearing iir */
35752 de_ier = I915_READ(DEIER);
35753@@ -2089,7 +2089,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35754 {
35755 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35756
35757- atomic_set(&dev_priv->irq_received, 0);
35758+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35759
35760 I915_WRITE(HWSTAM, 0xeffe);
35761
35762@@ -2124,7 +2124,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35763 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35764 int pipe;
35765
35766- atomic_set(&dev_priv->irq_received, 0);
35767+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35768
35769 /* VLV magic */
35770 I915_WRITE(VLV_IMR, 0);
35771@@ -2411,7 +2411,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35772 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35773 int pipe;
35774
35775- atomic_set(&dev_priv->irq_received, 0);
35776+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35777
35778 for_each_pipe(pipe)
35779 I915_WRITE(PIPESTAT(pipe), 0);
35780@@ -2490,7 +2490,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35781 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35782 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35783
35784- atomic_inc(&dev_priv->irq_received);
35785+ atomic_inc_unchecked(&dev_priv->irq_received);
35786
35787 iir = I915_READ16(IIR);
35788 if (iir == 0)
35789@@ -2565,7 +2565,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35790 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35791 int pipe;
35792
35793- atomic_set(&dev_priv->irq_received, 0);
35794+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35795
35796 if (I915_HAS_HOTPLUG(dev)) {
35797 I915_WRITE(PORT_HOTPLUG_EN, 0);
35798@@ -2664,7 +2664,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35799 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35800 int pipe, ret = IRQ_NONE;
35801
35802- atomic_inc(&dev_priv->irq_received);
35803+ atomic_inc_unchecked(&dev_priv->irq_received);
35804
35805 iir = I915_READ(IIR);
35806 do {
35807@@ -2791,7 +2791,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35808 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35809 int pipe;
35810
35811- atomic_set(&dev_priv->irq_received, 0);
35812+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35813
35814 I915_WRITE(PORT_HOTPLUG_EN, 0);
35815 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35816@@ -2898,7 +2898,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35817 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35818 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35819
35820- atomic_inc(&dev_priv->irq_received);
35821+ atomic_inc_unchecked(&dev_priv->irq_received);
35822
35823 iir = I915_READ(IIR);
35824
35825diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35826index e1f4e6e..c94a4b3 100644
35827--- a/drivers/gpu/drm/i915/intel_display.c
35828+++ b/drivers/gpu/drm/i915/intel_display.c
35829@@ -8933,13 +8933,13 @@ struct intel_quirk {
35830 int subsystem_vendor;
35831 int subsystem_device;
35832 void (*hook)(struct drm_device *dev);
35833-};
35834+} __do_const;
35835
35836 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35837 struct intel_dmi_quirk {
35838 void (*hook)(struct drm_device *dev);
35839 const struct dmi_system_id (*dmi_id_list)[];
35840-};
35841+} __do_const;
35842
35843 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35844 {
35845@@ -8947,18 +8947,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35846 return 1;
35847 }
35848
35849-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35850+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35851 {
35852- .dmi_id_list = &(const struct dmi_system_id[]) {
35853- {
35854- .callback = intel_dmi_reverse_brightness,
35855- .ident = "NCR Corporation",
35856- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35857- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35858- },
35859- },
35860- { } /* terminating entry */
35861+ .callback = intel_dmi_reverse_brightness,
35862+ .ident = "NCR Corporation",
35863+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35864+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35865 },
35866+ },
35867+ { } /* terminating entry */
35868+};
35869+
35870+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35871+ {
35872+ .dmi_id_list = &intel_dmi_quirks_table,
35873 .hook = quirk_invert_brightness,
35874 },
35875 };
35876diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35877index 54558a0..2d97005 100644
35878--- a/drivers/gpu/drm/mga/mga_drv.h
35879+++ b/drivers/gpu/drm/mga/mga_drv.h
35880@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35881 u32 clear_cmd;
35882 u32 maccess;
35883
35884- atomic_t vbl_received; /**< Number of vblanks received. */
35885+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35886 wait_queue_head_t fence_queue;
35887- atomic_t last_fence_retired;
35888+ atomic_unchecked_t last_fence_retired;
35889 u32 next_fence_to_post;
35890
35891 unsigned int fb_cpp;
35892diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35893index 709e90d..89a1c0d 100644
35894--- a/drivers/gpu/drm/mga/mga_ioc32.c
35895+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35896@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35897 return 0;
35898 }
35899
35900-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35901+drm_ioctl_compat_t mga_compat_ioctls[] = {
35902 [DRM_MGA_INIT] = compat_mga_init,
35903 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35904 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35905@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35906 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35907 {
35908 unsigned int nr = DRM_IOCTL_NR(cmd);
35909- drm_ioctl_compat_t *fn = NULL;
35910 int ret;
35911
35912 if (nr < DRM_COMMAND_BASE)
35913 return drm_compat_ioctl(filp, cmd, arg);
35914
35915- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35916- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35917-
35918- if (fn != NULL)
35919+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35920+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35921 ret = (*fn) (filp, cmd, arg);
35922- else
35923+ } else
35924 ret = drm_ioctl(filp, cmd, arg);
35925
35926 return ret;
35927diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35928index 598c281..60d590e 100644
35929--- a/drivers/gpu/drm/mga/mga_irq.c
35930+++ b/drivers/gpu/drm/mga/mga_irq.c
35931@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35932 if (crtc != 0)
35933 return 0;
35934
35935- return atomic_read(&dev_priv->vbl_received);
35936+ return atomic_read_unchecked(&dev_priv->vbl_received);
35937 }
35938
35939
35940@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35941 /* VBLANK interrupt */
35942 if (status & MGA_VLINEPEN) {
35943 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35944- atomic_inc(&dev_priv->vbl_received);
35945+ atomic_inc_unchecked(&dev_priv->vbl_received);
35946 drm_handle_vblank(dev, 0);
35947 handled = 1;
35948 }
35949@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35950 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35951 MGA_WRITE(MGA_PRIMEND, prim_end);
35952
35953- atomic_inc(&dev_priv->last_fence_retired);
35954+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35955 DRM_WAKEUP(&dev_priv->fence_queue);
35956 handled = 1;
35957 }
35958@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35959 * using fences.
35960 */
35961 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35962- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35963+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35964 - *sequence) <= (1 << 23)));
35965
35966 *sequence = cur_fence;
35967diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35968index 6aa2137..fe8dc55 100644
35969--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35970+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35971@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35972 struct bit_table {
35973 const char id;
35974 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35975-};
35976+} __no_const;
35977
35978 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35979
35980diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35981index f2b30f8..d0f9a95 100644
35982--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35983+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35984@@ -92,7 +92,7 @@ struct nouveau_drm {
35985 struct drm_global_reference mem_global_ref;
35986 struct ttm_bo_global_ref bo_global_ref;
35987 struct ttm_bo_device bdev;
35988- atomic_t validate_sequence;
35989+ atomic_unchecked_t validate_sequence;
35990 int (*move)(struct nouveau_channel *,
35991 struct ttm_buffer_object *,
35992 struct ttm_mem_reg *, struct ttm_mem_reg *);
35993diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35994index b4b4d0c..b7edc15 100644
35995--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35996+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35997@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35998 int ret, i;
35999 struct nouveau_bo *res_bo = NULL;
36000
36001- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
36002+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
36003 retry:
36004 if (++trycnt > 100000) {
36005 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
36006@@ -359,7 +359,7 @@ retry:
36007 if (ret) {
36008 validate_fini(op, NULL);
36009 if (unlikely(ret == -EAGAIN)) {
36010- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
36011+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
36012 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
36013 sequence);
36014 if (!ret)
36015diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
36016index 08214bc..9208577 100644
36017--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
36018+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
36019@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
36020 unsigned long arg)
36021 {
36022 unsigned int nr = DRM_IOCTL_NR(cmd);
36023- drm_ioctl_compat_t *fn = NULL;
36024+ drm_ioctl_compat_t fn = NULL;
36025 int ret;
36026
36027 if (nr < DRM_COMMAND_BASE)
36028diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
36029index 25d3495..d81aaf6 100644
36030--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
36031+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
36032@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
36033 bool can_switch;
36034
36035 spin_lock(&dev->count_lock);
36036- can_switch = (dev->open_count == 0);
36037+ can_switch = (local_read(&dev->open_count) == 0);
36038 spin_unlock(&dev->count_lock);
36039 return can_switch;
36040 }
36041diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
36042index 489cb8c..0b8d0d3 100644
36043--- a/drivers/gpu/drm/qxl/qxl_ttm.c
36044+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
36045@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
36046 }
36047 }
36048
36049-static struct vm_operations_struct qxl_ttm_vm_ops;
36050+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
36051 static const struct vm_operations_struct *ttm_vm_ops;
36052
36053 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36054@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
36055 return r;
36056 if (unlikely(ttm_vm_ops == NULL)) {
36057 ttm_vm_ops = vma->vm_ops;
36058+ pax_open_kernel();
36059 qxl_ttm_vm_ops = *ttm_vm_ops;
36060 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
36061+ pax_close_kernel();
36062 }
36063 vma->vm_ops = &qxl_ttm_vm_ops;
36064 return 0;
36065@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
36066 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
36067 {
36068 #if defined(CONFIG_DEBUG_FS)
36069- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
36070- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
36071- unsigned i;
36072+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
36073+ {
36074+ .name = "qxl_mem_mm",
36075+ .show = &qxl_mm_dump_table,
36076+ },
36077+ {
36078+ .name = "qxl_surf_mm",
36079+ .show = &qxl_mm_dump_table,
36080+ }
36081+ };
36082
36083- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
36084- if (i == 0)
36085- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
36086- else
36087- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
36088- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
36089- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
36090- qxl_mem_types_list[i].driver_features = 0;
36091- if (i == 0)
36092- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
36093- else
36094- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
36095+ pax_open_kernel();
36096+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
36097+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
36098+ pax_close_kernel();
36099
36100- }
36101- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
36102+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
36103 #else
36104 return 0;
36105 #endif
36106diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
36107index d4660cf..70dbe65 100644
36108--- a/drivers/gpu/drm/r128/r128_cce.c
36109+++ b/drivers/gpu/drm/r128/r128_cce.c
36110@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
36111
36112 /* GH: Simple idle check.
36113 */
36114- atomic_set(&dev_priv->idle_count, 0);
36115+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36116
36117 /* We don't support anything other than bus-mastering ring mode,
36118 * but the ring can be in either AGP or PCI space for the ring
36119diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
36120index 930c71b..499aded 100644
36121--- a/drivers/gpu/drm/r128/r128_drv.h
36122+++ b/drivers/gpu/drm/r128/r128_drv.h
36123@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
36124 int is_pci;
36125 unsigned long cce_buffers_offset;
36126
36127- atomic_t idle_count;
36128+ atomic_unchecked_t idle_count;
36129
36130 int page_flipping;
36131 int current_page;
36132 u32 crtc_offset;
36133 u32 crtc_offset_cntl;
36134
36135- atomic_t vbl_received;
36136+ atomic_unchecked_t vbl_received;
36137
36138 u32 color_fmt;
36139 unsigned int front_offset;
36140diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
36141index a954c54..9cc595c 100644
36142--- a/drivers/gpu/drm/r128/r128_ioc32.c
36143+++ b/drivers/gpu/drm/r128/r128_ioc32.c
36144@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
36145 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
36146 }
36147
36148-drm_ioctl_compat_t *r128_compat_ioctls[] = {
36149+drm_ioctl_compat_t r128_compat_ioctls[] = {
36150 [DRM_R128_INIT] = compat_r128_init,
36151 [DRM_R128_DEPTH] = compat_r128_depth,
36152 [DRM_R128_STIPPLE] = compat_r128_stipple,
36153@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
36154 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36155 {
36156 unsigned int nr = DRM_IOCTL_NR(cmd);
36157- drm_ioctl_compat_t *fn = NULL;
36158 int ret;
36159
36160 if (nr < DRM_COMMAND_BASE)
36161 return drm_compat_ioctl(filp, cmd, arg);
36162
36163- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
36164- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36165-
36166- if (fn != NULL)
36167+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
36168+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36169 ret = (*fn) (filp, cmd, arg);
36170- else
36171+ } else
36172 ret = drm_ioctl(filp, cmd, arg);
36173
36174 return ret;
36175diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36176index 2ea4f09..d391371 100644
36177--- a/drivers/gpu/drm/r128/r128_irq.c
36178+++ b/drivers/gpu/drm/r128/r128_irq.c
36179@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36180 if (crtc != 0)
36181 return 0;
36182
36183- return atomic_read(&dev_priv->vbl_received);
36184+ return atomic_read_unchecked(&dev_priv->vbl_received);
36185 }
36186
36187 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36188@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36189 /* VBLANK interrupt */
36190 if (status & R128_CRTC_VBLANK_INT) {
36191 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36192- atomic_inc(&dev_priv->vbl_received);
36193+ atomic_inc_unchecked(&dev_priv->vbl_received);
36194 drm_handle_vblank(dev, 0);
36195 return IRQ_HANDLED;
36196 }
36197diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36198index 19bb7e6..de7e2a2 100644
36199--- a/drivers/gpu/drm/r128/r128_state.c
36200+++ b/drivers/gpu/drm/r128/r128_state.c
36201@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36202
36203 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36204 {
36205- if (atomic_read(&dev_priv->idle_count) == 0)
36206+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36207 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36208 else
36209- atomic_set(&dev_priv->idle_count, 0);
36210+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36211 }
36212
36213 #endif
36214diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36215index 5a82b6b..9e69c73 100644
36216--- a/drivers/gpu/drm/radeon/mkregtable.c
36217+++ b/drivers/gpu/drm/radeon/mkregtable.c
36218@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36219 regex_t mask_rex;
36220 regmatch_t match[4];
36221 char buf[1024];
36222- size_t end;
36223+ long end;
36224 int len;
36225 int done = 0;
36226 int r;
36227 unsigned o;
36228 struct offset *offset;
36229 char last_reg_s[10];
36230- int last_reg;
36231+ unsigned long last_reg;
36232
36233 if (regcomp
36234 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36235diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36236index b0dc0b6..a9bfe9c 100644
36237--- a/drivers/gpu/drm/radeon/radeon_device.c
36238+++ b/drivers/gpu/drm/radeon/radeon_device.c
36239@@ -1014,7 +1014,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36240 bool can_switch;
36241
36242 spin_lock(&dev->count_lock);
36243- can_switch = (dev->open_count == 0);
36244+ can_switch = (local_read(&dev->open_count) == 0);
36245 spin_unlock(&dev->count_lock);
36246 return can_switch;
36247 }
36248diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36249index b369d42..8dd04eb 100644
36250--- a/drivers/gpu/drm/radeon/radeon_drv.h
36251+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36252@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
36253
36254 /* SW interrupt */
36255 wait_queue_head_t swi_queue;
36256- atomic_t swi_emitted;
36257+ atomic_unchecked_t swi_emitted;
36258 int vblank_crtc;
36259 uint32_t irq_enable_reg;
36260 uint32_t r500_disp_irq_reg;
36261diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36262index c180df8..5fd8186 100644
36263--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36264+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36265@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36266 request = compat_alloc_user_space(sizeof(*request));
36267 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36268 || __put_user(req32.param, &request->param)
36269- || __put_user((void __user *)(unsigned long)req32.value,
36270+ || __put_user((unsigned long)req32.value,
36271 &request->value))
36272 return -EFAULT;
36273
36274@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36275 #define compat_radeon_cp_setparam NULL
36276 #endif /* X86_64 || IA64 */
36277
36278-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36279+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36280 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36281 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36282 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36283@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36284 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36285 {
36286 unsigned int nr = DRM_IOCTL_NR(cmd);
36287- drm_ioctl_compat_t *fn = NULL;
36288 int ret;
36289
36290 if (nr < DRM_COMMAND_BASE)
36291 return drm_compat_ioctl(filp, cmd, arg);
36292
36293- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36294- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36295-
36296- if (fn != NULL)
36297+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36298+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36299 ret = (*fn) (filp, cmd, arg);
36300- else
36301+ } else
36302 ret = drm_ioctl(filp, cmd, arg);
36303
36304 return ret;
36305diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36306index 8d68e97..9dcfed8 100644
36307--- a/drivers/gpu/drm/radeon/radeon_irq.c
36308+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36309@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36310 unsigned int ret;
36311 RING_LOCALS;
36312
36313- atomic_inc(&dev_priv->swi_emitted);
36314- ret = atomic_read(&dev_priv->swi_emitted);
36315+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36316+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36317
36318 BEGIN_RING(4);
36319 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36320@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36321 drm_radeon_private_t *dev_priv =
36322 (drm_radeon_private_t *) dev->dev_private;
36323
36324- atomic_set(&dev_priv->swi_emitted, 0);
36325+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36326 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36327
36328 dev->max_vblank_count = 0x001fffff;
36329diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36330index 4d20910..6726b6d 100644
36331--- a/drivers/gpu/drm/radeon/radeon_state.c
36332+++ b/drivers/gpu/drm/radeon/radeon_state.c
36333@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36334 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36335 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36336
36337- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36338+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36339 sarea_priv->nbox * sizeof(depth_boxes[0])))
36340 return -EFAULT;
36341
36342@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36343 {
36344 drm_radeon_private_t *dev_priv = dev->dev_private;
36345 drm_radeon_getparam_t *param = data;
36346- int value;
36347+ int value = 0;
36348
36349 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36350
36351diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36352index 6c0ce89..57a2529 100644
36353--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36354+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36355@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36356 man->size = size >> PAGE_SHIFT;
36357 }
36358
36359-static struct vm_operations_struct radeon_ttm_vm_ops;
36360+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36361 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36362
36363 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36364@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36365 }
36366 if (unlikely(ttm_vm_ops == NULL)) {
36367 ttm_vm_ops = vma->vm_ops;
36368+ pax_open_kernel();
36369 radeon_ttm_vm_ops = *ttm_vm_ops;
36370 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36371+ pax_close_kernel();
36372 }
36373 vma->vm_ops = &radeon_ttm_vm_ops;
36374 return 0;
36375@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
36376 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36377 {
36378 #if defined(CONFIG_DEBUG_FS)
36379- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
36380- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
36381+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
36382+ {
36383+ .name = "radeon_vram_mm",
36384+ .show = &radeon_mm_dump_table,
36385+ },
36386+ {
36387+ .name = "radeon_gtt_mm",
36388+ .show = &radeon_mm_dump_table,
36389+ },
36390+ {
36391+ .name = "ttm_page_pool",
36392+ .show = &ttm_page_alloc_debugfs,
36393+ },
36394+ {
36395+ .name = "ttm_dma_page_pool",
36396+ .show = &ttm_dma_page_alloc_debugfs,
36397+ },
36398+ };
36399 unsigned i;
36400
36401- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
36402- if (i == 0)
36403- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36404- else
36405- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36406- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36407- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36408- radeon_mem_types_list[i].driver_features = 0;
36409- if (i == 0)
36410- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36411- else
36412- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36413-
36414- }
36415- /* Add ttm page pool to debugfs */
36416- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36417- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36418- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36419- radeon_mem_types_list[i].driver_features = 0;
36420- radeon_mem_types_list[i++].data = NULL;
36421+ pax_open_kernel();
36422+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36423+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36424+ pax_close_kernel();
36425 #ifdef CONFIG_SWIOTLB
36426- if (swiotlb_nr_tbl()) {
36427- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36428- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36429- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36430- radeon_mem_types_list[i].driver_features = 0;
36431- radeon_mem_types_list[i++].data = NULL;
36432- }
36433+ if (swiotlb_nr_tbl())
36434+ i++;
36435 #endif
36436 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36437
36438diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36439index 55880d5..9e95342 100644
36440--- a/drivers/gpu/drm/radeon/rs690.c
36441+++ b/drivers/gpu/drm/radeon/rs690.c
36442@@ -327,9 +327,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36443 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36444 rdev->pm.sideport_bandwidth.full)
36445 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36446- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36447+ read_delay_latency.full = dfixed_const(800 * 1000);
36448 read_delay_latency.full = dfixed_div(read_delay_latency,
36449 rdev->pm.igp_sideport_mclk);
36450+ a.full = dfixed_const(370);
36451+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36452 } else {
36453 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36454 rdev->pm.k8_bandwidth.full)
36455diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
36456index dbc2def..0a9f710 100644
36457--- a/drivers/gpu/drm/ttm/ttm_memory.c
36458+++ b/drivers/gpu/drm/ttm/ttm_memory.c
36459@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
36460 zone->glob = glob;
36461 glob->zone_kernel = zone;
36462 ret = kobject_init_and_add(
36463- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36464+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36465 if (unlikely(ret != 0)) {
36466 kobject_put(&zone->kobj);
36467 return ret;
36468@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
36469 zone->glob = glob;
36470 glob->zone_dma32 = zone;
36471 ret = kobject_init_and_add(
36472- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36473+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36474 if (unlikely(ret != 0)) {
36475 kobject_put(&zone->kobj);
36476 return ret;
36477diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36478index bd2a3b4..122d9ad 100644
36479--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36480+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36481@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36482 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36483 struct shrink_control *sc)
36484 {
36485- static atomic_t start_pool = ATOMIC_INIT(0);
36486+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36487 unsigned i;
36488- unsigned pool_offset = atomic_add_return(1, &start_pool);
36489+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36490 struct ttm_page_pool *pool;
36491 int shrink_pages = sc->nr_to_scan;
36492
36493diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36494index dc0c065..58a0782 100644
36495--- a/drivers/gpu/drm/udl/udl_fb.c
36496+++ b/drivers/gpu/drm/udl/udl_fb.c
36497@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36498 fb_deferred_io_cleanup(info);
36499 kfree(info->fbdefio);
36500 info->fbdefio = NULL;
36501- info->fbops->fb_mmap = udl_fb_mmap;
36502 }
36503
36504 pr_warn("released /dev/fb%d user=%d count=%d\n",
36505diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36506index 893a650..6190d3b 100644
36507--- a/drivers/gpu/drm/via/via_drv.h
36508+++ b/drivers/gpu/drm/via/via_drv.h
36509@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36510 typedef uint32_t maskarray_t[5];
36511
36512 typedef struct drm_via_irq {
36513- atomic_t irq_received;
36514+ atomic_unchecked_t irq_received;
36515 uint32_t pending_mask;
36516 uint32_t enable_mask;
36517 wait_queue_head_t irq_queue;
36518@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36519 struct timeval last_vblank;
36520 int last_vblank_valid;
36521 unsigned usec_per_vblank;
36522- atomic_t vbl_received;
36523+ atomic_unchecked_t vbl_received;
36524 drm_via_state_t hc_state;
36525 char pci_buf[VIA_PCI_BUF_SIZE];
36526 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36527diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36528index ac98964..5dbf512 100644
36529--- a/drivers/gpu/drm/via/via_irq.c
36530+++ b/drivers/gpu/drm/via/via_irq.c
36531@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36532 if (crtc != 0)
36533 return 0;
36534
36535- return atomic_read(&dev_priv->vbl_received);
36536+ return atomic_read_unchecked(&dev_priv->vbl_received);
36537 }
36538
36539 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36540@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36541
36542 status = VIA_READ(VIA_REG_INTERRUPT);
36543 if (status & VIA_IRQ_VBLANK_PENDING) {
36544- atomic_inc(&dev_priv->vbl_received);
36545- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36546+ atomic_inc_unchecked(&dev_priv->vbl_received);
36547+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36548 do_gettimeofday(&cur_vblank);
36549 if (dev_priv->last_vblank_valid) {
36550 dev_priv->usec_per_vblank =
36551@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36552 dev_priv->last_vblank = cur_vblank;
36553 dev_priv->last_vblank_valid = 1;
36554 }
36555- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36556+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36557 DRM_DEBUG("US per vblank is: %u\n",
36558 dev_priv->usec_per_vblank);
36559 }
36560@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36561
36562 for (i = 0; i < dev_priv->num_irqs; ++i) {
36563 if (status & cur_irq->pending_mask) {
36564- atomic_inc(&cur_irq->irq_received);
36565+ atomic_inc_unchecked(&cur_irq->irq_received);
36566 DRM_WAKEUP(&cur_irq->irq_queue);
36567 handled = 1;
36568 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36569@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36570 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36571 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36572 masks[irq][4]));
36573- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36574+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36575 } else {
36576 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36577 (((cur_irq_sequence =
36578- atomic_read(&cur_irq->irq_received)) -
36579+ atomic_read_unchecked(&cur_irq->irq_received)) -
36580 *sequence) <= (1 << 23)));
36581 }
36582 *sequence = cur_irq_sequence;
36583@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36584 }
36585
36586 for (i = 0; i < dev_priv->num_irqs; ++i) {
36587- atomic_set(&cur_irq->irq_received, 0);
36588+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36589 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36590 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36591 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36592@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36593 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36594 case VIA_IRQ_RELATIVE:
36595 irqwait->request.sequence +=
36596- atomic_read(&cur_irq->irq_received);
36597+ atomic_read_unchecked(&cur_irq->irq_received);
36598 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36599 case VIA_IRQ_ABSOLUTE:
36600 break;
36601diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36602index 13aeda7..4a952d1 100644
36603--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36604+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36605@@ -290,7 +290,7 @@ struct vmw_private {
36606 * Fencing and IRQs.
36607 */
36608
36609- atomic_t marker_seq;
36610+ atomic_unchecked_t marker_seq;
36611 wait_queue_head_t fence_queue;
36612 wait_queue_head_t fifo_queue;
36613 int fence_queue_waiters; /* Protected by hw_mutex */
36614diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36615index 3eb1486..0a47ee9 100644
36616--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36617+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36618@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36619 (unsigned int) min,
36620 (unsigned int) fifo->capabilities);
36621
36622- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36623+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36624 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36625 vmw_marker_queue_init(&fifo->marker_queue);
36626 return vmw_fifo_send_fence(dev_priv, &dummy);
36627@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36628 if (reserveable)
36629 iowrite32(bytes, fifo_mem +
36630 SVGA_FIFO_RESERVED);
36631- return fifo_mem + (next_cmd >> 2);
36632+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36633 } else {
36634 need_bounce = true;
36635 }
36636@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36637
36638 fm = vmw_fifo_reserve(dev_priv, bytes);
36639 if (unlikely(fm == NULL)) {
36640- *seqno = atomic_read(&dev_priv->marker_seq);
36641+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36642 ret = -ENOMEM;
36643 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36644 false, 3*HZ);
36645@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36646 }
36647
36648 do {
36649- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36650+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36651 } while (*seqno == 0);
36652
36653 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36654diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36655index c509d40..3b640c3 100644
36656--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36657+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36658@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
36659 int ret;
36660
36661 num_clips = arg->num_clips;
36662- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36663+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36664
36665 if (unlikely(num_clips == 0))
36666 return 0;
36667@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
36668 int ret;
36669
36670 num_clips = arg->num_clips;
36671- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36672+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36673
36674 if (unlikely(num_clips == 0))
36675 return 0;
36676diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36677index 4640adb..e1384ed 100644
36678--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36679+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36680@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36681 * emitted. Then the fence is stale and signaled.
36682 */
36683
36684- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36685+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36686 > VMW_FENCE_WRAP);
36687
36688 return ret;
36689@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36690
36691 if (fifo_idle)
36692 down_read(&fifo_state->rwsem);
36693- signal_seq = atomic_read(&dev_priv->marker_seq);
36694+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36695 ret = 0;
36696
36697 for (;;) {
36698diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36699index 8a8725c2..afed796 100644
36700--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36701+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36702@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36703 while (!vmw_lag_lt(queue, us)) {
36704 spin_lock(&queue->lock);
36705 if (list_empty(&queue->head))
36706- seqno = atomic_read(&dev_priv->marker_seq);
36707+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36708 else {
36709 marker = list_first_entry(&queue->head,
36710 struct vmw_marker, head);
36711diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
36712index 8c04943..4370ed9 100644
36713--- a/drivers/gpu/host1x/drm/dc.c
36714+++ b/drivers/gpu/host1x/drm/dc.c
36715@@ -999,7 +999,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
36716 }
36717
36718 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
36719- dc->debugfs_files[i].data = dc;
36720+ *(void **)&dc->debugfs_files[i].data = dc;
36721
36722 err = drm_debugfs_create_files(dc->debugfs_files,
36723 ARRAY_SIZE(debugfs_files),
36724diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36725index 402f486..f862d7e 100644
36726--- a/drivers/hid/hid-core.c
36727+++ b/drivers/hid/hid-core.c
36728@@ -2275,7 +2275,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36729
36730 int hid_add_device(struct hid_device *hdev)
36731 {
36732- static atomic_t id = ATOMIC_INIT(0);
36733+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36734 int ret;
36735
36736 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36737@@ -2309,7 +2309,7 @@ int hid_add_device(struct hid_device *hdev)
36738 /* XXX hack, any other cleaner solution after the driver core
36739 * is converted to allow more than 20 bytes as the device name? */
36740 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36741- hdev->vendor, hdev->product, atomic_inc_return(&id));
36742+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36743
36744 hid_debug_register(hdev, dev_name(&hdev->dev));
36745 ret = device_add(&hdev->dev);
36746diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36747index 90124ff..3761764 100644
36748--- a/drivers/hid/hid-wiimote-debug.c
36749+++ b/drivers/hid/hid-wiimote-debug.c
36750@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36751 else if (size == 0)
36752 return -EIO;
36753
36754- if (copy_to_user(u, buf, size))
36755+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36756 return -EFAULT;
36757
36758 *off += size;
36759diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36760index 0b122f8..b1d8160 100644
36761--- a/drivers/hv/channel.c
36762+++ b/drivers/hv/channel.c
36763@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36764 int ret = 0;
36765 int t;
36766
36767- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36768- atomic_inc(&vmbus_connection.next_gpadl_handle);
36769+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36770+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36771
36772 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36773 if (ret)
36774diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36775index ae49237..380d4c9 100644
36776--- a/drivers/hv/hv.c
36777+++ b/drivers/hv/hv.c
36778@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36779 u64 output_address = (output) ? virt_to_phys(output) : 0;
36780 u32 output_address_hi = output_address >> 32;
36781 u32 output_address_lo = output_address & 0xFFFFFFFF;
36782- void *hypercall_page = hv_context.hypercall_page;
36783+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36784
36785 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36786 "=a"(hv_status_lo) : "d" (control_hi),
36787diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36788index 12f2f9e..679603c 100644
36789--- a/drivers/hv/hyperv_vmbus.h
36790+++ b/drivers/hv/hyperv_vmbus.h
36791@@ -591,7 +591,7 @@ enum vmbus_connect_state {
36792 struct vmbus_connection {
36793 enum vmbus_connect_state conn_state;
36794
36795- atomic_t next_gpadl_handle;
36796+ atomic_unchecked_t next_gpadl_handle;
36797
36798 /*
36799 * Represents channel interrupts. Each bit position represents a
36800diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36801index 4004e54..c2de226 100644
36802--- a/drivers/hv/vmbus_drv.c
36803+++ b/drivers/hv/vmbus_drv.c
36804@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36805 {
36806 int ret = 0;
36807
36808- static atomic_t device_num = ATOMIC_INIT(0);
36809+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36810
36811 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36812- atomic_inc_return(&device_num));
36813+ atomic_inc_return_unchecked(&device_num));
36814
36815 child_device_obj->device.bus = &hv_bus;
36816 child_device_obj->device.parent = &hv_acpi_dev->dev;
36817diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36818index 6351aba..dc4aaf4 100644
36819--- a/drivers/hwmon/acpi_power_meter.c
36820+++ b/drivers/hwmon/acpi_power_meter.c
36821@@ -117,7 +117,7 @@ struct sensor_template {
36822 struct device_attribute *devattr,
36823 const char *buf, size_t count);
36824 int index;
36825-};
36826+} __do_const;
36827
36828 /* Averaging interval */
36829 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36830@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36831 struct sensor_template *attrs)
36832 {
36833 struct device *dev = &resource->acpi_dev->dev;
36834- struct sensor_device_attribute *sensors =
36835+ sensor_device_attribute_no_const *sensors =
36836 &resource->sensors[resource->num_sensors];
36837 int res = 0;
36838
36839diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36840index 62c2e32..8f2859a 100644
36841--- a/drivers/hwmon/applesmc.c
36842+++ b/drivers/hwmon/applesmc.c
36843@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36844 {
36845 struct applesmc_node_group *grp;
36846 struct applesmc_dev_attr *node;
36847- struct attribute *attr;
36848+ attribute_no_const *attr;
36849 int ret, i;
36850
36851 for (grp = groups; grp->format; grp++) {
36852diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36853index b25c643..a13460d 100644
36854--- a/drivers/hwmon/asus_atk0110.c
36855+++ b/drivers/hwmon/asus_atk0110.c
36856@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36857 struct atk_sensor_data {
36858 struct list_head list;
36859 struct atk_data *data;
36860- struct device_attribute label_attr;
36861- struct device_attribute input_attr;
36862- struct device_attribute limit1_attr;
36863- struct device_attribute limit2_attr;
36864+ device_attribute_no_const label_attr;
36865+ device_attribute_no_const input_attr;
36866+ device_attribute_no_const limit1_attr;
36867+ device_attribute_no_const limit2_attr;
36868 char label_attr_name[ATTR_NAME_SIZE];
36869 char input_attr_name[ATTR_NAME_SIZE];
36870 char limit1_attr_name[ATTR_NAME_SIZE];
36871@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36872 static struct device_attribute atk_name_attr =
36873 __ATTR(name, 0444, atk_name_show, NULL);
36874
36875-static void atk_init_attribute(struct device_attribute *attr, char *name,
36876+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36877 sysfs_show_func show)
36878 {
36879 sysfs_attr_init(&attr->attr);
36880diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36881index 658ce3a..0d0c2f3 100644
36882--- a/drivers/hwmon/coretemp.c
36883+++ b/drivers/hwmon/coretemp.c
36884@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36885 return NOTIFY_OK;
36886 }
36887
36888-static struct notifier_block coretemp_cpu_notifier __refdata = {
36889+static struct notifier_block coretemp_cpu_notifier = {
36890 .notifier_call = coretemp_cpu_callback,
36891 };
36892
36893diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36894index 1429f6e..ee03d59 100644
36895--- a/drivers/hwmon/ibmaem.c
36896+++ b/drivers/hwmon/ibmaem.c
36897@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
36898 struct aem_rw_sensor_template *rw)
36899 {
36900 struct device *dev = &data->pdev->dev;
36901- struct sensor_device_attribute *sensors = data->sensors;
36902+ sensor_device_attribute_no_const *sensors = data->sensors;
36903 int err;
36904
36905 /* Set up read-only sensors */
36906diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
36907index 52b77af..aed1ddf 100644
36908--- a/drivers/hwmon/iio_hwmon.c
36909+++ b/drivers/hwmon/iio_hwmon.c
36910@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
36911 {
36912 struct device *dev = &pdev->dev;
36913 struct iio_hwmon_state *st;
36914- struct sensor_device_attribute *a;
36915+ sensor_device_attribute_no_const *a;
36916 int ret, i;
36917 int in_i = 1, temp_i = 1, curr_i = 1;
36918 enum iio_chan_type type;
36919diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36920index 9add6092..ee7ba3f 100644
36921--- a/drivers/hwmon/pmbus/pmbus_core.c
36922+++ b/drivers/hwmon/pmbus/pmbus_core.c
36923@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
36924 return 0;
36925 }
36926
36927-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36928+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
36929 const char *name,
36930 umode_t mode,
36931 ssize_t (*show)(struct device *dev,
36932@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36933 dev_attr->store = store;
36934 }
36935
36936-static void pmbus_attr_init(struct sensor_device_attribute *a,
36937+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
36938 const char *name,
36939 umode_t mode,
36940 ssize_t (*show)(struct device *dev,
36941@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
36942 u16 reg, u8 mask)
36943 {
36944 struct pmbus_boolean *boolean;
36945- struct sensor_device_attribute *a;
36946+ sensor_device_attribute_no_const *a;
36947
36948 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
36949 if (!boolean)
36950@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
36951 bool update, bool readonly)
36952 {
36953 struct pmbus_sensor *sensor;
36954- struct device_attribute *a;
36955+ device_attribute_no_const *a;
36956
36957 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
36958 if (!sensor)
36959@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
36960 const char *lstring, int index)
36961 {
36962 struct pmbus_label *label;
36963- struct device_attribute *a;
36964+ device_attribute_no_const *a;
36965
36966 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
36967 if (!label)
36968diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36969index 2507f90..1645765 100644
36970--- a/drivers/hwmon/sht15.c
36971+++ b/drivers/hwmon/sht15.c
36972@@ -169,7 +169,7 @@ struct sht15_data {
36973 int supply_uv;
36974 bool supply_uv_valid;
36975 struct work_struct update_supply_work;
36976- atomic_t interrupt_handled;
36977+ atomic_unchecked_t interrupt_handled;
36978 };
36979
36980 /**
36981@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
36982 ret = gpio_direction_input(data->pdata->gpio_data);
36983 if (ret)
36984 return ret;
36985- atomic_set(&data->interrupt_handled, 0);
36986+ atomic_set_unchecked(&data->interrupt_handled, 0);
36987
36988 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36989 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36990 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36991 /* Only relevant if the interrupt hasn't occurred. */
36992- if (!atomic_read(&data->interrupt_handled))
36993+ if (!atomic_read_unchecked(&data->interrupt_handled))
36994 schedule_work(&data->read_work);
36995 }
36996 ret = wait_event_timeout(data->wait_queue,
36997@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36998
36999 /* First disable the interrupt */
37000 disable_irq_nosync(irq);
37001- atomic_inc(&data->interrupt_handled);
37002+ atomic_inc_unchecked(&data->interrupt_handled);
37003 /* Then schedule a reading work struct */
37004 if (data->state != SHT15_READING_NOTHING)
37005 schedule_work(&data->read_work);
37006@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
37007 * If not, then start the interrupt again - care here as could
37008 * have gone low in meantime so verify it hasn't!
37009 */
37010- atomic_set(&data->interrupt_handled, 0);
37011+ atomic_set_unchecked(&data->interrupt_handled, 0);
37012 enable_irq(gpio_to_irq(data->pdata->gpio_data));
37013 /* If still not occurred or another handler was scheduled */
37014 if (gpio_get_value(data->pdata->gpio_data)
37015- || atomic_read(&data->interrupt_handled))
37016+ || atomic_read_unchecked(&data->interrupt_handled))
37017 return;
37018 }
37019
37020diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
37021index 76f157b..9c0db1b 100644
37022--- a/drivers/hwmon/via-cputemp.c
37023+++ b/drivers/hwmon/via-cputemp.c
37024@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
37025 return NOTIFY_OK;
37026 }
37027
37028-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
37029+static struct notifier_block via_cputemp_cpu_notifier = {
37030 .notifier_call = via_cputemp_cpu_callback,
37031 };
37032
37033diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
37034index 07f01ac..d79ad3d 100644
37035--- a/drivers/i2c/busses/i2c-amd756-s4882.c
37036+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
37037@@ -43,7 +43,7 @@
37038 extern struct i2c_adapter amd756_smbus;
37039
37040 static struct i2c_adapter *s4882_adapter;
37041-static struct i2c_algorithm *s4882_algo;
37042+static i2c_algorithm_no_const *s4882_algo;
37043
37044 /* Wrapper access functions for multiplexed SMBus */
37045 static DEFINE_MUTEX(amd756_lock);
37046diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
37047index 2ca268d..c6acbdf 100644
37048--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
37049+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
37050@@ -41,7 +41,7 @@
37051 extern struct i2c_adapter *nforce2_smbus;
37052
37053 static struct i2c_adapter *s4985_adapter;
37054-static struct i2c_algorithm *s4985_algo;
37055+static i2c_algorithm_no_const *s4985_algo;
37056
37057 /* Wrapper access functions for multiplexed SMBus */
37058 static DEFINE_MUTEX(nforce2_lock);
37059diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
37060index c3ccdea..5b3dc1a 100644
37061--- a/drivers/i2c/i2c-dev.c
37062+++ b/drivers/i2c/i2c-dev.c
37063@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
37064 break;
37065 }
37066
37067- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
37068+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
37069 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
37070 if (IS_ERR(rdwr_pa[i].buf)) {
37071 res = PTR_ERR(rdwr_pa[i].buf);
37072diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
37073index 2ff6204..218c16e 100644
37074--- a/drivers/ide/ide-cd.c
37075+++ b/drivers/ide/ide-cd.c
37076@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
37077 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
37078 if ((unsigned long)buf & alignment
37079 || blk_rq_bytes(rq) & q->dma_pad_mask
37080- || object_is_on_stack(buf))
37081+ || object_starts_on_stack(buf))
37082 drive->dma = 0;
37083 }
37084 }
37085diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
37086index e145931..08bfc59 100644
37087--- a/drivers/iio/industrialio-core.c
37088+++ b/drivers/iio/industrialio-core.c
37089@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
37090 }
37091
37092 static
37093-int __iio_device_attr_init(struct device_attribute *dev_attr,
37094+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
37095 const char *postfix,
37096 struct iio_chan_spec const *chan,
37097 ssize_t (*readfunc)(struct device *dev,
37098diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
37099index 784b97c..c9ceadf 100644
37100--- a/drivers/infiniband/core/cm.c
37101+++ b/drivers/infiniband/core/cm.c
37102@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
37103
37104 struct cm_counter_group {
37105 struct kobject obj;
37106- atomic_long_t counter[CM_ATTR_COUNT];
37107+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
37108 };
37109
37110 struct cm_counter_attribute {
37111@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
37112 struct ib_mad_send_buf *msg = NULL;
37113 int ret;
37114
37115- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37116+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37117 counter[CM_REQ_COUNTER]);
37118
37119 /* Quick state check to discard duplicate REQs. */
37120@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
37121 if (!cm_id_priv)
37122 return;
37123
37124- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37125+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37126 counter[CM_REP_COUNTER]);
37127 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
37128 if (ret)
37129@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
37130 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
37131 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
37132 spin_unlock_irq(&cm_id_priv->lock);
37133- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37134+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37135 counter[CM_RTU_COUNTER]);
37136 goto out;
37137 }
37138@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
37139 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
37140 dreq_msg->local_comm_id);
37141 if (!cm_id_priv) {
37142- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37143+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37144 counter[CM_DREQ_COUNTER]);
37145 cm_issue_drep(work->port, work->mad_recv_wc);
37146 return -EINVAL;
37147@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
37148 case IB_CM_MRA_REP_RCVD:
37149 break;
37150 case IB_CM_TIMEWAIT:
37151- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37152+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37153 counter[CM_DREQ_COUNTER]);
37154 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37155 goto unlock;
37156@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
37157 cm_free_msg(msg);
37158 goto deref;
37159 case IB_CM_DREQ_RCVD:
37160- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37161+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37162 counter[CM_DREQ_COUNTER]);
37163 goto unlock;
37164 default:
37165@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
37166 ib_modify_mad(cm_id_priv->av.port->mad_agent,
37167 cm_id_priv->msg, timeout)) {
37168 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
37169- atomic_long_inc(&work->port->
37170+ atomic_long_inc_unchecked(&work->port->
37171 counter_group[CM_RECV_DUPLICATES].
37172 counter[CM_MRA_COUNTER]);
37173 goto out;
37174@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
37175 break;
37176 case IB_CM_MRA_REQ_RCVD:
37177 case IB_CM_MRA_REP_RCVD:
37178- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37179+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37180 counter[CM_MRA_COUNTER]);
37181 /* fall through */
37182 default:
37183@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
37184 case IB_CM_LAP_IDLE:
37185 break;
37186 case IB_CM_MRA_LAP_SENT:
37187- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37188+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37189 counter[CM_LAP_COUNTER]);
37190 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37191 goto unlock;
37192@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
37193 cm_free_msg(msg);
37194 goto deref;
37195 case IB_CM_LAP_RCVD:
37196- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37197+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37198 counter[CM_LAP_COUNTER]);
37199 goto unlock;
37200 default:
37201@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
37202 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
37203 if (cur_cm_id_priv) {
37204 spin_unlock_irq(&cm.lock);
37205- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37206+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37207 counter[CM_SIDR_REQ_COUNTER]);
37208 goto out; /* Duplicate message. */
37209 }
37210@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
37211 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
37212 msg->retries = 1;
37213
37214- atomic_long_add(1 + msg->retries,
37215+ atomic_long_add_unchecked(1 + msg->retries,
37216 &port->counter_group[CM_XMIT].counter[attr_index]);
37217 if (msg->retries)
37218- atomic_long_add(msg->retries,
37219+ atomic_long_add_unchecked(msg->retries,
37220 &port->counter_group[CM_XMIT_RETRIES].
37221 counter[attr_index]);
37222
37223@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
37224 }
37225
37226 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
37227- atomic_long_inc(&port->counter_group[CM_RECV].
37228+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
37229 counter[attr_id - CM_ATTR_ID_OFFSET]);
37230
37231 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
37232@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
37233 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
37234
37235 return sprintf(buf, "%ld\n",
37236- atomic_long_read(&group->counter[cm_attr->index]));
37237+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
37238 }
37239
37240 static const struct sysfs_ops cm_counter_ops = {
37241diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
37242index 9f5ad7c..588cd84 100644
37243--- a/drivers/infiniband/core/fmr_pool.c
37244+++ b/drivers/infiniband/core/fmr_pool.c
37245@@ -98,8 +98,8 @@ struct ib_fmr_pool {
37246
37247 struct task_struct *thread;
37248
37249- atomic_t req_ser;
37250- atomic_t flush_ser;
37251+ atomic_unchecked_t req_ser;
37252+ atomic_unchecked_t flush_ser;
37253
37254 wait_queue_head_t force_wait;
37255 };
37256@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37257 struct ib_fmr_pool *pool = pool_ptr;
37258
37259 do {
37260- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
37261+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
37262 ib_fmr_batch_release(pool);
37263
37264- atomic_inc(&pool->flush_ser);
37265+ atomic_inc_unchecked(&pool->flush_ser);
37266 wake_up_interruptible(&pool->force_wait);
37267
37268 if (pool->flush_function)
37269@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37270 }
37271
37272 set_current_state(TASK_INTERRUPTIBLE);
37273- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
37274+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
37275 !kthread_should_stop())
37276 schedule();
37277 __set_current_state(TASK_RUNNING);
37278@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
37279 pool->dirty_watermark = params->dirty_watermark;
37280 pool->dirty_len = 0;
37281 spin_lock_init(&pool->pool_lock);
37282- atomic_set(&pool->req_ser, 0);
37283- atomic_set(&pool->flush_ser, 0);
37284+ atomic_set_unchecked(&pool->req_ser, 0);
37285+ atomic_set_unchecked(&pool->flush_ser, 0);
37286 init_waitqueue_head(&pool->force_wait);
37287
37288 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37289@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37290 }
37291 spin_unlock_irq(&pool->pool_lock);
37292
37293- serial = atomic_inc_return(&pool->req_ser);
37294+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37295 wake_up_process(pool->thread);
37296
37297 if (wait_event_interruptible(pool->force_wait,
37298- atomic_read(&pool->flush_ser) - serial >= 0))
37299+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37300 return -EINTR;
37301
37302 return 0;
37303@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37304 } else {
37305 list_add_tail(&fmr->list, &pool->dirty_list);
37306 if (++pool->dirty_len >= pool->dirty_watermark) {
37307- atomic_inc(&pool->req_ser);
37308+ atomic_inc_unchecked(&pool->req_ser);
37309 wake_up_process(pool->thread);
37310 }
37311 }
37312diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37313index 4cb8eb2..146bf60 100644
37314--- a/drivers/infiniband/hw/cxgb4/mem.c
37315+++ b/drivers/infiniband/hw/cxgb4/mem.c
37316@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37317 int err;
37318 struct fw_ri_tpte tpt;
37319 u32 stag_idx;
37320- static atomic_t key;
37321+ static atomic_unchecked_t key;
37322
37323 if (c4iw_fatal_error(rdev))
37324 return -EIO;
37325@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37326 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37327 rdev->stats.stag.max = rdev->stats.stag.cur;
37328 mutex_unlock(&rdev->stats.lock);
37329- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37330+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37331 }
37332 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37333 __func__, stag_state, type, pdid, stag_idx);
37334diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37335index 79b3dbc..96e5fcc 100644
37336--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37337+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37338@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37339 struct ib_atomic_eth *ateth;
37340 struct ipath_ack_entry *e;
37341 u64 vaddr;
37342- atomic64_t *maddr;
37343+ atomic64_unchecked_t *maddr;
37344 u64 sdata;
37345 u32 rkey;
37346 u8 next;
37347@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37348 IB_ACCESS_REMOTE_ATOMIC)))
37349 goto nack_acc_unlck;
37350 /* Perform atomic OP and save result. */
37351- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37352+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37353 sdata = be64_to_cpu(ateth->swap_data);
37354 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37355 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37356- (u64) atomic64_add_return(sdata, maddr) - sdata :
37357+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37358 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37359 be64_to_cpu(ateth->compare_data),
37360 sdata);
37361diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37362index 1f95bba..9530f87 100644
37363--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37364+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37365@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37366 unsigned long flags;
37367 struct ib_wc wc;
37368 u64 sdata;
37369- atomic64_t *maddr;
37370+ atomic64_unchecked_t *maddr;
37371 enum ib_wc_status send_status;
37372
37373 /*
37374@@ -382,11 +382,11 @@ again:
37375 IB_ACCESS_REMOTE_ATOMIC)))
37376 goto acc_err;
37377 /* Perform atomic OP and save result. */
37378- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37379+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37380 sdata = wqe->wr.wr.atomic.compare_add;
37381 *(u64 *) sqp->s_sge.sge.vaddr =
37382 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37383- (u64) atomic64_add_return(sdata, maddr) - sdata :
37384+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37385 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37386 sdata, wqe->wr.wr.atomic.swap);
37387 goto send_comp;
37388diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37389index 9d3e5c1..d9afe4a 100644
37390--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37391+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37392@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37393 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37394 }
37395
37396-int mthca_QUERY_FW(struct mthca_dev *dev)
37397+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37398 {
37399 struct mthca_mailbox *mailbox;
37400 u32 *outbox;
37401diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37402index ed9a989..e0c5871 100644
37403--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37404+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37405@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37406 return key;
37407 }
37408
37409-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37410+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37411 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37412 {
37413 struct mthca_mailbox *mailbox;
37414diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37415index 4291410..d2ab1fb 100644
37416--- a/drivers/infiniband/hw/nes/nes.c
37417+++ b/drivers/infiniband/hw/nes/nes.c
37418@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37419 LIST_HEAD(nes_adapter_list);
37420 static LIST_HEAD(nes_dev_list);
37421
37422-atomic_t qps_destroyed;
37423+atomic_unchecked_t qps_destroyed;
37424
37425 static unsigned int ee_flsh_adapter;
37426 static unsigned int sysfs_nonidx_addr;
37427@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37428 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37429 struct nes_adapter *nesadapter = nesdev->nesadapter;
37430
37431- atomic_inc(&qps_destroyed);
37432+ atomic_inc_unchecked(&qps_destroyed);
37433
37434 /* Free the control structures */
37435
37436diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37437index 33cc589..3bd6538 100644
37438--- a/drivers/infiniband/hw/nes/nes.h
37439+++ b/drivers/infiniband/hw/nes/nes.h
37440@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37441 extern unsigned int wqm_quanta;
37442 extern struct list_head nes_adapter_list;
37443
37444-extern atomic_t cm_connects;
37445-extern atomic_t cm_accepts;
37446-extern atomic_t cm_disconnects;
37447-extern atomic_t cm_closes;
37448-extern atomic_t cm_connecteds;
37449-extern atomic_t cm_connect_reqs;
37450-extern atomic_t cm_rejects;
37451-extern atomic_t mod_qp_timouts;
37452-extern atomic_t qps_created;
37453-extern atomic_t qps_destroyed;
37454-extern atomic_t sw_qps_destroyed;
37455+extern atomic_unchecked_t cm_connects;
37456+extern atomic_unchecked_t cm_accepts;
37457+extern atomic_unchecked_t cm_disconnects;
37458+extern atomic_unchecked_t cm_closes;
37459+extern atomic_unchecked_t cm_connecteds;
37460+extern atomic_unchecked_t cm_connect_reqs;
37461+extern atomic_unchecked_t cm_rejects;
37462+extern atomic_unchecked_t mod_qp_timouts;
37463+extern atomic_unchecked_t qps_created;
37464+extern atomic_unchecked_t qps_destroyed;
37465+extern atomic_unchecked_t sw_qps_destroyed;
37466 extern u32 mh_detected;
37467 extern u32 mh_pauses_sent;
37468 extern u32 cm_packets_sent;
37469@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37470 extern u32 cm_packets_received;
37471 extern u32 cm_packets_dropped;
37472 extern u32 cm_packets_retrans;
37473-extern atomic_t cm_listens_created;
37474-extern atomic_t cm_listens_destroyed;
37475+extern atomic_unchecked_t cm_listens_created;
37476+extern atomic_unchecked_t cm_listens_destroyed;
37477 extern u32 cm_backlog_drops;
37478-extern atomic_t cm_loopbacks;
37479-extern atomic_t cm_nodes_created;
37480-extern atomic_t cm_nodes_destroyed;
37481-extern atomic_t cm_accel_dropped_pkts;
37482-extern atomic_t cm_resets_recvd;
37483-extern atomic_t pau_qps_created;
37484-extern atomic_t pau_qps_destroyed;
37485+extern atomic_unchecked_t cm_loopbacks;
37486+extern atomic_unchecked_t cm_nodes_created;
37487+extern atomic_unchecked_t cm_nodes_destroyed;
37488+extern atomic_unchecked_t cm_accel_dropped_pkts;
37489+extern atomic_unchecked_t cm_resets_recvd;
37490+extern atomic_unchecked_t pau_qps_created;
37491+extern atomic_unchecked_t pau_qps_destroyed;
37492
37493 extern u32 int_mod_timer_init;
37494 extern u32 int_mod_cq_depth_256;
37495diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37496index 24b9f1a..00fd004 100644
37497--- a/drivers/infiniband/hw/nes/nes_cm.c
37498+++ b/drivers/infiniband/hw/nes/nes_cm.c
37499@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37500 u32 cm_packets_retrans;
37501 u32 cm_packets_created;
37502 u32 cm_packets_received;
37503-atomic_t cm_listens_created;
37504-atomic_t cm_listens_destroyed;
37505+atomic_unchecked_t cm_listens_created;
37506+atomic_unchecked_t cm_listens_destroyed;
37507 u32 cm_backlog_drops;
37508-atomic_t cm_loopbacks;
37509-atomic_t cm_nodes_created;
37510-atomic_t cm_nodes_destroyed;
37511-atomic_t cm_accel_dropped_pkts;
37512-atomic_t cm_resets_recvd;
37513+atomic_unchecked_t cm_loopbacks;
37514+atomic_unchecked_t cm_nodes_created;
37515+atomic_unchecked_t cm_nodes_destroyed;
37516+atomic_unchecked_t cm_accel_dropped_pkts;
37517+atomic_unchecked_t cm_resets_recvd;
37518
37519 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37520 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37521@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37522
37523 static struct nes_cm_core *g_cm_core;
37524
37525-atomic_t cm_connects;
37526-atomic_t cm_accepts;
37527-atomic_t cm_disconnects;
37528-atomic_t cm_closes;
37529-atomic_t cm_connecteds;
37530-atomic_t cm_connect_reqs;
37531-atomic_t cm_rejects;
37532+atomic_unchecked_t cm_connects;
37533+atomic_unchecked_t cm_accepts;
37534+atomic_unchecked_t cm_disconnects;
37535+atomic_unchecked_t cm_closes;
37536+atomic_unchecked_t cm_connecteds;
37537+atomic_unchecked_t cm_connect_reqs;
37538+atomic_unchecked_t cm_rejects;
37539
37540 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37541 {
37542@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37543 kfree(listener);
37544 listener = NULL;
37545 ret = 0;
37546- atomic_inc(&cm_listens_destroyed);
37547+ atomic_inc_unchecked(&cm_listens_destroyed);
37548 } else {
37549 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37550 }
37551@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37552 cm_node->rem_mac);
37553
37554 add_hte_node(cm_core, cm_node);
37555- atomic_inc(&cm_nodes_created);
37556+ atomic_inc_unchecked(&cm_nodes_created);
37557
37558 return cm_node;
37559 }
37560@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37561 }
37562
37563 atomic_dec(&cm_core->node_cnt);
37564- atomic_inc(&cm_nodes_destroyed);
37565+ atomic_inc_unchecked(&cm_nodes_destroyed);
37566 nesqp = cm_node->nesqp;
37567 if (nesqp) {
37568 nesqp->cm_node = NULL;
37569@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37570
37571 static void drop_packet(struct sk_buff *skb)
37572 {
37573- atomic_inc(&cm_accel_dropped_pkts);
37574+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37575 dev_kfree_skb_any(skb);
37576 }
37577
37578@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37579 {
37580
37581 int reset = 0; /* whether to send reset in case of err.. */
37582- atomic_inc(&cm_resets_recvd);
37583+ atomic_inc_unchecked(&cm_resets_recvd);
37584 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37585 " refcnt=%d\n", cm_node, cm_node->state,
37586 atomic_read(&cm_node->ref_count));
37587@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37588 rem_ref_cm_node(cm_node->cm_core, cm_node);
37589 return NULL;
37590 }
37591- atomic_inc(&cm_loopbacks);
37592+ atomic_inc_unchecked(&cm_loopbacks);
37593 loopbackremotenode->loopbackpartner = cm_node;
37594 loopbackremotenode->tcp_cntxt.rcv_wscale =
37595 NES_CM_DEFAULT_RCV_WND_SCALE;
37596@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37597 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37598 else {
37599 rem_ref_cm_node(cm_core, cm_node);
37600- atomic_inc(&cm_accel_dropped_pkts);
37601+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37602 dev_kfree_skb_any(skb);
37603 }
37604 break;
37605@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37606
37607 if ((cm_id) && (cm_id->event_handler)) {
37608 if (issue_disconn) {
37609- atomic_inc(&cm_disconnects);
37610+ atomic_inc_unchecked(&cm_disconnects);
37611 cm_event.event = IW_CM_EVENT_DISCONNECT;
37612 cm_event.status = disconn_status;
37613 cm_event.local_addr = cm_id->local_addr;
37614@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37615 }
37616
37617 if (issue_close) {
37618- atomic_inc(&cm_closes);
37619+ atomic_inc_unchecked(&cm_closes);
37620 nes_disconnect(nesqp, 1);
37621
37622 cm_id->provider_data = nesqp;
37623@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37624
37625 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37626 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37627- atomic_inc(&cm_accepts);
37628+ atomic_inc_unchecked(&cm_accepts);
37629
37630 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37631 netdev_refcnt_read(nesvnic->netdev));
37632@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37633 struct nes_cm_core *cm_core;
37634 u8 *start_buff;
37635
37636- atomic_inc(&cm_rejects);
37637+ atomic_inc_unchecked(&cm_rejects);
37638 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37639 loopback = cm_node->loopbackpartner;
37640 cm_core = cm_node->cm_core;
37641@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37642 ntohl(cm_id->local_addr.sin_addr.s_addr),
37643 ntohs(cm_id->local_addr.sin_port));
37644
37645- atomic_inc(&cm_connects);
37646+ atomic_inc_unchecked(&cm_connects);
37647 nesqp->active_conn = 1;
37648
37649 /* cache the cm_id in the qp */
37650@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37651 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37652 return err;
37653 }
37654- atomic_inc(&cm_listens_created);
37655+ atomic_inc_unchecked(&cm_listens_created);
37656 }
37657
37658 cm_id->add_ref(cm_id);
37659@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37660
37661 if (nesqp->destroyed)
37662 return;
37663- atomic_inc(&cm_connecteds);
37664+ atomic_inc_unchecked(&cm_connecteds);
37665 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37666 " local port 0x%04X. jiffies = %lu.\n",
37667 nesqp->hwqp.qp_id,
37668@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37669
37670 cm_id->add_ref(cm_id);
37671 ret = cm_id->event_handler(cm_id, &cm_event);
37672- atomic_inc(&cm_closes);
37673+ atomic_inc_unchecked(&cm_closes);
37674 cm_event.event = IW_CM_EVENT_CLOSE;
37675 cm_event.status = 0;
37676 cm_event.provider_data = cm_id->provider_data;
37677@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37678 return;
37679 cm_id = cm_node->cm_id;
37680
37681- atomic_inc(&cm_connect_reqs);
37682+ atomic_inc_unchecked(&cm_connect_reqs);
37683 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37684 cm_node, cm_id, jiffies);
37685
37686@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37687 return;
37688 cm_id = cm_node->cm_id;
37689
37690- atomic_inc(&cm_connect_reqs);
37691+ atomic_inc_unchecked(&cm_connect_reqs);
37692 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37693 cm_node, cm_id, jiffies);
37694
37695diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37696index 4166452..fc952c3 100644
37697--- a/drivers/infiniband/hw/nes/nes_mgt.c
37698+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37699@@ -40,8 +40,8 @@
37700 #include "nes.h"
37701 #include "nes_mgt.h"
37702
37703-atomic_t pau_qps_created;
37704-atomic_t pau_qps_destroyed;
37705+atomic_unchecked_t pau_qps_created;
37706+atomic_unchecked_t pau_qps_destroyed;
37707
37708 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37709 {
37710@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37711 {
37712 struct sk_buff *skb;
37713 unsigned long flags;
37714- atomic_inc(&pau_qps_destroyed);
37715+ atomic_inc_unchecked(&pau_qps_destroyed);
37716
37717 /* Free packets that have not yet been forwarded */
37718 /* Lock is acquired by skb_dequeue when removing the skb */
37719@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37720 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37721 skb_queue_head_init(&nesqp->pau_list);
37722 spin_lock_init(&nesqp->pau_lock);
37723- atomic_inc(&pau_qps_created);
37724+ atomic_inc_unchecked(&pau_qps_created);
37725 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37726 }
37727
37728diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37729index 49eb511..a774366 100644
37730--- a/drivers/infiniband/hw/nes/nes_nic.c
37731+++ b/drivers/infiniband/hw/nes/nes_nic.c
37732@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37733 target_stat_values[++index] = mh_detected;
37734 target_stat_values[++index] = mh_pauses_sent;
37735 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37736- target_stat_values[++index] = atomic_read(&cm_connects);
37737- target_stat_values[++index] = atomic_read(&cm_accepts);
37738- target_stat_values[++index] = atomic_read(&cm_disconnects);
37739- target_stat_values[++index] = atomic_read(&cm_connecteds);
37740- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37741- target_stat_values[++index] = atomic_read(&cm_rejects);
37742- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37743- target_stat_values[++index] = atomic_read(&qps_created);
37744- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37745- target_stat_values[++index] = atomic_read(&qps_destroyed);
37746- target_stat_values[++index] = atomic_read(&cm_closes);
37747+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37748+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37749+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37750+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37751+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37752+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37753+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37754+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37755+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37756+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37757+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37758 target_stat_values[++index] = cm_packets_sent;
37759 target_stat_values[++index] = cm_packets_bounced;
37760 target_stat_values[++index] = cm_packets_created;
37761 target_stat_values[++index] = cm_packets_received;
37762 target_stat_values[++index] = cm_packets_dropped;
37763 target_stat_values[++index] = cm_packets_retrans;
37764- target_stat_values[++index] = atomic_read(&cm_listens_created);
37765- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37766+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37767+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37768 target_stat_values[++index] = cm_backlog_drops;
37769- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37770- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37771- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37772- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37773- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37774+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37775+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37776+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37777+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37778+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37779 target_stat_values[++index] = nesadapter->free_4kpbl;
37780 target_stat_values[++index] = nesadapter->free_256pbl;
37781 target_stat_values[++index] = int_mod_timer_init;
37782 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37783 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37784 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37785- target_stat_values[++index] = atomic_read(&pau_qps_created);
37786- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37787+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37788+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37789 }
37790
37791 /**
37792diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37793index 8f67fe2..8960859 100644
37794--- a/drivers/infiniband/hw/nes/nes_verbs.c
37795+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37796@@ -46,9 +46,9 @@
37797
37798 #include <rdma/ib_umem.h>
37799
37800-atomic_t mod_qp_timouts;
37801-atomic_t qps_created;
37802-atomic_t sw_qps_destroyed;
37803+atomic_unchecked_t mod_qp_timouts;
37804+atomic_unchecked_t qps_created;
37805+atomic_unchecked_t sw_qps_destroyed;
37806
37807 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37808
37809@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37810 if (init_attr->create_flags)
37811 return ERR_PTR(-EINVAL);
37812
37813- atomic_inc(&qps_created);
37814+ atomic_inc_unchecked(&qps_created);
37815 switch (init_attr->qp_type) {
37816 case IB_QPT_RC:
37817 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37818@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37819 struct iw_cm_event cm_event;
37820 int ret = 0;
37821
37822- atomic_inc(&sw_qps_destroyed);
37823+ atomic_inc_unchecked(&sw_qps_destroyed);
37824 nesqp->destroyed = 1;
37825
37826 /* Blow away the connection if it exists. */
37827diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37828index 4d11575..3e890e5 100644
37829--- a/drivers/infiniband/hw/qib/qib.h
37830+++ b/drivers/infiniband/hw/qib/qib.h
37831@@ -51,6 +51,7 @@
37832 #include <linux/completion.h>
37833 #include <linux/kref.h>
37834 #include <linux/sched.h>
37835+#include <linux/slab.h>
37836
37837 #include "qib_common.h"
37838 #include "qib_verbs.h"
37839diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37840index da739d9..da1c7f4 100644
37841--- a/drivers/input/gameport/gameport.c
37842+++ b/drivers/input/gameport/gameport.c
37843@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37844 */
37845 static void gameport_init_port(struct gameport *gameport)
37846 {
37847- static atomic_t gameport_no = ATOMIC_INIT(0);
37848+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37849
37850 __module_get(THIS_MODULE);
37851
37852 mutex_init(&gameport->drv_mutex);
37853 device_initialize(&gameport->dev);
37854 dev_set_name(&gameport->dev, "gameport%lu",
37855- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37856+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37857 gameport->dev.bus = &gameport_bus;
37858 gameport->dev.release = gameport_release_port;
37859 if (gameport->parent)
37860diff --git a/drivers/input/input.c b/drivers/input/input.c
37861index c044699..174d71a 100644
37862--- a/drivers/input/input.c
37863+++ b/drivers/input/input.c
37864@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37865 */
37866 int input_register_device(struct input_dev *dev)
37867 {
37868- static atomic_t input_no = ATOMIC_INIT(0);
37869+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37870 struct input_devres *devres = NULL;
37871 struct input_handler *handler;
37872 unsigned int packet_size;
37873@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37874 dev->setkeycode = input_default_setkeycode;
37875
37876 dev_set_name(&dev->dev, "input%ld",
37877- (unsigned long) atomic_inc_return(&input_no) - 1);
37878+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37879
37880 error = device_add(&dev->dev);
37881 if (error)
37882diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37883index 04c69af..5f92d00 100644
37884--- a/drivers/input/joystick/sidewinder.c
37885+++ b/drivers/input/joystick/sidewinder.c
37886@@ -30,6 +30,7 @@
37887 #include <linux/kernel.h>
37888 #include <linux/module.h>
37889 #include <linux/slab.h>
37890+#include <linux/sched.h>
37891 #include <linux/init.h>
37892 #include <linux/input.h>
37893 #include <linux/gameport.h>
37894diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37895index fa061d4..4a6957c 100644
37896--- a/drivers/input/joystick/xpad.c
37897+++ b/drivers/input/joystick/xpad.c
37898@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37899
37900 static int xpad_led_probe(struct usb_xpad *xpad)
37901 {
37902- static atomic_t led_seq = ATOMIC_INIT(0);
37903+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37904 long led_no;
37905 struct xpad_led *led;
37906 struct led_classdev *led_cdev;
37907@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37908 if (!led)
37909 return -ENOMEM;
37910
37911- led_no = (long)atomic_inc_return(&led_seq) - 1;
37912+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37913
37914 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37915 led->xpad = xpad;
37916diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37917index 2f0b39d..7370f13 100644
37918--- a/drivers/input/mouse/psmouse.h
37919+++ b/drivers/input/mouse/psmouse.h
37920@@ -116,7 +116,7 @@ struct psmouse_attribute {
37921 ssize_t (*set)(struct psmouse *psmouse, void *data,
37922 const char *buf, size_t count);
37923 bool protect;
37924-};
37925+} __do_const;
37926 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37927
37928 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37929diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37930index 4c842c3..590b0bf 100644
37931--- a/drivers/input/mousedev.c
37932+++ b/drivers/input/mousedev.c
37933@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37934
37935 spin_unlock_irq(&client->packet_lock);
37936
37937- if (copy_to_user(buffer, data, count))
37938+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37939 return -EFAULT;
37940
37941 return count;
37942diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37943index 25fc597..558bf3b3 100644
37944--- a/drivers/input/serio/serio.c
37945+++ b/drivers/input/serio/serio.c
37946@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37947 */
37948 static void serio_init_port(struct serio *serio)
37949 {
37950- static atomic_t serio_no = ATOMIC_INIT(0);
37951+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37952
37953 __module_get(THIS_MODULE);
37954
37955@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37956 mutex_init(&serio->drv_mutex);
37957 device_initialize(&serio->dev);
37958 dev_set_name(&serio->dev, "serio%ld",
37959- (long)atomic_inc_return(&serio_no) - 1);
37960+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37961 serio->dev.bus = &serio_bus;
37962 serio->dev.release = serio_release_port;
37963 serio->dev.groups = serio_device_attr_groups;
37964diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37965index d8f98b1..f62a640 100644
37966--- a/drivers/iommu/iommu.c
37967+++ b/drivers/iommu/iommu.c
37968@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
37969 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37970 {
37971 bus_register_notifier(bus, &iommu_bus_nb);
37972- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37973+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37974 }
37975
37976 /**
37977diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
37978index dcfea4e..f4226b2 100644
37979--- a/drivers/iommu/irq_remapping.c
37980+++ b/drivers/iommu/irq_remapping.c
37981@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
37982 void panic_if_irq_remap(const char *msg)
37983 {
37984 if (irq_remapping_enabled)
37985- panic(msg);
37986+ panic("%s", msg);
37987 }
37988
37989 static void ir_ack_apic_edge(struct irq_data *data)
37990@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
37991
37992 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
37993 {
37994- chip->irq_print_chip = ir_print_prefix;
37995- chip->irq_ack = ir_ack_apic_edge;
37996- chip->irq_eoi = ir_ack_apic_level;
37997- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37998+ pax_open_kernel();
37999+ *(void **)&chip->irq_print_chip = ir_print_prefix;
38000+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
38001+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
38002+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
38003+ pax_close_kernel();
38004 }
38005
38006 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
38007diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
38008index 19ceaa6..3625818 100644
38009--- a/drivers/irqchip/irq-gic.c
38010+++ b/drivers/irqchip/irq-gic.c
38011@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
38012 * Supported arch specific GIC irq extension.
38013 * Default make them NULL.
38014 */
38015-struct irq_chip gic_arch_extn = {
38016+irq_chip_no_const gic_arch_extn = {
38017 .irq_eoi = NULL,
38018 .irq_mask = NULL,
38019 .irq_unmask = NULL,
38020@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
38021 chained_irq_exit(chip, desc);
38022 }
38023
38024-static struct irq_chip gic_chip = {
38025+static irq_chip_no_const gic_chip __read_only = {
38026 .name = "GIC",
38027 .irq_mask = gic_mask_irq,
38028 .irq_unmask = gic_unmask_irq,
38029diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
38030index ac6f72b..81150f2 100644
38031--- a/drivers/isdn/capi/capi.c
38032+++ b/drivers/isdn/capi/capi.c
38033@@ -81,8 +81,8 @@ struct capiminor {
38034
38035 struct capi20_appl *ap;
38036 u32 ncci;
38037- atomic_t datahandle;
38038- atomic_t msgid;
38039+ atomic_unchecked_t datahandle;
38040+ atomic_unchecked_t msgid;
38041
38042 struct tty_port port;
38043 int ttyinstop;
38044@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
38045 capimsg_setu16(s, 2, mp->ap->applid);
38046 capimsg_setu8 (s, 4, CAPI_DATA_B3);
38047 capimsg_setu8 (s, 5, CAPI_RESP);
38048- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
38049+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
38050 capimsg_setu32(s, 8, mp->ncci);
38051 capimsg_setu16(s, 12, datahandle);
38052 }
38053@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
38054 mp->outbytes -= len;
38055 spin_unlock_bh(&mp->outlock);
38056
38057- datahandle = atomic_inc_return(&mp->datahandle);
38058+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
38059 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
38060 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
38061 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
38062 capimsg_setu16(skb->data, 2, mp->ap->applid);
38063 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
38064 capimsg_setu8 (skb->data, 5, CAPI_REQ);
38065- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
38066+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
38067 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
38068 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
38069 capimsg_setu16(skb->data, 16, len); /* Data length */
38070diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
38071index 600c79b..3752bab 100644
38072--- a/drivers/isdn/gigaset/interface.c
38073+++ b/drivers/isdn/gigaset/interface.c
38074@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
38075 }
38076 tty->driver_data = cs;
38077
38078- ++cs->port.count;
38079+ atomic_inc(&cs->port.count);
38080
38081- if (cs->port.count == 1) {
38082+ if (atomic_read(&cs->port.count) == 1) {
38083 tty_port_tty_set(&cs->port, tty);
38084 cs->port.low_latency = 1;
38085 }
38086@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
38087
38088 if (!cs->connected)
38089 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
38090- else if (!cs->port.count)
38091+ else if (!atomic_read(&cs->port.count))
38092 dev_warn(cs->dev, "%s: device not opened\n", __func__);
38093- else if (!--cs->port.count)
38094+ else if (!atomic_dec_return(&cs->port.count))
38095 tty_port_tty_set(&cs->port, NULL);
38096
38097 mutex_unlock(&cs->mutex);
38098diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
38099index 4d9b195..455075c 100644
38100--- a/drivers/isdn/hardware/avm/b1.c
38101+++ b/drivers/isdn/hardware/avm/b1.c
38102@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
38103 }
38104 if (left) {
38105 if (t4file->user) {
38106- if (copy_from_user(buf, dp, left))
38107+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38108 return -EFAULT;
38109 } else {
38110 memcpy(buf, dp, left);
38111@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
38112 }
38113 if (left) {
38114 if (config->user) {
38115- if (copy_from_user(buf, dp, left))
38116+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38117 return -EFAULT;
38118 } else {
38119 memcpy(buf, dp, left);
38120diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
38121index 3c5f249..5fac4d0 100644
38122--- a/drivers/isdn/i4l/isdn_tty.c
38123+++ b/drivers/isdn/i4l/isdn_tty.c
38124@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
38125
38126 #ifdef ISDN_DEBUG_MODEM_OPEN
38127 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
38128- port->count);
38129+ atomic_read(&port->count));
38130 #endif
38131- port->count++;
38132+ atomic_inc(&port->count);
38133 port->tty = tty;
38134 /*
38135 * Start up serial port
38136@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38137 #endif
38138 return;
38139 }
38140- if ((tty->count == 1) && (port->count != 1)) {
38141+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
38142 /*
38143 * Uh, oh. tty->count is 1, which means that the tty
38144 * structure will be freed. Info->count should always
38145@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38146 * serial port won't be shutdown.
38147 */
38148 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
38149- "info->count is %d\n", port->count);
38150- port->count = 1;
38151+ "info->count is %d\n", atomic_read(&port->count));
38152+ atomic_set(&port->count, 1);
38153 }
38154- if (--port->count < 0) {
38155+ if (atomic_dec_return(&port->count) < 0) {
38156 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
38157- info->line, port->count);
38158- port->count = 0;
38159+ info->line, atomic_read(&port->count));
38160+ atomic_set(&port->count, 0);
38161 }
38162- if (port->count) {
38163+ if (atomic_read(&port->count)) {
38164 #ifdef ISDN_DEBUG_MODEM_OPEN
38165 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
38166 #endif
38167@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
38168 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
38169 return;
38170 isdn_tty_shutdown(info);
38171- port->count = 0;
38172+ atomic_set(&port->count, 0);
38173 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38174 port->tty = NULL;
38175 wake_up_interruptible(&port->open_wait);
38176@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
38177 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
38178 modem_info *info = &dev->mdm.info[i];
38179
38180- if (info->port.count == 0)
38181+ if (atomic_read(&info->port.count) == 0)
38182 continue;
38183 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
38184 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
38185diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
38186index e74df7c..03a03ba 100644
38187--- a/drivers/isdn/icn/icn.c
38188+++ b/drivers/isdn/icn/icn.c
38189@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
38190 if (count > len)
38191 count = len;
38192 if (user) {
38193- if (copy_from_user(msg, buf, count))
38194+ if (count > sizeof msg || copy_from_user(msg, buf, count))
38195 return -EFAULT;
38196 } else
38197 memcpy(msg, buf, count);
38198diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
38199index 6a8405d..0bd1c7e 100644
38200--- a/drivers/leds/leds-clevo-mail.c
38201+++ b/drivers/leds/leds-clevo-mail.c
38202@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
38203 * detected as working, but in reality it is not) as low as
38204 * possible.
38205 */
38206-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
38207+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
38208 {
38209 .callback = clevo_mail_led_dmi_callback,
38210 .ident = "Clevo D410J",
38211diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
38212index 64e204e..c6bf189 100644
38213--- a/drivers/leds/leds-ss4200.c
38214+++ b/drivers/leds/leds-ss4200.c
38215@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
38216 * detected as working, but in reality it is not) as low as
38217 * possible.
38218 */
38219-static struct dmi_system_id __initdata nas_led_whitelist[] = {
38220+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
38221 {
38222 .callback = ss4200_led_dmi_callback,
38223 .ident = "Intel SS4200-E",
38224diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
38225index 0bf1e4e..b4bf44e 100644
38226--- a/drivers/lguest/core.c
38227+++ b/drivers/lguest/core.c
38228@@ -97,9 +97,17 @@ static __init int map_switcher(void)
38229 * The end address needs +1 because __get_vm_area allocates an
38230 * extra guard page, so we need space for that.
38231 */
38232+
38233+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
38234+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38235+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
38236+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38237+#else
38238 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38239 VM_ALLOC, switcher_addr, switcher_addr
38240 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38241+#endif
38242+
38243 if (!switcher_vma) {
38244 err = -ENOMEM;
38245 printk("lguest: could not map switcher pages high\n");
38246@@ -124,7 +132,7 @@ static __init int map_switcher(void)
38247 * Now the Switcher is mapped at the right address, we can't fail!
38248 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
38249 */
38250- memcpy(switcher_vma->addr, start_switcher_text,
38251+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
38252 end_switcher_text - start_switcher_text);
38253
38254 printk(KERN_INFO "lguest: mapped switcher at %p\n",
38255diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
38256index 5b9ac32..2ef4f26 100644
38257--- a/drivers/lguest/page_tables.c
38258+++ b/drivers/lguest/page_tables.c
38259@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
38260 /*:*/
38261
38262 #ifdef CONFIG_X86_PAE
38263-static void release_pmd(pmd_t *spmd)
38264+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
38265 {
38266 /* If the entry's not present, there's nothing to release. */
38267 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
38268diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
38269index f0a3347..f6608b2 100644
38270--- a/drivers/lguest/x86/core.c
38271+++ b/drivers/lguest/x86/core.c
38272@@ -59,7 +59,7 @@ static struct {
38273 /* Offset from where switcher.S was compiled to where we've copied it */
38274 static unsigned long switcher_offset(void)
38275 {
38276- return switcher_addr - (unsigned long)start_switcher_text;
38277+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
38278 }
38279
38280 /* This cpu's struct lguest_pages (after the Switcher text page) */
38281@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
38282 * These copies are pretty cheap, so we do them unconditionally: */
38283 /* Save the current Host top-level page directory.
38284 */
38285+
38286+#ifdef CONFIG_PAX_PER_CPU_PGD
38287+ pages->state.host_cr3 = read_cr3();
38288+#else
38289 pages->state.host_cr3 = __pa(current->mm->pgd);
38290+#endif
38291+
38292 /*
38293 * Set up the Guest's page tables to see this CPU's pages (and no
38294 * other CPU's pages).
38295@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
38296 * compiled-in switcher code and the high-mapped copy we just made.
38297 */
38298 for (i = 0; i < IDT_ENTRIES; i++)
38299- default_idt_entries[i] += switcher_offset();
38300+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
38301
38302 /*
38303 * Set up the Switcher's per-cpu areas.
38304@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
38305 * it will be undisturbed when we switch. To change %cs and jump we
38306 * need this structure to feed to Intel's "lcall" instruction.
38307 */
38308- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
38309+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
38310 lguest_entry.segment = LGUEST_CS;
38311
38312 /*
38313diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
38314index 40634b0..4f5855e 100644
38315--- a/drivers/lguest/x86/switcher_32.S
38316+++ b/drivers/lguest/x86/switcher_32.S
38317@@ -87,6 +87,7 @@
38318 #include <asm/page.h>
38319 #include <asm/segment.h>
38320 #include <asm/lguest.h>
38321+#include <asm/processor-flags.h>
38322
38323 // We mark the start of the code to copy
38324 // It's placed in .text tho it's never run here
38325@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38326 // Changes type when we load it: damn Intel!
38327 // For after we switch over our page tables
38328 // That entry will be read-only: we'd crash.
38329+
38330+#ifdef CONFIG_PAX_KERNEXEC
38331+ mov %cr0, %edx
38332+ xor $X86_CR0_WP, %edx
38333+ mov %edx, %cr0
38334+#endif
38335+
38336 movl $(GDT_ENTRY_TSS*8), %edx
38337 ltr %dx
38338
38339@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38340 // Let's clear it again for our return.
38341 // The GDT descriptor of the Host
38342 // Points to the table after two "size" bytes
38343- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38344+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38345 // Clear "used" from type field (byte 5, bit 2)
38346- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38347+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38348+
38349+#ifdef CONFIG_PAX_KERNEXEC
38350+ mov %cr0, %eax
38351+ xor $X86_CR0_WP, %eax
38352+ mov %eax, %cr0
38353+#endif
38354
38355 // Once our page table's switched, the Guest is live!
38356 // The Host fades as we run this final step.
38357@@ -295,13 +309,12 @@ deliver_to_host:
38358 // I consulted gcc, and it gave
38359 // These instructions, which I gladly credit:
38360 leal (%edx,%ebx,8), %eax
38361- movzwl (%eax),%edx
38362- movl 4(%eax), %eax
38363- xorw %ax, %ax
38364- orl %eax, %edx
38365+ movl 4(%eax), %edx
38366+ movw (%eax), %dx
38367 // Now the address of the handler's in %edx
38368 // We call it now: its "iret" drops us home.
38369- jmp *%edx
38370+ ljmp $__KERNEL_CS, $1f
38371+1: jmp *%edx
38372
38373 // Every interrupt can come to us here
38374 // But we must truly tell each apart.
38375diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
38376index 0003992..854bbce 100644
38377--- a/drivers/md/bcache/closure.h
38378+++ b/drivers/md/bcache/closure.h
38379@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
38380 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
38381 struct workqueue_struct *wq)
38382 {
38383- BUG_ON(object_is_on_stack(cl));
38384+ BUG_ON(object_starts_on_stack(cl));
38385 closure_set_ip(cl);
38386 cl->fn = fn;
38387 cl->wq = wq;
38388diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38389index 5a2c754..0fa55db 100644
38390--- a/drivers/md/bitmap.c
38391+++ b/drivers/md/bitmap.c
38392@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38393 chunk_kb ? "KB" : "B");
38394 if (bitmap->storage.file) {
38395 seq_printf(seq, ", file: ");
38396- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38397+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38398 }
38399
38400 seq_printf(seq, "\n");
38401diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38402index 81a79b7..87a0f73 100644
38403--- a/drivers/md/dm-ioctl.c
38404+++ b/drivers/md/dm-ioctl.c
38405@@ -1697,7 +1697,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38406 cmd == DM_LIST_VERSIONS_CMD)
38407 return 0;
38408
38409- if ((cmd == DM_DEV_CREATE_CMD)) {
38410+ if (cmd == DM_DEV_CREATE_CMD) {
38411 if (!*param->name) {
38412 DMWARN("name not supplied when creating device");
38413 return -EINVAL;
38414diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38415index 699b5be..eac0a15 100644
38416--- a/drivers/md/dm-raid1.c
38417+++ b/drivers/md/dm-raid1.c
38418@@ -40,7 +40,7 @@ enum dm_raid1_error {
38419
38420 struct mirror {
38421 struct mirror_set *ms;
38422- atomic_t error_count;
38423+ atomic_unchecked_t error_count;
38424 unsigned long error_type;
38425 struct dm_dev *dev;
38426 sector_t offset;
38427@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38428 struct mirror *m;
38429
38430 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38431- if (!atomic_read(&m->error_count))
38432+ if (!atomic_read_unchecked(&m->error_count))
38433 return m;
38434
38435 return NULL;
38436@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38437 * simple way to tell if a device has encountered
38438 * errors.
38439 */
38440- atomic_inc(&m->error_count);
38441+ atomic_inc_unchecked(&m->error_count);
38442
38443 if (test_and_set_bit(error_type, &m->error_type))
38444 return;
38445@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38446 struct mirror *m = get_default_mirror(ms);
38447
38448 do {
38449- if (likely(!atomic_read(&m->error_count)))
38450+ if (likely(!atomic_read_unchecked(&m->error_count)))
38451 return m;
38452
38453 if (m-- == ms->mirror)
38454@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
38455 {
38456 struct mirror *default_mirror = get_default_mirror(m->ms);
38457
38458- return !atomic_read(&default_mirror->error_count);
38459+ return !atomic_read_unchecked(&default_mirror->error_count);
38460 }
38461
38462 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38463@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38464 */
38465 if (likely(region_in_sync(ms, region, 1)))
38466 m = choose_mirror(ms, bio->bi_sector);
38467- else if (m && atomic_read(&m->error_count))
38468+ else if (m && atomic_read_unchecked(&m->error_count))
38469 m = NULL;
38470
38471 if (likely(m))
38472@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38473 }
38474
38475 ms->mirror[mirror].ms = ms;
38476- atomic_set(&(ms->mirror[mirror].error_count), 0);
38477+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38478 ms->mirror[mirror].error_type = 0;
38479 ms->mirror[mirror].offset = offset;
38480
38481@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
38482 */
38483 static char device_status_char(struct mirror *m)
38484 {
38485- if (!atomic_read(&(m->error_count)))
38486+ if (!atomic_read_unchecked(&(m->error_count)))
38487 return 'A';
38488
38489 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38490diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38491index d907ca6..cfb8384 100644
38492--- a/drivers/md/dm-stripe.c
38493+++ b/drivers/md/dm-stripe.c
38494@@ -20,7 +20,7 @@ struct stripe {
38495 struct dm_dev *dev;
38496 sector_t physical_start;
38497
38498- atomic_t error_count;
38499+ atomic_unchecked_t error_count;
38500 };
38501
38502 struct stripe_c {
38503@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38504 kfree(sc);
38505 return r;
38506 }
38507- atomic_set(&(sc->stripe[i].error_count), 0);
38508+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38509 }
38510
38511 ti->private = sc;
38512@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38513 DMEMIT("%d ", sc->stripes);
38514 for (i = 0; i < sc->stripes; i++) {
38515 DMEMIT("%s ", sc->stripe[i].dev->name);
38516- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38517+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38518 'D' : 'A';
38519 }
38520 buffer[i] = '\0';
38521@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38522 */
38523 for (i = 0; i < sc->stripes; i++)
38524 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38525- atomic_inc(&(sc->stripe[i].error_count));
38526- if (atomic_read(&(sc->stripe[i].error_count)) <
38527+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38528+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38529 DM_IO_ERROR_THRESHOLD)
38530 schedule_work(&sc->trigger_event);
38531 }
38532diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38533index 1ff252a..ee384c1 100644
38534--- a/drivers/md/dm-table.c
38535+++ b/drivers/md/dm-table.c
38536@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38537 if (!dev_size)
38538 return 0;
38539
38540- if ((start >= dev_size) || (start + len > dev_size)) {
38541+ if ((start >= dev_size) || (len > dev_size - start)) {
38542 DMWARN("%s: %s too small for target: "
38543 "start=%llu, len=%llu, dev_size=%llu",
38544 dm_device_name(ti->table->md), bdevname(bdev, b),
38545diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38546index 60bce43..9b997d0 100644
38547--- a/drivers/md/dm-thin-metadata.c
38548+++ b/drivers/md/dm-thin-metadata.c
38549@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38550 {
38551 pmd->info.tm = pmd->tm;
38552 pmd->info.levels = 2;
38553- pmd->info.value_type.context = pmd->data_sm;
38554+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38555 pmd->info.value_type.size = sizeof(__le64);
38556 pmd->info.value_type.inc = data_block_inc;
38557 pmd->info.value_type.dec = data_block_dec;
38558@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38559
38560 pmd->bl_info.tm = pmd->tm;
38561 pmd->bl_info.levels = 1;
38562- pmd->bl_info.value_type.context = pmd->data_sm;
38563+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38564 pmd->bl_info.value_type.size = sizeof(__le64);
38565 pmd->bl_info.value_type.inc = data_block_inc;
38566 pmd->bl_info.value_type.dec = data_block_dec;
38567diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38568index 33f2010..23fb84c 100644
38569--- a/drivers/md/dm.c
38570+++ b/drivers/md/dm.c
38571@@ -169,9 +169,9 @@ struct mapped_device {
38572 /*
38573 * Event handling.
38574 */
38575- atomic_t event_nr;
38576+ atomic_unchecked_t event_nr;
38577 wait_queue_head_t eventq;
38578- atomic_t uevent_seq;
38579+ atomic_unchecked_t uevent_seq;
38580 struct list_head uevent_list;
38581 spinlock_t uevent_lock; /* Protect access to uevent_list */
38582
38583@@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
38584 rwlock_init(&md->map_lock);
38585 atomic_set(&md->holders, 1);
38586 atomic_set(&md->open_count, 0);
38587- atomic_set(&md->event_nr, 0);
38588- atomic_set(&md->uevent_seq, 0);
38589+ atomic_set_unchecked(&md->event_nr, 0);
38590+ atomic_set_unchecked(&md->uevent_seq, 0);
38591 INIT_LIST_HEAD(&md->uevent_list);
38592 spin_lock_init(&md->uevent_lock);
38593
38594@@ -2033,7 +2033,7 @@ static void event_callback(void *context)
38595
38596 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38597
38598- atomic_inc(&md->event_nr);
38599+ atomic_inc_unchecked(&md->event_nr);
38600 wake_up(&md->eventq);
38601 }
38602
38603@@ -2690,18 +2690,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38604
38605 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38606 {
38607- return atomic_add_return(1, &md->uevent_seq);
38608+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38609 }
38610
38611 uint32_t dm_get_event_nr(struct mapped_device *md)
38612 {
38613- return atomic_read(&md->event_nr);
38614+ return atomic_read_unchecked(&md->event_nr);
38615 }
38616
38617 int dm_wait_event(struct mapped_device *md, int event_nr)
38618 {
38619 return wait_event_interruptible(md->eventq,
38620- (event_nr != atomic_read(&md->event_nr)));
38621+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38622 }
38623
38624 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38625diff --git a/drivers/md/md.c b/drivers/md/md.c
38626index 51f0345..c77810e 100644
38627--- a/drivers/md/md.c
38628+++ b/drivers/md/md.c
38629@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38630 * start build, activate spare
38631 */
38632 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38633-static atomic_t md_event_count;
38634+static atomic_unchecked_t md_event_count;
38635 void md_new_event(struct mddev *mddev)
38636 {
38637- atomic_inc(&md_event_count);
38638+ atomic_inc_unchecked(&md_event_count);
38639 wake_up(&md_event_waiters);
38640 }
38641 EXPORT_SYMBOL_GPL(md_new_event);
38642@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38643 */
38644 static void md_new_event_inintr(struct mddev *mddev)
38645 {
38646- atomic_inc(&md_event_count);
38647+ atomic_inc_unchecked(&md_event_count);
38648 wake_up(&md_event_waiters);
38649 }
38650
38651@@ -1501,7 +1501,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38652 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38653 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38654 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38655- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38656+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38657
38658 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38659 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38660@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38661 else
38662 sb->resync_offset = cpu_to_le64(0);
38663
38664- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38665+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38666
38667 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38668 sb->size = cpu_to_le64(mddev->dev_sectors);
38669@@ -2750,7 +2750,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38670 static ssize_t
38671 errors_show(struct md_rdev *rdev, char *page)
38672 {
38673- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38674+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38675 }
38676
38677 static ssize_t
38678@@ -2759,7 +2759,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38679 char *e;
38680 unsigned long n = simple_strtoul(buf, &e, 10);
38681 if (*buf && (*e == 0 || *e == '\n')) {
38682- atomic_set(&rdev->corrected_errors, n);
38683+ atomic_set_unchecked(&rdev->corrected_errors, n);
38684 return len;
38685 }
38686 return -EINVAL;
38687@@ -3207,8 +3207,8 @@ int md_rdev_init(struct md_rdev *rdev)
38688 rdev->sb_loaded = 0;
38689 rdev->bb_page = NULL;
38690 atomic_set(&rdev->nr_pending, 0);
38691- atomic_set(&rdev->read_errors, 0);
38692- atomic_set(&rdev->corrected_errors, 0);
38693+ atomic_set_unchecked(&rdev->read_errors, 0);
38694+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38695
38696 INIT_LIST_HEAD(&rdev->same_set);
38697 init_waitqueue_head(&rdev->blocked_wait);
38698@@ -7009,7 +7009,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38699
38700 spin_unlock(&pers_lock);
38701 seq_printf(seq, "\n");
38702- seq->poll_event = atomic_read(&md_event_count);
38703+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38704 return 0;
38705 }
38706 if (v == (void*)2) {
38707@@ -7112,7 +7112,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38708 return error;
38709
38710 seq = file->private_data;
38711- seq->poll_event = atomic_read(&md_event_count);
38712+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38713 return error;
38714 }
38715
38716@@ -7126,7 +7126,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38717 /* always allow read */
38718 mask = POLLIN | POLLRDNORM;
38719
38720- if (seq->poll_event != atomic_read(&md_event_count))
38721+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38722 mask |= POLLERR | POLLPRI;
38723 return mask;
38724 }
38725@@ -7170,7 +7170,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38726 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38727 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38728 (int)part_stat_read(&disk->part0, sectors[1]) -
38729- atomic_read(&disk->sync_io);
38730+ atomic_read_unchecked(&disk->sync_io);
38731 /* sync IO will cause sync_io to increase before the disk_stats
38732 * as sync_io is counted when a request starts, and
38733 * disk_stats is counted when it completes.
38734diff --git a/drivers/md/md.h b/drivers/md/md.h
38735index 653f992b6..6af6c40 100644
38736--- a/drivers/md/md.h
38737+++ b/drivers/md/md.h
38738@@ -94,13 +94,13 @@ struct md_rdev {
38739 * only maintained for arrays that
38740 * support hot removal
38741 */
38742- atomic_t read_errors; /* number of consecutive read errors that
38743+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38744 * we have tried to ignore.
38745 */
38746 struct timespec last_read_error; /* monotonic time since our
38747 * last read error
38748 */
38749- atomic_t corrected_errors; /* number of corrected read errors,
38750+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38751 * for reporting to userspace and storing
38752 * in superblock.
38753 */
38754@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38755
38756 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38757 {
38758- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38759+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38760 }
38761
38762 struct md_personality
38763diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38764index 3e6d115..ffecdeb 100644
38765--- a/drivers/md/persistent-data/dm-space-map.h
38766+++ b/drivers/md/persistent-data/dm-space-map.h
38767@@ -71,6 +71,7 @@ struct dm_space_map {
38768 dm_sm_threshold_fn fn,
38769 void *context);
38770 };
38771+typedef struct dm_space_map __no_const dm_space_map_no_const;
38772
38773 /*----------------------------------------------------------------*/
38774
38775diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38776index 6f48244..7d29145 100644
38777--- a/drivers/md/raid1.c
38778+++ b/drivers/md/raid1.c
38779@@ -1822,7 +1822,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38780 if (r1_sync_page_io(rdev, sect, s,
38781 bio->bi_io_vec[idx].bv_page,
38782 READ) != 0)
38783- atomic_add(s, &rdev->corrected_errors);
38784+ atomic_add_unchecked(s, &rdev->corrected_errors);
38785 }
38786 sectors -= s;
38787 sect += s;
38788@@ -2049,7 +2049,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38789 test_bit(In_sync, &rdev->flags)) {
38790 if (r1_sync_page_io(rdev, sect, s,
38791 conf->tmppage, READ)) {
38792- atomic_add(s, &rdev->corrected_errors);
38793+ atomic_add_unchecked(s, &rdev->corrected_errors);
38794 printk(KERN_INFO
38795 "md/raid1:%s: read error corrected "
38796 "(%d sectors at %llu on %s)\n",
38797diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38798index 081bb33..3c4b287 100644
38799--- a/drivers/md/raid10.c
38800+++ b/drivers/md/raid10.c
38801@@ -1940,7 +1940,7 @@ static void end_sync_read(struct bio *bio, int error)
38802 /* The write handler will notice the lack of
38803 * R10BIO_Uptodate and record any errors etc
38804 */
38805- atomic_add(r10_bio->sectors,
38806+ atomic_add_unchecked(r10_bio->sectors,
38807 &conf->mirrors[d].rdev->corrected_errors);
38808
38809 /* for reconstruct, we always reschedule after a read.
38810@@ -2298,7 +2298,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38811 {
38812 struct timespec cur_time_mon;
38813 unsigned long hours_since_last;
38814- unsigned int read_errors = atomic_read(&rdev->read_errors);
38815+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38816
38817 ktime_get_ts(&cur_time_mon);
38818
38819@@ -2320,9 +2320,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38820 * overflowing the shift of read_errors by hours_since_last.
38821 */
38822 if (hours_since_last >= 8 * sizeof(read_errors))
38823- atomic_set(&rdev->read_errors, 0);
38824+ atomic_set_unchecked(&rdev->read_errors, 0);
38825 else
38826- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38827+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38828 }
38829
38830 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38831@@ -2376,8 +2376,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38832 return;
38833
38834 check_decay_read_errors(mddev, rdev);
38835- atomic_inc(&rdev->read_errors);
38836- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38837+ atomic_inc_unchecked(&rdev->read_errors);
38838+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38839 char b[BDEVNAME_SIZE];
38840 bdevname(rdev->bdev, b);
38841
38842@@ -2385,7 +2385,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38843 "md/raid10:%s: %s: Raid device exceeded "
38844 "read_error threshold [cur %d:max %d]\n",
38845 mdname(mddev), b,
38846- atomic_read(&rdev->read_errors), max_read_errors);
38847+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38848 printk(KERN_NOTICE
38849 "md/raid10:%s: %s: Failing raid device\n",
38850 mdname(mddev), b);
38851@@ -2540,7 +2540,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38852 sect +
38853 choose_data_offset(r10_bio, rdev)),
38854 bdevname(rdev->bdev, b));
38855- atomic_add(s, &rdev->corrected_errors);
38856+ atomic_add_unchecked(s, &rdev->corrected_errors);
38857 }
38858
38859 rdev_dec_pending(rdev, mddev);
38860diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38861index a35b846..e295c6d 100644
38862--- a/drivers/md/raid5.c
38863+++ b/drivers/md/raid5.c
38864@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38865 mdname(conf->mddev), STRIPE_SECTORS,
38866 (unsigned long long)s,
38867 bdevname(rdev->bdev, b));
38868- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38869+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38870 clear_bit(R5_ReadError, &sh->dev[i].flags);
38871 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38872 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38873 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38874
38875- if (atomic_read(&rdev->read_errors))
38876- atomic_set(&rdev->read_errors, 0);
38877+ if (atomic_read_unchecked(&rdev->read_errors))
38878+ atomic_set_unchecked(&rdev->read_errors, 0);
38879 } else {
38880 const char *bdn = bdevname(rdev->bdev, b);
38881 int retry = 0;
38882 int set_bad = 0;
38883
38884 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38885- atomic_inc(&rdev->read_errors);
38886+ atomic_inc_unchecked(&rdev->read_errors);
38887 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38888 printk_ratelimited(
38889 KERN_WARNING
38890@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38891 mdname(conf->mddev),
38892 (unsigned long long)s,
38893 bdn);
38894- } else if (atomic_read(&rdev->read_errors)
38895+ } else if (atomic_read_unchecked(&rdev->read_errors)
38896 > conf->max_nr_stripes)
38897 printk(KERN_WARNING
38898 "md/raid:%s: Too many read errors, failing device %s.\n",
38899diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38900index 401ef64..836e563 100644
38901--- a/drivers/media/dvb-core/dvbdev.c
38902+++ b/drivers/media/dvb-core/dvbdev.c
38903@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38904 const struct dvb_device *template, void *priv, int type)
38905 {
38906 struct dvb_device *dvbdev;
38907- struct file_operations *dvbdevfops;
38908+ file_operations_no_const *dvbdevfops;
38909 struct device *clsdev;
38910 int minor;
38911 int id;
38912diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38913index 9b6c3bb..baeb5c7 100644
38914--- a/drivers/media/dvb-frontends/dib3000.h
38915+++ b/drivers/media/dvb-frontends/dib3000.h
38916@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38917 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38918 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38919 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38920-};
38921+} __no_const;
38922
38923 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
38924 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38925diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38926index c7a9be1..683f6f8 100644
38927--- a/drivers/media/pci/cx88/cx88-video.c
38928+++ b/drivers/media/pci/cx88/cx88-video.c
38929@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38930
38931 /* ------------------------------------------------------------------ */
38932
38933-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38934-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38935-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38936+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38937+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38938+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38939
38940 module_param_array(video_nr, int, NULL, 0444);
38941 module_param_array(vbi_nr, int, NULL, 0444);
38942diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38943index d338b19..aae4f9e 100644
38944--- a/drivers/media/platform/omap/omap_vout.c
38945+++ b/drivers/media/platform/omap/omap_vout.c
38946@@ -63,7 +63,6 @@ enum omap_vout_channels {
38947 OMAP_VIDEO2,
38948 };
38949
38950-static struct videobuf_queue_ops video_vbq_ops;
38951 /* Variables configurable through module params*/
38952 static u32 video1_numbuffers = 3;
38953 static u32 video2_numbuffers = 3;
38954@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
38955 {
38956 struct videobuf_queue *q;
38957 struct omap_vout_device *vout = NULL;
38958+ static struct videobuf_queue_ops video_vbq_ops = {
38959+ .buf_setup = omap_vout_buffer_setup,
38960+ .buf_prepare = omap_vout_buffer_prepare,
38961+ .buf_release = omap_vout_buffer_release,
38962+ .buf_queue = omap_vout_buffer_queue,
38963+ };
38964
38965 vout = video_drvdata(file);
38966 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38967@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
38968 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38969
38970 q = &vout->vbq;
38971- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38972- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38973- video_vbq_ops.buf_release = omap_vout_buffer_release;
38974- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38975 spin_lock_init(&vout->vbq_lock);
38976
38977 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38978diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38979index 04e6490..2df65bf 100644
38980--- a/drivers/media/platform/s5p-tv/mixer.h
38981+++ b/drivers/media/platform/s5p-tv/mixer.h
38982@@ -156,7 +156,7 @@ struct mxr_layer {
38983 /** layer index (unique identifier) */
38984 int idx;
38985 /** callbacks for layer methods */
38986- struct mxr_layer_ops ops;
38987+ struct mxr_layer_ops *ops;
38988 /** format array */
38989 const struct mxr_format **fmt_array;
38990 /** size of format array */
38991diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38992index b93a21f..2535195 100644
38993--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38994+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38995@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38996 {
38997 struct mxr_layer *layer;
38998 int ret;
38999- struct mxr_layer_ops ops = {
39000+ static struct mxr_layer_ops ops = {
39001 .release = mxr_graph_layer_release,
39002 .buffer_set = mxr_graph_buffer_set,
39003 .stream_set = mxr_graph_stream_set,
39004diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
39005index b713403..53cb5ad 100644
39006--- a/drivers/media/platform/s5p-tv/mixer_reg.c
39007+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
39008@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
39009 layer->update_buf = next;
39010 }
39011
39012- layer->ops.buffer_set(layer, layer->update_buf);
39013+ layer->ops->buffer_set(layer, layer->update_buf);
39014
39015 if (done && done != layer->shadow_buf)
39016 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
39017diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
39018index ef0efdf..8c78eb6 100644
39019--- a/drivers/media/platform/s5p-tv/mixer_video.c
39020+++ b/drivers/media/platform/s5p-tv/mixer_video.c
39021@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
39022 layer->geo.src.height = layer->geo.src.full_height;
39023
39024 mxr_geometry_dump(mdev, &layer->geo);
39025- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
39026+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
39027 mxr_geometry_dump(mdev, &layer->geo);
39028 }
39029
39030@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
39031 layer->geo.dst.full_width = mbus_fmt.width;
39032 layer->geo.dst.full_height = mbus_fmt.height;
39033 layer->geo.dst.field = mbus_fmt.field;
39034- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
39035+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
39036
39037 mxr_geometry_dump(mdev, &layer->geo);
39038 }
39039@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
39040 /* set source size to highest accepted value */
39041 geo->src.full_width = max(geo->dst.full_width, pix->width);
39042 geo->src.full_height = max(geo->dst.full_height, pix->height);
39043- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39044+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39045 mxr_geometry_dump(mdev, &layer->geo);
39046 /* set cropping to total visible screen */
39047 geo->src.width = pix->width;
39048@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
39049 geo->src.x_offset = 0;
39050 geo->src.y_offset = 0;
39051 /* assure consistency of geometry */
39052- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
39053+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
39054 mxr_geometry_dump(mdev, &layer->geo);
39055 /* set full size to lowest possible value */
39056 geo->src.full_width = 0;
39057 geo->src.full_height = 0;
39058- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39059+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
39060 mxr_geometry_dump(mdev, &layer->geo);
39061
39062 /* returning results */
39063@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
39064 target->width = s->r.width;
39065 target->height = s->r.height;
39066
39067- layer->ops.fix_geometry(layer, stage, s->flags);
39068+ layer->ops->fix_geometry(layer, stage, s->flags);
39069
39070 /* retrieve update selection rectangle */
39071 res.left = target->x_offset;
39072@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
39073 mxr_output_get(mdev);
39074
39075 mxr_layer_update_output(layer);
39076- layer->ops.format_set(layer);
39077+ layer->ops->format_set(layer);
39078 /* enabling layer in hardware */
39079 spin_lock_irqsave(&layer->enq_slock, flags);
39080 layer->state = MXR_LAYER_STREAMING;
39081 spin_unlock_irqrestore(&layer->enq_slock, flags);
39082
39083- layer->ops.stream_set(layer, MXR_ENABLE);
39084+ layer->ops->stream_set(layer, MXR_ENABLE);
39085 mxr_streamer_get(mdev);
39086
39087 return 0;
39088@@ -1030,7 +1030,7 @@ static int stop_streaming(struct vb2_queue *vq)
39089 spin_unlock_irqrestore(&layer->enq_slock, flags);
39090
39091 /* disabling layer in hardware */
39092- layer->ops.stream_set(layer, MXR_DISABLE);
39093+ layer->ops->stream_set(layer, MXR_DISABLE);
39094 /* remove one streamer */
39095 mxr_streamer_put(mdev);
39096 /* allow changes in output configuration */
39097@@ -1069,8 +1069,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
39098
39099 void mxr_layer_release(struct mxr_layer *layer)
39100 {
39101- if (layer->ops.release)
39102- layer->ops.release(layer);
39103+ if (layer->ops->release)
39104+ layer->ops->release(layer);
39105 }
39106
39107 void mxr_base_layer_release(struct mxr_layer *layer)
39108@@ -1096,7 +1096,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
39109
39110 layer->mdev = mdev;
39111 layer->idx = idx;
39112- layer->ops = *ops;
39113+ layer->ops = ops;
39114
39115 spin_lock_init(&layer->enq_slock);
39116 INIT_LIST_HEAD(&layer->enq_list);
39117diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39118index 3d13a63..da31bf1 100644
39119--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39120+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39121@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
39122 {
39123 struct mxr_layer *layer;
39124 int ret;
39125- struct mxr_layer_ops ops = {
39126+ static struct mxr_layer_ops ops = {
39127 .release = mxr_vp_layer_release,
39128 .buffer_set = mxr_vp_buffer_set,
39129 .stream_set = mxr_vp_stream_set,
39130diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
39131index 545c04c..a14bded 100644
39132--- a/drivers/media/radio/radio-cadet.c
39133+++ b/drivers/media/radio/radio-cadet.c
39134@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39135 unsigned char readbuf[RDS_BUFFER];
39136 int i = 0;
39137
39138+ if (count > RDS_BUFFER)
39139+ return -EFAULT;
39140 mutex_lock(&dev->lock);
39141 if (dev->rdsstat == 0)
39142 cadet_start_rds(dev);
39143@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39144 while (i < count && dev->rdsin != dev->rdsout)
39145 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
39146
39147- if (i && copy_to_user(data, readbuf, i))
39148+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
39149 i = -EFAULT;
39150 unlock:
39151 mutex_unlock(&dev->lock);
39152diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
39153index 3940bb0..fb3952a 100644
39154--- a/drivers/media/usb/dvb-usb/cxusb.c
39155+++ b/drivers/media/usb/dvb-usb/cxusb.c
39156@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
39157
39158 struct dib0700_adapter_state {
39159 int (*set_param_save) (struct dvb_frontend *);
39160-};
39161+} __no_const;
39162
39163 static int dib7070_set_param_override(struct dvb_frontend *fe)
39164 {
39165diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
39166index 6e237b6..dc25556 100644
39167--- a/drivers/media/usb/dvb-usb/dw2102.c
39168+++ b/drivers/media/usb/dvb-usb/dw2102.c
39169@@ -118,7 +118,7 @@ struct su3000_state {
39170
39171 struct s6x0_state {
39172 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
39173-};
39174+} __no_const;
39175
39176 /* debug */
39177 static int dvb_usb_dw2102_debug;
39178diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39179index f129551..ecf6514 100644
39180--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39181+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39182@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
39183 __u32 reserved;
39184 };
39185
39186-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39187+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
39188 enum v4l2_memory memory)
39189 {
39190 void __user *up_pln;
39191@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39192 return 0;
39193 }
39194
39195-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39196+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
39197 enum v4l2_memory memory)
39198 {
39199 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
39200@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
39201 put_user(kp->start_block, &up->start_block) ||
39202 put_user(kp->blocks, &up->blocks) ||
39203 put_user(tmp, &up->edid) ||
39204- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
39205+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
39206 return -EFAULT;
39207 return 0;
39208 }
39209diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
39210index 7658586..1079260 100644
39211--- a/drivers/media/v4l2-core/v4l2-ioctl.c
39212+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
39213@@ -1995,7 +1995,8 @@ struct v4l2_ioctl_info {
39214 struct file *file, void *fh, void *p);
39215 } u;
39216 void (*debug)(const void *arg, bool write_only);
39217-};
39218+} __do_const;
39219+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
39220
39221 /* This control needs a priority check */
39222 #define INFO_FL_PRIO (1 << 0)
39223@@ -2177,7 +2178,7 @@ static long __video_do_ioctl(struct file *file,
39224 struct video_device *vfd = video_devdata(file);
39225 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
39226 bool write_only = false;
39227- struct v4l2_ioctl_info default_info;
39228+ v4l2_ioctl_info_no_const default_info;
39229 const struct v4l2_ioctl_info *info;
39230 void *fh = file->private_data;
39231 struct v4l2_fh *vfh = NULL;
39232@@ -2251,7 +2252,7 @@ done:
39233 }
39234
39235 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39236- void * __user *user_ptr, void ***kernel_ptr)
39237+ void __user **user_ptr, void ***kernel_ptr)
39238 {
39239 int ret = 0;
39240
39241@@ -2267,7 +2268,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39242 ret = -EINVAL;
39243 break;
39244 }
39245- *user_ptr = (void __user *)buf->m.planes;
39246+ *user_ptr = (void __force_user *)buf->m.planes;
39247 *kernel_ptr = (void *)&buf->m.planes;
39248 *array_size = sizeof(struct v4l2_plane) * buf->length;
39249 ret = 1;
39250@@ -2302,7 +2303,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39251 ret = -EINVAL;
39252 break;
39253 }
39254- *user_ptr = (void __user *)ctrls->controls;
39255+ *user_ptr = (void __force_user *)ctrls->controls;
39256 *kernel_ptr = (void *)&ctrls->controls;
39257 *array_size = sizeof(struct v4l2_ext_control)
39258 * ctrls->count;
39259diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
39260index 767ff4d..c69d259 100644
39261--- a/drivers/message/fusion/mptbase.c
39262+++ b/drivers/message/fusion/mptbase.c
39263@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39264 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
39265 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
39266
39267+#ifdef CONFIG_GRKERNSEC_HIDESYM
39268+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
39269+#else
39270 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
39271 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
39272+#endif
39273+
39274 /*
39275 * Rounding UP to nearest 4-kB boundary here...
39276 */
39277@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39278 ioc->facts.GlobalCredits);
39279
39280 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
39281+#ifdef CONFIG_GRKERNSEC_HIDESYM
39282+ NULL, NULL);
39283+#else
39284 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
39285+#endif
39286 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
39287 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
39288 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
39289diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
39290index dd239bd..689c4f7 100644
39291--- a/drivers/message/fusion/mptsas.c
39292+++ b/drivers/message/fusion/mptsas.c
39293@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
39294 return 0;
39295 }
39296
39297+static inline void
39298+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39299+{
39300+ if (phy_info->port_details) {
39301+ phy_info->port_details->rphy = rphy;
39302+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39303+ ioc->name, rphy));
39304+ }
39305+
39306+ if (rphy) {
39307+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39308+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39309+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39310+ ioc->name, rphy, rphy->dev.release));
39311+ }
39312+}
39313+
39314 /* no mutex */
39315 static void
39316 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
39317@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
39318 return NULL;
39319 }
39320
39321-static inline void
39322-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39323-{
39324- if (phy_info->port_details) {
39325- phy_info->port_details->rphy = rphy;
39326- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39327- ioc->name, rphy));
39328- }
39329-
39330- if (rphy) {
39331- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39332- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39333- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39334- ioc->name, rphy, rphy->dev.release));
39335- }
39336-}
39337-
39338 static inline struct sas_port *
39339 mptsas_get_port(struct mptsas_phyinfo *phy_info)
39340 {
39341diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
39342index 727819c..ad74694 100644
39343--- a/drivers/message/fusion/mptscsih.c
39344+++ b/drivers/message/fusion/mptscsih.c
39345@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
39346
39347 h = shost_priv(SChost);
39348
39349- if (h) {
39350- if (h->info_kbuf == NULL)
39351- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39352- return h->info_kbuf;
39353- h->info_kbuf[0] = '\0';
39354+ if (!h)
39355+ return NULL;
39356
39357- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39358- h->info_kbuf[size-1] = '\0';
39359- }
39360+ if (h->info_kbuf == NULL)
39361+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39362+ return h->info_kbuf;
39363+ h->info_kbuf[0] = '\0';
39364+
39365+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39366+ h->info_kbuf[size-1] = '\0';
39367
39368 return h->info_kbuf;
39369 }
39370diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39371index b7d87cd..9890039 100644
39372--- a/drivers/message/i2o/i2o_proc.c
39373+++ b/drivers/message/i2o/i2o_proc.c
39374@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39375 "Array Controller Device"
39376 };
39377
39378-static char *chtostr(char *tmp, u8 *chars, int n)
39379-{
39380- tmp[0] = 0;
39381- return strncat(tmp, (char *)chars, n);
39382-}
39383-
39384 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39385 char *group)
39386 {
39387@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39388 } *result;
39389
39390 i2o_exec_execute_ddm_table ddm_table;
39391- char tmp[28 + 1];
39392
39393 result = kmalloc(sizeof(*result), GFP_KERNEL);
39394 if (!result)
39395@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39396
39397 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39398 seq_printf(seq, "%-#8x", ddm_table.module_id);
39399- seq_printf(seq, "%-29s",
39400- chtostr(tmp, ddm_table.module_name_version, 28));
39401+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39402 seq_printf(seq, "%9d ", ddm_table.data_size);
39403 seq_printf(seq, "%8d", ddm_table.code_size);
39404
39405@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39406
39407 i2o_driver_result_table *result;
39408 i2o_driver_store_table *dst;
39409- char tmp[28 + 1];
39410
39411 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39412 if (result == NULL)
39413@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39414
39415 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39416 seq_printf(seq, "%-#8x", dst->module_id);
39417- seq_printf(seq, "%-29s",
39418- chtostr(tmp, dst->module_name_version, 28));
39419- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39420+ seq_printf(seq, "%-.28s", dst->module_name_version);
39421+ seq_printf(seq, "%-.8s", dst->date);
39422 seq_printf(seq, "%8d ", dst->module_size);
39423 seq_printf(seq, "%8d ", dst->mpb_size);
39424 seq_printf(seq, "0x%04x", dst->module_flags);
39425@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39426 // == (allow) 512d bytes (max)
39427 static u16 *work16 = (u16 *) work32;
39428 int token;
39429- char tmp[16 + 1];
39430
39431 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39432
39433@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39434 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39435 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39436 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39437- seq_printf(seq, "Vendor info : %s\n",
39438- chtostr(tmp, (u8 *) (work32 + 2), 16));
39439- seq_printf(seq, "Product info : %s\n",
39440- chtostr(tmp, (u8 *) (work32 + 6), 16));
39441- seq_printf(seq, "Description : %s\n",
39442- chtostr(tmp, (u8 *) (work32 + 10), 16));
39443- seq_printf(seq, "Product rev. : %s\n",
39444- chtostr(tmp, (u8 *) (work32 + 14), 8));
39445+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39446+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39447+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39448+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39449
39450 seq_printf(seq, "Serial number : ");
39451 print_serial_number(seq, (u8 *) (work32 + 16),
39452@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39453 u8 pad[256]; // allow up to 256 byte (max) serial number
39454 } result;
39455
39456- char tmp[24 + 1];
39457-
39458 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39459
39460 if (token < 0) {
39461@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39462 }
39463
39464 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39465- seq_printf(seq, "Module name : %s\n",
39466- chtostr(tmp, result.module_name, 24));
39467- seq_printf(seq, "Module revision : %s\n",
39468- chtostr(tmp, result.module_rev, 8));
39469+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39470+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39471
39472 seq_printf(seq, "Serial number : ");
39473 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39474@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39475 u8 instance_number[4];
39476 } result;
39477
39478- char tmp[64 + 1];
39479-
39480 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39481
39482 if (token < 0) {
39483@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39484 return 0;
39485 }
39486
39487- seq_printf(seq, "Device name : %s\n",
39488- chtostr(tmp, result.device_name, 64));
39489- seq_printf(seq, "Service name : %s\n",
39490- chtostr(tmp, result.service_name, 64));
39491- seq_printf(seq, "Physical name : %s\n",
39492- chtostr(tmp, result.physical_location, 64));
39493- seq_printf(seq, "Instance number : %s\n",
39494- chtostr(tmp, result.instance_number, 4));
39495+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39496+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39497+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39498+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39499
39500 return 0;
39501 }
39502diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39503index a8c08f3..155fe3d 100644
39504--- a/drivers/message/i2o/iop.c
39505+++ b/drivers/message/i2o/iop.c
39506@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39507
39508 spin_lock_irqsave(&c->context_list_lock, flags);
39509
39510- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39511- atomic_inc(&c->context_list_counter);
39512+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39513+ atomic_inc_unchecked(&c->context_list_counter);
39514
39515- entry->context = atomic_read(&c->context_list_counter);
39516+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39517
39518 list_add(&entry->list, &c->context_list);
39519
39520@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39521
39522 #if BITS_PER_LONG == 64
39523 spin_lock_init(&c->context_list_lock);
39524- atomic_set(&c->context_list_counter, 0);
39525+ atomic_set_unchecked(&c->context_list_counter, 0);
39526 INIT_LIST_HEAD(&c->context_list);
39527 #endif
39528
39529diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39530index 45ece11..8efa218 100644
39531--- a/drivers/mfd/janz-cmodio.c
39532+++ b/drivers/mfd/janz-cmodio.c
39533@@ -13,6 +13,7 @@
39534
39535 #include <linux/kernel.h>
39536 #include <linux/module.h>
39537+#include <linux/slab.h>
39538 #include <linux/init.h>
39539 #include <linux/pci.h>
39540 #include <linux/interrupt.h>
39541diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39542index a5f9888..1c0ed56 100644
39543--- a/drivers/mfd/twl4030-irq.c
39544+++ b/drivers/mfd/twl4030-irq.c
39545@@ -35,6 +35,7 @@
39546 #include <linux/of.h>
39547 #include <linux/irqdomain.h>
39548 #include <linux/i2c/twl.h>
39549+#include <asm/pgtable.h>
39550
39551 #include "twl-core.h"
39552
39553@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39554 * Install an irq handler for each of the SIH modules;
39555 * clone dummy irq_chip since PIH can't *do* anything
39556 */
39557- twl4030_irq_chip = dummy_irq_chip;
39558- twl4030_irq_chip.name = "twl4030";
39559+ pax_open_kernel();
39560+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39561+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39562
39563- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39564+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39565+ pax_close_kernel();
39566
39567 for (i = irq_base; i < irq_end; i++) {
39568 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39569diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39570index 277a8db..0e0b754 100644
39571--- a/drivers/mfd/twl6030-irq.c
39572+++ b/drivers/mfd/twl6030-irq.c
39573@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39574 * install an irq handler for each of the modules;
39575 * clone dummy irq_chip since PIH can't *do* anything
39576 */
39577- twl6030_irq_chip = dummy_irq_chip;
39578- twl6030_irq_chip.name = "twl6030";
39579- twl6030_irq_chip.irq_set_type = NULL;
39580- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39581+ pax_open_kernel();
39582+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39583+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39584+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39585+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39586+ pax_close_kernel();
39587
39588 for (i = irq_base; i < irq_end; i++) {
39589 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39590diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39591index f32550a..e3e52a2 100644
39592--- a/drivers/misc/c2port/core.c
39593+++ b/drivers/misc/c2port/core.c
39594@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
39595 mutex_init(&c2dev->mutex);
39596
39597 /* Create binary file */
39598- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39599+ pax_open_kernel();
39600+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39601+ pax_close_kernel();
39602 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39603 if (unlikely(ret))
39604 goto error_device_create_bin_file;
39605diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39606index 36f5d52..32311c3 100644
39607--- a/drivers/misc/kgdbts.c
39608+++ b/drivers/misc/kgdbts.c
39609@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
39610 char before[BREAK_INSTR_SIZE];
39611 char after[BREAK_INSTR_SIZE];
39612
39613- probe_kernel_read(before, (char *)kgdbts_break_test,
39614+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39615 BREAK_INSTR_SIZE);
39616 init_simple_test();
39617 ts.tst = plant_and_detach_test;
39618@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
39619 /* Activate test with initial breakpoint */
39620 if (!is_early)
39621 kgdb_breakpoint();
39622- probe_kernel_read(after, (char *)kgdbts_break_test,
39623+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39624 BREAK_INSTR_SIZE);
39625 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39626 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39627diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39628index 4cd4a3d..b48cbc7 100644
39629--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39630+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39631@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39632 * the lid is closed. This leads to interrupts as soon as a little move
39633 * is done.
39634 */
39635- atomic_inc(&lis3->count);
39636+ atomic_inc_unchecked(&lis3->count);
39637
39638 wake_up_interruptible(&lis3->misc_wait);
39639 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39640@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39641 if (lis3->pm_dev)
39642 pm_runtime_get_sync(lis3->pm_dev);
39643
39644- atomic_set(&lis3->count, 0);
39645+ atomic_set_unchecked(&lis3->count, 0);
39646 return 0;
39647 }
39648
39649@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39650 add_wait_queue(&lis3->misc_wait, &wait);
39651 while (true) {
39652 set_current_state(TASK_INTERRUPTIBLE);
39653- data = atomic_xchg(&lis3->count, 0);
39654+ data = atomic_xchg_unchecked(&lis3->count, 0);
39655 if (data)
39656 break;
39657
39658@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39659 struct lis3lv02d, miscdev);
39660
39661 poll_wait(file, &lis3->misc_wait, wait);
39662- if (atomic_read(&lis3->count))
39663+ if (atomic_read_unchecked(&lis3->count))
39664 return POLLIN | POLLRDNORM;
39665 return 0;
39666 }
39667diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39668index c439c82..1f20f57 100644
39669--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39670+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39671@@ -297,7 +297,7 @@ struct lis3lv02d {
39672 struct input_polled_dev *idev; /* input device */
39673 struct platform_device *pdev; /* platform device */
39674 struct regulator_bulk_data regulators[2];
39675- atomic_t count; /* interrupt count after last read */
39676+ atomic_unchecked_t count; /* interrupt count after last read */
39677 union axis_conversion ac; /* hw -> logical axis */
39678 int mapped_btns[3];
39679
39680diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39681index 2f30bad..c4c13d0 100644
39682--- a/drivers/misc/sgi-gru/gruhandles.c
39683+++ b/drivers/misc/sgi-gru/gruhandles.c
39684@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39685 unsigned long nsec;
39686
39687 nsec = CLKS2NSEC(clks);
39688- atomic_long_inc(&mcs_op_statistics[op].count);
39689- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39690+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39691+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39692 if (mcs_op_statistics[op].max < nsec)
39693 mcs_op_statistics[op].max = nsec;
39694 }
39695diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39696index 797d796..ae8f01e 100644
39697--- a/drivers/misc/sgi-gru/gruprocfs.c
39698+++ b/drivers/misc/sgi-gru/gruprocfs.c
39699@@ -32,9 +32,9 @@
39700
39701 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39702
39703-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39704+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39705 {
39706- unsigned long val = atomic_long_read(v);
39707+ unsigned long val = atomic_long_read_unchecked(v);
39708
39709 seq_printf(s, "%16lu %s\n", val, id);
39710 }
39711@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39712
39713 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39714 for (op = 0; op < mcsop_last; op++) {
39715- count = atomic_long_read(&mcs_op_statistics[op].count);
39716- total = atomic_long_read(&mcs_op_statistics[op].total);
39717+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39718+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39719 max = mcs_op_statistics[op].max;
39720 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39721 count ? total / count : 0, max);
39722diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39723index 5c3ce24..4915ccb 100644
39724--- a/drivers/misc/sgi-gru/grutables.h
39725+++ b/drivers/misc/sgi-gru/grutables.h
39726@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39727 * GRU statistics.
39728 */
39729 struct gru_stats_s {
39730- atomic_long_t vdata_alloc;
39731- atomic_long_t vdata_free;
39732- atomic_long_t gts_alloc;
39733- atomic_long_t gts_free;
39734- atomic_long_t gms_alloc;
39735- atomic_long_t gms_free;
39736- atomic_long_t gts_double_allocate;
39737- atomic_long_t assign_context;
39738- atomic_long_t assign_context_failed;
39739- atomic_long_t free_context;
39740- atomic_long_t load_user_context;
39741- atomic_long_t load_kernel_context;
39742- atomic_long_t lock_kernel_context;
39743- atomic_long_t unlock_kernel_context;
39744- atomic_long_t steal_user_context;
39745- atomic_long_t steal_kernel_context;
39746- atomic_long_t steal_context_failed;
39747- atomic_long_t nopfn;
39748- atomic_long_t asid_new;
39749- atomic_long_t asid_next;
39750- atomic_long_t asid_wrap;
39751- atomic_long_t asid_reuse;
39752- atomic_long_t intr;
39753- atomic_long_t intr_cbr;
39754- atomic_long_t intr_tfh;
39755- atomic_long_t intr_spurious;
39756- atomic_long_t intr_mm_lock_failed;
39757- atomic_long_t call_os;
39758- atomic_long_t call_os_wait_queue;
39759- atomic_long_t user_flush_tlb;
39760- atomic_long_t user_unload_context;
39761- atomic_long_t user_exception;
39762- atomic_long_t set_context_option;
39763- atomic_long_t check_context_retarget_intr;
39764- atomic_long_t check_context_unload;
39765- atomic_long_t tlb_dropin;
39766- atomic_long_t tlb_preload_page;
39767- atomic_long_t tlb_dropin_fail_no_asid;
39768- atomic_long_t tlb_dropin_fail_upm;
39769- atomic_long_t tlb_dropin_fail_invalid;
39770- atomic_long_t tlb_dropin_fail_range_active;
39771- atomic_long_t tlb_dropin_fail_idle;
39772- atomic_long_t tlb_dropin_fail_fmm;
39773- atomic_long_t tlb_dropin_fail_no_exception;
39774- atomic_long_t tfh_stale_on_fault;
39775- atomic_long_t mmu_invalidate_range;
39776- atomic_long_t mmu_invalidate_page;
39777- atomic_long_t flush_tlb;
39778- atomic_long_t flush_tlb_gru;
39779- atomic_long_t flush_tlb_gru_tgh;
39780- atomic_long_t flush_tlb_gru_zero_asid;
39781+ atomic_long_unchecked_t vdata_alloc;
39782+ atomic_long_unchecked_t vdata_free;
39783+ atomic_long_unchecked_t gts_alloc;
39784+ atomic_long_unchecked_t gts_free;
39785+ atomic_long_unchecked_t gms_alloc;
39786+ atomic_long_unchecked_t gms_free;
39787+ atomic_long_unchecked_t gts_double_allocate;
39788+ atomic_long_unchecked_t assign_context;
39789+ atomic_long_unchecked_t assign_context_failed;
39790+ atomic_long_unchecked_t free_context;
39791+ atomic_long_unchecked_t load_user_context;
39792+ atomic_long_unchecked_t load_kernel_context;
39793+ atomic_long_unchecked_t lock_kernel_context;
39794+ atomic_long_unchecked_t unlock_kernel_context;
39795+ atomic_long_unchecked_t steal_user_context;
39796+ atomic_long_unchecked_t steal_kernel_context;
39797+ atomic_long_unchecked_t steal_context_failed;
39798+ atomic_long_unchecked_t nopfn;
39799+ atomic_long_unchecked_t asid_new;
39800+ atomic_long_unchecked_t asid_next;
39801+ atomic_long_unchecked_t asid_wrap;
39802+ atomic_long_unchecked_t asid_reuse;
39803+ atomic_long_unchecked_t intr;
39804+ atomic_long_unchecked_t intr_cbr;
39805+ atomic_long_unchecked_t intr_tfh;
39806+ atomic_long_unchecked_t intr_spurious;
39807+ atomic_long_unchecked_t intr_mm_lock_failed;
39808+ atomic_long_unchecked_t call_os;
39809+ atomic_long_unchecked_t call_os_wait_queue;
39810+ atomic_long_unchecked_t user_flush_tlb;
39811+ atomic_long_unchecked_t user_unload_context;
39812+ atomic_long_unchecked_t user_exception;
39813+ atomic_long_unchecked_t set_context_option;
39814+ atomic_long_unchecked_t check_context_retarget_intr;
39815+ atomic_long_unchecked_t check_context_unload;
39816+ atomic_long_unchecked_t tlb_dropin;
39817+ atomic_long_unchecked_t tlb_preload_page;
39818+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39819+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39820+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39821+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39822+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39823+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39824+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39825+ atomic_long_unchecked_t tfh_stale_on_fault;
39826+ atomic_long_unchecked_t mmu_invalidate_range;
39827+ atomic_long_unchecked_t mmu_invalidate_page;
39828+ atomic_long_unchecked_t flush_tlb;
39829+ atomic_long_unchecked_t flush_tlb_gru;
39830+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39831+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39832
39833- atomic_long_t copy_gpa;
39834- atomic_long_t read_gpa;
39835+ atomic_long_unchecked_t copy_gpa;
39836+ atomic_long_unchecked_t read_gpa;
39837
39838- atomic_long_t mesq_receive;
39839- atomic_long_t mesq_receive_none;
39840- atomic_long_t mesq_send;
39841- atomic_long_t mesq_send_failed;
39842- atomic_long_t mesq_noop;
39843- atomic_long_t mesq_send_unexpected_error;
39844- atomic_long_t mesq_send_lb_overflow;
39845- atomic_long_t mesq_send_qlimit_reached;
39846- atomic_long_t mesq_send_amo_nacked;
39847- atomic_long_t mesq_send_put_nacked;
39848- atomic_long_t mesq_page_overflow;
39849- atomic_long_t mesq_qf_locked;
39850- atomic_long_t mesq_qf_noop_not_full;
39851- atomic_long_t mesq_qf_switch_head_failed;
39852- atomic_long_t mesq_qf_unexpected_error;
39853- atomic_long_t mesq_noop_unexpected_error;
39854- atomic_long_t mesq_noop_lb_overflow;
39855- atomic_long_t mesq_noop_qlimit_reached;
39856- atomic_long_t mesq_noop_amo_nacked;
39857- atomic_long_t mesq_noop_put_nacked;
39858- atomic_long_t mesq_noop_page_overflow;
39859+ atomic_long_unchecked_t mesq_receive;
39860+ atomic_long_unchecked_t mesq_receive_none;
39861+ atomic_long_unchecked_t mesq_send;
39862+ atomic_long_unchecked_t mesq_send_failed;
39863+ atomic_long_unchecked_t mesq_noop;
39864+ atomic_long_unchecked_t mesq_send_unexpected_error;
39865+ atomic_long_unchecked_t mesq_send_lb_overflow;
39866+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39867+ atomic_long_unchecked_t mesq_send_amo_nacked;
39868+ atomic_long_unchecked_t mesq_send_put_nacked;
39869+ atomic_long_unchecked_t mesq_page_overflow;
39870+ atomic_long_unchecked_t mesq_qf_locked;
39871+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39872+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39873+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39874+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39875+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39876+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39877+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39878+ atomic_long_unchecked_t mesq_noop_put_nacked;
39879+ atomic_long_unchecked_t mesq_noop_page_overflow;
39880
39881 };
39882
39883@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39884 tghop_invalidate, mcsop_last};
39885
39886 struct mcs_op_statistic {
39887- atomic_long_t count;
39888- atomic_long_t total;
39889+ atomic_long_unchecked_t count;
39890+ atomic_long_unchecked_t total;
39891 unsigned long max;
39892 };
39893
39894@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39895
39896 #define STAT(id) do { \
39897 if (gru_options & OPT_STATS) \
39898- atomic_long_inc(&gru_stats.id); \
39899+ atomic_long_inc_unchecked(&gru_stats.id); \
39900 } while (0)
39901
39902 #ifdef CONFIG_SGI_GRU_DEBUG
39903diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39904index c862cd4..0d176fe 100644
39905--- a/drivers/misc/sgi-xp/xp.h
39906+++ b/drivers/misc/sgi-xp/xp.h
39907@@ -288,7 +288,7 @@ struct xpc_interface {
39908 xpc_notify_func, void *);
39909 void (*received) (short, int, void *);
39910 enum xp_retval (*partid_to_nasids) (short, void *);
39911-};
39912+} __no_const;
39913
39914 extern struct xpc_interface xpc_interface;
39915
39916diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39917index b94d5f7..7f494c5 100644
39918--- a/drivers/misc/sgi-xp/xpc.h
39919+++ b/drivers/misc/sgi-xp/xpc.h
39920@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39921 void (*received_payload) (struct xpc_channel *, void *);
39922 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39923 };
39924+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39925
39926 /* struct xpc_partition act_state values (for XPC HB) */
39927
39928@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39929 /* found in xpc_main.c */
39930 extern struct device *xpc_part;
39931 extern struct device *xpc_chan;
39932-extern struct xpc_arch_operations xpc_arch_ops;
39933+extern xpc_arch_operations_no_const xpc_arch_ops;
39934 extern int xpc_disengage_timelimit;
39935 extern int xpc_disengage_timedout;
39936 extern int xpc_activate_IRQ_rcvd;
39937diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39938index d971817..33bdca5 100644
39939--- a/drivers/misc/sgi-xp/xpc_main.c
39940+++ b/drivers/misc/sgi-xp/xpc_main.c
39941@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39942 .notifier_call = xpc_system_die,
39943 };
39944
39945-struct xpc_arch_operations xpc_arch_ops;
39946+xpc_arch_operations_no_const xpc_arch_ops;
39947
39948 /*
39949 * Timer function to enforce the timelimit on the partition disengage.
39950@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39951
39952 if (((die_args->trapnr == X86_TRAP_MF) ||
39953 (die_args->trapnr == X86_TRAP_XF)) &&
39954- !user_mode_vm(die_args->regs))
39955+ !user_mode(die_args->regs))
39956 xpc_die_deactivate();
39957
39958 break;
39959diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39960index 49f04bc..65660c2 100644
39961--- a/drivers/mmc/core/mmc_ops.c
39962+++ b/drivers/mmc/core/mmc_ops.c
39963@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39964 void *data_buf;
39965 int is_on_stack;
39966
39967- is_on_stack = object_is_on_stack(buf);
39968+ is_on_stack = object_starts_on_stack(buf);
39969 if (is_on_stack) {
39970 /*
39971 * dma onto stack is unsafe/nonportable, but callers to this
39972diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39973index 0b74189..818358f 100644
39974--- a/drivers/mmc/host/dw_mmc.h
39975+++ b/drivers/mmc/host/dw_mmc.h
39976@@ -202,5 +202,5 @@ struct dw_mci_drv_data {
39977 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
39978 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
39979 int (*parse_dt)(struct dw_mci *host);
39980-};
39981+} __do_const;
39982 #endif /* _DW_MMC_H_ */
39983diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39984index c6f6246..60760a8 100644
39985--- a/drivers/mmc/host/sdhci-s3c.c
39986+++ b/drivers/mmc/host/sdhci-s3c.c
39987@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39988 * we can use overriding functions instead of default.
39989 */
39990 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39991- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39992- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39993- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39994+ pax_open_kernel();
39995+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39996+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39997+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39998+ pax_close_kernel();
39999 }
40000
40001 /* It supports additional host capabilities if needed */
40002diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
40003index 0c8bb6b..6f35deb 100644
40004--- a/drivers/mtd/nand/denali.c
40005+++ b/drivers/mtd/nand/denali.c
40006@@ -24,6 +24,7 @@
40007 #include <linux/slab.h>
40008 #include <linux/mtd/mtd.h>
40009 #include <linux/module.h>
40010+#include <linux/slab.h>
40011
40012 #include "denali.h"
40013
40014diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
40015index 51b9d6a..52af9a7 100644
40016--- a/drivers/mtd/nftlmount.c
40017+++ b/drivers/mtd/nftlmount.c
40018@@ -24,6 +24,7 @@
40019 #include <asm/errno.h>
40020 #include <linux/delay.h>
40021 #include <linux/slab.h>
40022+#include <linux/sched.h>
40023 #include <linux/mtd/mtd.h>
40024 #include <linux/mtd/nand.h>
40025 #include <linux/mtd/nftl.h>
40026diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
40027index f9d5615..99dd95f 100644
40028--- a/drivers/mtd/sm_ftl.c
40029+++ b/drivers/mtd/sm_ftl.c
40030@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
40031 #define SM_CIS_VENDOR_OFFSET 0x59
40032 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
40033 {
40034- struct attribute_group *attr_group;
40035+ attribute_group_no_const *attr_group;
40036 struct attribute **attributes;
40037 struct sm_sysfs_attribute *vendor_attribute;
40038
40039diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
40040index f975696..4597e21 100644
40041--- a/drivers/net/bonding/bond_main.c
40042+++ b/drivers/net/bonding/bond_main.c
40043@@ -4870,7 +4870,7 @@ static unsigned int bond_get_num_tx_queues(void)
40044 return tx_queues;
40045 }
40046
40047-static struct rtnl_link_ops bond_link_ops __read_mostly = {
40048+static struct rtnl_link_ops bond_link_ops = {
40049 .kind = "bond",
40050 .priv_size = sizeof(struct bonding),
40051 .setup = bond_setup,
40052@@ -4995,8 +4995,8 @@ static void __exit bonding_exit(void)
40053
40054 bond_destroy_debugfs();
40055
40056- rtnl_link_unregister(&bond_link_ops);
40057 unregister_pernet_subsys(&bond_net_ops);
40058+ rtnl_link_unregister(&bond_link_ops);
40059
40060 #ifdef CONFIG_NET_POLL_CONTROLLER
40061 /*
40062diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
40063index e1d2643..7f4133b 100644
40064--- a/drivers/net/ethernet/8390/ax88796.c
40065+++ b/drivers/net/ethernet/8390/ax88796.c
40066@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
40067 if (ax->plat->reg_offsets)
40068 ei_local->reg_offset = ax->plat->reg_offsets;
40069 else {
40070+ resource_size_t _mem_size = mem_size;
40071+ do_div(_mem_size, 0x18);
40072 ei_local->reg_offset = ax->reg_offsets;
40073 for (ret = 0; ret < 0x18; ret++)
40074- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
40075+ ax->reg_offsets[ret] = _mem_size * ret;
40076 }
40077
40078 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
40079diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40080index 151675d..0139a9d 100644
40081--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40082+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40083@@ -1112,7 +1112,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
40084 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
40085 {
40086 /* RX_MODE controlling object */
40087- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
40088+ bnx2x_init_rx_mode_obj(bp);
40089
40090 /* multicast configuration controlling object */
40091 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
40092diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40093index ce1a916..10b52b0 100644
40094--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40095+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40096@@ -960,6 +960,9 @@ static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
40097 struct bnx2x *bp = netdev_priv(dev);
40098
40099 /* Use the ethtool_dump "flag" field as the dump preset index */
40100+ if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
40101+ return -EINVAL;
40102+
40103 bp->dump_preset_idx = val->flag;
40104 return 0;
40105 }
40106@@ -986,8 +989,6 @@ static int bnx2x_get_dump_data(struct net_device *dev,
40107 struct bnx2x *bp = netdev_priv(dev);
40108 struct dump_header dump_hdr = {0};
40109
40110- memset(p, 0, dump->len);
40111-
40112 /* Disable parity attentions as long as following dump may
40113 * cause false alarms by reading never written registers. We
40114 * will re-enable parity attentions right after the dump.
40115diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40116index b4c9dea..2a9927f 100644
40117--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40118+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40119@@ -11497,6 +11497,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
40120 bp->min_msix_vec_cnt = 2;
40121 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
40122
40123+ bp->dump_preset_idx = 1;
40124+
40125 return rc;
40126 }
40127
40128diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40129index 32a9609..0b1c53a 100644
40130--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40131+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40132@@ -2387,15 +2387,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
40133 return rc;
40134 }
40135
40136-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40137- struct bnx2x_rx_mode_obj *o)
40138+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
40139 {
40140 if (CHIP_IS_E1x(bp)) {
40141- o->wait_comp = bnx2x_empty_rx_mode_wait;
40142- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
40143+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
40144+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
40145 } else {
40146- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
40147- o->config_rx_mode = bnx2x_set_rx_mode_e2;
40148+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
40149+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
40150 }
40151 }
40152
40153diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40154index 43c00bc..dd1d03d 100644
40155--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40156+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40157@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
40158
40159 /********************* RX MODE ****************/
40160
40161-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40162- struct bnx2x_rx_mode_obj *o);
40163+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
40164
40165 /**
40166 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
40167diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
40168index ff6e30e..87e8452 100644
40169--- a/drivers/net/ethernet/broadcom/tg3.h
40170+++ b/drivers/net/ethernet/broadcom/tg3.h
40171@@ -147,6 +147,7 @@
40172 #define CHIPREV_ID_5750_A0 0x4000
40173 #define CHIPREV_ID_5750_A1 0x4001
40174 #define CHIPREV_ID_5750_A3 0x4003
40175+#define CHIPREV_ID_5750_C1 0x4201
40176 #define CHIPREV_ID_5750_C2 0x4202
40177 #define CHIPREV_ID_5752_A0_HW 0x5000
40178 #define CHIPREV_ID_5752_A0 0x6000
40179diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40180index 71497e8..b650951 100644
40181--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40182+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40183@@ -3037,7 +3037,9 @@ static void t3_io_resume(struct pci_dev *pdev)
40184 CH_ALERT(adapter, "adapter recovering, PEX ERR 0x%x\n",
40185 t3_read_reg(adapter, A_PCIE_PEX_ERR));
40186
40187+ rtnl_lock();
40188 t3_resume_ports(adapter);
40189+ rtnl_unlock();
40190 }
40191
40192 static const struct pci_error_handlers t3_err_handler = {
40193diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40194index 8cffcdf..aadf043 100644
40195--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40196+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40197@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
40198 */
40199 struct l2t_skb_cb {
40200 arp_failure_handler_func arp_failure_handler;
40201-};
40202+} __no_const;
40203
40204 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
40205
40206diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
40207index 4c83003..2a2a5b9 100644
40208--- a/drivers/net/ethernet/dec/tulip/de4x5.c
40209+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
40210@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40211 for (i=0; i<ETH_ALEN; i++) {
40212 tmp.addr[i] = dev->dev_addr[i];
40213 }
40214- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40215+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40216 break;
40217
40218 case DE4X5_SET_HWADDR: /* Set the hardware address */
40219@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40220 spin_lock_irqsave(&lp->lock, flags);
40221 memcpy(&statbuf, &lp->pktStats, ioc->len);
40222 spin_unlock_irqrestore(&lp->lock, flags);
40223- if (copy_to_user(ioc->data, &statbuf, ioc->len))
40224+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
40225 return -EFAULT;
40226 break;
40227 }
40228diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
40229index 6e43426..1bd8365 100644
40230--- a/drivers/net/ethernet/emulex/benet/be_main.c
40231+++ b/drivers/net/ethernet/emulex/benet/be_main.c
40232@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
40233
40234 if (wrapped)
40235 newacc += 65536;
40236- ACCESS_ONCE(*acc) = newacc;
40237+ ACCESS_ONCE_RW(*acc) = newacc;
40238 }
40239
40240 void populate_erx_stats(struct be_adapter *adapter,
40241diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
40242index 21b85fb..b49e5fc 100644
40243--- a/drivers/net/ethernet/faraday/ftgmac100.c
40244+++ b/drivers/net/ethernet/faraday/ftgmac100.c
40245@@ -31,6 +31,8 @@
40246 #include <linux/netdevice.h>
40247 #include <linux/phy.h>
40248 #include <linux/platform_device.h>
40249+#include <linux/interrupt.h>
40250+#include <linux/irqreturn.h>
40251 #include <net/ip.h>
40252
40253 #include "ftgmac100.h"
40254diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
40255index a6eda8d..935d273 100644
40256--- a/drivers/net/ethernet/faraday/ftmac100.c
40257+++ b/drivers/net/ethernet/faraday/ftmac100.c
40258@@ -31,6 +31,8 @@
40259 #include <linux/module.h>
40260 #include <linux/netdevice.h>
40261 #include <linux/platform_device.h>
40262+#include <linux/interrupt.h>
40263+#include <linux/irqreturn.h>
40264
40265 #include "ftmac100.h"
40266
40267diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40268index 331987d..3be1135 100644
40269--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40270+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40271@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40272 }
40273
40274 /* update the base incval used to calculate frequency adjustment */
40275- ACCESS_ONCE(adapter->base_incval) = incval;
40276+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40277 smp_mb();
40278
40279 /* need lock to prevent incorrect read while modifying cyclecounter */
40280diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40281index fbe5363..266b4e3 100644
40282--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40283+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40284@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40285 struct __vxge_hw_fifo *fifo;
40286 struct vxge_hw_fifo_config *config;
40287 u32 txdl_size, txdl_per_memblock;
40288- struct vxge_hw_mempool_cbs fifo_mp_callback;
40289+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40290+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40291+ };
40292+
40293 struct __vxge_hw_virtualpath *vpath;
40294
40295 if ((vp == NULL) || (attr == NULL)) {
40296@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40297 goto exit;
40298 }
40299
40300- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40301-
40302 fifo->mempool =
40303 __vxge_hw_mempool_create(vpath->hldev,
40304 fifo->config->memblock_size,
40305diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40306index 5e7fb1d..f8d1810 100644
40307--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40308+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40309@@ -1948,7 +1948,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
40310 op_mode = QLC_83XX_DEFAULT_OPMODE;
40311
40312 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
40313- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40314+ pax_open_kernel();
40315+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40316+ pax_close_kernel();
40317 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40318 } else {
40319 return -EIO;
40320diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40321index b0c3de9..fc5857e 100644
40322--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40323+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40324@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
40325 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
40326 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
40327 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40328- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40329+ pax_open_kernel();
40330+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40331+ pax_close_kernel();
40332 } else if (priv_level == QLCNIC_PRIV_FUNC) {
40333 ahw->op_mode = QLCNIC_PRIV_FUNC;
40334 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
40335- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40336+ pax_open_kernel();
40337+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40338+ pax_close_kernel();
40339 } else if (priv_level == QLCNIC_MGMT_FUNC) {
40340 ahw->op_mode = QLCNIC_MGMT_FUNC;
40341 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40342- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40343+ pax_open_kernel();
40344+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40345+ pax_close_kernel();
40346 } else {
40347 return -EIO;
40348 }
40349diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
40350index 6acf82b..14b097e 100644
40351--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
40352+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_ctx.c
40353@@ -206,10 +206,10 @@ int qlcnic_fw_cmd_set_drv_version(struct qlcnic_adapter *adapter)
40354 if (err) {
40355 dev_info(&adapter->pdev->dev,
40356 "Failed to set driver version in firmware\n");
40357- return -EIO;
40358+ err = -EIO;
40359 }
40360-
40361- return 0;
40362+ qlcnic_free_mbx_args(&cmd);
40363+ return err;
40364 }
40365
40366 int
40367diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
40368index d3f8797..82a03d3 100644
40369--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
40370+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_io.c
40371@@ -262,7 +262,7 @@ void qlcnic_82xx_change_filter(struct qlcnic_adapter *adapter, u64 *uaddr,
40372
40373 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
40374 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
40375- memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
40376+ memcpy(mac_req->mac_addr, uaddr, ETH_ALEN);
40377
40378 vlan_req = (struct qlcnic_vlan_req *)&req->words[1];
40379 vlan_req->vlan_id = cpu_to_le16(vlan_id);
40380diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40381index 393f961..d343034 100644
40382--- a/drivers/net/ethernet/realtek/r8169.c
40383+++ b/drivers/net/ethernet/realtek/r8169.c
40384@@ -753,22 +753,22 @@ struct rtl8169_private {
40385 struct mdio_ops {
40386 void (*write)(struct rtl8169_private *, int, int);
40387 int (*read)(struct rtl8169_private *, int);
40388- } mdio_ops;
40389+ } __no_const mdio_ops;
40390
40391 struct pll_power_ops {
40392 void (*down)(struct rtl8169_private *);
40393 void (*up)(struct rtl8169_private *);
40394- } pll_power_ops;
40395+ } __no_const pll_power_ops;
40396
40397 struct jumbo_ops {
40398 void (*enable)(struct rtl8169_private *);
40399 void (*disable)(struct rtl8169_private *);
40400- } jumbo_ops;
40401+ } __no_const jumbo_ops;
40402
40403 struct csi_ops {
40404 void (*write)(struct rtl8169_private *, int, int);
40405 u32 (*read)(struct rtl8169_private *, int);
40406- } csi_ops;
40407+ } __no_const csi_ops;
40408
40409 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40410 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40411diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40412index 9a95abf..36df7f9 100644
40413--- a/drivers/net/ethernet/sfc/ptp.c
40414+++ b/drivers/net/ethernet/sfc/ptp.c
40415@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40416 (u32)((u64)ptp->start.dma_addr >> 32));
40417
40418 /* Clear flag that signals MC ready */
40419- ACCESS_ONCE(*start) = 0;
40420+ ACCESS_ONCE_RW(*start) = 0;
40421 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40422 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40423
40424diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40425index 50617c5..b13724c 100644
40426--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40427+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40428@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40429
40430 writel(value, ioaddr + MMC_CNTRL);
40431
40432- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40433- MMC_CNTRL, value);
40434+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40435+// MMC_CNTRL, value);
40436 }
40437
40438 /* To mask all all interrupts.*/
40439diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40440index e6fe0d8..2b7d752 100644
40441--- a/drivers/net/hyperv/hyperv_net.h
40442+++ b/drivers/net/hyperv/hyperv_net.h
40443@@ -101,7 +101,7 @@ struct rndis_device {
40444
40445 enum rndis_device_state state;
40446 bool link_state;
40447- atomic_t new_req_id;
40448+ atomic_unchecked_t new_req_id;
40449
40450 spinlock_t request_lock;
40451 struct list_head req_list;
40452diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40453index 0775f0a..d4fb316 100644
40454--- a/drivers/net/hyperv/rndis_filter.c
40455+++ b/drivers/net/hyperv/rndis_filter.c
40456@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40457 * template
40458 */
40459 set = &rndis_msg->msg.set_req;
40460- set->req_id = atomic_inc_return(&dev->new_req_id);
40461+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40462
40463 /* Add to the request list */
40464 spin_lock_irqsave(&dev->request_lock, flags);
40465@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40466
40467 /* Setup the rndis set */
40468 halt = &request->request_msg.msg.halt_req;
40469- halt->req_id = atomic_inc_return(&dev->new_req_id);
40470+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40471
40472 /* Ignore return since this msg is optional. */
40473 rndis_filter_send_request(dev, request);
40474diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40475index bf0d55e..82bcfbd1 100644
40476--- a/drivers/net/ieee802154/fakehard.c
40477+++ b/drivers/net/ieee802154/fakehard.c
40478@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40479 phy->transmit_power = 0xbf;
40480
40481 dev->netdev_ops = &fake_ops;
40482- dev->ml_priv = &fake_mlme;
40483+ dev->ml_priv = (void *)&fake_mlme;
40484
40485 priv = netdev_priv(dev);
40486 priv->phy = phy;
40487diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40488index 6e91931..2b0ebe7 100644
40489--- a/drivers/net/macvlan.c
40490+++ b/drivers/net/macvlan.c
40491@@ -905,13 +905,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40492 int macvlan_link_register(struct rtnl_link_ops *ops)
40493 {
40494 /* common fields */
40495- ops->priv_size = sizeof(struct macvlan_dev);
40496- ops->validate = macvlan_validate;
40497- ops->maxtype = IFLA_MACVLAN_MAX;
40498- ops->policy = macvlan_policy;
40499- ops->changelink = macvlan_changelink;
40500- ops->get_size = macvlan_get_size;
40501- ops->fill_info = macvlan_fill_info;
40502+ pax_open_kernel();
40503+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40504+ *(void **)&ops->validate = macvlan_validate;
40505+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40506+ *(const void **)&ops->policy = macvlan_policy;
40507+ *(void **)&ops->changelink = macvlan_changelink;
40508+ *(void **)&ops->get_size = macvlan_get_size;
40509+ *(void **)&ops->fill_info = macvlan_fill_info;
40510+ pax_close_kernel();
40511
40512 return rtnl_link_register(ops);
40513 };
40514@@ -967,7 +969,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40515 return NOTIFY_DONE;
40516 }
40517
40518-static struct notifier_block macvlan_notifier_block __read_mostly = {
40519+static struct notifier_block macvlan_notifier_block = {
40520 .notifier_call = macvlan_device_event,
40521 };
40522
40523diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40524index 523d6b2..5e16aa1 100644
40525--- a/drivers/net/macvtap.c
40526+++ b/drivers/net/macvtap.c
40527@@ -1110,7 +1110,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40528 return NOTIFY_DONE;
40529 }
40530
40531-static struct notifier_block macvtap_notifier_block __read_mostly = {
40532+static struct notifier_block macvtap_notifier_block = {
40533 .notifier_call = macvtap_device_event,
40534 };
40535
40536diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40537index daec9b0..6428fcb 100644
40538--- a/drivers/net/phy/mdio-bitbang.c
40539+++ b/drivers/net/phy/mdio-bitbang.c
40540@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40541 struct mdiobb_ctrl *ctrl = bus->priv;
40542
40543 module_put(ctrl->ops->owner);
40544+ mdiobus_unregister(bus);
40545 mdiobus_free(bus);
40546 }
40547 EXPORT_SYMBOL(free_mdio_bitbang);
40548diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40549index 72ff14b..11d442d 100644
40550--- a/drivers/net/ppp/ppp_generic.c
40551+++ b/drivers/net/ppp/ppp_generic.c
40552@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40553 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40554 struct ppp_stats stats;
40555 struct ppp_comp_stats cstats;
40556- char *vers;
40557
40558 switch (cmd) {
40559 case SIOCGPPPSTATS:
40560@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40561 break;
40562
40563 case SIOCGPPPVER:
40564- vers = PPP_VERSION;
40565- if (copy_to_user(addr, vers, strlen(vers) + 1))
40566+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40567 break;
40568 err = 0;
40569 break;
40570diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
40571index 1252d9c..80e660b 100644
40572--- a/drivers/net/slip/slhc.c
40573+++ b/drivers/net/slip/slhc.c
40574@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
40575 register struct tcphdr *thp;
40576 register struct iphdr *ip;
40577 register struct cstate *cs;
40578- int len, hdrlen;
40579+ long len, hdrlen;
40580 unsigned char *cp = icp;
40581
40582 /* We've got a compressed packet; read the change byte */
40583diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40584index b305105..8ead6df 100644
40585--- a/drivers/net/team/team.c
40586+++ b/drivers/net/team/team.c
40587@@ -2682,7 +2682,7 @@ static int team_device_event(struct notifier_block *unused,
40588 return NOTIFY_DONE;
40589 }
40590
40591-static struct notifier_block team_notifier_block __read_mostly = {
40592+static struct notifier_block team_notifier_block = {
40593 .notifier_call = team_device_event,
40594 };
40595
40596diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40597index 2491eb2..694b2ec 100644
40598--- a/drivers/net/tun.c
40599+++ b/drivers/net/tun.c
40600@@ -1869,7 +1869,7 @@ unlock:
40601 }
40602
40603 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40604- unsigned long arg, int ifreq_len)
40605+ unsigned long arg, size_t ifreq_len)
40606 {
40607 struct tun_file *tfile = file->private_data;
40608 struct tun_struct *tun;
40609@@ -1881,6 +1881,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40610 int vnet_hdr_sz;
40611 int ret;
40612
40613+ if (ifreq_len > sizeof ifr)
40614+ return -EFAULT;
40615+
40616 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40617 if (copy_from_user(&ifr, argp, ifreq_len))
40618 return -EFAULT;
40619diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40620index cba1d46..f703766 100644
40621--- a/drivers/net/usb/hso.c
40622+++ b/drivers/net/usb/hso.c
40623@@ -71,7 +71,7 @@
40624 #include <asm/byteorder.h>
40625 #include <linux/serial_core.h>
40626 #include <linux/serial.h>
40627-
40628+#include <asm/local.h>
40629
40630 #define MOD_AUTHOR "Option Wireless"
40631 #define MOD_DESCRIPTION "USB High Speed Option driver"
40632@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40633 struct urb *urb;
40634
40635 urb = serial->rx_urb[0];
40636- if (serial->port.count > 0) {
40637+ if (atomic_read(&serial->port.count) > 0) {
40638 count = put_rxbuf_data(urb, serial);
40639 if (count == -1)
40640 return;
40641@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40642 DUMP1(urb->transfer_buffer, urb->actual_length);
40643
40644 /* Anyone listening? */
40645- if (serial->port.count == 0)
40646+ if (atomic_read(&serial->port.count) == 0)
40647 return;
40648
40649 if (status == 0) {
40650@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40651 tty_port_tty_set(&serial->port, tty);
40652
40653 /* check for port already opened, if not set the termios */
40654- serial->port.count++;
40655- if (serial->port.count == 1) {
40656+ if (atomic_inc_return(&serial->port.count) == 1) {
40657 serial->rx_state = RX_IDLE;
40658 /* Force default termio settings */
40659 _hso_serial_set_termios(tty, NULL);
40660@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40661 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40662 if (result) {
40663 hso_stop_serial_device(serial->parent);
40664- serial->port.count--;
40665+ atomic_dec(&serial->port.count);
40666 kref_put(&serial->parent->ref, hso_serial_ref_free);
40667 }
40668 } else {
40669@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40670
40671 /* reset the rts and dtr */
40672 /* do the actual close */
40673- serial->port.count--;
40674+ atomic_dec(&serial->port.count);
40675
40676- if (serial->port.count <= 0) {
40677- serial->port.count = 0;
40678+ if (atomic_read(&serial->port.count) <= 0) {
40679+ atomic_set(&serial->port.count, 0);
40680 tty_port_tty_set(&serial->port, NULL);
40681 if (!usb_gone)
40682 hso_stop_serial_device(serial->parent);
40683@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40684
40685 /* the actual setup */
40686 spin_lock_irqsave(&serial->serial_lock, flags);
40687- if (serial->port.count)
40688+ if (atomic_read(&serial->port.count))
40689 _hso_serial_set_termios(tty, old);
40690 else
40691 tty->termios = *old;
40692@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40693 D1("Pending read interrupt on port %d\n", i);
40694 spin_lock(&serial->serial_lock);
40695 if (serial->rx_state == RX_IDLE &&
40696- serial->port.count > 0) {
40697+ atomic_read(&serial->port.count) > 0) {
40698 /* Setup and send a ctrl req read on
40699 * port i */
40700 if (!serial->rx_urb_filled[0]) {
40701@@ -3057,7 +3056,7 @@ static int hso_resume(struct usb_interface *iface)
40702 /* Start all serial ports */
40703 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40704 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40705- if (dev2ser(serial_table[i])->port.count) {
40706+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40707 result =
40708 hso_start_serial_device(serial_table[i], GFP_NOIO);
40709 hso_kick_transmit(dev2ser(serial_table[i]));
40710diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40711index 57325f3..36b181f 100644
40712--- a/drivers/net/vxlan.c
40713+++ b/drivers/net/vxlan.c
40714@@ -1579,7 +1579,7 @@ nla_put_failure:
40715 return -EMSGSIZE;
40716 }
40717
40718-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40719+static struct rtnl_link_ops vxlan_link_ops = {
40720 .kind = "vxlan",
40721 .maxtype = IFLA_VXLAN_MAX,
40722 .policy = vxlan_policy,
40723diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40724index 34c8a33..3261fdc 100644
40725--- a/drivers/net/wireless/at76c50x-usb.c
40726+++ b/drivers/net/wireless/at76c50x-usb.c
40727@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40728 }
40729
40730 /* Convert timeout from the DFU status to jiffies */
40731-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40732+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40733 {
40734 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40735 | (s->poll_timeout[1] << 8)
40736diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40737index 8d78253..bebbb68 100644
40738--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40739+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40740@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40741 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40742 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40743
40744- ACCESS_ONCE(ads->ds_link) = i->link;
40745- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40746+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40747+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40748
40749 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40750 ctl6 = SM(i->keytype, AR_EncrType);
40751@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40752
40753 if ((i->is_first || i->is_last) &&
40754 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40755- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40756+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40757 | set11nTries(i->rates, 1)
40758 | set11nTries(i->rates, 2)
40759 | set11nTries(i->rates, 3)
40760 | (i->dur_update ? AR_DurUpdateEna : 0)
40761 | SM(0, AR_BurstDur);
40762
40763- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40764+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40765 | set11nRate(i->rates, 1)
40766 | set11nRate(i->rates, 2)
40767 | set11nRate(i->rates, 3);
40768 } else {
40769- ACCESS_ONCE(ads->ds_ctl2) = 0;
40770- ACCESS_ONCE(ads->ds_ctl3) = 0;
40771+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40772+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40773 }
40774
40775 if (!i->is_first) {
40776- ACCESS_ONCE(ads->ds_ctl0) = 0;
40777- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40778- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40779+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40780+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40781+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40782 return;
40783 }
40784
40785@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40786 break;
40787 }
40788
40789- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40790+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40791 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40792 | SM(i->txpower, AR_XmitPower)
40793 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40794@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40795 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40796 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40797
40798- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40799- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40800+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40801+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40802
40803 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40804 return;
40805
40806- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40807+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40808 | set11nPktDurRTSCTS(i->rates, 1);
40809
40810- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40811+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40812 | set11nPktDurRTSCTS(i->rates, 3);
40813
40814- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40815+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40816 | set11nRateFlags(i->rates, 1)
40817 | set11nRateFlags(i->rates, 2)
40818 | set11nRateFlags(i->rates, 3)
40819diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40820index 301bf72..3f5654f 100644
40821--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40822+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40823@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40824 (i->qcu << AR_TxQcuNum_S) | desc_len;
40825
40826 checksum += val;
40827- ACCESS_ONCE(ads->info) = val;
40828+ ACCESS_ONCE_RW(ads->info) = val;
40829
40830 checksum += i->link;
40831- ACCESS_ONCE(ads->link) = i->link;
40832+ ACCESS_ONCE_RW(ads->link) = i->link;
40833
40834 checksum += i->buf_addr[0];
40835- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40836+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40837 checksum += i->buf_addr[1];
40838- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40839+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40840 checksum += i->buf_addr[2];
40841- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40842+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40843 checksum += i->buf_addr[3];
40844- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40845+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40846
40847 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40848- ACCESS_ONCE(ads->ctl3) = val;
40849+ ACCESS_ONCE_RW(ads->ctl3) = val;
40850 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40851- ACCESS_ONCE(ads->ctl5) = val;
40852+ ACCESS_ONCE_RW(ads->ctl5) = val;
40853 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40854- ACCESS_ONCE(ads->ctl7) = val;
40855+ ACCESS_ONCE_RW(ads->ctl7) = val;
40856 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40857- ACCESS_ONCE(ads->ctl9) = val;
40858+ ACCESS_ONCE_RW(ads->ctl9) = val;
40859
40860 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40861- ACCESS_ONCE(ads->ctl10) = checksum;
40862+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40863
40864 if (i->is_first || i->is_last) {
40865- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40866+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40867 | set11nTries(i->rates, 1)
40868 | set11nTries(i->rates, 2)
40869 | set11nTries(i->rates, 3)
40870 | (i->dur_update ? AR_DurUpdateEna : 0)
40871 | SM(0, AR_BurstDur);
40872
40873- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40874+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40875 | set11nRate(i->rates, 1)
40876 | set11nRate(i->rates, 2)
40877 | set11nRate(i->rates, 3);
40878 } else {
40879- ACCESS_ONCE(ads->ctl13) = 0;
40880- ACCESS_ONCE(ads->ctl14) = 0;
40881+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40882+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40883 }
40884
40885 ads->ctl20 = 0;
40886@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40887
40888 ctl17 = SM(i->keytype, AR_EncrType);
40889 if (!i->is_first) {
40890- ACCESS_ONCE(ads->ctl11) = 0;
40891- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40892- ACCESS_ONCE(ads->ctl15) = 0;
40893- ACCESS_ONCE(ads->ctl16) = 0;
40894- ACCESS_ONCE(ads->ctl17) = ctl17;
40895- ACCESS_ONCE(ads->ctl18) = 0;
40896- ACCESS_ONCE(ads->ctl19) = 0;
40897+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40898+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40899+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40900+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40901+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40902+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40903+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40904 return;
40905 }
40906
40907- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40908+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40909 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40910 | SM(i->txpower, AR_XmitPower)
40911 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40912@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40913 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40914 ctl12 |= SM(val, AR_PAPRDChainMask);
40915
40916- ACCESS_ONCE(ads->ctl12) = ctl12;
40917- ACCESS_ONCE(ads->ctl17) = ctl17;
40918+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40919+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40920
40921- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40922+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40923 | set11nPktDurRTSCTS(i->rates, 1);
40924
40925- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40926+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40927 | set11nPktDurRTSCTS(i->rates, 3);
40928
40929- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40930+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40931 | set11nRateFlags(i->rates, 1)
40932 | set11nRateFlags(i->rates, 2)
40933 | set11nRateFlags(i->rates, 3)
40934 | SM(i->rtscts_rate, AR_RTSCTSRate);
40935
40936- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40937+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40938 }
40939
40940 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40941diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40942index ae30343..a117806 100644
40943--- a/drivers/net/wireless/ath/ath9k/hw.h
40944+++ b/drivers/net/wireless/ath/ath9k/hw.h
40945@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
40946
40947 /* ANI */
40948 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40949-};
40950+} __no_const;
40951
40952 /**
40953 * struct ath_spec_scan - parameters for Atheros spectral scan
40954@@ -721,7 +721,7 @@ struct ath_hw_ops {
40955 struct ath_spec_scan *param);
40956 void (*spectral_scan_trigger)(struct ath_hw *ah);
40957 void (*spectral_scan_wait)(struct ath_hw *ah);
40958-};
40959+} __no_const;
40960
40961 struct ath_nf_limits {
40962 s16 max;
40963diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40964index b37a582..680835d 100644
40965--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40966+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40967@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40968 */
40969 if (il3945_mod_params.disable_hw_scan) {
40970 D_INFO("Disabling hw_scan\n");
40971- il3945_mac_ops.hw_scan = NULL;
40972+ pax_open_kernel();
40973+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40974+ pax_close_kernel();
40975 }
40976
40977 D_INFO("*** LOAD DRIVER ***\n");
40978diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40979index d532948..e0d8bb1 100644
40980--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40981+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40982@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40983 {
40984 struct iwl_priv *priv = file->private_data;
40985 char buf[64];
40986- int buf_size;
40987+ size_t buf_size;
40988 u32 offset, len;
40989
40990 memset(buf, 0, sizeof(buf));
40991@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40992 struct iwl_priv *priv = file->private_data;
40993
40994 char buf[8];
40995- int buf_size;
40996+ size_t buf_size;
40997 u32 reset_flag;
40998
40999 memset(buf, 0, sizeof(buf));
41000@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
41001 {
41002 struct iwl_priv *priv = file->private_data;
41003 char buf[8];
41004- int buf_size;
41005+ size_t buf_size;
41006 int ht40;
41007
41008 memset(buf, 0, sizeof(buf));
41009@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
41010 {
41011 struct iwl_priv *priv = file->private_data;
41012 char buf[8];
41013- int buf_size;
41014+ size_t buf_size;
41015 int value;
41016
41017 memset(buf, 0, sizeof(buf));
41018@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
41019 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
41020 DEBUGFS_READ_FILE_OPS(current_sleep_command);
41021
41022-static const char *fmt_value = " %-30s %10u\n";
41023-static const char *fmt_hex = " %-30s 0x%02X\n";
41024-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
41025-static const char *fmt_header =
41026+static const char fmt_value[] = " %-30s %10u\n";
41027+static const char fmt_hex[] = " %-30s 0x%02X\n";
41028+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
41029+static const char fmt_header[] =
41030 "%-32s current cumulative delta max\n";
41031
41032 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
41033@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
41034 {
41035 struct iwl_priv *priv = file->private_data;
41036 char buf[8];
41037- int buf_size;
41038+ size_t buf_size;
41039 int clear;
41040
41041 memset(buf, 0, sizeof(buf));
41042@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
41043 {
41044 struct iwl_priv *priv = file->private_data;
41045 char buf[8];
41046- int buf_size;
41047+ size_t buf_size;
41048 int trace;
41049
41050 memset(buf, 0, sizeof(buf));
41051@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
41052 {
41053 struct iwl_priv *priv = file->private_data;
41054 char buf[8];
41055- int buf_size;
41056+ size_t buf_size;
41057 int missed;
41058
41059 memset(buf, 0, sizeof(buf));
41060@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
41061
41062 struct iwl_priv *priv = file->private_data;
41063 char buf[8];
41064- int buf_size;
41065+ size_t buf_size;
41066 int plcp;
41067
41068 memset(buf, 0, sizeof(buf));
41069@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
41070
41071 struct iwl_priv *priv = file->private_data;
41072 char buf[8];
41073- int buf_size;
41074+ size_t buf_size;
41075 int flush;
41076
41077 memset(buf, 0, sizeof(buf));
41078@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
41079
41080 struct iwl_priv *priv = file->private_data;
41081 char buf[8];
41082- int buf_size;
41083+ size_t buf_size;
41084 int rts;
41085
41086 if (!priv->cfg->ht_params)
41087@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
41088 {
41089 struct iwl_priv *priv = file->private_data;
41090 char buf[8];
41091- int buf_size;
41092+ size_t buf_size;
41093
41094 memset(buf, 0, sizeof(buf));
41095 buf_size = min(count, sizeof(buf) - 1);
41096@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
41097 struct iwl_priv *priv = file->private_data;
41098 u32 event_log_flag;
41099 char buf[8];
41100- int buf_size;
41101+ size_t buf_size;
41102
41103 /* check that the interface is up */
41104 if (!iwl_is_ready(priv))
41105@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
41106 struct iwl_priv *priv = file->private_data;
41107 char buf[8];
41108 u32 calib_disabled;
41109- int buf_size;
41110+ size_t buf_size;
41111
41112 memset(buf, 0, sizeof(buf));
41113 buf_size = min(count, sizeof(buf) - 1);
41114diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
41115index 50ba0a4..29424e7 100644
41116--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
41117+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
41118@@ -1329,7 +1329,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
41119 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
41120
41121 char buf[8];
41122- int buf_size;
41123+ size_t buf_size;
41124 u32 reset_flag;
41125
41126 memset(buf, 0, sizeof(buf));
41127@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
41128 {
41129 struct iwl_trans *trans = file->private_data;
41130 char buf[8];
41131- int buf_size;
41132+ size_t buf_size;
41133 int csr;
41134
41135 memset(buf, 0, sizeof(buf));
41136diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
41137index cb34c78..9fec0dc 100644
41138--- a/drivers/net/wireless/mac80211_hwsim.c
41139+++ b/drivers/net/wireless/mac80211_hwsim.c
41140@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
41141
41142 if (channels > 1) {
41143 hwsim_if_comb.num_different_channels = channels;
41144- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41145- mac80211_hwsim_ops.cancel_hw_scan =
41146- mac80211_hwsim_cancel_hw_scan;
41147- mac80211_hwsim_ops.sw_scan_start = NULL;
41148- mac80211_hwsim_ops.sw_scan_complete = NULL;
41149- mac80211_hwsim_ops.remain_on_channel =
41150- mac80211_hwsim_roc;
41151- mac80211_hwsim_ops.cancel_remain_on_channel =
41152- mac80211_hwsim_croc;
41153- mac80211_hwsim_ops.add_chanctx =
41154- mac80211_hwsim_add_chanctx;
41155- mac80211_hwsim_ops.remove_chanctx =
41156- mac80211_hwsim_remove_chanctx;
41157- mac80211_hwsim_ops.change_chanctx =
41158- mac80211_hwsim_change_chanctx;
41159- mac80211_hwsim_ops.assign_vif_chanctx =
41160- mac80211_hwsim_assign_vif_chanctx;
41161- mac80211_hwsim_ops.unassign_vif_chanctx =
41162- mac80211_hwsim_unassign_vif_chanctx;
41163+ pax_open_kernel();
41164+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41165+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
41166+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
41167+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
41168+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
41169+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
41170+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
41171+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
41172+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
41173+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
41174+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
41175+ pax_close_kernel();
41176 }
41177
41178 spin_lock_init(&hwsim_radio_lock);
41179diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
41180index 8169a85..7fa3b47 100644
41181--- a/drivers/net/wireless/rndis_wlan.c
41182+++ b/drivers/net/wireless/rndis_wlan.c
41183@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
41184
41185 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
41186
41187- if (rts_threshold < 0 || rts_threshold > 2347)
41188+ if (rts_threshold > 2347)
41189 rts_threshold = 2347;
41190
41191 tmp = cpu_to_le32(rts_threshold);
41192diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
41193index 7510723..5ba37f5 100644
41194--- a/drivers/net/wireless/rt2x00/rt2x00.h
41195+++ b/drivers/net/wireless/rt2x00/rt2x00.h
41196@@ -386,7 +386,7 @@ struct rt2x00_intf {
41197 * for hardware which doesn't support hardware
41198 * sequence counting.
41199 */
41200- atomic_t seqno;
41201+ atomic_unchecked_t seqno;
41202 };
41203
41204 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
41205diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
41206index 2c12311..7b77f24 100644
41207--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
41208+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
41209@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
41210 * sequence counter given by mac80211.
41211 */
41212 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
41213- seqno = atomic_add_return(0x10, &intf->seqno);
41214+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
41215 else
41216- seqno = atomic_read(&intf->seqno);
41217+ seqno = atomic_read_unchecked(&intf->seqno);
41218
41219 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
41220 hdr->seq_ctrl |= cpu_to_le16(seqno);
41221diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
41222index e2b3d9c..67a5184 100644
41223--- a/drivers/net/wireless/ti/wl1251/sdio.c
41224+++ b/drivers/net/wireless/ti/wl1251/sdio.c
41225@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
41226
41227 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
41228
41229- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41230- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41231+ pax_open_kernel();
41232+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41233+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41234+ pax_close_kernel();
41235
41236 wl1251_info("using dedicated interrupt line");
41237 } else {
41238- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41239- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41240+ pax_open_kernel();
41241+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41242+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41243+ pax_close_kernel();
41244
41245 wl1251_info("using SDIO interrupt");
41246 }
41247diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41248index 1c627da..69f7d17 100644
41249--- a/drivers/net/wireless/ti/wl12xx/main.c
41250+++ b/drivers/net/wireless/ti/wl12xx/main.c
41251@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41252 sizeof(wl->conf.mem));
41253
41254 /* read data preparation is only needed by wl127x */
41255- wl->ops->prepare_read = wl127x_prepare_read;
41256+ pax_open_kernel();
41257+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41258+ pax_close_kernel();
41259
41260 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41261 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41262@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41263 sizeof(wl->conf.mem));
41264
41265 /* read data preparation is only needed by wl127x */
41266- wl->ops->prepare_read = wl127x_prepare_read;
41267+ pax_open_kernel();
41268+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41269+ pax_close_kernel();
41270
41271 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41272 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41273diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41274index 9fa692d..b31fee0 100644
41275--- a/drivers/net/wireless/ti/wl18xx/main.c
41276+++ b/drivers/net/wireless/ti/wl18xx/main.c
41277@@ -1687,8 +1687,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41278 }
41279
41280 if (!checksum_param) {
41281- wl18xx_ops.set_rx_csum = NULL;
41282- wl18xx_ops.init_vif = NULL;
41283+ pax_open_kernel();
41284+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41285+ *(void **)&wl18xx_ops.init_vif = NULL;
41286+ pax_close_kernel();
41287 }
41288
41289 /* Enable 11a Band only if we have 5G antennas */
41290diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41291index 7ef0b4a..ff65c28 100644
41292--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41293+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41294@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
41295 {
41296 struct zd_usb *usb = urb->context;
41297 struct zd_usb_interrupt *intr = &usb->intr;
41298- int len;
41299+ unsigned int len;
41300 u16 int_num;
41301
41302 ZD_ASSERT(in_interrupt());
41303diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41304index d93b2b6..ae50401 100644
41305--- a/drivers/oprofile/buffer_sync.c
41306+++ b/drivers/oprofile/buffer_sync.c
41307@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41308 if (cookie == NO_COOKIE)
41309 offset = pc;
41310 if (cookie == INVALID_COOKIE) {
41311- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41312+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41313 offset = pc;
41314 }
41315 if (cookie != last_cookie) {
41316@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41317 /* add userspace sample */
41318
41319 if (!mm) {
41320- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41321+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41322 return 0;
41323 }
41324
41325 cookie = lookup_dcookie(mm, s->eip, &offset);
41326
41327 if (cookie == INVALID_COOKIE) {
41328- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41329+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41330 return 0;
41331 }
41332
41333@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41334 /* ignore backtraces if failed to add a sample */
41335 if (state == sb_bt_start) {
41336 state = sb_bt_ignore;
41337- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41338+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41339 }
41340 }
41341 release_mm(mm);
41342diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41343index c0cc4e7..44d4e54 100644
41344--- a/drivers/oprofile/event_buffer.c
41345+++ b/drivers/oprofile/event_buffer.c
41346@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41347 }
41348
41349 if (buffer_pos == buffer_size) {
41350- atomic_inc(&oprofile_stats.event_lost_overflow);
41351+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41352 return;
41353 }
41354
41355diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41356index ed2c3ec..deda85a 100644
41357--- a/drivers/oprofile/oprof.c
41358+++ b/drivers/oprofile/oprof.c
41359@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41360 if (oprofile_ops.switch_events())
41361 return;
41362
41363- atomic_inc(&oprofile_stats.multiplex_counter);
41364+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41365 start_switch_worker();
41366 }
41367
41368diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41369index 84a208d..d61b0a1 100644
41370--- a/drivers/oprofile/oprofile_files.c
41371+++ b/drivers/oprofile/oprofile_files.c
41372@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41373
41374 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41375
41376-static ssize_t timeout_read(struct file *file, char __user *buf,
41377+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41378 size_t count, loff_t *offset)
41379 {
41380 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41381diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41382index 917d28e..d62d981 100644
41383--- a/drivers/oprofile/oprofile_stats.c
41384+++ b/drivers/oprofile/oprofile_stats.c
41385@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41386 cpu_buf->sample_invalid_eip = 0;
41387 }
41388
41389- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41390- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41391- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41392- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41393- atomic_set(&oprofile_stats.multiplex_counter, 0);
41394+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41395+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41396+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41397+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41398+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41399 }
41400
41401
41402diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41403index 38b6fc0..b5cbfce 100644
41404--- a/drivers/oprofile/oprofile_stats.h
41405+++ b/drivers/oprofile/oprofile_stats.h
41406@@ -13,11 +13,11 @@
41407 #include <linux/atomic.h>
41408
41409 struct oprofile_stat_struct {
41410- atomic_t sample_lost_no_mm;
41411- atomic_t sample_lost_no_mapping;
41412- atomic_t bt_lost_no_mapping;
41413- atomic_t event_lost_overflow;
41414- atomic_t multiplex_counter;
41415+ atomic_unchecked_t sample_lost_no_mm;
41416+ atomic_unchecked_t sample_lost_no_mapping;
41417+ atomic_unchecked_t bt_lost_no_mapping;
41418+ atomic_unchecked_t event_lost_overflow;
41419+ atomic_unchecked_t multiplex_counter;
41420 };
41421
41422 extern struct oprofile_stat_struct oprofile_stats;
41423diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41424index 7c12d9c..558bf3bb 100644
41425--- a/drivers/oprofile/oprofilefs.c
41426+++ b/drivers/oprofile/oprofilefs.c
41427@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
41428
41429
41430 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41431- char const *name, atomic_t *val)
41432+ char const *name, atomic_unchecked_t *val)
41433 {
41434 return __oprofilefs_create_file(sb, root, name,
41435 &atomic_ro_fops, 0444, val);
41436diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41437index 93404f7..4a313d8 100644
41438--- a/drivers/oprofile/timer_int.c
41439+++ b/drivers/oprofile/timer_int.c
41440@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41441 return NOTIFY_OK;
41442 }
41443
41444-static struct notifier_block __refdata oprofile_cpu_notifier = {
41445+static struct notifier_block oprofile_cpu_notifier = {
41446 .notifier_call = oprofile_cpu_notify,
41447 };
41448
41449diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41450index 92ed045..62d39bd7 100644
41451--- a/drivers/parport/procfs.c
41452+++ b/drivers/parport/procfs.c
41453@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41454
41455 *ppos += len;
41456
41457- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41458+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41459 }
41460
41461 #ifdef CONFIG_PARPORT_1284
41462@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41463
41464 *ppos += len;
41465
41466- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41467+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41468 }
41469 #endif /* IEEE1284.3 support. */
41470
41471diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41472index c35e8ad..fc33beb 100644
41473--- a/drivers/pci/hotplug/acpiphp_ibm.c
41474+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41475@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41476 goto init_cleanup;
41477 }
41478
41479- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41480+ pax_open_kernel();
41481+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41482+ pax_close_kernel();
41483 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41484
41485 return retval;
41486diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41487index a6a71c4..c91097b 100644
41488--- a/drivers/pci/hotplug/cpcihp_generic.c
41489+++ b/drivers/pci/hotplug/cpcihp_generic.c
41490@@ -73,7 +73,6 @@ static u16 port;
41491 static unsigned int enum_bit;
41492 static u8 enum_mask;
41493
41494-static struct cpci_hp_controller_ops generic_hpc_ops;
41495 static struct cpci_hp_controller generic_hpc;
41496
41497 static int __init validate_parameters(void)
41498@@ -139,6 +138,10 @@ static int query_enum(void)
41499 return ((value & enum_mask) == enum_mask);
41500 }
41501
41502+static struct cpci_hp_controller_ops generic_hpc_ops = {
41503+ .query_enum = query_enum,
41504+};
41505+
41506 static int __init cpcihp_generic_init(void)
41507 {
41508 int status;
41509@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41510 pci_dev_put(dev);
41511
41512 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41513- generic_hpc_ops.query_enum = query_enum;
41514 generic_hpc.ops = &generic_hpc_ops;
41515
41516 status = cpci_hp_register_controller(&generic_hpc);
41517diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41518index 449b4bb..257e2e8 100644
41519--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41520+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41521@@ -59,7 +59,6 @@
41522 /* local variables */
41523 static bool debug;
41524 static bool poll;
41525-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41526 static struct cpci_hp_controller zt5550_hpc;
41527
41528 /* Primary cPCI bus bridge device */
41529@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41530 return 0;
41531 }
41532
41533+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41534+ .query_enum = zt5550_hc_query_enum,
41535+};
41536+
41537 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41538 {
41539 int status;
41540@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41541 dbg("returned from zt5550_hc_config");
41542
41543 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41544- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41545 zt5550_hpc.ops = &zt5550_hpc_ops;
41546 if(!poll) {
41547 zt5550_hpc.irq = hc_dev->irq;
41548 zt5550_hpc.irq_flags = IRQF_SHARED;
41549 zt5550_hpc.dev_id = hc_dev;
41550
41551- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41552- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41553- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41554+ pax_open_kernel();
41555+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41556+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41557+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41558+ pax_open_kernel();
41559 } else {
41560 info("using ENUM# polling mode");
41561 }
41562diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41563index 76ba8a1..20ca857 100644
41564--- a/drivers/pci/hotplug/cpqphp_nvram.c
41565+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41566@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41567
41568 void compaq_nvram_init (void __iomem *rom_start)
41569 {
41570+
41571+#ifndef CONFIG_PAX_KERNEXEC
41572 if (rom_start) {
41573 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41574 }
41575+#endif
41576+
41577 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41578
41579 /* initialize our int15 lock */
41580diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41581index ec20f74..c1d961e 100644
41582--- a/drivers/pci/hotplug/pci_hotplug_core.c
41583+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41584@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41585 return -EINVAL;
41586 }
41587
41588- slot->ops->owner = owner;
41589- slot->ops->mod_name = mod_name;
41590+ pax_open_kernel();
41591+ *(struct module **)&slot->ops->owner = owner;
41592+ *(const char **)&slot->ops->mod_name = mod_name;
41593+ pax_close_kernel();
41594
41595 mutex_lock(&pci_hp_mutex);
41596 /*
41597diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41598index 7d72c5e..edce02c 100644
41599--- a/drivers/pci/hotplug/pciehp_core.c
41600+++ b/drivers/pci/hotplug/pciehp_core.c
41601@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41602 struct slot *slot = ctrl->slot;
41603 struct hotplug_slot *hotplug = NULL;
41604 struct hotplug_slot_info *info = NULL;
41605- struct hotplug_slot_ops *ops = NULL;
41606+ hotplug_slot_ops_no_const *ops = NULL;
41607 char name[SLOT_NAME_SIZE];
41608 int retval = -ENOMEM;
41609
41610diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41611index 5b4a9d9..cd5ac1f 100644
41612--- a/drivers/pci/pci-sysfs.c
41613+++ b/drivers/pci/pci-sysfs.c
41614@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41615 {
41616 /* allocate attribute structure, piggyback attribute name */
41617 int name_len = write_combine ? 13 : 10;
41618- struct bin_attribute *res_attr;
41619+ bin_attribute_no_const *res_attr;
41620 int retval;
41621
41622 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41623@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41624 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41625 {
41626 int retval;
41627- struct bin_attribute *attr;
41628+ bin_attribute_no_const *attr;
41629
41630 /* If the device has VPD, try to expose it in sysfs. */
41631 if (dev->vpd) {
41632@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41633 {
41634 int retval;
41635 int rom_size = 0;
41636- struct bin_attribute *attr;
41637+ bin_attribute_no_const *attr;
41638
41639 if (!sysfs_initialized)
41640 return -EACCES;
41641diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41642index d1182c4..2a138ec 100644
41643--- a/drivers/pci/pci.h
41644+++ b/drivers/pci/pci.h
41645@@ -92,7 +92,7 @@ struct pci_vpd_ops {
41646 struct pci_vpd {
41647 unsigned int len;
41648 const struct pci_vpd_ops *ops;
41649- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41650+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41651 };
41652
41653 int pci_vpd_pci22_init(struct pci_dev *dev);
41654diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41655index d320df6..ca9a8f6 100644
41656--- a/drivers/pci/pcie/aspm.c
41657+++ b/drivers/pci/pcie/aspm.c
41658@@ -27,9 +27,9 @@
41659 #define MODULE_PARAM_PREFIX "pcie_aspm."
41660
41661 /* Note: those are not register definitions */
41662-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41663-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41664-#define ASPM_STATE_L1 (4) /* L1 state */
41665+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41666+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41667+#define ASPM_STATE_L1 (4U) /* L1 state */
41668 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41669 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41670
41671diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41672index ea37072..10e58e56 100644
41673--- a/drivers/pci/probe.c
41674+++ b/drivers/pci/probe.c
41675@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41676 struct pci_bus_region region;
41677 bool bar_too_big = false, bar_disabled = false;
41678
41679- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41680+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41681
41682 /* No printks while decoding is disabled! */
41683 if (!dev->mmio_always_on) {
41684diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41685index 0812608..b04018c4 100644
41686--- a/drivers/pci/proc.c
41687+++ b/drivers/pci/proc.c
41688@@ -453,7 +453,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41689 static int __init pci_proc_init(void)
41690 {
41691 struct pci_dev *dev = NULL;
41692+
41693+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41694+#ifdef CONFIG_GRKERNSEC_PROC_USER
41695+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41696+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41697+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41698+#endif
41699+#else
41700 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41701+#endif
41702 proc_create("devices", 0, proc_bus_pci_dir,
41703 &proc_bus_pci_dev_operations);
41704 proc_initialized = 1;
41705diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
41706index 3e5b4497..dcdfb70 100644
41707--- a/drivers/platform/x86/chromeos_laptop.c
41708+++ b/drivers/platform/x86/chromeos_laptop.c
41709@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
41710 return 0;
41711 }
41712
41713-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
41714+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
41715 {
41716 .ident = "Samsung Series 5 550 - Touchpad",
41717 .matches = {
41718diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41719index 6b22938..bc9700e 100644
41720--- a/drivers/platform/x86/msi-laptop.c
41721+++ b/drivers/platform/x86/msi-laptop.c
41722@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41723
41724 if (!quirks->ec_read_only) {
41725 /* allow userland write sysfs file */
41726- dev_attr_bluetooth.store = store_bluetooth;
41727- dev_attr_wlan.store = store_wlan;
41728- dev_attr_threeg.store = store_threeg;
41729- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41730- dev_attr_wlan.attr.mode |= S_IWUSR;
41731- dev_attr_threeg.attr.mode |= S_IWUSR;
41732+ pax_open_kernel();
41733+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41734+ *(void **)&dev_attr_wlan.store = store_wlan;
41735+ *(void **)&dev_attr_threeg.store = store_threeg;
41736+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41737+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41738+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41739+ pax_close_kernel();
41740 }
41741
41742 /* disable hardware control by fn key */
41743diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41744index 2ac045f..39c443d 100644
41745--- a/drivers/platform/x86/sony-laptop.c
41746+++ b/drivers/platform/x86/sony-laptop.c
41747@@ -2483,7 +2483,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
41748 }
41749
41750 /* High speed charging function */
41751-static struct device_attribute *hsc_handle;
41752+static device_attribute_no_const *hsc_handle;
41753
41754 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41755 struct device_attribute *attr,
41756diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41757index 54d31c0..3f896d3 100644
41758--- a/drivers/platform/x86/thinkpad_acpi.c
41759+++ b/drivers/platform/x86/thinkpad_acpi.c
41760@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
41761 return 0;
41762 }
41763
41764-void static hotkey_mask_warn_incomplete_mask(void)
41765+static void hotkey_mask_warn_incomplete_mask(void)
41766 {
41767 /* log only what the user can fix... */
41768 const u32 wantedmask = hotkey_driver_mask &
41769@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41770 }
41771 }
41772
41773-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41774- struct tp_nvram_state *newn,
41775- const u32 event_mask)
41776-{
41777-
41778 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41779 do { \
41780 if ((event_mask & (1 << __scancode)) && \
41781@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41782 tpacpi_hotkey_send_key(__scancode); \
41783 } while (0)
41784
41785- void issue_volchange(const unsigned int oldvol,
41786- const unsigned int newvol)
41787- {
41788- unsigned int i = oldvol;
41789+static void issue_volchange(const unsigned int oldvol,
41790+ const unsigned int newvol,
41791+ const u32 event_mask)
41792+{
41793+ unsigned int i = oldvol;
41794
41795- while (i > newvol) {
41796- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41797- i--;
41798- }
41799- while (i < newvol) {
41800- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41801- i++;
41802- }
41803+ while (i > newvol) {
41804+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41805+ i--;
41806 }
41807+ while (i < newvol) {
41808+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41809+ i++;
41810+ }
41811+}
41812
41813- void issue_brightnesschange(const unsigned int oldbrt,
41814- const unsigned int newbrt)
41815- {
41816- unsigned int i = oldbrt;
41817+static void issue_brightnesschange(const unsigned int oldbrt,
41818+ const unsigned int newbrt,
41819+ const u32 event_mask)
41820+{
41821+ unsigned int i = oldbrt;
41822
41823- while (i > newbrt) {
41824- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41825- i--;
41826- }
41827- while (i < newbrt) {
41828- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41829- i++;
41830- }
41831+ while (i > newbrt) {
41832+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41833+ i--;
41834+ }
41835+ while (i < newbrt) {
41836+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41837+ i++;
41838 }
41839+}
41840
41841+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41842+ struct tp_nvram_state *newn,
41843+ const u32 event_mask)
41844+{
41845 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41846 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41847 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41848@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41849 oldn->volume_level != newn->volume_level) {
41850 /* recently muted, or repeated mute keypress, or
41851 * multiple presses ending in mute */
41852- issue_volchange(oldn->volume_level, newn->volume_level);
41853+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41854 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41855 }
41856 } else {
41857@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41858 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41859 }
41860 if (oldn->volume_level != newn->volume_level) {
41861- issue_volchange(oldn->volume_level, newn->volume_level);
41862+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41863 } else if (oldn->volume_toggle != newn->volume_toggle) {
41864 /* repeated vol up/down keypress at end of scale ? */
41865 if (newn->volume_level == 0)
41866@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41867 /* handle brightness */
41868 if (oldn->brightness_level != newn->brightness_level) {
41869 issue_brightnesschange(oldn->brightness_level,
41870- newn->brightness_level);
41871+ newn->brightness_level,
41872+ event_mask);
41873 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41874 /* repeated key presses that didn't change state */
41875 if (newn->brightness_level == 0)
41876@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41877 && !tp_features.bright_unkfw)
41878 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41879 }
41880+}
41881
41882 #undef TPACPI_COMPARE_KEY
41883 #undef TPACPI_MAY_SEND_KEY
41884-}
41885
41886 /*
41887 * Polling driver
41888diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41889index 769d265..a3a05ca 100644
41890--- a/drivers/pnp/pnpbios/bioscalls.c
41891+++ b/drivers/pnp/pnpbios/bioscalls.c
41892@@ -58,7 +58,7 @@ do { \
41893 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41894 } while(0)
41895
41896-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41897+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41898 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41899
41900 /*
41901@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41902
41903 cpu = get_cpu();
41904 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41905+
41906+ pax_open_kernel();
41907 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41908+ pax_close_kernel();
41909
41910 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41911 spin_lock_irqsave(&pnp_bios_lock, flags);
41912@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41913 :"memory");
41914 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41915
41916+ pax_open_kernel();
41917 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41918+ pax_close_kernel();
41919+
41920 put_cpu();
41921
41922 /* If we get here and this is set then the PnP BIOS faulted on us. */
41923@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41924 return status;
41925 }
41926
41927-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41928+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41929 {
41930 int i;
41931
41932@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41933 pnp_bios_callpoint.offset = header->fields.pm16offset;
41934 pnp_bios_callpoint.segment = PNP_CS16;
41935
41936+ pax_open_kernel();
41937+
41938 for_each_possible_cpu(i) {
41939 struct desc_struct *gdt = get_cpu_gdt_table(i);
41940 if (!gdt)
41941@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41942 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41943 (unsigned long)__va(header->fields.pm16dseg));
41944 }
41945+
41946+ pax_close_kernel();
41947 }
41948diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41949index 3e6db1c..1fbbdae 100644
41950--- a/drivers/pnp/resource.c
41951+++ b/drivers/pnp/resource.c
41952@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41953 return 1;
41954
41955 /* check if the resource is valid */
41956- if (*irq < 0 || *irq > 15)
41957+ if (*irq > 15)
41958 return 0;
41959
41960 /* check if the resource is reserved */
41961@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41962 return 1;
41963
41964 /* check if the resource is valid */
41965- if (*dma < 0 || *dma == 4 || *dma > 7)
41966+ if (*dma == 4 || *dma > 7)
41967 return 0;
41968
41969 /* check if the resource is reserved */
41970diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41971index 0c52e2a..3421ab7 100644
41972--- a/drivers/power/pda_power.c
41973+++ b/drivers/power/pda_power.c
41974@@ -37,7 +37,11 @@ static int polling;
41975
41976 #if IS_ENABLED(CONFIG_USB_PHY)
41977 static struct usb_phy *transceiver;
41978-static struct notifier_block otg_nb;
41979+static int otg_handle_notification(struct notifier_block *nb,
41980+ unsigned long event, void *unused);
41981+static struct notifier_block otg_nb = {
41982+ .notifier_call = otg_handle_notification
41983+};
41984 #endif
41985
41986 static struct regulator *ac_draw;
41987@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41988
41989 #if IS_ENABLED(CONFIG_USB_PHY)
41990 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41991- otg_nb.notifier_call = otg_handle_notification;
41992 ret = usb_register_notifier(transceiver, &otg_nb);
41993 if (ret) {
41994 dev_err(dev, "failure to register otg notifier\n");
41995diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41996index cc439fd..8fa30df 100644
41997--- a/drivers/power/power_supply.h
41998+++ b/drivers/power/power_supply.h
41999@@ -16,12 +16,12 @@ struct power_supply;
42000
42001 #ifdef CONFIG_SYSFS
42002
42003-extern void power_supply_init_attrs(struct device_type *dev_type);
42004+extern void power_supply_init_attrs(void);
42005 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
42006
42007 #else
42008
42009-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
42010+static inline void power_supply_init_attrs(void) {}
42011 #define power_supply_uevent NULL
42012
42013 #endif /* CONFIG_SYSFS */
42014diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
42015index 1c517c3..ffa2f17 100644
42016--- a/drivers/power/power_supply_core.c
42017+++ b/drivers/power/power_supply_core.c
42018@@ -24,7 +24,10 @@
42019 struct class *power_supply_class;
42020 EXPORT_SYMBOL_GPL(power_supply_class);
42021
42022-static struct device_type power_supply_dev_type;
42023+extern const struct attribute_group *power_supply_attr_groups[];
42024+static struct device_type power_supply_dev_type = {
42025+ .groups = power_supply_attr_groups,
42026+};
42027
42028 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
42029 struct power_supply *supply)
42030@@ -554,7 +557,7 @@ static int __init power_supply_class_init(void)
42031 return PTR_ERR(power_supply_class);
42032
42033 power_supply_class->dev_uevent = power_supply_uevent;
42034- power_supply_init_attrs(&power_supply_dev_type);
42035+ power_supply_init_attrs();
42036
42037 return 0;
42038 }
42039diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
42040index 29178f7..c65f324 100644
42041--- a/drivers/power/power_supply_sysfs.c
42042+++ b/drivers/power/power_supply_sysfs.c
42043@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
42044 .is_visible = power_supply_attr_is_visible,
42045 };
42046
42047-static const struct attribute_group *power_supply_attr_groups[] = {
42048+const struct attribute_group *power_supply_attr_groups[] = {
42049 &power_supply_attr_group,
42050 NULL,
42051 };
42052
42053-void power_supply_init_attrs(struct device_type *dev_type)
42054+void power_supply_init_attrs(void)
42055 {
42056 int i;
42057
42058- dev_type->groups = power_supply_attr_groups;
42059-
42060 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
42061 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
42062 }
42063diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
42064index d428ef9..fdc0357 100644
42065--- a/drivers/regulator/max8660.c
42066+++ b/drivers/regulator/max8660.c
42067@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
42068 max8660->shadow_regs[MAX8660_OVER1] = 5;
42069 } else {
42070 /* Otherwise devices can be toggled via software */
42071- max8660_dcdc_ops.enable = max8660_dcdc_enable;
42072- max8660_dcdc_ops.disable = max8660_dcdc_disable;
42073+ pax_open_kernel();
42074+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
42075+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
42076+ pax_close_kernel();
42077 }
42078
42079 /*
42080diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
42081index adb1414..c13e0ce 100644
42082--- a/drivers/regulator/max8973-regulator.c
42083+++ b/drivers/regulator/max8973-regulator.c
42084@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
42085 if (!pdata->enable_ext_control) {
42086 max->desc.enable_reg = MAX8973_VOUT;
42087 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
42088- max8973_dcdc_ops.enable = regulator_enable_regmap;
42089- max8973_dcdc_ops.disable = regulator_disable_regmap;
42090- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
42091+ pax_open_kernel();
42092+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
42093+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
42094+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
42095+ pax_close_kernel();
42096 }
42097
42098 max->enable_external_control = pdata->enable_ext_control;
42099diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
42100index b716283..3cc4349 100644
42101--- a/drivers/regulator/mc13892-regulator.c
42102+++ b/drivers/regulator/mc13892-regulator.c
42103@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
42104 }
42105 mc13xxx_unlock(mc13892);
42106
42107- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
42108+ pax_open_kernel();
42109+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
42110 = mc13892_vcam_set_mode;
42111- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
42112+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
42113 = mc13892_vcam_get_mode;
42114+ pax_close_kernel();
42115
42116 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
42117 ARRAY_SIZE(mc13892_regulators));
42118diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
42119index f1cb706..4c7832a 100644
42120--- a/drivers/rtc/rtc-cmos.c
42121+++ b/drivers/rtc/rtc-cmos.c
42122@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
42123 hpet_rtc_timer_init();
42124
42125 /* export at least the first block of NVRAM */
42126- nvram.size = address_space - NVRAM_OFFSET;
42127+ pax_open_kernel();
42128+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
42129+ pax_close_kernel();
42130 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
42131 if (retval < 0) {
42132 dev_dbg(dev, "can't create nvram file? %d\n", retval);
42133diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
42134index d049393..bb20be0 100644
42135--- a/drivers/rtc/rtc-dev.c
42136+++ b/drivers/rtc/rtc-dev.c
42137@@ -16,6 +16,7 @@
42138 #include <linux/module.h>
42139 #include <linux/rtc.h>
42140 #include <linux/sched.h>
42141+#include <linux/grsecurity.h>
42142 #include "rtc-core.h"
42143
42144 static dev_t rtc_devt;
42145@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
42146 if (copy_from_user(&tm, uarg, sizeof(tm)))
42147 return -EFAULT;
42148
42149+ gr_log_timechange();
42150+
42151 return rtc_set_time(rtc, &tm);
42152
42153 case RTC_PIE_ON:
42154diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
42155index b53992a..776df84 100644
42156--- a/drivers/rtc/rtc-ds1307.c
42157+++ b/drivers/rtc/rtc-ds1307.c
42158@@ -107,7 +107,7 @@ struct ds1307 {
42159 u8 offset; /* register's offset */
42160 u8 regs[11];
42161 u16 nvram_offset;
42162- struct bin_attribute *nvram;
42163+ bin_attribute_no_const *nvram;
42164 enum ds_type type;
42165 unsigned long flags;
42166 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
42167diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
42168index 130f29a..6179d03 100644
42169--- a/drivers/rtc/rtc-m48t59.c
42170+++ b/drivers/rtc/rtc-m48t59.c
42171@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
42172 goto out;
42173 }
42174
42175- m48t59_nvram_attr.size = pdata->offset;
42176+ pax_open_kernel();
42177+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
42178+ pax_close_kernel();
42179
42180 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
42181 if (ret) {
42182diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
42183index e693af6..2e525b6 100644
42184--- a/drivers/scsi/bfa/bfa_fcpim.h
42185+++ b/drivers/scsi/bfa/bfa_fcpim.h
42186@@ -36,7 +36,7 @@ struct bfa_iotag_s {
42187
42188 struct bfa_itn_s {
42189 bfa_isr_func_t isr;
42190-};
42191+} __no_const;
42192
42193 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
42194 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
42195diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
42196index 23a90e7..9cf04ee 100644
42197--- a/drivers/scsi/bfa/bfa_ioc.h
42198+++ b/drivers/scsi/bfa/bfa_ioc.h
42199@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
42200 bfa_ioc_disable_cbfn_t disable_cbfn;
42201 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
42202 bfa_ioc_reset_cbfn_t reset_cbfn;
42203-};
42204+} __no_const;
42205
42206 /*
42207 * IOC event notification mechanism.
42208@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
42209 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
42210 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
42211 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
42212-};
42213+} __no_const;
42214
42215 /*
42216 * Queue element to wait for room in request queue. FIFO order is
42217diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
42218index df0c3c7..b00e1d0 100644
42219--- a/drivers/scsi/hosts.c
42220+++ b/drivers/scsi/hosts.c
42221@@ -42,7 +42,7 @@
42222 #include "scsi_logging.h"
42223
42224
42225-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42226+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42227
42228
42229 static void scsi_host_cls_release(struct device *dev)
42230@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
42231 * subtract one because we increment first then return, but we need to
42232 * know what the next host number was before increment
42233 */
42234- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
42235+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
42236 shost->dma_channel = 0xff;
42237
42238 /* These three are default values which can be overridden */
42239diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
42240index 7f4f790..b75b92a 100644
42241--- a/drivers/scsi/hpsa.c
42242+++ b/drivers/scsi/hpsa.c
42243@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
42244 unsigned long flags;
42245
42246 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42247- return h->access.command_completed(h, q);
42248+ return h->access->command_completed(h, q);
42249
42250 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42251 a = rq->head[rq->current_entry];
42252@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
42253 while (!list_empty(&h->reqQ)) {
42254 c = list_entry(h->reqQ.next, struct CommandList, list);
42255 /* can't do anything if fifo is full */
42256- if ((h->access.fifo_full(h))) {
42257+ if ((h->access->fifo_full(h))) {
42258 dev_warn(&h->pdev->dev, "fifo full\n");
42259 break;
42260 }
42261@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
42262
42263 /* Tell the controller execute command */
42264 spin_unlock_irqrestore(&h->lock, flags);
42265- h->access.submit_command(h, c);
42266+ h->access->submit_command(h, c);
42267 spin_lock_irqsave(&h->lock, flags);
42268 }
42269 spin_unlock_irqrestore(&h->lock, flags);
42270@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
42271
42272 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42273 {
42274- return h->access.command_completed(h, q);
42275+ return h->access->command_completed(h, q);
42276 }
42277
42278 static inline bool interrupt_pending(struct ctlr_info *h)
42279 {
42280- return h->access.intr_pending(h);
42281+ return h->access->intr_pending(h);
42282 }
42283
42284 static inline long interrupt_not_for_us(struct ctlr_info *h)
42285 {
42286- return (h->access.intr_pending(h) == 0) ||
42287+ return (h->access->intr_pending(h) == 0) ||
42288 (h->interrupts_enabled == 0);
42289 }
42290
42291@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42292 if (prod_index < 0)
42293 return -ENODEV;
42294 h->product_name = products[prod_index].product_name;
42295- h->access = *(products[prod_index].access);
42296+ h->access = products[prod_index].access;
42297
42298 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42299 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42300@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42301
42302 assert_spin_locked(&lockup_detector_lock);
42303 remove_ctlr_from_lockup_detector_list(h);
42304- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42305+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42306 spin_lock_irqsave(&h->lock, flags);
42307 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42308 spin_unlock_irqrestore(&h->lock, flags);
42309@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
42310 }
42311
42312 /* make sure the board interrupts are off */
42313- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42314+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42315
42316 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42317 goto clean2;
42318@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
42319 * fake ones to scoop up any residual completions.
42320 */
42321 spin_lock_irqsave(&h->lock, flags);
42322- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42323+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42324 spin_unlock_irqrestore(&h->lock, flags);
42325 free_irqs(h);
42326 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42327@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
42328 dev_info(&h->pdev->dev, "Board READY.\n");
42329 dev_info(&h->pdev->dev,
42330 "Waiting for stale completions to drain.\n");
42331- h->access.set_intr_mask(h, HPSA_INTR_ON);
42332+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42333 msleep(10000);
42334- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42335+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42336
42337 rc = controller_reset_failed(h->cfgtable);
42338 if (rc)
42339@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
42340 }
42341
42342 /* Turn the interrupts on so we can service requests */
42343- h->access.set_intr_mask(h, HPSA_INTR_ON);
42344+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42345
42346 hpsa_hba_inquiry(h);
42347 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42348@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42349 * To write all data in the battery backed cache to disks
42350 */
42351 hpsa_flush_cache(h);
42352- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42353+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42354 hpsa_free_irqs_and_disable_msix(h);
42355 }
42356
42357@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42358 return;
42359 }
42360 /* Change the access methods to the performant access methods */
42361- h->access = SA5_performant_access;
42362+ h->access = &SA5_performant_access;
42363 h->transMethod = CFGTBL_Trans_Performant;
42364 }
42365
42366diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42367index 9816479..c5d4e97 100644
42368--- a/drivers/scsi/hpsa.h
42369+++ b/drivers/scsi/hpsa.h
42370@@ -79,7 +79,7 @@ struct ctlr_info {
42371 unsigned int msix_vector;
42372 unsigned int msi_vector;
42373 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42374- struct access_method access;
42375+ struct access_method *access;
42376
42377 /* queue and queue Info */
42378 struct list_head reqQ;
42379diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42380index 8b928c6..9c76300 100644
42381--- a/drivers/scsi/libfc/fc_exch.c
42382+++ b/drivers/scsi/libfc/fc_exch.c
42383@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42384 u16 pool_max_index;
42385
42386 struct {
42387- atomic_t no_free_exch;
42388- atomic_t no_free_exch_xid;
42389- atomic_t xid_not_found;
42390- atomic_t xid_busy;
42391- atomic_t seq_not_found;
42392- atomic_t non_bls_resp;
42393+ atomic_unchecked_t no_free_exch;
42394+ atomic_unchecked_t no_free_exch_xid;
42395+ atomic_unchecked_t xid_not_found;
42396+ atomic_unchecked_t xid_busy;
42397+ atomic_unchecked_t seq_not_found;
42398+ atomic_unchecked_t non_bls_resp;
42399 } stats;
42400 };
42401
42402@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42403 /* allocate memory for exchange */
42404 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42405 if (!ep) {
42406- atomic_inc(&mp->stats.no_free_exch);
42407+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42408 goto out;
42409 }
42410 memset(ep, 0, sizeof(*ep));
42411@@ -797,7 +797,7 @@ out:
42412 return ep;
42413 err:
42414 spin_unlock_bh(&pool->lock);
42415- atomic_inc(&mp->stats.no_free_exch_xid);
42416+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42417 mempool_free(ep, mp->ep_pool);
42418 return NULL;
42419 }
42420@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42421 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42422 ep = fc_exch_find(mp, xid);
42423 if (!ep) {
42424- atomic_inc(&mp->stats.xid_not_found);
42425+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42426 reject = FC_RJT_OX_ID;
42427 goto out;
42428 }
42429@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42430 ep = fc_exch_find(mp, xid);
42431 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42432 if (ep) {
42433- atomic_inc(&mp->stats.xid_busy);
42434+ atomic_inc_unchecked(&mp->stats.xid_busy);
42435 reject = FC_RJT_RX_ID;
42436 goto rel;
42437 }
42438@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42439 }
42440 xid = ep->xid; /* get our XID */
42441 } else if (!ep) {
42442- atomic_inc(&mp->stats.xid_not_found);
42443+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42444 reject = FC_RJT_RX_ID; /* XID not found */
42445 goto out;
42446 }
42447@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42448 } else {
42449 sp = &ep->seq;
42450 if (sp->id != fh->fh_seq_id) {
42451- atomic_inc(&mp->stats.seq_not_found);
42452+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42453 if (f_ctl & FC_FC_END_SEQ) {
42454 /*
42455 * Update sequence_id based on incoming last
42456@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42457
42458 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42459 if (!ep) {
42460- atomic_inc(&mp->stats.xid_not_found);
42461+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42462 goto out;
42463 }
42464 if (ep->esb_stat & ESB_ST_COMPLETE) {
42465- atomic_inc(&mp->stats.xid_not_found);
42466+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42467 goto rel;
42468 }
42469 if (ep->rxid == FC_XID_UNKNOWN)
42470 ep->rxid = ntohs(fh->fh_rx_id);
42471 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42472- atomic_inc(&mp->stats.xid_not_found);
42473+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42474 goto rel;
42475 }
42476 if (ep->did != ntoh24(fh->fh_s_id) &&
42477 ep->did != FC_FID_FLOGI) {
42478- atomic_inc(&mp->stats.xid_not_found);
42479+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42480 goto rel;
42481 }
42482 sof = fr_sof(fp);
42483@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42484 sp->ssb_stat |= SSB_ST_RESP;
42485 sp->id = fh->fh_seq_id;
42486 } else if (sp->id != fh->fh_seq_id) {
42487- atomic_inc(&mp->stats.seq_not_found);
42488+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42489 goto rel;
42490 }
42491
42492@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42493 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42494
42495 if (!sp)
42496- atomic_inc(&mp->stats.xid_not_found);
42497+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42498 else
42499- atomic_inc(&mp->stats.non_bls_resp);
42500+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42501
42502 fc_frame_free(fp);
42503 }
42504@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42505
42506 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42507 mp = ema->mp;
42508- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42509+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42510 st->fc_no_free_exch_xid +=
42511- atomic_read(&mp->stats.no_free_exch_xid);
42512- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42513- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42514- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42515- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42516+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42517+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42518+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42519+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42520+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42521 }
42522 }
42523 EXPORT_SYMBOL(fc_exch_update_stats);
42524diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42525index 161c98e..6d563b3 100644
42526--- a/drivers/scsi/libsas/sas_ata.c
42527+++ b/drivers/scsi/libsas/sas_ata.c
42528@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42529 .postreset = ata_std_postreset,
42530 .error_handler = ata_std_error_handler,
42531 .post_internal_cmd = sas_ata_post_internal,
42532- .qc_defer = ata_std_qc_defer,
42533+ .qc_defer = ata_std_qc_defer,
42534 .qc_prep = ata_noop_qc_prep,
42535 .qc_issue = sas_ata_qc_issue,
42536 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42537diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42538index bcc56ca..6f4174a 100644
42539--- a/drivers/scsi/lpfc/lpfc.h
42540+++ b/drivers/scsi/lpfc/lpfc.h
42541@@ -431,7 +431,7 @@ struct lpfc_vport {
42542 struct dentry *debug_nodelist;
42543 struct dentry *vport_debugfs_root;
42544 struct lpfc_debugfs_trc *disc_trc;
42545- atomic_t disc_trc_cnt;
42546+ atomic_unchecked_t disc_trc_cnt;
42547 #endif
42548 uint8_t stat_data_enabled;
42549 uint8_t stat_data_blocked;
42550@@ -865,8 +865,8 @@ struct lpfc_hba {
42551 struct timer_list fabric_block_timer;
42552 unsigned long bit_flags;
42553 #define FABRIC_COMANDS_BLOCKED 0
42554- atomic_t num_rsrc_err;
42555- atomic_t num_cmd_success;
42556+ atomic_unchecked_t num_rsrc_err;
42557+ atomic_unchecked_t num_cmd_success;
42558 unsigned long last_rsrc_error_time;
42559 unsigned long last_ramp_down_time;
42560 unsigned long last_ramp_up_time;
42561@@ -902,7 +902,7 @@ struct lpfc_hba {
42562
42563 struct dentry *debug_slow_ring_trc;
42564 struct lpfc_debugfs_trc *slow_ring_trc;
42565- atomic_t slow_ring_trc_cnt;
42566+ atomic_unchecked_t slow_ring_trc_cnt;
42567 /* iDiag debugfs sub-directory */
42568 struct dentry *idiag_root;
42569 struct dentry *idiag_pci_cfg;
42570diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42571index f525ecb..32549a4 100644
42572--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42573+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42574@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42575
42576 #include <linux/debugfs.h>
42577
42578-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42579+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42580 static unsigned long lpfc_debugfs_start_time = 0L;
42581
42582 /* iDiag */
42583@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42584 lpfc_debugfs_enable = 0;
42585
42586 len = 0;
42587- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42588+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42589 (lpfc_debugfs_max_disc_trc - 1);
42590 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42591 dtp = vport->disc_trc + i;
42592@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42593 lpfc_debugfs_enable = 0;
42594
42595 len = 0;
42596- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42597+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42598 (lpfc_debugfs_max_slow_ring_trc - 1);
42599 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42600 dtp = phba->slow_ring_trc + i;
42601@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42602 !vport || !vport->disc_trc)
42603 return;
42604
42605- index = atomic_inc_return(&vport->disc_trc_cnt) &
42606+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42607 (lpfc_debugfs_max_disc_trc - 1);
42608 dtp = vport->disc_trc + index;
42609 dtp->fmt = fmt;
42610 dtp->data1 = data1;
42611 dtp->data2 = data2;
42612 dtp->data3 = data3;
42613- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42614+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42615 dtp->jif = jiffies;
42616 #endif
42617 return;
42618@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42619 !phba || !phba->slow_ring_trc)
42620 return;
42621
42622- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42623+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42624 (lpfc_debugfs_max_slow_ring_trc - 1);
42625 dtp = phba->slow_ring_trc + index;
42626 dtp->fmt = fmt;
42627 dtp->data1 = data1;
42628 dtp->data2 = data2;
42629 dtp->data3 = data3;
42630- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42631+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42632 dtp->jif = jiffies;
42633 #endif
42634 return;
42635@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42636 "slow_ring buffer\n");
42637 goto debug_failed;
42638 }
42639- atomic_set(&phba->slow_ring_trc_cnt, 0);
42640+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42641 memset(phba->slow_ring_trc, 0,
42642 (sizeof(struct lpfc_debugfs_trc) *
42643 lpfc_debugfs_max_slow_ring_trc));
42644@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42645 "buffer\n");
42646 goto debug_failed;
42647 }
42648- atomic_set(&vport->disc_trc_cnt, 0);
42649+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42650
42651 snprintf(name, sizeof(name), "discovery_trace");
42652 vport->debug_disc_trc =
42653diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42654index cb465b2..2e7b25f 100644
42655--- a/drivers/scsi/lpfc/lpfc_init.c
42656+++ b/drivers/scsi/lpfc/lpfc_init.c
42657@@ -10950,8 +10950,10 @@ lpfc_init(void)
42658 "misc_register returned with status %d", error);
42659
42660 if (lpfc_enable_npiv) {
42661- lpfc_transport_functions.vport_create = lpfc_vport_create;
42662- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42663+ pax_open_kernel();
42664+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42665+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42666+ pax_close_kernel();
42667 }
42668 lpfc_transport_template =
42669 fc_attach_transport(&lpfc_transport_functions);
42670diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42671index 8523b278e..ce1d812 100644
42672--- a/drivers/scsi/lpfc/lpfc_scsi.c
42673+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42674@@ -331,7 +331,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42675 uint32_t evt_posted;
42676
42677 spin_lock_irqsave(&phba->hbalock, flags);
42678- atomic_inc(&phba->num_rsrc_err);
42679+ atomic_inc_unchecked(&phba->num_rsrc_err);
42680 phba->last_rsrc_error_time = jiffies;
42681
42682 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42683@@ -372,7 +372,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42684 unsigned long flags;
42685 struct lpfc_hba *phba = vport->phba;
42686 uint32_t evt_posted;
42687- atomic_inc(&phba->num_cmd_success);
42688+ atomic_inc_unchecked(&phba->num_cmd_success);
42689
42690 if (vport->cfg_lun_queue_depth <= queue_depth)
42691 return;
42692@@ -416,8 +416,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42693 unsigned long num_rsrc_err, num_cmd_success;
42694 int i;
42695
42696- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42697- num_cmd_success = atomic_read(&phba->num_cmd_success);
42698+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42699+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42700
42701 /*
42702 * The error and success command counters are global per
42703@@ -445,8 +445,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42704 }
42705 }
42706 lpfc_destroy_vport_work_array(phba, vports);
42707- atomic_set(&phba->num_rsrc_err, 0);
42708- atomic_set(&phba->num_cmd_success, 0);
42709+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42710+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42711 }
42712
42713 /**
42714@@ -480,8 +480,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42715 }
42716 }
42717 lpfc_destroy_vport_work_array(phba, vports);
42718- atomic_set(&phba->num_rsrc_err, 0);
42719- atomic_set(&phba->num_cmd_success, 0);
42720+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42721+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42722 }
42723
42724 /**
42725diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42726index 8e1b737..50ff510 100644
42727--- a/drivers/scsi/pmcraid.c
42728+++ b/drivers/scsi/pmcraid.c
42729@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42730 res->scsi_dev = scsi_dev;
42731 scsi_dev->hostdata = res;
42732 res->change_detected = 0;
42733- atomic_set(&res->read_failures, 0);
42734- atomic_set(&res->write_failures, 0);
42735+ atomic_set_unchecked(&res->read_failures, 0);
42736+ atomic_set_unchecked(&res->write_failures, 0);
42737 rc = 0;
42738 }
42739 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42740@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42741
42742 /* If this was a SCSI read/write command keep count of errors */
42743 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42744- atomic_inc(&res->read_failures);
42745+ atomic_inc_unchecked(&res->read_failures);
42746 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42747- atomic_inc(&res->write_failures);
42748+ atomic_inc_unchecked(&res->write_failures);
42749
42750 if (!RES_IS_GSCSI(res->cfg_entry) &&
42751 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42752@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42753 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42754 * hrrq_id assigned here in queuecommand
42755 */
42756- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42757+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42758 pinstance->num_hrrq;
42759 cmd->cmd_done = pmcraid_io_done;
42760
42761@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
42762 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42763 * hrrq_id assigned here in queuecommand
42764 */
42765- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42766+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42767 pinstance->num_hrrq;
42768
42769 if (request_size) {
42770@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42771
42772 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42773 /* add resources only after host is added into system */
42774- if (!atomic_read(&pinstance->expose_resources))
42775+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42776 return;
42777
42778 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42779@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42780 init_waitqueue_head(&pinstance->reset_wait_q);
42781
42782 atomic_set(&pinstance->outstanding_cmds, 0);
42783- atomic_set(&pinstance->last_message_id, 0);
42784- atomic_set(&pinstance->expose_resources, 0);
42785+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42786+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42787
42788 INIT_LIST_HEAD(&pinstance->free_res_q);
42789 INIT_LIST_HEAD(&pinstance->used_res_q);
42790@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42791 /* Schedule worker thread to handle CCN and take care of adding and
42792 * removing devices to OS
42793 */
42794- atomic_set(&pinstance->expose_resources, 1);
42795+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42796 schedule_work(&pinstance->worker_q);
42797 return rc;
42798
42799diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42800index e1d150f..6c6df44 100644
42801--- a/drivers/scsi/pmcraid.h
42802+++ b/drivers/scsi/pmcraid.h
42803@@ -748,7 +748,7 @@ struct pmcraid_instance {
42804 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42805
42806 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42807- atomic_t last_message_id;
42808+ atomic_unchecked_t last_message_id;
42809
42810 /* configuration table */
42811 struct pmcraid_config_table *cfg_table;
42812@@ -777,7 +777,7 @@ struct pmcraid_instance {
42813 atomic_t outstanding_cmds;
42814
42815 /* should add/delete resources to mid-layer now ?*/
42816- atomic_t expose_resources;
42817+ atomic_unchecked_t expose_resources;
42818
42819
42820
42821@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42822 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42823 };
42824 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42825- atomic_t read_failures; /* count of failed READ commands */
42826- atomic_t write_failures; /* count of failed WRITE commands */
42827+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42828+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42829
42830 /* To indicate add/delete/modify during CCN */
42831 u8 change_detected;
42832diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42833index bf60c63..74d4dce 100644
42834--- a/drivers/scsi/qla2xxx/qla_attr.c
42835+++ b/drivers/scsi/qla2xxx/qla_attr.c
42836@@ -2001,7 +2001,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42837 return 0;
42838 }
42839
42840-struct fc_function_template qla2xxx_transport_functions = {
42841+fc_function_template_no_const qla2xxx_transport_functions = {
42842
42843 .show_host_node_name = 1,
42844 .show_host_port_name = 1,
42845@@ -2048,7 +2048,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42846 .bsg_timeout = qla24xx_bsg_timeout,
42847 };
42848
42849-struct fc_function_template qla2xxx_transport_vport_functions = {
42850+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42851
42852 .show_host_node_name = 1,
42853 .show_host_port_name = 1,
42854diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42855index 026bfde..90c4018 100644
42856--- a/drivers/scsi/qla2xxx/qla_gbl.h
42857+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42858@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42859 struct device_attribute;
42860 extern struct device_attribute *qla2x00_host_attrs[];
42861 struct fc_function_template;
42862-extern struct fc_function_template qla2xxx_transport_functions;
42863-extern struct fc_function_template qla2xxx_transport_vport_functions;
42864+extern fc_function_template_no_const qla2xxx_transport_functions;
42865+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42866 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42867 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42868 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42869diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42870index ad72c1d..afc9a98 100644
42871--- a/drivers/scsi/qla2xxx/qla_os.c
42872+++ b/drivers/scsi/qla2xxx/qla_os.c
42873@@ -1571,8 +1571,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42874 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42875 /* Ok, a 64bit DMA mask is applicable. */
42876 ha->flags.enable_64bit_addressing = 1;
42877- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42878- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42879+ pax_open_kernel();
42880+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42881+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42882+ pax_close_kernel();
42883 return;
42884 }
42885 }
42886diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42887index ddf16a8..80f4dd0 100644
42888--- a/drivers/scsi/qla4xxx/ql4_def.h
42889+++ b/drivers/scsi/qla4xxx/ql4_def.h
42890@@ -291,7 +291,7 @@ struct ddb_entry {
42891 * (4000 only) */
42892 atomic_t relogin_timer; /* Max Time to wait for
42893 * relogin to complete */
42894- atomic_t relogin_retry_count; /* Num of times relogin has been
42895+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42896 * retried */
42897 uint32_t default_time2wait; /* Default Min time between
42898 * relogins (+aens) */
42899diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42900index 4d231c1..2892c37 100644
42901--- a/drivers/scsi/qla4xxx/ql4_os.c
42902+++ b/drivers/scsi/qla4xxx/ql4_os.c
42903@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42904 */
42905 if (!iscsi_is_session_online(cls_sess)) {
42906 /* Reset retry relogin timer */
42907- atomic_inc(&ddb_entry->relogin_retry_count);
42908+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42909 DEBUG2(ql4_printk(KERN_INFO, ha,
42910 "%s: index[%d] relogin timed out-retrying"
42911 " relogin (%d), retry (%d)\n", __func__,
42912 ddb_entry->fw_ddb_index,
42913- atomic_read(&ddb_entry->relogin_retry_count),
42914+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42915 ddb_entry->default_time2wait + 4));
42916 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42917 atomic_set(&ddb_entry->retry_relogin_timer,
42918@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42919
42920 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42921 atomic_set(&ddb_entry->relogin_timer, 0);
42922- atomic_set(&ddb_entry->relogin_retry_count, 0);
42923+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42924 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42925 ddb_entry->default_relogin_timeout =
42926 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42927diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42928index 3b1ea34..1583a72 100644
42929--- a/drivers/scsi/scsi.c
42930+++ b/drivers/scsi/scsi.c
42931@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42932 unsigned long timeout;
42933 int rtn = 0;
42934
42935- atomic_inc(&cmd->device->iorequest_cnt);
42936+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42937
42938 /* check if the device is still usable */
42939 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42940diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42941index 86d5220..f22c51a 100644
42942--- a/drivers/scsi/scsi_lib.c
42943+++ b/drivers/scsi/scsi_lib.c
42944@@ -1458,7 +1458,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42945 shost = sdev->host;
42946 scsi_init_cmd_errh(cmd);
42947 cmd->result = DID_NO_CONNECT << 16;
42948- atomic_inc(&cmd->device->iorequest_cnt);
42949+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42950
42951 /*
42952 * SCSI request completion path will do scsi_device_unbusy(),
42953@@ -1484,9 +1484,9 @@ static void scsi_softirq_done(struct request *rq)
42954
42955 INIT_LIST_HEAD(&cmd->eh_entry);
42956
42957- atomic_inc(&cmd->device->iodone_cnt);
42958+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42959 if (cmd->result)
42960- atomic_inc(&cmd->device->ioerr_cnt);
42961+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42962
42963 disposition = scsi_decide_disposition(cmd);
42964 if (disposition != SUCCESS &&
42965diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42966index 931a7d9..0c2a754 100644
42967--- a/drivers/scsi/scsi_sysfs.c
42968+++ b/drivers/scsi/scsi_sysfs.c
42969@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42970 char *buf) \
42971 { \
42972 struct scsi_device *sdev = to_scsi_device(dev); \
42973- unsigned long long count = atomic_read(&sdev->field); \
42974+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42975 return snprintf(buf, 20, "0x%llx\n", count); \
42976 } \
42977 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42978diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42979index 84a1fdf..693b0d6 100644
42980--- a/drivers/scsi/scsi_tgt_lib.c
42981+++ b/drivers/scsi/scsi_tgt_lib.c
42982@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42983 int err;
42984
42985 dprintk("%lx %u\n", uaddr, len);
42986- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42987+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42988 if (err) {
42989 /*
42990 * TODO: need to fixup sg_tablesize, max_segment_size,
42991diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42992index e106c27..11a380e 100644
42993--- a/drivers/scsi/scsi_transport_fc.c
42994+++ b/drivers/scsi/scsi_transport_fc.c
42995@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42996 * Netlink Infrastructure
42997 */
42998
42999-static atomic_t fc_event_seq;
43000+static atomic_unchecked_t fc_event_seq;
43001
43002 /**
43003 * fc_get_event_number - Obtain the next sequential FC event number
43004@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
43005 u32
43006 fc_get_event_number(void)
43007 {
43008- return atomic_add_return(1, &fc_event_seq);
43009+ return atomic_add_return_unchecked(1, &fc_event_seq);
43010 }
43011 EXPORT_SYMBOL(fc_get_event_number);
43012
43013@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
43014 {
43015 int error;
43016
43017- atomic_set(&fc_event_seq, 0);
43018+ atomic_set_unchecked(&fc_event_seq, 0);
43019
43020 error = transport_class_register(&fc_host_class);
43021 if (error)
43022@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
43023 char *cp;
43024
43025 *val = simple_strtoul(buf, &cp, 0);
43026- if ((*cp && (*cp != '\n')) || (*val < 0))
43027+ if (*cp && (*cp != '\n'))
43028 return -EINVAL;
43029 /*
43030 * Check for overflow; dev_loss_tmo is u32
43031diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
43032index 133926b..903000d 100644
43033--- a/drivers/scsi/scsi_transport_iscsi.c
43034+++ b/drivers/scsi/scsi_transport_iscsi.c
43035@@ -80,7 +80,7 @@ struct iscsi_internal {
43036 struct transport_container session_cont;
43037 };
43038
43039-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
43040+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
43041 static struct workqueue_struct *iscsi_eh_timer_workq;
43042
43043 static DEFINE_IDA(iscsi_sess_ida);
43044@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
43045 int err;
43046
43047 ihost = shost->shost_data;
43048- session->sid = atomic_add_return(1, &iscsi_session_nr);
43049+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
43050
43051 if (target_id == ISCSI_MAX_TARGET) {
43052 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
43053@@ -3944,7 +3944,7 @@ static __init int iscsi_transport_init(void)
43054 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
43055 ISCSI_TRANSPORT_VERSION);
43056
43057- atomic_set(&iscsi_session_nr, 0);
43058+ atomic_set_unchecked(&iscsi_session_nr, 0);
43059
43060 err = class_register(&iscsi_transport_class);
43061 if (err)
43062diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
43063index f379c7f..e8fc69c 100644
43064--- a/drivers/scsi/scsi_transport_srp.c
43065+++ b/drivers/scsi/scsi_transport_srp.c
43066@@ -33,7 +33,7 @@
43067 #include "scsi_transport_srp_internal.h"
43068
43069 struct srp_host_attrs {
43070- atomic_t next_port_id;
43071+ atomic_unchecked_t next_port_id;
43072 };
43073 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
43074
43075@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
43076 struct Scsi_Host *shost = dev_to_shost(dev);
43077 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
43078
43079- atomic_set(&srp_host->next_port_id, 0);
43080+ atomic_set_unchecked(&srp_host->next_port_id, 0);
43081 return 0;
43082 }
43083
43084@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
43085 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
43086 rport->roles = ids->roles;
43087
43088- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
43089+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
43090 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
43091
43092 transport_setup_device(&rport->dev);
43093diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
43094index 610417e..1544fa9 100644
43095--- a/drivers/scsi/sd.c
43096+++ b/drivers/scsi/sd.c
43097@@ -2928,7 +2928,7 @@ static int sd_probe(struct device *dev)
43098 sdkp->disk = gd;
43099 sdkp->index = index;
43100 atomic_set(&sdkp->openers, 0);
43101- atomic_set(&sdkp->device->ioerr_cnt, 0);
43102+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
43103
43104 if (!sdp->request_queue->rq_timeout) {
43105 if (sdp->type != TYPE_MOD)
43106diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
43107index df5e961..df6b97f 100644
43108--- a/drivers/scsi/sg.c
43109+++ b/drivers/scsi/sg.c
43110@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
43111 sdp->disk->disk_name,
43112 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
43113 NULL,
43114- (char *)arg);
43115+ (char __user *)arg);
43116 case BLKTRACESTART:
43117 return blk_trace_startstop(sdp->device->request_queue, 1);
43118 case BLKTRACESTOP:
43119diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
43120index 32b7bb1..2f1c4bd 100644
43121--- a/drivers/spi/spi.c
43122+++ b/drivers/spi/spi.c
43123@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
43124 EXPORT_SYMBOL_GPL(spi_bus_unlock);
43125
43126 /* portable code must never pass more than 32 bytes */
43127-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
43128+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
43129
43130 static u8 *buf;
43131
43132diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
43133index 3675020..e80d92c 100644
43134--- a/drivers/staging/media/solo6x10/solo6x10-core.c
43135+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
43136@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
43137
43138 static int solo_sysfs_init(struct solo_dev *solo_dev)
43139 {
43140- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
43141+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
43142 struct device *dev = &solo_dev->dev;
43143 const char *driver;
43144 int i;
43145diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
43146index 34afc16..ffe44dd 100644
43147--- a/drivers/staging/octeon/ethernet-rx.c
43148+++ b/drivers/staging/octeon/ethernet-rx.c
43149@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43150 /* Increment RX stats for virtual ports */
43151 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
43152 #ifdef CONFIG_64BIT
43153- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
43154- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
43155+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
43156+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
43157 #else
43158- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
43159- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
43160+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
43161+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
43162 #endif
43163 }
43164 netif_receive_skb(skb);
43165@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43166 dev->name);
43167 */
43168 #ifdef CONFIG_64BIT
43169- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
43170+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43171 #else
43172- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
43173+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
43174 #endif
43175 dev_kfree_skb_irq(skb);
43176 }
43177diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
43178index c3a90e7..023619a 100644
43179--- a/drivers/staging/octeon/ethernet.c
43180+++ b/drivers/staging/octeon/ethernet.c
43181@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
43182 * since the RX tasklet also increments it.
43183 */
43184 #ifdef CONFIG_64BIT
43185- atomic64_add(rx_status.dropped_packets,
43186- (atomic64_t *)&priv->stats.rx_dropped);
43187+ atomic64_add_unchecked(rx_status.dropped_packets,
43188+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43189 #else
43190- atomic_add(rx_status.dropped_packets,
43191- (atomic_t *)&priv->stats.rx_dropped);
43192+ atomic_add_unchecked(rx_status.dropped_packets,
43193+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
43194 #endif
43195 }
43196
43197diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43198index dc23395..cf7e9b1 100644
43199--- a/drivers/staging/rtl8712/rtl871x_io.h
43200+++ b/drivers/staging/rtl8712/rtl871x_io.h
43201@@ -108,7 +108,7 @@ struct _io_ops {
43202 u8 *pmem);
43203 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43204 u8 *pmem);
43205-};
43206+} __no_const;
43207
43208 struct io_req {
43209 struct list_head list;
43210diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43211index 1f5088b..0e59820 100644
43212--- a/drivers/staging/sbe-2t3e3/netdev.c
43213+++ b/drivers/staging/sbe-2t3e3/netdev.c
43214@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43215 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43216
43217 if (rlen)
43218- if (copy_to_user(data, &resp, rlen))
43219+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43220 return -EFAULT;
43221
43222 return 0;
43223diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43224index a863a98..d272795 100644
43225--- a/drivers/staging/usbip/vhci.h
43226+++ b/drivers/staging/usbip/vhci.h
43227@@ -83,7 +83,7 @@ struct vhci_hcd {
43228 unsigned resuming:1;
43229 unsigned long re_timeout;
43230
43231- atomic_t seqnum;
43232+ atomic_unchecked_t seqnum;
43233
43234 /*
43235 * NOTE:
43236diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43237index d7974cb..d78076b 100644
43238--- a/drivers/staging/usbip/vhci_hcd.c
43239+++ b/drivers/staging/usbip/vhci_hcd.c
43240@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
43241
43242 spin_lock(&vdev->priv_lock);
43243
43244- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43245+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43246 if (priv->seqnum == 0xffff)
43247 dev_info(&urb->dev->dev, "seqnum max\n");
43248
43249@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43250 return -ENOMEM;
43251 }
43252
43253- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43254+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43255 if (unlink->seqnum == 0xffff)
43256 pr_info("seqnum max\n");
43257
43258@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
43259 vdev->rhport = rhport;
43260 }
43261
43262- atomic_set(&vhci->seqnum, 0);
43263+ atomic_set_unchecked(&vhci->seqnum, 0);
43264 spin_lock_init(&vhci->lock);
43265
43266 hcd->power_budget = 0; /* no limit */
43267diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43268index d07fcb5..358e1e1 100644
43269--- a/drivers/staging/usbip/vhci_rx.c
43270+++ b/drivers/staging/usbip/vhci_rx.c
43271@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43272 if (!urb) {
43273 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43274 pr_info("max seqnum %d\n",
43275- atomic_read(&the_controller->seqnum));
43276+ atomic_read_unchecked(&the_controller->seqnum));
43277 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43278 return;
43279 }
43280diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43281index 8417c2f..ef5ebd6 100644
43282--- a/drivers/staging/vt6655/hostap.c
43283+++ b/drivers/staging/vt6655/hostap.c
43284@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
43285 *
43286 */
43287
43288+static net_device_ops_no_const apdev_netdev_ops;
43289+
43290 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43291 {
43292 PSDevice apdev_priv;
43293 struct net_device *dev = pDevice->dev;
43294 int ret;
43295- const struct net_device_ops apdev_netdev_ops = {
43296- .ndo_start_xmit = pDevice->tx_80211,
43297- };
43298
43299 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43300
43301@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43302 *apdev_priv = *pDevice;
43303 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43304
43305+ /* only half broken now */
43306+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43307 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43308
43309 pDevice->apdev->type = ARPHRD_IEEE80211;
43310diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43311index c699a30..b90a5fd 100644
43312--- a/drivers/staging/vt6656/hostap.c
43313+++ b/drivers/staging/vt6656/hostap.c
43314@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43315 *
43316 */
43317
43318+static net_device_ops_no_const apdev_netdev_ops;
43319+
43320 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43321 {
43322 struct vnt_private *apdev_priv;
43323 struct net_device *dev = pDevice->dev;
43324 int ret;
43325- const struct net_device_ops apdev_netdev_ops = {
43326- .ndo_start_xmit = pDevice->tx_80211,
43327- };
43328
43329 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43330
43331@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43332 *apdev_priv = *pDevice;
43333 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43334
43335+ /* only half broken now */
43336+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43337 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43338
43339 pDevice->apdev->type = ARPHRD_IEEE80211;
43340diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43341index d7e51e4..d07eaab 100644
43342--- a/drivers/staging/zcache/tmem.c
43343+++ b/drivers/staging/zcache/tmem.c
43344@@ -51,7 +51,7 @@
43345 * A tmem host implementation must use this function to register callbacks
43346 * for memory allocation.
43347 */
43348-static struct tmem_hostops tmem_hostops;
43349+static tmem_hostops_no_const tmem_hostops;
43350
43351 static void tmem_objnode_tree_init(void);
43352
43353@@ -65,7 +65,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43354 * A tmem host implementation must use this function to register
43355 * callbacks for a page-accessible memory (PAM) implementation.
43356 */
43357-static struct tmem_pamops tmem_pamops;
43358+static tmem_pamops_no_const tmem_pamops;
43359
43360 void tmem_register_pamops(struct tmem_pamops *m)
43361 {
43362diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43363index d128ce2..a43980c 100644
43364--- a/drivers/staging/zcache/tmem.h
43365+++ b/drivers/staging/zcache/tmem.h
43366@@ -226,6 +226,7 @@ struct tmem_pamops {
43367 int (*replace_in_obj)(void *, struct tmem_obj *);
43368 #endif
43369 };
43370+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43371 extern void tmem_register_pamops(struct tmem_pamops *m);
43372
43373 /* memory allocation methods provided by the host implementation */
43374@@ -235,6 +236,7 @@ struct tmem_hostops {
43375 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43376 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43377 };
43378+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43379 extern void tmem_register_hostops(struct tmem_hostops *m);
43380
43381 /* core tmem accessor functions */
43382diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43383index 4630481..c26782a 100644
43384--- a/drivers/target/target_core_device.c
43385+++ b/drivers/target/target_core_device.c
43386@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43387 spin_lock_init(&dev->se_port_lock);
43388 spin_lock_init(&dev->se_tmr_lock);
43389 spin_lock_init(&dev->qf_cmd_lock);
43390- atomic_set(&dev->dev_ordered_id, 0);
43391+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43392 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43393 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43394 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43395diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43396index 21e3158..43c6004 100644
43397--- a/drivers/target/target_core_transport.c
43398+++ b/drivers/target/target_core_transport.c
43399@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43400 * Used to determine when ORDERED commands should go from
43401 * Dormant to Active status.
43402 */
43403- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43404+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43405 smp_mb__after_atomic_inc();
43406 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43407 cmd->se_ordered_id, cmd->sam_task_attr,
43408diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43409index 33f83fe..d80f8e1 100644
43410--- a/drivers/tty/cyclades.c
43411+++ b/drivers/tty/cyclades.c
43412@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43413 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43414 info->port.count);
43415 #endif
43416- info->port.count++;
43417+ atomic_inc(&info->port.count);
43418 #ifdef CY_DEBUG_COUNT
43419 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43420- current->pid, info->port.count);
43421+ current->pid, atomic_read(&info->port.count));
43422 #endif
43423
43424 /*
43425@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43426 for (j = 0; j < cy_card[i].nports; j++) {
43427 info = &cy_card[i].ports[j];
43428
43429- if (info->port.count) {
43430+ if (atomic_read(&info->port.count)) {
43431 /* XXX is the ldisc num worth this? */
43432 struct tty_struct *tty;
43433 struct tty_ldisc *ld;
43434diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43435index eb255e8..f637a57 100644
43436--- a/drivers/tty/hvc/hvc_console.c
43437+++ b/drivers/tty/hvc/hvc_console.c
43438@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43439
43440 spin_lock_irqsave(&hp->port.lock, flags);
43441 /* Check and then increment for fast path open. */
43442- if (hp->port.count++ > 0) {
43443+ if (atomic_inc_return(&hp->port.count) > 1) {
43444 spin_unlock_irqrestore(&hp->port.lock, flags);
43445 hvc_kick();
43446 return 0;
43447@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43448
43449 spin_lock_irqsave(&hp->port.lock, flags);
43450
43451- if (--hp->port.count == 0) {
43452+ if (atomic_dec_return(&hp->port.count) == 0) {
43453 spin_unlock_irqrestore(&hp->port.lock, flags);
43454 /* We are done with the tty pointer now. */
43455 tty_port_tty_set(&hp->port, NULL);
43456@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43457 */
43458 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43459 } else {
43460- if (hp->port.count < 0)
43461+ if (atomic_read(&hp->port.count) < 0)
43462 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43463- hp->vtermno, hp->port.count);
43464+ hp->vtermno, atomic_read(&hp->port.count));
43465 spin_unlock_irqrestore(&hp->port.lock, flags);
43466 }
43467 }
43468@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43469 * open->hangup case this can be called after the final close so prevent
43470 * that from happening for now.
43471 */
43472- if (hp->port.count <= 0) {
43473+ if (atomic_read(&hp->port.count) <= 0) {
43474 spin_unlock_irqrestore(&hp->port.lock, flags);
43475 return;
43476 }
43477
43478- hp->port.count = 0;
43479+ atomic_set(&hp->port.count, 0);
43480 spin_unlock_irqrestore(&hp->port.lock, flags);
43481 tty_port_tty_set(&hp->port, NULL);
43482
43483@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43484 return -EPIPE;
43485
43486 /* FIXME what's this (unprotected) check for? */
43487- if (hp->port.count <= 0)
43488+ if (atomic_read(&hp->port.count) <= 0)
43489 return -EIO;
43490
43491 spin_lock_irqsave(&hp->lock, flags);
43492diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43493index 81e939e..95ead10 100644
43494--- a/drivers/tty/hvc/hvcs.c
43495+++ b/drivers/tty/hvc/hvcs.c
43496@@ -83,6 +83,7 @@
43497 #include <asm/hvcserver.h>
43498 #include <asm/uaccess.h>
43499 #include <asm/vio.h>
43500+#include <asm/local.h>
43501
43502 /*
43503 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43504@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43505
43506 spin_lock_irqsave(&hvcsd->lock, flags);
43507
43508- if (hvcsd->port.count > 0) {
43509+ if (atomic_read(&hvcsd->port.count) > 0) {
43510 spin_unlock_irqrestore(&hvcsd->lock, flags);
43511 printk(KERN_INFO "HVCS: vterm state unchanged. "
43512 "The hvcs device node is still in use.\n");
43513@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43514 }
43515 }
43516
43517- hvcsd->port.count = 0;
43518+ atomic_set(&hvcsd->port.count, 0);
43519 hvcsd->port.tty = tty;
43520 tty->driver_data = hvcsd;
43521
43522@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43523 unsigned long flags;
43524
43525 spin_lock_irqsave(&hvcsd->lock, flags);
43526- hvcsd->port.count++;
43527+ atomic_inc(&hvcsd->port.count);
43528 hvcsd->todo_mask |= HVCS_SCHED_READ;
43529 spin_unlock_irqrestore(&hvcsd->lock, flags);
43530
43531@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43532 hvcsd = tty->driver_data;
43533
43534 spin_lock_irqsave(&hvcsd->lock, flags);
43535- if (--hvcsd->port.count == 0) {
43536+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43537
43538 vio_disable_interrupts(hvcsd->vdev);
43539
43540@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43541
43542 free_irq(irq, hvcsd);
43543 return;
43544- } else if (hvcsd->port.count < 0) {
43545+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43546 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43547 " is missmanaged.\n",
43548- hvcsd->vdev->unit_address, hvcsd->port.count);
43549+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43550 }
43551
43552 spin_unlock_irqrestore(&hvcsd->lock, flags);
43553@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43554
43555 spin_lock_irqsave(&hvcsd->lock, flags);
43556 /* Preserve this so that we know how many kref refs to put */
43557- temp_open_count = hvcsd->port.count;
43558+ temp_open_count = atomic_read(&hvcsd->port.count);
43559
43560 /*
43561 * Don't kref put inside the spinlock because the destruction
43562@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43563 tty->driver_data = NULL;
43564 hvcsd->port.tty = NULL;
43565
43566- hvcsd->port.count = 0;
43567+ atomic_set(&hvcsd->port.count, 0);
43568
43569 /* This will drop any buffered data on the floor which is OK in a hangup
43570 * scenario. */
43571@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
43572 * the middle of a write operation? This is a crummy place to do this
43573 * but we want to keep it all in the spinlock.
43574 */
43575- if (hvcsd->port.count <= 0) {
43576+ if (atomic_read(&hvcsd->port.count) <= 0) {
43577 spin_unlock_irqrestore(&hvcsd->lock, flags);
43578 return -ENODEV;
43579 }
43580@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43581 {
43582 struct hvcs_struct *hvcsd = tty->driver_data;
43583
43584- if (!hvcsd || hvcsd->port.count <= 0)
43585+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43586 return 0;
43587
43588 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43589diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43590index 8fd72ff..34a0bed 100644
43591--- a/drivers/tty/ipwireless/tty.c
43592+++ b/drivers/tty/ipwireless/tty.c
43593@@ -29,6 +29,7 @@
43594 #include <linux/tty_driver.h>
43595 #include <linux/tty_flip.h>
43596 #include <linux/uaccess.h>
43597+#include <asm/local.h>
43598
43599 #include "tty.h"
43600 #include "network.h"
43601@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43602 mutex_unlock(&tty->ipw_tty_mutex);
43603 return -ENODEV;
43604 }
43605- if (tty->port.count == 0)
43606+ if (atomic_read(&tty->port.count) == 0)
43607 tty->tx_bytes_queued = 0;
43608
43609- tty->port.count++;
43610+ atomic_inc(&tty->port.count);
43611
43612 tty->port.tty = linux_tty;
43613 linux_tty->driver_data = tty;
43614@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43615
43616 static void do_ipw_close(struct ipw_tty *tty)
43617 {
43618- tty->port.count--;
43619-
43620- if (tty->port.count == 0) {
43621+ if (atomic_dec_return(&tty->port.count) == 0) {
43622 struct tty_struct *linux_tty = tty->port.tty;
43623
43624 if (linux_tty != NULL) {
43625@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43626 return;
43627
43628 mutex_lock(&tty->ipw_tty_mutex);
43629- if (tty->port.count == 0) {
43630+ if (atomic_read(&tty->port.count) == 0) {
43631 mutex_unlock(&tty->ipw_tty_mutex);
43632 return;
43633 }
43634@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43635
43636 mutex_lock(&tty->ipw_tty_mutex);
43637
43638- if (!tty->port.count) {
43639+ if (!atomic_read(&tty->port.count)) {
43640 mutex_unlock(&tty->ipw_tty_mutex);
43641 return;
43642 }
43643@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43644 return -ENODEV;
43645
43646 mutex_lock(&tty->ipw_tty_mutex);
43647- if (!tty->port.count) {
43648+ if (!atomic_read(&tty->port.count)) {
43649 mutex_unlock(&tty->ipw_tty_mutex);
43650 return -EINVAL;
43651 }
43652@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43653 if (!tty)
43654 return -ENODEV;
43655
43656- if (!tty->port.count)
43657+ if (!atomic_read(&tty->port.count))
43658 return -EINVAL;
43659
43660 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43661@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43662 if (!tty)
43663 return 0;
43664
43665- if (!tty->port.count)
43666+ if (!atomic_read(&tty->port.count))
43667 return 0;
43668
43669 return tty->tx_bytes_queued;
43670@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43671 if (!tty)
43672 return -ENODEV;
43673
43674- if (!tty->port.count)
43675+ if (!atomic_read(&tty->port.count))
43676 return -EINVAL;
43677
43678 return get_control_lines(tty);
43679@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43680 if (!tty)
43681 return -ENODEV;
43682
43683- if (!tty->port.count)
43684+ if (!atomic_read(&tty->port.count))
43685 return -EINVAL;
43686
43687 return set_control_lines(tty, set, clear);
43688@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43689 if (!tty)
43690 return -ENODEV;
43691
43692- if (!tty->port.count)
43693+ if (!atomic_read(&tty->port.count))
43694 return -EINVAL;
43695
43696 /* FIXME: Exactly how is the tty object locked here .. */
43697@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43698 * are gone */
43699 mutex_lock(&ttyj->ipw_tty_mutex);
43700 }
43701- while (ttyj->port.count)
43702+ while (atomic_read(&ttyj->port.count))
43703 do_ipw_close(ttyj);
43704 ipwireless_disassociate_network_ttys(network,
43705 ttyj->channel_idx);
43706diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43707index 1deaca4..c8582d4 100644
43708--- a/drivers/tty/moxa.c
43709+++ b/drivers/tty/moxa.c
43710@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43711 }
43712
43713 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43714- ch->port.count++;
43715+ atomic_inc(&ch->port.count);
43716 tty->driver_data = ch;
43717 tty_port_tty_set(&ch->port, tty);
43718 mutex_lock(&ch->port.mutex);
43719diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43720index 6422390..49003ac8 100644
43721--- a/drivers/tty/n_gsm.c
43722+++ b/drivers/tty/n_gsm.c
43723@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43724 spin_lock_init(&dlci->lock);
43725 mutex_init(&dlci->mutex);
43726 dlci->fifo = &dlci->_fifo;
43727- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43728+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43729 kfree(dlci);
43730 return NULL;
43731 }
43732@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43733 struct gsm_dlci *dlci = tty->driver_data;
43734 struct tty_port *port = &dlci->port;
43735
43736- port->count++;
43737+ atomic_inc(&port->count);
43738 dlci_get(dlci);
43739 dlci_get(dlci->gsm->dlci[0]);
43740 mux_get(dlci->gsm);
43741diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43742index 6c7fe90..9241dab 100644
43743--- a/drivers/tty/n_tty.c
43744+++ b/drivers/tty/n_tty.c
43745@@ -2203,6 +2203,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43746 {
43747 *ops = tty_ldisc_N_TTY;
43748 ops->owner = NULL;
43749- ops->refcount = ops->flags = 0;
43750+ atomic_set(&ops->refcount, 0);
43751+ ops->flags = 0;
43752 }
43753 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43754diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43755index abfd990..5ab5da9 100644
43756--- a/drivers/tty/pty.c
43757+++ b/drivers/tty/pty.c
43758@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
43759 panic("Couldn't register Unix98 pts driver");
43760
43761 /* Now create the /dev/ptmx special device */
43762+ pax_open_kernel();
43763 tty_default_fops(&ptmx_fops);
43764- ptmx_fops.open = ptmx_open;
43765+ *(void **)&ptmx_fops.open = ptmx_open;
43766+ pax_close_kernel();
43767
43768 cdev_init(&ptmx_cdev, &ptmx_fops);
43769 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43770diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43771index 354564e..fe50d9a 100644
43772--- a/drivers/tty/rocket.c
43773+++ b/drivers/tty/rocket.c
43774@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43775 tty->driver_data = info;
43776 tty_port_tty_set(port, tty);
43777
43778- if (port->count++ == 0) {
43779+ if (atomic_inc_return(&port->count) == 1) {
43780 atomic_inc(&rp_num_ports_open);
43781
43782 #ifdef ROCKET_DEBUG_OPEN
43783@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43784 #endif
43785 }
43786 #ifdef ROCKET_DEBUG_OPEN
43787- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43788+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43789 #endif
43790
43791 /*
43792@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
43793 spin_unlock_irqrestore(&info->port.lock, flags);
43794 return;
43795 }
43796- if (info->port.count)
43797+ if (atomic_read(&info->port.count))
43798 atomic_dec(&rp_num_ports_open);
43799 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43800 spin_unlock_irqrestore(&info->port.lock, flags);
43801diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43802index 1002054..dd644a8 100644
43803--- a/drivers/tty/serial/kgdboc.c
43804+++ b/drivers/tty/serial/kgdboc.c
43805@@ -24,8 +24,9 @@
43806 #define MAX_CONFIG_LEN 40
43807
43808 static struct kgdb_io kgdboc_io_ops;
43809+static struct kgdb_io kgdboc_io_ops_console;
43810
43811-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43812+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43813 static int configured = -1;
43814
43815 static char config[MAX_CONFIG_LEN];
43816@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43817 kgdboc_unregister_kbd();
43818 if (configured == 1)
43819 kgdb_unregister_io_module(&kgdboc_io_ops);
43820+ else if (configured == 2)
43821+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43822 }
43823
43824 static int configure_kgdboc(void)
43825@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43826 int err;
43827 char *cptr = config;
43828 struct console *cons;
43829+ int is_console = 0;
43830
43831 err = kgdboc_option_setup(config);
43832 if (err || !strlen(config) || isspace(config[0]))
43833 goto noconfig;
43834
43835 err = -ENODEV;
43836- kgdboc_io_ops.is_console = 0;
43837 kgdb_tty_driver = NULL;
43838
43839 kgdboc_use_kms = 0;
43840@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43841 int idx;
43842 if (cons->device && cons->device(cons, &idx) == p &&
43843 idx == tty_line) {
43844- kgdboc_io_ops.is_console = 1;
43845+ is_console = 1;
43846 break;
43847 }
43848 cons = cons->next;
43849@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43850 kgdb_tty_line = tty_line;
43851
43852 do_register:
43853- err = kgdb_register_io_module(&kgdboc_io_ops);
43854+ if (is_console) {
43855+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43856+ configured = 2;
43857+ } else {
43858+ err = kgdb_register_io_module(&kgdboc_io_ops);
43859+ configured = 1;
43860+ }
43861 if (err)
43862 goto noconfig;
43863
43864@@ -205,8 +214,6 @@ do_register:
43865 if (err)
43866 goto nmi_con_failed;
43867
43868- configured = 1;
43869-
43870 return 0;
43871
43872 nmi_con_failed:
43873@@ -223,7 +230,7 @@ noconfig:
43874 static int __init init_kgdboc(void)
43875 {
43876 /* Already configured? */
43877- if (configured == 1)
43878+ if (configured >= 1)
43879 return 0;
43880
43881 return configure_kgdboc();
43882@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43883 if (config[len - 1] == '\n')
43884 config[len - 1] = '\0';
43885
43886- if (configured == 1)
43887+ if (configured >= 1)
43888 cleanup_kgdboc();
43889
43890 /* Go and configure with the new params. */
43891@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43892 .post_exception = kgdboc_post_exp_handler,
43893 };
43894
43895+static struct kgdb_io kgdboc_io_ops_console = {
43896+ .name = "kgdboc",
43897+ .read_char = kgdboc_get_char,
43898+ .write_char = kgdboc_put_char,
43899+ .pre_exception = kgdboc_pre_exp_handler,
43900+ .post_exception = kgdboc_post_exp_handler,
43901+ .is_console = 1
43902+};
43903+
43904 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43905 /* This is only available if kgdboc is a built in for early debugging */
43906 static int __init kgdboc_early_init(char *opt)
43907diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43908index 0c8a9fa..234a95f 100644
43909--- a/drivers/tty/serial/samsung.c
43910+++ b/drivers/tty/serial/samsung.c
43911@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43912 }
43913 }
43914
43915+static int s3c64xx_serial_startup(struct uart_port *port);
43916 static int s3c24xx_serial_startup(struct uart_port *port)
43917 {
43918 struct s3c24xx_uart_port *ourport = to_ourport(port);
43919 int ret;
43920
43921+ /* Startup sequence is different for s3c64xx and higher SoC's */
43922+ if (s3c24xx_serial_has_interrupt_mask(port))
43923+ return s3c64xx_serial_startup(port);
43924+
43925 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43926 port->mapbase, port->membase);
43927
43928@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43929 /* setup info for port */
43930 port->dev = &platdev->dev;
43931
43932- /* Startup sequence is different for s3c64xx and higher SoC's */
43933- if (s3c24xx_serial_has_interrupt_mask(port))
43934- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43935-
43936 port->uartclk = 1;
43937
43938 if (cfg->uart_flags & UPF_CONS_FLOW) {
43939diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43940index f87dbfd..42ad4b1 100644
43941--- a/drivers/tty/serial/serial_core.c
43942+++ b/drivers/tty/serial/serial_core.c
43943@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
43944 uart_flush_buffer(tty);
43945 uart_shutdown(tty, state);
43946 spin_lock_irqsave(&port->lock, flags);
43947- port->count = 0;
43948+ atomic_set(&port->count, 0);
43949 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43950 spin_unlock_irqrestore(&port->lock, flags);
43951 tty_port_tty_set(port, NULL);
43952@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43953 goto end;
43954 }
43955
43956- port->count++;
43957+ atomic_inc(&port->count);
43958 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43959 retval = -ENXIO;
43960 goto err_dec_count;
43961@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43962 /*
43963 * Make sure the device is in D0 state.
43964 */
43965- if (port->count == 1)
43966+ if (atomic_read(&port->count) == 1)
43967 uart_change_pm(state, UART_PM_STATE_ON);
43968
43969 /*
43970@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43971 end:
43972 return retval;
43973 err_dec_count:
43974- port->count--;
43975+ atomic_inc(&port->count);
43976 mutex_unlock(&port->mutex);
43977 goto end;
43978 }
43979diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43980index 8eaf1ab..85c030d 100644
43981--- a/drivers/tty/synclink.c
43982+++ b/drivers/tty/synclink.c
43983@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43984
43985 if (debug_level >= DEBUG_LEVEL_INFO)
43986 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43987- __FILE__,__LINE__, info->device_name, info->port.count);
43988+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43989
43990 if (tty_port_close_start(&info->port, tty, filp) == 0)
43991 goto cleanup;
43992@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43993 cleanup:
43994 if (debug_level >= DEBUG_LEVEL_INFO)
43995 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43996- tty->driver->name, info->port.count);
43997+ tty->driver->name, atomic_read(&info->port.count));
43998
43999 } /* end of mgsl_close() */
44000
44001@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
44002
44003 mgsl_flush_buffer(tty);
44004 shutdown(info);
44005-
44006- info->port.count = 0;
44007+
44008+ atomic_set(&info->port.count, 0);
44009 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44010 info->port.tty = NULL;
44011
44012@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44013
44014 if (debug_level >= DEBUG_LEVEL_INFO)
44015 printk("%s(%d):block_til_ready before block on %s count=%d\n",
44016- __FILE__,__LINE__, tty->driver->name, port->count );
44017+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44018
44019 spin_lock_irqsave(&info->irq_spinlock, flags);
44020 if (!tty_hung_up_p(filp)) {
44021 extra_count = true;
44022- port->count--;
44023+ atomic_dec(&port->count);
44024 }
44025 spin_unlock_irqrestore(&info->irq_spinlock, flags);
44026 port->blocked_open++;
44027@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44028
44029 if (debug_level >= DEBUG_LEVEL_INFO)
44030 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
44031- __FILE__,__LINE__, tty->driver->name, port->count );
44032+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44033
44034 tty_unlock(tty);
44035 schedule();
44036@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
44037
44038 /* FIXME: Racy on hangup during close wait */
44039 if (extra_count)
44040- port->count++;
44041+ atomic_inc(&port->count);
44042 port->blocked_open--;
44043
44044 if (debug_level >= DEBUG_LEVEL_INFO)
44045 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
44046- __FILE__,__LINE__, tty->driver->name, port->count );
44047+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44048
44049 if (!retval)
44050 port->flags |= ASYNC_NORMAL_ACTIVE;
44051@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44052
44053 if (debug_level >= DEBUG_LEVEL_INFO)
44054 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
44055- __FILE__,__LINE__,tty->driver->name, info->port.count);
44056+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44057
44058 /* If port is closing, signal caller to try again */
44059 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44060@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
44061 spin_unlock_irqrestore(&info->netlock, flags);
44062 goto cleanup;
44063 }
44064- info->port.count++;
44065+ atomic_inc(&info->port.count);
44066 spin_unlock_irqrestore(&info->netlock, flags);
44067
44068- if (info->port.count == 1) {
44069+ if (atomic_read(&info->port.count) == 1) {
44070 /* 1st open on this device, init hardware */
44071 retval = startup(info);
44072 if (retval < 0)
44073@@ -3446,8 +3446,8 @@ cleanup:
44074 if (retval) {
44075 if (tty->count == 1)
44076 info->port.tty = NULL; /* tty layer will release tty struct */
44077- if(info->port.count)
44078- info->port.count--;
44079+ if (atomic_read(&info->port.count))
44080+ atomic_dec(&info->port.count);
44081 }
44082
44083 return retval;
44084@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44085 unsigned short new_crctype;
44086
44087 /* return error if TTY interface open */
44088- if (info->port.count)
44089+ if (atomic_read(&info->port.count))
44090 return -EBUSY;
44091
44092 switch (encoding)
44093@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
44094
44095 /* arbitrate between network and tty opens */
44096 spin_lock_irqsave(&info->netlock, flags);
44097- if (info->port.count != 0 || info->netcount != 0) {
44098+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44099 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44100 spin_unlock_irqrestore(&info->netlock, flags);
44101 return -EBUSY;
44102@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44103 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44104
44105 /* return error if TTY interface open */
44106- if (info->port.count)
44107+ if (atomic_read(&info->port.count))
44108 return -EBUSY;
44109
44110 if (cmd != SIOCWANDEV)
44111diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
44112index 1abf946..1ee34fc 100644
44113--- a/drivers/tty/synclink_gt.c
44114+++ b/drivers/tty/synclink_gt.c
44115@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44116 tty->driver_data = info;
44117 info->port.tty = tty;
44118
44119- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
44120+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
44121
44122 /* If port is closing, signal caller to try again */
44123 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44124@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44125 mutex_unlock(&info->port.mutex);
44126 goto cleanup;
44127 }
44128- info->port.count++;
44129+ atomic_inc(&info->port.count);
44130 spin_unlock_irqrestore(&info->netlock, flags);
44131
44132- if (info->port.count == 1) {
44133+ if (atomic_read(&info->port.count) == 1) {
44134 /* 1st open on this device, init hardware */
44135 retval = startup(info);
44136 if (retval < 0) {
44137@@ -715,8 +715,8 @@ cleanup:
44138 if (retval) {
44139 if (tty->count == 1)
44140 info->port.tty = NULL; /* tty layer will release tty struct */
44141- if(info->port.count)
44142- info->port.count--;
44143+ if(atomic_read(&info->port.count))
44144+ atomic_dec(&info->port.count);
44145 }
44146
44147 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44148@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44149
44150 if (sanity_check(info, tty->name, "close"))
44151 return;
44152- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44153+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44154
44155 if (tty_port_close_start(&info->port, tty, filp) == 0)
44156 goto cleanup;
44157@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44158 tty_port_close_end(&info->port, tty);
44159 info->port.tty = NULL;
44160 cleanup:
44161- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44162+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44163 }
44164
44165 static void hangup(struct tty_struct *tty)
44166@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
44167 shutdown(info);
44168
44169 spin_lock_irqsave(&info->port.lock, flags);
44170- info->port.count = 0;
44171+ atomic_set(&info->port.count, 0);
44172 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44173 info->port.tty = NULL;
44174 spin_unlock_irqrestore(&info->port.lock, flags);
44175@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44176 unsigned short new_crctype;
44177
44178 /* return error if TTY interface open */
44179- if (info->port.count)
44180+ if (atomic_read(&info->port.count))
44181 return -EBUSY;
44182
44183 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44184@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
44185
44186 /* arbitrate between network and tty opens */
44187 spin_lock_irqsave(&info->netlock, flags);
44188- if (info->port.count != 0 || info->netcount != 0) {
44189+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44190 DBGINFO(("%s hdlc_open busy\n", dev->name));
44191 spin_unlock_irqrestore(&info->netlock, flags);
44192 return -EBUSY;
44193@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44194 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44195
44196 /* return error if TTY interface open */
44197- if (info->port.count)
44198+ if (atomic_read(&info->port.count))
44199 return -EBUSY;
44200
44201 if (cmd != SIOCWANDEV)
44202@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44203 if (port == NULL)
44204 continue;
44205 spin_lock(&port->lock);
44206- if ((port->port.count || port->netcount) &&
44207+ if ((atomic_read(&port->port.count) || port->netcount) &&
44208 port->pending_bh && !port->bh_running &&
44209 !port->bh_requested) {
44210 DBGISR(("%s bh queued\n", port->device_name));
44211@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44212 spin_lock_irqsave(&info->lock, flags);
44213 if (!tty_hung_up_p(filp)) {
44214 extra_count = true;
44215- port->count--;
44216+ atomic_dec(&port->count);
44217 }
44218 spin_unlock_irqrestore(&info->lock, flags);
44219 port->blocked_open++;
44220@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44221 remove_wait_queue(&port->open_wait, &wait);
44222
44223 if (extra_count)
44224- port->count++;
44225+ atomic_inc(&port->count);
44226 port->blocked_open--;
44227
44228 if (!retval)
44229diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44230index ff17138..e38b41e 100644
44231--- a/drivers/tty/synclinkmp.c
44232+++ b/drivers/tty/synclinkmp.c
44233@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44234
44235 if (debug_level >= DEBUG_LEVEL_INFO)
44236 printk("%s(%d):%s open(), old ref count = %d\n",
44237- __FILE__,__LINE__,tty->driver->name, info->port.count);
44238+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44239
44240 /* If port is closing, signal caller to try again */
44241 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44242@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44243 spin_unlock_irqrestore(&info->netlock, flags);
44244 goto cleanup;
44245 }
44246- info->port.count++;
44247+ atomic_inc(&info->port.count);
44248 spin_unlock_irqrestore(&info->netlock, flags);
44249
44250- if (info->port.count == 1) {
44251+ if (atomic_read(&info->port.count) == 1) {
44252 /* 1st open on this device, init hardware */
44253 retval = startup(info);
44254 if (retval < 0)
44255@@ -796,8 +796,8 @@ cleanup:
44256 if (retval) {
44257 if (tty->count == 1)
44258 info->port.tty = NULL; /* tty layer will release tty struct */
44259- if(info->port.count)
44260- info->port.count--;
44261+ if(atomic_read(&info->port.count))
44262+ atomic_dec(&info->port.count);
44263 }
44264
44265 return retval;
44266@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44267
44268 if (debug_level >= DEBUG_LEVEL_INFO)
44269 printk("%s(%d):%s close() entry, count=%d\n",
44270- __FILE__,__LINE__, info->device_name, info->port.count);
44271+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44272
44273 if (tty_port_close_start(&info->port, tty, filp) == 0)
44274 goto cleanup;
44275@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44276 cleanup:
44277 if (debug_level >= DEBUG_LEVEL_INFO)
44278 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44279- tty->driver->name, info->port.count);
44280+ tty->driver->name, atomic_read(&info->port.count));
44281 }
44282
44283 /* Called by tty_hangup() when a hangup is signaled.
44284@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
44285 shutdown(info);
44286
44287 spin_lock_irqsave(&info->port.lock, flags);
44288- info->port.count = 0;
44289+ atomic_set(&info->port.count, 0);
44290 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44291 info->port.tty = NULL;
44292 spin_unlock_irqrestore(&info->port.lock, flags);
44293@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44294 unsigned short new_crctype;
44295
44296 /* return error if TTY interface open */
44297- if (info->port.count)
44298+ if (atomic_read(&info->port.count))
44299 return -EBUSY;
44300
44301 switch (encoding)
44302@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
44303
44304 /* arbitrate between network and tty opens */
44305 spin_lock_irqsave(&info->netlock, flags);
44306- if (info->port.count != 0 || info->netcount != 0) {
44307+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44308 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44309 spin_unlock_irqrestore(&info->netlock, flags);
44310 return -EBUSY;
44311@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44312 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44313
44314 /* return error if TTY interface open */
44315- if (info->port.count)
44316+ if (atomic_read(&info->port.count))
44317 return -EBUSY;
44318
44319 if (cmd != SIOCWANDEV)
44320@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44321 * do not request bottom half processing if the
44322 * device is not open in a normal mode.
44323 */
44324- if ( port && (port->port.count || port->netcount) &&
44325+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44326 port->pending_bh && !port->bh_running &&
44327 !port->bh_requested ) {
44328 if ( debug_level >= DEBUG_LEVEL_ISR )
44329@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44330
44331 if (debug_level >= DEBUG_LEVEL_INFO)
44332 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44333- __FILE__,__LINE__, tty->driver->name, port->count );
44334+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44335
44336 spin_lock_irqsave(&info->lock, flags);
44337 if (!tty_hung_up_p(filp)) {
44338 extra_count = true;
44339- port->count--;
44340+ atomic_dec(&port->count);
44341 }
44342 spin_unlock_irqrestore(&info->lock, flags);
44343 port->blocked_open++;
44344@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44345
44346 if (debug_level >= DEBUG_LEVEL_INFO)
44347 printk("%s(%d):%s block_til_ready() count=%d\n",
44348- __FILE__,__LINE__, tty->driver->name, port->count );
44349+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44350
44351 tty_unlock(tty);
44352 schedule();
44353@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44354 remove_wait_queue(&port->open_wait, &wait);
44355
44356 if (extra_count)
44357- port->count++;
44358+ atomic_inc(&port->count);
44359 port->blocked_open--;
44360
44361 if (debug_level >= DEBUG_LEVEL_INFO)
44362 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44363- __FILE__,__LINE__, tty->driver->name, port->count );
44364+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44365
44366 if (!retval)
44367 port->flags |= ASYNC_NORMAL_ACTIVE;
44368diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44369index b51c154..17d55d1 100644
44370--- a/drivers/tty/sysrq.c
44371+++ b/drivers/tty/sysrq.c
44372@@ -1022,7 +1022,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44373 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44374 size_t count, loff_t *ppos)
44375 {
44376- if (count) {
44377+ if (count && capable(CAP_SYS_ADMIN)) {
44378 char c;
44379
44380 if (get_user(c, buf))
44381diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44382index 4476682..d77e748 100644
44383--- a/drivers/tty/tty_io.c
44384+++ b/drivers/tty/tty_io.c
44385@@ -3466,7 +3466,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44386
44387 void tty_default_fops(struct file_operations *fops)
44388 {
44389- *fops = tty_fops;
44390+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44391 }
44392
44393 /*
44394diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44395index 1afe192..73d2c20 100644
44396--- a/drivers/tty/tty_ldisc.c
44397+++ b/drivers/tty/tty_ldisc.c
44398@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44399 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44400 tty_ldiscs[disc] = new_ldisc;
44401 new_ldisc->num = disc;
44402- new_ldisc->refcount = 0;
44403+ atomic_set(&new_ldisc->refcount, 0);
44404 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44405
44406 return ret;
44407@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
44408 return -EINVAL;
44409
44410 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44411- if (tty_ldiscs[disc]->refcount)
44412+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44413 ret = -EBUSY;
44414 else
44415 tty_ldiscs[disc] = NULL;
44416@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44417 if (ldops) {
44418 ret = ERR_PTR(-EAGAIN);
44419 if (try_module_get(ldops->owner)) {
44420- ldops->refcount++;
44421+ atomic_inc(&ldops->refcount);
44422 ret = ldops;
44423 }
44424 }
44425@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44426 unsigned long flags;
44427
44428 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44429- ldops->refcount--;
44430+ atomic_dec(&ldops->refcount);
44431 module_put(ldops->owner);
44432 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44433 }
44434@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
44435 /* unreleased reader reference(s) will cause this WARN */
44436 WARN_ON(!atomic_dec_and_test(&ld->users));
44437
44438- ld->ops->refcount--;
44439+ atomic_dec(&ld->ops->refcount);
44440 module_put(ld->ops->owner);
44441 kfree(ld);
44442 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44443diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44444index f597e88..b7f68ed 100644
44445--- a/drivers/tty/tty_port.c
44446+++ b/drivers/tty/tty_port.c
44447@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
44448 unsigned long flags;
44449
44450 spin_lock_irqsave(&port->lock, flags);
44451- port->count = 0;
44452+ atomic_set(&port->count, 0);
44453 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44454 tty = port->tty;
44455 if (tty)
44456@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44457 /* The port lock protects the port counts */
44458 spin_lock_irqsave(&port->lock, flags);
44459 if (!tty_hung_up_p(filp))
44460- port->count--;
44461+ atomic_dec(&port->count);
44462 port->blocked_open++;
44463 spin_unlock_irqrestore(&port->lock, flags);
44464
44465@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44466 we must not mess that up further */
44467 spin_lock_irqsave(&port->lock, flags);
44468 if (!tty_hung_up_p(filp))
44469- port->count++;
44470+ atomic_inc(&port->count);
44471 port->blocked_open--;
44472 if (retval == 0)
44473 port->flags |= ASYNC_NORMAL_ACTIVE;
44474@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
44475 return 0;
44476 }
44477
44478- if (tty->count == 1 && port->count != 1) {
44479+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44480 printk(KERN_WARNING
44481 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44482- port->count);
44483- port->count = 1;
44484+ atomic_read(&port->count));
44485+ atomic_set(&port->count, 1);
44486 }
44487- if (--port->count < 0) {
44488+ if (atomic_dec_return(&port->count) < 0) {
44489 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44490- port->count);
44491- port->count = 0;
44492+ atomic_read(&port->count));
44493+ atomic_set(&port->count, 0);
44494 }
44495
44496- if (port->count) {
44497+ if (atomic_read(&port->count)) {
44498 spin_unlock_irqrestore(&port->lock, flags);
44499 if (port->ops->drop)
44500 port->ops->drop(port);
44501@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44502 {
44503 spin_lock_irq(&port->lock);
44504 if (!tty_hung_up_p(filp))
44505- ++port->count;
44506+ atomic_inc(&port->count);
44507 spin_unlock_irq(&port->lock);
44508 tty_port_tty_set(port, tty);
44509
44510diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44511index a9af1b9a..1e08e7f 100644
44512--- a/drivers/tty/vt/keyboard.c
44513+++ b/drivers/tty/vt/keyboard.c
44514@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44515 kbd->kbdmode == VC_OFF) &&
44516 value != KVAL(K_SAK))
44517 return; /* SAK is allowed even in raw mode */
44518+
44519+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44520+ {
44521+ void *func = fn_handler[value];
44522+ if (func == fn_show_state || func == fn_show_ptregs ||
44523+ func == fn_show_mem)
44524+ return;
44525+ }
44526+#endif
44527+
44528 fn_handler[value](vc);
44529 }
44530
44531@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44532 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44533 return -EFAULT;
44534
44535- if (!capable(CAP_SYS_TTY_CONFIG))
44536- perm = 0;
44537-
44538 switch (cmd) {
44539 case KDGKBENT:
44540 /* Ensure another thread doesn't free it under us */
44541@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44542 spin_unlock_irqrestore(&kbd_event_lock, flags);
44543 return put_user(val, &user_kbe->kb_value);
44544 case KDSKBENT:
44545+ if (!capable(CAP_SYS_TTY_CONFIG))
44546+ perm = 0;
44547+
44548 if (!perm)
44549 return -EPERM;
44550 if (!i && v == K_NOSUCHMAP) {
44551@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44552 int i, j, k;
44553 int ret;
44554
44555- if (!capable(CAP_SYS_TTY_CONFIG))
44556- perm = 0;
44557-
44558 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44559 if (!kbs) {
44560 ret = -ENOMEM;
44561@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44562 kfree(kbs);
44563 return ((p && *p) ? -EOVERFLOW : 0);
44564 case KDSKBSENT:
44565+ if (!capable(CAP_SYS_TTY_CONFIG))
44566+ perm = 0;
44567+
44568 if (!perm) {
44569 ret = -EPERM;
44570 goto reterr;
44571diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44572index b645c47..a55c182 100644
44573--- a/drivers/uio/uio.c
44574+++ b/drivers/uio/uio.c
44575@@ -25,6 +25,7 @@
44576 #include <linux/kobject.h>
44577 #include <linux/cdev.h>
44578 #include <linux/uio_driver.h>
44579+#include <asm/local.h>
44580
44581 #define UIO_MAX_DEVICES (1U << MINORBITS)
44582
44583@@ -32,10 +33,10 @@ struct uio_device {
44584 struct module *owner;
44585 struct device *dev;
44586 int minor;
44587- atomic_t event;
44588+ atomic_unchecked_t event;
44589 struct fasync_struct *async_queue;
44590 wait_queue_head_t wait;
44591- int vma_count;
44592+ local_t vma_count;
44593 struct uio_info *info;
44594 struct kobject *map_dir;
44595 struct kobject *portio_dir;
44596@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44597 struct device_attribute *attr, char *buf)
44598 {
44599 struct uio_device *idev = dev_get_drvdata(dev);
44600- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44601+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44602 }
44603
44604 static struct device_attribute uio_class_attributes[] = {
44605@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
44606 {
44607 struct uio_device *idev = info->uio_dev;
44608
44609- atomic_inc(&idev->event);
44610+ atomic_inc_unchecked(&idev->event);
44611 wake_up_interruptible(&idev->wait);
44612 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44613 }
44614@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44615 }
44616
44617 listener->dev = idev;
44618- listener->event_count = atomic_read(&idev->event);
44619+ listener->event_count = atomic_read_unchecked(&idev->event);
44620 filep->private_data = listener;
44621
44622 if (idev->info->open) {
44623@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44624 return -EIO;
44625
44626 poll_wait(filep, &idev->wait, wait);
44627- if (listener->event_count != atomic_read(&idev->event))
44628+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44629 return POLLIN | POLLRDNORM;
44630 return 0;
44631 }
44632@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44633 do {
44634 set_current_state(TASK_INTERRUPTIBLE);
44635
44636- event_count = atomic_read(&idev->event);
44637+ event_count = atomic_read_unchecked(&idev->event);
44638 if (event_count != listener->event_count) {
44639 if (copy_to_user(buf, &event_count, count))
44640 retval = -EFAULT;
44641@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44642 static void uio_vma_open(struct vm_area_struct *vma)
44643 {
44644 struct uio_device *idev = vma->vm_private_data;
44645- idev->vma_count++;
44646+ local_inc(&idev->vma_count);
44647 }
44648
44649 static void uio_vma_close(struct vm_area_struct *vma)
44650 {
44651 struct uio_device *idev = vma->vm_private_data;
44652- idev->vma_count--;
44653+ local_dec(&idev->vma_count);
44654 }
44655
44656 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44657@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
44658 idev->owner = owner;
44659 idev->info = info;
44660 init_waitqueue_head(&idev->wait);
44661- atomic_set(&idev->event, 0);
44662+ atomic_set_unchecked(&idev->event, 0);
44663
44664 ret = uio_get_minor(idev);
44665 if (ret)
44666diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44667index 8a7eb77..c00402f 100644
44668--- a/drivers/usb/atm/cxacru.c
44669+++ b/drivers/usb/atm/cxacru.c
44670@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44671 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44672 if (ret < 2)
44673 return -EINVAL;
44674- if (index < 0 || index > 0x7f)
44675+ if (index > 0x7f)
44676 return -EINVAL;
44677 pos += tmp;
44678
44679diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44680index d3527dd..26effa2 100644
44681--- a/drivers/usb/atm/usbatm.c
44682+++ b/drivers/usb/atm/usbatm.c
44683@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44684 if (printk_ratelimit())
44685 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44686 __func__, vpi, vci);
44687- atomic_inc(&vcc->stats->rx_err);
44688+ atomic_inc_unchecked(&vcc->stats->rx_err);
44689 return;
44690 }
44691
44692@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44693 if (length > ATM_MAX_AAL5_PDU) {
44694 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44695 __func__, length, vcc);
44696- atomic_inc(&vcc->stats->rx_err);
44697+ atomic_inc_unchecked(&vcc->stats->rx_err);
44698 goto out;
44699 }
44700
44701@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44702 if (sarb->len < pdu_length) {
44703 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44704 __func__, pdu_length, sarb->len, vcc);
44705- atomic_inc(&vcc->stats->rx_err);
44706+ atomic_inc_unchecked(&vcc->stats->rx_err);
44707 goto out;
44708 }
44709
44710 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44711 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44712 __func__, vcc);
44713- atomic_inc(&vcc->stats->rx_err);
44714+ atomic_inc_unchecked(&vcc->stats->rx_err);
44715 goto out;
44716 }
44717
44718@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44719 if (printk_ratelimit())
44720 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44721 __func__, length);
44722- atomic_inc(&vcc->stats->rx_drop);
44723+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44724 goto out;
44725 }
44726
44727@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44728
44729 vcc->push(vcc, skb);
44730
44731- atomic_inc(&vcc->stats->rx);
44732+ atomic_inc_unchecked(&vcc->stats->rx);
44733 out:
44734 skb_trim(sarb, 0);
44735 }
44736@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44737 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44738
44739 usbatm_pop(vcc, skb);
44740- atomic_inc(&vcc->stats->tx);
44741+ atomic_inc_unchecked(&vcc->stats->tx);
44742
44743 skb = skb_dequeue(&instance->sndqueue);
44744 }
44745@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44746 if (!left--)
44747 return sprintf(page,
44748 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44749- atomic_read(&atm_dev->stats.aal5.tx),
44750- atomic_read(&atm_dev->stats.aal5.tx_err),
44751- atomic_read(&atm_dev->stats.aal5.rx),
44752- atomic_read(&atm_dev->stats.aal5.rx_err),
44753- atomic_read(&atm_dev->stats.aal5.rx_drop));
44754+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44755+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44756+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44757+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44758+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44759
44760 if (!left--) {
44761 if (instance->disconnected)
44762diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44763index 2a3bbdf..91d72cf 100644
44764--- a/drivers/usb/core/devices.c
44765+++ b/drivers/usb/core/devices.c
44766@@ -126,7 +126,7 @@ static const char format_endpt[] =
44767 * time it gets called.
44768 */
44769 static struct device_connect_event {
44770- atomic_t count;
44771+ atomic_unchecked_t count;
44772 wait_queue_head_t wait;
44773 } device_event = {
44774 .count = ATOMIC_INIT(1),
44775@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44776
44777 void usbfs_conn_disc_event(void)
44778 {
44779- atomic_add(2, &device_event.count);
44780+ atomic_add_unchecked(2, &device_event.count);
44781 wake_up(&device_event.wait);
44782 }
44783
44784@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
44785
44786 poll_wait(file, &device_event.wait, wait);
44787
44788- event_count = atomic_read(&device_event.count);
44789+ event_count = atomic_read_unchecked(&device_event.count);
44790 if (file->f_version != event_count) {
44791 file->f_version = event_count;
44792 return POLLIN | POLLRDNORM;
44793diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44794index d53547d..6a22d02 100644
44795--- a/drivers/usb/core/hcd.c
44796+++ b/drivers/usb/core/hcd.c
44797@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44798 */
44799 usb_get_urb(urb);
44800 atomic_inc(&urb->use_count);
44801- atomic_inc(&urb->dev->urbnum);
44802+ atomic_inc_unchecked(&urb->dev->urbnum);
44803 usbmon_urb_submit(&hcd->self, urb);
44804
44805 /* NOTE requirements on root-hub callers (usbfs and the hub
44806@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44807 urb->hcpriv = NULL;
44808 INIT_LIST_HEAD(&urb->urb_list);
44809 atomic_dec(&urb->use_count);
44810- atomic_dec(&urb->dev->urbnum);
44811+ atomic_dec_unchecked(&urb->dev->urbnum);
44812 if (atomic_read(&urb->reject))
44813 wake_up(&usb_kill_urb_queue);
44814 usb_put_urb(urb);
44815diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44816index 444d30e..f15c850 100644
44817--- a/drivers/usb/core/message.c
44818+++ b/drivers/usb/core/message.c
44819@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44820 * method can wait for it to complete. Since you don't have a handle on the
44821 * URB used, you can't cancel the request.
44822 */
44823-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44824+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44825 __u8 requesttype, __u16 value, __u16 index, void *data,
44826 __u16 size, int timeout)
44827 {
44828diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44829index aa38db4..0a08682 100644
44830--- a/drivers/usb/core/sysfs.c
44831+++ b/drivers/usb/core/sysfs.c
44832@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44833 struct usb_device *udev;
44834
44835 udev = to_usb_device(dev);
44836- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44837+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44838 }
44839 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44840
44841diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44842index b10da72..43aa0b2 100644
44843--- a/drivers/usb/core/usb.c
44844+++ b/drivers/usb/core/usb.c
44845@@ -389,7 +389,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44846 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44847 dev->state = USB_STATE_ATTACHED;
44848 dev->lpm_disable_count = 1;
44849- atomic_set(&dev->urbnum, 0);
44850+ atomic_set_unchecked(&dev->urbnum, 0);
44851
44852 INIT_LIST_HEAD(&dev->ep0.urb_list);
44853 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44854diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44855index 5e29dde..eca992f 100644
44856--- a/drivers/usb/early/ehci-dbgp.c
44857+++ b/drivers/usb/early/ehci-dbgp.c
44858@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44859
44860 #ifdef CONFIG_KGDB
44861 static struct kgdb_io kgdbdbgp_io_ops;
44862-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44863+static struct kgdb_io kgdbdbgp_io_ops_console;
44864+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44865 #else
44866 #define dbgp_kgdb_mode (0)
44867 #endif
44868@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44869 .write_char = kgdbdbgp_write_char,
44870 };
44871
44872+static struct kgdb_io kgdbdbgp_io_ops_console = {
44873+ .name = "kgdbdbgp",
44874+ .read_char = kgdbdbgp_read_char,
44875+ .write_char = kgdbdbgp_write_char,
44876+ .is_console = 1
44877+};
44878+
44879 static int kgdbdbgp_wait_time;
44880
44881 static int __init kgdbdbgp_parse_config(char *str)
44882@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44883 ptr++;
44884 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44885 }
44886- kgdb_register_io_module(&kgdbdbgp_io_ops);
44887- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44888+ if (early_dbgp_console.index != -1)
44889+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44890+ else
44891+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44892
44893 return 0;
44894 }
44895diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44896index b369292..9f3ba40 100644
44897--- a/drivers/usb/gadget/u_serial.c
44898+++ b/drivers/usb/gadget/u_serial.c
44899@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44900 spin_lock_irq(&port->port_lock);
44901
44902 /* already open? Great. */
44903- if (port->port.count) {
44904+ if (atomic_read(&port->port.count)) {
44905 status = 0;
44906- port->port.count++;
44907+ atomic_inc(&port->port.count);
44908
44909 /* currently opening/closing? wait ... */
44910 } else if (port->openclose) {
44911@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44912 tty->driver_data = port;
44913 port->port.tty = tty;
44914
44915- port->port.count = 1;
44916+ atomic_set(&port->port.count, 1);
44917 port->openclose = false;
44918
44919 /* if connected, start the I/O stream */
44920@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44921
44922 spin_lock_irq(&port->port_lock);
44923
44924- if (port->port.count != 1) {
44925- if (port->port.count == 0)
44926+ if (atomic_read(&port->port.count) != 1) {
44927+ if (atomic_read(&port->port.count) == 0)
44928 WARN_ON(1);
44929 else
44930- --port->port.count;
44931+ atomic_dec(&port->port.count);
44932 goto exit;
44933 }
44934
44935@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44936 * and sleep if necessary
44937 */
44938 port->openclose = true;
44939- port->port.count = 0;
44940+ atomic_set(&port->port.count, 0);
44941
44942 gser = port->port_usb;
44943 if (gser && gser->disconnect)
44944@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
44945 int cond;
44946
44947 spin_lock_irq(&port->port_lock);
44948- cond = (port->port.count == 0) && !port->openclose;
44949+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44950 spin_unlock_irq(&port->port_lock);
44951 return cond;
44952 }
44953@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44954 /* if it's already open, start I/O ... and notify the serial
44955 * protocol about open/close status (connect/disconnect).
44956 */
44957- if (port->port.count) {
44958+ if (atomic_read(&port->port.count)) {
44959 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44960 gs_start_io(port);
44961 if (gser->connect)
44962@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
44963
44964 port->port_usb = NULL;
44965 gser->ioport = NULL;
44966- if (port->port.count > 0 || port->openclose) {
44967+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44968 wake_up_interruptible(&port->drain_wait);
44969 if (port->port.tty)
44970 tty_hangup(port->port.tty);
44971@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
44972
44973 /* finally, free any unused/unusable I/O buffers */
44974 spin_lock_irqsave(&port->port_lock, flags);
44975- if (port->port.count == 0 && !port->openclose)
44976+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44977 gs_buf_free(&port->port_write_buf);
44978 gs_free_requests(gser->out, &port->read_pool, NULL);
44979 gs_free_requests(gser->out, &port->read_queue, NULL);
44980diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44981index 5f3bcd3..bfca43f 100644
44982--- a/drivers/usb/serial/console.c
44983+++ b/drivers/usb/serial/console.c
44984@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44985
44986 info->port = port;
44987
44988- ++port->port.count;
44989+ atomic_inc(&port->port.count);
44990 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44991 if (serial->type->set_termios) {
44992 /*
44993@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44994 }
44995 /* Now that any required fake tty operations are completed restore
44996 * the tty port count */
44997- --port->port.count;
44998+ atomic_dec(&port->port.count);
44999 /* The console is special in terms of closing the device so
45000 * indicate this port is now acting as a system console. */
45001 port->port.console = 1;
45002@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
45003 free_tty:
45004 kfree(tty);
45005 reset_open_count:
45006- port->port.count = 0;
45007+ atomic_set(&port->port.count, 0);
45008 usb_autopm_put_interface(serial->interface);
45009 error_get_interface:
45010 usb_serial_put(serial);
45011diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
45012index 75f70f0..d467e1a 100644
45013--- a/drivers/usb/storage/usb.h
45014+++ b/drivers/usb/storage/usb.h
45015@@ -63,7 +63,7 @@ struct us_unusual_dev {
45016 __u8 useProtocol;
45017 __u8 useTransport;
45018 int (*initFunction)(struct us_data *);
45019-};
45020+} __do_const;
45021
45022
45023 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
45024diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
45025index d6bea3e..60b250e 100644
45026--- a/drivers/usb/wusbcore/wa-hc.h
45027+++ b/drivers/usb/wusbcore/wa-hc.h
45028@@ -192,7 +192,7 @@ struct wahc {
45029 struct list_head xfer_delayed_list;
45030 spinlock_t xfer_list_lock;
45031 struct work_struct xfer_work;
45032- atomic_t xfer_id_count;
45033+ atomic_unchecked_t xfer_id_count;
45034 };
45035
45036
45037@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
45038 INIT_LIST_HEAD(&wa->xfer_delayed_list);
45039 spin_lock_init(&wa->xfer_list_lock);
45040 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
45041- atomic_set(&wa->xfer_id_count, 1);
45042+ atomic_set_unchecked(&wa->xfer_id_count, 1);
45043 }
45044
45045 /**
45046diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
45047index 6ef94bc..1b41265 100644
45048--- a/drivers/usb/wusbcore/wa-xfer.c
45049+++ b/drivers/usb/wusbcore/wa-xfer.c
45050@@ -296,7 +296,7 @@ out:
45051 */
45052 static void wa_xfer_id_init(struct wa_xfer *xfer)
45053 {
45054- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
45055+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
45056 }
45057
45058 /*
45059diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
45060index 5174eba..86e764a 100644
45061--- a/drivers/vhost/vringh.c
45062+++ b/drivers/vhost/vringh.c
45063@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
45064
45065 static inline int putu16_kern(u16 *p, u16 val)
45066 {
45067- ACCESS_ONCE(*p) = val;
45068+ ACCESS_ONCE_RW(*p) = val;
45069 return 0;
45070 }
45071
45072diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
45073index 8c55011..eed4ae1a 100644
45074--- a/drivers/video/aty/aty128fb.c
45075+++ b/drivers/video/aty/aty128fb.c
45076@@ -149,7 +149,7 @@ enum {
45077 };
45078
45079 /* Must match above enum */
45080-static char * const r128_family[] = {
45081+static const char * const r128_family[] = {
45082 "AGP",
45083 "PCI",
45084 "PRO AGP",
45085diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
45086index 4f27fdc..d3537e6 100644
45087--- a/drivers/video/aty/atyfb_base.c
45088+++ b/drivers/video/aty/atyfb_base.c
45089@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
45090 par->accel_flags = var->accel_flags; /* hack */
45091
45092 if (var->accel_flags) {
45093- info->fbops->fb_sync = atyfb_sync;
45094+ pax_open_kernel();
45095+ *(void **)&info->fbops->fb_sync = atyfb_sync;
45096+ pax_close_kernel();
45097 info->flags &= ~FBINFO_HWACCEL_DISABLED;
45098 } else {
45099- info->fbops->fb_sync = NULL;
45100+ pax_open_kernel();
45101+ *(void **)&info->fbops->fb_sync = NULL;
45102+ pax_close_kernel();
45103 info->flags |= FBINFO_HWACCEL_DISABLED;
45104 }
45105
45106diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45107index 95ec042..e6affdd 100644
45108--- a/drivers/video/aty/mach64_cursor.c
45109+++ b/drivers/video/aty/mach64_cursor.c
45110@@ -7,6 +7,7 @@
45111 #include <linux/string.h>
45112
45113 #include <asm/io.h>
45114+#include <asm/pgtable.h>
45115
45116 #ifdef __sparc__
45117 #include <asm/fbio.h>
45118@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45119 info->sprite.buf_align = 16; /* and 64 lines tall. */
45120 info->sprite.flags = FB_PIXMAP_IO;
45121
45122- info->fbops->fb_cursor = atyfb_cursor;
45123+ pax_open_kernel();
45124+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45125+ pax_close_kernel();
45126
45127 return 0;
45128 }
45129diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
45130index c74e7aa..e3c2790 100644
45131--- a/drivers/video/backlight/backlight.c
45132+++ b/drivers/video/backlight/backlight.c
45133@@ -304,7 +304,7 @@ struct backlight_device *backlight_device_register(const char *name,
45134 new_bd->dev.class = backlight_class;
45135 new_bd->dev.parent = parent;
45136 new_bd->dev.release = bl_device_release;
45137- dev_set_name(&new_bd->dev, name);
45138+ dev_set_name(&new_bd->dev, "%s", name);
45139 dev_set_drvdata(&new_bd->dev, devdata);
45140
45141 /* Set default properties */
45142diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45143index bca6ccc..252107e 100644
45144--- a/drivers/video/backlight/kb3886_bl.c
45145+++ b/drivers/video/backlight/kb3886_bl.c
45146@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45147 static unsigned long kb3886bl_flags;
45148 #define KB3886BL_SUSPENDED 0x01
45149
45150-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45151+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45152 {
45153 .ident = "Sahara Touch-iT",
45154 .matches = {
45155diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
45156index 34fb6bd..3649fd9 100644
45157--- a/drivers/video/backlight/lcd.c
45158+++ b/drivers/video/backlight/lcd.c
45159@@ -219,7 +219,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent,
45160 new_ld->dev.class = lcd_class;
45161 new_ld->dev.parent = parent;
45162 new_ld->dev.release = lcd_device_release;
45163- dev_set_name(&new_ld->dev, name);
45164+ dev_set_name(&new_ld->dev, "%s", name);
45165 dev_set_drvdata(&new_ld->dev, devdata);
45166
45167 rc = device_register(&new_ld->dev);
45168diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45169index 900aa4e..6d49418 100644
45170--- a/drivers/video/fb_defio.c
45171+++ b/drivers/video/fb_defio.c
45172@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45173
45174 BUG_ON(!fbdefio);
45175 mutex_init(&fbdefio->lock);
45176- info->fbops->fb_mmap = fb_deferred_io_mmap;
45177+ pax_open_kernel();
45178+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45179+ pax_close_kernel();
45180 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45181 INIT_LIST_HEAD(&fbdefio->pagelist);
45182 if (fbdefio->delay == 0) /* set a default of 1 s */
45183@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45184 page->mapping = NULL;
45185 }
45186
45187- info->fbops->fb_mmap = NULL;
45188+ *(void **)&info->fbops->fb_mmap = NULL;
45189 mutex_destroy(&fbdefio->lock);
45190 }
45191 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45192diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45193index 5c3960d..15cf8fc 100644
45194--- a/drivers/video/fbcmap.c
45195+++ b/drivers/video/fbcmap.c
45196@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45197 rc = -ENODEV;
45198 goto out;
45199 }
45200- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45201- !info->fbops->fb_setcmap)) {
45202+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45203 rc = -EINVAL;
45204 goto out1;
45205 }
45206diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45207index 098bfc6..796841d 100644
45208--- a/drivers/video/fbmem.c
45209+++ b/drivers/video/fbmem.c
45210@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45211 image->dx += image->width + 8;
45212 }
45213 } else if (rotate == FB_ROTATE_UD) {
45214- for (x = 0; x < num && image->dx >= 0; x++) {
45215+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45216 info->fbops->fb_imageblit(info, image);
45217 image->dx -= image->width + 8;
45218 }
45219@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45220 image->dy += image->height + 8;
45221 }
45222 } else if (rotate == FB_ROTATE_CCW) {
45223- for (x = 0; x < num && image->dy >= 0; x++) {
45224+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45225 info->fbops->fb_imageblit(info, image);
45226 image->dy -= image->height + 8;
45227 }
45228@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45229 return -EFAULT;
45230 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45231 return -EINVAL;
45232- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45233+ if (con2fb.framebuffer >= FB_MAX)
45234 return -EINVAL;
45235 if (!registered_fb[con2fb.framebuffer])
45236 request_module("fb%d", con2fb.framebuffer);
45237diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45238index 7672d2e..b56437f 100644
45239--- a/drivers/video/i810/i810_accel.c
45240+++ b/drivers/video/i810/i810_accel.c
45241@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45242 }
45243 }
45244 printk("ringbuffer lockup!!!\n");
45245+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45246 i810_report_error(mmio);
45247 par->dev_flags |= LOCKUP;
45248 info->pixmap.scan_align = 1;
45249diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45250index 3c14e43..eafa544 100644
45251--- a/drivers/video/logo/logo_linux_clut224.ppm
45252+++ b/drivers/video/logo/logo_linux_clut224.ppm
45253@@ -1,1604 +1,1123 @@
45254 P3
45255-# Standard 224-color Linux logo
45256 80 80
45257 255
45258- 0 0 0 0 0 0 0 0 0 0 0 0
45259- 0 0 0 0 0 0 0 0 0 0 0 0
45260- 0 0 0 0 0 0 0 0 0 0 0 0
45261- 0 0 0 0 0 0 0 0 0 0 0 0
45262- 0 0 0 0 0 0 0 0 0 0 0 0
45263- 0 0 0 0 0 0 0 0 0 0 0 0
45264- 0 0 0 0 0 0 0 0 0 0 0 0
45265- 0 0 0 0 0 0 0 0 0 0 0 0
45266- 0 0 0 0 0 0 0 0 0 0 0 0
45267- 6 6 6 6 6 6 10 10 10 10 10 10
45268- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0
45279- 0 0 0 0 0 0 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 0 0 0 0 0 0
45283- 0 0 0 0 0 0 0 0 0 0 0 0
45284- 0 0 0 0 0 0 0 0 0 0 0 0
45285- 0 0 0 0 0 0 0 0 0 0 0 0
45286- 0 0 0 6 6 6 10 10 10 14 14 14
45287- 22 22 22 26 26 26 30 30 30 34 34 34
45288- 30 30 30 30 30 30 26 26 26 18 18 18
45289- 14 14 14 10 10 10 6 6 6 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 0 0 0 0 0 0
45299- 0 0 0 0 0 1 0 0 1 0 0 0
45300- 0 0 0 0 0 0 0 0 0 0 0 0
45301- 0 0 0 0 0 0 0 0 0 0 0 0
45302- 0 0 0 0 0 0 0 0 0 0 0 0
45303- 0 0 0 0 0 0 0 0 0 0 0 0
45304- 0 0 0 0 0 0 0 0 0 0 0 0
45305- 0 0 0 0 0 0 0 0 0 0 0 0
45306- 6 6 6 14 14 14 26 26 26 42 42 42
45307- 54 54 54 66 66 66 78 78 78 78 78 78
45308- 78 78 78 74 74 74 66 66 66 54 54 54
45309- 42 42 42 26 26 26 18 18 18 10 10 10
45310- 6 6 6 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 0 0 0 0 0 0
45319- 0 0 1 0 0 0 0 0 0 0 0 0
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 0 0 0 0 0 0 0 0 0 0
45322- 0 0 0 0 0 0 0 0 0 0 0 0
45323- 0 0 0 0 0 0 0 0 0 0 0 0
45324- 0 0 0 0 0 0 0 0 0 0 0 0
45325- 0 0 0 0 0 0 0 0 0 10 10 10
45326- 22 22 22 42 42 42 66 66 66 86 86 86
45327- 66 66 66 38 38 38 38 38 38 22 22 22
45328- 26 26 26 34 34 34 54 54 54 66 66 66
45329- 86 86 86 70 70 70 46 46 46 26 26 26
45330- 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
45339- 0 0 1 0 0 1 0 0 1 0 0 0
45340- 0 0 0 0 0 0 0 0 0 0 0 0
45341- 0 0 0 0 0 0 0 0 0 0 0 0
45342- 0 0 0 0 0 0 0 0 0 0 0 0
45343- 0 0 0 0 0 0 0 0 0 0 0 0
45344- 0 0 0 0 0 0 0 0 0 0 0 0
45345- 0 0 0 0 0 0 10 10 10 26 26 26
45346- 50 50 50 82 82 82 58 58 58 6 6 6
45347- 2 2 6 2 2 6 2 2 6 2 2 6
45348- 2 2 6 2 2 6 2 2 6 2 2 6
45349- 6 6 6 54 54 54 86 86 86 66 66 66
45350- 38 38 38 18 18 18 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
45359- 0 0 0 0 0 0 0 0 0 0 0 0
45360- 0 0 0 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 0 0 0 0 0 0 0 0 0 0 0 0
45363- 0 0 0 0 0 0 0 0 0 0 0 0
45364- 0 0 0 0 0 0 0 0 0 0 0 0
45365- 0 0 0 6 6 6 22 22 22 50 50 50
45366- 78 78 78 34 34 34 2 2 6 2 2 6
45367- 2 2 6 2 2 6 2 2 6 2 2 6
45368- 2 2 6 2 2 6 2 2 6 2 2 6
45369- 2 2 6 2 2 6 6 6 6 70 70 70
45370- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0
45378- 0 0 0 0 0 0 0 0 0 0 0 0
45379- 0 0 1 0 0 1 0 0 1 0 0 0
45380- 0 0 0 0 0 0 0 0 0 0 0 0
45381- 0 0 0 0 0 0 0 0 0 0 0 0
45382- 0 0 0 0 0 0 0 0 0 0 0 0
45383- 0 0 0 0 0 0 0 0 0 0 0 0
45384- 0 0 0 0 0 0 0 0 0 0 0 0
45385- 6 6 6 18 18 18 42 42 42 82 82 82
45386- 26 26 26 2 2 6 2 2 6 2 2 6
45387- 2 2 6 2 2 6 2 2 6 2 2 6
45388- 2 2 6 2 2 6 2 2 6 14 14 14
45389- 46 46 46 34 34 34 6 6 6 2 2 6
45390- 42 42 42 78 78 78 42 42 42 18 18 18
45391- 6 6 6 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 0 0 0
45398- 0 0 0 0 0 0 0 0 0 0 0 0
45399- 0 0 1 0 0 0 0 0 1 0 0 0
45400- 0 0 0 0 0 0 0 0 0 0 0 0
45401- 0 0 0 0 0 0 0 0 0 0 0 0
45402- 0 0 0 0 0 0 0 0 0 0 0 0
45403- 0 0 0 0 0 0 0 0 0 0 0 0
45404- 0 0 0 0 0 0 0 0 0 0 0 0
45405- 10 10 10 30 30 30 66 66 66 58 58 58
45406- 2 2 6 2 2 6 2 2 6 2 2 6
45407- 2 2 6 2 2 6 2 2 6 2 2 6
45408- 2 2 6 2 2 6 2 2 6 26 26 26
45409- 86 86 86 101 101 101 46 46 46 10 10 10
45410- 2 2 6 58 58 58 70 70 70 34 34 34
45411- 10 10 10 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 0 0 0 0 0 0
45418- 0 0 0 0 0 0 0 0 0 0 0 0
45419- 0 0 1 0 0 1 0 0 1 0 0 0
45420- 0 0 0 0 0 0 0 0 0 0 0 0
45421- 0 0 0 0 0 0 0 0 0 0 0 0
45422- 0 0 0 0 0 0 0 0 0 0 0 0
45423- 0 0 0 0 0 0 0 0 0 0 0 0
45424- 0 0 0 0 0 0 0 0 0 0 0 0
45425- 14 14 14 42 42 42 86 86 86 10 10 10
45426- 2 2 6 2 2 6 2 2 6 2 2 6
45427- 2 2 6 2 2 6 2 2 6 2 2 6
45428- 2 2 6 2 2 6 2 2 6 30 30 30
45429- 94 94 94 94 94 94 58 58 58 26 26 26
45430- 2 2 6 6 6 6 78 78 78 54 54 54
45431- 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0
45438- 0 0 0 0 0 0 0 0 0 0 0 0
45439- 0 0 0 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 0 0 0 0 0 0 0 0 0 0
45442- 0 0 0 0 0 0 0 0 0 0 0 0
45443- 0 0 0 0 0 0 0 0 0 0 0 0
45444- 0 0 0 0 0 0 0 0 0 6 6 6
45445- 22 22 22 62 62 62 62 62 62 2 2 6
45446- 2 2 6 2 2 6 2 2 6 2 2 6
45447- 2 2 6 2 2 6 2 2 6 2 2 6
45448- 2 2 6 2 2 6 2 2 6 26 26 26
45449- 54 54 54 38 38 38 18 18 18 10 10 10
45450- 2 2 6 2 2 6 34 34 34 82 82 82
45451- 38 38 38 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
45458- 0 0 0 0 0 0 0 0 0 0 0 0
45459- 0 0 0 0 0 1 0 0 1 0 0 0
45460- 0 0 0 0 0 0 0 0 0 0 0 0
45461- 0 0 0 0 0 0 0 0 0 0 0 0
45462- 0 0 0 0 0 0 0 0 0 0 0 0
45463- 0 0 0 0 0 0 0 0 0 0 0 0
45464- 0 0 0 0 0 0 0 0 0 6 6 6
45465- 30 30 30 78 78 78 30 30 30 2 2 6
45466- 2 2 6 2 2 6 2 2 6 2 2 6
45467- 2 2 6 2 2 6 2 2 6 2 2 6
45468- 2 2 6 2 2 6 2 2 6 10 10 10
45469- 10 10 10 2 2 6 2 2 6 2 2 6
45470- 2 2 6 2 2 6 2 2 6 78 78 78
45471- 50 50 50 18 18 18 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
45478- 0 0 0 0 0 0 0 0 0 0 0 0
45479- 0 0 1 0 0 0 0 0 0 0 0 0
45480- 0 0 0 0 0 0 0 0 0 0 0 0
45481- 0 0 0 0 0 0 0 0 0 0 0 0
45482- 0 0 0 0 0 0 0 0 0 0 0 0
45483- 0 0 0 0 0 0 0 0 0 0 0 0
45484- 0 0 0 0 0 0 0 0 0 10 10 10
45485- 38 38 38 86 86 86 14 14 14 2 2 6
45486- 2 2 6 2 2 6 2 2 6 2 2 6
45487- 2 2 6 2 2 6 2 2 6 2 2 6
45488- 2 2 6 2 2 6 2 2 6 2 2 6
45489- 2 2 6 2 2 6 2 2 6 2 2 6
45490- 2 2 6 2 2 6 2 2 6 54 54 54
45491- 66 66 66 26 26 26 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
45498- 0 0 0 0 0 0 0 0 0 0 0 0
45499- 0 0 0 0 0 1 0 0 1 0 0 0
45500- 0 0 0 0 0 0 0 0 0 0 0 0
45501- 0 0 0 0 0 0 0 0 0 0 0 0
45502- 0 0 0 0 0 0 0 0 0 0 0 0
45503- 0 0 0 0 0 0 0 0 0 0 0 0
45504- 0 0 0 0 0 0 0 0 0 14 14 14
45505- 42 42 42 82 82 82 2 2 6 2 2 6
45506- 2 2 6 6 6 6 10 10 10 2 2 6
45507- 2 2 6 2 2 6 2 2 6 2 2 6
45508- 2 2 6 2 2 6 2 2 6 6 6 6
45509- 14 14 14 10 10 10 2 2 6 2 2 6
45510- 2 2 6 2 2 6 2 2 6 18 18 18
45511- 82 82 82 34 34 34 10 10 10 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 0 0 0
45517- 0 0 0 0 0 0 0 0 0 0 0 0
45518- 0 0 0 0 0 0 0 0 0 0 0 0
45519- 0 0 1 0 0 0 0 0 0 0 0 0
45520- 0 0 0 0 0 0 0 0 0 0 0 0
45521- 0 0 0 0 0 0 0 0 0 0 0 0
45522- 0 0 0 0 0 0 0 0 0 0 0 0
45523- 0 0 0 0 0 0 0 0 0 0 0 0
45524- 0 0 0 0 0 0 0 0 0 14 14 14
45525- 46 46 46 86 86 86 2 2 6 2 2 6
45526- 6 6 6 6 6 6 22 22 22 34 34 34
45527- 6 6 6 2 2 6 2 2 6 2 2 6
45528- 2 2 6 2 2 6 18 18 18 34 34 34
45529- 10 10 10 50 50 50 22 22 22 2 2 6
45530- 2 2 6 2 2 6 2 2 6 10 10 10
45531- 86 86 86 42 42 42 14 14 14 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 0 0 0
45537- 0 0 0 0 0 0 0 0 0 0 0 0
45538- 0 0 0 0 0 0 0 0 0 0 0 0
45539- 0 0 1 0 0 1 0 0 1 0 0 0
45540- 0 0 0 0 0 0 0 0 0 0 0 0
45541- 0 0 0 0 0 0 0 0 0 0 0 0
45542- 0 0 0 0 0 0 0 0 0 0 0 0
45543- 0 0 0 0 0 0 0 0 0 0 0 0
45544- 0 0 0 0 0 0 0 0 0 14 14 14
45545- 46 46 46 86 86 86 2 2 6 2 2 6
45546- 38 38 38 116 116 116 94 94 94 22 22 22
45547- 22 22 22 2 2 6 2 2 6 2 2 6
45548- 14 14 14 86 86 86 138 138 138 162 162 162
45549-154 154 154 38 38 38 26 26 26 6 6 6
45550- 2 2 6 2 2 6 2 2 6 2 2 6
45551- 86 86 86 46 46 46 14 14 14 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 0 0 0
45557- 0 0 0 0 0 0 0 0 0 0 0 0
45558- 0 0 0 0 0 0 0 0 0 0 0 0
45559- 0 0 0 0 0 0 0 0 0 0 0 0
45560- 0 0 0 0 0 0 0 0 0 0 0 0
45561- 0 0 0 0 0 0 0 0 0 0 0 0
45562- 0 0 0 0 0 0 0 0 0 0 0 0
45563- 0 0 0 0 0 0 0 0 0 0 0 0
45564- 0 0 0 0 0 0 0 0 0 14 14 14
45565- 46 46 46 86 86 86 2 2 6 14 14 14
45566-134 134 134 198 198 198 195 195 195 116 116 116
45567- 10 10 10 2 2 6 2 2 6 6 6 6
45568-101 98 89 187 187 187 210 210 210 218 218 218
45569-214 214 214 134 134 134 14 14 14 6 6 6
45570- 2 2 6 2 2 6 2 2 6 2 2 6
45571- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0 0 0
45577- 0 0 0 0 0 0 0 0 0 0 0 0
45578- 0 0 0 0 0 0 0 0 1 0 0 0
45579- 0 0 1 0 0 1 0 0 1 0 0 0
45580- 0 0 0 0 0 0 0 0 0 0 0 0
45581- 0 0 0 0 0 0 0 0 0 0 0 0
45582- 0 0 0 0 0 0 0 0 0 0 0 0
45583- 0 0 0 0 0 0 0 0 0 0 0 0
45584- 0 0 0 0 0 0 0 0 0 14 14 14
45585- 46 46 46 86 86 86 2 2 6 54 54 54
45586-218 218 218 195 195 195 226 226 226 246 246 246
45587- 58 58 58 2 2 6 2 2 6 30 30 30
45588-210 210 210 253 253 253 174 174 174 123 123 123
45589-221 221 221 234 234 234 74 74 74 2 2 6
45590- 2 2 6 2 2 6 2 2 6 2 2 6
45591- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0
45597- 0 0 0 0 0 0 0 0 0 0 0 0
45598- 0 0 0 0 0 0 0 0 0 0 0 0
45599- 0 0 0 0 0 0 0 0 0 0 0 0
45600- 0 0 0 0 0 0 0 0 0 0 0 0
45601- 0 0 0 0 0 0 0 0 0 0 0 0
45602- 0 0 0 0 0 0 0 0 0 0 0 0
45603- 0 0 0 0 0 0 0 0 0 0 0 0
45604- 0 0 0 0 0 0 0 0 0 14 14 14
45605- 46 46 46 82 82 82 2 2 6 106 106 106
45606-170 170 170 26 26 26 86 86 86 226 226 226
45607-123 123 123 10 10 10 14 14 14 46 46 46
45608-231 231 231 190 190 190 6 6 6 70 70 70
45609- 90 90 90 238 238 238 158 158 158 2 2 6
45610- 2 2 6 2 2 6 2 2 6 2 2 6
45611- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
45617- 0 0 0 0 0 0 0 0 0 0 0 0
45618- 0 0 0 0 0 0 0 0 1 0 0 0
45619- 0 0 1 0 0 1 0 0 1 0 0 0
45620- 0 0 0 0 0 0 0 0 0 0 0 0
45621- 0 0 0 0 0 0 0 0 0 0 0 0
45622- 0 0 0 0 0 0 0 0 0 0 0 0
45623- 0 0 0 0 0 0 0 0 0 0 0 0
45624- 0 0 0 0 0 0 0 0 0 14 14 14
45625- 42 42 42 86 86 86 6 6 6 116 116 116
45626-106 106 106 6 6 6 70 70 70 149 149 149
45627-128 128 128 18 18 18 38 38 38 54 54 54
45628-221 221 221 106 106 106 2 2 6 14 14 14
45629- 46 46 46 190 190 190 198 198 198 2 2 6
45630- 2 2 6 2 2 6 2 2 6 2 2 6
45631- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0
45637- 0 0 0 0 0 0 0 0 0 0 0 0
45638- 0 0 0 0 0 0 0 0 1 0 0 0
45639- 0 0 1 0 0 0 0 0 1 0 0 0
45640- 0 0 0 0 0 0 0 0 0 0 0 0
45641- 0 0 0 0 0 0 0 0 0 0 0 0
45642- 0 0 0 0 0 0 0 0 0 0 0 0
45643- 0 0 0 0 0 0 0 0 0 0 0 0
45644- 0 0 0 0 0 0 0 0 0 14 14 14
45645- 42 42 42 94 94 94 14 14 14 101 101 101
45646-128 128 128 2 2 6 18 18 18 116 116 116
45647-118 98 46 121 92 8 121 92 8 98 78 10
45648-162 162 162 106 106 106 2 2 6 2 2 6
45649- 2 2 6 195 195 195 195 195 195 6 6 6
45650- 2 2 6 2 2 6 2 2 6 2 2 6
45651- 74 74 74 62 62 62 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
45657- 0 0 0 0 0 0 0 0 0 0 0 0
45658- 0 0 0 0 0 0 0 0 1 0 0 1
45659- 0 0 1 0 0 0 0 0 1 0 0 0
45660- 0 0 0 0 0 0 0 0 0 0 0 0
45661- 0 0 0 0 0 0 0 0 0 0 0 0
45662- 0 0 0 0 0 0 0 0 0 0 0 0
45663- 0 0 0 0 0 0 0 0 0 0 0 0
45664- 0 0 0 0 0 0 0 0 0 10 10 10
45665- 38 38 38 90 90 90 14 14 14 58 58 58
45666-210 210 210 26 26 26 54 38 6 154 114 10
45667-226 170 11 236 186 11 225 175 15 184 144 12
45668-215 174 15 175 146 61 37 26 9 2 2 6
45669- 70 70 70 246 246 246 138 138 138 2 2 6
45670- 2 2 6 2 2 6 2 2 6 2 2 6
45671- 70 70 70 66 66 66 26 26 26 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
45677- 0 0 0 0 0 0 0 0 0 0 0 0
45678- 0 0 0 0 0 0 0 0 0 0 0 0
45679- 0 0 0 0 0 0 0 0 0 0 0 0
45680- 0 0 0 0 0 0 0 0 0 0 0 0
45681- 0 0 0 0 0 0 0 0 0 0 0 0
45682- 0 0 0 0 0 0 0 0 0 0 0 0
45683- 0 0 0 0 0 0 0 0 0 0 0 0
45684- 0 0 0 0 0 0 0 0 0 10 10 10
45685- 38 38 38 86 86 86 14 14 14 10 10 10
45686-195 195 195 188 164 115 192 133 9 225 175 15
45687-239 182 13 234 190 10 232 195 16 232 200 30
45688-245 207 45 241 208 19 232 195 16 184 144 12
45689-218 194 134 211 206 186 42 42 42 2 2 6
45690- 2 2 6 2 2 6 2 2 6 2 2 6
45691- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
45696- 0 0 0 0 0 0 0 0 0 0 0 0
45697- 0 0 0 0 0 0 0 0 0 0 0 0
45698- 0 0 0 0 0 0 0 0 0 0 0 0
45699- 0 0 0 0 0 0 0 0 0 0 0 0
45700- 0 0 0 0 0 0 0 0 0 0 0 0
45701- 0 0 0 0 0 0 0 0 0 0 0 0
45702- 0 0 0 0 0 0 0 0 0 0 0 0
45703- 0 0 0 0 0 0 0 0 0 0 0 0
45704- 0 0 0 0 0 0 0 0 0 10 10 10
45705- 34 34 34 86 86 86 14 14 14 2 2 6
45706-121 87 25 192 133 9 219 162 10 239 182 13
45707-236 186 11 232 195 16 241 208 19 244 214 54
45708-246 218 60 246 218 38 246 215 20 241 208 19
45709-241 208 19 226 184 13 121 87 25 2 2 6
45710- 2 2 6 2 2 6 2 2 6 2 2 6
45711- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
45716- 0 0 0 0 0 0 0 0 0 0 0 0
45717- 0 0 0 0 0 0 0 0 0 0 0 0
45718- 0 0 0 0 0 0 0 0 0 0 0 0
45719- 0 0 0 0 0 0 0 0 0 0 0 0
45720- 0 0 0 0 0 0 0 0 0 0 0 0
45721- 0 0 0 0 0 0 0 0 0 0 0 0
45722- 0 0 0 0 0 0 0 0 0 0 0 0
45723- 0 0 0 0 0 0 0 0 0 0 0 0
45724- 0 0 0 0 0 0 0 0 0 10 10 10
45725- 34 34 34 82 82 82 30 30 30 61 42 6
45726-180 123 7 206 145 10 230 174 11 239 182 13
45727-234 190 10 238 202 15 241 208 19 246 218 74
45728-246 218 38 246 215 20 246 215 20 246 215 20
45729-226 184 13 215 174 15 184 144 12 6 6 6
45730- 2 2 6 2 2 6 2 2 6 2 2 6
45731- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
45736- 0 0 0 0 0 0 0 0 0 0 0 0
45737- 0 0 0 0 0 0 0 0 0 0 0 0
45738- 0 0 0 0 0 0 0 0 0 0 0 0
45739- 0 0 0 0 0 0 0 0 0 0 0 0
45740- 0 0 0 0 0 0 0 0 0 0 0 0
45741- 0 0 0 0 0 0 0 0 0 0 0 0
45742- 0 0 0 0 0 0 0 0 0 0 0 0
45743- 0 0 0 0 0 0 0 0 0 0 0 0
45744- 0 0 0 0 0 0 0 0 0 10 10 10
45745- 30 30 30 78 78 78 50 50 50 104 69 6
45746-192 133 9 216 158 10 236 178 12 236 186 11
45747-232 195 16 241 208 19 244 214 54 245 215 43
45748-246 215 20 246 215 20 241 208 19 198 155 10
45749-200 144 11 216 158 10 156 118 10 2 2 6
45750- 2 2 6 2 2 6 2 2 6 2 2 6
45751- 6 6 6 90 90 90 54 54 54 18 18 18
45752- 6 6 6 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 0 0 0 0 0 0
45756- 0 0 0 0 0 0 0 0 0 0 0 0
45757- 0 0 0 0 0 0 0 0 0 0 0 0
45758- 0 0 0 0 0 0 0 0 0 0 0 0
45759- 0 0 0 0 0 0 0 0 0 0 0 0
45760- 0 0 0 0 0 0 0 0 0 0 0 0
45761- 0 0 0 0 0 0 0 0 0 0 0 0
45762- 0 0 0 0 0 0 0 0 0 0 0 0
45763- 0 0 0 0 0 0 0 0 0 0 0 0
45764- 0 0 0 0 0 0 0 0 0 10 10 10
45765- 30 30 30 78 78 78 46 46 46 22 22 22
45766-137 92 6 210 162 10 239 182 13 238 190 10
45767-238 202 15 241 208 19 246 215 20 246 215 20
45768-241 208 19 203 166 17 185 133 11 210 150 10
45769-216 158 10 210 150 10 102 78 10 2 2 6
45770- 6 6 6 54 54 54 14 14 14 2 2 6
45771- 2 2 6 62 62 62 74 74 74 30 30 30
45772- 10 10 10 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 0 0 0 0 0 0
45776- 0 0 0 0 0 0 0 0 0 0 0 0
45777- 0 0 0 0 0 0 0 0 0 0 0 0
45778- 0 0 0 0 0 0 0 0 0 0 0 0
45779- 0 0 0 0 0 0 0 0 0 0 0 0
45780- 0 0 0 0 0 0 0 0 0 0 0 0
45781- 0 0 0 0 0 0 0 0 0 0 0 0
45782- 0 0 0 0 0 0 0 0 0 0 0 0
45783- 0 0 0 0 0 0 0 0 0 0 0 0
45784- 0 0 0 0 0 0 0 0 0 10 10 10
45785- 34 34 34 78 78 78 50 50 50 6 6 6
45786- 94 70 30 139 102 15 190 146 13 226 184 13
45787-232 200 30 232 195 16 215 174 15 190 146 13
45788-168 122 10 192 133 9 210 150 10 213 154 11
45789-202 150 34 182 157 106 101 98 89 2 2 6
45790- 2 2 6 78 78 78 116 116 116 58 58 58
45791- 2 2 6 22 22 22 90 90 90 46 46 46
45792- 18 18 18 6 6 6 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 0 0 0 0 0 0
45796- 0 0 0 0 0 0 0 0 0 0 0 0
45797- 0 0 0 0 0 0 0 0 0 0 0 0
45798- 0 0 0 0 0 0 0 0 0 0 0 0
45799- 0 0 0 0 0 0 0 0 0 0 0 0
45800- 0 0 0 0 0 0 0 0 0 0 0 0
45801- 0 0 0 0 0 0 0 0 0 0 0 0
45802- 0 0 0 0 0 0 0 0 0 0 0 0
45803- 0 0 0 0 0 0 0 0 0 0 0 0
45804- 0 0 0 0 0 0 0 0 0 10 10 10
45805- 38 38 38 86 86 86 50 50 50 6 6 6
45806-128 128 128 174 154 114 156 107 11 168 122 10
45807-198 155 10 184 144 12 197 138 11 200 144 11
45808-206 145 10 206 145 10 197 138 11 188 164 115
45809-195 195 195 198 198 198 174 174 174 14 14 14
45810- 2 2 6 22 22 22 116 116 116 116 116 116
45811- 22 22 22 2 2 6 74 74 74 70 70 70
45812- 30 30 30 10 10 10 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 0 0 0 0 0 0
45816- 0 0 0 0 0 0 0 0 0 0 0 0
45817- 0 0 0 0 0 0 0 0 0 0 0 0
45818- 0 0 0 0 0 0 0 0 0 0 0 0
45819- 0 0 0 0 0 0 0 0 0 0 0 0
45820- 0 0 0 0 0 0 0 0 0 0 0 0
45821- 0 0 0 0 0 0 0 0 0 0 0 0
45822- 0 0 0 0 0 0 0 0 0 0 0 0
45823- 0 0 0 0 0 0 0 0 0 0 0 0
45824- 0 0 0 0 0 0 6 6 6 18 18 18
45825- 50 50 50 101 101 101 26 26 26 10 10 10
45826-138 138 138 190 190 190 174 154 114 156 107 11
45827-197 138 11 200 144 11 197 138 11 192 133 9
45828-180 123 7 190 142 34 190 178 144 187 187 187
45829-202 202 202 221 221 221 214 214 214 66 66 66
45830- 2 2 6 2 2 6 50 50 50 62 62 62
45831- 6 6 6 2 2 6 10 10 10 90 90 90
45832- 50 50 50 18 18 18 6 6 6 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 0 0 0
45835- 0 0 0 0 0 0 0 0 0 0 0 0
45836- 0 0 0 0 0 0 0 0 0 0 0 0
45837- 0 0 0 0 0 0 0 0 0 0 0 0
45838- 0 0 0 0 0 0 0 0 0 0 0 0
45839- 0 0 0 0 0 0 0 0 0 0 0 0
45840- 0 0 0 0 0 0 0 0 0 0 0 0
45841- 0 0 0 0 0 0 0 0 0 0 0 0
45842- 0 0 0 0 0 0 0 0 0 0 0 0
45843- 0 0 0 0 0 0 0 0 0 0 0 0
45844- 0 0 0 0 0 0 10 10 10 34 34 34
45845- 74 74 74 74 74 74 2 2 6 6 6 6
45846-144 144 144 198 198 198 190 190 190 178 166 146
45847-154 121 60 156 107 11 156 107 11 168 124 44
45848-174 154 114 187 187 187 190 190 190 210 210 210
45849-246 246 246 253 253 253 253 253 253 182 182 182
45850- 6 6 6 2 2 6 2 2 6 2 2 6
45851- 2 2 6 2 2 6 2 2 6 62 62 62
45852- 74 74 74 34 34 34 14 14 14 0 0 0
45853- 0 0 0 0 0 0 0 0 0 0 0 0
45854- 0 0 0 0 0 0 0 0 0 0 0 0
45855- 0 0 0 0 0 0 0 0 0 0 0 0
45856- 0 0 0 0 0 0 0 0 0 0 0 0
45857- 0 0 0 0 0 0 0 0 0 0 0 0
45858- 0 0 0 0 0 0 0 0 0 0 0 0
45859- 0 0 0 0 0 0 0 0 0 0 0 0
45860- 0 0 0 0 0 0 0 0 0 0 0 0
45861- 0 0 0 0 0 0 0 0 0 0 0 0
45862- 0 0 0 0 0 0 0 0 0 0 0 0
45863- 0 0 0 0 0 0 0 0 0 0 0 0
45864- 0 0 0 10 10 10 22 22 22 54 54 54
45865- 94 94 94 18 18 18 2 2 6 46 46 46
45866-234 234 234 221 221 221 190 190 190 190 190 190
45867-190 190 190 187 187 187 187 187 187 190 190 190
45868-190 190 190 195 195 195 214 214 214 242 242 242
45869-253 253 253 253 253 253 253 253 253 253 253 253
45870- 82 82 82 2 2 6 2 2 6 2 2 6
45871- 2 2 6 2 2 6 2 2 6 14 14 14
45872- 86 86 86 54 54 54 22 22 22 6 6 6
45873- 0 0 0 0 0 0 0 0 0 0 0 0
45874- 0 0 0 0 0 0 0 0 0 0 0 0
45875- 0 0 0 0 0 0 0 0 0 0 0 0
45876- 0 0 0 0 0 0 0 0 0 0 0 0
45877- 0 0 0 0 0 0 0 0 0 0 0 0
45878- 0 0 0 0 0 0 0 0 0 0 0 0
45879- 0 0 0 0 0 0 0 0 0 0 0 0
45880- 0 0 0 0 0 0 0 0 0 0 0 0
45881- 0 0 0 0 0 0 0 0 0 0 0 0
45882- 0 0 0 0 0 0 0 0 0 0 0 0
45883- 0 0 0 0 0 0 0 0 0 0 0 0
45884- 6 6 6 18 18 18 46 46 46 90 90 90
45885- 46 46 46 18 18 18 6 6 6 182 182 182
45886-253 253 253 246 246 246 206 206 206 190 190 190
45887-190 190 190 190 190 190 190 190 190 190 190 190
45888-206 206 206 231 231 231 250 250 250 253 253 253
45889-253 253 253 253 253 253 253 253 253 253 253 253
45890-202 202 202 14 14 14 2 2 6 2 2 6
45891- 2 2 6 2 2 6 2 2 6 2 2 6
45892- 42 42 42 86 86 86 42 42 42 18 18 18
45893- 6 6 6 0 0 0 0 0 0 0 0 0
45894- 0 0 0 0 0 0 0 0 0 0 0 0
45895- 0 0 0 0 0 0 0 0 0 0 0 0
45896- 0 0 0 0 0 0 0 0 0 0 0 0
45897- 0 0 0 0 0 0 0 0 0 0 0 0
45898- 0 0 0 0 0 0 0 0 0 0 0 0
45899- 0 0 0 0 0 0 0 0 0 0 0 0
45900- 0 0 0 0 0 0 0 0 0 0 0 0
45901- 0 0 0 0 0 0 0 0 0 0 0 0
45902- 0 0 0 0 0 0 0 0 0 0 0 0
45903- 0 0 0 0 0 0 0 0 0 6 6 6
45904- 14 14 14 38 38 38 74 74 74 66 66 66
45905- 2 2 6 6 6 6 90 90 90 250 250 250
45906-253 253 253 253 253 253 238 238 238 198 198 198
45907-190 190 190 190 190 190 195 195 195 221 221 221
45908-246 246 246 253 253 253 253 253 253 253 253 253
45909-253 253 253 253 253 253 253 253 253 253 253 253
45910-253 253 253 82 82 82 2 2 6 2 2 6
45911- 2 2 6 2 2 6 2 2 6 2 2 6
45912- 2 2 6 78 78 78 70 70 70 34 34 34
45913- 14 14 14 6 6 6 0 0 0 0 0 0
45914- 0 0 0 0 0 0 0 0 0 0 0 0
45915- 0 0 0 0 0 0 0 0 0 0 0 0
45916- 0 0 0 0 0 0 0 0 0 0 0 0
45917- 0 0 0 0 0 0 0 0 0 0 0 0
45918- 0 0 0 0 0 0 0 0 0 0 0 0
45919- 0 0 0 0 0 0 0 0 0 0 0 0
45920- 0 0 0 0 0 0 0 0 0 0 0 0
45921- 0 0 0 0 0 0 0 0 0 0 0 0
45922- 0 0 0 0 0 0 0 0 0 0 0 0
45923- 0 0 0 0 0 0 0 0 0 14 14 14
45924- 34 34 34 66 66 66 78 78 78 6 6 6
45925- 2 2 6 18 18 18 218 218 218 253 253 253
45926-253 253 253 253 253 253 253 253 253 246 246 246
45927-226 226 226 231 231 231 246 246 246 253 253 253
45928-253 253 253 253 253 253 253 253 253 253 253 253
45929-253 253 253 253 253 253 253 253 253 253 253 253
45930-253 253 253 178 178 178 2 2 6 2 2 6
45931- 2 2 6 2 2 6 2 2 6 2 2 6
45932- 2 2 6 18 18 18 90 90 90 62 62 62
45933- 30 30 30 10 10 10 0 0 0 0 0 0
45934- 0 0 0 0 0 0 0 0 0 0 0 0
45935- 0 0 0 0 0 0 0 0 0 0 0 0
45936- 0 0 0 0 0 0 0 0 0 0 0 0
45937- 0 0 0 0 0 0 0 0 0 0 0 0
45938- 0 0 0 0 0 0 0 0 0 0 0 0
45939- 0 0 0 0 0 0 0 0 0 0 0 0
45940- 0 0 0 0 0 0 0 0 0 0 0 0
45941- 0 0 0 0 0 0 0 0 0 0 0 0
45942- 0 0 0 0 0 0 0 0 0 0 0 0
45943- 0 0 0 0 0 0 10 10 10 26 26 26
45944- 58 58 58 90 90 90 18 18 18 2 2 6
45945- 2 2 6 110 110 110 253 253 253 253 253 253
45946-253 253 253 253 253 253 253 253 253 253 253 253
45947-250 250 250 253 253 253 253 253 253 253 253 253
45948-253 253 253 253 253 253 253 253 253 253 253 253
45949-253 253 253 253 253 253 253 253 253 253 253 253
45950-253 253 253 231 231 231 18 18 18 2 2 6
45951- 2 2 6 2 2 6 2 2 6 2 2 6
45952- 2 2 6 2 2 6 18 18 18 94 94 94
45953- 54 54 54 26 26 26 10 10 10 0 0 0
45954- 0 0 0 0 0 0 0 0 0 0 0 0
45955- 0 0 0 0 0 0 0 0 0 0 0 0
45956- 0 0 0 0 0 0 0 0 0 0 0 0
45957- 0 0 0 0 0 0 0 0 0 0 0 0
45958- 0 0 0 0 0 0 0 0 0 0 0 0
45959- 0 0 0 0 0 0 0 0 0 0 0 0
45960- 0 0 0 0 0 0 0 0 0 0 0 0
45961- 0 0 0 0 0 0 0 0 0 0 0 0
45962- 0 0 0 0 0 0 0 0 0 0 0 0
45963- 0 0 0 6 6 6 22 22 22 50 50 50
45964- 90 90 90 26 26 26 2 2 6 2 2 6
45965- 14 14 14 195 195 195 250 250 250 253 253 253
45966-253 253 253 253 253 253 253 253 253 253 253 253
45967-253 253 253 253 253 253 253 253 253 253 253 253
45968-253 253 253 253 253 253 253 253 253 253 253 253
45969-253 253 253 253 253 253 253 253 253 253 253 253
45970-250 250 250 242 242 242 54 54 54 2 2 6
45971- 2 2 6 2 2 6 2 2 6 2 2 6
45972- 2 2 6 2 2 6 2 2 6 38 38 38
45973- 86 86 86 50 50 50 22 22 22 6 6 6
45974- 0 0 0 0 0 0 0 0 0 0 0 0
45975- 0 0 0 0 0 0 0 0 0 0 0 0
45976- 0 0 0 0 0 0 0 0 0 0 0 0
45977- 0 0 0 0 0 0 0 0 0 0 0 0
45978- 0 0 0 0 0 0 0 0 0 0 0 0
45979- 0 0 0 0 0 0 0 0 0 0 0 0
45980- 0 0 0 0 0 0 0 0 0 0 0 0
45981- 0 0 0 0 0 0 0 0 0 0 0 0
45982- 0 0 0 0 0 0 0 0 0 0 0 0
45983- 6 6 6 14 14 14 38 38 38 82 82 82
45984- 34 34 34 2 2 6 2 2 6 2 2 6
45985- 42 42 42 195 195 195 246 246 246 253 253 253
45986-253 253 253 253 253 253 253 253 253 250 250 250
45987-242 242 242 242 242 242 250 250 250 253 253 253
45988-253 253 253 253 253 253 253 253 253 253 253 253
45989-253 253 253 250 250 250 246 246 246 238 238 238
45990-226 226 226 231 231 231 101 101 101 6 6 6
45991- 2 2 6 2 2 6 2 2 6 2 2 6
45992- 2 2 6 2 2 6 2 2 6 2 2 6
45993- 38 38 38 82 82 82 42 42 42 14 14 14
45994- 6 6 6 0 0 0 0 0 0 0 0 0
45995- 0 0 0 0 0 0 0 0 0 0 0 0
45996- 0 0 0 0 0 0 0 0 0 0 0 0
45997- 0 0 0 0 0 0 0 0 0 0 0 0
45998- 0 0 0 0 0 0 0 0 0 0 0 0
45999- 0 0 0 0 0 0 0 0 0 0 0 0
46000- 0 0 0 0 0 0 0 0 0 0 0 0
46001- 0 0 0 0 0 0 0 0 0 0 0 0
46002- 0 0 0 0 0 0 0 0 0 0 0 0
46003- 10 10 10 26 26 26 62 62 62 66 66 66
46004- 2 2 6 2 2 6 2 2 6 6 6 6
46005- 70 70 70 170 170 170 206 206 206 234 234 234
46006-246 246 246 250 250 250 250 250 250 238 238 238
46007-226 226 226 231 231 231 238 238 238 250 250 250
46008-250 250 250 250 250 250 246 246 246 231 231 231
46009-214 214 214 206 206 206 202 202 202 202 202 202
46010-198 198 198 202 202 202 182 182 182 18 18 18
46011- 2 2 6 2 2 6 2 2 6 2 2 6
46012- 2 2 6 2 2 6 2 2 6 2 2 6
46013- 2 2 6 62 62 62 66 66 66 30 30 30
46014- 10 10 10 0 0 0 0 0 0 0 0 0
46015- 0 0 0 0 0 0 0 0 0 0 0 0
46016- 0 0 0 0 0 0 0 0 0 0 0 0
46017- 0 0 0 0 0 0 0 0 0 0 0 0
46018- 0 0 0 0 0 0 0 0 0 0 0 0
46019- 0 0 0 0 0 0 0 0 0 0 0 0
46020- 0 0 0 0 0 0 0 0 0 0 0 0
46021- 0 0 0 0 0 0 0 0 0 0 0 0
46022- 0 0 0 0 0 0 0 0 0 0 0 0
46023- 14 14 14 42 42 42 82 82 82 18 18 18
46024- 2 2 6 2 2 6 2 2 6 10 10 10
46025- 94 94 94 182 182 182 218 218 218 242 242 242
46026-250 250 250 253 253 253 253 253 253 250 250 250
46027-234 234 234 253 253 253 253 253 253 253 253 253
46028-253 253 253 253 253 253 253 253 253 246 246 246
46029-238 238 238 226 226 226 210 210 210 202 202 202
46030-195 195 195 195 195 195 210 210 210 158 158 158
46031- 6 6 6 14 14 14 50 50 50 14 14 14
46032- 2 2 6 2 2 6 2 2 6 2 2 6
46033- 2 2 6 6 6 6 86 86 86 46 46 46
46034- 18 18 18 6 6 6 0 0 0 0 0 0
46035- 0 0 0 0 0 0 0 0 0 0 0 0
46036- 0 0 0 0 0 0 0 0 0 0 0 0
46037- 0 0 0 0 0 0 0 0 0 0 0 0
46038- 0 0 0 0 0 0 0 0 0 0 0 0
46039- 0 0 0 0 0 0 0 0 0 0 0 0
46040- 0 0 0 0 0 0 0 0 0 0 0 0
46041- 0 0 0 0 0 0 0 0 0 0 0 0
46042- 0 0 0 0 0 0 0 0 0 6 6 6
46043- 22 22 22 54 54 54 70 70 70 2 2 6
46044- 2 2 6 10 10 10 2 2 6 22 22 22
46045-166 166 166 231 231 231 250 250 250 253 253 253
46046-253 253 253 253 253 253 253 253 253 250 250 250
46047-242 242 242 253 253 253 253 253 253 253 253 253
46048-253 253 253 253 253 253 253 253 253 253 253 253
46049-253 253 253 253 253 253 253 253 253 246 246 246
46050-231 231 231 206 206 206 198 198 198 226 226 226
46051- 94 94 94 2 2 6 6 6 6 38 38 38
46052- 30 30 30 2 2 6 2 2 6 2 2 6
46053- 2 2 6 2 2 6 62 62 62 66 66 66
46054- 26 26 26 10 10 10 0 0 0 0 0 0
46055- 0 0 0 0 0 0 0 0 0 0 0 0
46056- 0 0 0 0 0 0 0 0 0 0 0 0
46057- 0 0 0 0 0 0 0 0 0 0 0 0
46058- 0 0 0 0 0 0 0 0 0 0 0 0
46059- 0 0 0 0 0 0 0 0 0 0 0 0
46060- 0 0 0 0 0 0 0 0 0 0 0 0
46061- 0 0 0 0 0 0 0 0 0 0 0 0
46062- 0 0 0 0 0 0 0 0 0 10 10 10
46063- 30 30 30 74 74 74 50 50 50 2 2 6
46064- 26 26 26 26 26 26 2 2 6 106 106 106
46065-238 238 238 253 253 253 253 253 253 253 253 253
46066-253 253 253 253 253 253 253 253 253 253 253 253
46067-253 253 253 253 253 253 253 253 253 253 253 253
46068-253 253 253 253 253 253 253 253 253 253 253 253
46069-253 253 253 253 253 253 253 253 253 253 253 253
46070-253 253 253 246 246 246 218 218 218 202 202 202
46071-210 210 210 14 14 14 2 2 6 2 2 6
46072- 30 30 30 22 22 22 2 2 6 2 2 6
46073- 2 2 6 2 2 6 18 18 18 86 86 86
46074- 42 42 42 14 14 14 0 0 0 0 0 0
46075- 0 0 0 0 0 0 0 0 0 0 0 0
46076- 0 0 0 0 0 0 0 0 0 0 0 0
46077- 0 0 0 0 0 0 0 0 0 0 0 0
46078- 0 0 0 0 0 0 0 0 0 0 0 0
46079- 0 0 0 0 0 0 0 0 0 0 0 0
46080- 0 0 0 0 0 0 0 0 0 0 0 0
46081- 0 0 0 0 0 0 0 0 0 0 0 0
46082- 0 0 0 0 0 0 0 0 0 14 14 14
46083- 42 42 42 90 90 90 22 22 22 2 2 6
46084- 42 42 42 2 2 6 18 18 18 218 218 218
46085-253 253 253 253 253 253 253 253 253 253 253 253
46086-253 253 253 253 253 253 253 253 253 253 253 253
46087-253 253 253 253 253 253 253 253 253 253 253 253
46088-253 253 253 253 253 253 253 253 253 253 253 253
46089-253 253 253 253 253 253 253 253 253 253 253 253
46090-253 253 253 253 253 253 250 250 250 221 221 221
46091-218 218 218 101 101 101 2 2 6 14 14 14
46092- 18 18 18 38 38 38 10 10 10 2 2 6
46093- 2 2 6 2 2 6 2 2 6 78 78 78
46094- 58 58 58 22 22 22 6 6 6 0 0 0
46095- 0 0 0 0 0 0 0 0 0 0 0 0
46096- 0 0 0 0 0 0 0 0 0 0 0 0
46097- 0 0 0 0 0 0 0 0 0 0 0 0
46098- 0 0 0 0 0 0 0 0 0 0 0 0
46099- 0 0 0 0 0 0 0 0 0 0 0 0
46100- 0 0 0 0 0 0 0 0 0 0 0 0
46101- 0 0 0 0 0 0 0 0 0 0 0 0
46102- 0 0 0 0 0 0 6 6 6 18 18 18
46103- 54 54 54 82 82 82 2 2 6 26 26 26
46104- 22 22 22 2 2 6 123 123 123 253 253 253
46105-253 253 253 253 253 253 253 253 253 253 253 253
46106-253 253 253 253 253 253 253 253 253 253 253 253
46107-253 253 253 253 253 253 253 253 253 253 253 253
46108-253 253 253 253 253 253 253 253 253 253 253 253
46109-253 253 253 253 253 253 253 253 253 253 253 253
46110-253 253 253 253 253 253 253 253 253 250 250 250
46111-238 238 238 198 198 198 6 6 6 38 38 38
46112- 58 58 58 26 26 26 38 38 38 2 2 6
46113- 2 2 6 2 2 6 2 2 6 46 46 46
46114- 78 78 78 30 30 30 10 10 10 0 0 0
46115- 0 0 0 0 0 0 0 0 0 0 0 0
46116- 0 0 0 0 0 0 0 0 0 0 0 0
46117- 0 0 0 0 0 0 0 0 0 0 0 0
46118- 0 0 0 0 0 0 0 0 0 0 0 0
46119- 0 0 0 0 0 0 0 0 0 0 0 0
46120- 0 0 0 0 0 0 0 0 0 0 0 0
46121- 0 0 0 0 0 0 0 0 0 0 0 0
46122- 0 0 0 0 0 0 10 10 10 30 30 30
46123- 74 74 74 58 58 58 2 2 6 42 42 42
46124- 2 2 6 22 22 22 231 231 231 253 253 253
46125-253 253 253 253 253 253 253 253 253 253 253 253
46126-253 253 253 253 253 253 253 253 253 250 250 250
46127-253 253 253 253 253 253 253 253 253 253 253 253
46128-253 253 253 253 253 253 253 253 253 253 253 253
46129-253 253 253 253 253 253 253 253 253 253 253 253
46130-253 253 253 253 253 253 253 253 253 253 253 253
46131-253 253 253 246 246 246 46 46 46 38 38 38
46132- 42 42 42 14 14 14 38 38 38 14 14 14
46133- 2 2 6 2 2 6 2 2 6 6 6 6
46134- 86 86 86 46 46 46 14 14 14 0 0 0
46135- 0 0 0 0 0 0 0 0 0 0 0 0
46136- 0 0 0 0 0 0 0 0 0 0 0 0
46137- 0 0 0 0 0 0 0 0 0 0 0 0
46138- 0 0 0 0 0 0 0 0 0 0 0 0
46139- 0 0 0 0 0 0 0 0 0 0 0 0
46140- 0 0 0 0 0 0 0 0 0 0 0 0
46141- 0 0 0 0 0 0 0 0 0 0 0 0
46142- 0 0 0 6 6 6 14 14 14 42 42 42
46143- 90 90 90 18 18 18 18 18 18 26 26 26
46144- 2 2 6 116 116 116 253 253 253 253 253 253
46145-253 253 253 253 253 253 253 253 253 253 253 253
46146-253 253 253 253 253 253 250 250 250 238 238 238
46147-253 253 253 253 253 253 253 253 253 253 253 253
46148-253 253 253 253 253 253 253 253 253 253 253 253
46149-253 253 253 253 253 253 253 253 253 253 253 253
46150-253 253 253 253 253 253 253 253 253 253 253 253
46151-253 253 253 253 253 253 94 94 94 6 6 6
46152- 2 2 6 2 2 6 10 10 10 34 34 34
46153- 2 2 6 2 2 6 2 2 6 2 2 6
46154- 74 74 74 58 58 58 22 22 22 6 6 6
46155- 0 0 0 0 0 0 0 0 0 0 0 0
46156- 0 0 0 0 0 0 0 0 0 0 0 0
46157- 0 0 0 0 0 0 0 0 0 0 0 0
46158- 0 0 0 0 0 0 0 0 0 0 0 0
46159- 0 0 0 0 0 0 0 0 0 0 0 0
46160- 0 0 0 0 0 0 0 0 0 0 0 0
46161- 0 0 0 0 0 0 0 0 0 0 0 0
46162- 0 0 0 10 10 10 26 26 26 66 66 66
46163- 82 82 82 2 2 6 38 38 38 6 6 6
46164- 14 14 14 210 210 210 253 253 253 253 253 253
46165-253 253 253 253 253 253 253 253 253 253 253 253
46166-253 253 253 253 253 253 246 246 246 242 242 242
46167-253 253 253 253 253 253 253 253 253 253 253 253
46168-253 253 253 253 253 253 253 253 253 253 253 253
46169-253 253 253 253 253 253 253 253 253 253 253 253
46170-253 253 253 253 253 253 253 253 253 253 253 253
46171-253 253 253 253 253 253 144 144 144 2 2 6
46172- 2 2 6 2 2 6 2 2 6 46 46 46
46173- 2 2 6 2 2 6 2 2 6 2 2 6
46174- 42 42 42 74 74 74 30 30 30 10 10 10
46175- 0 0 0 0 0 0 0 0 0 0 0 0
46176- 0 0 0 0 0 0 0 0 0 0 0 0
46177- 0 0 0 0 0 0 0 0 0 0 0 0
46178- 0 0 0 0 0 0 0 0 0 0 0 0
46179- 0 0 0 0 0 0 0 0 0 0 0 0
46180- 0 0 0 0 0 0 0 0 0 0 0 0
46181- 0 0 0 0 0 0 0 0 0 0 0 0
46182- 6 6 6 14 14 14 42 42 42 90 90 90
46183- 26 26 26 6 6 6 42 42 42 2 2 6
46184- 74 74 74 250 250 250 253 253 253 253 253 253
46185-253 253 253 253 253 253 253 253 253 253 253 253
46186-253 253 253 253 253 253 242 242 242 242 242 242
46187-253 253 253 253 253 253 253 253 253 253 253 253
46188-253 253 253 253 253 253 253 253 253 253 253 253
46189-253 253 253 253 253 253 253 253 253 253 253 253
46190-253 253 253 253 253 253 253 253 253 253 253 253
46191-253 253 253 253 253 253 182 182 182 2 2 6
46192- 2 2 6 2 2 6 2 2 6 46 46 46
46193- 2 2 6 2 2 6 2 2 6 2 2 6
46194- 10 10 10 86 86 86 38 38 38 10 10 10
46195- 0 0 0 0 0 0 0 0 0 0 0 0
46196- 0 0 0 0 0 0 0 0 0 0 0 0
46197- 0 0 0 0 0 0 0 0 0 0 0 0
46198- 0 0 0 0 0 0 0 0 0 0 0 0
46199- 0 0 0 0 0 0 0 0 0 0 0 0
46200- 0 0 0 0 0 0 0 0 0 0 0 0
46201- 0 0 0 0 0 0 0 0 0 0 0 0
46202- 10 10 10 26 26 26 66 66 66 82 82 82
46203- 2 2 6 22 22 22 18 18 18 2 2 6
46204-149 149 149 253 253 253 253 253 253 253 253 253
46205-253 253 253 253 253 253 253 253 253 253 253 253
46206-253 253 253 253 253 253 234 234 234 242 242 242
46207-253 253 253 253 253 253 253 253 253 253 253 253
46208-253 253 253 253 253 253 253 253 253 253 253 253
46209-253 253 253 253 253 253 253 253 253 253 253 253
46210-253 253 253 253 253 253 253 253 253 253 253 253
46211-253 253 253 253 253 253 206 206 206 2 2 6
46212- 2 2 6 2 2 6 2 2 6 38 38 38
46213- 2 2 6 2 2 6 2 2 6 2 2 6
46214- 6 6 6 86 86 86 46 46 46 14 14 14
46215- 0 0 0 0 0 0 0 0 0 0 0 0
46216- 0 0 0 0 0 0 0 0 0 0 0 0
46217- 0 0 0 0 0 0 0 0 0 0 0 0
46218- 0 0 0 0 0 0 0 0 0 0 0 0
46219- 0 0 0 0 0 0 0 0 0 0 0 0
46220- 0 0 0 0 0 0 0 0 0 0 0 0
46221- 0 0 0 0 0 0 0 0 0 6 6 6
46222- 18 18 18 46 46 46 86 86 86 18 18 18
46223- 2 2 6 34 34 34 10 10 10 6 6 6
46224-210 210 210 253 253 253 253 253 253 253 253 253
46225-253 253 253 253 253 253 253 253 253 253 253 253
46226-253 253 253 253 253 253 234 234 234 242 242 242
46227-253 253 253 253 253 253 253 253 253 253 253 253
46228-253 253 253 253 253 253 253 253 253 253 253 253
46229-253 253 253 253 253 253 253 253 253 253 253 253
46230-253 253 253 253 253 253 253 253 253 253 253 253
46231-253 253 253 253 253 253 221 221 221 6 6 6
46232- 2 2 6 2 2 6 6 6 6 30 30 30
46233- 2 2 6 2 2 6 2 2 6 2 2 6
46234- 2 2 6 82 82 82 54 54 54 18 18 18
46235- 6 6 6 0 0 0 0 0 0 0 0 0
46236- 0 0 0 0 0 0 0 0 0 0 0 0
46237- 0 0 0 0 0 0 0 0 0 0 0 0
46238- 0 0 0 0 0 0 0 0 0 0 0 0
46239- 0 0 0 0 0 0 0 0 0 0 0 0
46240- 0 0 0 0 0 0 0 0 0 0 0 0
46241- 0 0 0 0 0 0 0 0 0 10 10 10
46242- 26 26 26 66 66 66 62 62 62 2 2 6
46243- 2 2 6 38 38 38 10 10 10 26 26 26
46244-238 238 238 253 253 253 253 253 253 253 253 253
46245-253 253 253 253 253 253 253 253 253 253 253 253
46246-253 253 253 253 253 253 231 231 231 238 238 238
46247-253 253 253 253 253 253 253 253 253 253 253 253
46248-253 253 253 253 253 253 253 253 253 253 253 253
46249-253 253 253 253 253 253 253 253 253 253 253 253
46250-253 253 253 253 253 253 253 253 253 253 253 253
46251-253 253 253 253 253 253 231 231 231 6 6 6
46252- 2 2 6 2 2 6 10 10 10 30 30 30
46253- 2 2 6 2 2 6 2 2 6 2 2 6
46254- 2 2 6 66 66 66 58 58 58 22 22 22
46255- 6 6 6 0 0 0 0 0 0 0 0 0
46256- 0 0 0 0 0 0 0 0 0 0 0 0
46257- 0 0 0 0 0 0 0 0 0 0 0 0
46258- 0 0 0 0 0 0 0 0 0 0 0 0
46259- 0 0 0 0 0 0 0 0 0 0 0 0
46260- 0 0 0 0 0 0 0 0 0 0 0 0
46261- 0 0 0 0 0 0 0 0 0 10 10 10
46262- 38 38 38 78 78 78 6 6 6 2 2 6
46263- 2 2 6 46 46 46 14 14 14 42 42 42
46264-246 246 246 253 253 253 253 253 253 253 253 253
46265-253 253 253 253 253 253 253 253 253 253 253 253
46266-253 253 253 253 253 253 231 231 231 242 242 242
46267-253 253 253 253 253 253 253 253 253 253 253 253
46268-253 253 253 253 253 253 253 253 253 253 253 253
46269-253 253 253 253 253 253 253 253 253 253 253 253
46270-253 253 253 253 253 253 253 253 253 253 253 253
46271-253 253 253 253 253 253 234 234 234 10 10 10
46272- 2 2 6 2 2 6 22 22 22 14 14 14
46273- 2 2 6 2 2 6 2 2 6 2 2 6
46274- 2 2 6 66 66 66 62 62 62 22 22 22
46275- 6 6 6 0 0 0 0 0 0 0 0 0
46276- 0 0 0 0 0 0 0 0 0 0 0 0
46277- 0 0 0 0 0 0 0 0 0 0 0 0
46278- 0 0 0 0 0 0 0 0 0 0 0 0
46279- 0 0 0 0 0 0 0 0 0 0 0 0
46280- 0 0 0 0 0 0 0 0 0 0 0 0
46281- 0 0 0 0 0 0 6 6 6 18 18 18
46282- 50 50 50 74 74 74 2 2 6 2 2 6
46283- 14 14 14 70 70 70 34 34 34 62 62 62
46284-250 250 250 253 253 253 253 253 253 253 253 253
46285-253 253 253 253 253 253 253 253 253 253 253 253
46286-253 253 253 253 253 253 231 231 231 246 246 246
46287-253 253 253 253 253 253 253 253 253 253 253 253
46288-253 253 253 253 253 253 253 253 253 253 253 253
46289-253 253 253 253 253 253 253 253 253 253 253 253
46290-253 253 253 253 253 253 253 253 253 253 253 253
46291-253 253 253 253 253 253 234 234 234 14 14 14
46292- 2 2 6 2 2 6 30 30 30 2 2 6
46293- 2 2 6 2 2 6 2 2 6 2 2 6
46294- 2 2 6 66 66 66 62 62 62 22 22 22
46295- 6 6 6 0 0 0 0 0 0 0 0 0
46296- 0 0 0 0 0 0 0 0 0 0 0 0
46297- 0 0 0 0 0 0 0 0 0 0 0 0
46298- 0 0 0 0 0 0 0 0 0 0 0 0
46299- 0 0 0 0 0 0 0 0 0 0 0 0
46300- 0 0 0 0 0 0 0 0 0 0 0 0
46301- 0 0 0 0 0 0 6 6 6 18 18 18
46302- 54 54 54 62 62 62 2 2 6 2 2 6
46303- 2 2 6 30 30 30 46 46 46 70 70 70
46304-250 250 250 253 253 253 253 253 253 253 253 253
46305-253 253 253 253 253 253 253 253 253 253 253 253
46306-253 253 253 253 253 253 231 231 231 246 246 246
46307-253 253 253 253 253 253 253 253 253 253 253 253
46308-253 253 253 253 253 253 253 253 253 253 253 253
46309-253 253 253 253 253 253 253 253 253 253 253 253
46310-253 253 253 253 253 253 253 253 253 253 253 253
46311-253 253 253 253 253 253 226 226 226 10 10 10
46312- 2 2 6 6 6 6 30 30 30 2 2 6
46313- 2 2 6 2 2 6 2 2 6 2 2 6
46314- 2 2 6 66 66 66 58 58 58 22 22 22
46315- 6 6 6 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 0 0 0
46318- 0 0 0 0 0 0 0 0 0 0 0 0
46319- 0 0 0 0 0 0 0 0 0 0 0 0
46320- 0 0 0 0 0 0 0 0 0 0 0 0
46321- 0 0 0 0 0 0 6 6 6 22 22 22
46322- 58 58 58 62 62 62 2 2 6 2 2 6
46323- 2 2 6 2 2 6 30 30 30 78 78 78
46324-250 250 250 253 253 253 253 253 253 253 253 253
46325-253 253 253 253 253 253 253 253 253 253 253 253
46326-253 253 253 253 253 253 231 231 231 246 246 246
46327-253 253 253 253 253 253 253 253 253 253 253 253
46328-253 253 253 253 253 253 253 253 253 253 253 253
46329-253 253 253 253 253 253 253 253 253 253 253 253
46330-253 253 253 253 253 253 253 253 253 253 253 253
46331-253 253 253 253 253 253 206 206 206 2 2 6
46332- 22 22 22 34 34 34 18 14 6 22 22 22
46333- 26 26 26 18 18 18 6 6 6 2 2 6
46334- 2 2 6 82 82 82 54 54 54 18 18 18
46335- 6 6 6 0 0 0 0 0 0 0 0 0
46336- 0 0 0 0 0 0 0 0 0 0 0 0
46337- 0 0 0 0 0 0 0 0 0 0 0 0
46338- 0 0 0 0 0 0 0 0 0 0 0 0
46339- 0 0 0 0 0 0 0 0 0 0 0 0
46340- 0 0 0 0 0 0 0 0 0 0 0 0
46341- 0 0 0 0 0 0 6 6 6 26 26 26
46342- 62 62 62 106 106 106 74 54 14 185 133 11
46343-210 162 10 121 92 8 6 6 6 62 62 62
46344-238 238 238 253 253 253 253 253 253 253 253 253
46345-253 253 253 253 253 253 253 253 253 253 253 253
46346-253 253 253 253 253 253 231 231 231 246 246 246
46347-253 253 253 253 253 253 253 253 253 253 253 253
46348-253 253 253 253 253 253 253 253 253 253 253 253
46349-253 253 253 253 253 253 253 253 253 253 253 253
46350-253 253 253 253 253 253 253 253 253 253 253 253
46351-253 253 253 253 253 253 158 158 158 18 18 18
46352- 14 14 14 2 2 6 2 2 6 2 2 6
46353- 6 6 6 18 18 18 66 66 66 38 38 38
46354- 6 6 6 94 94 94 50 50 50 18 18 18
46355- 6 6 6 0 0 0 0 0 0 0 0 0
46356- 0 0 0 0 0 0 0 0 0 0 0 0
46357- 0 0 0 0 0 0 0 0 0 0 0 0
46358- 0 0 0 0 0 0 0 0 0 0 0 0
46359- 0 0 0 0 0 0 0 0 0 0 0 0
46360- 0 0 0 0 0 0 0 0 0 6 6 6
46361- 10 10 10 10 10 10 18 18 18 38 38 38
46362- 78 78 78 142 134 106 216 158 10 242 186 14
46363-246 190 14 246 190 14 156 118 10 10 10 10
46364- 90 90 90 238 238 238 253 253 253 253 253 253
46365-253 253 253 253 253 253 253 253 253 253 253 253
46366-253 253 253 253 253 253 231 231 231 250 250 250
46367-253 253 253 253 253 253 253 253 253 253 253 253
46368-253 253 253 253 253 253 253 253 253 253 253 253
46369-253 253 253 253 253 253 253 253 253 253 253 253
46370-253 253 253 253 253 253 253 253 253 246 230 190
46371-238 204 91 238 204 91 181 142 44 37 26 9
46372- 2 2 6 2 2 6 2 2 6 2 2 6
46373- 2 2 6 2 2 6 38 38 38 46 46 46
46374- 26 26 26 106 106 106 54 54 54 18 18 18
46375- 6 6 6 0 0 0 0 0 0 0 0 0
46376- 0 0 0 0 0 0 0 0 0 0 0 0
46377- 0 0 0 0 0 0 0 0 0 0 0 0
46378- 0 0 0 0 0 0 0 0 0 0 0 0
46379- 0 0 0 0 0 0 0 0 0 0 0 0
46380- 0 0 0 6 6 6 14 14 14 22 22 22
46381- 30 30 30 38 38 38 50 50 50 70 70 70
46382-106 106 106 190 142 34 226 170 11 242 186 14
46383-246 190 14 246 190 14 246 190 14 154 114 10
46384- 6 6 6 74 74 74 226 226 226 253 253 253
46385-253 253 253 253 253 253 253 253 253 253 253 253
46386-253 253 253 253 253 253 231 231 231 250 250 250
46387-253 253 253 253 253 253 253 253 253 253 253 253
46388-253 253 253 253 253 253 253 253 253 253 253 253
46389-253 253 253 253 253 253 253 253 253 253 253 253
46390-253 253 253 253 253 253 253 253 253 228 184 62
46391-241 196 14 241 208 19 232 195 16 38 30 10
46392- 2 2 6 2 2 6 2 2 6 2 2 6
46393- 2 2 6 6 6 6 30 30 30 26 26 26
46394-203 166 17 154 142 90 66 66 66 26 26 26
46395- 6 6 6 0 0 0 0 0 0 0 0 0
46396- 0 0 0 0 0 0 0 0 0 0 0 0
46397- 0 0 0 0 0 0 0 0 0 0 0 0
46398- 0 0 0 0 0 0 0 0 0 0 0 0
46399- 0 0 0 0 0 0 0 0 0 0 0 0
46400- 6 6 6 18 18 18 38 38 38 58 58 58
46401- 78 78 78 86 86 86 101 101 101 123 123 123
46402-175 146 61 210 150 10 234 174 13 246 186 14
46403-246 190 14 246 190 14 246 190 14 238 190 10
46404-102 78 10 2 2 6 46 46 46 198 198 198
46405-253 253 253 253 253 253 253 253 253 253 253 253
46406-253 253 253 253 253 253 234 234 234 242 242 242
46407-253 253 253 253 253 253 253 253 253 253 253 253
46408-253 253 253 253 253 253 253 253 253 253 253 253
46409-253 253 253 253 253 253 253 253 253 253 253 253
46410-253 253 253 253 253 253 253 253 253 224 178 62
46411-242 186 14 241 196 14 210 166 10 22 18 6
46412- 2 2 6 2 2 6 2 2 6 2 2 6
46413- 2 2 6 2 2 6 6 6 6 121 92 8
46414-238 202 15 232 195 16 82 82 82 34 34 34
46415- 10 10 10 0 0 0 0 0 0 0 0 0
46416- 0 0 0 0 0 0 0 0 0 0 0 0
46417- 0 0 0 0 0 0 0 0 0 0 0 0
46418- 0 0 0 0 0 0 0 0 0 0 0 0
46419- 0 0 0 0 0 0 0 0 0 0 0 0
46420- 14 14 14 38 38 38 70 70 70 154 122 46
46421-190 142 34 200 144 11 197 138 11 197 138 11
46422-213 154 11 226 170 11 242 186 14 246 190 14
46423-246 190 14 246 190 14 246 190 14 246 190 14
46424-225 175 15 46 32 6 2 2 6 22 22 22
46425-158 158 158 250 250 250 253 253 253 253 253 253
46426-253 253 253 253 253 253 253 253 253 253 253 253
46427-253 253 253 253 253 253 253 253 253 253 253 253
46428-253 253 253 253 253 253 253 253 253 253 253 253
46429-253 253 253 253 253 253 253 253 253 253 253 253
46430-253 253 253 250 250 250 242 242 242 224 178 62
46431-239 182 13 236 186 11 213 154 11 46 32 6
46432- 2 2 6 2 2 6 2 2 6 2 2 6
46433- 2 2 6 2 2 6 61 42 6 225 175 15
46434-238 190 10 236 186 11 112 100 78 42 42 42
46435- 14 14 14 0 0 0 0 0 0 0 0 0
46436- 0 0 0 0 0 0 0 0 0 0 0 0
46437- 0 0 0 0 0 0 0 0 0 0 0 0
46438- 0 0 0 0 0 0 0 0 0 0 0 0
46439- 0 0 0 0 0 0 0 0 0 6 6 6
46440- 22 22 22 54 54 54 154 122 46 213 154 11
46441-226 170 11 230 174 11 226 170 11 226 170 11
46442-236 178 12 242 186 14 246 190 14 246 190 14
46443-246 190 14 246 190 14 246 190 14 246 190 14
46444-241 196 14 184 144 12 10 10 10 2 2 6
46445- 6 6 6 116 116 116 242 242 242 253 253 253
46446-253 253 253 253 253 253 253 253 253 253 253 253
46447-253 253 253 253 253 253 253 253 253 253 253 253
46448-253 253 253 253 253 253 253 253 253 253 253 253
46449-253 253 253 253 253 253 253 253 253 253 253 253
46450-253 253 253 231 231 231 198 198 198 214 170 54
46451-236 178 12 236 178 12 210 150 10 137 92 6
46452- 18 14 6 2 2 6 2 2 6 2 2 6
46453- 6 6 6 70 47 6 200 144 11 236 178 12
46454-239 182 13 239 182 13 124 112 88 58 58 58
46455- 22 22 22 6 6 6 0 0 0 0 0 0
46456- 0 0 0 0 0 0 0 0 0 0 0 0
46457- 0 0 0 0 0 0 0 0 0 0 0 0
46458- 0 0 0 0 0 0 0 0 0 0 0 0
46459- 0 0 0 0 0 0 0 0 0 10 10 10
46460- 30 30 30 70 70 70 180 133 36 226 170 11
46461-239 182 13 242 186 14 242 186 14 246 186 14
46462-246 190 14 246 190 14 246 190 14 246 190 14
46463-246 190 14 246 190 14 246 190 14 246 190 14
46464-246 190 14 232 195 16 98 70 6 2 2 6
46465- 2 2 6 2 2 6 66 66 66 221 221 221
46466-253 253 253 253 253 253 253 253 253 253 253 253
46467-253 253 253 253 253 253 253 253 253 253 253 253
46468-253 253 253 253 253 253 253 253 253 253 253 253
46469-253 253 253 253 253 253 253 253 253 253 253 253
46470-253 253 253 206 206 206 198 198 198 214 166 58
46471-230 174 11 230 174 11 216 158 10 192 133 9
46472-163 110 8 116 81 8 102 78 10 116 81 8
46473-167 114 7 197 138 11 226 170 11 239 182 13
46474-242 186 14 242 186 14 162 146 94 78 78 78
46475- 34 34 34 14 14 14 6 6 6 0 0 0
46476- 0 0 0 0 0 0 0 0 0 0 0 0
46477- 0 0 0 0 0 0 0 0 0 0 0 0
46478- 0 0 0 0 0 0 0 0 0 0 0 0
46479- 0 0 0 0 0 0 0 0 0 6 6 6
46480- 30 30 30 78 78 78 190 142 34 226 170 11
46481-239 182 13 246 190 14 246 190 14 246 190 14
46482-246 190 14 246 190 14 246 190 14 246 190 14
46483-246 190 14 246 190 14 246 190 14 246 190 14
46484-246 190 14 241 196 14 203 166 17 22 18 6
46485- 2 2 6 2 2 6 2 2 6 38 38 38
46486-218 218 218 253 253 253 253 253 253 253 253 253
46487-253 253 253 253 253 253 253 253 253 253 253 253
46488-253 253 253 253 253 253 253 253 253 253 253 253
46489-253 253 253 253 253 253 253 253 253 253 253 253
46490-250 250 250 206 206 206 198 198 198 202 162 69
46491-226 170 11 236 178 12 224 166 10 210 150 10
46492-200 144 11 197 138 11 192 133 9 197 138 11
46493-210 150 10 226 170 11 242 186 14 246 190 14
46494-246 190 14 246 186 14 225 175 15 124 112 88
46495- 62 62 62 30 30 30 14 14 14 6 6 6
46496- 0 0 0 0 0 0 0 0 0 0 0 0
46497- 0 0 0 0 0 0 0 0 0 0 0 0
46498- 0 0 0 0 0 0 0 0 0 0 0 0
46499- 0 0 0 0 0 0 0 0 0 10 10 10
46500- 30 30 30 78 78 78 174 135 50 224 166 10
46501-239 182 13 246 190 14 246 190 14 246 190 14
46502-246 190 14 246 190 14 246 190 14 246 190 14
46503-246 190 14 246 190 14 246 190 14 246 190 14
46504-246 190 14 246 190 14 241 196 14 139 102 15
46505- 2 2 6 2 2 6 2 2 6 2 2 6
46506- 78 78 78 250 250 250 253 253 253 253 253 253
46507-253 253 253 253 253 253 253 253 253 253 253 253
46508-253 253 253 253 253 253 253 253 253 253 253 253
46509-253 253 253 253 253 253 253 253 253 253 253 253
46510-250 250 250 214 214 214 198 198 198 190 150 46
46511-219 162 10 236 178 12 234 174 13 224 166 10
46512-216 158 10 213 154 11 213 154 11 216 158 10
46513-226 170 11 239 182 13 246 190 14 246 190 14
46514-246 190 14 246 190 14 242 186 14 206 162 42
46515-101 101 101 58 58 58 30 30 30 14 14 14
46516- 6 6 6 0 0 0 0 0 0 0 0 0
46517- 0 0 0 0 0 0 0 0 0 0 0 0
46518- 0 0 0 0 0 0 0 0 0 0 0 0
46519- 0 0 0 0 0 0 0 0 0 10 10 10
46520- 30 30 30 74 74 74 174 135 50 216 158 10
46521-236 178 12 246 190 14 246 190 14 246 190 14
46522-246 190 14 246 190 14 246 190 14 246 190 14
46523-246 190 14 246 190 14 246 190 14 246 190 14
46524-246 190 14 246 190 14 241 196 14 226 184 13
46525- 61 42 6 2 2 6 2 2 6 2 2 6
46526- 22 22 22 238 238 238 253 253 253 253 253 253
46527-253 253 253 253 253 253 253 253 253 253 253 253
46528-253 253 253 253 253 253 253 253 253 253 253 253
46529-253 253 253 253 253 253 253 253 253 253 253 253
46530-253 253 253 226 226 226 187 187 187 180 133 36
46531-216 158 10 236 178 12 239 182 13 236 178 12
46532-230 174 11 226 170 11 226 170 11 230 174 11
46533-236 178 12 242 186 14 246 190 14 246 190 14
46534-246 190 14 246 190 14 246 186 14 239 182 13
46535-206 162 42 106 106 106 66 66 66 34 34 34
46536- 14 14 14 6 6 6 0 0 0 0 0 0
46537- 0 0 0 0 0 0 0 0 0 0 0 0
46538- 0 0 0 0 0 0 0 0 0 0 0 0
46539- 0 0 0 0 0 0 0 0 0 6 6 6
46540- 26 26 26 70 70 70 163 133 67 213 154 11
46541-236 178 12 246 190 14 246 190 14 246 190 14
46542-246 190 14 246 190 14 246 190 14 246 190 14
46543-246 190 14 246 190 14 246 190 14 246 190 14
46544-246 190 14 246 190 14 246 190 14 241 196 14
46545-190 146 13 18 14 6 2 2 6 2 2 6
46546- 46 46 46 246 246 246 253 253 253 253 253 253
46547-253 253 253 253 253 253 253 253 253 253 253 253
46548-253 253 253 253 253 253 253 253 253 253 253 253
46549-253 253 253 253 253 253 253 253 253 253 253 253
46550-253 253 253 221 221 221 86 86 86 156 107 11
46551-216 158 10 236 178 12 242 186 14 246 186 14
46552-242 186 14 239 182 13 239 182 13 242 186 14
46553-242 186 14 246 186 14 246 190 14 246 190 14
46554-246 190 14 246 190 14 246 190 14 246 190 14
46555-242 186 14 225 175 15 142 122 72 66 66 66
46556- 30 30 30 10 10 10 0 0 0 0 0 0
46557- 0 0 0 0 0 0 0 0 0 0 0 0
46558- 0 0 0 0 0 0 0 0 0 0 0 0
46559- 0 0 0 0 0 0 0 0 0 6 6 6
46560- 26 26 26 70 70 70 163 133 67 210 150 10
46561-236 178 12 246 190 14 246 190 14 246 190 14
46562-246 190 14 246 190 14 246 190 14 246 190 14
46563-246 190 14 246 190 14 246 190 14 246 190 14
46564-246 190 14 246 190 14 246 190 14 246 190 14
46565-232 195 16 121 92 8 34 34 34 106 106 106
46566-221 221 221 253 253 253 253 253 253 253 253 253
46567-253 253 253 253 253 253 253 253 253 253 253 253
46568-253 253 253 253 253 253 253 253 253 253 253 253
46569-253 253 253 253 253 253 253 253 253 253 253 253
46570-242 242 242 82 82 82 18 14 6 163 110 8
46571-216 158 10 236 178 12 242 186 14 246 190 14
46572-246 190 14 246 190 14 246 190 14 246 190 14
46573-246 190 14 246 190 14 246 190 14 246 190 14
46574-246 190 14 246 190 14 246 190 14 246 190 14
46575-246 190 14 246 190 14 242 186 14 163 133 67
46576- 46 46 46 18 18 18 6 6 6 0 0 0
46577- 0 0 0 0 0 0 0 0 0 0 0 0
46578- 0 0 0 0 0 0 0 0 0 0 0 0
46579- 0 0 0 0 0 0 0 0 0 10 10 10
46580- 30 30 30 78 78 78 163 133 67 210 150 10
46581-236 178 12 246 186 14 246 190 14 246 190 14
46582-246 190 14 246 190 14 246 190 14 246 190 14
46583-246 190 14 246 190 14 246 190 14 246 190 14
46584-246 190 14 246 190 14 246 190 14 246 190 14
46585-241 196 14 215 174 15 190 178 144 253 253 253
46586-253 253 253 253 253 253 253 253 253 253 253 253
46587-253 253 253 253 253 253 253 253 253 253 253 253
46588-253 253 253 253 253 253 253 253 253 253 253 253
46589-253 253 253 253 253 253 253 253 253 218 218 218
46590- 58 58 58 2 2 6 22 18 6 167 114 7
46591-216 158 10 236 178 12 246 186 14 246 190 14
46592-246 190 14 246 190 14 246 190 14 246 190 14
46593-246 190 14 246 190 14 246 190 14 246 190 14
46594-246 190 14 246 190 14 246 190 14 246 190 14
46595-246 190 14 246 186 14 242 186 14 190 150 46
46596- 54 54 54 22 22 22 6 6 6 0 0 0
46597- 0 0 0 0 0 0 0 0 0 0 0 0
46598- 0 0 0 0 0 0 0 0 0 0 0 0
46599- 0 0 0 0 0 0 0 0 0 14 14 14
46600- 38 38 38 86 86 86 180 133 36 213 154 11
46601-236 178 12 246 186 14 246 190 14 246 190 14
46602-246 190 14 246 190 14 246 190 14 246 190 14
46603-246 190 14 246 190 14 246 190 14 246 190 14
46604-246 190 14 246 190 14 246 190 14 246 190 14
46605-246 190 14 232 195 16 190 146 13 214 214 214
46606-253 253 253 253 253 253 253 253 253 253 253 253
46607-253 253 253 253 253 253 253 253 253 253 253 253
46608-253 253 253 253 253 253 253 253 253 253 253 253
46609-253 253 253 250 250 250 170 170 170 26 26 26
46610- 2 2 6 2 2 6 37 26 9 163 110 8
46611-219 162 10 239 182 13 246 186 14 246 190 14
46612-246 190 14 246 190 14 246 190 14 246 190 14
46613-246 190 14 246 190 14 246 190 14 246 190 14
46614-246 190 14 246 190 14 246 190 14 246 190 14
46615-246 186 14 236 178 12 224 166 10 142 122 72
46616- 46 46 46 18 18 18 6 6 6 0 0 0
46617- 0 0 0 0 0 0 0 0 0 0 0 0
46618- 0 0 0 0 0 0 0 0 0 0 0 0
46619- 0 0 0 0 0 0 6 6 6 18 18 18
46620- 50 50 50 109 106 95 192 133 9 224 166 10
46621-242 186 14 246 190 14 246 190 14 246 190 14
46622-246 190 14 246 190 14 246 190 14 246 190 14
46623-246 190 14 246 190 14 246 190 14 246 190 14
46624-246 190 14 246 190 14 246 190 14 246 190 14
46625-242 186 14 226 184 13 210 162 10 142 110 46
46626-226 226 226 253 253 253 253 253 253 253 253 253
46627-253 253 253 253 253 253 253 253 253 253 253 253
46628-253 253 253 253 253 253 253 253 253 253 253 253
46629-198 198 198 66 66 66 2 2 6 2 2 6
46630- 2 2 6 2 2 6 50 34 6 156 107 11
46631-219 162 10 239 182 13 246 186 14 246 190 14
46632-246 190 14 246 190 14 246 190 14 246 190 14
46633-246 190 14 246 190 14 246 190 14 246 190 14
46634-246 190 14 246 190 14 246 190 14 242 186 14
46635-234 174 13 213 154 11 154 122 46 66 66 66
46636- 30 30 30 10 10 10 0 0 0 0 0 0
46637- 0 0 0 0 0 0 0 0 0 0 0 0
46638- 0 0 0 0 0 0 0 0 0 0 0 0
46639- 0 0 0 0 0 0 6 6 6 22 22 22
46640- 58 58 58 154 121 60 206 145 10 234 174 13
46641-242 186 14 246 186 14 246 190 14 246 190 14
46642-246 190 14 246 190 14 246 190 14 246 190 14
46643-246 190 14 246 190 14 246 190 14 246 190 14
46644-246 190 14 246 190 14 246 190 14 246 190 14
46645-246 186 14 236 178 12 210 162 10 163 110 8
46646- 61 42 6 138 138 138 218 218 218 250 250 250
46647-253 253 253 253 253 253 253 253 253 250 250 250
46648-242 242 242 210 210 210 144 144 144 66 66 66
46649- 6 6 6 2 2 6 2 2 6 2 2 6
46650- 2 2 6 2 2 6 61 42 6 163 110 8
46651-216 158 10 236 178 12 246 190 14 246 190 14
46652-246 190 14 246 190 14 246 190 14 246 190 14
46653-246 190 14 246 190 14 246 190 14 246 190 14
46654-246 190 14 239 182 13 230 174 11 216 158 10
46655-190 142 34 124 112 88 70 70 70 38 38 38
46656- 18 18 18 6 6 6 0 0 0 0 0 0
46657- 0 0 0 0 0 0 0 0 0 0 0 0
46658- 0 0 0 0 0 0 0 0 0 0 0 0
46659- 0 0 0 0 0 0 6 6 6 22 22 22
46660- 62 62 62 168 124 44 206 145 10 224 166 10
46661-236 178 12 239 182 13 242 186 14 242 186 14
46662-246 186 14 246 190 14 246 190 14 246 190 14
46663-246 190 14 246 190 14 246 190 14 246 190 14
46664-246 190 14 246 190 14 246 190 14 246 190 14
46665-246 190 14 236 178 12 216 158 10 175 118 6
46666- 80 54 7 2 2 6 6 6 6 30 30 30
46667- 54 54 54 62 62 62 50 50 50 38 38 38
46668- 14 14 14 2 2 6 2 2 6 2 2 6
46669- 2 2 6 2 2 6 2 2 6 2 2 6
46670- 2 2 6 6 6 6 80 54 7 167 114 7
46671-213 154 11 236 178 12 246 190 14 246 190 14
46672-246 190 14 246 190 14 246 190 14 246 190 14
46673-246 190 14 242 186 14 239 182 13 239 182 13
46674-230 174 11 210 150 10 174 135 50 124 112 88
46675- 82 82 82 54 54 54 34 34 34 18 18 18
46676- 6 6 6 0 0 0 0 0 0 0 0 0
46677- 0 0 0 0 0 0 0 0 0 0 0 0
46678- 0 0 0 0 0 0 0 0 0 0 0 0
46679- 0 0 0 0 0 0 6 6 6 18 18 18
46680- 50 50 50 158 118 36 192 133 9 200 144 11
46681-216 158 10 219 162 10 224 166 10 226 170 11
46682-230 174 11 236 178 12 239 182 13 239 182 13
46683-242 186 14 246 186 14 246 190 14 246 190 14
46684-246 190 14 246 190 14 246 190 14 246 190 14
46685-246 186 14 230 174 11 210 150 10 163 110 8
46686-104 69 6 10 10 10 2 2 6 2 2 6
46687- 2 2 6 2 2 6 2 2 6 2 2 6
46688- 2 2 6 2 2 6 2 2 6 2 2 6
46689- 2 2 6 2 2 6 2 2 6 2 2 6
46690- 2 2 6 6 6 6 91 60 6 167 114 7
46691-206 145 10 230 174 11 242 186 14 246 190 14
46692-246 190 14 246 190 14 246 186 14 242 186 14
46693-239 182 13 230 174 11 224 166 10 213 154 11
46694-180 133 36 124 112 88 86 86 86 58 58 58
46695- 38 38 38 22 22 22 10 10 10 6 6 6
46696- 0 0 0 0 0 0 0 0 0 0 0 0
46697- 0 0 0 0 0 0 0 0 0 0 0 0
46698- 0 0 0 0 0 0 0 0 0 0 0 0
46699- 0 0 0 0 0 0 0 0 0 14 14 14
46700- 34 34 34 70 70 70 138 110 50 158 118 36
46701-167 114 7 180 123 7 192 133 9 197 138 11
46702-200 144 11 206 145 10 213 154 11 219 162 10
46703-224 166 10 230 174 11 239 182 13 242 186 14
46704-246 186 14 246 186 14 246 186 14 246 186 14
46705-239 182 13 216 158 10 185 133 11 152 99 6
46706-104 69 6 18 14 6 2 2 6 2 2 6
46707- 2 2 6 2 2 6 2 2 6 2 2 6
46708- 2 2 6 2 2 6 2 2 6 2 2 6
46709- 2 2 6 2 2 6 2 2 6 2 2 6
46710- 2 2 6 6 6 6 80 54 7 152 99 6
46711-192 133 9 219 162 10 236 178 12 239 182 13
46712-246 186 14 242 186 14 239 182 13 236 178 12
46713-224 166 10 206 145 10 192 133 9 154 121 60
46714- 94 94 94 62 62 62 42 42 42 22 22 22
46715- 14 14 14 6 6 6 0 0 0 0 0 0
46716- 0 0 0 0 0 0 0 0 0 0 0 0
46717- 0 0 0 0 0 0 0 0 0 0 0 0
46718- 0 0 0 0 0 0 0 0 0 0 0 0
46719- 0 0 0 0 0 0 0 0 0 6 6 6
46720- 18 18 18 34 34 34 58 58 58 78 78 78
46721-101 98 89 124 112 88 142 110 46 156 107 11
46722-163 110 8 167 114 7 175 118 6 180 123 7
46723-185 133 11 197 138 11 210 150 10 219 162 10
46724-226 170 11 236 178 12 236 178 12 234 174 13
46725-219 162 10 197 138 11 163 110 8 130 83 6
46726- 91 60 6 10 10 10 2 2 6 2 2 6
46727- 18 18 18 38 38 38 38 38 38 38 38 38
46728- 38 38 38 38 38 38 38 38 38 38 38 38
46729- 38 38 38 38 38 38 26 26 26 2 2 6
46730- 2 2 6 6 6 6 70 47 6 137 92 6
46731-175 118 6 200 144 11 219 162 10 230 174 11
46732-234 174 13 230 174 11 219 162 10 210 150 10
46733-192 133 9 163 110 8 124 112 88 82 82 82
46734- 50 50 50 30 30 30 14 14 14 6 6 6
46735- 0 0 0 0 0 0 0 0 0 0 0 0
46736- 0 0 0 0 0 0 0 0 0 0 0 0
46737- 0 0 0 0 0 0 0 0 0 0 0 0
46738- 0 0 0 0 0 0 0 0 0 0 0 0
46739- 0 0 0 0 0 0 0 0 0 0 0 0
46740- 6 6 6 14 14 14 22 22 22 34 34 34
46741- 42 42 42 58 58 58 74 74 74 86 86 86
46742-101 98 89 122 102 70 130 98 46 121 87 25
46743-137 92 6 152 99 6 163 110 8 180 123 7
46744-185 133 11 197 138 11 206 145 10 200 144 11
46745-180 123 7 156 107 11 130 83 6 104 69 6
46746- 50 34 6 54 54 54 110 110 110 101 98 89
46747- 86 86 86 82 82 82 78 78 78 78 78 78
46748- 78 78 78 78 78 78 78 78 78 78 78 78
46749- 78 78 78 82 82 82 86 86 86 94 94 94
46750-106 106 106 101 101 101 86 66 34 124 80 6
46751-156 107 11 180 123 7 192 133 9 200 144 11
46752-206 145 10 200 144 11 192 133 9 175 118 6
46753-139 102 15 109 106 95 70 70 70 42 42 42
46754- 22 22 22 10 10 10 0 0 0 0 0 0
46755- 0 0 0 0 0 0 0 0 0 0 0 0
46756- 0 0 0 0 0 0 0 0 0 0 0 0
46757- 0 0 0 0 0 0 0 0 0 0 0 0
46758- 0 0 0 0 0 0 0 0 0 0 0 0
46759- 0 0 0 0 0 0 0 0 0 0 0 0
46760- 0 0 0 0 0 0 6 6 6 10 10 10
46761- 14 14 14 22 22 22 30 30 30 38 38 38
46762- 50 50 50 62 62 62 74 74 74 90 90 90
46763-101 98 89 112 100 78 121 87 25 124 80 6
46764-137 92 6 152 99 6 152 99 6 152 99 6
46765-138 86 6 124 80 6 98 70 6 86 66 30
46766-101 98 89 82 82 82 58 58 58 46 46 46
46767- 38 38 38 34 34 34 34 34 34 34 34 34
46768- 34 34 34 34 34 34 34 34 34 34 34 34
46769- 34 34 34 34 34 34 38 38 38 42 42 42
46770- 54 54 54 82 82 82 94 86 76 91 60 6
46771-134 86 6 156 107 11 167 114 7 175 118 6
46772-175 118 6 167 114 7 152 99 6 121 87 25
46773-101 98 89 62 62 62 34 34 34 18 18 18
46774- 6 6 6 0 0 0 0 0 0 0 0 0
46775- 0 0 0 0 0 0 0 0 0 0 0 0
46776- 0 0 0 0 0 0 0 0 0 0 0 0
46777- 0 0 0 0 0 0 0 0 0 0 0 0
46778- 0 0 0 0 0 0 0 0 0 0 0 0
46779- 0 0 0 0 0 0 0 0 0 0 0 0
46780- 0 0 0 0 0 0 0 0 0 0 0 0
46781- 0 0 0 6 6 6 6 6 6 10 10 10
46782- 18 18 18 22 22 22 30 30 30 42 42 42
46783- 50 50 50 66 66 66 86 86 86 101 98 89
46784-106 86 58 98 70 6 104 69 6 104 69 6
46785-104 69 6 91 60 6 82 62 34 90 90 90
46786- 62 62 62 38 38 38 22 22 22 14 14 14
46787- 10 10 10 10 10 10 10 10 10 10 10 10
46788- 10 10 10 10 10 10 6 6 6 10 10 10
46789- 10 10 10 10 10 10 10 10 10 14 14 14
46790- 22 22 22 42 42 42 70 70 70 89 81 66
46791- 80 54 7 104 69 6 124 80 6 137 92 6
46792-134 86 6 116 81 8 100 82 52 86 86 86
46793- 58 58 58 30 30 30 14 14 14 6 6 6
46794- 0 0 0 0 0 0 0 0 0 0 0 0
46795- 0 0 0 0 0 0 0 0 0 0 0 0
46796- 0 0 0 0 0 0 0 0 0 0 0 0
46797- 0 0 0 0 0 0 0 0 0 0 0 0
46798- 0 0 0 0 0 0 0 0 0 0 0 0
46799- 0 0 0 0 0 0 0 0 0 0 0 0
46800- 0 0 0 0 0 0 0 0 0 0 0 0
46801- 0 0 0 0 0 0 0 0 0 0 0 0
46802- 0 0 0 6 6 6 10 10 10 14 14 14
46803- 18 18 18 26 26 26 38 38 38 54 54 54
46804- 70 70 70 86 86 86 94 86 76 89 81 66
46805- 89 81 66 86 86 86 74 74 74 50 50 50
46806- 30 30 30 14 14 14 6 6 6 0 0 0
46807- 0 0 0 0 0 0 0 0 0 0 0 0
46808- 0 0 0 0 0 0 0 0 0 0 0 0
46809- 0 0 0 0 0 0 0 0 0 0 0 0
46810- 6 6 6 18 18 18 34 34 34 58 58 58
46811- 82 82 82 89 81 66 89 81 66 89 81 66
46812- 94 86 66 94 86 76 74 74 74 50 50 50
46813- 26 26 26 14 14 14 6 6 6 0 0 0
46814- 0 0 0 0 0 0 0 0 0 0 0 0
46815- 0 0 0 0 0 0 0 0 0 0 0 0
46816- 0 0 0 0 0 0 0 0 0 0 0 0
46817- 0 0 0 0 0 0 0 0 0 0 0 0
46818- 0 0 0 0 0 0 0 0 0 0 0 0
46819- 0 0 0 0 0 0 0 0 0 0 0 0
46820- 0 0 0 0 0 0 0 0 0 0 0 0
46821- 0 0 0 0 0 0 0 0 0 0 0 0
46822- 0 0 0 0 0 0 0 0 0 0 0 0
46823- 6 6 6 6 6 6 14 14 14 18 18 18
46824- 30 30 30 38 38 38 46 46 46 54 54 54
46825- 50 50 50 42 42 42 30 30 30 18 18 18
46826- 10 10 10 0 0 0 0 0 0 0 0 0
46827- 0 0 0 0 0 0 0 0 0 0 0 0
46828- 0 0 0 0 0 0 0 0 0 0 0 0
46829- 0 0 0 0 0 0 0 0 0 0 0 0
46830- 0 0 0 6 6 6 14 14 14 26 26 26
46831- 38 38 38 50 50 50 58 58 58 58 58 58
46832- 54 54 54 42 42 42 30 30 30 18 18 18
46833- 10 10 10 0 0 0 0 0 0 0 0 0
46834- 0 0 0 0 0 0 0 0 0 0 0 0
46835- 0 0 0 0 0 0 0 0 0 0 0 0
46836- 0 0 0 0 0 0 0 0 0 0 0 0
46837- 0 0 0 0 0 0 0 0 0 0 0 0
46838- 0 0 0 0 0 0 0 0 0 0 0 0
46839- 0 0 0 0 0 0 0 0 0 0 0 0
46840- 0 0 0 0 0 0 0 0 0 0 0 0
46841- 0 0 0 0 0 0 0 0 0 0 0 0
46842- 0 0 0 0 0 0 0 0 0 0 0 0
46843- 0 0 0 0 0 0 0 0 0 6 6 6
46844- 6 6 6 10 10 10 14 14 14 18 18 18
46845- 18 18 18 14 14 14 10 10 10 6 6 6
46846- 0 0 0 0 0 0 0 0 0 0 0 0
46847- 0 0 0 0 0 0 0 0 0 0 0 0
46848- 0 0 0 0 0 0 0 0 0 0 0 0
46849- 0 0 0 0 0 0 0 0 0 0 0 0
46850- 0 0 0 0 0 0 0 0 0 6 6 6
46851- 14 14 14 18 18 18 22 22 22 22 22 22
46852- 18 18 18 14 14 14 10 10 10 6 6 6
46853- 0 0 0 0 0 0 0 0 0 0 0 0
46854- 0 0 0 0 0 0 0 0 0 0 0 0
46855- 0 0 0 0 0 0 0 0 0 0 0 0
46856- 0 0 0 0 0 0 0 0 0 0 0 0
46857- 0 0 0 0 0 0 0 0 0 0 0 0
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46871+4 4 4 4 4 4
46872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46874+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46885+4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46888+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46898+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46899+4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46902+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46912+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46913+4 4 4 4 4 4
46914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46916+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46926+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46927+4 4 4 4 4 4
46928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46930+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46940+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46941+4 4 4 4 4 4
46942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46944+4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0
46947+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46951+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46952+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46953+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46954+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46955+4 4 4 4 4 4
46956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46958+4 4 4 4 4 4 4 4 4 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 2 2 2 0 0 0 3 4 3 26 28 28
46961+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46962+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46965+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46966+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46967+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46968+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46969+4 4 4 4 4 4
46970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46972+4 4 4 4 4 4 4 4 4 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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46975+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46976+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46979+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46980+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46981+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46982+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46983+4 4 4 4 4 4
46984+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46987+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46988+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46989+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46990+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46992+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46993+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46994+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46995+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46996+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46997+4 4 4 4 4 4
46998+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47001+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
47002+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
47003+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
47004+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
47005+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47006+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
47007+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
47008+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
47009+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
47010+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
47011+4 4 4 4 4 4
47012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47015+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
47016+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
47017+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
47018+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
47019+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47020+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
47021+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
47022+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
47023+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
47024+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
47025+4 4 4 4 4 4
47026+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47028+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
47029+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
47030+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
47031+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
47032+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
47033+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
47034+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
47035+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
47036+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
47037+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
47038+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
47039+4 4 4 4 4 4
47040+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47042+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
47043+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
47044+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
47045+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
47046+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
47047+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
47048+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
47049+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
47050+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
47051+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
47052+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
47053+4 4 4 4 4 4
47054+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47056+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
47057+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
47058+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
47059+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
47060+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
47061+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
47062+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
47063+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
47064+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
47065+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
47066+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
47067+4 4 4 4 4 4
47068+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47070+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
47071+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
47072+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
47073+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
47074+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
47075+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
47076+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
47077+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
47078+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
47079+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
47080+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
47081+4 4 4 4 4 4
47082+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47083+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
47084+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
47085+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
47086+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
47087+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
47088+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
47089+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
47090+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
47091+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
47092+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
47093+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
47094+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
47095+4 4 4 4 4 4
47096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47097+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
47098+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
47099+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
47100+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47101+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
47102+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
47103+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
47104+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
47105+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
47106+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
47107+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
47108+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
47109+0 0 0 4 4 4
47110+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47111+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
47112+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
47113+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
47114+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
47115+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
47116+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
47117+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
47118+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
47119+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
47120+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
47121+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
47122+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
47123+2 0 0 0 0 0
47124+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
47125+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
47126+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
47127+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
47128+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
47129+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
47130+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
47131+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
47132+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47133+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47134+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47135+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47136+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47137+37 38 37 0 0 0
47138+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47139+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47140+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47141+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47142+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47143+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47144+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47145+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47146+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47147+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47148+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47149+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47150+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47151+85 115 134 4 0 0
47152+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47153+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47154+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47155+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47156+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47157+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47158+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47159+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47160+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47161+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47162+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47163+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47164+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47165+60 73 81 4 0 0
47166+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47167+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47168+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47169+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47170+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47171+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47172+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47173+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47174+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47175+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47176+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47177+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47178+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47179+16 19 21 4 0 0
47180+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47181+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47182+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47183+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47184+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47185+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47186+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47187+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47188+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47189+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47190+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47191+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47192+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47193+4 0 0 4 3 3
47194+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47195+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47196+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47197+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47198+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47199+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47200+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47201+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47202+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47203+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47204+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47205+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47206+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47207+3 2 2 4 4 4
47208+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47209+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47210+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47211+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47212+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47213+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47214+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47215+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47216+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47217+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47218+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47219+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47220+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47221+4 4 4 4 4 4
47222+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47223+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47224+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47225+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47226+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47227+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47228+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47229+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47230+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47231+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47232+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47233+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47234+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47235+4 4 4 4 4 4
47236+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47237+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47238+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47239+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47240+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47241+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47242+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47243+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47244+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47245+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47246+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47247+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47248+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47249+5 5 5 5 5 5
47250+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47251+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47252+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47253+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47254+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47255+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47256+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47257+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47258+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47259+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47260+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47261+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47262+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47263+5 5 5 4 4 4
47264+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47265+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47266+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47267+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47268+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47269+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47270+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47271+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47272+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47273+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47274+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47275+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47277+4 4 4 4 4 4
47278+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47279+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47280+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47281+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47282+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47283+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47284+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47285+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47286+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47287+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47288+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47289+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47291+4 4 4 4 4 4
47292+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47293+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47294+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47295+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47296+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47297+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47298+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47299+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47300+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47301+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47302+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47305+4 4 4 4 4 4
47306+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47307+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47308+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47309+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47310+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47311+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47312+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47313+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47314+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47315+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47316+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47319+4 4 4 4 4 4
47320+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47321+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47322+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47323+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47324+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47325+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47326+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47327+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47328+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47329+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47330+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47333+4 4 4 4 4 4
47334+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47335+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47336+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47337+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47338+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47339+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47340+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47341+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47342+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47343+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47344+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47347+4 4 4 4 4 4
47348+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47349+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47350+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47351+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47352+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47353+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47354+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47355+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47356+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47357+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47358+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47361+4 4 4 4 4 4
47362+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47363+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47364+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47365+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47366+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47367+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47368+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47369+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47370+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47371+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47372+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47375+4 4 4 4 4 4
47376+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47377+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47378+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47379+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47380+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47381+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47382+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47383+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47384+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47385+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47386+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47389+4 4 4 4 4 4
47390+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47391+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47392+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47393+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47394+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47395+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47396+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47397+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47398+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47399+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47400+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47403+4 4 4 4 4 4
47404+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47405+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47406+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47407+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47408+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47409+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47410+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47411+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47412+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47413+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47414+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47417+4 4 4 4 4 4
47418+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47419+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47420+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47421+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47422+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47423+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47424+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47425+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47426+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47427+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47428+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47429+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
47432+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47433+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47434+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47435+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47436+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47437+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47438+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47439+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47440+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47441+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47442+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47443+4 4 4 4 4 4 4 4 4 4 4 4 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
47446+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47447+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47448+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47449+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47450+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47451+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47452+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47453+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47454+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47455+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47456+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47457+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47459+4 4 4 4 4 4
47460+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47461+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47462+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47463+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47464+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47465+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47466+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47467+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47468+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47469+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47470+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47471+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47473+4 4 4 4 4 4
47474+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47475+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47476+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47477+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47478+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47479+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47480+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47481+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47482+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47483+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47484+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47485+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47487+4 4 4 4 4 4
47488+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47489+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47490+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47491+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47492+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47493+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47494+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47495+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47496+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47497+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47498+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47499+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47501+4 4 4 4 4 4
47502+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47503+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47504+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47505+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47506+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47507+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47508+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47509+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47510+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47511+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47512+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47513+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47515+4 4 4 4 4 4
47516+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47517+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47518+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47519+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47520+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47521+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47522+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47523+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47524+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47525+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47526+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47527+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47529+4 4 4 4 4 4
47530+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47531+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47532+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47533+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47534+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47535+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47536+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47537+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47538+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47539+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47540+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47541+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47543+4 4 4 4 4 4
47544+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47545+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47546+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47547+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47548+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47549+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47550+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47551+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47552+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47553+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47554+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47557+4 4 4 4 4 4
47558+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47559+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47560+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47561+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47562+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47563+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47564+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47565+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47566+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47567+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47568+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47571+4 4 4 4 4 4
47572+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47573+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47574+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47575+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47576+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47577+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47578+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47579+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47580+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47581+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47582+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47585+4 4 4 4 4 4
47586+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47587+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47588+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47589+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47590+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47591+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47592+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47593+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47594+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47595+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47596+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47599+4 4 4 4 4 4
47600+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47601+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47602+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47603+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47604+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47605+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47606+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47607+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47608+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47609+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47610+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47613+4 4 4 4 4 4
47614+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47615+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47616+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47617+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47618+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47619+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47620+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47621+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47622+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47623+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47624+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47627+4 4 4 4 4 4
47628+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47629+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47630+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47631+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47632+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47633+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47634+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47635+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47636+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47637+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47638+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47641+4 4 4 4 4 4
47642+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47643+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47644+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47645+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47646+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47647+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47648+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47649+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47650+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47651+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47652+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47655+4 4 4 4 4 4
47656+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47657+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47658+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47659+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47660+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47661+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47662+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47663+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47664+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47665+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47666+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47669+4 4 4 4 4 4
47670+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47671+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47672+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47673+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47674+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47675+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47676+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47677+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47678+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47679+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47683+4 4 4 4 4 4
47684+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47685+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47686+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47687+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47688+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47689+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47690+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47691+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47692+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47693+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47697+4 4 4 4 4 4
47698+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47699+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47700+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47701+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47702+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47703+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47704+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47705+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47706+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47707+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47711+4 4 4 4 4 4
47712+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47713+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47714+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47715+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47716+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47717+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47718+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47719+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47720+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47721+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47725+4 4 4 4 4 4
47726+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47727+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47728+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47729+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47730+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47731+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47732+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47733+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47734+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47739+4 4 4 4 4 4
47740+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47741+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47742+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47743+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47744+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47745+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47746+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47747+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47748+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47753+4 4 4 4 4 4
47754+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47755+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47756+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47757+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47758+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47759+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47760+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47761+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47762+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47767+4 4 4 4 4 4
47768+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47769+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47770+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47771+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47772+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47773+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47774+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47775+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47781+4 4 4 4 4 4
47782+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47783+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47784+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47785+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47786+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47787+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47788+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47789+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47795+4 4 4 4 4 4
47796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47797+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47798+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47799+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47800+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47801+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47802+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47803+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47809+4 4 4 4 4 4
47810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47811+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47812+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47813+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47814+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47815+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47816+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47817+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47823+4 4 4 4 4 4
47824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47825+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47826+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47827+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47828+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47829+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47830+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47831+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47837+4 4 4 4 4 4
47838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47840+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47841+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47842+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47843+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47844+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47845+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47851+4 4 4 4 4 4
47852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47855+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47856+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47857+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47858+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47865+4 4 4 4 4 4
47866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47868+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47869+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47870+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47871+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47872+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47879+4 4 4 4 4 4
47880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47882+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47883+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47884+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47885+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47886+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47893+4 4 4 4 4 4
47894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47896+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47897+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47898+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47899+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47900+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47907+4 4 4 4 4 4
47908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47910+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47912+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47913+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47914+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47921+4 4 4 4 4 4
47922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47924+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47925+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47926+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47927+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47928+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47929+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47935+4 4 4 4 4 4
47936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47938+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47939+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47940+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47941+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47942+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47943+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47949+4 4 4 4 4 4
47950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47952+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47953+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47954+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47955+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47957+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47963+4 4 4 4 4 4
47964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47966+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47968+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47969+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47971+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47977+4 4 4 4 4 4
47978diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47979index fe92eed..106e085 100644
47980--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47981+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47982@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47983 struct mb862xxfb_par *par = info->par;
47984
47985 if (info->var.bits_per_pixel == 32) {
47986- info->fbops->fb_fillrect = cfb_fillrect;
47987- info->fbops->fb_copyarea = cfb_copyarea;
47988- info->fbops->fb_imageblit = cfb_imageblit;
47989+ pax_open_kernel();
47990+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47991+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47992+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47993+ pax_close_kernel();
47994 } else {
47995 outreg(disp, GC_L0EM, 3);
47996- info->fbops->fb_fillrect = mb86290fb_fillrect;
47997- info->fbops->fb_copyarea = mb86290fb_copyarea;
47998- info->fbops->fb_imageblit = mb86290fb_imageblit;
47999+ pax_open_kernel();
48000+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
48001+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
48002+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
48003+ pax_close_kernel();
48004 }
48005 outreg(draw, GDC_REG_DRAW_BASE, 0);
48006 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
48007diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
48008index ff22871..b129bed 100644
48009--- a/drivers/video/nvidia/nvidia.c
48010+++ b/drivers/video/nvidia/nvidia.c
48011@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
48012 info->fix.line_length = (info->var.xres_virtual *
48013 info->var.bits_per_pixel) >> 3;
48014 if (info->var.accel_flags) {
48015- info->fbops->fb_imageblit = nvidiafb_imageblit;
48016- info->fbops->fb_fillrect = nvidiafb_fillrect;
48017- info->fbops->fb_copyarea = nvidiafb_copyarea;
48018- info->fbops->fb_sync = nvidiafb_sync;
48019+ pax_open_kernel();
48020+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
48021+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
48022+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
48023+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
48024+ pax_close_kernel();
48025 info->pixmap.scan_align = 4;
48026 info->flags &= ~FBINFO_HWACCEL_DISABLED;
48027 info->flags |= FBINFO_READS_FAST;
48028 NVResetGraphics(info);
48029 } else {
48030- info->fbops->fb_imageblit = cfb_imageblit;
48031- info->fbops->fb_fillrect = cfb_fillrect;
48032- info->fbops->fb_copyarea = cfb_copyarea;
48033- info->fbops->fb_sync = NULL;
48034+ pax_open_kernel();
48035+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
48036+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
48037+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
48038+ *(void **)&info->fbops->fb_sync = NULL;
48039+ pax_close_kernel();
48040 info->pixmap.scan_align = 1;
48041 info->flags |= FBINFO_HWACCEL_DISABLED;
48042 info->flags &= ~FBINFO_READS_FAST;
48043@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
48044 info->pixmap.size = 8 * 1024;
48045 info->pixmap.flags = FB_PIXMAP_SYSTEM;
48046
48047- if (!hwcur)
48048- info->fbops->fb_cursor = NULL;
48049+ if (!hwcur) {
48050+ pax_open_kernel();
48051+ *(void **)&info->fbops->fb_cursor = NULL;
48052+ pax_close_kernel();
48053+ }
48054
48055 info->var.accel_flags = (!noaccel);
48056
48057diff --git a/drivers/video/output.c b/drivers/video/output.c
48058index 0d6f2cd..6285b97 100644
48059--- a/drivers/video/output.c
48060+++ b/drivers/video/output.c
48061@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
48062 new_dev->props = op;
48063 new_dev->dev.class = &video_output_class;
48064 new_dev->dev.parent = dev;
48065- dev_set_name(&new_dev->dev, name);
48066+ dev_set_name(&new_dev->dev, "%s", name);
48067 dev_set_drvdata(&new_dev->dev, devdata);
48068 ret_code = device_register(&new_dev->dev);
48069 if (ret_code) {
48070diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
48071index 05c2dc3..ea1f391 100644
48072--- a/drivers/video/s1d13xxxfb.c
48073+++ b/drivers/video/s1d13xxxfb.c
48074@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
48075
48076 switch(prod_id) {
48077 case S1D13506_PROD_ID: /* activate acceleration */
48078- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48079- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48080+ pax_open_kernel();
48081+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
48082+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
48083+ pax_close_kernel();
48084 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
48085 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
48086 break;
48087diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
48088index b2b33fc..f9f4658 100644
48089--- a/drivers/video/smscufx.c
48090+++ b/drivers/video/smscufx.c
48091@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
48092 fb_deferred_io_cleanup(info);
48093 kfree(info->fbdefio);
48094 info->fbdefio = NULL;
48095- info->fbops->fb_mmap = ufx_ops_mmap;
48096+ pax_open_kernel();
48097+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
48098+ pax_close_kernel();
48099 }
48100
48101 pr_debug("released /dev/fb%d user=%d count=%d",
48102diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
48103index ec03e72..f578436 100644
48104--- a/drivers/video/udlfb.c
48105+++ b/drivers/video/udlfb.c
48106@@ -623,11 +623,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
48107 dlfb_urb_completion(urb);
48108
48109 error:
48110- atomic_add(bytes_sent, &dev->bytes_sent);
48111- atomic_add(bytes_identical, &dev->bytes_identical);
48112- atomic_add(width*height*2, &dev->bytes_rendered);
48113+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48114+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48115+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
48116 end_cycles = get_cycles();
48117- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48118+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48119 >> 10)), /* Kcycles */
48120 &dev->cpu_kcycles_used);
48121
48122@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
48123 dlfb_urb_completion(urb);
48124
48125 error:
48126- atomic_add(bytes_sent, &dev->bytes_sent);
48127- atomic_add(bytes_identical, &dev->bytes_identical);
48128- atomic_add(bytes_rendered, &dev->bytes_rendered);
48129+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48130+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48131+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
48132 end_cycles = get_cycles();
48133- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48134+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48135 >> 10)), /* Kcycles */
48136 &dev->cpu_kcycles_used);
48137 }
48138@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48139 fb_deferred_io_cleanup(info);
48140 kfree(info->fbdefio);
48141 info->fbdefio = NULL;
48142- info->fbops->fb_mmap = dlfb_ops_mmap;
48143+ pax_open_kernel();
48144+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48145+ pax_close_kernel();
48146 }
48147
48148 pr_warn("released /dev/fb%d user=%d count=%d\n",
48149@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48150 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48151 struct dlfb_data *dev = fb_info->par;
48152 return snprintf(buf, PAGE_SIZE, "%u\n",
48153- atomic_read(&dev->bytes_rendered));
48154+ atomic_read_unchecked(&dev->bytes_rendered));
48155 }
48156
48157 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48158@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48159 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48160 struct dlfb_data *dev = fb_info->par;
48161 return snprintf(buf, PAGE_SIZE, "%u\n",
48162- atomic_read(&dev->bytes_identical));
48163+ atomic_read_unchecked(&dev->bytes_identical));
48164 }
48165
48166 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48167@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48168 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48169 struct dlfb_data *dev = fb_info->par;
48170 return snprintf(buf, PAGE_SIZE, "%u\n",
48171- atomic_read(&dev->bytes_sent));
48172+ atomic_read_unchecked(&dev->bytes_sent));
48173 }
48174
48175 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48176@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48177 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48178 struct dlfb_data *dev = fb_info->par;
48179 return snprintf(buf, PAGE_SIZE, "%u\n",
48180- atomic_read(&dev->cpu_kcycles_used));
48181+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48182 }
48183
48184 static ssize_t edid_show(
48185@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48186 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48187 struct dlfb_data *dev = fb_info->par;
48188
48189- atomic_set(&dev->bytes_rendered, 0);
48190- atomic_set(&dev->bytes_identical, 0);
48191- atomic_set(&dev->bytes_sent, 0);
48192- atomic_set(&dev->cpu_kcycles_used, 0);
48193+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48194+ atomic_set_unchecked(&dev->bytes_identical, 0);
48195+ atomic_set_unchecked(&dev->bytes_sent, 0);
48196+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48197
48198 return count;
48199 }
48200diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48201index e328a61..1b08ecb 100644
48202--- a/drivers/video/uvesafb.c
48203+++ b/drivers/video/uvesafb.c
48204@@ -19,6 +19,7 @@
48205 #include <linux/io.h>
48206 #include <linux/mutex.h>
48207 #include <linux/slab.h>
48208+#include <linux/moduleloader.h>
48209 #include <video/edid.h>
48210 #include <video/uvesafb.h>
48211 #ifdef CONFIG_X86
48212@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48213 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48214 par->pmi_setpal = par->ypan = 0;
48215 } else {
48216+
48217+#ifdef CONFIG_PAX_KERNEXEC
48218+#ifdef CONFIG_MODULES
48219+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48220+#endif
48221+ if (!par->pmi_code) {
48222+ par->pmi_setpal = par->ypan = 0;
48223+ return 0;
48224+ }
48225+#endif
48226+
48227 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48228 + task->t.regs.edi);
48229+
48230+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48231+ pax_open_kernel();
48232+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48233+ pax_close_kernel();
48234+
48235+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48236+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48237+#else
48238 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48239 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48240+#endif
48241+
48242 printk(KERN_INFO "uvesafb: protected mode interface info at "
48243 "%04x:%04x\n",
48244 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48245@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48246 par->ypan = ypan;
48247
48248 if (par->pmi_setpal || par->ypan) {
48249+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48250 if (__supported_pte_mask & _PAGE_NX) {
48251 par->pmi_setpal = par->ypan = 0;
48252 printk(KERN_WARNING "uvesafb: NX protection is actively."
48253 "We have better not to use the PMI.\n");
48254- } else {
48255+ } else
48256+#endif
48257 uvesafb_vbe_getpmi(task, par);
48258- }
48259 }
48260 #else
48261 /* The protected mode interface is not available on non-x86. */
48262@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48263 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48264
48265 /* Disable blanking if the user requested so. */
48266- if (!blank)
48267- info->fbops->fb_blank = NULL;
48268+ if (!blank) {
48269+ pax_open_kernel();
48270+ *(void **)&info->fbops->fb_blank = NULL;
48271+ pax_close_kernel();
48272+ }
48273
48274 /*
48275 * Find out how much IO memory is required for the mode with
48276@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48277 info->flags = FBINFO_FLAG_DEFAULT |
48278 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48279
48280- if (!par->ypan)
48281- info->fbops->fb_pan_display = NULL;
48282+ if (!par->ypan) {
48283+ pax_open_kernel();
48284+ *(void **)&info->fbops->fb_pan_display = NULL;
48285+ pax_close_kernel();
48286+ }
48287 }
48288
48289 static void uvesafb_init_mtrr(struct fb_info *info)
48290@@ -1836,6 +1866,11 @@ out:
48291 if (par->vbe_modes)
48292 kfree(par->vbe_modes);
48293
48294+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48295+ if (par->pmi_code)
48296+ module_free_exec(NULL, par->pmi_code);
48297+#endif
48298+
48299 framebuffer_release(info);
48300 return err;
48301 }
48302@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48303 kfree(par->vbe_state_orig);
48304 if (par->vbe_state_saved)
48305 kfree(par->vbe_state_saved);
48306+
48307+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48308+ if (par->pmi_code)
48309+ module_free_exec(NULL, par->pmi_code);
48310+#endif
48311+
48312 }
48313
48314 framebuffer_release(info);
48315diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48316index 501b340..d80aa17 100644
48317--- a/drivers/video/vesafb.c
48318+++ b/drivers/video/vesafb.c
48319@@ -9,6 +9,7 @@
48320 */
48321
48322 #include <linux/module.h>
48323+#include <linux/moduleloader.h>
48324 #include <linux/kernel.h>
48325 #include <linux/errno.h>
48326 #include <linux/string.h>
48327@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48328 static int vram_total __initdata; /* Set total amount of memory */
48329 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48330 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48331-static void (*pmi_start)(void) __read_mostly;
48332-static void (*pmi_pal) (void) __read_mostly;
48333+static void (*pmi_start)(void) __read_only;
48334+static void (*pmi_pal) (void) __read_only;
48335 static int depth __read_mostly;
48336 static int vga_compat __read_mostly;
48337 /* --------------------------------------------------------------------- */
48338@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48339 unsigned int size_vmode;
48340 unsigned int size_remap;
48341 unsigned int size_total;
48342+ void *pmi_code = NULL;
48343
48344 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48345 return -ENODEV;
48346@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48347 size_remap = size_total;
48348 vesafb_fix.smem_len = size_remap;
48349
48350-#ifndef __i386__
48351- screen_info.vesapm_seg = 0;
48352-#endif
48353-
48354 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48355 printk(KERN_WARNING
48356 "vesafb: cannot reserve video memory at 0x%lx\n",
48357@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48358 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48359 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48360
48361+#ifdef __i386__
48362+
48363+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48364+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48365+ if (!pmi_code)
48366+#elif !defined(CONFIG_PAX_KERNEXEC)
48367+ if (0)
48368+#endif
48369+
48370+#endif
48371+ screen_info.vesapm_seg = 0;
48372+
48373 if (screen_info.vesapm_seg) {
48374- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48375- screen_info.vesapm_seg,screen_info.vesapm_off);
48376+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48377+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48378 }
48379
48380 if (screen_info.vesapm_seg < 0xc000)
48381@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48382
48383 if (ypan || pmi_setpal) {
48384 unsigned short *pmi_base;
48385+
48386 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48387- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48388- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48389+
48390+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48391+ pax_open_kernel();
48392+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48393+#else
48394+ pmi_code = pmi_base;
48395+#endif
48396+
48397+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48398+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48399+
48400+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48401+ pmi_start = ktva_ktla(pmi_start);
48402+ pmi_pal = ktva_ktla(pmi_pal);
48403+ pax_close_kernel();
48404+#endif
48405+
48406 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48407 if (pmi_base[3]) {
48408 printk(KERN_INFO "vesafb: pmi: ports = ");
48409@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48410 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48411 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48412
48413- if (!ypan)
48414- info->fbops->fb_pan_display = NULL;
48415+ if (!ypan) {
48416+ pax_open_kernel();
48417+ *(void **)&info->fbops->fb_pan_display = NULL;
48418+ pax_close_kernel();
48419+ }
48420
48421 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48422 err = -ENOMEM;
48423@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48424 info->node, info->fix.id);
48425 return 0;
48426 err:
48427+
48428+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48429+ module_free_exec(NULL, pmi_code);
48430+#endif
48431+
48432 if (info->screen_base)
48433 iounmap(info->screen_base);
48434 framebuffer_release(info);
48435diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48436index 88714ae..16c2e11 100644
48437--- a/drivers/video/via/via_clock.h
48438+++ b/drivers/video/via/via_clock.h
48439@@ -56,7 +56,7 @@ struct via_clock {
48440
48441 void (*set_engine_pll_state)(u8 state);
48442 void (*set_engine_pll)(struct via_pll_config config);
48443-};
48444+} __no_const;
48445
48446
48447 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48448diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48449index fef20db..d28b1ab 100644
48450--- a/drivers/xen/xenfs/xenstored.c
48451+++ b/drivers/xen/xenfs/xenstored.c
48452@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48453 static int xsd_kva_open(struct inode *inode, struct file *file)
48454 {
48455 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48456+#ifdef CONFIG_GRKERNSEC_HIDESYM
48457+ NULL);
48458+#else
48459 xen_store_interface);
48460+#endif
48461+
48462 if (!file->private_data)
48463 return -ENOMEM;
48464 return 0;
48465diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
48466index 055562c..fdfb10d 100644
48467--- a/fs/9p/vfs_addr.c
48468+++ b/fs/9p/vfs_addr.c
48469@@ -186,7 +186,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
48470
48471 retval = v9fs_file_write_internal(inode,
48472 v9inode->writeback_fid,
48473- (__force const char __user *)buffer,
48474+ (const char __force_user *)buffer,
48475 len, &offset, 0);
48476 if (retval > 0)
48477 retval = 0;
48478diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48479index d86edc8..40ff2fb 100644
48480--- a/fs/9p/vfs_inode.c
48481+++ b/fs/9p/vfs_inode.c
48482@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48483 void
48484 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48485 {
48486- char *s = nd_get_link(nd);
48487+ const char *s = nd_get_link(nd);
48488
48489 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48490 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48491diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48492index 370b24c..ff0be7b 100644
48493--- a/fs/Kconfig.binfmt
48494+++ b/fs/Kconfig.binfmt
48495@@ -103,7 +103,7 @@ config HAVE_AOUT
48496
48497 config BINFMT_AOUT
48498 tristate "Kernel support for a.out and ECOFF binaries"
48499- depends on HAVE_AOUT
48500+ depends on HAVE_AOUT && BROKEN
48501 ---help---
48502 A.out (Assembler.OUTput) is a set of formats for libraries and
48503 executables used in the earliest versions of UNIX. Linux used
48504diff --git a/fs/aio.c b/fs/aio.c
48505index 2bbcacf..8614116 100644
48506--- a/fs/aio.c
48507+++ b/fs/aio.c
48508@@ -160,7 +160,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48509 size += sizeof(struct io_event) * nr_events;
48510 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48511
48512- if (nr_pages < 0)
48513+ if (nr_pages <= 0)
48514 return -EINVAL;
48515
48516 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48517@@ -950,6 +950,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
48518 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
48519 {
48520 ssize_t ret;
48521+ struct iovec iovstack;
48522
48523 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48524
48525@@ -957,17 +958,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
48526 if (compat)
48527 ret = compat_rw_copy_check_uvector(rw,
48528 (struct compat_iovec __user *)kiocb->ki_buf,
48529- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
48530+ kiocb->ki_nr_segs, 1, &iovstack,
48531 &kiocb->ki_iovec);
48532 else
48533 #endif
48534 ret = rw_copy_check_uvector(rw,
48535 (struct iovec __user *)kiocb->ki_buf,
48536- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
48537+ kiocb->ki_nr_segs, 1, &iovstack,
48538 &kiocb->ki_iovec);
48539 if (ret < 0)
48540 return ret;
48541
48542+ if (kiocb->ki_iovec == &iovstack) {
48543+ kiocb->ki_inline_vec = iovstack;
48544+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48545+ }
48546+
48547 /* ki_nbytes now reflect bytes instead of segs */
48548 kiocb->ki_nbytes = ret;
48549 return 0;
48550diff --git a/fs/attr.c b/fs/attr.c
48551index 1449adb..a2038c2 100644
48552--- a/fs/attr.c
48553+++ b/fs/attr.c
48554@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48555 unsigned long limit;
48556
48557 limit = rlimit(RLIMIT_FSIZE);
48558+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48559 if (limit != RLIM_INFINITY && offset > limit)
48560 goto out_sig;
48561 if (offset > inode->i_sb->s_maxbytes)
48562diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48563index 3db70da..7aeec5b 100644
48564--- a/fs/autofs4/waitq.c
48565+++ b/fs/autofs4/waitq.c
48566@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48567 {
48568 unsigned long sigpipe, flags;
48569 mm_segment_t fs;
48570- const char *data = (const char *)addr;
48571+ const char __user *data = (const char __force_user *)addr;
48572 ssize_t wr = 0;
48573
48574 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48575@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48576 return 1;
48577 }
48578
48579+#ifdef CONFIG_GRKERNSEC_HIDESYM
48580+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48581+#endif
48582+
48583 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48584 enum autofs_notify notify)
48585 {
48586@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48587
48588 /* If this is a direct mount request create a dummy name */
48589 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48590+#ifdef CONFIG_GRKERNSEC_HIDESYM
48591+ /* this name does get written to userland via autofs4_write() */
48592+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48593+#else
48594 qstr.len = sprintf(name, "%p", dentry);
48595+#endif
48596 else {
48597 qstr.len = autofs4_getpath(sbi, dentry, &name);
48598 if (!qstr.len) {
48599diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48600index 2722387..c8dd2a7 100644
48601--- a/fs/befs/endian.h
48602+++ b/fs/befs/endian.h
48603@@ -11,7 +11,7 @@
48604
48605 #include <asm/byteorder.h>
48606
48607-static inline u64
48608+static inline u64 __intentional_overflow(-1)
48609 fs64_to_cpu(const struct super_block *sb, fs64 n)
48610 {
48611 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48612@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48613 return (__force fs64)cpu_to_be64(n);
48614 }
48615
48616-static inline u32
48617+static inline u32 __intentional_overflow(-1)
48618 fs32_to_cpu(const struct super_block *sb, fs32 n)
48619 {
48620 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48621diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48622index f95dddc..b1e2c1c 100644
48623--- a/fs/befs/linuxvfs.c
48624+++ b/fs/befs/linuxvfs.c
48625@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48626 {
48627 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48628 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48629- char *link = nd_get_link(nd);
48630+ const char *link = nd_get_link(nd);
48631 if (!IS_ERR(link))
48632 kfree(link);
48633 }
48634diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48635index bce8769..7fc7544 100644
48636--- a/fs/binfmt_aout.c
48637+++ b/fs/binfmt_aout.c
48638@@ -16,6 +16,7 @@
48639 #include <linux/string.h>
48640 #include <linux/fs.h>
48641 #include <linux/file.h>
48642+#include <linux/security.h>
48643 #include <linux/stat.h>
48644 #include <linux/fcntl.h>
48645 #include <linux/ptrace.h>
48646@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48647 #endif
48648 # define START_STACK(u) ((void __user *)u.start_stack)
48649
48650+ memset(&dump, 0, sizeof(dump));
48651+
48652 fs = get_fs();
48653 set_fs(KERNEL_DS);
48654 has_dumped = 1;
48655@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48656
48657 /* If the size of the dump file exceeds the rlimit, then see what would happen
48658 if we wrote the stack, but not the data area. */
48659+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48660 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48661 dump.u_dsize = 0;
48662
48663 /* Make sure we have enough room to write the stack and data areas. */
48664+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48665 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48666 dump.u_ssize = 0;
48667
48668@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48669 rlim = rlimit(RLIMIT_DATA);
48670 if (rlim >= RLIM_INFINITY)
48671 rlim = ~0;
48672+
48673+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48674 if (ex.a_data + ex.a_bss > rlim)
48675 return -ENOMEM;
48676
48677@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48678
48679 install_exec_creds(bprm);
48680
48681+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48682+ current->mm->pax_flags = 0UL;
48683+#endif
48684+
48685+#ifdef CONFIG_PAX_PAGEEXEC
48686+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48687+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48688+
48689+#ifdef CONFIG_PAX_EMUTRAMP
48690+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48691+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48692+#endif
48693+
48694+#ifdef CONFIG_PAX_MPROTECT
48695+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48696+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48697+#endif
48698+
48699+ }
48700+#endif
48701+
48702 if (N_MAGIC(ex) == OMAGIC) {
48703 unsigned long text_addr, map_size;
48704 loff_t pos;
48705@@ -324,7 +352,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48706 }
48707
48708 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48709- PROT_READ | PROT_WRITE | PROT_EXEC,
48710+ PROT_READ | PROT_WRITE,
48711 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48712 fd_offset + ex.a_text);
48713 if (error != N_DATADDR(ex)) {
48714diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48715index f8a0b0e..6f036ed 100644
48716--- a/fs/binfmt_elf.c
48717+++ b/fs/binfmt_elf.c
48718@@ -34,6 +34,7 @@
48719 #include <linux/utsname.h>
48720 #include <linux/coredump.h>
48721 #include <linux/sched.h>
48722+#include <linux/xattr.h>
48723 #include <asm/uaccess.h>
48724 #include <asm/param.h>
48725 #include <asm/page.h>
48726@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
48727 #define elf_core_dump NULL
48728 #endif
48729
48730+#ifdef CONFIG_PAX_MPROTECT
48731+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48732+#endif
48733+
48734+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
48735+static void elf_handle_mmap(struct file *file);
48736+#endif
48737+
48738 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48739 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48740 #else
48741@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
48742 .load_binary = load_elf_binary,
48743 .load_shlib = load_elf_library,
48744 .core_dump = elf_core_dump,
48745+
48746+#ifdef CONFIG_PAX_MPROTECT
48747+ .handle_mprotect= elf_handle_mprotect,
48748+#endif
48749+
48750+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
48751+ .handle_mmap = elf_handle_mmap,
48752+#endif
48753+
48754 .min_coredump = ELF_EXEC_PAGESIZE,
48755 };
48756
48757@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
48758
48759 static int set_brk(unsigned long start, unsigned long end)
48760 {
48761+ unsigned long e = end;
48762+
48763 start = ELF_PAGEALIGN(start);
48764 end = ELF_PAGEALIGN(end);
48765 if (end > start) {
48766@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
48767 if (BAD_ADDR(addr))
48768 return addr;
48769 }
48770- current->mm->start_brk = current->mm->brk = end;
48771+ current->mm->start_brk = current->mm->brk = e;
48772 return 0;
48773 }
48774
48775@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48776 elf_addr_t __user *u_rand_bytes;
48777 const char *k_platform = ELF_PLATFORM;
48778 const char *k_base_platform = ELF_BASE_PLATFORM;
48779- unsigned char k_rand_bytes[16];
48780+ u32 k_rand_bytes[4];
48781 int items;
48782 elf_addr_t *elf_info;
48783 int ei_index = 0;
48784 const struct cred *cred = current_cred();
48785 struct vm_area_struct *vma;
48786+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48787
48788 /*
48789 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48790@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48791 * Generate 16 random bytes for userspace PRNG seeding.
48792 */
48793 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48794- u_rand_bytes = (elf_addr_t __user *)
48795- STACK_ALLOC(p, sizeof(k_rand_bytes));
48796+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
48797+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
48798+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
48799+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
48800+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48801+ u_rand_bytes = (elf_addr_t __user *) p;
48802 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48803 return -EFAULT;
48804
48805@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48806 return -EFAULT;
48807 current->mm->env_end = p;
48808
48809+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48810+
48811 /* Put the elf_info on the stack in the right place. */
48812 sp = (elf_addr_t __user *)envp + 1;
48813- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48814+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48815 return -EFAULT;
48816 return 0;
48817 }
48818@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48819 an ELF header */
48820
48821 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48822- struct file *interpreter, unsigned long *interp_map_addr,
48823- unsigned long no_base)
48824+ struct file *interpreter, unsigned long no_base)
48825 {
48826 struct elf_phdr *elf_phdata;
48827 struct elf_phdr *eppnt;
48828- unsigned long load_addr = 0;
48829+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48830 int load_addr_set = 0;
48831 unsigned long last_bss = 0, elf_bss = 0;
48832- unsigned long error = ~0UL;
48833+ unsigned long error = -EINVAL;
48834 unsigned long total_size;
48835 int retval, i, size;
48836
48837@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48838 goto out_close;
48839 }
48840
48841+#ifdef CONFIG_PAX_SEGMEXEC
48842+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48843+ pax_task_size = SEGMEXEC_TASK_SIZE;
48844+#endif
48845+
48846 eppnt = elf_phdata;
48847 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48848 if (eppnt->p_type == PT_LOAD) {
48849@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48850 map_addr = elf_map(interpreter, load_addr + vaddr,
48851 eppnt, elf_prot, elf_type, total_size);
48852 total_size = 0;
48853- if (!*interp_map_addr)
48854- *interp_map_addr = map_addr;
48855 error = map_addr;
48856 if (BAD_ADDR(map_addr))
48857 goto out_close;
48858@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48859 k = load_addr + eppnt->p_vaddr;
48860 if (BAD_ADDR(k) ||
48861 eppnt->p_filesz > eppnt->p_memsz ||
48862- eppnt->p_memsz > TASK_SIZE ||
48863- TASK_SIZE - eppnt->p_memsz < k) {
48864+ eppnt->p_memsz > pax_task_size ||
48865+ pax_task_size - eppnt->p_memsz < k) {
48866 error = -ENOMEM;
48867 goto out_close;
48868 }
48869@@ -538,6 +567,315 @@ out:
48870 return error;
48871 }
48872
48873+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48874+#ifdef CONFIG_PAX_SOFTMODE
48875+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48876+{
48877+ unsigned long pax_flags = 0UL;
48878+
48879+#ifdef CONFIG_PAX_PAGEEXEC
48880+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48881+ pax_flags |= MF_PAX_PAGEEXEC;
48882+#endif
48883+
48884+#ifdef CONFIG_PAX_SEGMEXEC
48885+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48886+ pax_flags |= MF_PAX_SEGMEXEC;
48887+#endif
48888+
48889+#ifdef CONFIG_PAX_EMUTRAMP
48890+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48891+ pax_flags |= MF_PAX_EMUTRAMP;
48892+#endif
48893+
48894+#ifdef CONFIG_PAX_MPROTECT
48895+ if (elf_phdata->p_flags & PF_MPROTECT)
48896+ pax_flags |= MF_PAX_MPROTECT;
48897+#endif
48898+
48899+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48900+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48901+ pax_flags |= MF_PAX_RANDMMAP;
48902+#endif
48903+
48904+ return pax_flags;
48905+}
48906+#endif
48907+
48908+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48909+{
48910+ unsigned long pax_flags = 0UL;
48911+
48912+#ifdef CONFIG_PAX_PAGEEXEC
48913+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48914+ pax_flags |= MF_PAX_PAGEEXEC;
48915+#endif
48916+
48917+#ifdef CONFIG_PAX_SEGMEXEC
48918+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48919+ pax_flags |= MF_PAX_SEGMEXEC;
48920+#endif
48921+
48922+#ifdef CONFIG_PAX_EMUTRAMP
48923+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48924+ pax_flags |= MF_PAX_EMUTRAMP;
48925+#endif
48926+
48927+#ifdef CONFIG_PAX_MPROTECT
48928+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48929+ pax_flags |= MF_PAX_MPROTECT;
48930+#endif
48931+
48932+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48933+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48934+ pax_flags |= MF_PAX_RANDMMAP;
48935+#endif
48936+
48937+ return pax_flags;
48938+}
48939+#endif
48940+
48941+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48942+#ifdef CONFIG_PAX_SOFTMODE
48943+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48944+{
48945+ unsigned long pax_flags = 0UL;
48946+
48947+#ifdef CONFIG_PAX_PAGEEXEC
48948+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48949+ pax_flags |= MF_PAX_PAGEEXEC;
48950+#endif
48951+
48952+#ifdef CONFIG_PAX_SEGMEXEC
48953+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48954+ pax_flags |= MF_PAX_SEGMEXEC;
48955+#endif
48956+
48957+#ifdef CONFIG_PAX_EMUTRAMP
48958+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48959+ pax_flags |= MF_PAX_EMUTRAMP;
48960+#endif
48961+
48962+#ifdef CONFIG_PAX_MPROTECT
48963+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48964+ pax_flags |= MF_PAX_MPROTECT;
48965+#endif
48966+
48967+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48968+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48969+ pax_flags |= MF_PAX_RANDMMAP;
48970+#endif
48971+
48972+ return pax_flags;
48973+}
48974+#endif
48975+
48976+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48977+{
48978+ unsigned long pax_flags = 0UL;
48979+
48980+#ifdef CONFIG_PAX_PAGEEXEC
48981+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48982+ pax_flags |= MF_PAX_PAGEEXEC;
48983+#endif
48984+
48985+#ifdef CONFIG_PAX_SEGMEXEC
48986+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48987+ pax_flags |= MF_PAX_SEGMEXEC;
48988+#endif
48989+
48990+#ifdef CONFIG_PAX_EMUTRAMP
48991+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48992+ pax_flags |= MF_PAX_EMUTRAMP;
48993+#endif
48994+
48995+#ifdef CONFIG_PAX_MPROTECT
48996+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48997+ pax_flags |= MF_PAX_MPROTECT;
48998+#endif
48999+
49000+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
49001+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
49002+ pax_flags |= MF_PAX_RANDMMAP;
49003+#endif
49004+
49005+ return pax_flags;
49006+}
49007+#endif
49008+
49009+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49010+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
49011+{
49012+ unsigned long pax_flags = 0UL;
49013+
49014+#ifdef CONFIG_PAX_EI_PAX
49015+
49016+#ifdef CONFIG_PAX_PAGEEXEC
49017+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
49018+ pax_flags |= MF_PAX_PAGEEXEC;
49019+#endif
49020+
49021+#ifdef CONFIG_PAX_SEGMEXEC
49022+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
49023+ pax_flags |= MF_PAX_SEGMEXEC;
49024+#endif
49025+
49026+#ifdef CONFIG_PAX_EMUTRAMP
49027+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
49028+ pax_flags |= MF_PAX_EMUTRAMP;
49029+#endif
49030+
49031+#ifdef CONFIG_PAX_MPROTECT
49032+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
49033+ pax_flags |= MF_PAX_MPROTECT;
49034+#endif
49035+
49036+#ifdef CONFIG_PAX_ASLR
49037+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
49038+ pax_flags |= MF_PAX_RANDMMAP;
49039+#endif
49040+
49041+#else
49042+
49043+#ifdef CONFIG_PAX_PAGEEXEC
49044+ pax_flags |= MF_PAX_PAGEEXEC;
49045+#endif
49046+
49047+#ifdef CONFIG_PAX_SEGMEXEC
49048+ pax_flags |= MF_PAX_SEGMEXEC;
49049+#endif
49050+
49051+#ifdef CONFIG_PAX_MPROTECT
49052+ pax_flags |= MF_PAX_MPROTECT;
49053+#endif
49054+
49055+#ifdef CONFIG_PAX_RANDMMAP
49056+ if (randomize_va_space)
49057+ pax_flags |= MF_PAX_RANDMMAP;
49058+#endif
49059+
49060+#endif
49061+
49062+ return pax_flags;
49063+}
49064+
49065+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
49066+{
49067+
49068+#ifdef CONFIG_PAX_PT_PAX_FLAGS
49069+ unsigned long i;
49070+
49071+ for (i = 0UL; i < elf_ex->e_phnum; i++)
49072+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
49073+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
49074+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
49075+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
49076+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
49077+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
49078+ return ~0UL;
49079+
49080+#ifdef CONFIG_PAX_SOFTMODE
49081+ if (pax_softmode)
49082+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
49083+ else
49084+#endif
49085+
49086+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
49087+ break;
49088+ }
49089+#endif
49090+
49091+ return ~0UL;
49092+}
49093+
49094+static unsigned long pax_parse_xattr_pax(struct file * const file)
49095+{
49096+
49097+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
49098+ ssize_t xattr_size, i;
49099+ unsigned char xattr_value[sizeof("pemrs") - 1];
49100+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
49101+
49102+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
49103+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
49104+ return ~0UL;
49105+
49106+ for (i = 0; i < xattr_size; i++)
49107+ switch (xattr_value[i]) {
49108+ default:
49109+ return ~0UL;
49110+
49111+#define parse_flag(option1, option2, flag) \
49112+ case option1: \
49113+ if (pax_flags_hardmode & MF_PAX_##flag) \
49114+ return ~0UL; \
49115+ pax_flags_hardmode |= MF_PAX_##flag; \
49116+ break; \
49117+ case option2: \
49118+ if (pax_flags_softmode & MF_PAX_##flag) \
49119+ return ~0UL; \
49120+ pax_flags_softmode |= MF_PAX_##flag; \
49121+ break;
49122+
49123+ parse_flag('p', 'P', PAGEEXEC);
49124+ parse_flag('e', 'E', EMUTRAMP);
49125+ parse_flag('m', 'M', MPROTECT);
49126+ parse_flag('r', 'R', RANDMMAP);
49127+ parse_flag('s', 'S', SEGMEXEC);
49128+
49129+#undef parse_flag
49130+ }
49131+
49132+ if (pax_flags_hardmode & pax_flags_softmode)
49133+ return ~0UL;
49134+
49135+#ifdef CONFIG_PAX_SOFTMODE
49136+ if (pax_softmode)
49137+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
49138+ else
49139+#endif
49140+
49141+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49142+#else
49143+ return ~0UL;
49144+#endif
49145+
49146+}
49147+
49148+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49149+{
49150+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49151+
49152+ pax_flags = pax_parse_ei_pax(elf_ex);
49153+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49154+ xattr_pax_flags = pax_parse_xattr_pax(file);
49155+
49156+ if (pt_pax_flags == ~0UL)
49157+ pt_pax_flags = xattr_pax_flags;
49158+ else if (xattr_pax_flags == ~0UL)
49159+ xattr_pax_flags = pt_pax_flags;
49160+ if (pt_pax_flags != xattr_pax_flags)
49161+ return -EINVAL;
49162+ if (pt_pax_flags != ~0UL)
49163+ pax_flags = pt_pax_flags;
49164+
49165+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49166+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49167+ if ((__supported_pte_mask & _PAGE_NX))
49168+ pax_flags &= ~MF_PAX_SEGMEXEC;
49169+ else
49170+ pax_flags &= ~MF_PAX_PAGEEXEC;
49171+ }
49172+#endif
49173+
49174+ if (0 > pax_check_flags(&pax_flags))
49175+ return -EINVAL;
49176+
49177+ current->mm->pax_flags = pax_flags;
49178+ return 0;
49179+}
49180+#endif
49181+
49182 /*
49183 * These are the functions used to load ELF style executables and shared
49184 * libraries. There is no binary dependent code anywhere else.
49185@@ -554,6 +892,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49186 {
49187 unsigned int random_variable = 0;
49188
49189+#ifdef CONFIG_PAX_RANDUSTACK
49190+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49191+ return stack_top - current->mm->delta_stack;
49192+#endif
49193+
49194 if ((current->flags & PF_RANDOMIZE) &&
49195 !(current->personality & ADDR_NO_RANDOMIZE)) {
49196 random_variable = get_random_int() & STACK_RND_MASK;
49197@@ -572,7 +915,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49198 unsigned long load_addr = 0, load_bias = 0;
49199 int load_addr_set = 0;
49200 char * elf_interpreter = NULL;
49201- unsigned long error;
49202+ unsigned long error = 0;
49203 struct elf_phdr *elf_ppnt, *elf_phdata;
49204 unsigned long elf_bss, elf_brk;
49205 int retval, i;
49206@@ -582,12 +925,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49207 unsigned long start_code, end_code, start_data, end_data;
49208 unsigned long reloc_func_desc __maybe_unused = 0;
49209 int executable_stack = EXSTACK_DEFAULT;
49210- unsigned long def_flags = 0;
49211 struct pt_regs *regs = current_pt_regs();
49212 struct {
49213 struct elfhdr elf_ex;
49214 struct elfhdr interp_elf_ex;
49215 } *loc;
49216+ unsigned long pax_task_size = TASK_SIZE;
49217
49218 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49219 if (!loc) {
49220@@ -723,11 +1066,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49221 goto out_free_dentry;
49222
49223 /* OK, This is the point of no return */
49224- current->mm->def_flags = def_flags;
49225+
49226+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49227+ current->mm->pax_flags = 0UL;
49228+#endif
49229+
49230+#ifdef CONFIG_PAX_DLRESOLVE
49231+ current->mm->call_dl_resolve = 0UL;
49232+#endif
49233+
49234+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49235+ current->mm->call_syscall = 0UL;
49236+#endif
49237+
49238+#ifdef CONFIG_PAX_ASLR
49239+ current->mm->delta_mmap = 0UL;
49240+ current->mm->delta_stack = 0UL;
49241+#endif
49242+
49243+ current->mm->def_flags = 0;
49244+
49245+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49246+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49247+ send_sig(SIGKILL, current, 0);
49248+ goto out_free_dentry;
49249+ }
49250+#endif
49251+
49252+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49253+ pax_set_initial_flags(bprm);
49254+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49255+ if (pax_set_initial_flags_func)
49256+ (pax_set_initial_flags_func)(bprm);
49257+#endif
49258+
49259+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49260+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49261+ current->mm->context.user_cs_limit = PAGE_SIZE;
49262+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49263+ }
49264+#endif
49265+
49266+#ifdef CONFIG_PAX_SEGMEXEC
49267+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49268+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49269+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49270+ pax_task_size = SEGMEXEC_TASK_SIZE;
49271+ current->mm->def_flags |= VM_NOHUGEPAGE;
49272+ }
49273+#endif
49274+
49275+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49276+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49277+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49278+ put_cpu();
49279+ }
49280+#endif
49281
49282 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49283 may depend on the personality. */
49284 SET_PERSONALITY(loc->elf_ex);
49285+
49286+#ifdef CONFIG_PAX_ASLR
49287+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49288+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49289+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49290+ }
49291+#endif
49292+
49293+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49294+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49295+ executable_stack = EXSTACK_DISABLE_X;
49296+ current->personality &= ~READ_IMPLIES_EXEC;
49297+ } else
49298+#endif
49299+
49300 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49301 current->personality |= READ_IMPLIES_EXEC;
49302
49303@@ -819,6 +1232,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49304 #else
49305 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49306 #endif
49307+
49308+#ifdef CONFIG_PAX_RANDMMAP
49309+ /* PaX: randomize base address at the default exe base if requested */
49310+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49311+#ifdef CONFIG_SPARC64
49312+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49313+#else
49314+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49315+#endif
49316+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49317+ elf_flags |= MAP_FIXED;
49318+ }
49319+#endif
49320+
49321 }
49322
49323 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49324@@ -851,9 +1278,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49325 * allowed task size. Note that p_filesz must always be
49326 * <= p_memsz so it is only necessary to check p_memsz.
49327 */
49328- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49329- elf_ppnt->p_memsz > TASK_SIZE ||
49330- TASK_SIZE - elf_ppnt->p_memsz < k) {
49331+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49332+ elf_ppnt->p_memsz > pax_task_size ||
49333+ pax_task_size - elf_ppnt->p_memsz < k) {
49334 /* set_brk can never work. Avoid overflows. */
49335 send_sig(SIGKILL, current, 0);
49336 retval = -EINVAL;
49337@@ -892,17 +1319,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
49338 goto out_free_dentry;
49339 }
49340 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49341- send_sig(SIGSEGV, current, 0);
49342- retval = -EFAULT; /* Nobody gets to see this, but.. */
49343- goto out_free_dentry;
49344+ /*
49345+ * This bss-zeroing can fail if the ELF
49346+ * file specifies odd protections. So
49347+ * we don't check the return value
49348+ */
49349 }
49350
49351+#ifdef CONFIG_PAX_RANDMMAP
49352+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49353+ unsigned long start, size, flags;
49354+ vm_flags_t vm_flags;
49355+
49356+ start = ELF_PAGEALIGN(elf_brk);
49357+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49358+ flags = MAP_FIXED | MAP_PRIVATE;
49359+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49360+
49361+ down_write(&current->mm->mmap_sem);
49362+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49363+ retval = -ENOMEM;
49364+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49365+// if (current->personality & ADDR_NO_RANDOMIZE)
49366+// vm_flags |= VM_READ | VM_MAYREAD;
49367+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
49368+ retval = IS_ERR_VALUE(start) ? start : 0;
49369+ }
49370+ up_write(&current->mm->mmap_sem);
49371+ if (retval == 0)
49372+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49373+ if (retval < 0) {
49374+ send_sig(SIGKILL, current, 0);
49375+ goto out_free_dentry;
49376+ }
49377+ }
49378+#endif
49379+
49380 if (elf_interpreter) {
49381- unsigned long interp_map_addr = 0;
49382-
49383 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49384 interpreter,
49385- &interp_map_addr,
49386 load_bias);
49387 if (!IS_ERR((void *)elf_entry)) {
49388 /*
49389@@ -1124,7 +1579,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49390 * Decide what to dump of a segment, part, all or none.
49391 */
49392 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49393- unsigned long mm_flags)
49394+ unsigned long mm_flags, long signr)
49395 {
49396 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49397
49398@@ -1162,7 +1617,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49399 if (vma->vm_file == NULL)
49400 return 0;
49401
49402- if (FILTER(MAPPED_PRIVATE))
49403+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49404 goto whole;
49405
49406 /*
49407@@ -1387,9 +1842,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49408 {
49409 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49410 int i = 0;
49411- do
49412+ do {
49413 i += 2;
49414- while (auxv[i - 2] != AT_NULL);
49415+ } while (auxv[i - 2] != AT_NULL);
49416 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49417 }
49418
49419@@ -1398,7 +1853,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
49420 {
49421 mm_segment_t old_fs = get_fs();
49422 set_fs(KERNEL_DS);
49423- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
49424+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
49425 set_fs(old_fs);
49426 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
49427 }
49428@@ -2019,14 +2474,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49429 }
49430
49431 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49432- unsigned long mm_flags)
49433+ struct coredump_params *cprm)
49434 {
49435 struct vm_area_struct *vma;
49436 size_t size = 0;
49437
49438 for (vma = first_vma(current, gate_vma); vma != NULL;
49439 vma = next_vma(vma, gate_vma))
49440- size += vma_dump_size(vma, mm_flags);
49441+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49442 return size;
49443 }
49444
49445@@ -2119,7 +2574,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49446
49447 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49448
49449- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49450+ offset += elf_core_vma_data_size(gate_vma, cprm);
49451 offset += elf_core_extra_data_size();
49452 e_shoff = offset;
49453
49454@@ -2133,10 +2588,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49455 offset = dataoff;
49456
49457 size += sizeof(*elf);
49458+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49459 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49460 goto end_coredump;
49461
49462 size += sizeof(*phdr4note);
49463+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49464 if (size > cprm->limit
49465 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49466 goto end_coredump;
49467@@ -2150,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49468 phdr.p_offset = offset;
49469 phdr.p_vaddr = vma->vm_start;
49470 phdr.p_paddr = 0;
49471- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49472+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49473 phdr.p_memsz = vma->vm_end - vma->vm_start;
49474 offset += phdr.p_filesz;
49475 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49476@@ -2161,6 +2618,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49477 phdr.p_align = ELF_EXEC_PAGESIZE;
49478
49479 size += sizeof(phdr);
49480+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49481 if (size > cprm->limit
49482 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49483 goto end_coredump;
49484@@ -2185,7 +2643,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49485 unsigned long addr;
49486 unsigned long end;
49487
49488- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49489+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49490
49491 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49492 struct page *page;
49493@@ -2194,6 +2652,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49494 page = get_dump_page(addr);
49495 if (page) {
49496 void *kaddr = kmap(page);
49497+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49498 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49499 !dump_write(cprm->file, kaddr,
49500 PAGE_SIZE);
49501@@ -2211,6 +2670,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49502
49503 if (e_phnum == PN_XNUM) {
49504 size += sizeof(*shdr4extnum);
49505+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49506 if (size > cprm->limit
49507 || !dump_write(cprm->file, shdr4extnum,
49508 sizeof(*shdr4extnum)))
49509@@ -2231,6 +2691,167 @@ out:
49510
49511 #endif /* CONFIG_ELF_CORE */
49512
49513+#ifdef CONFIG_PAX_MPROTECT
49514+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49515+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49516+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49517+ *
49518+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49519+ * basis because we want to allow the common case and not the special ones.
49520+ */
49521+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49522+{
49523+ struct elfhdr elf_h;
49524+ struct elf_phdr elf_p;
49525+ unsigned long i;
49526+ unsigned long oldflags;
49527+ bool is_textrel_rw, is_textrel_rx, is_relro;
49528+
49529+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
49530+ return;
49531+
49532+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49533+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49534+
49535+#ifdef CONFIG_PAX_ELFRELOCS
49536+ /* possible TEXTREL */
49537+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49538+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
49539+#else
49540+ is_textrel_rw = false;
49541+ is_textrel_rx = false;
49542+#endif
49543+
49544+ /* possible RELRO */
49545+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49546+
49547+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49548+ return;
49549+
49550+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49551+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49552+
49553+#ifdef CONFIG_PAX_ETEXECRELOCS
49554+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49555+#else
49556+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49557+#endif
49558+
49559+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49560+ !elf_check_arch(&elf_h) ||
49561+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49562+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49563+ return;
49564+
49565+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49566+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49567+ return;
49568+ switch (elf_p.p_type) {
49569+ case PT_DYNAMIC:
49570+ if (!is_textrel_rw && !is_textrel_rx)
49571+ continue;
49572+ i = 0UL;
49573+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49574+ elf_dyn dyn;
49575+
49576+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49577+ break;
49578+ if (dyn.d_tag == DT_NULL)
49579+ break;
49580+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49581+ gr_log_textrel(vma);
49582+ if (is_textrel_rw)
49583+ vma->vm_flags |= VM_MAYWRITE;
49584+ else
49585+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49586+ vma->vm_flags &= ~VM_MAYWRITE;
49587+ break;
49588+ }
49589+ i++;
49590+ }
49591+ is_textrel_rw = false;
49592+ is_textrel_rx = false;
49593+ continue;
49594+
49595+ case PT_GNU_RELRO:
49596+ if (!is_relro)
49597+ continue;
49598+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49599+ vma->vm_flags &= ~VM_MAYWRITE;
49600+ is_relro = false;
49601+ continue;
49602+
49603+#ifdef CONFIG_PAX_PT_PAX_FLAGS
49604+ case PT_PAX_FLAGS: {
49605+ const char *msg_mprotect = "", *msg_emutramp = "";
49606+ char *buffer_lib, *buffer_exe;
49607+
49608+ if (elf_p.p_flags & PF_NOMPROTECT)
49609+ msg_mprotect = "MPROTECT disabled";
49610+
49611+#ifdef CONFIG_PAX_EMUTRAMP
49612+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
49613+ msg_emutramp = "EMUTRAMP enabled";
49614+#endif
49615+
49616+ if (!msg_mprotect[0] && !msg_emutramp[0])
49617+ continue;
49618+
49619+ if (!printk_ratelimit())
49620+ continue;
49621+
49622+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
49623+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
49624+ if (buffer_lib && buffer_exe) {
49625+ char *path_lib, *path_exe;
49626+
49627+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
49628+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
49629+
49630+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
49631+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
49632+
49633+ }
49634+ free_page((unsigned long)buffer_exe);
49635+ free_page((unsigned long)buffer_lib);
49636+ continue;
49637+ }
49638+#endif
49639+
49640+ }
49641+ }
49642+}
49643+#endif
49644+
49645+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
49646+
49647+extern int grsec_enable_log_rwxmaps;
49648+
49649+static void elf_handle_mmap(struct file *file)
49650+{
49651+ struct elfhdr elf_h;
49652+ struct elf_phdr elf_p;
49653+ unsigned long i;
49654+
49655+ if (!grsec_enable_log_rwxmaps)
49656+ return;
49657+
49658+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49659+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49660+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
49661+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49662+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49663+ return;
49664+
49665+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49666+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49667+ return;
49668+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
49669+ gr_log_ptgnustack(file);
49670+ }
49671+}
49672+#endif
49673+
49674 static int __init init_elf_binfmt(void)
49675 {
49676 register_binfmt(&elf_format);
49677diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49678index d50bbe5..af3b649 100644
49679--- a/fs/binfmt_flat.c
49680+++ b/fs/binfmt_flat.c
49681@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49682 realdatastart = (unsigned long) -ENOMEM;
49683 printk("Unable to allocate RAM for process data, errno %d\n",
49684 (int)-realdatastart);
49685+ down_write(&current->mm->mmap_sem);
49686 vm_munmap(textpos, text_len);
49687+ up_write(&current->mm->mmap_sem);
49688 ret = realdatastart;
49689 goto err;
49690 }
49691@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49692 }
49693 if (IS_ERR_VALUE(result)) {
49694 printk("Unable to read data+bss, errno %d\n", (int)-result);
49695+ down_write(&current->mm->mmap_sem);
49696 vm_munmap(textpos, text_len);
49697 vm_munmap(realdatastart, len);
49698+ up_write(&current->mm->mmap_sem);
49699 ret = result;
49700 goto err;
49701 }
49702@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49703 }
49704 if (IS_ERR_VALUE(result)) {
49705 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49706+ down_write(&current->mm->mmap_sem);
49707 vm_munmap(textpos, text_len + data_len + extra +
49708 MAX_SHARED_LIBS * sizeof(unsigned long));
49709+ up_write(&current->mm->mmap_sem);
49710 ret = result;
49711 goto err;
49712 }
49713diff --git a/fs/bio.c b/fs/bio.c
49714index 94bbc04..6fe78a4 100644
49715--- a/fs/bio.c
49716+++ b/fs/bio.c
49717@@ -1096,7 +1096,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49718 /*
49719 * Overflow, abort
49720 */
49721- if (end < start)
49722+ if (end < start || end - start > INT_MAX - nr_pages)
49723 return ERR_PTR(-EINVAL);
49724
49725 nr_pages += end - start;
49726@@ -1230,7 +1230,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49727 /*
49728 * Overflow, abort
49729 */
49730- if (end < start)
49731+ if (end < start || end - start > INT_MAX - nr_pages)
49732 return ERR_PTR(-EINVAL);
49733
49734 nr_pages += end - start;
49735@@ -1492,7 +1492,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49736 const int read = bio_data_dir(bio) == READ;
49737 struct bio_map_data *bmd = bio->bi_private;
49738 int i;
49739- char *p = bmd->sgvecs[0].iov_base;
49740+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49741
49742 bio_for_each_segment_all(bvec, bio, i) {
49743 char *addr = page_address(bvec->bv_page);
49744diff --git a/fs/block_dev.c b/fs/block_dev.c
49745index 85f5c85..d6f0b1a 100644
49746--- a/fs/block_dev.c
49747+++ b/fs/block_dev.c
49748@@ -658,7 +658,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49749 else if (bdev->bd_contains == bdev)
49750 return true; /* is a whole device which isn't held */
49751
49752- else if (whole->bd_holder == bd_may_claim)
49753+ else if (whole->bd_holder == (void *)bd_may_claim)
49754 return true; /* is a partition of a device that is being partitioned */
49755 else if (whole->bd_holder != NULL)
49756 return false; /* is a partition of a held device */
49757diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49758index 7fb054b..ad36c67 100644
49759--- a/fs/btrfs/ctree.c
49760+++ b/fs/btrfs/ctree.c
49761@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49762 free_extent_buffer(buf);
49763 add_root_to_dirty_list(root);
49764 } else {
49765- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49766- parent_start = parent->start;
49767- else
49768+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49769+ if (parent)
49770+ parent_start = parent->start;
49771+ else
49772+ parent_start = 0;
49773+ } else
49774 parent_start = 0;
49775
49776 WARN_ON(trans->transid != btrfs_header_generation(parent));
49777diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49778index 0f81d67..0ad55fe 100644
49779--- a/fs/btrfs/ioctl.c
49780+++ b/fs/btrfs/ioctl.c
49781@@ -3084,9 +3084,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49782 for (i = 0; i < num_types; i++) {
49783 struct btrfs_space_info *tmp;
49784
49785+ /* Don't copy in more than we allocated */
49786 if (!slot_count)
49787 break;
49788
49789+ slot_count--;
49790+
49791 info = NULL;
49792 rcu_read_lock();
49793 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49794@@ -3108,10 +3111,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49795 memcpy(dest, &space, sizeof(space));
49796 dest++;
49797 space_args.total_spaces++;
49798- slot_count--;
49799 }
49800- if (!slot_count)
49801- break;
49802 }
49803 up_read(&info->groups_sem);
49804 }
49805diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49806index f0857e0..e7023c5 100644
49807--- a/fs/btrfs/super.c
49808+++ b/fs/btrfs/super.c
49809@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49810 function, line, errstr);
49811 return;
49812 }
49813- ACCESS_ONCE(trans->transaction->aborted) = errno;
49814+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49815 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49816 }
49817 /*
49818diff --git a/fs/buffer.c b/fs/buffer.c
49819index d2a4d1b..df798ca 100644
49820--- a/fs/buffer.c
49821+++ b/fs/buffer.c
49822@@ -3367,7 +3367,7 @@ void __init buffer_init(void)
49823 bh_cachep = kmem_cache_create("buffer_head",
49824 sizeof(struct buffer_head), 0,
49825 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
49826- SLAB_MEM_SPREAD),
49827+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
49828 NULL);
49829
49830 /*
49831diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49832index 622f469..e8d2d55 100644
49833--- a/fs/cachefiles/bind.c
49834+++ b/fs/cachefiles/bind.c
49835@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49836 args);
49837
49838 /* start by checking things over */
49839- ASSERT(cache->fstop_percent >= 0 &&
49840- cache->fstop_percent < cache->fcull_percent &&
49841+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49842 cache->fcull_percent < cache->frun_percent &&
49843 cache->frun_percent < 100);
49844
49845- ASSERT(cache->bstop_percent >= 0 &&
49846- cache->bstop_percent < cache->bcull_percent &&
49847+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49848 cache->bcull_percent < cache->brun_percent &&
49849 cache->brun_percent < 100);
49850
49851diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49852index 0a1467b..6a53245 100644
49853--- a/fs/cachefiles/daemon.c
49854+++ b/fs/cachefiles/daemon.c
49855@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49856 if (n > buflen)
49857 return -EMSGSIZE;
49858
49859- if (copy_to_user(_buffer, buffer, n) != 0)
49860+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49861 return -EFAULT;
49862
49863 return n;
49864@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49865 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49866 return -EIO;
49867
49868- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49869+ if (datalen > PAGE_SIZE - 1)
49870 return -EOPNOTSUPP;
49871
49872 /* drag the command string into the kernel so we can parse it */
49873@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49874 if (args[0] != '%' || args[1] != '\0')
49875 return -EINVAL;
49876
49877- if (fstop < 0 || fstop >= cache->fcull_percent)
49878+ if (fstop >= cache->fcull_percent)
49879 return cachefiles_daemon_range_error(cache, args);
49880
49881 cache->fstop_percent = fstop;
49882@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49883 if (args[0] != '%' || args[1] != '\0')
49884 return -EINVAL;
49885
49886- if (bstop < 0 || bstop >= cache->bcull_percent)
49887+ if (bstop >= cache->bcull_percent)
49888 return cachefiles_daemon_range_error(cache, args);
49889
49890 cache->bstop_percent = bstop;
49891diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49892index 4938251..7e01445 100644
49893--- a/fs/cachefiles/internal.h
49894+++ b/fs/cachefiles/internal.h
49895@@ -59,7 +59,7 @@ struct cachefiles_cache {
49896 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49897 struct rb_root active_nodes; /* active nodes (can't be culled) */
49898 rwlock_t active_lock; /* lock for active_nodes */
49899- atomic_t gravecounter; /* graveyard uniquifier */
49900+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49901 unsigned frun_percent; /* when to stop culling (% files) */
49902 unsigned fcull_percent; /* when to start culling (% files) */
49903 unsigned fstop_percent; /* when to stop allocating (% files) */
49904@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49905 * proc.c
49906 */
49907 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49908-extern atomic_t cachefiles_lookup_histogram[HZ];
49909-extern atomic_t cachefiles_mkdir_histogram[HZ];
49910-extern atomic_t cachefiles_create_histogram[HZ];
49911+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49912+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49913+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49914
49915 extern int __init cachefiles_proc_init(void);
49916 extern void cachefiles_proc_cleanup(void);
49917 static inline
49918-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49919+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49920 {
49921 unsigned long jif = jiffies - start_jif;
49922 if (jif >= HZ)
49923 jif = HZ - 1;
49924- atomic_inc(&histogram[jif]);
49925+ atomic_inc_unchecked(&histogram[jif]);
49926 }
49927
49928 #else
49929diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49930index 8c01c5fc..15f982e 100644
49931--- a/fs/cachefiles/namei.c
49932+++ b/fs/cachefiles/namei.c
49933@@ -317,7 +317,7 @@ try_again:
49934 /* first step is to make up a grave dentry in the graveyard */
49935 sprintf(nbuffer, "%08x%08x",
49936 (uint32_t) get_seconds(),
49937- (uint32_t) atomic_inc_return(&cache->gravecounter));
49938+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49939
49940 /* do the multiway lock magic */
49941 trap = lock_rename(cache->graveyard, dir);
49942diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49943index eccd339..4c1d995 100644
49944--- a/fs/cachefiles/proc.c
49945+++ b/fs/cachefiles/proc.c
49946@@ -14,9 +14,9 @@
49947 #include <linux/seq_file.h>
49948 #include "internal.h"
49949
49950-atomic_t cachefiles_lookup_histogram[HZ];
49951-atomic_t cachefiles_mkdir_histogram[HZ];
49952-atomic_t cachefiles_create_histogram[HZ];
49953+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49954+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49955+atomic_unchecked_t cachefiles_create_histogram[HZ];
49956
49957 /*
49958 * display the latency histogram
49959@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49960 return 0;
49961 default:
49962 index = (unsigned long) v - 3;
49963- x = atomic_read(&cachefiles_lookup_histogram[index]);
49964- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49965- z = atomic_read(&cachefiles_create_histogram[index]);
49966+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49967+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49968+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49969 if (x == 0 && y == 0 && z == 0)
49970 return 0;
49971
49972diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49973index 317f9ee..3d24511 100644
49974--- a/fs/cachefiles/rdwr.c
49975+++ b/fs/cachefiles/rdwr.c
49976@@ -966,7 +966,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49977 old_fs = get_fs();
49978 set_fs(KERNEL_DS);
49979 ret = file->f_op->write(
49980- file, (const void __user *) data, len, &pos);
49981+ file, (const void __force_user *) data, len, &pos);
49982 set_fs(old_fs);
49983 kunmap(page);
49984 file_end_write(file);
49985diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49986index f02d82b..2632cf86 100644
49987--- a/fs/ceph/dir.c
49988+++ b/fs/ceph/dir.c
49989@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49990 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49991 struct ceph_mds_client *mdsc = fsc->mdsc;
49992 unsigned frag = fpos_frag(filp->f_pos);
49993- int off = fpos_off(filp->f_pos);
49994+ unsigned int off = fpos_off(filp->f_pos);
49995 int err;
49996 u32 ftype;
49997 struct ceph_mds_reply_info_parsed *rinfo;
49998diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49999index d597483..747901b 100644
50000--- a/fs/cifs/cifs_debug.c
50001+++ b/fs/cifs/cifs_debug.c
50002@@ -284,8 +284,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
50003
50004 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
50005 #ifdef CONFIG_CIFS_STATS2
50006- atomic_set(&totBufAllocCount, 0);
50007- atomic_set(&totSmBufAllocCount, 0);
50008+ atomic_set_unchecked(&totBufAllocCount, 0);
50009+ atomic_set_unchecked(&totSmBufAllocCount, 0);
50010 #endif /* CONFIG_CIFS_STATS2 */
50011 spin_lock(&cifs_tcp_ses_lock);
50012 list_for_each(tmp1, &cifs_tcp_ses_list) {
50013@@ -298,7 +298,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
50014 tcon = list_entry(tmp3,
50015 struct cifs_tcon,
50016 tcon_list);
50017- atomic_set(&tcon->num_smbs_sent, 0);
50018+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
50019 if (server->ops->clear_stats)
50020 server->ops->clear_stats(tcon);
50021 }
50022@@ -330,8 +330,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
50023 smBufAllocCount.counter, cifs_min_small);
50024 #ifdef CONFIG_CIFS_STATS2
50025 seq_printf(m, "Total Large %d Small %d Allocations\n",
50026- atomic_read(&totBufAllocCount),
50027- atomic_read(&totSmBufAllocCount));
50028+ atomic_read_unchecked(&totBufAllocCount),
50029+ atomic_read_unchecked(&totSmBufAllocCount));
50030 #endif /* CONFIG_CIFS_STATS2 */
50031
50032 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
50033@@ -360,7 +360,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
50034 if (tcon->need_reconnect)
50035 seq_puts(m, "\tDISCONNECTED ");
50036 seq_printf(m, "\nSMBs: %d",
50037- atomic_read(&tcon->num_smbs_sent));
50038+ atomic_read_unchecked(&tcon->num_smbs_sent));
50039 if (server->ops->print_stats)
50040 server->ops->print_stats(m, tcon);
50041 }
50042diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
50043index 3752b9f..8db5569 100644
50044--- a/fs/cifs/cifsfs.c
50045+++ b/fs/cifs/cifsfs.c
50046@@ -1035,7 +1035,7 @@ cifs_init_request_bufs(void)
50047 */
50048 cifs_req_cachep = kmem_cache_create("cifs_request",
50049 CIFSMaxBufSize + max_hdr_size, 0,
50050- SLAB_HWCACHE_ALIGN, NULL);
50051+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
50052 if (cifs_req_cachep == NULL)
50053 return -ENOMEM;
50054
50055@@ -1062,7 +1062,7 @@ cifs_init_request_bufs(void)
50056 efficient to alloc 1 per page off the slab compared to 17K (5page)
50057 alloc of large cifs buffers even when page debugging is on */
50058 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
50059- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
50060+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
50061 NULL);
50062 if (cifs_sm_req_cachep == NULL) {
50063 mempool_destroy(cifs_req_poolp);
50064@@ -1147,8 +1147,8 @@ init_cifs(void)
50065 atomic_set(&bufAllocCount, 0);
50066 atomic_set(&smBufAllocCount, 0);
50067 #ifdef CONFIG_CIFS_STATS2
50068- atomic_set(&totBufAllocCount, 0);
50069- atomic_set(&totSmBufAllocCount, 0);
50070+ atomic_set_unchecked(&totBufAllocCount, 0);
50071+ atomic_set_unchecked(&totSmBufAllocCount, 0);
50072 #endif /* CONFIG_CIFS_STATS2 */
50073
50074 atomic_set(&midCount, 0);
50075diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
50076index 4f07f6f..55de8ce 100644
50077--- a/fs/cifs/cifsglob.h
50078+++ b/fs/cifs/cifsglob.h
50079@@ -751,35 +751,35 @@ struct cifs_tcon {
50080 __u16 Flags; /* optional support bits */
50081 enum statusEnum tidStatus;
50082 #ifdef CONFIG_CIFS_STATS
50083- atomic_t num_smbs_sent;
50084+ atomic_unchecked_t num_smbs_sent;
50085 union {
50086 struct {
50087- atomic_t num_writes;
50088- atomic_t num_reads;
50089- atomic_t num_flushes;
50090- atomic_t num_oplock_brks;
50091- atomic_t num_opens;
50092- atomic_t num_closes;
50093- atomic_t num_deletes;
50094- atomic_t num_mkdirs;
50095- atomic_t num_posixopens;
50096- atomic_t num_posixmkdirs;
50097- atomic_t num_rmdirs;
50098- atomic_t num_renames;
50099- atomic_t num_t2renames;
50100- atomic_t num_ffirst;
50101- atomic_t num_fnext;
50102- atomic_t num_fclose;
50103- atomic_t num_hardlinks;
50104- atomic_t num_symlinks;
50105- atomic_t num_locks;
50106- atomic_t num_acl_get;
50107- atomic_t num_acl_set;
50108+ atomic_unchecked_t num_writes;
50109+ atomic_unchecked_t num_reads;
50110+ atomic_unchecked_t num_flushes;
50111+ atomic_unchecked_t num_oplock_brks;
50112+ atomic_unchecked_t num_opens;
50113+ atomic_unchecked_t num_closes;
50114+ atomic_unchecked_t num_deletes;
50115+ atomic_unchecked_t num_mkdirs;
50116+ atomic_unchecked_t num_posixopens;
50117+ atomic_unchecked_t num_posixmkdirs;
50118+ atomic_unchecked_t num_rmdirs;
50119+ atomic_unchecked_t num_renames;
50120+ atomic_unchecked_t num_t2renames;
50121+ atomic_unchecked_t num_ffirst;
50122+ atomic_unchecked_t num_fnext;
50123+ atomic_unchecked_t num_fclose;
50124+ atomic_unchecked_t num_hardlinks;
50125+ atomic_unchecked_t num_symlinks;
50126+ atomic_unchecked_t num_locks;
50127+ atomic_unchecked_t num_acl_get;
50128+ atomic_unchecked_t num_acl_set;
50129 } cifs_stats;
50130 #ifdef CONFIG_CIFS_SMB2
50131 struct {
50132- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
50133- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
50134+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
50135+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
50136 } smb2_stats;
50137 #endif /* CONFIG_CIFS_SMB2 */
50138 } stats;
50139@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
50140 }
50141
50142 #ifdef CONFIG_CIFS_STATS
50143-#define cifs_stats_inc atomic_inc
50144+#define cifs_stats_inc atomic_inc_unchecked
50145
50146 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
50147 unsigned int bytes)
50148@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
50149 /* Various Debug counters */
50150 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
50151 #ifdef CONFIG_CIFS_STATS2
50152-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
50153-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
50154+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
50155+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
50156 #endif
50157 GLOBAL_EXTERN atomic_t smBufAllocCount;
50158 GLOBAL_EXTERN atomic_t midCount;
50159diff --git a/fs/cifs/link.c b/fs/cifs/link.c
50160index b83c3f5..6437caa 100644
50161--- a/fs/cifs/link.c
50162+++ b/fs/cifs/link.c
50163@@ -616,7 +616,7 @@ symlink_exit:
50164
50165 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
50166 {
50167- char *p = nd_get_link(nd);
50168+ const char *p = nd_get_link(nd);
50169 if (!IS_ERR(p))
50170 kfree(p);
50171 }
50172diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
50173index 1bec014..f329411 100644
50174--- a/fs/cifs/misc.c
50175+++ b/fs/cifs/misc.c
50176@@ -169,7 +169,7 @@ cifs_buf_get(void)
50177 memset(ret_buf, 0, buf_size + 3);
50178 atomic_inc(&bufAllocCount);
50179 #ifdef CONFIG_CIFS_STATS2
50180- atomic_inc(&totBufAllocCount);
50181+ atomic_inc_unchecked(&totBufAllocCount);
50182 #endif /* CONFIG_CIFS_STATS2 */
50183 }
50184
50185@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
50186 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
50187 atomic_inc(&smBufAllocCount);
50188 #ifdef CONFIG_CIFS_STATS2
50189- atomic_inc(&totSmBufAllocCount);
50190+ atomic_inc_unchecked(&totSmBufAllocCount);
50191 #endif /* CONFIG_CIFS_STATS2 */
50192
50193 }
50194diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
50195index 3efdb9d..e845a5e 100644
50196--- a/fs/cifs/smb1ops.c
50197+++ b/fs/cifs/smb1ops.c
50198@@ -591,27 +591,27 @@ static void
50199 cifs_clear_stats(struct cifs_tcon *tcon)
50200 {
50201 #ifdef CONFIG_CIFS_STATS
50202- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
50203- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
50204- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
50205- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50206- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
50207- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
50208- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50209- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
50210- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
50211- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
50212- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
50213- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
50214- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
50215- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
50216- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
50217- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
50218- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
50219- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
50220- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
50221- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
50222- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
50223+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50224+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50225+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50226+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50227+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50228+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50229+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50230+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50231+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50232+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50233+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50234+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50235+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50236+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50237+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50238+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50239+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50240+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50241+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50242+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50243+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50244 #endif
50245 }
50246
50247@@ -620,36 +620,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50248 {
50249 #ifdef CONFIG_CIFS_STATS
50250 seq_printf(m, " Oplocks breaks: %d",
50251- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50252+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50253 seq_printf(m, "\nReads: %d Bytes: %llu",
50254- atomic_read(&tcon->stats.cifs_stats.num_reads),
50255+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50256 (long long)(tcon->bytes_read));
50257 seq_printf(m, "\nWrites: %d Bytes: %llu",
50258- atomic_read(&tcon->stats.cifs_stats.num_writes),
50259+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50260 (long long)(tcon->bytes_written));
50261 seq_printf(m, "\nFlushes: %d",
50262- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50263+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50264 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50265- atomic_read(&tcon->stats.cifs_stats.num_locks),
50266- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50267- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50268+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50269+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50270+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50271 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50272- atomic_read(&tcon->stats.cifs_stats.num_opens),
50273- atomic_read(&tcon->stats.cifs_stats.num_closes),
50274- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50275+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50276+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50277+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50278 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50279- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50280- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50281+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50282+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50283 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50284- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50285- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50286+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50287+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50288 seq_printf(m, "\nRenames: %d T2 Renames %d",
50289- atomic_read(&tcon->stats.cifs_stats.num_renames),
50290- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50291+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50292+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50293 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50294- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50295- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50296- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50297+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50298+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50299+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50300 #endif
50301 }
50302
50303diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50304index f2e76f3..c44fac7 100644
50305--- a/fs/cifs/smb2ops.c
50306+++ b/fs/cifs/smb2ops.c
50307@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50308 #ifdef CONFIG_CIFS_STATS
50309 int i;
50310 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50311- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50312- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50313+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50314+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50315 }
50316 #endif
50317 }
50318@@ -284,66 +284,66 @@ static void
50319 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50320 {
50321 #ifdef CONFIG_CIFS_STATS
50322- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50323- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50324+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50325+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50326 seq_printf(m, "\nNegotiates: %d sent %d failed",
50327- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50328- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50329+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50330+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50331 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50332- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50333- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50334+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50335+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50336 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50337 seq_printf(m, "\nLogoffs: %d sent %d failed",
50338- atomic_read(&sent[SMB2_LOGOFF_HE]),
50339- atomic_read(&failed[SMB2_LOGOFF_HE]));
50340+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50341+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50342 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50343- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50344- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50345+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50346+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50347 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50348- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50349- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50350+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50351+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50352 seq_printf(m, "\nCreates: %d sent %d failed",
50353- atomic_read(&sent[SMB2_CREATE_HE]),
50354- atomic_read(&failed[SMB2_CREATE_HE]));
50355+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50356+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50357 seq_printf(m, "\nCloses: %d sent %d failed",
50358- atomic_read(&sent[SMB2_CLOSE_HE]),
50359- atomic_read(&failed[SMB2_CLOSE_HE]));
50360+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50361+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50362 seq_printf(m, "\nFlushes: %d sent %d failed",
50363- atomic_read(&sent[SMB2_FLUSH_HE]),
50364- atomic_read(&failed[SMB2_FLUSH_HE]));
50365+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50366+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50367 seq_printf(m, "\nReads: %d sent %d failed",
50368- atomic_read(&sent[SMB2_READ_HE]),
50369- atomic_read(&failed[SMB2_READ_HE]));
50370+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50371+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50372 seq_printf(m, "\nWrites: %d sent %d failed",
50373- atomic_read(&sent[SMB2_WRITE_HE]),
50374- atomic_read(&failed[SMB2_WRITE_HE]));
50375+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50376+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50377 seq_printf(m, "\nLocks: %d sent %d failed",
50378- atomic_read(&sent[SMB2_LOCK_HE]),
50379- atomic_read(&failed[SMB2_LOCK_HE]));
50380+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50381+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50382 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50383- atomic_read(&sent[SMB2_IOCTL_HE]),
50384- atomic_read(&failed[SMB2_IOCTL_HE]));
50385+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50386+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50387 seq_printf(m, "\nCancels: %d sent %d failed",
50388- atomic_read(&sent[SMB2_CANCEL_HE]),
50389- atomic_read(&failed[SMB2_CANCEL_HE]));
50390+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50391+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50392 seq_printf(m, "\nEchos: %d sent %d failed",
50393- atomic_read(&sent[SMB2_ECHO_HE]),
50394- atomic_read(&failed[SMB2_ECHO_HE]));
50395+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50396+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50397 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50398- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50399- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50400+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50401+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50402 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50403- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50404- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50405+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50406+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50407 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50408- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50409- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50410+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50411+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50412 seq_printf(m, "\nSetInfos: %d sent %d failed",
50413- atomic_read(&sent[SMB2_SET_INFO_HE]),
50414- atomic_read(&failed[SMB2_SET_INFO_HE]));
50415+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50416+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50417 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50418- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50419- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50420+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50421+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50422 #endif
50423 }
50424
50425diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50426index 2b95ce2..d079d75 100644
50427--- a/fs/cifs/smb2pdu.c
50428+++ b/fs/cifs/smb2pdu.c
50429@@ -1760,8 +1760,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50430 default:
50431 cifs_dbg(VFS, "info level %u isn't supported\n",
50432 srch_inf->info_level);
50433- rc = -EINVAL;
50434- goto qdir_exit;
50435+ return -EINVAL;
50436 }
50437
50438 req->FileIndex = cpu_to_le32(index);
50439diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50440index 1da168c..8bc7ff6 100644
50441--- a/fs/coda/cache.c
50442+++ b/fs/coda/cache.c
50443@@ -24,7 +24,7 @@
50444 #include "coda_linux.h"
50445 #include "coda_cache.h"
50446
50447-static atomic_t permission_epoch = ATOMIC_INIT(0);
50448+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50449
50450 /* replace or extend an acl cache hit */
50451 void coda_cache_enter(struct inode *inode, int mask)
50452@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50453 struct coda_inode_info *cii = ITOC(inode);
50454
50455 spin_lock(&cii->c_lock);
50456- cii->c_cached_epoch = atomic_read(&permission_epoch);
50457+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50458 if (!uid_eq(cii->c_uid, current_fsuid())) {
50459 cii->c_uid = current_fsuid();
50460 cii->c_cached_perm = mask;
50461@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50462 {
50463 struct coda_inode_info *cii = ITOC(inode);
50464 spin_lock(&cii->c_lock);
50465- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50466+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50467 spin_unlock(&cii->c_lock);
50468 }
50469
50470 /* remove all acl caches */
50471 void coda_cache_clear_all(struct super_block *sb)
50472 {
50473- atomic_inc(&permission_epoch);
50474+ atomic_inc_unchecked(&permission_epoch);
50475 }
50476
50477
50478@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50479 spin_lock(&cii->c_lock);
50480 hit = (mask & cii->c_cached_perm) == mask &&
50481 uid_eq(cii->c_uid, current_fsuid()) &&
50482- cii->c_cached_epoch == atomic_read(&permission_epoch);
50483+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50484 spin_unlock(&cii->c_lock);
50485
50486 return hit;
50487diff --git a/fs/compat.c b/fs/compat.c
50488index fc3b55d..7b568ae 100644
50489--- a/fs/compat.c
50490+++ b/fs/compat.c
50491@@ -54,7 +54,7 @@
50492 #include <asm/ioctls.h>
50493 #include "internal.h"
50494
50495-int compat_log = 1;
50496+int compat_log = 0;
50497
50498 int compat_printk(const char *fmt, ...)
50499 {
50500@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50501
50502 set_fs(KERNEL_DS);
50503 /* The __user pointer cast is valid because of the set_fs() */
50504- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50505+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50506 set_fs(oldfs);
50507 /* truncating is ok because it's a user address */
50508 if (!ret)
50509@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50510 goto out;
50511
50512 ret = -EINVAL;
50513- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50514+ if (nr_segs > UIO_MAXIOV)
50515 goto out;
50516 if (nr_segs > fast_segs) {
50517 ret = -ENOMEM;
50518@@ -833,6 +833,7 @@ struct compat_old_linux_dirent {
50519
50520 struct compat_readdir_callback {
50521 struct compat_old_linux_dirent __user *dirent;
50522+ struct file * file;
50523 int result;
50524 };
50525
50526@@ -850,6 +851,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50527 buf->result = -EOVERFLOW;
50528 return -EOVERFLOW;
50529 }
50530+
50531+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50532+ return 0;
50533+
50534 buf->result++;
50535 dirent = buf->dirent;
50536 if (!access_ok(VERIFY_WRITE, dirent,
50537@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50538
50539 buf.result = 0;
50540 buf.dirent = dirent;
50541+ buf.file = f.file;
50542
50543 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50544 if (buf.result)
50545@@ -899,6 +905,7 @@ struct compat_linux_dirent {
50546 struct compat_getdents_callback {
50547 struct compat_linux_dirent __user *current_dir;
50548 struct compat_linux_dirent __user *previous;
50549+ struct file * file;
50550 int count;
50551 int error;
50552 };
50553@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50554 buf->error = -EOVERFLOW;
50555 return -EOVERFLOW;
50556 }
50557+
50558+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50559+ return 0;
50560+
50561 dirent = buf->previous;
50562 if (dirent) {
50563 if (__put_user(offset, &dirent->d_off))
50564@@ -965,6 +976,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50565 buf.previous = NULL;
50566 buf.count = count;
50567 buf.error = 0;
50568+ buf.file = f.file;
50569
50570 error = vfs_readdir(f.file, compat_filldir, &buf);
50571 if (error >= 0)
50572@@ -985,6 +997,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50573 struct compat_getdents_callback64 {
50574 struct linux_dirent64 __user *current_dir;
50575 struct linux_dirent64 __user *previous;
50576+ struct file * file;
50577 int count;
50578 int error;
50579 };
50580@@ -1001,6 +1014,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50581 buf->error = -EINVAL; /* only used if we fail.. */
50582 if (reclen > buf->count)
50583 return -EINVAL;
50584+
50585+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50586+ return 0;
50587+
50588 dirent = buf->previous;
50589
50590 if (dirent) {
50591@@ -1050,13 +1067,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50592 buf.previous = NULL;
50593 buf.count = count;
50594 buf.error = 0;
50595+ buf.file = f.file;
50596
50597 error = vfs_readdir(f.file, compat_filldir64, &buf);
50598 if (error >= 0)
50599 error = buf.error;
50600 lastdirent = buf.previous;
50601 if (lastdirent) {
50602- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50603+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50604 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50605 error = -EFAULT;
50606 else
50607diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50608index a81147e..20bf2b5 100644
50609--- a/fs/compat_binfmt_elf.c
50610+++ b/fs/compat_binfmt_elf.c
50611@@ -30,11 +30,13 @@
50612 #undef elf_phdr
50613 #undef elf_shdr
50614 #undef elf_note
50615+#undef elf_dyn
50616 #undef elf_addr_t
50617 #define elfhdr elf32_hdr
50618 #define elf_phdr elf32_phdr
50619 #define elf_shdr elf32_shdr
50620 #define elf_note elf32_note
50621+#define elf_dyn Elf32_Dyn
50622 #define elf_addr_t Elf32_Addr
50623
50624 /*
50625diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50626index 996cdc5..15e2f33 100644
50627--- a/fs/compat_ioctl.c
50628+++ b/fs/compat_ioctl.c
50629@@ -622,7 +622,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50630 return -EFAULT;
50631 if (__get_user(udata, &ss32->iomem_base))
50632 return -EFAULT;
50633- ss.iomem_base = compat_ptr(udata);
50634+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50635 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50636 __get_user(ss.port_high, &ss32->port_high))
50637 return -EFAULT;
50638@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
50639 for (i = 0; i < nmsgs; i++) {
50640 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
50641 return -EFAULT;
50642- if (get_user(datap, &umsgs[i].buf) ||
50643- put_user(compat_ptr(datap), &tmsgs[i].buf))
50644+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
50645+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
50646 return -EFAULT;
50647 }
50648 return sys_ioctl(fd, cmd, (unsigned long)tdata);
50649@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
50650 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50651 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50652 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50653- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50654+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50655 return -EFAULT;
50656
50657 return ioctl_preallocate(file, p);
50658@@ -1619,8 +1619,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50659 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50660 {
50661 unsigned int a, b;
50662- a = *(unsigned int *)p;
50663- b = *(unsigned int *)q;
50664+ a = *(const unsigned int *)p;
50665+ b = *(const unsigned int *)q;
50666 if (a > b)
50667 return 1;
50668 if (a < b)
50669diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50670index 7aabc6a..34c1197 100644
50671--- a/fs/configfs/dir.c
50672+++ b/fs/configfs/dir.c
50673@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50674 }
50675 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50676 struct configfs_dirent *next;
50677- const char * name;
50678+ const unsigned char * name;
50679+ char d_name[sizeof(next->s_dentry->d_iname)];
50680 int len;
50681 struct inode *inode = NULL;
50682
50683@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50684 continue;
50685
50686 name = configfs_get_name(next);
50687- len = strlen(name);
50688+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50689+ len = next->s_dentry->d_name.len;
50690+ memcpy(d_name, name, len);
50691+ name = d_name;
50692+ } else
50693+ len = strlen(name);
50694
50695 /*
50696 * We'll have a dentry and an inode for
50697diff --git a/fs/coredump.c b/fs/coredump.c
50698index dafafba..10b3b27 100644
50699--- a/fs/coredump.c
50700+++ b/fs/coredump.c
50701@@ -52,7 +52,7 @@ struct core_name {
50702 char *corename;
50703 int used, size;
50704 };
50705-static atomic_t call_count = ATOMIC_INIT(1);
50706+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50707
50708 /* The maximal length of core_pattern is also specified in sysctl.c */
50709
50710@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50711 {
50712 char *old_corename = cn->corename;
50713
50714- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50715+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50716 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50717
50718 if (!cn->corename) {
50719@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50720 int pid_in_pattern = 0;
50721 int err = 0;
50722
50723- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50724+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50725 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50726 cn->used = 0;
50727
50728@@ -435,8 +435,8 @@ static void wait_for_dump_helpers(struct file *file)
50729 struct pipe_inode_info *pipe = file->private_data;
50730
50731 pipe_lock(pipe);
50732- pipe->readers++;
50733- pipe->writers--;
50734+ atomic_inc(&pipe->readers);
50735+ atomic_dec(&pipe->writers);
50736 wake_up_interruptible_sync(&pipe->wait);
50737 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50738 pipe_unlock(pipe);
50739@@ -445,11 +445,11 @@ static void wait_for_dump_helpers(struct file *file)
50740 * We actually want wait_event_freezable() but then we need
50741 * to clear TIF_SIGPENDING and improve dump_interrupted().
50742 */
50743- wait_event_interruptible(pipe->wait, pipe->readers == 1);
50744+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
50745
50746 pipe_lock(pipe);
50747- pipe->readers--;
50748- pipe->writers++;
50749+ atomic_dec(&pipe->readers);
50750+ atomic_inc(&pipe->writers);
50751 pipe_unlock(pipe);
50752 }
50753
50754@@ -496,7 +496,8 @@ void do_coredump(siginfo_t *siginfo)
50755 struct files_struct *displaced;
50756 bool need_nonrelative = false;
50757 bool core_dumped = false;
50758- static atomic_t core_dump_count = ATOMIC_INIT(0);
50759+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50760+ long signr = siginfo->si_signo;
50761 struct coredump_params cprm = {
50762 .siginfo = siginfo,
50763 .regs = signal_pt_regs(),
50764@@ -509,7 +510,10 @@ void do_coredump(siginfo_t *siginfo)
50765 .mm_flags = mm->flags,
50766 };
50767
50768- audit_core_dumps(siginfo->si_signo);
50769+ audit_core_dumps(signr);
50770+
50771+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50772+ gr_handle_brute_attach(cprm.mm_flags);
50773
50774 binfmt = mm->binfmt;
50775 if (!binfmt || !binfmt->core_dump)
50776@@ -533,7 +537,7 @@ void do_coredump(siginfo_t *siginfo)
50777 need_nonrelative = true;
50778 }
50779
50780- retval = coredump_wait(siginfo->si_signo, &core_state);
50781+ retval = coredump_wait(signr, &core_state);
50782 if (retval < 0)
50783 goto fail_creds;
50784
50785@@ -576,7 +580,7 @@ void do_coredump(siginfo_t *siginfo)
50786 }
50787 cprm.limit = RLIM_INFINITY;
50788
50789- dump_count = atomic_inc_return(&core_dump_count);
50790+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50791 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50792 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50793 task_tgid_vnr(current), current->comm);
50794@@ -608,6 +612,8 @@ void do_coredump(siginfo_t *siginfo)
50795 } else {
50796 struct inode *inode;
50797
50798+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50799+
50800 if (cprm.limit < binfmt->min_coredump)
50801 goto fail_unlock;
50802
50803@@ -666,7 +672,7 @@ close_fail:
50804 filp_close(cprm.file, NULL);
50805 fail_dropcount:
50806 if (ispipe)
50807- atomic_dec(&core_dump_count);
50808+ atomic_dec_unchecked(&core_dump_count);
50809 fail_unlock:
50810 kfree(cn.corename);
50811 fail_corename:
50812@@ -687,7 +693,7 @@ int dump_write(struct file *file, const void *addr, int nr)
50813 {
50814 return !dump_interrupted() &&
50815 access_ok(VERIFY_READ, addr, nr) &&
50816- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50817+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50818 }
50819 EXPORT_SYMBOL(dump_write);
50820
50821diff --git a/fs/dcache.c b/fs/dcache.c
50822index f09b908..04b9690 100644
50823--- a/fs/dcache.c
50824+++ b/fs/dcache.c
50825@@ -3086,7 +3086,8 @@ void __init vfs_caches_init(unsigned long mempages)
50826 mempages -= reserve;
50827
50828 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50829- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50830+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
50831+ SLAB_NO_SANITIZE, NULL);
50832
50833 dcache_init();
50834 inode_init();
50835diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50836index 4888cb3..e0f7cf8 100644
50837--- a/fs/debugfs/inode.c
50838+++ b/fs/debugfs/inode.c
50839@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50840 */
50841 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50842 {
50843+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50844+ return __create_file(name, S_IFDIR | S_IRWXU,
50845+#else
50846 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50847+#endif
50848 parent, NULL, NULL);
50849 }
50850 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50851diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50852index 5eab400..810a3f5 100644
50853--- a/fs/ecryptfs/inode.c
50854+++ b/fs/ecryptfs/inode.c
50855@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50856 old_fs = get_fs();
50857 set_fs(get_ds());
50858 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50859- (char __user *)lower_buf,
50860+ (char __force_user *)lower_buf,
50861 PATH_MAX);
50862 set_fs(old_fs);
50863 if (rc < 0)
50864@@ -706,7 +706,7 @@ out:
50865 static void
50866 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50867 {
50868- char *buf = nd_get_link(nd);
50869+ const char *buf = nd_get_link(nd);
50870 if (!IS_ERR(buf)) {
50871 /* Free the char* */
50872 kfree(buf);
50873diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50874index e4141f2..d8263e8 100644
50875--- a/fs/ecryptfs/miscdev.c
50876+++ b/fs/ecryptfs/miscdev.c
50877@@ -304,7 +304,7 @@ check_list:
50878 goto out_unlock_msg_ctx;
50879 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50880 if (msg_ctx->msg) {
50881- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50882+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50883 goto out_unlock_msg_ctx;
50884 i += packet_length_size;
50885 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50886diff --git a/fs/exec.c b/fs/exec.c
50887index ffd7a81..d95acf6 100644
50888--- a/fs/exec.c
50889+++ b/fs/exec.c
50890@@ -55,8 +55,20 @@
50891 #include <linux/pipe_fs_i.h>
50892 #include <linux/oom.h>
50893 #include <linux/compat.h>
50894+#include <linux/random.h>
50895+#include <linux/seq_file.h>
50896+#include <linux/coredump.h>
50897+#include <linux/mman.h>
50898+
50899+#ifdef CONFIG_PAX_REFCOUNT
50900+#include <linux/kallsyms.h>
50901+#include <linux/kdebug.h>
50902+#endif
50903+
50904+#include <trace/events/fs.h>
50905
50906 #include <asm/uaccess.h>
50907+#include <asm/sections.h>
50908 #include <asm/mmu_context.h>
50909 #include <asm/tlb.h>
50910
50911@@ -66,17 +78,32 @@
50912
50913 #include <trace/events/sched.h>
50914
50915+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50916+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50917+{
50918+ 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");
50919+}
50920+#endif
50921+
50922+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50923+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50924+EXPORT_SYMBOL(pax_set_initial_flags_func);
50925+#endif
50926+
50927 int suid_dumpable = 0;
50928
50929 static LIST_HEAD(formats);
50930 static DEFINE_RWLOCK(binfmt_lock);
50931
50932+extern int gr_process_kernel_exec_ban(void);
50933+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
50934+
50935 void __register_binfmt(struct linux_binfmt * fmt, int insert)
50936 {
50937 BUG_ON(!fmt);
50938 write_lock(&binfmt_lock);
50939- insert ? list_add(&fmt->lh, &formats) :
50940- list_add_tail(&fmt->lh, &formats);
50941+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50942+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50943 write_unlock(&binfmt_lock);
50944 }
50945
50946@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
50947 void unregister_binfmt(struct linux_binfmt * fmt)
50948 {
50949 write_lock(&binfmt_lock);
50950- list_del(&fmt->lh);
50951+ pax_list_del((struct list_head *)&fmt->lh);
50952 write_unlock(&binfmt_lock);
50953 }
50954
50955@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50956 int write)
50957 {
50958 struct page *page;
50959- int ret;
50960
50961-#ifdef CONFIG_STACK_GROWSUP
50962- if (write) {
50963- ret = expand_downwards(bprm->vma, pos);
50964- if (ret < 0)
50965- return NULL;
50966- }
50967-#endif
50968- ret = get_user_pages(current, bprm->mm, pos,
50969- 1, write, 1, &page, NULL);
50970- if (ret <= 0)
50971+ if (0 > expand_downwards(bprm->vma, pos))
50972+ return NULL;
50973+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50974 return NULL;
50975
50976 if (write) {
50977@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50978 if (size <= ARG_MAX)
50979 return page;
50980
50981+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50982+ // only allow 512KB for argv+env on suid/sgid binaries
50983+ // to prevent easy ASLR exhaustion
50984+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50985+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50986+ (size > (512 * 1024))) {
50987+ put_page(page);
50988+ return NULL;
50989+ }
50990+#endif
50991+
50992 /*
50993 * Limit to 1/4-th the stack size for the argv+env strings.
50994 * This ensures that:
50995@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50996 vma->vm_end = STACK_TOP_MAX;
50997 vma->vm_start = vma->vm_end - PAGE_SIZE;
50998 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50999+
51000+#ifdef CONFIG_PAX_SEGMEXEC
51001+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
51002+#endif
51003+
51004 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
51005 INIT_LIST_HEAD(&vma->anon_vma_chain);
51006
51007@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
51008 mm->stack_vm = mm->total_vm = 1;
51009 up_write(&mm->mmap_sem);
51010 bprm->p = vma->vm_end - sizeof(void *);
51011+
51012+#ifdef CONFIG_PAX_RANDUSTACK
51013+ if (randomize_va_space)
51014+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
51015+#endif
51016+
51017 return 0;
51018 err:
51019 up_write(&mm->mmap_sem);
51020@@ -396,7 +437,7 @@ struct user_arg_ptr {
51021 } ptr;
51022 };
51023
51024-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
51025+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
51026 {
51027 const char __user *native;
51028
51029@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
51030 compat_uptr_t compat;
51031
51032 if (get_user(compat, argv.ptr.compat + nr))
51033- return ERR_PTR(-EFAULT);
51034+ return (const char __force_user *)ERR_PTR(-EFAULT);
51035
51036 return compat_ptr(compat);
51037 }
51038 #endif
51039
51040 if (get_user(native, argv.ptr.native + nr))
51041- return ERR_PTR(-EFAULT);
51042+ return (const char __force_user *)ERR_PTR(-EFAULT);
51043
51044 return native;
51045 }
51046@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
51047 if (!p)
51048 break;
51049
51050- if (IS_ERR(p))
51051+ if (IS_ERR((const char __force_kernel *)p))
51052 return -EFAULT;
51053
51054 if (i >= max)
51055@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
51056
51057 ret = -EFAULT;
51058 str = get_user_arg_ptr(argv, argc);
51059- if (IS_ERR(str))
51060+ if (IS_ERR((const char __force_kernel *)str))
51061 goto out;
51062
51063 len = strnlen_user(str, MAX_ARG_STRLEN);
51064@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
51065 int r;
51066 mm_segment_t oldfs = get_fs();
51067 struct user_arg_ptr argv = {
51068- .ptr.native = (const char __user *const __user *)__argv,
51069+ .ptr.native = (const char __force_user * const __force_user *)__argv,
51070 };
51071
51072 set_fs(KERNEL_DS);
51073@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51074 unsigned long new_end = old_end - shift;
51075 struct mmu_gather tlb;
51076
51077- BUG_ON(new_start > new_end);
51078+ if (new_start >= new_end || new_start < mmap_min_addr)
51079+ return -ENOMEM;
51080
51081 /*
51082 * ensure there are no vmas between where we want to go
51083@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
51084 if (vma != find_vma(mm, new_start))
51085 return -EFAULT;
51086
51087+#ifdef CONFIG_PAX_SEGMEXEC
51088+ BUG_ON(pax_find_mirror_vma(vma));
51089+#endif
51090+
51091 /*
51092 * cover the whole range: [new_start, old_end)
51093 */
51094@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51095 stack_top = arch_align_stack(stack_top);
51096 stack_top = PAGE_ALIGN(stack_top);
51097
51098- if (unlikely(stack_top < mmap_min_addr) ||
51099- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
51100- return -ENOMEM;
51101-
51102 stack_shift = vma->vm_end - stack_top;
51103
51104 bprm->p -= stack_shift;
51105@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
51106 bprm->exec -= stack_shift;
51107
51108 down_write(&mm->mmap_sem);
51109+
51110+ /* Move stack pages down in memory. */
51111+ if (stack_shift) {
51112+ ret = shift_arg_pages(vma, stack_shift);
51113+ if (ret)
51114+ goto out_unlock;
51115+ }
51116+
51117 vm_flags = VM_STACK_FLAGS;
51118
51119+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51120+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
51121+ vm_flags &= ~VM_EXEC;
51122+
51123+#ifdef CONFIG_PAX_MPROTECT
51124+ if (mm->pax_flags & MF_PAX_MPROTECT)
51125+ vm_flags &= ~VM_MAYEXEC;
51126+#endif
51127+
51128+ }
51129+#endif
51130+
51131 /*
51132 * Adjust stack execute permissions; explicitly enable for
51133 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
51134@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
51135 goto out_unlock;
51136 BUG_ON(prev != vma);
51137
51138- /* Move stack pages down in memory. */
51139- if (stack_shift) {
51140- ret = shift_arg_pages(vma, stack_shift);
51141- if (ret)
51142- goto out_unlock;
51143- }
51144-
51145 /* mprotect_fixup is overkill to remove the temporary stack flags */
51146 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
51147
51148@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
51149 #endif
51150 current->mm->start_stack = bprm->p;
51151 ret = expand_stack(vma, stack_base);
51152+
51153+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
51154+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
51155+ unsigned long size;
51156+ vm_flags_t vm_flags;
51157+
51158+ size = STACK_TOP - vma->vm_end;
51159+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
51160+
51161+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
51162+
51163+#ifdef CONFIG_X86
51164+ if (!ret) {
51165+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
51166+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
51167+ }
51168+#endif
51169+
51170+ }
51171+#endif
51172+
51173 if (ret)
51174 ret = -EFAULT;
51175
51176@@ -772,6 +848,8 @@ struct file *open_exec(const char *name)
51177
51178 fsnotify_open(file);
51179
51180+ trace_open_exec(name);
51181+
51182 err = deny_write_access(file);
51183 if (err)
51184 goto exit;
51185@@ -795,7 +873,7 @@ int kernel_read(struct file *file, loff_t offset,
51186 old_fs = get_fs();
51187 set_fs(get_ds());
51188 /* The cast to a user pointer is valid due to the set_fs() */
51189- result = vfs_read(file, (void __user *)addr, count, &pos);
51190+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
51191 set_fs(old_fs);
51192 return result;
51193 }
51194@@ -1251,7 +1329,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
51195 }
51196 rcu_read_unlock();
51197
51198- if (p->fs->users > n_fs) {
51199+ if (atomic_read(&p->fs->users) > n_fs) {
51200 bprm->unsafe |= LSM_UNSAFE_SHARE;
51201 } else {
51202 res = -EAGAIN;
51203@@ -1451,6 +1529,31 @@ int search_binary_handler(struct linux_binprm *bprm)
51204
51205 EXPORT_SYMBOL(search_binary_handler);
51206
51207+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51208+static DEFINE_PER_CPU(u64, exec_counter);
51209+static int __init init_exec_counters(void)
51210+{
51211+ unsigned int cpu;
51212+
51213+ for_each_possible_cpu(cpu) {
51214+ per_cpu(exec_counter, cpu) = (u64)cpu;
51215+ }
51216+
51217+ return 0;
51218+}
51219+early_initcall(init_exec_counters);
51220+static inline void increment_exec_counter(void)
51221+{
51222+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
51223+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
51224+}
51225+#else
51226+static inline void increment_exec_counter(void) {}
51227+#endif
51228+
51229+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51230+ struct user_arg_ptr argv);
51231+
51232 /*
51233 * sys_execve() executes a new program.
51234 */
51235@@ -1458,6 +1561,11 @@ static int do_execve_common(const char *filename,
51236 struct user_arg_ptr argv,
51237 struct user_arg_ptr envp)
51238 {
51239+#ifdef CONFIG_GRKERNSEC
51240+ struct file *old_exec_file;
51241+ struct acl_subject_label *old_acl;
51242+ struct rlimit old_rlim[RLIM_NLIMITS];
51243+#endif
51244 struct linux_binprm *bprm;
51245 struct file *file;
51246 struct files_struct *displaced;
51247@@ -1465,6 +1573,8 @@ static int do_execve_common(const char *filename,
51248 int retval;
51249 const struct cred *cred = current_cred();
51250
51251+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
51252+
51253 /*
51254 * We move the actual failure in case of RLIMIT_NPROC excess from
51255 * set*uid() to execve() because too many poorly written programs
51256@@ -1505,12 +1615,22 @@ static int do_execve_common(const char *filename,
51257 if (IS_ERR(file))
51258 goto out_unmark;
51259
51260+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51261+ retval = -EPERM;
51262+ goto out_file;
51263+ }
51264+
51265 sched_exec();
51266
51267 bprm->file = file;
51268 bprm->filename = filename;
51269 bprm->interp = filename;
51270
51271+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
51272+ retval = -EACCES;
51273+ goto out_file;
51274+ }
51275+
51276 retval = bprm_mm_init(bprm);
51277 if (retval)
51278 goto out_file;
51279@@ -1527,24 +1647,70 @@ static int do_execve_common(const char *filename,
51280 if (retval < 0)
51281 goto out;
51282
51283+#ifdef CONFIG_GRKERNSEC
51284+ old_acl = current->acl;
51285+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51286+ old_exec_file = current->exec_file;
51287+ get_file(file);
51288+ current->exec_file = file;
51289+#endif
51290+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51291+ /* limit suid stack to 8MB
51292+ * we saved the old limits above and will restore them if this exec fails
51293+ */
51294+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51295+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51296+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51297+#endif
51298+
51299+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
51300+ retval = -EPERM;
51301+ goto out_fail;
51302+ }
51303+
51304+ if (!gr_tpe_allow(file)) {
51305+ retval = -EACCES;
51306+ goto out_fail;
51307+ }
51308+
51309+ if (gr_check_crash_exec(file)) {
51310+ retval = -EACCES;
51311+ goto out_fail;
51312+ }
51313+
51314+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
51315+ bprm->unsafe);
51316+ if (retval < 0)
51317+ goto out_fail;
51318+
51319 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51320 if (retval < 0)
51321- goto out;
51322+ goto out_fail;
51323
51324 bprm->exec = bprm->p;
51325 retval = copy_strings(bprm->envc, envp, bprm);
51326 if (retval < 0)
51327- goto out;
51328+ goto out_fail;
51329
51330 retval = copy_strings(bprm->argc, argv, bprm);
51331 if (retval < 0)
51332- goto out;
51333+ goto out_fail;
51334+
51335+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
51336+
51337+ gr_handle_exec_args(bprm, argv);
51338
51339 retval = search_binary_handler(bprm);
51340 if (retval < 0)
51341- goto out;
51342+ goto out_fail;
51343+#ifdef CONFIG_GRKERNSEC
51344+ if (old_exec_file)
51345+ fput(old_exec_file);
51346+#endif
51347
51348 /* execve succeeded */
51349+
51350+ increment_exec_counter();
51351 current->fs->in_exec = 0;
51352 current->in_execve = 0;
51353 acct_update_integrals(current);
51354@@ -1553,6 +1719,14 @@ static int do_execve_common(const char *filename,
51355 put_files_struct(displaced);
51356 return retval;
51357
51358+out_fail:
51359+#ifdef CONFIG_GRKERNSEC
51360+ current->acl = old_acl;
51361+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51362+ fput(current->exec_file);
51363+ current->exec_file = old_exec_file;
51364+#endif
51365+
51366 out:
51367 if (bprm->mm) {
51368 acct_arg_size(bprm, 0);
51369@@ -1701,3 +1875,285 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51370 return error;
51371 }
51372 #endif
51373+
51374+int pax_check_flags(unsigned long *flags)
51375+{
51376+ int retval = 0;
51377+
51378+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51379+ if (*flags & MF_PAX_SEGMEXEC)
51380+ {
51381+ *flags &= ~MF_PAX_SEGMEXEC;
51382+ retval = -EINVAL;
51383+ }
51384+#endif
51385+
51386+ if ((*flags & MF_PAX_PAGEEXEC)
51387+
51388+#ifdef CONFIG_PAX_PAGEEXEC
51389+ && (*flags & MF_PAX_SEGMEXEC)
51390+#endif
51391+
51392+ )
51393+ {
51394+ *flags &= ~MF_PAX_PAGEEXEC;
51395+ retval = -EINVAL;
51396+ }
51397+
51398+ if ((*flags & MF_PAX_MPROTECT)
51399+
51400+#ifdef CONFIG_PAX_MPROTECT
51401+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51402+#endif
51403+
51404+ )
51405+ {
51406+ *flags &= ~MF_PAX_MPROTECT;
51407+ retval = -EINVAL;
51408+ }
51409+
51410+ if ((*flags & MF_PAX_EMUTRAMP)
51411+
51412+#ifdef CONFIG_PAX_EMUTRAMP
51413+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51414+#endif
51415+
51416+ )
51417+ {
51418+ *flags &= ~MF_PAX_EMUTRAMP;
51419+ retval = -EINVAL;
51420+ }
51421+
51422+ return retval;
51423+}
51424+
51425+EXPORT_SYMBOL(pax_check_flags);
51426+
51427+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51428+char *pax_get_path(const struct path *path, char *buf, int buflen)
51429+{
51430+ char *pathname = d_path(path, buf, buflen);
51431+
51432+ if (IS_ERR(pathname))
51433+ goto toolong;
51434+
51435+ pathname = mangle_path(buf, pathname, "\t\n\\");
51436+ if (!pathname)
51437+ goto toolong;
51438+
51439+ *pathname = 0;
51440+ return buf;
51441+
51442+toolong:
51443+ return "<path too long>";
51444+}
51445+EXPORT_SYMBOL(pax_get_path);
51446+
51447+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51448+{
51449+ struct task_struct *tsk = current;
51450+ struct mm_struct *mm = current->mm;
51451+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51452+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51453+ char *path_exec = NULL;
51454+ char *path_fault = NULL;
51455+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51456+ siginfo_t info = { };
51457+
51458+ if (buffer_exec && buffer_fault) {
51459+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51460+
51461+ down_read(&mm->mmap_sem);
51462+ vma = mm->mmap;
51463+ while (vma && (!vma_exec || !vma_fault)) {
51464+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51465+ vma_exec = vma;
51466+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51467+ vma_fault = vma;
51468+ vma = vma->vm_next;
51469+ }
51470+ if (vma_exec)
51471+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51472+ if (vma_fault) {
51473+ start = vma_fault->vm_start;
51474+ end = vma_fault->vm_end;
51475+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51476+ if (vma_fault->vm_file)
51477+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51478+ else if (pc >= mm->start_brk && pc < mm->brk)
51479+ path_fault = "<heap>";
51480+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
51481+ path_fault = "<stack>";
51482+ else
51483+ path_fault = "<anonymous mapping>";
51484+ }
51485+ up_read(&mm->mmap_sem);
51486+ }
51487+ if (tsk->signal->curr_ip)
51488+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51489+ else
51490+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51491+ 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),
51492+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51493+ free_page((unsigned long)buffer_exec);
51494+ free_page((unsigned long)buffer_fault);
51495+ pax_report_insns(regs, pc, sp);
51496+ info.si_signo = SIGKILL;
51497+ info.si_errno = 0;
51498+ info.si_code = SI_KERNEL;
51499+ info.si_pid = 0;
51500+ info.si_uid = 0;
51501+ do_coredump(&info);
51502+}
51503+#endif
51504+
51505+#ifdef CONFIG_PAX_REFCOUNT
51506+void pax_report_refcount_overflow(struct pt_regs *regs)
51507+{
51508+ if (current->signal->curr_ip)
51509+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51510+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51511+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51512+ else
51513+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51514+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51515+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51516+ show_regs(regs);
51517+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51518+}
51519+#endif
51520+
51521+#ifdef CONFIG_PAX_USERCOPY
51522+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51523+static noinline int check_stack_object(const void *obj, unsigned long len)
51524+{
51525+ const void * const stack = task_stack_page(current);
51526+ const void * const stackend = stack + THREAD_SIZE;
51527+
51528+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51529+ const void *frame = NULL;
51530+ const void *oldframe;
51531+#endif
51532+
51533+ if (obj + len < obj)
51534+ return -1;
51535+
51536+ if (obj + len <= stack || stackend <= obj)
51537+ return 0;
51538+
51539+ if (obj < stack || stackend < obj + len)
51540+ return -1;
51541+
51542+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51543+ oldframe = __builtin_frame_address(1);
51544+ if (oldframe)
51545+ frame = __builtin_frame_address(2);
51546+ /*
51547+ low ----------------------------------------------> high
51548+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51549+ ^----------------^
51550+ allow copies only within here
51551+ */
51552+ while (stack <= frame && frame < stackend) {
51553+ /* if obj + len extends past the last frame, this
51554+ check won't pass and the next frame will be 0,
51555+ causing us to bail out and correctly report
51556+ the copy as invalid
51557+ */
51558+ if (obj + len <= frame)
51559+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51560+ oldframe = frame;
51561+ frame = *(const void * const *)frame;
51562+ }
51563+ return -1;
51564+#else
51565+ return 1;
51566+#endif
51567+}
51568+
51569+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51570+{
51571+ if (current->signal->curr_ip)
51572+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51573+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51574+ else
51575+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51576+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51577+ dump_stack();
51578+ gr_handle_kernel_exploit();
51579+ do_group_exit(SIGKILL);
51580+}
51581+#endif
51582+
51583+#ifdef CONFIG_PAX_USERCOPY
51584+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51585+{
51586+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51587+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51588+#ifdef CONFIG_MODULES
51589+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
51590+#else
51591+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51592+#endif
51593+
51594+#else
51595+ unsigned long textlow = (unsigned long)_stext;
51596+ unsigned long texthigh = (unsigned long)_etext;
51597+#endif
51598+
51599+ if (high <= textlow || low > texthigh)
51600+ return false;
51601+ else
51602+ return true;
51603+}
51604+#endif
51605+
51606+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51607+{
51608+
51609+#ifdef CONFIG_PAX_USERCOPY
51610+ const char *type;
51611+
51612+ if (!n)
51613+ return;
51614+
51615+ type = check_heap_object(ptr, n);
51616+ if (!type) {
51617+ int ret = check_stack_object(ptr, n);
51618+ if (ret == 1 || ret == 2)
51619+ return;
51620+ if (ret == 0) {
51621+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51622+ type = "<kernel text>";
51623+ else
51624+ return;
51625+ } else
51626+ type = "<process stack>";
51627+ }
51628+
51629+ pax_report_usercopy(ptr, n, to_user, type);
51630+#endif
51631+
51632+}
51633+EXPORT_SYMBOL(__check_object_size);
51634+
51635+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51636+void pax_track_stack(void)
51637+{
51638+ unsigned long sp = (unsigned long)&sp;
51639+ if (sp < current_thread_info()->lowest_stack &&
51640+ sp > (unsigned long)task_stack_page(current))
51641+ current_thread_info()->lowest_stack = sp;
51642+}
51643+EXPORT_SYMBOL(pax_track_stack);
51644+#endif
51645+
51646+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51647+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51648+{
51649+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51650+ dump_stack();
51651+ do_group_exit(SIGKILL);
51652+}
51653+EXPORT_SYMBOL(report_size_overflow);
51654+#endif
51655diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51656index 9f9992b..8b59411 100644
51657--- a/fs/ext2/balloc.c
51658+++ b/fs/ext2/balloc.c
51659@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51660
51661 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51662 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51663- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51664+ if (free_blocks < root_blocks + 1 &&
51665 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51666 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51667- !in_group_p (sbi->s_resgid))) {
51668+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51669 return 0;
51670 }
51671 return 1;
51672diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51673index 22548f5..41521d8 100644
51674--- a/fs/ext3/balloc.c
51675+++ b/fs/ext3/balloc.c
51676@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51677
51678 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51679 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51680- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51681+ if (free_blocks < root_blocks + 1 &&
51682 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51683 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51684- !in_group_p (sbi->s_resgid))) {
51685+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51686 return 0;
51687 }
51688 return 1;
51689diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51690index 3742e4c..69a797f 100644
51691--- a/fs/ext4/balloc.c
51692+++ b/fs/ext4/balloc.c
51693@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51694 /* Hm, nope. Are (enough) root reserved clusters available? */
51695 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51696 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51697- capable(CAP_SYS_RESOURCE) ||
51698- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51699+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51700+ capable_nolog(CAP_SYS_RESOURCE)) {
51701
51702 if (free_clusters >= (nclusters + dirty_clusters +
51703 resv_clusters))
51704diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51705index 5aae3d1..b5da7f8 100644
51706--- a/fs/ext4/ext4.h
51707+++ b/fs/ext4/ext4.h
51708@@ -1252,19 +1252,19 @@ struct ext4_sb_info {
51709 unsigned long s_mb_last_start;
51710
51711 /* stats for buddy allocator */
51712- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51713- atomic_t s_bal_success; /* we found long enough chunks */
51714- atomic_t s_bal_allocated; /* in blocks */
51715- atomic_t s_bal_ex_scanned; /* total extents scanned */
51716- atomic_t s_bal_goals; /* goal hits */
51717- atomic_t s_bal_breaks; /* too long searches */
51718- atomic_t s_bal_2orders; /* 2^order hits */
51719+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51720+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51721+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51722+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51723+ atomic_unchecked_t s_bal_goals; /* goal hits */
51724+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51725+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51726 spinlock_t s_bal_lock;
51727 unsigned long s_mb_buddies_generated;
51728 unsigned long long s_mb_generation_time;
51729- atomic_t s_mb_lost_chunks;
51730- atomic_t s_mb_preallocated;
51731- atomic_t s_mb_discarded;
51732+ atomic_unchecked_t s_mb_lost_chunks;
51733+ atomic_unchecked_t s_mb_preallocated;
51734+ atomic_unchecked_t s_mb_discarded;
51735 atomic_t s_lock_busy;
51736
51737 /* locality groups */
51738diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51739index 59c6750..a549154 100644
51740--- a/fs/ext4/mballoc.c
51741+++ b/fs/ext4/mballoc.c
51742@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51743 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51744
51745 if (EXT4_SB(sb)->s_mb_stats)
51746- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51747+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51748
51749 break;
51750 }
51751@@ -2170,7 +2170,7 @@ repeat:
51752 ac->ac_status = AC_STATUS_CONTINUE;
51753 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51754 cr = 3;
51755- atomic_inc(&sbi->s_mb_lost_chunks);
51756+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51757 goto repeat;
51758 }
51759 }
51760@@ -2678,25 +2678,25 @@ int ext4_mb_release(struct super_block *sb)
51761 if (sbi->s_mb_stats) {
51762 ext4_msg(sb, KERN_INFO,
51763 "mballoc: %u blocks %u reqs (%u success)",
51764- atomic_read(&sbi->s_bal_allocated),
51765- atomic_read(&sbi->s_bal_reqs),
51766- atomic_read(&sbi->s_bal_success));
51767+ atomic_read_unchecked(&sbi->s_bal_allocated),
51768+ atomic_read_unchecked(&sbi->s_bal_reqs),
51769+ atomic_read_unchecked(&sbi->s_bal_success));
51770 ext4_msg(sb, KERN_INFO,
51771 "mballoc: %u extents scanned, %u goal hits, "
51772 "%u 2^N hits, %u breaks, %u lost",
51773- atomic_read(&sbi->s_bal_ex_scanned),
51774- atomic_read(&sbi->s_bal_goals),
51775- atomic_read(&sbi->s_bal_2orders),
51776- atomic_read(&sbi->s_bal_breaks),
51777- atomic_read(&sbi->s_mb_lost_chunks));
51778+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51779+ atomic_read_unchecked(&sbi->s_bal_goals),
51780+ atomic_read_unchecked(&sbi->s_bal_2orders),
51781+ atomic_read_unchecked(&sbi->s_bal_breaks),
51782+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51783 ext4_msg(sb, KERN_INFO,
51784 "mballoc: %lu generated and it took %Lu",
51785 sbi->s_mb_buddies_generated,
51786 sbi->s_mb_generation_time);
51787 ext4_msg(sb, KERN_INFO,
51788 "mballoc: %u preallocated, %u discarded",
51789- atomic_read(&sbi->s_mb_preallocated),
51790- atomic_read(&sbi->s_mb_discarded));
51791+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51792+ atomic_read_unchecked(&sbi->s_mb_discarded));
51793 }
51794
51795 free_percpu(sbi->s_locality_groups);
51796@@ -3150,16 +3150,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51797 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51798
51799 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51800- atomic_inc(&sbi->s_bal_reqs);
51801- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51802+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51803+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51804 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51805- atomic_inc(&sbi->s_bal_success);
51806- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51807+ atomic_inc_unchecked(&sbi->s_bal_success);
51808+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51809 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51810 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51811- atomic_inc(&sbi->s_bal_goals);
51812+ atomic_inc_unchecked(&sbi->s_bal_goals);
51813 if (ac->ac_found > sbi->s_mb_max_to_scan)
51814- atomic_inc(&sbi->s_bal_breaks);
51815+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51816 }
51817
51818 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51819@@ -3559,7 +3559,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51820 trace_ext4_mb_new_inode_pa(ac, pa);
51821
51822 ext4_mb_use_inode_pa(ac, pa);
51823- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51824+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51825
51826 ei = EXT4_I(ac->ac_inode);
51827 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51828@@ -3619,7 +3619,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51829 trace_ext4_mb_new_group_pa(ac, pa);
51830
51831 ext4_mb_use_group_pa(ac, pa);
51832- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51833+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51834
51835 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51836 lg = ac->ac_lg;
51837@@ -3708,7 +3708,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51838 * from the bitmap and continue.
51839 */
51840 }
51841- atomic_add(free, &sbi->s_mb_discarded);
51842+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51843
51844 return err;
51845 }
51846@@ -3726,7 +3726,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51847 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51848 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51849 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51850- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51851+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51852 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51853
51854 return 0;
51855diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
51856index 214461e..3614c89 100644
51857--- a/fs/ext4/mmp.c
51858+++ b/fs/ext4/mmp.c
51859@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
51860 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
51861 const char *function, unsigned int line, const char *msg)
51862 {
51863- __ext4_warning(sb, function, line, msg);
51864+ __ext4_warning(sb, function, line, "%s", msg);
51865 __ext4_warning(sb, function, line,
51866 "MMP failure info: last update time: %llu, last update "
51867 "node: %s, last update device: %s\n",
51868diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
51869index 49d3c01..9579efd 100644
51870--- a/fs/ext4/resize.c
51871+++ b/fs/ext4/resize.c
51872@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
51873 ext4_fsblk_t end = start + input->blocks_count;
51874 ext4_group_t group = input->group;
51875 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
51876- unsigned overhead = ext4_group_overhead_blocks(sb, group);
51877- ext4_fsblk_t metaend = start + overhead;
51878+ unsigned overhead;
51879+ ext4_fsblk_t metaend;
51880 struct buffer_head *bh = NULL;
51881 ext4_grpblk_t free_blocks_count, offset;
51882 int err = -EINVAL;
51883
51884+ if (group != sbi->s_groups_count) {
51885+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51886+ input->group, sbi->s_groups_count);
51887+ return -EINVAL;
51888+ }
51889+
51890+ overhead = ext4_group_overhead_blocks(sb, group);
51891+ metaend = start + overhead;
51892 input->free_blocks_count = free_blocks_count =
51893 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
51894
51895@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
51896 free_blocks_count, input->reserved_blocks);
51897
51898 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
51899- if (group != sbi->s_groups_count)
51900- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51901- input->group, sbi->s_groups_count);
51902- else if (offset != 0)
51903+ if (offset != 0)
51904 ext4_warning(sb, "Last group not full");
51905 else if (input->reserved_blocks > input->blocks_count / 5)
51906 ext4_warning(sb, "Reserved blocks too high (%u)",
51907diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51908index 6681c03..d88cd33 100644
51909--- a/fs/ext4/super.c
51910+++ b/fs/ext4/super.c
51911@@ -1236,7 +1236,7 @@ static ext4_fsblk_t get_sb_block(void **data)
51912 }
51913
51914 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
51915-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51916+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51917 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
51918
51919 #ifdef CONFIG_QUOTA
51920@@ -2372,7 +2372,7 @@ struct ext4_attr {
51921 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51922 const char *, size_t);
51923 int offset;
51924-};
51925+} __do_const;
51926
51927 static int parse_strtoull(const char *buf,
51928 unsigned long long max, unsigned long long *value)
51929diff --git a/fs/fcntl.c b/fs/fcntl.c
51930index 6599222..e7bf0de 100644
51931--- a/fs/fcntl.c
51932+++ b/fs/fcntl.c
51933@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51934 if (err)
51935 return err;
51936
51937+ if (gr_handle_chroot_fowner(pid, type))
51938+ return -ENOENT;
51939+ if (gr_check_protected_task_fowner(pid, type))
51940+ return -EACCES;
51941+
51942 f_modown(filp, pid, type, force);
51943 return 0;
51944 }
51945diff --git a/fs/fhandle.c b/fs/fhandle.c
51946index 999ff5c..41f4109 100644
51947--- a/fs/fhandle.c
51948+++ b/fs/fhandle.c
51949@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51950 } else
51951 retval = 0;
51952 /* copy the mount id */
51953- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51954- sizeof(*mnt_id)) ||
51955+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51956 copy_to_user(ufh, handle,
51957 sizeof(struct file_handle) + handle_bytes))
51958 retval = -EFAULT;
51959diff --git a/fs/file.c b/fs/file.c
51960index 4a78f98..9447397 100644
51961--- a/fs/file.c
51962+++ b/fs/file.c
51963@@ -16,6 +16,7 @@
51964 #include <linux/slab.h>
51965 #include <linux/vmalloc.h>
51966 #include <linux/file.h>
51967+#include <linux/security.h>
51968 #include <linux/fdtable.h>
51969 #include <linux/bitops.h>
51970 #include <linux/interrupt.h>
51971@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51972 if (!file)
51973 return __close_fd(files, fd);
51974
51975+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51976 if (fd >= rlimit(RLIMIT_NOFILE))
51977 return -EBADF;
51978
51979@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51980 if (unlikely(oldfd == newfd))
51981 return -EINVAL;
51982
51983+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51984 if (newfd >= rlimit(RLIMIT_NOFILE))
51985 return -EBADF;
51986
51987@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51988 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51989 {
51990 int err;
51991+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51992 if (from >= rlimit(RLIMIT_NOFILE))
51993 return -EINVAL;
51994 err = alloc_fd(from, flags);
51995diff --git a/fs/filesystems.c b/fs/filesystems.c
51996index 92567d9..fcd8cbf 100644
51997--- a/fs/filesystems.c
51998+++ b/fs/filesystems.c
51999@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
52000 int len = dot ? dot - name : strlen(name);
52001
52002 fs = __get_fs_type(name, len);
52003+#ifdef CONFIG_GRKERNSEC_MODHARDEN
52004+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
52005+#else
52006 if (!fs && (request_module("fs-%.*s", len, name) == 0))
52007+#endif
52008 fs = __get_fs_type(name, len);
52009
52010 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
52011diff --git a/fs/fs_struct.c b/fs/fs_struct.c
52012index d8ac61d..79a36f0 100644
52013--- a/fs/fs_struct.c
52014+++ b/fs/fs_struct.c
52015@@ -4,6 +4,7 @@
52016 #include <linux/path.h>
52017 #include <linux/slab.h>
52018 #include <linux/fs_struct.h>
52019+#include <linux/grsecurity.h>
52020 #include "internal.h"
52021
52022 /*
52023@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
52024 write_seqcount_begin(&fs->seq);
52025 old_root = fs->root;
52026 fs->root = *path;
52027+ gr_set_chroot_entries(current, path);
52028 write_seqcount_end(&fs->seq);
52029 spin_unlock(&fs->lock);
52030 if (old_root.dentry)
52031@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
52032 int hits = 0;
52033 spin_lock(&fs->lock);
52034 write_seqcount_begin(&fs->seq);
52035+ /* this root replacement is only done by pivot_root,
52036+ leave grsec's chroot tagging alone for this task
52037+ so that a pivoted root isn't treated as a chroot
52038+ */
52039 hits += replace_path(&fs->root, old_root, new_root);
52040 hits += replace_path(&fs->pwd, old_root, new_root);
52041 write_seqcount_end(&fs->seq);
52042@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
52043 task_lock(tsk);
52044 spin_lock(&fs->lock);
52045 tsk->fs = NULL;
52046- kill = !--fs->users;
52047+ gr_clear_chroot_entries(tsk);
52048+ kill = !atomic_dec_return(&fs->users);
52049 spin_unlock(&fs->lock);
52050 task_unlock(tsk);
52051 if (kill)
52052@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52053 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
52054 /* We don't need to lock fs - think why ;-) */
52055 if (fs) {
52056- fs->users = 1;
52057+ atomic_set(&fs->users, 1);
52058 fs->in_exec = 0;
52059 spin_lock_init(&fs->lock);
52060 seqcount_init(&fs->seq);
52061@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
52062 spin_lock(&old->lock);
52063 fs->root = old->root;
52064 path_get(&fs->root);
52065+ /* instead of calling gr_set_chroot_entries here,
52066+ we call it from every caller of this function
52067+ */
52068 fs->pwd = old->pwd;
52069 path_get(&fs->pwd);
52070 spin_unlock(&old->lock);
52071@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
52072
52073 task_lock(current);
52074 spin_lock(&fs->lock);
52075- kill = !--fs->users;
52076+ kill = !atomic_dec_return(&fs->users);
52077 current->fs = new_fs;
52078+ gr_set_chroot_entries(current, &new_fs->root);
52079 spin_unlock(&fs->lock);
52080 task_unlock(current);
52081
52082@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
52083
52084 int current_umask(void)
52085 {
52086- return current->fs->umask;
52087+ return current->fs->umask | gr_acl_umask();
52088 }
52089 EXPORT_SYMBOL(current_umask);
52090
52091 /* to be mentioned only in INIT_TASK */
52092 struct fs_struct init_fs = {
52093- .users = 1,
52094+ .users = ATOMIC_INIT(1),
52095 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
52096 .seq = SEQCNT_ZERO,
52097 .umask = 0022,
52098diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
52099index e2cba1f..17a25bb 100644
52100--- a/fs/fscache/cookie.c
52101+++ b/fs/fscache/cookie.c
52102@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
52103 parent ? (char *) parent->def->name : "<no-parent>",
52104 def->name, netfs_data);
52105
52106- fscache_stat(&fscache_n_acquires);
52107+ fscache_stat_unchecked(&fscache_n_acquires);
52108
52109 /* if there's no parent cookie, then we don't create one here either */
52110 if (!parent) {
52111- fscache_stat(&fscache_n_acquires_null);
52112+ fscache_stat_unchecked(&fscache_n_acquires_null);
52113 _leave(" [no parent]");
52114 return NULL;
52115 }
52116@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
52117 /* allocate and initialise a cookie */
52118 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
52119 if (!cookie) {
52120- fscache_stat(&fscache_n_acquires_oom);
52121+ fscache_stat_unchecked(&fscache_n_acquires_oom);
52122 _leave(" [ENOMEM]");
52123 return NULL;
52124 }
52125@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52126
52127 switch (cookie->def->type) {
52128 case FSCACHE_COOKIE_TYPE_INDEX:
52129- fscache_stat(&fscache_n_cookie_index);
52130+ fscache_stat_unchecked(&fscache_n_cookie_index);
52131 break;
52132 case FSCACHE_COOKIE_TYPE_DATAFILE:
52133- fscache_stat(&fscache_n_cookie_data);
52134+ fscache_stat_unchecked(&fscache_n_cookie_data);
52135 break;
52136 default:
52137- fscache_stat(&fscache_n_cookie_special);
52138+ fscache_stat_unchecked(&fscache_n_cookie_special);
52139 break;
52140 }
52141
52142@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
52143 if (fscache_acquire_non_index_cookie(cookie) < 0) {
52144 atomic_dec(&parent->n_children);
52145 __fscache_cookie_put(cookie);
52146- fscache_stat(&fscache_n_acquires_nobufs);
52147+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
52148 _leave(" = NULL");
52149 return NULL;
52150 }
52151 }
52152
52153- fscache_stat(&fscache_n_acquires_ok);
52154+ fscache_stat_unchecked(&fscache_n_acquires_ok);
52155 _leave(" = %p", cookie);
52156 return cookie;
52157 }
52158@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
52159 cache = fscache_select_cache_for_object(cookie->parent);
52160 if (!cache) {
52161 up_read(&fscache_addremove_sem);
52162- fscache_stat(&fscache_n_acquires_no_cache);
52163+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
52164 _leave(" = -ENOMEDIUM [no cache]");
52165 return -ENOMEDIUM;
52166 }
52167@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
52168 object = cache->ops->alloc_object(cache, cookie);
52169 fscache_stat_d(&fscache_n_cop_alloc_object);
52170 if (IS_ERR(object)) {
52171- fscache_stat(&fscache_n_object_no_alloc);
52172+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
52173 ret = PTR_ERR(object);
52174 goto error;
52175 }
52176
52177- fscache_stat(&fscache_n_object_alloc);
52178+ fscache_stat_unchecked(&fscache_n_object_alloc);
52179
52180 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
52181
52182@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
52183
52184 _enter("{%s}", cookie->def->name);
52185
52186- fscache_stat(&fscache_n_invalidates);
52187+ fscache_stat_unchecked(&fscache_n_invalidates);
52188
52189 /* Only permit invalidation of data files. Invalidating an index will
52190 * require the caller to release all its attachments to the tree rooted
52191@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
52192 {
52193 struct fscache_object *object;
52194
52195- fscache_stat(&fscache_n_updates);
52196+ fscache_stat_unchecked(&fscache_n_updates);
52197
52198 if (!cookie) {
52199- fscache_stat(&fscache_n_updates_null);
52200+ fscache_stat_unchecked(&fscache_n_updates_null);
52201 _leave(" [no cookie]");
52202 return;
52203 }
52204@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52205 struct fscache_object *object;
52206 unsigned long event;
52207
52208- fscache_stat(&fscache_n_relinquishes);
52209+ fscache_stat_unchecked(&fscache_n_relinquishes);
52210 if (retire)
52211- fscache_stat(&fscache_n_relinquishes_retire);
52212+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52213
52214 if (!cookie) {
52215- fscache_stat(&fscache_n_relinquishes_null);
52216+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52217 _leave(" [no cookie]");
52218 return;
52219 }
52220@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52221
52222 /* wait for the cookie to finish being instantiated (or to fail) */
52223 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52224- fscache_stat(&fscache_n_relinquishes_waitcrt);
52225+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52226 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52227 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52228 }
52229diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52230index ee38fef..0a326d4 100644
52231--- a/fs/fscache/internal.h
52232+++ b/fs/fscache/internal.h
52233@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52234 * stats.c
52235 */
52236 #ifdef CONFIG_FSCACHE_STATS
52237-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52238-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52239+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52240+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52241
52242-extern atomic_t fscache_n_op_pend;
52243-extern atomic_t fscache_n_op_run;
52244-extern atomic_t fscache_n_op_enqueue;
52245-extern atomic_t fscache_n_op_deferred_release;
52246-extern atomic_t fscache_n_op_release;
52247-extern atomic_t fscache_n_op_gc;
52248-extern atomic_t fscache_n_op_cancelled;
52249-extern atomic_t fscache_n_op_rejected;
52250+extern atomic_unchecked_t fscache_n_op_pend;
52251+extern atomic_unchecked_t fscache_n_op_run;
52252+extern atomic_unchecked_t fscache_n_op_enqueue;
52253+extern atomic_unchecked_t fscache_n_op_deferred_release;
52254+extern atomic_unchecked_t fscache_n_op_release;
52255+extern atomic_unchecked_t fscache_n_op_gc;
52256+extern atomic_unchecked_t fscache_n_op_cancelled;
52257+extern atomic_unchecked_t fscache_n_op_rejected;
52258
52259-extern atomic_t fscache_n_attr_changed;
52260-extern atomic_t fscache_n_attr_changed_ok;
52261-extern atomic_t fscache_n_attr_changed_nobufs;
52262-extern atomic_t fscache_n_attr_changed_nomem;
52263-extern atomic_t fscache_n_attr_changed_calls;
52264+extern atomic_unchecked_t fscache_n_attr_changed;
52265+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52266+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52267+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52268+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52269
52270-extern atomic_t fscache_n_allocs;
52271-extern atomic_t fscache_n_allocs_ok;
52272-extern atomic_t fscache_n_allocs_wait;
52273-extern atomic_t fscache_n_allocs_nobufs;
52274-extern atomic_t fscache_n_allocs_intr;
52275-extern atomic_t fscache_n_allocs_object_dead;
52276-extern atomic_t fscache_n_alloc_ops;
52277-extern atomic_t fscache_n_alloc_op_waits;
52278+extern atomic_unchecked_t fscache_n_allocs;
52279+extern atomic_unchecked_t fscache_n_allocs_ok;
52280+extern atomic_unchecked_t fscache_n_allocs_wait;
52281+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52282+extern atomic_unchecked_t fscache_n_allocs_intr;
52283+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52284+extern atomic_unchecked_t fscache_n_alloc_ops;
52285+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52286
52287-extern atomic_t fscache_n_retrievals;
52288-extern atomic_t fscache_n_retrievals_ok;
52289-extern atomic_t fscache_n_retrievals_wait;
52290-extern atomic_t fscache_n_retrievals_nodata;
52291-extern atomic_t fscache_n_retrievals_nobufs;
52292-extern atomic_t fscache_n_retrievals_intr;
52293-extern atomic_t fscache_n_retrievals_nomem;
52294-extern atomic_t fscache_n_retrievals_object_dead;
52295-extern atomic_t fscache_n_retrieval_ops;
52296-extern atomic_t fscache_n_retrieval_op_waits;
52297+extern atomic_unchecked_t fscache_n_retrievals;
52298+extern atomic_unchecked_t fscache_n_retrievals_ok;
52299+extern atomic_unchecked_t fscache_n_retrievals_wait;
52300+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52301+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52302+extern atomic_unchecked_t fscache_n_retrievals_intr;
52303+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52304+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52305+extern atomic_unchecked_t fscache_n_retrieval_ops;
52306+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52307
52308-extern atomic_t fscache_n_stores;
52309-extern atomic_t fscache_n_stores_ok;
52310-extern atomic_t fscache_n_stores_again;
52311-extern atomic_t fscache_n_stores_nobufs;
52312-extern atomic_t fscache_n_stores_oom;
52313-extern atomic_t fscache_n_store_ops;
52314-extern atomic_t fscache_n_store_calls;
52315-extern atomic_t fscache_n_store_pages;
52316-extern atomic_t fscache_n_store_radix_deletes;
52317-extern atomic_t fscache_n_store_pages_over_limit;
52318+extern atomic_unchecked_t fscache_n_stores;
52319+extern atomic_unchecked_t fscache_n_stores_ok;
52320+extern atomic_unchecked_t fscache_n_stores_again;
52321+extern atomic_unchecked_t fscache_n_stores_nobufs;
52322+extern atomic_unchecked_t fscache_n_stores_oom;
52323+extern atomic_unchecked_t fscache_n_store_ops;
52324+extern atomic_unchecked_t fscache_n_store_calls;
52325+extern atomic_unchecked_t fscache_n_store_pages;
52326+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52327+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52328
52329-extern atomic_t fscache_n_store_vmscan_not_storing;
52330-extern atomic_t fscache_n_store_vmscan_gone;
52331-extern atomic_t fscache_n_store_vmscan_busy;
52332-extern atomic_t fscache_n_store_vmscan_cancelled;
52333-extern atomic_t fscache_n_store_vmscan_wait;
52334+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52335+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52336+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52337+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52338+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52339
52340-extern atomic_t fscache_n_marks;
52341-extern atomic_t fscache_n_uncaches;
52342+extern atomic_unchecked_t fscache_n_marks;
52343+extern atomic_unchecked_t fscache_n_uncaches;
52344
52345-extern atomic_t fscache_n_acquires;
52346-extern atomic_t fscache_n_acquires_null;
52347-extern atomic_t fscache_n_acquires_no_cache;
52348-extern atomic_t fscache_n_acquires_ok;
52349-extern atomic_t fscache_n_acquires_nobufs;
52350-extern atomic_t fscache_n_acquires_oom;
52351+extern atomic_unchecked_t fscache_n_acquires;
52352+extern atomic_unchecked_t fscache_n_acquires_null;
52353+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52354+extern atomic_unchecked_t fscache_n_acquires_ok;
52355+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52356+extern atomic_unchecked_t fscache_n_acquires_oom;
52357
52358-extern atomic_t fscache_n_invalidates;
52359-extern atomic_t fscache_n_invalidates_run;
52360+extern atomic_unchecked_t fscache_n_invalidates;
52361+extern atomic_unchecked_t fscache_n_invalidates_run;
52362
52363-extern atomic_t fscache_n_updates;
52364-extern atomic_t fscache_n_updates_null;
52365-extern atomic_t fscache_n_updates_run;
52366+extern atomic_unchecked_t fscache_n_updates;
52367+extern atomic_unchecked_t fscache_n_updates_null;
52368+extern atomic_unchecked_t fscache_n_updates_run;
52369
52370-extern atomic_t fscache_n_relinquishes;
52371-extern atomic_t fscache_n_relinquishes_null;
52372-extern atomic_t fscache_n_relinquishes_waitcrt;
52373-extern atomic_t fscache_n_relinquishes_retire;
52374+extern atomic_unchecked_t fscache_n_relinquishes;
52375+extern atomic_unchecked_t fscache_n_relinquishes_null;
52376+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52377+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52378
52379-extern atomic_t fscache_n_cookie_index;
52380-extern atomic_t fscache_n_cookie_data;
52381-extern atomic_t fscache_n_cookie_special;
52382+extern atomic_unchecked_t fscache_n_cookie_index;
52383+extern atomic_unchecked_t fscache_n_cookie_data;
52384+extern atomic_unchecked_t fscache_n_cookie_special;
52385
52386-extern atomic_t fscache_n_object_alloc;
52387-extern atomic_t fscache_n_object_no_alloc;
52388-extern atomic_t fscache_n_object_lookups;
52389-extern atomic_t fscache_n_object_lookups_negative;
52390-extern atomic_t fscache_n_object_lookups_positive;
52391-extern atomic_t fscache_n_object_lookups_timed_out;
52392-extern atomic_t fscache_n_object_created;
52393-extern atomic_t fscache_n_object_avail;
52394-extern atomic_t fscache_n_object_dead;
52395+extern atomic_unchecked_t fscache_n_object_alloc;
52396+extern atomic_unchecked_t fscache_n_object_no_alloc;
52397+extern atomic_unchecked_t fscache_n_object_lookups;
52398+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52399+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52400+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52401+extern atomic_unchecked_t fscache_n_object_created;
52402+extern atomic_unchecked_t fscache_n_object_avail;
52403+extern atomic_unchecked_t fscache_n_object_dead;
52404
52405-extern atomic_t fscache_n_checkaux_none;
52406-extern atomic_t fscache_n_checkaux_okay;
52407-extern atomic_t fscache_n_checkaux_update;
52408-extern atomic_t fscache_n_checkaux_obsolete;
52409+extern atomic_unchecked_t fscache_n_checkaux_none;
52410+extern atomic_unchecked_t fscache_n_checkaux_okay;
52411+extern atomic_unchecked_t fscache_n_checkaux_update;
52412+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52413
52414 extern atomic_t fscache_n_cop_alloc_object;
52415 extern atomic_t fscache_n_cop_lookup_object;
52416@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52417 atomic_inc(stat);
52418 }
52419
52420+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52421+{
52422+ atomic_inc_unchecked(stat);
52423+}
52424+
52425 static inline void fscache_stat_d(atomic_t *stat)
52426 {
52427 atomic_dec(stat);
52428@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52429
52430 #define __fscache_stat(stat) (NULL)
52431 #define fscache_stat(stat) do {} while (0)
52432+#define fscache_stat_unchecked(stat) do {} while (0)
52433 #define fscache_stat_d(stat) do {} while (0)
52434 #endif
52435
52436diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52437index 50d41c1..10ee117 100644
52438--- a/fs/fscache/object.c
52439+++ b/fs/fscache/object.c
52440@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52441 /* Invalidate an object on disk */
52442 case FSCACHE_OBJECT_INVALIDATING:
52443 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52444- fscache_stat(&fscache_n_invalidates_run);
52445+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52446 fscache_stat(&fscache_n_cop_invalidate_object);
52447 fscache_invalidate_object(object);
52448 fscache_stat_d(&fscache_n_cop_invalidate_object);
52449@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52450 /* update the object metadata on disk */
52451 case FSCACHE_OBJECT_UPDATING:
52452 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52453- fscache_stat(&fscache_n_updates_run);
52454+ fscache_stat_unchecked(&fscache_n_updates_run);
52455 fscache_stat(&fscache_n_cop_update_object);
52456 object->cache->ops->update_object(object);
52457 fscache_stat_d(&fscache_n_cop_update_object);
52458@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52459 spin_lock(&object->lock);
52460 object->state = FSCACHE_OBJECT_DEAD;
52461 spin_unlock(&object->lock);
52462- fscache_stat(&fscache_n_object_dead);
52463+ fscache_stat_unchecked(&fscache_n_object_dead);
52464 goto terminal_transit;
52465
52466 /* handle the parent cache of this object being withdrawn from
52467@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52468 spin_lock(&object->lock);
52469 object->state = FSCACHE_OBJECT_DEAD;
52470 spin_unlock(&object->lock);
52471- fscache_stat(&fscache_n_object_dead);
52472+ fscache_stat_unchecked(&fscache_n_object_dead);
52473 goto terminal_transit;
52474
52475 /* complain about the object being woken up once it is
52476@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52477 parent->cookie->def->name, cookie->def->name,
52478 object->cache->tag->name);
52479
52480- fscache_stat(&fscache_n_object_lookups);
52481+ fscache_stat_unchecked(&fscache_n_object_lookups);
52482 fscache_stat(&fscache_n_cop_lookup_object);
52483 ret = object->cache->ops->lookup_object(object);
52484 fscache_stat_d(&fscache_n_cop_lookup_object);
52485@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52486 if (ret == -ETIMEDOUT) {
52487 /* probably stuck behind another object, so move this one to
52488 * the back of the queue */
52489- fscache_stat(&fscache_n_object_lookups_timed_out);
52490+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52491 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52492 }
52493
52494@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52495
52496 spin_lock(&object->lock);
52497 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52498- fscache_stat(&fscache_n_object_lookups_negative);
52499+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52500
52501 /* transit here to allow write requests to begin stacking up
52502 * and read requests to begin returning ENODATA */
52503@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52504 * result, in which case there may be data available */
52505 spin_lock(&object->lock);
52506 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52507- fscache_stat(&fscache_n_object_lookups_positive);
52508+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52509
52510 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52511
52512@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52513 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52514 } else {
52515 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52516- fscache_stat(&fscache_n_object_created);
52517+ fscache_stat_unchecked(&fscache_n_object_created);
52518
52519 object->state = FSCACHE_OBJECT_AVAILABLE;
52520 spin_unlock(&object->lock);
52521@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52522 fscache_enqueue_dependents(object);
52523
52524 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52525- fscache_stat(&fscache_n_object_avail);
52526+ fscache_stat_unchecked(&fscache_n_object_avail);
52527
52528 _leave("");
52529 }
52530@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52531 enum fscache_checkaux result;
52532
52533 if (!object->cookie->def->check_aux) {
52534- fscache_stat(&fscache_n_checkaux_none);
52535+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52536 return FSCACHE_CHECKAUX_OKAY;
52537 }
52538
52539@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52540 switch (result) {
52541 /* entry okay as is */
52542 case FSCACHE_CHECKAUX_OKAY:
52543- fscache_stat(&fscache_n_checkaux_okay);
52544+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52545 break;
52546
52547 /* entry requires update */
52548 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52549- fscache_stat(&fscache_n_checkaux_update);
52550+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52551 break;
52552
52553 /* entry requires deletion */
52554 case FSCACHE_CHECKAUX_OBSOLETE:
52555- fscache_stat(&fscache_n_checkaux_obsolete);
52556+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52557 break;
52558
52559 default:
52560diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52561index 762a9ec..2023284 100644
52562--- a/fs/fscache/operation.c
52563+++ b/fs/fscache/operation.c
52564@@ -17,7 +17,7 @@
52565 #include <linux/slab.h>
52566 #include "internal.h"
52567
52568-atomic_t fscache_op_debug_id;
52569+atomic_unchecked_t fscache_op_debug_id;
52570 EXPORT_SYMBOL(fscache_op_debug_id);
52571
52572 /**
52573@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52574 ASSERTCMP(atomic_read(&op->usage), >, 0);
52575 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52576
52577- fscache_stat(&fscache_n_op_enqueue);
52578+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52579 switch (op->flags & FSCACHE_OP_TYPE) {
52580 case FSCACHE_OP_ASYNC:
52581 _debug("queue async");
52582@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52583 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52584 if (op->processor)
52585 fscache_enqueue_operation(op);
52586- fscache_stat(&fscache_n_op_run);
52587+ fscache_stat_unchecked(&fscache_n_op_run);
52588 }
52589
52590 /*
52591@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52592 if (object->n_in_progress > 0) {
52593 atomic_inc(&op->usage);
52594 list_add_tail(&op->pend_link, &object->pending_ops);
52595- fscache_stat(&fscache_n_op_pend);
52596+ fscache_stat_unchecked(&fscache_n_op_pend);
52597 } else if (!list_empty(&object->pending_ops)) {
52598 atomic_inc(&op->usage);
52599 list_add_tail(&op->pend_link, &object->pending_ops);
52600- fscache_stat(&fscache_n_op_pend);
52601+ fscache_stat_unchecked(&fscache_n_op_pend);
52602 fscache_start_operations(object);
52603 } else {
52604 ASSERTCMP(object->n_in_progress, ==, 0);
52605@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52606 object->n_exclusive++; /* reads and writes must wait */
52607 atomic_inc(&op->usage);
52608 list_add_tail(&op->pend_link, &object->pending_ops);
52609- fscache_stat(&fscache_n_op_pend);
52610+ fscache_stat_unchecked(&fscache_n_op_pend);
52611 ret = 0;
52612 } else {
52613 /* If we're in any other state, there must have been an I/O
52614@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52615 if (object->n_exclusive > 0) {
52616 atomic_inc(&op->usage);
52617 list_add_tail(&op->pend_link, &object->pending_ops);
52618- fscache_stat(&fscache_n_op_pend);
52619+ fscache_stat_unchecked(&fscache_n_op_pend);
52620 } else if (!list_empty(&object->pending_ops)) {
52621 atomic_inc(&op->usage);
52622 list_add_tail(&op->pend_link, &object->pending_ops);
52623- fscache_stat(&fscache_n_op_pend);
52624+ fscache_stat_unchecked(&fscache_n_op_pend);
52625 fscache_start_operations(object);
52626 } else {
52627 ASSERTCMP(object->n_exclusive, ==, 0);
52628@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52629 object->n_ops++;
52630 atomic_inc(&op->usage);
52631 list_add_tail(&op->pend_link, &object->pending_ops);
52632- fscache_stat(&fscache_n_op_pend);
52633+ fscache_stat_unchecked(&fscache_n_op_pend);
52634 ret = 0;
52635 } else if (object->state == FSCACHE_OBJECT_DYING ||
52636 object->state == FSCACHE_OBJECT_LC_DYING ||
52637 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52638- fscache_stat(&fscache_n_op_rejected);
52639+ fscache_stat_unchecked(&fscache_n_op_rejected);
52640 op->state = FSCACHE_OP_ST_CANCELLED;
52641 ret = -ENOBUFS;
52642 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52643@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52644 ret = -EBUSY;
52645 if (op->state == FSCACHE_OP_ST_PENDING) {
52646 ASSERT(!list_empty(&op->pend_link));
52647- fscache_stat(&fscache_n_op_cancelled);
52648+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52649 list_del_init(&op->pend_link);
52650 if (do_cancel)
52651 do_cancel(op);
52652@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52653 while (!list_empty(&object->pending_ops)) {
52654 op = list_entry(object->pending_ops.next,
52655 struct fscache_operation, pend_link);
52656- fscache_stat(&fscache_n_op_cancelled);
52657+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52658 list_del_init(&op->pend_link);
52659
52660 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52661@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52662 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52663 op->state = FSCACHE_OP_ST_DEAD;
52664
52665- fscache_stat(&fscache_n_op_release);
52666+ fscache_stat_unchecked(&fscache_n_op_release);
52667
52668 if (op->release) {
52669 op->release(op);
52670@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52671 * lock, and defer it otherwise */
52672 if (!spin_trylock(&object->lock)) {
52673 _debug("defer put");
52674- fscache_stat(&fscache_n_op_deferred_release);
52675+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52676
52677 cache = object->cache;
52678 spin_lock(&cache->op_gc_list_lock);
52679@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52680
52681 _debug("GC DEFERRED REL OBJ%x OP%x",
52682 object->debug_id, op->debug_id);
52683- fscache_stat(&fscache_n_op_gc);
52684+ fscache_stat_unchecked(&fscache_n_op_gc);
52685
52686 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52687 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52688diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52689index ff000e5..c44ec6d 100644
52690--- a/fs/fscache/page.c
52691+++ b/fs/fscache/page.c
52692@@ -61,7 +61,7 @@ try_again:
52693 val = radix_tree_lookup(&cookie->stores, page->index);
52694 if (!val) {
52695 rcu_read_unlock();
52696- fscache_stat(&fscache_n_store_vmscan_not_storing);
52697+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52698 __fscache_uncache_page(cookie, page);
52699 return true;
52700 }
52701@@ -91,11 +91,11 @@ try_again:
52702 spin_unlock(&cookie->stores_lock);
52703
52704 if (xpage) {
52705- fscache_stat(&fscache_n_store_vmscan_cancelled);
52706- fscache_stat(&fscache_n_store_radix_deletes);
52707+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52708+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52709 ASSERTCMP(xpage, ==, page);
52710 } else {
52711- fscache_stat(&fscache_n_store_vmscan_gone);
52712+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52713 }
52714
52715 wake_up_bit(&cookie->flags, 0);
52716@@ -110,11 +110,11 @@ page_busy:
52717 * sleeping on memory allocation, so we may need to impose a timeout
52718 * too. */
52719 if (!(gfp & __GFP_WAIT)) {
52720- fscache_stat(&fscache_n_store_vmscan_busy);
52721+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52722 return false;
52723 }
52724
52725- fscache_stat(&fscache_n_store_vmscan_wait);
52726+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52727 __fscache_wait_on_page_write(cookie, page);
52728 gfp &= ~__GFP_WAIT;
52729 goto try_again;
52730@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52731 FSCACHE_COOKIE_STORING_TAG);
52732 if (!radix_tree_tag_get(&cookie->stores, page->index,
52733 FSCACHE_COOKIE_PENDING_TAG)) {
52734- fscache_stat(&fscache_n_store_radix_deletes);
52735+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52736 xpage = radix_tree_delete(&cookie->stores, page->index);
52737 }
52738 spin_unlock(&cookie->stores_lock);
52739@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52740
52741 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52742
52743- fscache_stat(&fscache_n_attr_changed_calls);
52744+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52745
52746 if (fscache_object_is_active(object)) {
52747 fscache_stat(&fscache_n_cop_attr_changed);
52748@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52749
52750 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52751
52752- fscache_stat(&fscache_n_attr_changed);
52753+ fscache_stat_unchecked(&fscache_n_attr_changed);
52754
52755 op = kzalloc(sizeof(*op), GFP_KERNEL);
52756 if (!op) {
52757- fscache_stat(&fscache_n_attr_changed_nomem);
52758+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52759 _leave(" = -ENOMEM");
52760 return -ENOMEM;
52761 }
52762@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52763 if (fscache_submit_exclusive_op(object, op) < 0)
52764 goto nobufs;
52765 spin_unlock(&cookie->lock);
52766- fscache_stat(&fscache_n_attr_changed_ok);
52767+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52768 fscache_put_operation(op);
52769 _leave(" = 0");
52770 return 0;
52771@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52772 nobufs:
52773 spin_unlock(&cookie->lock);
52774 kfree(op);
52775- fscache_stat(&fscache_n_attr_changed_nobufs);
52776+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52777 _leave(" = %d", -ENOBUFS);
52778 return -ENOBUFS;
52779 }
52780@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52781 /* allocate a retrieval operation and attempt to submit it */
52782 op = kzalloc(sizeof(*op), GFP_NOIO);
52783 if (!op) {
52784- fscache_stat(&fscache_n_retrievals_nomem);
52785+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52786 return NULL;
52787 }
52788
52789@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52790 return 0;
52791 }
52792
52793- fscache_stat(&fscache_n_retrievals_wait);
52794+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52795
52796 jif = jiffies;
52797 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52798 fscache_wait_bit_interruptible,
52799 TASK_INTERRUPTIBLE) != 0) {
52800- fscache_stat(&fscache_n_retrievals_intr);
52801+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52802 _leave(" = -ERESTARTSYS");
52803 return -ERESTARTSYS;
52804 }
52805@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52806 */
52807 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52808 struct fscache_retrieval *op,
52809- atomic_t *stat_op_waits,
52810- atomic_t *stat_object_dead)
52811+ atomic_unchecked_t *stat_op_waits,
52812+ atomic_unchecked_t *stat_object_dead)
52813 {
52814 int ret;
52815
52816@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52817 goto check_if_dead;
52818
52819 _debug(">>> WT");
52820- fscache_stat(stat_op_waits);
52821+ fscache_stat_unchecked(stat_op_waits);
52822 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52823 fscache_wait_bit_interruptible,
52824 TASK_INTERRUPTIBLE) != 0) {
52825@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52826
52827 check_if_dead:
52828 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52829- fscache_stat(stat_object_dead);
52830+ fscache_stat_unchecked(stat_object_dead);
52831 _leave(" = -ENOBUFS [cancelled]");
52832 return -ENOBUFS;
52833 }
52834 if (unlikely(fscache_object_is_dead(object))) {
52835 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52836 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52837- fscache_stat(stat_object_dead);
52838+ fscache_stat_unchecked(stat_object_dead);
52839 return -ENOBUFS;
52840 }
52841 return 0;
52842@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52843
52844 _enter("%p,%p,,,", cookie, page);
52845
52846- fscache_stat(&fscache_n_retrievals);
52847+ fscache_stat_unchecked(&fscache_n_retrievals);
52848
52849 if (hlist_empty(&cookie->backing_objects))
52850 goto nobufs;
52851@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52852 goto nobufs_unlock_dec;
52853 spin_unlock(&cookie->lock);
52854
52855- fscache_stat(&fscache_n_retrieval_ops);
52856+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52857
52858 /* pin the netfs read context in case we need to do the actual netfs
52859 * read because we've encountered a cache read failure */
52860@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52861
52862 error:
52863 if (ret == -ENOMEM)
52864- fscache_stat(&fscache_n_retrievals_nomem);
52865+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52866 else if (ret == -ERESTARTSYS)
52867- fscache_stat(&fscache_n_retrievals_intr);
52868+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52869 else if (ret == -ENODATA)
52870- fscache_stat(&fscache_n_retrievals_nodata);
52871+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52872 else if (ret < 0)
52873- fscache_stat(&fscache_n_retrievals_nobufs);
52874+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52875 else
52876- fscache_stat(&fscache_n_retrievals_ok);
52877+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52878
52879 fscache_put_retrieval(op);
52880 _leave(" = %d", ret);
52881@@ -467,7 +467,7 @@ nobufs_unlock:
52882 spin_unlock(&cookie->lock);
52883 kfree(op);
52884 nobufs:
52885- fscache_stat(&fscache_n_retrievals_nobufs);
52886+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52887 _leave(" = -ENOBUFS");
52888 return -ENOBUFS;
52889 }
52890@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52891
52892 _enter("%p,,%d,,,", cookie, *nr_pages);
52893
52894- fscache_stat(&fscache_n_retrievals);
52895+ fscache_stat_unchecked(&fscache_n_retrievals);
52896
52897 if (hlist_empty(&cookie->backing_objects))
52898 goto nobufs;
52899@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52900 goto nobufs_unlock_dec;
52901 spin_unlock(&cookie->lock);
52902
52903- fscache_stat(&fscache_n_retrieval_ops);
52904+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52905
52906 /* pin the netfs read context in case we need to do the actual netfs
52907 * read because we've encountered a cache read failure */
52908@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52909
52910 error:
52911 if (ret == -ENOMEM)
52912- fscache_stat(&fscache_n_retrievals_nomem);
52913+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52914 else if (ret == -ERESTARTSYS)
52915- fscache_stat(&fscache_n_retrievals_intr);
52916+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52917 else if (ret == -ENODATA)
52918- fscache_stat(&fscache_n_retrievals_nodata);
52919+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52920 else if (ret < 0)
52921- fscache_stat(&fscache_n_retrievals_nobufs);
52922+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52923 else
52924- fscache_stat(&fscache_n_retrievals_ok);
52925+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52926
52927 fscache_put_retrieval(op);
52928 _leave(" = %d", ret);
52929@@ -591,7 +591,7 @@ nobufs_unlock:
52930 spin_unlock(&cookie->lock);
52931 kfree(op);
52932 nobufs:
52933- fscache_stat(&fscache_n_retrievals_nobufs);
52934+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52935 _leave(" = -ENOBUFS");
52936 return -ENOBUFS;
52937 }
52938@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52939
52940 _enter("%p,%p,,,", cookie, page);
52941
52942- fscache_stat(&fscache_n_allocs);
52943+ fscache_stat_unchecked(&fscache_n_allocs);
52944
52945 if (hlist_empty(&cookie->backing_objects))
52946 goto nobufs;
52947@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52948 goto nobufs_unlock;
52949 spin_unlock(&cookie->lock);
52950
52951- fscache_stat(&fscache_n_alloc_ops);
52952+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52953
52954 ret = fscache_wait_for_retrieval_activation(
52955 object, op,
52956@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52957
52958 error:
52959 if (ret == -ERESTARTSYS)
52960- fscache_stat(&fscache_n_allocs_intr);
52961+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52962 else if (ret < 0)
52963- fscache_stat(&fscache_n_allocs_nobufs);
52964+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52965 else
52966- fscache_stat(&fscache_n_allocs_ok);
52967+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52968
52969 fscache_put_retrieval(op);
52970 _leave(" = %d", ret);
52971@@ -677,7 +677,7 @@ nobufs_unlock:
52972 spin_unlock(&cookie->lock);
52973 kfree(op);
52974 nobufs:
52975- fscache_stat(&fscache_n_allocs_nobufs);
52976+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52977 _leave(" = -ENOBUFS");
52978 return -ENOBUFS;
52979 }
52980@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52981
52982 spin_lock(&cookie->stores_lock);
52983
52984- fscache_stat(&fscache_n_store_calls);
52985+ fscache_stat_unchecked(&fscache_n_store_calls);
52986
52987 /* find a page to store */
52988 page = NULL;
52989@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52990 page = results[0];
52991 _debug("gang %d [%lx]", n, page->index);
52992 if (page->index > op->store_limit) {
52993- fscache_stat(&fscache_n_store_pages_over_limit);
52994+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52995 goto superseded;
52996 }
52997
52998@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52999 spin_unlock(&cookie->stores_lock);
53000 spin_unlock(&object->lock);
53001
53002- fscache_stat(&fscache_n_store_pages);
53003+ fscache_stat_unchecked(&fscache_n_store_pages);
53004 fscache_stat(&fscache_n_cop_write_page);
53005 ret = object->cache->ops->write_page(op, page);
53006 fscache_stat_d(&fscache_n_cop_write_page);
53007@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53008 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
53009 ASSERT(PageFsCache(page));
53010
53011- fscache_stat(&fscache_n_stores);
53012+ fscache_stat_unchecked(&fscache_n_stores);
53013
53014 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
53015 _leave(" = -ENOBUFS [invalidating]");
53016@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53017 spin_unlock(&cookie->stores_lock);
53018 spin_unlock(&object->lock);
53019
53020- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
53021+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
53022 op->store_limit = object->store_limit;
53023
53024 if (fscache_submit_op(object, &op->op) < 0)
53025@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53026
53027 spin_unlock(&cookie->lock);
53028 radix_tree_preload_end();
53029- fscache_stat(&fscache_n_store_ops);
53030- fscache_stat(&fscache_n_stores_ok);
53031+ fscache_stat_unchecked(&fscache_n_store_ops);
53032+ fscache_stat_unchecked(&fscache_n_stores_ok);
53033
53034 /* the work queue now carries its own ref on the object */
53035 fscache_put_operation(&op->op);
53036@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
53037 return 0;
53038
53039 already_queued:
53040- fscache_stat(&fscache_n_stores_again);
53041+ fscache_stat_unchecked(&fscache_n_stores_again);
53042 already_pending:
53043 spin_unlock(&cookie->stores_lock);
53044 spin_unlock(&object->lock);
53045 spin_unlock(&cookie->lock);
53046 radix_tree_preload_end();
53047 kfree(op);
53048- fscache_stat(&fscache_n_stores_ok);
53049+ fscache_stat_unchecked(&fscache_n_stores_ok);
53050 _leave(" = 0");
53051 return 0;
53052
53053@@ -959,14 +959,14 @@ nobufs:
53054 spin_unlock(&cookie->lock);
53055 radix_tree_preload_end();
53056 kfree(op);
53057- fscache_stat(&fscache_n_stores_nobufs);
53058+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
53059 _leave(" = -ENOBUFS");
53060 return -ENOBUFS;
53061
53062 nomem_free:
53063 kfree(op);
53064 nomem:
53065- fscache_stat(&fscache_n_stores_oom);
53066+ fscache_stat_unchecked(&fscache_n_stores_oom);
53067 _leave(" = -ENOMEM");
53068 return -ENOMEM;
53069 }
53070@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
53071 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
53072 ASSERTCMP(page, !=, NULL);
53073
53074- fscache_stat(&fscache_n_uncaches);
53075+ fscache_stat_unchecked(&fscache_n_uncaches);
53076
53077 /* cache withdrawal may beat us to it */
53078 if (!PageFsCache(page))
53079@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
53080 struct fscache_cookie *cookie = op->op.object->cookie;
53081
53082 #ifdef CONFIG_FSCACHE_STATS
53083- atomic_inc(&fscache_n_marks);
53084+ atomic_inc_unchecked(&fscache_n_marks);
53085 #endif
53086
53087 _debug("- mark %p{%lx}", page, page->index);
53088diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
53089index 40d13c7..ddf52b9 100644
53090--- a/fs/fscache/stats.c
53091+++ b/fs/fscache/stats.c
53092@@ -18,99 +18,99 @@
53093 /*
53094 * operation counters
53095 */
53096-atomic_t fscache_n_op_pend;
53097-atomic_t fscache_n_op_run;
53098-atomic_t fscache_n_op_enqueue;
53099-atomic_t fscache_n_op_requeue;
53100-atomic_t fscache_n_op_deferred_release;
53101-atomic_t fscache_n_op_release;
53102-atomic_t fscache_n_op_gc;
53103-atomic_t fscache_n_op_cancelled;
53104-atomic_t fscache_n_op_rejected;
53105+atomic_unchecked_t fscache_n_op_pend;
53106+atomic_unchecked_t fscache_n_op_run;
53107+atomic_unchecked_t fscache_n_op_enqueue;
53108+atomic_unchecked_t fscache_n_op_requeue;
53109+atomic_unchecked_t fscache_n_op_deferred_release;
53110+atomic_unchecked_t fscache_n_op_release;
53111+atomic_unchecked_t fscache_n_op_gc;
53112+atomic_unchecked_t fscache_n_op_cancelled;
53113+atomic_unchecked_t fscache_n_op_rejected;
53114
53115-atomic_t fscache_n_attr_changed;
53116-atomic_t fscache_n_attr_changed_ok;
53117-atomic_t fscache_n_attr_changed_nobufs;
53118-atomic_t fscache_n_attr_changed_nomem;
53119-atomic_t fscache_n_attr_changed_calls;
53120+atomic_unchecked_t fscache_n_attr_changed;
53121+atomic_unchecked_t fscache_n_attr_changed_ok;
53122+atomic_unchecked_t fscache_n_attr_changed_nobufs;
53123+atomic_unchecked_t fscache_n_attr_changed_nomem;
53124+atomic_unchecked_t fscache_n_attr_changed_calls;
53125
53126-atomic_t fscache_n_allocs;
53127-atomic_t fscache_n_allocs_ok;
53128-atomic_t fscache_n_allocs_wait;
53129-atomic_t fscache_n_allocs_nobufs;
53130-atomic_t fscache_n_allocs_intr;
53131-atomic_t fscache_n_allocs_object_dead;
53132-atomic_t fscache_n_alloc_ops;
53133-atomic_t fscache_n_alloc_op_waits;
53134+atomic_unchecked_t fscache_n_allocs;
53135+atomic_unchecked_t fscache_n_allocs_ok;
53136+atomic_unchecked_t fscache_n_allocs_wait;
53137+atomic_unchecked_t fscache_n_allocs_nobufs;
53138+atomic_unchecked_t fscache_n_allocs_intr;
53139+atomic_unchecked_t fscache_n_allocs_object_dead;
53140+atomic_unchecked_t fscache_n_alloc_ops;
53141+atomic_unchecked_t fscache_n_alloc_op_waits;
53142
53143-atomic_t fscache_n_retrievals;
53144-atomic_t fscache_n_retrievals_ok;
53145-atomic_t fscache_n_retrievals_wait;
53146-atomic_t fscache_n_retrievals_nodata;
53147-atomic_t fscache_n_retrievals_nobufs;
53148-atomic_t fscache_n_retrievals_intr;
53149-atomic_t fscache_n_retrievals_nomem;
53150-atomic_t fscache_n_retrievals_object_dead;
53151-atomic_t fscache_n_retrieval_ops;
53152-atomic_t fscache_n_retrieval_op_waits;
53153+atomic_unchecked_t fscache_n_retrievals;
53154+atomic_unchecked_t fscache_n_retrievals_ok;
53155+atomic_unchecked_t fscache_n_retrievals_wait;
53156+atomic_unchecked_t fscache_n_retrievals_nodata;
53157+atomic_unchecked_t fscache_n_retrievals_nobufs;
53158+atomic_unchecked_t fscache_n_retrievals_intr;
53159+atomic_unchecked_t fscache_n_retrievals_nomem;
53160+atomic_unchecked_t fscache_n_retrievals_object_dead;
53161+atomic_unchecked_t fscache_n_retrieval_ops;
53162+atomic_unchecked_t fscache_n_retrieval_op_waits;
53163
53164-atomic_t fscache_n_stores;
53165-atomic_t fscache_n_stores_ok;
53166-atomic_t fscache_n_stores_again;
53167-atomic_t fscache_n_stores_nobufs;
53168-atomic_t fscache_n_stores_oom;
53169-atomic_t fscache_n_store_ops;
53170-atomic_t fscache_n_store_calls;
53171-atomic_t fscache_n_store_pages;
53172-atomic_t fscache_n_store_radix_deletes;
53173-atomic_t fscache_n_store_pages_over_limit;
53174+atomic_unchecked_t fscache_n_stores;
53175+atomic_unchecked_t fscache_n_stores_ok;
53176+atomic_unchecked_t fscache_n_stores_again;
53177+atomic_unchecked_t fscache_n_stores_nobufs;
53178+atomic_unchecked_t fscache_n_stores_oom;
53179+atomic_unchecked_t fscache_n_store_ops;
53180+atomic_unchecked_t fscache_n_store_calls;
53181+atomic_unchecked_t fscache_n_store_pages;
53182+atomic_unchecked_t fscache_n_store_radix_deletes;
53183+atomic_unchecked_t fscache_n_store_pages_over_limit;
53184
53185-atomic_t fscache_n_store_vmscan_not_storing;
53186-atomic_t fscache_n_store_vmscan_gone;
53187-atomic_t fscache_n_store_vmscan_busy;
53188-atomic_t fscache_n_store_vmscan_cancelled;
53189-atomic_t fscache_n_store_vmscan_wait;
53190+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
53191+atomic_unchecked_t fscache_n_store_vmscan_gone;
53192+atomic_unchecked_t fscache_n_store_vmscan_busy;
53193+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53194+atomic_unchecked_t fscache_n_store_vmscan_wait;
53195
53196-atomic_t fscache_n_marks;
53197-atomic_t fscache_n_uncaches;
53198+atomic_unchecked_t fscache_n_marks;
53199+atomic_unchecked_t fscache_n_uncaches;
53200
53201-atomic_t fscache_n_acquires;
53202-atomic_t fscache_n_acquires_null;
53203-atomic_t fscache_n_acquires_no_cache;
53204-atomic_t fscache_n_acquires_ok;
53205-atomic_t fscache_n_acquires_nobufs;
53206-atomic_t fscache_n_acquires_oom;
53207+atomic_unchecked_t fscache_n_acquires;
53208+atomic_unchecked_t fscache_n_acquires_null;
53209+atomic_unchecked_t fscache_n_acquires_no_cache;
53210+atomic_unchecked_t fscache_n_acquires_ok;
53211+atomic_unchecked_t fscache_n_acquires_nobufs;
53212+atomic_unchecked_t fscache_n_acquires_oom;
53213
53214-atomic_t fscache_n_invalidates;
53215-atomic_t fscache_n_invalidates_run;
53216+atomic_unchecked_t fscache_n_invalidates;
53217+atomic_unchecked_t fscache_n_invalidates_run;
53218
53219-atomic_t fscache_n_updates;
53220-atomic_t fscache_n_updates_null;
53221-atomic_t fscache_n_updates_run;
53222+atomic_unchecked_t fscache_n_updates;
53223+atomic_unchecked_t fscache_n_updates_null;
53224+atomic_unchecked_t fscache_n_updates_run;
53225
53226-atomic_t fscache_n_relinquishes;
53227-atomic_t fscache_n_relinquishes_null;
53228-atomic_t fscache_n_relinquishes_waitcrt;
53229-atomic_t fscache_n_relinquishes_retire;
53230+atomic_unchecked_t fscache_n_relinquishes;
53231+atomic_unchecked_t fscache_n_relinquishes_null;
53232+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53233+atomic_unchecked_t fscache_n_relinquishes_retire;
53234
53235-atomic_t fscache_n_cookie_index;
53236-atomic_t fscache_n_cookie_data;
53237-atomic_t fscache_n_cookie_special;
53238+atomic_unchecked_t fscache_n_cookie_index;
53239+atomic_unchecked_t fscache_n_cookie_data;
53240+atomic_unchecked_t fscache_n_cookie_special;
53241
53242-atomic_t fscache_n_object_alloc;
53243-atomic_t fscache_n_object_no_alloc;
53244-atomic_t fscache_n_object_lookups;
53245-atomic_t fscache_n_object_lookups_negative;
53246-atomic_t fscache_n_object_lookups_positive;
53247-atomic_t fscache_n_object_lookups_timed_out;
53248-atomic_t fscache_n_object_created;
53249-atomic_t fscache_n_object_avail;
53250-atomic_t fscache_n_object_dead;
53251+atomic_unchecked_t fscache_n_object_alloc;
53252+atomic_unchecked_t fscache_n_object_no_alloc;
53253+atomic_unchecked_t fscache_n_object_lookups;
53254+atomic_unchecked_t fscache_n_object_lookups_negative;
53255+atomic_unchecked_t fscache_n_object_lookups_positive;
53256+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53257+atomic_unchecked_t fscache_n_object_created;
53258+atomic_unchecked_t fscache_n_object_avail;
53259+atomic_unchecked_t fscache_n_object_dead;
53260
53261-atomic_t fscache_n_checkaux_none;
53262-atomic_t fscache_n_checkaux_okay;
53263-atomic_t fscache_n_checkaux_update;
53264-atomic_t fscache_n_checkaux_obsolete;
53265+atomic_unchecked_t fscache_n_checkaux_none;
53266+atomic_unchecked_t fscache_n_checkaux_okay;
53267+atomic_unchecked_t fscache_n_checkaux_update;
53268+atomic_unchecked_t fscache_n_checkaux_obsolete;
53269
53270 atomic_t fscache_n_cop_alloc_object;
53271 atomic_t fscache_n_cop_lookup_object;
53272@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53273 seq_puts(m, "FS-Cache statistics\n");
53274
53275 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53276- atomic_read(&fscache_n_cookie_index),
53277- atomic_read(&fscache_n_cookie_data),
53278- atomic_read(&fscache_n_cookie_special));
53279+ atomic_read_unchecked(&fscache_n_cookie_index),
53280+ atomic_read_unchecked(&fscache_n_cookie_data),
53281+ atomic_read_unchecked(&fscache_n_cookie_special));
53282
53283 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53284- atomic_read(&fscache_n_object_alloc),
53285- atomic_read(&fscache_n_object_no_alloc),
53286- atomic_read(&fscache_n_object_avail),
53287- atomic_read(&fscache_n_object_dead));
53288+ atomic_read_unchecked(&fscache_n_object_alloc),
53289+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53290+ atomic_read_unchecked(&fscache_n_object_avail),
53291+ atomic_read_unchecked(&fscache_n_object_dead));
53292 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53293- atomic_read(&fscache_n_checkaux_none),
53294- atomic_read(&fscache_n_checkaux_okay),
53295- atomic_read(&fscache_n_checkaux_update),
53296- atomic_read(&fscache_n_checkaux_obsolete));
53297+ atomic_read_unchecked(&fscache_n_checkaux_none),
53298+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53299+ atomic_read_unchecked(&fscache_n_checkaux_update),
53300+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53301
53302 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53303- atomic_read(&fscache_n_marks),
53304- atomic_read(&fscache_n_uncaches));
53305+ atomic_read_unchecked(&fscache_n_marks),
53306+ atomic_read_unchecked(&fscache_n_uncaches));
53307
53308 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53309 " oom=%u\n",
53310- atomic_read(&fscache_n_acquires),
53311- atomic_read(&fscache_n_acquires_null),
53312- atomic_read(&fscache_n_acquires_no_cache),
53313- atomic_read(&fscache_n_acquires_ok),
53314- atomic_read(&fscache_n_acquires_nobufs),
53315- atomic_read(&fscache_n_acquires_oom));
53316+ atomic_read_unchecked(&fscache_n_acquires),
53317+ atomic_read_unchecked(&fscache_n_acquires_null),
53318+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53319+ atomic_read_unchecked(&fscache_n_acquires_ok),
53320+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53321+ atomic_read_unchecked(&fscache_n_acquires_oom));
53322
53323 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53324- atomic_read(&fscache_n_object_lookups),
53325- atomic_read(&fscache_n_object_lookups_negative),
53326- atomic_read(&fscache_n_object_lookups_positive),
53327- atomic_read(&fscache_n_object_created),
53328- atomic_read(&fscache_n_object_lookups_timed_out));
53329+ atomic_read_unchecked(&fscache_n_object_lookups),
53330+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53331+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53332+ atomic_read_unchecked(&fscache_n_object_created),
53333+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53334
53335 seq_printf(m, "Invals : n=%u run=%u\n",
53336- atomic_read(&fscache_n_invalidates),
53337- atomic_read(&fscache_n_invalidates_run));
53338+ atomic_read_unchecked(&fscache_n_invalidates),
53339+ atomic_read_unchecked(&fscache_n_invalidates_run));
53340
53341 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53342- atomic_read(&fscache_n_updates),
53343- atomic_read(&fscache_n_updates_null),
53344- atomic_read(&fscache_n_updates_run));
53345+ atomic_read_unchecked(&fscache_n_updates),
53346+ atomic_read_unchecked(&fscache_n_updates_null),
53347+ atomic_read_unchecked(&fscache_n_updates_run));
53348
53349 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53350- atomic_read(&fscache_n_relinquishes),
53351- atomic_read(&fscache_n_relinquishes_null),
53352- atomic_read(&fscache_n_relinquishes_waitcrt),
53353- atomic_read(&fscache_n_relinquishes_retire));
53354+ atomic_read_unchecked(&fscache_n_relinquishes),
53355+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53356+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53357+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53358
53359 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53360- atomic_read(&fscache_n_attr_changed),
53361- atomic_read(&fscache_n_attr_changed_ok),
53362- atomic_read(&fscache_n_attr_changed_nobufs),
53363- atomic_read(&fscache_n_attr_changed_nomem),
53364- atomic_read(&fscache_n_attr_changed_calls));
53365+ atomic_read_unchecked(&fscache_n_attr_changed),
53366+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53367+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53368+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53369+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53370
53371 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53372- atomic_read(&fscache_n_allocs),
53373- atomic_read(&fscache_n_allocs_ok),
53374- atomic_read(&fscache_n_allocs_wait),
53375- atomic_read(&fscache_n_allocs_nobufs),
53376- atomic_read(&fscache_n_allocs_intr));
53377+ atomic_read_unchecked(&fscache_n_allocs),
53378+ atomic_read_unchecked(&fscache_n_allocs_ok),
53379+ atomic_read_unchecked(&fscache_n_allocs_wait),
53380+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53381+ atomic_read_unchecked(&fscache_n_allocs_intr));
53382 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53383- atomic_read(&fscache_n_alloc_ops),
53384- atomic_read(&fscache_n_alloc_op_waits),
53385- atomic_read(&fscache_n_allocs_object_dead));
53386+ atomic_read_unchecked(&fscache_n_alloc_ops),
53387+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53388+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53389
53390 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53391 " int=%u oom=%u\n",
53392- atomic_read(&fscache_n_retrievals),
53393- atomic_read(&fscache_n_retrievals_ok),
53394- atomic_read(&fscache_n_retrievals_wait),
53395- atomic_read(&fscache_n_retrievals_nodata),
53396- atomic_read(&fscache_n_retrievals_nobufs),
53397- atomic_read(&fscache_n_retrievals_intr),
53398- atomic_read(&fscache_n_retrievals_nomem));
53399+ atomic_read_unchecked(&fscache_n_retrievals),
53400+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53401+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53402+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53403+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53404+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53405+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53406 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53407- atomic_read(&fscache_n_retrieval_ops),
53408- atomic_read(&fscache_n_retrieval_op_waits),
53409- atomic_read(&fscache_n_retrievals_object_dead));
53410+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53411+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53412+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53413
53414 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53415- atomic_read(&fscache_n_stores),
53416- atomic_read(&fscache_n_stores_ok),
53417- atomic_read(&fscache_n_stores_again),
53418- atomic_read(&fscache_n_stores_nobufs),
53419- atomic_read(&fscache_n_stores_oom));
53420+ atomic_read_unchecked(&fscache_n_stores),
53421+ atomic_read_unchecked(&fscache_n_stores_ok),
53422+ atomic_read_unchecked(&fscache_n_stores_again),
53423+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53424+ atomic_read_unchecked(&fscache_n_stores_oom));
53425 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53426- atomic_read(&fscache_n_store_ops),
53427- atomic_read(&fscache_n_store_calls),
53428- atomic_read(&fscache_n_store_pages),
53429- atomic_read(&fscache_n_store_radix_deletes),
53430- atomic_read(&fscache_n_store_pages_over_limit));
53431+ atomic_read_unchecked(&fscache_n_store_ops),
53432+ atomic_read_unchecked(&fscache_n_store_calls),
53433+ atomic_read_unchecked(&fscache_n_store_pages),
53434+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53435+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53436
53437 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53438- atomic_read(&fscache_n_store_vmscan_not_storing),
53439- atomic_read(&fscache_n_store_vmscan_gone),
53440- atomic_read(&fscache_n_store_vmscan_busy),
53441- atomic_read(&fscache_n_store_vmscan_cancelled),
53442- atomic_read(&fscache_n_store_vmscan_wait));
53443+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53444+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53445+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53446+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53447+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53448
53449 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53450- atomic_read(&fscache_n_op_pend),
53451- atomic_read(&fscache_n_op_run),
53452- atomic_read(&fscache_n_op_enqueue),
53453- atomic_read(&fscache_n_op_cancelled),
53454- atomic_read(&fscache_n_op_rejected));
53455+ atomic_read_unchecked(&fscache_n_op_pend),
53456+ atomic_read_unchecked(&fscache_n_op_run),
53457+ atomic_read_unchecked(&fscache_n_op_enqueue),
53458+ atomic_read_unchecked(&fscache_n_op_cancelled),
53459+ atomic_read_unchecked(&fscache_n_op_rejected));
53460 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53461- atomic_read(&fscache_n_op_deferred_release),
53462- atomic_read(&fscache_n_op_release),
53463- atomic_read(&fscache_n_op_gc));
53464+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53465+ atomic_read_unchecked(&fscache_n_op_release),
53466+ atomic_read_unchecked(&fscache_n_op_gc));
53467
53468 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53469 atomic_read(&fscache_n_cop_alloc_object),
53470diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53471index aef34b1..59bfd7b 100644
53472--- a/fs/fuse/cuse.c
53473+++ b/fs/fuse/cuse.c
53474@@ -600,10 +600,12 @@ static int __init cuse_init(void)
53475 INIT_LIST_HEAD(&cuse_conntbl[i]);
53476
53477 /* inherit and extend fuse_dev_operations */
53478- cuse_channel_fops = fuse_dev_operations;
53479- cuse_channel_fops.owner = THIS_MODULE;
53480- cuse_channel_fops.open = cuse_channel_open;
53481- cuse_channel_fops.release = cuse_channel_release;
53482+ pax_open_kernel();
53483+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53484+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53485+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53486+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53487+ pax_close_kernel();
53488
53489 cuse_class = class_create(THIS_MODULE, "cuse");
53490 if (IS_ERR(cuse_class))
53491diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53492index 1d55f94..088da65 100644
53493--- a/fs/fuse/dev.c
53494+++ b/fs/fuse/dev.c
53495@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53496 ret = 0;
53497 pipe_lock(pipe);
53498
53499- if (!pipe->readers) {
53500+ if (!atomic_read(&pipe->readers)) {
53501 send_sig(SIGPIPE, current, 0);
53502 if (!ret)
53503 ret = -EPIPE;
53504@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53505 page_nr++;
53506 ret += buf->len;
53507
53508- if (pipe->files)
53509+ if (atomic_read(&pipe->files))
53510 do_wakeup = 1;
53511 }
53512
53513diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53514index 5b12746..b481b03 100644
53515--- a/fs/fuse/dir.c
53516+++ b/fs/fuse/dir.c
53517@@ -1437,7 +1437,7 @@ static char *read_link(struct dentry *dentry)
53518 return link;
53519 }
53520
53521-static void free_link(char *link)
53522+static void free_link(const char *link)
53523 {
53524 if (!IS_ERR(link))
53525 free_page((unsigned long) link);
53526diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53527index 62b484e..0f9a140 100644
53528--- a/fs/gfs2/inode.c
53529+++ b/fs/gfs2/inode.c
53530@@ -1441,7 +1441,7 @@ out:
53531
53532 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53533 {
53534- char *s = nd_get_link(nd);
53535+ const char *s = nd_get_link(nd);
53536 if (!IS_ERR(s))
53537 kfree(s);
53538 }
53539diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53540index a3f868a..bb308ae 100644
53541--- a/fs/hugetlbfs/inode.c
53542+++ b/fs/hugetlbfs/inode.c
53543@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53544 struct mm_struct *mm = current->mm;
53545 struct vm_area_struct *vma;
53546 struct hstate *h = hstate_file(file);
53547+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53548 struct vm_unmapped_area_info info;
53549
53550 if (len & ~huge_page_mask(h))
53551@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53552 return addr;
53553 }
53554
53555+#ifdef CONFIG_PAX_RANDMMAP
53556+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53557+#endif
53558+
53559 if (addr) {
53560 addr = ALIGN(addr, huge_page_size(h));
53561 vma = find_vma(mm, addr);
53562- if (TASK_SIZE - len >= addr &&
53563- (!vma || addr + len <= vma->vm_start))
53564+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53565 return addr;
53566 }
53567
53568 info.flags = 0;
53569 info.length = len;
53570 info.low_limit = TASK_UNMAPPED_BASE;
53571+
53572+#ifdef CONFIG_PAX_RANDMMAP
53573+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53574+ info.low_limit += mm->delta_mmap;
53575+#endif
53576+
53577 info.high_limit = TASK_SIZE;
53578 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53579 info.align_offset = 0;
53580@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53581 };
53582 MODULE_ALIAS_FS("hugetlbfs");
53583
53584-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53585+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53586
53587 static int can_do_hugetlb_shm(void)
53588 {
53589diff --git a/fs/inode.c b/fs/inode.c
53590index 00d5fc3..98ce7d7 100644
53591--- a/fs/inode.c
53592+++ b/fs/inode.c
53593@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
53594
53595 #ifdef CONFIG_SMP
53596 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53597- static atomic_t shared_last_ino;
53598- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53599+ static atomic_unchecked_t shared_last_ino;
53600+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53601
53602 res = next - LAST_INO_BATCH;
53603 }
53604diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53605index 4a6cf28..d3a29d3 100644
53606--- a/fs/jffs2/erase.c
53607+++ b/fs/jffs2/erase.c
53608@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53609 struct jffs2_unknown_node marker = {
53610 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53611 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53612- .totlen = cpu_to_je32(c->cleanmarker_size)
53613+ .totlen = cpu_to_je32(c->cleanmarker_size),
53614+ .hdr_crc = cpu_to_je32(0)
53615 };
53616
53617 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53618diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53619index a6597d6..41b30ec 100644
53620--- a/fs/jffs2/wbuf.c
53621+++ b/fs/jffs2/wbuf.c
53622@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53623 {
53624 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53625 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53626- .totlen = constant_cpu_to_je32(8)
53627+ .totlen = constant_cpu_to_je32(8),
53628+ .hdr_crc = constant_cpu_to_je32(0)
53629 };
53630
53631 /*
53632diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53633index 788e0a9..8433098 100644
53634--- a/fs/jfs/super.c
53635+++ b/fs/jfs/super.c
53636@@ -878,7 +878,7 @@ static int __init init_jfs_fs(void)
53637
53638 jfs_inode_cachep =
53639 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53640- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53641+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53642 init_once);
53643 if (jfs_inode_cachep == NULL)
53644 return -ENOMEM;
53645diff --git a/fs/libfs.c b/fs/libfs.c
53646index 916da8c..1588998 100644
53647--- a/fs/libfs.c
53648+++ b/fs/libfs.c
53649@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53650
53651 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53652 struct dentry *next;
53653+ char d_name[sizeof(next->d_iname)];
53654+ const unsigned char *name;
53655+
53656 next = list_entry(p, struct dentry, d_u.d_child);
53657 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53658 if (!simple_positive(next)) {
53659@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53660
53661 spin_unlock(&next->d_lock);
53662 spin_unlock(&dentry->d_lock);
53663- if (filldir(dirent, next->d_name.name,
53664+ name = next->d_name.name;
53665+ if (name == next->d_iname) {
53666+ memcpy(d_name, name, next->d_name.len);
53667+ name = d_name;
53668+ }
53669+ if (filldir(dirent, name,
53670 next->d_name.len, filp->f_pos,
53671 next->d_inode->i_ino,
53672 dt_type(next->d_inode)) < 0)
53673diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53674index 9760ecb..9b838ef 100644
53675--- a/fs/lockd/clntproc.c
53676+++ b/fs/lockd/clntproc.c
53677@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53678 /*
53679 * Cookie counter for NLM requests
53680 */
53681-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53682+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53683
53684 void nlmclnt_next_cookie(struct nlm_cookie *c)
53685 {
53686- u32 cookie = atomic_inc_return(&nlm_cookie);
53687+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53688
53689 memcpy(c->data, &cookie, 4);
53690 c->len=4;
53691diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
53692index a2aa97d..10d6c41 100644
53693--- a/fs/lockd/svc.c
53694+++ b/fs/lockd/svc.c
53695@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
53696 svc_sock_update_bufs(serv);
53697 serv->sv_maxconn = nlm_max_connections;
53698
53699- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
53700+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
53701 if (IS_ERR(nlmsvc_task)) {
53702 error = PTR_ERR(nlmsvc_task);
53703 printk(KERN_WARNING
53704diff --git a/fs/locks.c b/fs/locks.c
53705index cb424a4..850e4dd 100644
53706--- a/fs/locks.c
53707+++ b/fs/locks.c
53708@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53709 return;
53710
53711 if (filp->f_op && filp->f_op->flock) {
53712- struct file_lock fl = {
53713+ struct file_lock flock = {
53714 .fl_pid = current->tgid,
53715 .fl_file = filp,
53716 .fl_flags = FL_FLOCK,
53717 .fl_type = F_UNLCK,
53718 .fl_end = OFFSET_MAX,
53719 };
53720- filp->f_op->flock(filp, F_SETLKW, &fl);
53721- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53722- fl.fl_ops->fl_release_private(&fl);
53723+ filp->f_op->flock(filp, F_SETLKW, &flock);
53724+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53725+ flock.fl_ops->fl_release_private(&flock);
53726 }
53727
53728 lock_flocks();
53729diff --git a/fs/namei.c b/fs/namei.c
53730index 9ed9361..2b72db1 100644
53731--- a/fs/namei.c
53732+++ b/fs/namei.c
53733@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53734 if (ret != -EACCES)
53735 return ret;
53736
53737+#ifdef CONFIG_GRKERNSEC
53738+ /* we'll block if we have to log due to a denied capability use */
53739+ if (mask & MAY_NOT_BLOCK)
53740+ return -ECHILD;
53741+#endif
53742+
53743 if (S_ISDIR(inode->i_mode)) {
53744 /* DACs are overridable for directories */
53745- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53746- return 0;
53747 if (!(mask & MAY_WRITE))
53748- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53749+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53750+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53751 return 0;
53752+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53753+ return 0;
53754 return -EACCES;
53755 }
53756 /*
53757+ * Searching includes executable on directories, else just read.
53758+ */
53759+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53760+ if (mask == MAY_READ)
53761+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53762+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53763+ return 0;
53764+
53765+ /*
53766 * Read/write DACs are always overridable.
53767 * Executable DACs are overridable when there is
53768 * at least one exec bit set.
53769@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53770 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53771 return 0;
53772
53773- /*
53774- * Searching includes executable on directories, else just read.
53775- */
53776- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53777- if (mask == MAY_READ)
53778- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53779- return 0;
53780-
53781 return -EACCES;
53782 }
53783
53784@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53785 {
53786 struct dentry *dentry = link->dentry;
53787 int error;
53788- char *s;
53789+ const char *s;
53790
53791 BUG_ON(nd->flags & LOOKUP_RCU);
53792
53793@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53794 if (error)
53795 goto out_put_nd_path;
53796
53797+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53798+ dentry->d_inode, dentry, nd->path.mnt)) {
53799+ error = -EACCES;
53800+ goto out_put_nd_path;
53801+ }
53802+
53803 nd->last_type = LAST_BIND;
53804 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53805 error = PTR_ERR(*p);
53806@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53807 if (res)
53808 break;
53809 res = walk_component(nd, path, LOOKUP_FOLLOW);
53810+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53811+ res = -EACCES;
53812 put_link(nd, &link, cookie);
53813 } while (res > 0);
53814
53815@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
53816 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53817 {
53818 unsigned long a, b, adata, bdata, mask, hash, len;
53819- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53820+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53821
53822 hash = a = 0;
53823 len = -sizeof(unsigned long);
53824@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
53825 if (err)
53826 break;
53827 err = lookup_last(nd, &path);
53828+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53829+ err = -EACCES;
53830 put_link(nd, &link, cookie);
53831 }
53832 }
53833@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
53834 if (!err)
53835 err = complete_walk(nd);
53836
53837+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53838+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53839+ path_put(&nd->path);
53840+ err = -ENOENT;
53841+ }
53842+ }
53843+
53844 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53845 if (!can_lookup(nd->inode)) {
53846 path_put(&nd->path);
53847@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
53848 retval = path_lookupat(dfd, name->name,
53849 flags | LOOKUP_REVAL, nd);
53850
53851- if (likely(!retval))
53852+ if (likely(!retval)) {
53853 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53854+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53855+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53856+ path_put(&nd->path);
53857+ return -ENOENT;
53858+ }
53859+ }
53860+ }
53861 return retval;
53862 }
53863
53864@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53865 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53866 return -EPERM;
53867
53868+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53869+ return -EPERM;
53870+ if (gr_handle_rawio(inode))
53871+ return -EPERM;
53872+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53873+ return -EACCES;
53874+
53875 return 0;
53876 }
53877
53878@@ -2602,7 +2641,7 @@ looked_up:
53879 * cleared otherwise prior to returning.
53880 */
53881 static int lookup_open(struct nameidata *nd, struct path *path,
53882- struct file *file,
53883+ struct path *link, struct file *file,
53884 const struct open_flags *op,
53885 bool got_write, int *opened)
53886 {
53887@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53888 /* Negative dentry, just create the file */
53889 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53890 umode_t mode = op->mode;
53891+
53892+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53893+ error = -EACCES;
53894+ goto out_dput;
53895+ }
53896+
53897+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53898+ error = -EACCES;
53899+ goto out_dput;
53900+ }
53901+
53902 if (!IS_POSIXACL(dir->d_inode))
53903 mode &= ~current_umask();
53904 /*
53905@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53906 nd->flags & LOOKUP_EXCL);
53907 if (error)
53908 goto out_dput;
53909+ else
53910+ gr_handle_create(dentry, nd->path.mnt);
53911 }
53912 out_no_open:
53913 path->dentry = dentry;
53914@@ -2672,7 +2724,7 @@ out_dput:
53915 /*
53916 * Handle the last step of open()
53917 */
53918-static int do_last(struct nameidata *nd, struct path *path,
53919+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53920 struct file *file, const struct open_flags *op,
53921 int *opened, struct filename *name)
53922 {
53923@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53924 error = complete_walk(nd);
53925 if (error)
53926 return error;
53927+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53928+ error = -ENOENT;
53929+ goto out;
53930+ }
53931 audit_inode(name, nd->path.dentry, 0);
53932 if (open_flag & O_CREAT) {
53933 error = -EISDIR;
53934 goto out;
53935 }
53936+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53937+ error = -EACCES;
53938+ goto out;
53939+ }
53940 goto finish_open;
53941 case LAST_BIND:
53942 error = complete_walk(nd);
53943 if (error)
53944 return error;
53945+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53946+ error = -ENOENT;
53947+ goto out;
53948+ }
53949+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53950+ error = -EACCES;
53951+ goto out;
53952+ }
53953 audit_inode(name, dir, 0);
53954 goto finish_open;
53955 }
53956@@ -2759,7 +2827,7 @@ retry_lookup:
53957 */
53958 }
53959 mutex_lock(&dir->d_inode->i_mutex);
53960- error = lookup_open(nd, path, file, op, got_write, opened);
53961+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53962 mutex_unlock(&dir->d_inode->i_mutex);
53963
53964 if (error <= 0) {
53965@@ -2783,11 +2851,28 @@ retry_lookup:
53966 goto finish_open_created;
53967 }
53968
53969+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53970+ error = -ENOENT;
53971+ goto exit_dput;
53972+ }
53973+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53974+ error = -EACCES;
53975+ goto exit_dput;
53976+ }
53977+
53978 /*
53979 * create/update audit record if it already exists.
53980 */
53981- if (path->dentry->d_inode)
53982+ if (path->dentry->d_inode) {
53983+ /* only check if O_CREAT is specified, all other checks need to go
53984+ into may_open */
53985+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53986+ error = -EACCES;
53987+ goto exit_dput;
53988+ }
53989+
53990 audit_inode(name, path->dentry, 0);
53991+ }
53992
53993 /*
53994 * If atomic_open() acquired write access it is dropped now due to
53995@@ -2828,6 +2913,11 @@ finish_lookup:
53996 }
53997 }
53998 BUG_ON(inode != path->dentry->d_inode);
53999+ /* if we're resolving a symlink to another symlink */
54000+ if (link && gr_handle_symlink_owner(link, inode)) {
54001+ error = -EACCES;
54002+ goto out;
54003+ }
54004 return 1;
54005 }
54006
54007@@ -2837,7 +2927,6 @@ finish_lookup:
54008 save_parent.dentry = nd->path.dentry;
54009 save_parent.mnt = mntget(path->mnt);
54010 nd->path.dentry = path->dentry;
54011-
54012 }
54013 nd->inode = inode;
54014 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
54015@@ -2846,6 +2935,16 @@ finish_lookup:
54016 path_put(&save_parent);
54017 return error;
54018 }
54019+
54020+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
54021+ error = -ENOENT;
54022+ goto out;
54023+ }
54024+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
54025+ error = -EACCES;
54026+ goto out;
54027+ }
54028+
54029 error = -EISDIR;
54030 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
54031 goto out;
54032@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
54033 if (unlikely(error))
54034 goto out;
54035
54036- error = do_last(nd, &path, file, op, &opened, pathname);
54037+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
54038 while (unlikely(error > 0)) { /* trailing symlink */
54039 struct path link = path;
54040 void *cookie;
54041@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
54042 error = follow_link(&link, nd, &cookie);
54043 if (unlikely(error))
54044 break;
54045- error = do_last(nd, &path, file, op, &opened, pathname);
54046+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
54047 put_link(nd, &link, cookie);
54048 }
54049 out:
54050@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
54051 goto unlock;
54052
54053 error = -EEXIST;
54054- if (dentry->d_inode)
54055+ if (dentry->d_inode) {
54056+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
54057+ error = -ENOENT;
54058+ }
54059 goto fail;
54060+ }
54061 /*
54062 * Special case - lookup gave negative, but... we had foo/bar/
54063 * From the vfs_mknod() POV we just have a negative dentry -
54064@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
54065 }
54066 EXPORT_SYMBOL(user_path_create);
54067
54068+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
54069+{
54070+ struct filename *tmp = getname(pathname);
54071+ struct dentry *res;
54072+ if (IS_ERR(tmp))
54073+ return ERR_CAST(tmp);
54074+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
54075+ if (IS_ERR(res))
54076+ putname(tmp);
54077+ else
54078+ *to = tmp;
54079+ return res;
54080+}
54081+
54082 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
54083 {
54084 int error = may_create(dir, dentry);
54085@@ -3177,6 +3294,17 @@ retry:
54086
54087 if (!IS_POSIXACL(path.dentry->d_inode))
54088 mode &= ~current_umask();
54089+
54090+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
54091+ error = -EPERM;
54092+ goto out;
54093+ }
54094+
54095+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
54096+ error = -EACCES;
54097+ goto out;
54098+ }
54099+
54100 error = security_path_mknod(&path, dentry, mode, dev);
54101 if (error)
54102 goto out;
54103@@ -3193,6 +3321,8 @@ retry:
54104 break;
54105 }
54106 out:
54107+ if (!error)
54108+ gr_handle_create(dentry, path.mnt);
54109 done_path_create(&path, dentry);
54110 if (retry_estale(error, lookup_flags)) {
54111 lookup_flags |= LOOKUP_REVAL;
54112@@ -3245,9 +3375,16 @@ retry:
54113
54114 if (!IS_POSIXACL(path.dentry->d_inode))
54115 mode &= ~current_umask();
54116+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
54117+ error = -EACCES;
54118+ goto out;
54119+ }
54120 error = security_path_mkdir(&path, dentry, mode);
54121 if (!error)
54122 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
54123+ if (!error)
54124+ gr_handle_create(dentry, path.mnt);
54125+out:
54126 done_path_create(&path, dentry);
54127 if (retry_estale(error, lookup_flags)) {
54128 lookup_flags |= LOOKUP_REVAL;
54129@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
54130 struct filename *name;
54131 struct dentry *dentry;
54132 struct nameidata nd;
54133+ ino_t saved_ino = 0;
54134+ dev_t saved_dev = 0;
54135 unsigned int lookup_flags = 0;
54136 retry:
54137 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54138@@ -3360,10 +3499,21 @@ retry:
54139 error = -ENOENT;
54140 goto exit3;
54141 }
54142+
54143+ saved_ino = dentry->d_inode->i_ino;
54144+ saved_dev = gr_get_dev_from_dentry(dentry);
54145+
54146+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
54147+ error = -EACCES;
54148+ goto exit3;
54149+ }
54150+
54151 error = security_path_rmdir(&nd.path, dentry);
54152 if (error)
54153 goto exit3;
54154 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
54155+ if (!error && (saved_dev || saved_ino))
54156+ gr_handle_delete(saved_ino, saved_dev);
54157 exit3:
54158 dput(dentry);
54159 exit2:
54160@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
54161 struct dentry *dentry;
54162 struct nameidata nd;
54163 struct inode *inode = NULL;
54164+ ino_t saved_ino = 0;
54165+ dev_t saved_dev = 0;
54166 unsigned int lookup_flags = 0;
54167 retry:
54168 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
54169@@ -3455,10 +3607,22 @@ retry:
54170 if (!inode)
54171 goto slashes;
54172 ihold(inode);
54173+
54174+ if (inode->i_nlink <= 1) {
54175+ saved_ino = inode->i_ino;
54176+ saved_dev = gr_get_dev_from_dentry(dentry);
54177+ }
54178+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
54179+ error = -EACCES;
54180+ goto exit2;
54181+ }
54182+
54183 error = security_path_unlink(&nd.path, dentry);
54184 if (error)
54185 goto exit2;
54186 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
54187+ if (!error && (saved_ino || saved_dev))
54188+ gr_handle_delete(saved_ino, saved_dev);
54189 exit2:
54190 dput(dentry);
54191 }
54192@@ -3536,9 +3700,17 @@ retry:
54193 if (IS_ERR(dentry))
54194 goto out_putname;
54195
54196+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
54197+ error = -EACCES;
54198+ goto out;
54199+ }
54200+
54201 error = security_path_symlink(&path, dentry, from->name);
54202 if (!error)
54203 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54204+ if (!error)
54205+ gr_handle_create(dentry, path.mnt);
54206+out:
54207 done_path_create(&path, dentry);
54208 if (retry_estale(error, lookup_flags)) {
54209 lookup_flags |= LOOKUP_REVAL;
54210@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54211 {
54212 struct dentry *new_dentry;
54213 struct path old_path, new_path;
54214+ struct filename *to = NULL;
54215 int how = 0;
54216 int error;
54217
54218@@ -3635,7 +3808,7 @@ retry:
54219 if (error)
54220 return error;
54221
54222- new_dentry = user_path_create(newdfd, newname, &new_path,
54223+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54224 (how & LOOKUP_REVAL));
54225 error = PTR_ERR(new_dentry);
54226 if (IS_ERR(new_dentry))
54227@@ -3647,11 +3820,28 @@ retry:
54228 error = may_linkat(&old_path);
54229 if (unlikely(error))
54230 goto out_dput;
54231+
54232+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54233+ old_path.dentry->d_inode,
54234+ old_path.dentry->d_inode->i_mode, to)) {
54235+ error = -EACCES;
54236+ goto out_dput;
54237+ }
54238+
54239+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54240+ old_path.dentry, old_path.mnt, to)) {
54241+ error = -EACCES;
54242+ goto out_dput;
54243+ }
54244+
54245 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54246 if (error)
54247 goto out_dput;
54248 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54249+ if (!error)
54250+ gr_handle_create(new_dentry, new_path.mnt);
54251 out_dput:
54252+ putname(to);
54253 done_path_create(&new_path, new_dentry);
54254 if (retry_estale(error, how)) {
54255 how |= LOOKUP_REVAL;
54256@@ -3897,12 +4087,21 @@ retry:
54257 if (new_dentry == trap)
54258 goto exit5;
54259
54260+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54261+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54262+ to);
54263+ if (error)
54264+ goto exit5;
54265+
54266 error = security_path_rename(&oldnd.path, old_dentry,
54267 &newnd.path, new_dentry);
54268 if (error)
54269 goto exit5;
54270 error = vfs_rename(old_dir->d_inode, old_dentry,
54271 new_dir->d_inode, new_dentry);
54272+ if (!error)
54273+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54274+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54275 exit5:
54276 dput(new_dentry);
54277 exit4:
54278@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54279
54280 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54281 {
54282+ char tmpbuf[64];
54283+ const char *newlink;
54284 int len;
54285
54286 len = PTR_ERR(link);
54287@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54288 len = strlen(link);
54289 if (len > (unsigned) buflen)
54290 len = buflen;
54291- if (copy_to_user(buffer, link, len))
54292+
54293+ if (len < sizeof(tmpbuf)) {
54294+ memcpy(tmpbuf, link, len);
54295+ newlink = tmpbuf;
54296+ } else
54297+ newlink = link;
54298+
54299+ if (copy_to_user(buffer, newlink, len))
54300 len = -EFAULT;
54301 out:
54302 return len;
54303diff --git a/fs/namespace.c b/fs/namespace.c
54304index 7b1ca9b..6faeccf 100644
54305--- a/fs/namespace.c
54306+++ b/fs/namespace.c
54307@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
54308 if (!(sb->s_flags & MS_RDONLY))
54309 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54310 up_write(&sb->s_umount);
54311+
54312+ gr_log_remount(mnt->mnt_devname, retval);
54313+
54314 return retval;
54315 }
54316
54317@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
54318 }
54319 br_write_unlock(&vfsmount_lock);
54320 namespace_unlock();
54321+
54322+ gr_log_unmount(mnt->mnt_devname, retval);
54323+
54324 return retval;
54325 }
54326
54327@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
54328 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
54329 */
54330
54331-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
54332+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
54333 {
54334 struct path path;
54335 struct mount *mnt;
54336@@ -1342,7 +1348,7 @@ out:
54337 /*
54338 * The 2.0 compatible umount. No flags.
54339 */
54340-SYSCALL_DEFINE1(oldumount, char __user *, name)
54341+SYSCALL_DEFINE1(oldumount, const char __user *, name)
54342 {
54343 return sys_umount(name, 0);
54344 }
54345@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54346 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54347 MS_STRICTATIME);
54348
54349+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54350+ retval = -EPERM;
54351+ goto dput_out;
54352+ }
54353+
54354+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54355+ retval = -EPERM;
54356+ goto dput_out;
54357+ }
54358+
54359 if (flags & MS_REMOUNT)
54360 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54361 data_page);
54362@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54363 dev_name, data_page);
54364 dput_out:
54365 path_put(&path);
54366+
54367+ gr_log_mount(dev_name, dir_name, retval);
54368+
54369 return retval;
54370 }
54371
54372@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
54373 }
54374 EXPORT_SYMBOL(mount_subtree);
54375
54376-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
54377- char __user *, type, unsigned long, flags, void __user *, data)
54378+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
54379+ const char __user *, type, unsigned long, flags, void __user *, data)
54380 {
54381 int ret;
54382 char *kernel_type;
54383@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54384 if (error)
54385 goto out2;
54386
54387+ if (gr_handle_chroot_pivot()) {
54388+ error = -EPERM;
54389+ goto out2;
54390+ }
54391+
54392 get_fs_root(current->fs, &root);
54393 old_mp = lock_mount(&old);
54394 error = PTR_ERR(old_mp);
54395@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54396 !nsown_capable(CAP_SYS_ADMIN))
54397 return -EPERM;
54398
54399- if (fs->users != 1)
54400+ if (atomic_read(&fs->users) != 1)
54401 return -EINVAL;
54402
54403 get_mnt_ns(mnt_ns);
54404diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
54405index cff089a..4c3d57a 100644
54406--- a/fs/nfs/callback.c
54407+++ b/fs/nfs/callback.c
54408@@ -211,7 +211,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54409 struct svc_rqst *rqstp;
54410 int (*callback_svc)(void *vrqstp);
54411 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
54412- char svc_name[12];
54413 int ret;
54414
54415 nfs_callback_bc_serv(minorversion, xprt, serv);
54416@@ -235,10 +234,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54417
54418 svc_sock_update_bufs(serv);
54419
54420- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
54421 cb_info->serv = serv;
54422 cb_info->rqst = rqstp;
54423- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
54424+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
54425 if (IS_ERR(cb_info->task)) {
54426 ret = PTR_ERR(cb_info->task);
54427 svc_exit_thread(cb_info->rqst);
54428diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54429index a35582c..ebbdcd5 100644
54430--- a/fs/nfs/callback_xdr.c
54431+++ b/fs/nfs/callback_xdr.c
54432@@ -51,7 +51,7 @@ struct callback_op {
54433 callback_decode_arg_t decode_args;
54434 callback_encode_res_t encode_res;
54435 long res_maxsize;
54436-};
54437+} __do_const;
54438
54439 static struct callback_op callback_ops[];
54440
54441diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54442index c1c7a9d..7afa0b8 100644
54443--- a/fs/nfs/inode.c
54444+++ b/fs/nfs/inode.c
54445@@ -1043,16 +1043,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54446 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54447 }
54448
54449-static atomic_long_t nfs_attr_generation_counter;
54450+static atomic_long_unchecked_t nfs_attr_generation_counter;
54451
54452 static unsigned long nfs_read_attr_generation_counter(void)
54453 {
54454- return atomic_long_read(&nfs_attr_generation_counter);
54455+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54456 }
54457
54458 unsigned long nfs_inc_attr_generation_counter(void)
54459 {
54460- return atomic_long_inc_return(&nfs_attr_generation_counter);
54461+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54462 }
54463
54464 void nfs_fattr_init(struct nfs_fattr *fattr)
54465diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
54466index 2c37442..9b9538b 100644
54467--- a/fs/nfs/nfs4state.c
54468+++ b/fs/nfs/nfs4state.c
54469@@ -1193,7 +1193,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
54470 snprintf(buf, sizeof(buf), "%s-manager",
54471 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
54472 rcu_read_unlock();
54473- task = kthread_run(nfs4_run_state_manager, clp, buf);
54474+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
54475 if (IS_ERR(task)) {
54476 printk(KERN_ERR "%s: kthread_run: %ld\n",
54477 __func__, PTR_ERR(task));
54478diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54479index 27d74a2..c4c2a73 100644
54480--- a/fs/nfsd/nfs4proc.c
54481+++ b/fs/nfsd/nfs4proc.c
54482@@ -1126,7 +1126,7 @@ struct nfsd4_operation {
54483 nfsd4op_rsize op_rsize_bop;
54484 stateid_getter op_get_currentstateid;
54485 stateid_setter op_set_currentstateid;
54486-};
54487+} __do_const;
54488
54489 static struct nfsd4_operation nfsd4_ops[];
54490
54491diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54492index 582321a..0224663 100644
54493--- a/fs/nfsd/nfs4xdr.c
54494+++ b/fs/nfsd/nfs4xdr.c
54495@@ -1458,7 +1458,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54496
54497 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54498
54499-static nfsd4_dec nfsd4_dec_ops[] = {
54500+static const nfsd4_dec nfsd4_dec_ops[] = {
54501 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54502 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54503 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54504@@ -1498,7 +1498,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54505 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54506 };
54507
54508-static nfsd4_dec nfsd41_dec_ops[] = {
54509+static const nfsd4_dec nfsd41_dec_ops[] = {
54510 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54511 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54512 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54513@@ -1560,7 +1560,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54514 };
54515
54516 struct nfsd4_minorversion_ops {
54517- nfsd4_dec *decoders;
54518+ const nfsd4_dec *decoders;
54519 int nops;
54520 };
54521
54522diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54523index e76244e..9fe8f2f1 100644
54524--- a/fs/nfsd/nfscache.c
54525+++ b/fs/nfsd/nfscache.c
54526@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54527 {
54528 struct svc_cacherep *rp = rqstp->rq_cacherep;
54529 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
54530- int len;
54531+ long len;
54532 size_t bufsize = 0;
54533
54534 if (!rp)
54535 return;
54536
54537- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54538- len >>= 2;
54539+ if (statp) {
54540+ len = (char*)statp - (char*)resv->iov_base;
54541+ len = resv->iov_len - len;
54542+ len >>= 2;
54543+ }
54544
54545 /* Don't cache excessive amounts of data and XDR failures */
54546 if (!statp || len > (256 >> 2)) {
54547diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54548index baf149a..76b86ad 100644
54549--- a/fs/nfsd/vfs.c
54550+++ b/fs/nfsd/vfs.c
54551@@ -940,7 +940,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54552 } else {
54553 oldfs = get_fs();
54554 set_fs(KERNEL_DS);
54555- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54556+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54557 set_fs(oldfs);
54558 }
54559
54560@@ -1027,7 +1027,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54561
54562 /* Write the data. */
54563 oldfs = get_fs(); set_fs(KERNEL_DS);
54564- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54565+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54566 set_fs(oldfs);
54567 if (host_err < 0)
54568 goto out_nfserr;
54569@@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54570 */
54571
54572 oldfs = get_fs(); set_fs(KERNEL_DS);
54573- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54574+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54575 set_fs(oldfs);
54576
54577 if (host_err < 0)
54578diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54579index fea6bd5..8ee9d81 100644
54580--- a/fs/nls/nls_base.c
54581+++ b/fs/nls/nls_base.c
54582@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54583
54584 int register_nls(struct nls_table * nls)
54585 {
54586- struct nls_table ** tmp = &tables;
54587+ struct nls_table *tmp = tables;
54588
54589 if (nls->next)
54590 return -EBUSY;
54591
54592 spin_lock(&nls_lock);
54593- while (*tmp) {
54594- if (nls == *tmp) {
54595+ while (tmp) {
54596+ if (nls == tmp) {
54597 spin_unlock(&nls_lock);
54598 return -EBUSY;
54599 }
54600- tmp = &(*tmp)->next;
54601+ tmp = tmp->next;
54602 }
54603- nls->next = tables;
54604+ pax_open_kernel();
54605+ *(struct nls_table **)&nls->next = tables;
54606+ pax_close_kernel();
54607 tables = nls;
54608 spin_unlock(&nls_lock);
54609 return 0;
54610@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54611
54612 int unregister_nls(struct nls_table * nls)
54613 {
54614- struct nls_table ** tmp = &tables;
54615+ struct nls_table * const * tmp = &tables;
54616
54617 spin_lock(&nls_lock);
54618 while (*tmp) {
54619 if (nls == *tmp) {
54620- *tmp = nls->next;
54621+ pax_open_kernel();
54622+ *(struct nls_table **)tmp = nls->next;
54623+ pax_close_kernel();
54624 spin_unlock(&nls_lock);
54625 return 0;
54626 }
54627diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54628index 7424929..35f6be5 100644
54629--- a/fs/nls/nls_euc-jp.c
54630+++ b/fs/nls/nls_euc-jp.c
54631@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54632 p_nls = load_nls("cp932");
54633
54634 if (p_nls) {
54635- table.charset2upper = p_nls->charset2upper;
54636- table.charset2lower = p_nls->charset2lower;
54637+ pax_open_kernel();
54638+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54639+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54640+ pax_close_kernel();
54641 return register_nls(&table);
54642 }
54643
54644diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54645index e7bc1d7..06bd4bb 100644
54646--- a/fs/nls/nls_koi8-ru.c
54647+++ b/fs/nls/nls_koi8-ru.c
54648@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54649 p_nls = load_nls("koi8-u");
54650
54651 if (p_nls) {
54652- table.charset2upper = p_nls->charset2upper;
54653- table.charset2lower = p_nls->charset2lower;
54654+ pax_open_kernel();
54655+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54656+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54657+ pax_close_kernel();
54658 return register_nls(&table);
54659 }
54660
54661diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54662index 6c80083..a1e6299 100644
54663--- a/fs/notify/fanotify/fanotify_user.c
54664+++ b/fs/notify/fanotify/fanotify_user.c
54665@@ -122,6 +122,7 @@ static int fill_event_metadata(struct fsnotify_group *group,
54666 metadata->event_len = FAN_EVENT_METADATA_LEN;
54667 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
54668 metadata->vers = FANOTIFY_METADATA_VERSION;
54669+ metadata->reserved = 0;
54670 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
54671 metadata->pid = pid_vnr(event->tgid);
54672 if (unlikely(event->mask & FAN_Q_OVERFLOW))
54673@@ -252,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54674
54675 fd = fanotify_event_metadata.fd;
54676 ret = -EFAULT;
54677- if (copy_to_user(buf, &fanotify_event_metadata,
54678- fanotify_event_metadata.event_len))
54679+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54680+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54681 goto out_close_fd;
54682
54683 ret = prepare_for_access_response(group, event, fd);
54684diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54685index 7b51b05..5ea5ef6 100644
54686--- a/fs/notify/notification.c
54687+++ b/fs/notify/notification.c
54688@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54689 * get set to 0 so it will never get 'freed'
54690 */
54691 static struct fsnotify_event *q_overflow_event;
54692-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54693+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54694
54695 /**
54696 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54697@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54698 */
54699 u32 fsnotify_get_cookie(void)
54700 {
54701- return atomic_inc_return(&fsnotify_sync_cookie);
54702+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54703 }
54704 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54705
54706diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54707index aa411c3..c260a84 100644
54708--- a/fs/ntfs/dir.c
54709+++ b/fs/ntfs/dir.c
54710@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54711 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54712 ~(s64)(ndir->itype.index.block_size - 1)));
54713 /* Bounds checks. */
54714- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54715+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54716 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54717 "inode 0x%lx or driver bug.", vdir->i_ino);
54718 goto err_out;
54719diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54720index c5670b8..01a3656 100644
54721--- a/fs/ntfs/file.c
54722+++ b/fs/ntfs/file.c
54723@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54724 #endif /* NTFS_RW */
54725 };
54726
54727-const struct file_operations ntfs_empty_file_ops = {};
54728+const struct file_operations ntfs_empty_file_ops __read_only;
54729
54730-const struct inode_operations ntfs_empty_inode_ops = {};
54731+const struct inode_operations ntfs_empty_inode_ops __read_only;
54732diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54733index aebeacd..0dcdd26 100644
54734--- a/fs/ocfs2/localalloc.c
54735+++ b/fs/ocfs2/localalloc.c
54736@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54737 goto bail;
54738 }
54739
54740- atomic_inc(&osb->alloc_stats.moves);
54741+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54742
54743 bail:
54744 if (handle)
54745diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54746index d355e6e..578d905 100644
54747--- a/fs/ocfs2/ocfs2.h
54748+++ b/fs/ocfs2/ocfs2.h
54749@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54750
54751 struct ocfs2_alloc_stats
54752 {
54753- atomic_t moves;
54754- atomic_t local_data;
54755- atomic_t bitmap_data;
54756- atomic_t bg_allocs;
54757- atomic_t bg_extends;
54758+ atomic_unchecked_t moves;
54759+ atomic_unchecked_t local_data;
54760+ atomic_unchecked_t bitmap_data;
54761+ atomic_unchecked_t bg_allocs;
54762+ atomic_unchecked_t bg_extends;
54763 };
54764
54765 enum ocfs2_local_alloc_state
54766diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54767index b7e74b5..19c6536 100644
54768--- a/fs/ocfs2/suballoc.c
54769+++ b/fs/ocfs2/suballoc.c
54770@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54771 mlog_errno(status);
54772 goto bail;
54773 }
54774- atomic_inc(&osb->alloc_stats.bg_extends);
54775+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54776
54777 /* You should never ask for this much metadata */
54778 BUG_ON(bits_wanted >
54779@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54780 mlog_errno(status);
54781 goto bail;
54782 }
54783- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54784+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54785
54786 *suballoc_loc = res.sr_bg_blkno;
54787 *suballoc_bit_start = res.sr_bit_offset;
54788@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54789 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54790 res->sr_bits);
54791
54792- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54793+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54794
54795 BUG_ON(res->sr_bits != 1);
54796
54797@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54798 mlog_errno(status);
54799 goto bail;
54800 }
54801- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54802+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54803
54804 BUG_ON(res.sr_bits != 1);
54805
54806@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54807 cluster_start,
54808 num_clusters);
54809 if (!status)
54810- atomic_inc(&osb->alloc_stats.local_data);
54811+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54812 } else {
54813 if (min_clusters > (osb->bitmap_cpg - 1)) {
54814 /* The only paths asking for contiguousness
54815@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54816 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54817 res.sr_bg_blkno,
54818 res.sr_bit_offset);
54819- atomic_inc(&osb->alloc_stats.bitmap_data);
54820+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54821 *num_clusters = res.sr_bits;
54822 }
54823 }
54824diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54825index 01b8516..579c4df 100644
54826--- a/fs/ocfs2/super.c
54827+++ b/fs/ocfs2/super.c
54828@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54829 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54830 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54831 "Stats",
54832- atomic_read(&osb->alloc_stats.bitmap_data),
54833- atomic_read(&osb->alloc_stats.local_data),
54834- atomic_read(&osb->alloc_stats.bg_allocs),
54835- atomic_read(&osb->alloc_stats.moves),
54836- atomic_read(&osb->alloc_stats.bg_extends));
54837+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54838+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54839+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54840+ atomic_read_unchecked(&osb->alloc_stats.moves),
54841+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54842
54843 out += snprintf(buf + out, len - out,
54844 "%10s => State: %u Descriptor: %llu Size: %u bits "
54845@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54846 spin_lock_init(&osb->osb_xattr_lock);
54847 ocfs2_init_steal_slots(osb);
54848
54849- atomic_set(&osb->alloc_stats.moves, 0);
54850- atomic_set(&osb->alloc_stats.local_data, 0);
54851- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54852- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54853- atomic_set(&osb->alloc_stats.bg_extends, 0);
54854+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54855+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54856+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54857+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54858+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54859
54860 /* Copy the blockcheck stats from the superblock probe */
54861 osb->osb_ecc_stats = *stats;
54862diff --git a/fs/open.c b/fs/open.c
54863index 8c74100..4239c48 100644
54864--- a/fs/open.c
54865+++ b/fs/open.c
54866@@ -32,6 +32,8 @@
54867 #include <linux/dnotify.h>
54868 #include <linux/compat.h>
54869
54870+#define CREATE_TRACE_POINTS
54871+#include <trace/events/fs.h>
54872 #include "internal.h"
54873
54874 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54875@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
54876 error = locks_verify_truncate(inode, NULL, length);
54877 if (!error)
54878 error = security_path_truncate(path);
54879+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54880+ error = -EACCES;
54881 if (!error)
54882 error = do_truncate(path->dentry, length, 0, NULL);
54883
54884@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54885 error = locks_verify_truncate(inode, f.file, length);
54886 if (!error)
54887 error = security_path_truncate(&f.file->f_path);
54888+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54889+ error = -EACCES;
54890 if (!error)
54891 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54892 sb_end_write(inode->i_sb);
54893@@ -360,6 +366,9 @@ retry:
54894 if (__mnt_is_readonly(path.mnt))
54895 res = -EROFS;
54896
54897+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54898+ res = -EACCES;
54899+
54900 out_path_release:
54901 path_put(&path);
54902 if (retry_estale(res, lookup_flags)) {
54903@@ -391,6 +400,8 @@ retry:
54904 if (error)
54905 goto dput_and_out;
54906
54907+ gr_log_chdir(path.dentry, path.mnt);
54908+
54909 set_fs_pwd(current->fs, &path);
54910
54911 dput_and_out:
54912@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54913 goto out_putf;
54914
54915 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54916+
54917+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54918+ error = -EPERM;
54919+
54920+ if (!error)
54921+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54922+
54923 if (!error)
54924 set_fs_pwd(current->fs, &f.file->f_path);
54925 out_putf:
54926@@ -449,7 +467,13 @@ retry:
54927 if (error)
54928 goto dput_and_out;
54929
54930+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54931+ goto dput_and_out;
54932+
54933 set_fs_root(current->fs, &path);
54934+
54935+ gr_handle_chroot_chdir(&path);
54936+
54937 error = 0;
54938 dput_and_out:
54939 path_put(&path);
54940@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
54941 if (error)
54942 return error;
54943 mutex_lock(&inode->i_mutex);
54944+
54945+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54946+ error = -EACCES;
54947+ goto out_unlock;
54948+ }
54949+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54950+ error = -EACCES;
54951+ goto out_unlock;
54952+ }
54953+
54954 error = security_path_chmod(path, mode);
54955 if (error)
54956 goto out_unlock;
54957@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54958 uid = make_kuid(current_user_ns(), user);
54959 gid = make_kgid(current_user_ns(), group);
54960
54961+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54962+ return -EACCES;
54963+
54964 newattrs.ia_valid = ATTR_CTIME;
54965 if (user != (uid_t) -1) {
54966 if (!uid_valid(uid))
54967@@ -946,6 +983,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54968 } else {
54969 fsnotify_open(f);
54970 fd_install(fd, f);
54971+ trace_do_sys_open(tmp->name, flags, mode);
54972 }
54973 }
54974 putname(tmp);
54975diff --git a/fs/pipe.c b/fs/pipe.c
54976index d2c45e1..009fe1c 100644
54977--- a/fs/pipe.c
54978+++ b/fs/pipe.c
54979@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
54980
54981 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
54982 {
54983- if (pipe->files)
54984+ if (atomic_read(&pipe->files))
54985 mutex_lock_nested(&pipe->mutex, subclass);
54986 }
54987
54988@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
54989
54990 void pipe_unlock(struct pipe_inode_info *pipe)
54991 {
54992- if (pipe->files)
54993+ if (atomic_read(&pipe->files))
54994 mutex_unlock(&pipe->mutex);
54995 }
54996 EXPORT_SYMBOL(pipe_unlock);
54997@@ -449,9 +449,9 @@ redo:
54998 }
54999 if (bufs) /* More to do? */
55000 continue;
55001- if (!pipe->writers)
55002+ if (!atomic_read(&pipe->writers))
55003 break;
55004- if (!pipe->waiting_writers) {
55005+ if (!atomic_read(&pipe->waiting_writers)) {
55006 /* syscall merging: Usually we must not sleep
55007 * if O_NONBLOCK is set, or if we got some data.
55008 * But if a writer sleeps in kernel space, then
55009@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
55010 ret = 0;
55011 __pipe_lock(pipe);
55012
55013- if (!pipe->readers) {
55014+ if (!atomic_read(&pipe->readers)) {
55015 send_sig(SIGPIPE, current, 0);
55016 ret = -EPIPE;
55017 goto out;
55018@@ -562,7 +562,7 @@ redo1:
55019 for (;;) {
55020 int bufs;
55021
55022- if (!pipe->readers) {
55023+ if (!atomic_read(&pipe->readers)) {
55024 send_sig(SIGPIPE, current, 0);
55025 if (!ret)
55026 ret = -EPIPE;
55027@@ -653,9 +653,9 @@ redo2:
55028 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
55029 do_wakeup = 0;
55030 }
55031- pipe->waiting_writers++;
55032+ atomic_inc(&pipe->waiting_writers);
55033 pipe_wait(pipe);
55034- pipe->waiting_writers--;
55035+ atomic_dec(&pipe->waiting_writers);
55036 }
55037 out:
55038 __pipe_unlock(pipe);
55039@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
55040 mask = 0;
55041 if (filp->f_mode & FMODE_READ) {
55042 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
55043- if (!pipe->writers && filp->f_version != pipe->w_counter)
55044+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
55045 mask |= POLLHUP;
55046 }
55047
55048@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
55049 * Most Unices do not set POLLERR for FIFOs but on Linux they
55050 * behave exactly like pipes for poll().
55051 */
55052- if (!pipe->readers)
55053+ if (!atomic_read(&pipe->readers))
55054 mask |= POLLERR;
55055 }
55056
55057@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
55058
55059 __pipe_lock(pipe);
55060 if (file->f_mode & FMODE_READ)
55061- pipe->readers--;
55062+ atomic_dec(&pipe->readers);
55063 if (file->f_mode & FMODE_WRITE)
55064- pipe->writers--;
55065+ atomic_dec(&pipe->writers);
55066
55067- if (pipe->readers || pipe->writers) {
55068+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
55069 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
55070 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
55071 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
55072 }
55073 spin_lock(&inode->i_lock);
55074- if (!--pipe->files) {
55075+ if (atomic_dec_and_test(&pipe->files)) {
55076 inode->i_pipe = NULL;
55077 kill = 1;
55078 }
55079@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
55080 kfree(pipe);
55081 }
55082
55083-static struct vfsmount *pipe_mnt __read_mostly;
55084+struct vfsmount *pipe_mnt __read_mostly;
55085
55086 /*
55087 * pipefs_dname() is called from d_path().
55088@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
55089 goto fail_iput;
55090
55091 inode->i_pipe = pipe;
55092- pipe->files = 2;
55093- pipe->readers = pipe->writers = 1;
55094+ atomic_set(&pipe->files, 2);
55095+ atomic_set(&pipe->readers, 1);
55096+ atomic_set(&pipe->writers, 1);
55097 inode->i_fop = &pipefifo_fops;
55098
55099 /*
55100@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
55101 spin_lock(&inode->i_lock);
55102 if (inode->i_pipe) {
55103 pipe = inode->i_pipe;
55104- pipe->files++;
55105+ atomic_inc(&pipe->files);
55106 spin_unlock(&inode->i_lock);
55107 } else {
55108 spin_unlock(&inode->i_lock);
55109 pipe = alloc_pipe_info();
55110 if (!pipe)
55111 return -ENOMEM;
55112- pipe->files = 1;
55113+ atomic_set(&pipe->files, 1);
55114 spin_lock(&inode->i_lock);
55115 if (unlikely(inode->i_pipe)) {
55116- inode->i_pipe->files++;
55117+ atomic_inc(&inode->i_pipe->files);
55118 spin_unlock(&inode->i_lock);
55119 free_pipe_info(pipe);
55120 pipe = inode->i_pipe;
55121@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
55122 * opened, even when there is no process writing the FIFO.
55123 */
55124 pipe->r_counter++;
55125- if (pipe->readers++ == 0)
55126+ if (atomic_inc_return(&pipe->readers) == 1)
55127 wake_up_partner(pipe);
55128
55129- if (!is_pipe && !pipe->writers) {
55130+ if (!is_pipe && !atomic_read(&pipe->writers)) {
55131 if ((filp->f_flags & O_NONBLOCK)) {
55132 /* suppress POLLHUP until we have
55133 * seen a writer */
55134@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
55135 * errno=ENXIO when there is no process reading the FIFO.
55136 */
55137 ret = -ENXIO;
55138- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
55139+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
55140 goto err;
55141
55142 pipe->w_counter++;
55143- if (!pipe->writers++)
55144+ if (atomic_inc_return(&pipe->writers) == 1)
55145 wake_up_partner(pipe);
55146
55147- if (!is_pipe && !pipe->readers) {
55148+ if (!is_pipe && !atomic_read(&pipe->readers)) {
55149 if (wait_for_partner(pipe, &pipe->r_counter))
55150 goto err_wr;
55151 }
55152@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
55153 * the process can at least talk to itself.
55154 */
55155
55156- pipe->readers++;
55157- pipe->writers++;
55158+ atomic_inc(&pipe->readers);
55159+ atomic_inc(&pipe->writers);
55160 pipe->r_counter++;
55161 pipe->w_counter++;
55162- if (pipe->readers == 1 || pipe->writers == 1)
55163+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
55164 wake_up_partner(pipe);
55165 break;
55166
55167@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
55168 return 0;
55169
55170 err_rd:
55171- if (!--pipe->readers)
55172+ if (atomic_dec_and_test(&pipe->readers))
55173 wake_up_interruptible(&pipe->wait);
55174 ret = -ERESTARTSYS;
55175 goto err;
55176
55177 err_wr:
55178- if (!--pipe->writers)
55179+ if (atomic_dec_and_test(&pipe->writers))
55180 wake_up_interruptible(&pipe->wait);
55181 ret = -ERESTARTSYS;
55182 goto err;
55183
55184 err:
55185 spin_lock(&inode->i_lock);
55186- if (!--pipe->files) {
55187+ if (atomic_dec_and_test(&pipe->files)) {
55188 inode->i_pipe = NULL;
55189 kill = 1;
55190 }
55191diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
55192index 15af622..0e9f4467 100644
55193--- a/fs/proc/Kconfig
55194+++ b/fs/proc/Kconfig
55195@@ -30,12 +30,12 @@ config PROC_FS
55196
55197 config PROC_KCORE
55198 bool "/proc/kcore support" if !ARM
55199- depends on PROC_FS && MMU
55200+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
55201
55202 config PROC_VMCORE
55203 bool "/proc/vmcore support"
55204- depends on PROC_FS && CRASH_DUMP
55205- default y
55206+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
55207+ default n
55208 help
55209 Exports the dump image of crashed kernel in ELF format.
55210
55211@@ -59,8 +59,8 @@ config PROC_SYSCTL
55212 limited in memory.
55213
55214 config PROC_PAGE_MONITOR
55215- default y
55216- depends on PROC_FS && MMU
55217+ default n
55218+ depends on PROC_FS && MMU && !GRKERNSEC
55219 bool "Enable /proc page monitoring" if EXPERT
55220 help
55221 Various /proc files exist to monitor process memory utilization:
55222diff --git a/fs/proc/array.c b/fs/proc/array.c
55223index cbd0f1b..adec3f0 100644
55224--- a/fs/proc/array.c
55225+++ b/fs/proc/array.c
55226@@ -60,6 +60,7 @@
55227 #include <linux/tty.h>
55228 #include <linux/string.h>
55229 #include <linux/mman.h>
55230+#include <linux/grsecurity.h>
55231 #include <linux/proc_fs.h>
55232 #include <linux/ioport.h>
55233 #include <linux/uaccess.h>
55234@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
55235 seq_putc(m, '\n');
55236 }
55237
55238+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55239+static inline void task_pax(struct seq_file *m, struct task_struct *p)
55240+{
55241+ if (p->mm)
55242+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55243+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55244+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55245+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55246+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55247+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55248+ else
55249+ seq_printf(m, "PaX:\t-----\n");
55250+}
55251+#endif
55252+
55253 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55254 struct pid *pid, struct task_struct *task)
55255 {
55256@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55257 task_cpus_allowed(m, task);
55258 cpuset_task_status_allowed(m, task);
55259 task_context_switch_counts(m, task);
55260+
55261+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55262+ task_pax(m, task);
55263+#endif
55264+
55265+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55266+ task_grsec_rbac(m, task);
55267+#endif
55268+
55269 return 0;
55270 }
55271
55272+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55273+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55274+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55275+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55276+#endif
55277+
55278 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55279 struct pid *pid, struct task_struct *task, int whole)
55280 {
55281@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55282 char tcomm[sizeof(task->comm)];
55283 unsigned long flags;
55284
55285+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55286+ if (current->exec_id != m->exec_id) {
55287+ gr_log_badprocpid("stat");
55288+ return 0;
55289+ }
55290+#endif
55291+
55292 state = *get_task_state(task);
55293 vsize = eip = esp = 0;
55294 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55295@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55296 gtime = task_gtime(task);
55297 }
55298
55299+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55300+ if (PAX_RAND_FLAGS(mm)) {
55301+ eip = 0;
55302+ esp = 0;
55303+ wchan = 0;
55304+ }
55305+#endif
55306+#ifdef CONFIG_GRKERNSEC_HIDESYM
55307+ wchan = 0;
55308+ eip =0;
55309+ esp =0;
55310+#endif
55311+
55312 /* scale priority and nice values from timeslices to -20..20 */
55313 /* to make it look like a "normal" Unix priority/nice value */
55314 priority = task_prio(task);
55315@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55316 seq_put_decimal_ull(m, ' ', vsize);
55317 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55318 seq_put_decimal_ull(m, ' ', rsslim);
55319+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55320+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55321+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55322+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55323+#else
55324 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55325 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55326 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55327+#endif
55328 seq_put_decimal_ull(m, ' ', esp);
55329 seq_put_decimal_ull(m, ' ', eip);
55330 /* The signal information here is obsolete.
55331@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55332 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55333 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55334
55335- if (mm && permitted) {
55336+ if (mm && permitted
55337+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55338+ && !PAX_RAND_FLAGS(mm)
55339+#endif
55340+ ) {
55341 seq_put_decimal_ull(m, ' ', mm->start_data);
55342 seq_put_decimal_ull(m, ' ', mm->end_data);
55343 seq_put_decimal_ull(m, ' ', mm->start_brk);
55344@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55345 struct pid *pid, struct task_struct *task)
55346 {
55347 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55348- struct mm_struct *mm = get_task_mm(task);
55349+ struct mm_struct *mm;
55350
55351+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55352+ if (current->exec_id != m->exec_id) {
55353+ gr_log_badprocpid("statm");
55354+ return 0;
55355+ }
55356+#endif
55357+ mm = get_task_mm(task);
55358 if (mm) {
55359 size = task_statm(mm, &shared, &text, &data, &resident);
55360 mmput(mm);
55361@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55362 return 0;
55363 }
55364
55365+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55366+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55367+{
55368+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55369+}
55370+#endif
55371+
55372 #ifdef CONFIG_CHECKPOINT_RESTORE
55373 static struct pid *
55374 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55375diff --git a/fs/proc/base.c b/fs/proc/base.c
55376index c3834da..b402b2b 100644
55377--- a/fs/proc/base.c
55378+++ b/fs/proc/base.c
55379@@ -113,6 +113,14 @@ struct pid_entry {
55380 union proc_op op;
55381 };
55382
55383+struct getdents_callback {
55384+ struct linux_dirent __user * current_dir;
55385+ struct linux_dirent __user * previous;
55386+ struct file * file;
55387+ int count;
55388+ int error;
55389+};
55390+
55391 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55392 .name = (NAME), \
55393 .len = sizeof(NAME) - 1, \
55394@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55395 if (!mm->arg_end)
55396 goto out_mm; /* Shh! No looking before we're done */
55397
55398+ if (gr_acl_handle_procpidmem(task))
55399+ goto out_mm;
55400+
55401 len = mm->arg_end - mm->arg_start;
55402
55403 if (len > PAGE_SIZE)
55404@@ -237,12 +248,28 @@ out:
55405 return res;
55406 }
55407
55408+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55409+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55410+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55411+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55412+#endif
55413+
55414 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55415 {
55416 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55417 int res = PTR_ERR(mm);
55418 if (mm && !IS_ERR(mm)) {
55419 unsigned int nwords = 0;
55420+
55421+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55422+ /* allow if we're currently ptracing this task */
55423+ if (PAX_RAND_FLAGS(mm) &&
55424+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55425+ mmput(mm);
55426+ return 0;
55427+ }
55428+#endif
55429+
55430 do {
55431 nwords += 2;
55432 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55433@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55434 }
55435
55436
55437-#ifdef CONFIG_KALLSYMS
55438+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55439 /*
55440 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55441 * Returns the resolved symbol. If that fails, simply return the address.
55442@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
55443 mutex_unlock(&task->signal->cred_guard_mutex);
55444 }
55445
55446-#ifdef CONFIG_STACKTRACE
55447+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55448
55449 #define MAX_STACK_TRACE_DEPTH 64
55450
55451@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55452 return count;
55453 }
55454
55455-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55456+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55457 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55458 {
55459 long nr;
55460@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55461 /************************************************************************/
55462
55463 /* permission checks */
55464-static int proc_fd_access_allowed(struct inode *inode)
55465+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55466 {
55467 struct task_struct *task;
55468 int allowed = 0;
55469@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55470 */
55471 task = get_proc_task(inode);
55472 if (task) {
55473- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55474+ if (log)
55475+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55476+ else
55477+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55478 put_task_struct(task);
55479 }
55480 return allowed;
55481@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55482 struct task_struct *task,
55483 int hide_pid_min)
55484 {
55485+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55486+ return false;
55487+
55488+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55489+ rcu_read_lock();
55490+ {
55491+ const struct cred *tmpcred = current_cred();
55492+ const struct cred *cred = __task_cred(task);
55493+
55494+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55495+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55496+ || in_group_p(grsec_proc_gid)
55497+#endif
55498+ ) {
55499+ rcu_read_unlock();
55500+ return true;
55501+ }
55502+ }
55503+ rcu_read_unlock();
55504+
55505+ if (!pid->hide_pid)
55506+ return false;
55507+#endif
55508+
55509 if (pid->hide_pid < hide_pid_min)
55510 return true;
55511 if (in_group_p(pid->pid_gid))
55512 return true;
55513+
55514 return ptrace_may_access(task, PTRACE_MODE_READ);
55515 }
55516
55517@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55518 put_task_struct(task);
55519
55520 if (!has_perms) {
55521+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55522+ {
55523+#else
55524 if (pid->hide_pid == 2) {
55525+#endif
55526 /*
55527 * Let's make getdents(), stat(), and open()
55528 * consistent with each other. If a process
55529@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55530 if (!task)
55531 return -ESRCH;
55532
55533+ if (gr_acl_handle_procpidmem(task)) {
55534+ put_task_struct(task);
55535+ return -EPERM;
55536+ }
55537+
55538 mm = mm_access(task, mode);
55539 put_task_struct(task);
55540
55541@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55542
55543 file->private_data = mm;
55544
55545+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55546+ file->f_version = current->exec_id;
55547+#endif
55548+
55549 return 0;
55550 }
55551
55552@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55553 ssize_t copied;
55554 char *page;
55555
55556+#ifdef CONFIG_GRKERNSEC
55557+ if (write)
55558+ return -EPERM;
55559+#endif
55560+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55561+ if (file->f_version != current->exec_id) {
55562+ gr_log_badprocpid("mem");
55563+ return 0;
55564+ }
55565+#endif
55566+
55567 if (!mm)
55568 return 0;
55569
55570@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55571 goto free;
55572
55573 while (count > 0) {
55574- int this_len = min_t(int, count, PAGE_SIZE);
55575+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55576
55577 if (write && copy_from_user(page, buf, this_len)) {
55578 copied = -EFAULT;
55579@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55580 if (!mm)
55581 return 0;
55582
55583+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55584+ if (file->f_version != current->exec_id) {
55585+ gr_log_badprocpid("environ");
55586+ return 0;
55587+ }
55588+#endif
55589+
55590 page = (char *)__get_free_page(GFP_TEMPORARY);
55591 if (!page)
55592 return -ENOMEM;
55593@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55594 goto free;
55595 while (count > 0) {
55596 size_t this_len, max_len;
55597- int retval;
55598+ ssize_t retval;
55599
55600 if (src >= (mm->env_end - mm->env_start))
55601 break;
55602@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55603 int error = -EACCES;
55604
55605 /* Are we allowed to snoop on the tasks file descriptors? */
55606- if (!proc_fd_access_allowed(inode))
55607+ if (!proc_fd_access_allowed(inode, 0))
55608 goto out;
55609
55610 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55611@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55612 struct path path;
55613
55614 /* Are we allowed to snoop on the tasks file descriptors? */
55615- if (!proc_fd_access_allowed(inode))
55616- goto out;
55617+ /* logging this is needed for learning on chromium to work properly,
55618+ but we don't want to flood the logs from 'ps' which does a readlink
55619+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55620+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55621+ */
55622+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55623+ if (!proc_fd_access_allowed(inode,0))
55624+ goto out;
55625+ } else {
55626+ if (!proc_fd_access_allowed(inode,1))
55627+ goto out;
55628+ }
55629
55630 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55631 if (error)
55632@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55633 rcu_read_lock();
55634 cred = __task_cred(task);
55635 inode->i_uid = cred->euid;
55636+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55637+ inode->i_gid = grsec_proc_gid;
55638+#else
55639 inode->i_gid = cred->egid;
55640+#endif
55641 rcu_read_unlock();
55642 }
55643 security_task_to_inode(task, inode);
55644@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55645 return -ENOENT;
55646 }
55647 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55648+#ifdef CONFIG_GRKERNSEC_PROC_USER
55649+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55650+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55651+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55652+#endif
55653 task_dumpable(task)) {
55654 cred = __task_cred(task);
55655 stat->uid = cred->euid;
55656+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55657+ stat->gid = grsec_proc_gid;
55658+#else
55659 stat->gid = cred->egid;
55660+#endif
55661 }
55662 }
55663 rcu_read_unlock();
55664@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55665
55666 if (task) {
55667 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55668+#ifdef CONFIG_GRKERNSEC_PROC_USER
55669+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55670+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55671+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55672+#endif
55673 task_dumpable(task)) {
55674 rcu_read_lock();
55675 cred = __task_cred(task);
55676 inode->i_uid = cred->euid;
55677+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55678+ inode->i_gid = grsec_proc_gid;
55679+#else
55680 inode->i_gid = cred->egid;
55681+#endif
55682 rcu_read_unlock();
55683 } else {
55684 inode->i_uid = GLOBAL_ROOT_UID;
55685@@ -2196,6 +2314,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55686 if (!task)
55687 goto out_no_task;
55688
55689+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55690+ goto out;
55691+
55692 /*
55693 * Yes, it does not scale. And it should not. Don't add
55694 * new entries into /proc/<tgid>/ without very good reasons.
55695@@ -2240,6 +2361,9 @@ static int proc_pident_readdir(struct file *filp,
55696 if (!task)
55697 goto out_no_task;
55698
55699+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55700+ goto out;
55701+
55702 ret = 0;
55703 i = filp->f_pos;
55704 switch (i) {
55705@@ -2653,7 +2777,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55706 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55707 #endif
55708 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55709-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55710+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55711 INF("syscall", S_IRUGO, proc_pid_syscall),
55712 #endif
55713 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55714@@ -2678,10 +2802,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55715 #ifdef CONFIG_SECURITY
55716 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55717 #endif
55718-#ifdef CONFIG_KALLSYMS
55719+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55720 INF("wchan", S_IRUGO, proc_pid_wchan),
55721 #endif
55722-#ifdef CONFIG_STACKTRACE
55723+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55724 ONE("stack", S_IRUGO, proc_pid_stack),
55725 #endif
55726 #ifdef CONFIG_SCHEDSTATS
55727@@ -2715,6 +2839,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55728 #ifdef CONFIG_HARDWALL
55729 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55730 #endif
55731+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55732+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55733+#endif
55734 #ifdef CONFIG_USER_NS
55735 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55736 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55737@@ -2847,7 +2974,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55738 if (!inode)
55739 goto out;
55740
55741+#ifdef CONFIG_GRKERNSEC_PROC_USER
55742+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55743+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55744+ inode->i_gid = grsec_proc_gid;
55745+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55746+#else
55747 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55748+#endif
55749 inode->i_op = &proc_tgid_base_inode_operations;
55750 inode->i_fop = &proc_tgid_base_operations;
55751 inode->i_flags|=S_IMMUTABLE;
55752@@ -2885,7 +3019,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55753 if (!task)
55754 goto out;
55755
55756+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55757+ goto out_put_task;
55758+
55759 result = proc_pid_instantiate(dir, dentry, task, NULL);
55760+out_put_task:
55761 put_task_struct(task);
55762 out:
55763 return result;
55764@@ -2948,6 +3086,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55765 static int fake_filldir(void *buf, const char *name, int namelen,
55766 loff_t offset, u64 ino, unsigned d_type)
55767 {
55768+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55769+ __buf->error = -EINVAL;
55770 return 0;
55771 }
55772
55773@@ -3007,7 +3147,7 @@ static const struct pid_entry tid_base_stuff[] = {
55774 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55775 #endif
55776 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55777-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55778+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55779 INF("syscall", S_IRUGO, proc_pid_syscall),
55780 #endif
55781 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55782@@ -3034,10 +3174,10 @@ static const struct pid_entry tid_base_stuff[] = {
55783 #ifdef CONFIG_SECURITY
55784 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55785 #endif
55786-#ifdef CONFIG_KALLSYMS
55787+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55788 INF("wchan", S_IRUGO, proc_pid_wchan),
55789 #endif
55790-#ifdef CONFIG_STACKTRACE
55791+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55792 ONE("stack", S_IRUGO, proc_pid_stack),
55793 #endif
55794 #ifdef CONFIG_SCHEDSTATS
55795diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55796index 82676e3..5f8518a 100644
55797--- a/fs/proc/cmdline.c
55798+++ b/fs/proc/cmdline.c
55799@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55800
55801 static int __init proc_cmdline_init(void)
55802 {
55803+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55804+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55805+#else
55806 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55807+#endif
55808 return 0;
55809 }
55810 module_init(proc_cmdline_init);
55811diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55812index b143471..bb105e5 100644
55813--- a/fs/proc/devices.c
55814+++ b/fs/proc/devices.c
55815@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55816
55817 static int __init proc_devices_init(void)
55818 {
55819+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55820+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55821+#else
55822 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55823+#endif
55824 return 0;
55825 }
55826 module_init(proc_devices_init);
55827diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55828index d7a4a28..0201742 100644
55829--- a/fs/proc/fd.c
55830+++ b/fs/proc/fd.c
55831@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55832 if (!task)
55833 return -ENOENT;
55834
55835- files = get_files_struct(task);
55836+ if (!gr_acl_handle_procpidmem(task))
55837+ files = get_files_struct(task);
55838 put_task_struct(task);
55839
55840 if (files) {
55841@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55842 */
55843 int proc_fd_permission(struct inode *inode, int mask)
55844 {
55845+ struct task_struct *task;
55846 int rv = generic_permission(inode, mask);
55847- if (rv == 0)
55848- return 0;
55849+
55850 if (task_pid(current) == proc_pid(inode))
55851 rv = 0;
55852+
55853+ task = get_proc_task(inode);
55854+ if (task == NULL)
55855+ return rv;
55856+
55857+ if (gr_acl_handle_procpidmem(task))
55858+ rv = -EACCES;
55859+
55860+ put_task_struct(task);
55861+
55862 return rv;
55863 }
55864
55865diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55866index 073aea6..0630370 100644
55867--- a/fs/proc/inode.c
55868+++ b/fs/proc/inode.c
55869@@ -23,11 +23,17 @@
55870 #include <linux/slab.h>
55871 #include <linux/mount.h>
55872 #include <linux/magic.h>
55873+#include <linux/grsecurity.h>
55874
55875 #include <asm/uaccess.h>
55876
55877 #include "internal.h"
55878
55879+#ifdef CONFIG_PROC_SYSCTL
55880+extern const struct inode_operations proc_sys_inode_operations;
55881+extern const struct inode_operations proc_sys_dir_operations;
55882+#endif
55883+
55884 static void proc_evict_inode(struct inode *inode)
55885 {
55886 struct proc_dir_entry *de;
55887@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
55888 ns = PROC_I(inode)->ns.ns;
55889 if (ns_ops && ns)
55890 ns_ops->put(ns);
55891+
55892+#ifdef CONFIG_PROC_SYSCTL
55893+ if (inode->i_op == &proc_sys_inode_operations ||
55894+ inode->i_op == &proc_sys_dir_operations)
55895+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55896+#endif
55897+
55898 }
55899
55900 static struct kmem_cache * proc_inode_cachep;
55901@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55902 if (de->mode) {
55903 inode->i_mode = de->mode;
55904 inode->i_uid = de->uid;
55905+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55906+ inode->i_gid = grsec_proc_gid;
55907+#else
55908 inode->i_gid = de->gid;
55909+#endif
55910 }
55911 if (de->size)
55912 inode->i_size = de->size;
55913diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55914index d600fb0..3b495fe 100644
55915--- a/fs/proc/internal.h
55916+++ b/fs/proc/internal.h
55917@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
55918 struct pid *, struct task_struct *);
55919 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
55920 struct pid *, struct task_struct *);
55921+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55922+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55923+#endif
55924
55925 /*
55926 * base.c
55927diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55928index 0a22194..a9fc8c1 100644
55929--- a/fs/proc/kcore.c
55930+++ b/fs/proc/kcore.c
55931@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55932 * the addresses in the elf_phdr on our list.
55933 */
55934 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55935- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55936+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55937+ if (tsz > buflen)
55938 tsz = buflen;
55939-
55940+
55941 while (buflen) {
55942 struct kcore_list *m;
55943
55944@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55945 kfree(elf_buf);
55946 } else {
55947 if (kern_addr_valid(start)) {
55948- unsigned long n;
55949+ char *elf_buf;
55950+ mm_segment_t oldfs;
55951
55952- n = copy_to_user(buffer, (char *)start, tsz);
55953- /*
55954- * We cannot distinguish between fault on source
55955- * and fault on destination. When this happens
55956- * we clear too and hope it will trigger the
55957- * EFAULT again.
55958- */
55959- if (n) {
55960- if (clear_user(buffer + tsz - n,
55961- n))
55962+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55963+ if (!elf_buf)
55964+ return -ENOMEM;
55965+ oldfs = get_fs();
55966+ set_fs(KERNEL_DS);
55967+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55968+ set_fs(oldfs);
55969+ if (copy_to_user(buffer, elf_buf, tsz)) {
55970+ kfree(elf_buf);
55971 return -EFAULT;
55972+ }
55973 }
55974+ set_fs(oldfs);
55975+ kfree(elf_buf);
55976 } else {
55977 if (clear_user(buffer, tsz))
55978 return -EFAULT;
55979@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55980
55981 static int open_kcore(struct inode *inode, struct file *filp)
55982 {
55983+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55984+ return -EPERM;
55985+#endif
55986 if (!capable(CAP_SYS_RAWIO))
55987 return -EPERM;
55988 if (kcore_need_update)
55989diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55990index 5aa847a..f77c8d4 100644
55991--- a/fs/proc/meminfo.c
55992+++ b/fs/proc/meminfo.c
55993@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55994 vmi.used >> 10,
55995 vmi.largest_chunk >> 10
55996 #ifdef CONFIG_MEMORY_FAILURE
55997- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55998+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55999 #endif
56000 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
56001 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
56002diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
56003index ccfd99b..1b7e255 100644
56004--- a/fs/proc/nommu.c
56005+++ b/fs/proc/nommu.c
56006@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
56007 if (len < 1)
56008 len = 1;
56009 seq_printf(m, "%*c", len, ' ');
56010- seq_path(m, &file->f_path, "");
56011+ seq_path(m, &file->f_path, "\n\\");
56012 }
56013
56014 seq_putc(m, '\n');
56015diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
56016index 986e832..6e8e859 100644
56017--- a/fs/proc/proc_net.c
56018+++ b/fs/proc/proc_net.c
56019@@ -23,6 +23,7 @@
56020 #include <linux/nsproxy.h>
56021 #include <net/net_namespace.h>
56022 #include <linux/seq_file.h>
56023+#include <linux/grsecurity.h>
56024
56025 #include "internal.h"
56026
56027@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
56028 struct task_struct *task;
56029 struct nsproxy *ns;
56030 struct net *net = NULL;
56031+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56032+ const struct cred *cred = current_cred();
56033+#endif
56034+
56035+#ifdef CONFIG_GRKERNSEC_PROC_USER
56036+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
56037+ return net;
56038+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56039+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
56040+ return net;
56041+#endif
56042
56043 rcu_read_lock();
56044 task = pid_task(proc_pid(dir), PIDTYPE_PID);
56045diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
56046index ac05f33..1e6dc7e 100644
56047--- a/fs/proc/proc_sysctl.c
56048+++ b/fs/proc/proc_sysctl.c
56049@@ -13,11 +13,15 @@
56050 #include <linux/module.h>
56051 #include "internal.h"
56052
56053+extern int gr_handle_chroot_sysctl(const int op);
56054+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
56055+ const int op);
56056+
56057 static const struct dentry_operations proc_sys_dentry_operations;
56058 static const struct file_operations proc_sys_file_operations;
56059-static const struct inode_operations proc_sys_inode_operations;
56060+const struct inode_operations proc_sys_inode_operations;
56061 static const struct file_operations proc_sys_dir_file_operations;
56062-static const struct inode_operations proc_sys_dir_operations;
56063+const struct inode_operations proc_sys_dir_operations;
56064
56065 void proc_sys_poll_notify(struct ctl_table_poll *poll)
56066 {
56067@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
56068
56069 err = NULL;
56070 d_set_d_op(dentry, &proc_sys_dentry_operations);
56071+
56072+ gr_handle_proc_create(dentry, inode);
56073+
56074 d_add(dentry, inode);
56075
56076 out:
56077@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
56078 struct inode *inode = file_inode(filp);
56079 struct ctl_table_header *head = grab_header(inode);
56080 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
56081+ int op = write ? MAY_WRITE : MAY_READ;
56082 ssize_t error;
56083 size_t res;
56084
56085@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
56086 * and won't be until we finish.
56087 */
56088 error = -EPERM;
56089- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
56090+ if (sysctl_perm(head, table, op))
56091 goto out;
56092
56093 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
56094@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
56095 if (!table->proc_handler)
56096 goto out;
56097
56098+#ifdef CONFIG_GRKERNSEC
56099+ error = -EPERM;
56100+ if (gr_handle_chroot_sysctl(op))
56101+ goto out;
56102+ dget(filp->f_path.dentry);
56103+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
56104+ dput(filp->f_path.dentry);
56105+ goto out;
56106+ }
56107+ dput(filp->f_path.dentry);
56108+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
56109+ goto out;
56110+ if (write && !capable(CAP_SYS_ADMIN))
56111+ goto out;
56112+#endif
56113+
56114 /* careful: calling conventions are nasty here */
56115 res = count;
56116 error = table->proc_handler(table, write, buf, &res, ppos);
56117@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
56118 return -ENOMEM;
56119 } else {
56120 d_set_d_op(child, &proc_sys_dentry_operations);
56121+
56122+ gr_handle_proc_create(child, inode);
56123+
56124 d_add(child, inode);
56125 }
56126 } else {
56127@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
56128 if ((*pos)++ < file->f_pos)
56129 return 0;
56130
56131+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
56132+ return 0;
56133+
56134 if (unlikely(S_ISLNK(table->mode)))
56135 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
56136 else
56137@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
56138 if (IS_ERR(head))
56139 return PTR_ERR(head);
56140
56141+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
56142+ return -ENOENT;
56143+
56144 generic_fillattr(inode, stat);
56145 if (table)
56146 stat->mode = (stat->mode & S_IFMT) | table->mode;
56147@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
56148 .llseek = generic_file_llseek,
56149 };
56150
56151-static const struct inode_operations proc_sys_inode_operations = {
56152+const struct inode_operations proc_sys_inode_operations = {
56153 .permission = proc_sys_permission,
56154 .setattr = proc_sys_setattr,
56155 .getattr = proc_sys_getattr,
56156 };
56157
56158-static const struct inode_operations proc_sys_dir_operations = {
56159+const struct inode_operations proc_sys_dir_operations = {
56160 .lookup = proc_sys_lookup,
56161 .permission = proc_sys_permission,
56162 .setattr = proc_sys_setattr,
56163@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
56164 static struct ctl_dir *new_dir(struct ctl_table_set *set,
56165 const char *name, int namelen)
56166 {
56167- struct ctl_table *table;
56168+ ctl_table_no_const *table;
56169 struct ctl_dir *new;
56170 struct ctl_node *node;
56171 char *new_name;
56172@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
56173 return NULL;
56174
56175 node = (struct ctl_node *)(new + 1);
56176- table = (struct ctl_table *)(node + 1);
56177+ table = (ctl_table_no_const *)(node + 1);
56178 new_name = (char *)(table + 2);
56179 memcpy(new_name, name, namelen);
56180 new_name[namelen] = '\0';
56181@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
56182 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
56183 struct ctl_table_root *link_root)
56184 {
56185- struct ctl_table *link_table, *entry, *link;
56186+ ctl_table_no_const *link_table, *link;
56187+ struct ctl_table *entry;
56188 struct ctl_table_header *links;
56189 struct ctl_node *node;
56190 char *link_name;
56191@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
56192 return NULL;
56193
56194 node = (struct ctl_node *)(links + 1);
56195- link_table = (struct ctl_table *)(node + nr_entries);
56196+ link_table = (ctl_table_no_const *)(node + nr_entries);
56197 link_name = (char *)&link_table[nr_entries + 1];
56198
56199 for (link = link_table, entry = table; entry->procname; link++, entry++) {
56200@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56201 struct ctl_table_header ***subheader, struct ctl_table_set *set,
56202 struct ctl_table *table)
56203 {
56204- struct ctl_table *ctl_table_arg = NULL;
56205- struct ctl_table *entry, *files;
56206+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
56207+ struct ctl_table *entry;
56208 int nr_files = 0;
56209 int nr_dirs = 0;
56210 int err = -ENOMEM;
56211@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56212 nr_files++;
56213 }
56214
56215- files = table;
56216 /* If there are mixed files and directories we need a new table */
56217 if (nr_dirs && nr_files) {
56218- struct ctl_table *new;
56219+ ctl_table_no_const *new;
56220 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
56221 GFP_KERNEL);
56222 if (!files)
56223@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56224 /* Register everything except a directory full of subdirectories */
56225 if (nr_files || !nr_dirs) {
56226 struct ctl_table_header *header;
56227- header = __register_sysctl_table(set, path, files);
56228+ header = __register_sysctl_table(set, path, files ? files : table);
56229 if (!header) {
56230 kfree(ctl_table_arg);
56231 goto out;
56232diff --git a/fs/proc/root.c b/fs/proc/root.c
56233index 41a6ea9..23eaa92 100644
56234--- a/fs/proc/root.c
56235+++ b/fs/proc/root.c
56236@@ -182,7 +182,15 @@ void __init proc_root_init(void)
56237 #ifdef CONFIG_PROC_DEVICETREE
56238 proc_device_tree_init();
56239 #endif
56240+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56241+#ifdef CONFIG_GRKERNSEC_PROC_USER
56242+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56243+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56244+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56245+#endif
56246+#else
56247 proc_mkdir("bus", NULL);
56248+#endif
56249 proc_sys_init();
56250 }
56251
56252diff --git a/fs/proc/self.c b/fs/proc/self.c
56253index 6b6a993..807cccc 100644
56254--- a/fs/proc/self.c
56255+++ b/fs/proc/self.c
56256@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56257 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56258 void *cookie)
56259 {
56260- char *s = nd_get_link(nd);
56261+ const char *s = nd_get_link(nd);
56262 if (!IS_ERR(s))
56263 kfree(s);
56264 }
56265diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56266index 3e636d8..83e3b71 100644
56267--- a/fs/proc/task_mmu.c
56268+++ b/fs/proc/task_mmu.c
56269@@ -11,12 +11,19 @@
56270 #include <linux/rmap.h>
56271 #include <linux/swap.h>
56272 #include <linux/swapops.h>
56273+#include <linux/grsecurity.h>
56274
56275 #include <asm/elf.h>
56276 #include <asm/uaccess.h>
56277 #include <asm/tlbflush.h>
56278 #include "internal.h"
56279
56280+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56281+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56282+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56283+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56284+#endif
56285+
56286 void task_mem(struct seq_file *m, struct mm_struct *mm)
56287 {
56288 unsigned long data, text, lib, swap;
56289@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56290 "VmExe:\t%8lu kB\n"
56291 "VmLib:\t%8lu kB\n"
56292 "VmPTE:\t%8lu kB\n"
56293- "VmSwap:\t%8lu kB\n",
56294- hiwater_vm << (PAGE_SHIFT-10),
56295+ "VmSwap:\t%8lu kB\n"
56296+
56297+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56298+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56299+#endif
56300+
56301+ ,hiwater_vm << (PAGE_SHIFT-10),
56302 total_vm << (PAGE_SHIFT-10),
56303 mm->locked_vm << (PAGE_SHIFT-10),
56304 mm->pinned_vm << (PAGE_SHIFT-10),
56305@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56306 data << (PAGE_SHIFT-10),
56307 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56308 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56309- swap << (PAGE_SHIFT-10));
56310+ swap << (PAGE_SHIFT-10)
56311+
56312+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56313+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56314+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56315+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56316+#else
56317+ , mm->context.user_cs_base
56318+ , mm->context.user_cs_limit
56319+#endif
56320+#endif
56321+
56322+ );
56323 }
56324
56325 unsigned long task_vsize(struct mm_struct *mm)
56326@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56327 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56328 }
56329
56330- /* We don't show the stack guard page in /proc/maps */
56331+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56332+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56333+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56334+#else
56335 start = vma->vm_start;
56336- if (stack_guard_page_start(vma, start))
56337- start += PAGE_SIZE;
56338 end = vma->vm_end;
56339- if (stack_guard_page_end(vma, end))
56340- end -= PAGE_SIZE;
56341+#endif
56342
56343 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56344 start,
56345@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56346 flags & VM_WRITE ? 'w' : '-',
56347 flags & VM_EXEC ? 'x' : '-',
56348 flags & VM_MAYSHARE ? 's' : 'p',
56349+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56350+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56351+#else
56352 pgoff,
56353+#endif
56354 MAJOR(dev), MINOR(dev), ino, &len);
56355
56356 /*
56357@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56358 */
56359 if (file) {
56360 pad_len_spaces(m, len);
56361- seq_path(m, &file->f_path, "\n");
56362+ seq_path(m, &file->f_path, "\n\\");
56363 goto done;
56364 }
56365
56366@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56367 * Thread stack in /proc/PID/task/TID/maps or
56368 * the main process stack.
56369 */
56370- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56371- vma->vm_end >= mm->start_stack)) {
56372+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56373+ (vma->vm_start <= mm->start_stack &&
56374+ vma->vm_end >= mm->start_stack)) {
56375 name = "[stack]";
56376 } else {
56377 /* Thread stack in /proc/PID/maps */
56378@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56379 struct proc_maps_private *priv = m->private;
56380 struct task_struct *task = priv->task;
56381
56382+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56383+ if (current->exec_id != m->exec_id) {
56384+ gr_log_badprocpid("maps");
56385+ return 0;
56386+ }
56387+#endif
56388+
56389 show_map_vma(m, vma, is_pid);
56390
56391 if (m->count < m->size) /* vma is copied successfully */
56392@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56393 .private = &mss,
56394 };
56395
56396+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56397+ if (current->exec_id != m->exec_id) {
56398+ gr_log_badprocpid("smaps");
56399+ return 0;
56400+ }
56401+#endif
56402 memset(&mss, 0, sizeof mss);
56403- mss.vma = vma;
56404- /* mmap_sem is held in m_start */
56405- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56406- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56407-
56408+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56409+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56410+#endif
56411+ mss.vma = vma;
56412+ /* mmap_sem is held in m_start */
56413+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56414+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56415+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56416+ }
56417+#endif
56418 show_map_vma(m, vma, is_pid);
56419
56420 seq_printf(m,
56421@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56422 "KernelPageSize: %8lu kB\n"
56423 "MMUPageSize: %8lu kB\n"
56424 "Locked: %8lu kB\n",
56425+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56426+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56427+#else
56428 (vma->vm_end - vma->vm_start) >> 10,
56429+#endif
56430 mss.resident >> 10,
56431 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56432 mss.shared_clean >> 10,
56433@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56434 int n;
56435 char buffer[50];
56436
56437+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56438+ if (current->exec_id != m->exec_id) {
56439+ gr_log_badprocpid("numa_maps");
56440+ return 0;
56441+ }
56442+#endif
56443+
56444 if (!mm)
56445 return 0;
56446
56447@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56448 mpol_to_str(buffer, sizeof(buffer), pol);
56449 mpol_cond_put(pol);
56450
56451+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56452+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56453+#else
56454 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56455+#endif
56456
56457 if (file) {
56458 seq_printf(m, " file=");
56459- seq_path(m, &file->f_path, "\n\t= ");
56460+ seq_path(m, &file->f_path, "\n\t\\= ");
56461 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56462 seq_printf(m, " heap");
56463 } else {
56464diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56465index 56123a6..5a2f6ec 100644
56466--- a/fs/proc/task_nommu.c
56467+++ b/fs/proc/task_nommu.c
56468@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56469 else
56470 bytes += kobjsize(mm);
56471
56472- if (current->fs && current->fs->users > 1)
56473+ if (current->fs && atomic_read(&current->fs->users) > 1)
56474 sbytes += kobjsize(current->fs);
56475 else
56476 bytes += kobjsize(current->fs);
56477@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56478
56479 if (file) {
56480 pad_len_spaces(m, len);
56481- seq_path(m, &file->f_path, "");
56482+ seq_path(m, &file->f_path, "\n\\");
56483 } else if (mm) {
56484 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56485
56486diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
56487index 17f7e08..e4b1529 100644
56488--- a/fs/proc/vmcore.c
56489+++ b/fs/proc/vmcore.c
56490@@ -99,9 +99,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
56491 nr_bytes = count;
56492
56493 /* If pfn is not ram, return zeros for sparse dump files */
56494- if (pfn_is_ram(pfn) == 0)
56495- memset(buf, 0, nr_bytes);
56496- else {
56497+ if (pfn_is_ram(pfn) == 0) {
56498+ if (userbuf) {
56499+ if (clear_user((char __force_user *)buf, nr_bytes))
56500+ return -EFAULT;
56501+ } else
56502+ memset(buf, 0, nr_bytes);
56503+ } else {
56504 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
56505 offset, userbuf);
56506 if (tmp < 0)
56507@@ -186,7 +190,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
56508 if (tsz > nr_bytes)
56509 tsz = nr_bytes;
56510
56511- tmp = read_from_oldmem(buffer, tsz, &start, 1);
56512+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
56513 if (tmp < 0)
56514 return tmp;
56515 buflen -= tsz;
56516diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56517index b00fcc9..e0c6381 100644
56518--- a/fs/qnx6/qnx6.h
56519+++ b/fs/qnx6/qnx6.h
56520@@ -74,7 +74,7 @@ enum {
56521 BYTESEX_BE,
56522 };
56523
56524-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56525+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56526 {
56527 if (sbi->s_bytesex == BYTESEX_LE)
56528 return le64_to_cpu((__force __le64)n);
56529@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56530 return (__force __fs64)cpu_to_be64(n);
56531 }
56532
56533-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56534+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56535 {
56536 if (sbi->s_bytesex == BYTESEX_LE)
56537 return le32_to_cpu((__force __le32)n);
56538diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56539index 16e8abb..2dcf914 100644
56540--- a/fs/quota/netlink.c
56541+++ b/fs/quota/netlink.c
56542@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56543 void quota_send_warning(struct kqid qid, dev_t dev,
56544 const char warntype)
56545 {
56546- static atomic_t seq;
56547+ static atomic_unchecked_t seq;
56548 struct sk_buff *skb;
56549 void *msg_head;
56550 int ret;
56551@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56552 "VFS: Not enough memory to send quota warning.\n");
56553 return;
56554 }
56555- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56556+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56557 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56558 if (!msg_head) {
56559 printk(KERN_ERR
56560diff --git a/fs/read_write.c b/fs/read_write.c
56561index 2cefa41..c7e2fe0 100644
56562--- a/fs/read_write.c
56563+++ b/fs/read_write.c
56564@@ -411,7 +411,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
56565
56566 old_fs = get_fs();
56567 set_fs(get_ds());
56568- p = (__force const char __user *)buf;
56569+ p = (const char __force_user *)buf;
56570 if (count > MAX_RW_COUNT)
56571 count = MAX_RW_COUNT;
56572 if (file->f_op->write)
56573diff --git a/fs/readdir.c b/fs/readdir.c
56574index fee38e0..12fdf47 100644
56575--- a/fs/readdir.c
56576+++ b/fs/readdir.c
56577@@ -17,6 +17,7 @@
56578 #include <linux/security.h>
56579 #include <linux/syscalls.h>
56580 #include <linux/unistd.h>
56581+#include <linux/namei.h>
56582
56583 #include <asm/uaccess.h>
56584
56585@@ -67,6 +68,7 @@ struct old_linux_dirent {
56586
56587 struct readdir_callback {
56588 struct old_linux_dirent __user * dirent;
56589+ struct file * file;
56590 int result;
56591 };
56592
56593@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56594 buf->result = -EOVERFLOW;
56595 return -EOVERFLOW;
56596 }
56597+
56598+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56599+ return 0;
56600+
56601 buf->result++;
56602 dirent = buf->dirent;
56603 if (!access_ok(VERIFY_WRITE, dirent,
56604@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56605
56606 buf.result = 0;
56607 buf.dirent = dirent;
56608+ buf.file = f.file;
56609
56610 error = vfs_readdir(f.file, fillonedir, &buf);
56611 if (buf.result)
56612@@ -139,6 +146,7 @@ struct linux_dirent {
56613 struct getdents_callback {
56614 struct linux_dirent __user * current_dir;
56615 struct linux_dirent __user * previous;
56616+ struct file * file;
56617 int count;
56618 int error;
56619 };
56620@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56621 buf->error = -EOVERFLOW;
56622 return -EOVERFLOW;
56623 }
56624+
56625+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56626+ return 0;
56627+
56628 dirent = buf->previous;
56629 if (dirent) {
56630 if (__put_user(offset, &dirent->d_off))
56631@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56632 buf.previous = NULL;
56633 buf.count = count;
56634 buf.error = 0;
56635+ buf.file = f.file;
56636
56637 error = vfs_readdir(f.file, filldir, &buf);
56638 if (error >= 0)
56639@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56640 struct getdents_callback64 {
56641 struct linux_dirent64 __user * current_dir;
56642 struct linux_dirent64 __user * previous;
56643+ struct file *file;
56644 int count;
56645 int error;
56646 };
56647@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56648 buf->error = -EINVAL; /* only used if we fail.. */
56649 if (reclen > buf->count)
56650 return -EINVAL;
56651+
56652+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56653+ return 0;
56654+
56655 dirent = buf->previous;
56656 if (dirent) {
56657 if (__put_user(offset, &dirent->d_off))
56658@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56659
56660 buf.current_dir = dirent;
56661 buf.previous = NULL;
56662+ buf.file = f.file;
56663 buf.count = count;
56664 buf.error = 0;
56665
56666@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56667 error = buf.error;
56668 lastdirent = buf.previous;
56669 if (lastdirent) {
56670- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56671+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56672 if (__put_user(d_off, &lastdirent->d_off))
56673 error = -EFAULT;
56674 else
56675diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56676index 2b7882b..1c5ef48 100644
56677--- a/fs/reiserfs/do_balan.c
56678+++ b/fs/reiserfs/do_balan.c
56679@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56680 return;
56681 }
56682
56683- atomic_inc(&(fs_generation(tb->tb_sb)));
56684+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56685 do_balance_starts(tb);
56686
56687 /* balance leaf returns 0 except if combining L R and S into
56688diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56689index 33532f7..4846ade 100644
56690--- a/fs/reiserfs/procfs.c
56691+++ b/fs/reiserfs/procfs.c
56692@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56693 "SMALL_TAILS " : "NO_TAILS ",
56694 replay_only(sb) ? "REPLAY_ONLY " : "",
56695 convert_reiserfs(sb) ? "CONV " : "",
56696- atomic_read(&r->s_generation_counter),
56697+ atomic_read_unchecked(&r->s_generation_counter),
56698 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56699 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56700 SF(s_good_search_by_key_reada), SF(s_bmaps),
56701diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56702index 157e474..65a6114 100644
56703--- a/fs/reiserfs/reiserfs.h
56704+++ b/fs/reiserfs/reiserfs.h
56705@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56706 /* Comment? -Hans */
56707 wait_queue_head_t s_wait;
56708 /* To be obsoleted soon by per buffer seals.. -Hans */
56709- atomic_t s_generation_counter; // increased by one every time the
56710+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56711 // tree gets re-balanced
56712 unsigned long s_properties; /* File system properties. Currently holds
56713 on-disk FS format */
56714@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56715 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56716
56717 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56718-#define get_generation(s) atomic_read (&fs_generation(s))
56719+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56720 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56721 #define __fs_changed(gen,s) (gen != get_generation (s))
56722 #define fs_changed(gen,s) \
56723diff --git a/fs/select.c b/fs/select.c
56724index 8c1c96c..a0f9b6d 100644
56725--- a/fs/select.c
56726+++ b/fs/select.c
56727@@ -20,6 +20,7 @@
56728 #include <linux/export.h>
56729 #include <linux/slab.h>
56730 #include <linux/poll.h>
56731+#include <linux/security.h>
56732 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56733 #include <linux/file.h>
56734 #include <linux/fdtable.h>
56735@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56736 struct poll_list *walk = head;
56737 unsigned long todo = nfds;
56738
56739+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56740 if (nfds > rlimit(RLIMIT_NOFILE))
56741 return -EINVAL;
56742
56743diff --git a/fs/seq_file.c b/fs/seq_file.c
56744index 774c1eb..b67582a 100644
56745--- a/fs/seq_file.c
56746+++ b/fs/seq_file.c
56747@@ -10,6 +10,7 @@
56748 #include <linux/seq_file.h>
56749 #include <linux/slab.h>
56750 #include <linux/cred.h>
56751+#include <linux/sched.h>
56752
56753 #include <asm/uaccess.h>
56754 #include <asm/page.h>
56755@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56756 #ifdef CONFIG_USER_NS
56757 p->user_ns = file->f_cred->user_ns;
56758 #endif
56759+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56760+ p->exec_id = current->exec_id;
56761+#endif
56762
56763 /*
56764 * Wrappers around seq_open(e.g. swaps_open) need to be
56765@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56766 return 0;
56767 }
56768 if (!m->buf) {
56769- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56770+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56771 if (!m->buf)
56772 return -ENOMEM;
56773 }
56774@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56775 Eoverflow:
56776 m->op->stop(m, p);
56777 kfree(m->buf);
56778- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56779+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56780 return !m->buf ? -ENOMEM : -EAGAIN;
56781 }
56782
56783@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56784
56785 /* grab buffer if we didn't have one */
56786 if (!m->buf) {
56787- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56788+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56789 if (!m->buf)
56790 goto Enomem;
56791 }
56792@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56793 goto Fill;
56794 m->op->stop(m, p);
56795 kfree(m->buf);
56796- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56797+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56798 if (!m->buf)
56799 goto Enomem;
56800 m->count = 0;
56801@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56802 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56803 void *data)
56804 {
56805- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56806+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56807 int res = -ENOMEM;
56808
56809 if (op) {
56810diff --git a/fs/splice.c b/fs/splice.c
56811index d37431d..81c3044 100644
56812--- a/fs/splice.c
56813+++ b/fs/splice.c
56814@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56815 pipe_lock(pipe);
56816
56817 for (;;) {
56818- if (!pipe->readers) {
56819+ if (!atomic_read(&pipe->readers)) {
56820 send_sig(SIGPIPE, current, 0);
56821 if (!ret)
56822 ret = -EPIPE;
56823@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56824 page_nr++;
56825 ret += buf->len;
56826
56827- if (pipe->files)
56828+ if (atomic_read(&pipe->files))
56829 do_wakeup = 1;
56830
56831 if (!--spd->nr_pages)
56832@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56833 do_wakeup = 0;
56834 }
56835
56836- pipe->waiting_writers++;
56837+ atomic_inc(&pipe->waiting_writers);
56838 pipe_wait(pipe);
56839- pipe->waiting_writers--;
56840+ atomic_dec(&pipe->waiting_writers);
56841 }
56842
56843 pipe_unlock(pipe);
56844@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56845 old_fs = get_fs();
56846 set_fs(get_ds());
56847 /* The cast to a user pointer is valid due to the set_fs() */
56848- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56849+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56850 set_fs(old_fs);
56851
56852 return res;
56853@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56854 old_fs = get_fs();
56855 set_fs(get_ds());
56856 /* The cast to a user pointer is valid due to the set_fs() */
56857- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
56858+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56859 set_fs(old_fs);
56860
56861 return res;
56862@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56863 goto err;
56864
56865 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56866- vec[i].iov_base = (void __user *) page_address(page);
56867+ vec[i].iov_base = (void __force_user *) page_address(page);
56868 vec[i].iov_len = this_len;
56869 spd.pages[i] = page;
56870 spd.nr_pages++;
56871@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
56872 ops->release(pipe, buf);
56873 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
56874 pipe->nrbufs--;
56875- if (pipe->files)
56876+ if (atomic_read(&pipe->files))
56877 sd->need_wakeup = true;
56878 }
56879
56880@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56881 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56882 {
56883 while (!pipe->nrbufs) {
56884- if (!pipe->writers)
56885+ if (!atomic_read(&pipe->writers))
56886 return 0;
56887
56888- if (!pipe->waiting_writers && sd->num_spliced)
56889+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56890 return 0;
56891
56892 if (sd->flags & SPLICE_F_NONBLOCK)
56893@@ -1193,7 +1193,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56894 * out of the pipe right after the splice_to_pipe(). So set
56895 * PIPE_READERS appropriately.
56896 */
56897- pipe->readers = 1;
56898+ atomic_set(&pipe->readers, 1);
56899
56900 current->splice_pipe = pipe;
56901 }
56902@@ -1769,9 +1769,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56903 ret = -ERESTARTSYS;
56904 break;
56905 }
56906- if (!pipe->writers)
56907+ if (!atomic_read(&pipe->writers))
56908 break;
56909- if (!pipe->waiting_writers) {
56910+ if (!atomic_read(&pipe->waiting_writers)) {
56911 if (flags & SPLICE_F_NONBLOCK) {
56912 ret = -EAGAIN;
56913 break;
56914@@ -1803,7 +1803,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56915 pipe_lock(pipe);
56916
56917 while (pipe->nrbufs >= pipe->buffers) {
56918- if (!pipe->readers) {
56919+ if (!atomic_read(&pipe->readers)) {
56920 send_sig(SIGPIPE, current, 0);
56921 ret = -EPIPE;
56922 break;
56923@@ -1816,9 +1816,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56924 ret = -ERESTARTSYS;
56925 break;
56926 }
56927- pipe->waiting_writers++;
56928+ atomic_inc(&pipe->waiting_writers);
56929 pipe_wait(pipe);
56930- pipe->waiting_writers--;
56931+ atomic_dec(&pipe->waiting_writers);
56932 }
56933
56934 pipe_unlock(pipe);
56935@@ -1854,14 +1854,14 @@ retry:
56936 pipe_double_lock(ipipe, opipe);
56937
56938 do {
56939- if (!opipe->readers) {
56940+ if (!atomic_read(&opipe->readers)) {
56941 send_sig(SIGPIPE, current, 0);
56942 if (!ret)
56943 ret = -EPIPE;
56944 break;
56945 }
56946
56947- if (!ipipe->nrbufs && !ipipe->writers)
56948+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56949 break;
56950
56951 /*
56952@@ -1958,7 +1958,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56953 pipe_double_lock(ipipe, opipe);
56954
56955 do {
56956- if (!opipe->readers) {
56957+ if (!atomic_read(&opipe->readers)) {
56958 send_sig(SIGPIPE, current, 0);
56959 if (!ret)
56960 ret = -EPIPE;
56961@@ -2003,7 +2003,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56962 * return EAGAIN if we have the potential of some data in the
56963 * future, otherwise just return 0
56964 */
56965- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56966+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56967 ret = -EAGAIN;
56968
56969 pipe_unlock(ipipe);
56970diff --git a/fs/stat.c b/fs/stat.c
56971index 04ce1ac..a13dd1e 100644
56972--- a/fs/stat.c
56973+++ b/fs/stat.c
56974@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56975 stat->gid = inode->i_gid;
56976 stat->rdev = inode->i_rdev;
56977 stat->size = i_size_read(inode);
56978- stat->atime = inode->i_atime;
56979- stat->mtime = inode->i_mtime;
56980+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56981+ stat->atime = inode->i_ctime;
56982+ stat->mtime = inode->i_ctime;
56983+ } else {
56984+ stat->atime = inode->i_atime;
56985+ stat->mtime = inode->i_mtime;
56986+ }
56987 stat->ctime = inode->i_ctime;
56988 stat->blksize = (1 << inode->i_blkbits);
56989 stat->blocks = inode->i_blocks;
56990@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
56991 if (retval)
56992 return retval;
56993
56994- if (inode->i_op->getattr)
56995- return inode->i_op->getattr(path->mnt, path->dentry, stat);
56996+ if (inode->i_op->getattr) {
56997+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
56998+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56999+ stat->atime = stat->ctime;
57000+ stat->mtime = stat->ctime;
57001+ }
57002+ return retval;
57003+ }
57004
57005 generic_fillattr(inode, stat);
57006 return 0;
57007diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
57008index 15c68f9..36a8b3e 100644
57009--- a/fs/sysfs/bin.c
57010+++ b/fs/sysfs/bin.c
57011@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
57012 return ret;
57013 }
57014
57015-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
57016- void *buf, int len, int write)
57017+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
57018+ void *buf, size_t len, int write)
57019 {
57020 struct file *file = vma->vm_file;
57021 struct bin_buffer *bb = file->private_data;
57022 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
57023- int ret;
57024+ ssize_t ret;
57025
57026 if (!bb->vm_ops)
57027 return -EINVAL;
57028diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
57029index e8e0e71..79c28ac5 100644
57030--- a/fs/sysfs/dir.c
57031+++ b/fs/sysfs/dir.c
57032@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
57033 *
57034 * Returns 31 bit hash of ns + name (so it fits in an off_t )
57035 */
57036-static unsigned int sysfs_name_hash(const void *ns, const char *name)
57037+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
57038 {
57039 unsigned long hash = init_name_hash();
57040 unsigned int len = strlen(name);
57041@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
57042 struct sysfs_dirent *sd;
57043 int rc;
57044
57045+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
57046+ const char *parent_name = parent_sd->s_name;
57047+
57048+ mode = S_IFDIR | S_IRWXU;
57049+
57050+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
57051+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
57052+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
57053+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
57054+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
57055+#endif
57056+
57057 /* allocate */
57058 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
57059 if (!sd)
57060diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
57061index 602f56d..6853db8 100644
57062--- a/fs/sysfs/file.c
57063+++ b/fs/sysfs/file.c
57064@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
57065
57066 struct sysfs_open_dirent {
57067 atomic_t refcnt;
57068- atomic_t event;
57069+ atomic_unchecked_t event;
57070 wait_queue_head_t poll;
57071 struct list_head buffers; /* goes through sysfs_buffer.list */
57072 };
57073@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
57074 if (!sysfs_get_active(attr_sd))
57075 return -ENODEV;
57076
57077- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
57078+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
57079 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
57080
57081 sysfs_put_active(attr_sd);
57082@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
57083 return -ENOMEM;
57084
57085 atomic_set(&new_od->refcnt, 0);
57086- atomic_set(&new_od->event, 1);
57087+ atomic_set_unchecked(&new_od->event, 1);
57088 init_waitqueue_head(&new_od->poll);
57089 INIT_LIST_HEAD(&new_od->buffers);
57090 goto retry;
57091@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
57092
57093 sysfs_put_active(attr_sd);
57094
57095- if (buffer->event != atomic_read(&od->event))
57096+ if (buffer->event != atomic_read_unchecked(&od->event))
57097 goto trigger;
57098
57099 return DEFAULT_POLLMASK;
57100@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
57101
57102 od = sd->s_attr.open;
57103 if (od) {
57104- atomic_inc(&od->event);
57105+ atomic_inc_unchecked(&od->event);
57106 wake_up_interruptible(&od->poll);
57107 }
57108
57109diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
57110index 8c940df..25b733e 100644
57111--- a/fs/sysfs/symlink.c
57112+++ b/fs/sysfs/symlink.c
57113@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
57114
57115 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
57116 {
57117- char *page = nd_get_link(nd);
57118+ const char *page = nd_get_link(nd);
57119 if (!IS_ERR(page))
57120 free_page((unsigned long)page);
57121 }
57122diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
57123index 69d4889..a810bd4 100644
57124--- a/fs/sysv/sysv.h
57125+++ b/fs/sysv/sysv.h
57126@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
57127 #endif
57128 }
57129
57130-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
57131+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
57132 {
57133 if (sbi->s_bytesex == BYTESEX_PDP)
57134 return PDP_swab((__force __u32)n);
57135diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
57136index e18b988..f1d4ad0f 100644
57137--- a/fs/ubifs/io.c
57138+++ b/fs/ubifs/io.c
57139@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
57140 return err;
57141 }
57142
57143-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
57144+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
57145 {
57146 int err;
57147
57148diff --git a/fs/udf/misc.c b/fs/udf/misc.c
57149index c175b4d..8f36a16 100644
57150--- a/fs/udf/misc.c
57151+++ b/fs/udf/misc.c
57152@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
57153
57154 u8 udf_tag_checksum(const struct tag *t)
57155 {
57156- u8 *data = (u8 *)t;
57157+ const u8 *data = (const u8 *)t;
57158 u8 checksum = 0;
57159 int i;
57160 for (i = 0; i < sizeof(struct tag); ++i)
57161diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
57162index 8d974c4..b82f6ec 100644
57163--- a/fs/ufs/swab.h
57164+++ b/fs/ufs/swab.h
57165@@ -22,7 +22,7 @@ enum {
57166 BYTESEX_BE
57167 };
57168
57169-static inline u64
57170+static inline u64 __intentional_overflow(-1)
57171 fs64_to_cpu(struct super_block *sbp, __fs64 n)
57172 {
57173 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
57174@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
57175 return (__force __fs64)cpu_to_be64(n);
57176 }
57177
57178-static inline u32
57179+static inline u32 __intentional_overflow(-1)
57180 fs32_to_cpu(struct super_block *sbp, __fs32 n)
57181 {
57182 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
57183diff --git a/fs/utimes.c b/fs/utimes.c
57184index f4fb7ec..3fe03c0 100644
57185--- a/fs/utimes.c
57186+++ b/fs/utimes.c
57187@@ -1,6 +1,7 @@
57188 #include <linux/compiler.h>
57189 #include <linux/file.h>
57190 #include <linux/fs.h>
57191+#include <linux/security.h>
57192 #include <linux/linkage.h>
57193 #include <linux/mount.h>
57194 #include <linux/namei.h>
57195@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
57196 goto mnt_drop_write_and_out;
57197 }
57198 }
57199+
57200+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
57201+ error = -EACCES;
57202+ goto mnt_drop_write_and_out;
57203+ }
57204+
57205 mutex_lock(&inode->i_mutex);
57206 error = notify_change(path->dentry, &newattrs);
57207 mutex_unlock(&inode->i_mutex);
57208diff --git a/fs/xattr.c b/fs/xattr.c
57209index 3377dff..4d074d9 100644
57210--- a/fs/xattr.c
57211+++ b/fs/xattr.c
57212@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
57213 return rc;
57214 }
57215
57216+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57217+ssize_t
57218+pax_getxattr(struct dentry *dentry, void *value, size_t size)
57219+{
57220+ struct inode *inode = dentry->d_inode;
57221+ ssize_t error;
57222+
57223+ error = inode_permission(inode, MAY_EXEC);
57224+ if (error)
57225+ return error;
57226+
57227+ if (inode->i_op->getxattr)
57228+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
57229+ else
57230+ error = -EOPNOTSUPP;
57231+
57232+ return error;
57233+}
57234+EXPORT_SYMBOL(pax_getxattr);
57235+#endif
57236+
57237 ssize_t
57238 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
57239 {
57240@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
57241 * Extended attribute SET operations
57242 */
57243 static long
57244-setxattr(struct dentry *d, const char __user *name, const void __user *value,
57245+setxattr(struct path *path, const char __user *name, const void __user *value,
57246 size_t size, int flags)
57247 {
57248 int error;
57249@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
57250 posix_acl_fix_xattr_from_user(kvalue, size);
57251 }
57252
57253- error = vfs_setxattr(d, kname, kvalue, size, flags);
57254+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
57255+ error = -EACCES;
57256+ goto out;
57257+ }
57258+
57259+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
57260 out:
57261 if (vvalue)
57262 vfree(vvalue);
57263@@ -377,7 +403,7 @@ retry:
57264 return error;
57265 error = mnt_want_write(path.mnt);
57266 if (!error) {
57267- error = setxattr(path.dentry, name, value, size, flags);
57268+ error = setxattr(&path, name, value, size, flags);
57269 mnt_drop_write(path.mnt);
57270 }
57271 path_put(&path);
57272@@ -401,7 +427,7 @@ retry:
57273 return error;
57274 error = mnt_want_write(path.mnt);
57275 if (!error) {
57276- error = setxattr(path.dentry, name, value, size, flags);
57277+ error = setxattr(&path, name, value, size, flags);
57278 mnt_drop_write(path.mnt);
57279 }
57280 path_put(&path);
57281@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
57282 const void __user *,value, size_t, size, int, flags)
57283 {
57284 struct fd f = fdget(fd);
57285- struct dentry *dentry;
57286 int error = -EBADF;
57287
57288 if (!f.file)
57289 return error;
57290- dentry = f.file->f_path.dentry;
57291- audit_inode(NULL, dentry, 0);
57292+ audit_inode(NULL, f.file->f_path.dentry, 0);
57293 error = mnt_want_write_file(f.file);
57294 if (!error) {
57295- error = setxattr(dentry, name, value, size, flags);
57296+ error = setxattr(&f.file->f_path, name, value, size, flags);
57297 mnt_drop_write_file(f.file);
57298 }
57299 fdput(f);
57300diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
57301index 9fbea87..6b19972 100644
57302--- a/fs/xattr_acl.c
57303+++ b/fs/xattr_acl.c
57304@@ -76,8 +76,8 @@ struct posix_acl *
57305 posix_acl_from_xattr(struct user_namespace *user_ns,
57306 const void *value, size_t size)
57307 {
57308- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57309- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57310+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57311+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57312 int count;
57313 struct posix_acl *acl;
57314 struct posix_acl_entry *acl_e;
57315diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57316index 8904284..ee0e14b 100644
57317--- a/fs/xfs/xfs_bmap.c
57318+++ b/fs/xfs/xfs_bmap.c
57319@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
57320
57321 #else
57322 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
57323-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57324+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
57325 #endif /* DEBUG */
57326
57327 /*
57328diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57329index 6157424..ac98f6d 100644
57330--- a/fs/xfs/xfs_dir2_sf.c
57331+++ b/fs/xfs/xfs_dir2_sf.c
57332@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57333 }
57334
57335 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57336- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57337+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57338+ char name[sfep->namelen];
57339+ memcpy(name, sfep->name, sfep->namelen);
57340+ if (filldir(dirent, name, sfep->namelen,
57341+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57342+ *offset = off & 0x7fffffff;
57343+ return 0;
57344+ }
57345+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57346 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57347 *offset = off & 0x7fffffff;
57348 return 0;
57349diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57350index 5e99968..45bd327 100644
57351--- a/fs/xfs/xfs_ioctl.c
57352+++ b/fs/xfs/xfs_ioctl.c
57353@@ -127,7 +127,7 @@ xfs_find_handle(
57354 }
57355
57356 error = -EFAULT;
57357- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57358+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57359 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57360 goto out_put;
57361
57362diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57363index ca9ecaa..60100c7 100644
57364--- a/fs/xfs/xfs_iops.c
57365+++ b/fs/xfs/xfs_iops.c
57366@@ -395,7 +395,7 @@ xfs_vn_put_link(
57367 struct nameidata *nd,
57368 void *p)
57369 {
57370- char *s = nd_get_link(nd);
57371+ const char *s = nd_get_link(nd);
57372
57373 if (!IS_ERR(s))
57374 kfree(s);
57375diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57376new file mode 100644
57377index 0000000..712a85d
57378--- /dev/null
57379+++ b/grsecurity/Kconfig
57380@@ -0,0 +1,1043 @@
57381+#
57382+# grecurity configuration
57383+#
57384+menu "Memory Protections"
57385+depends on GRKERNSEC
57386+
57387+config GRKERNSEC_KMEM
57388+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57389+ default y if GRKERNSEC_CONFIG_AUTO
57390+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57391+ help
57392+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57393+ be written to or read from to modify or leak the contents of the running
57394+ kernel. /dev/port will also not be allowed to be opened and support
57395+ for /dev/cpu/*/msr will be removed. If you have module
57396+ support disabled, enabling this will close up five ways that are
57397+ currently used to insert malicious code into the running kernel.
57398+
57399+ Even with all these features enabled, we still highly recommend that
57400+ you use the RBAC system, as it is still possible for an attacker to
57401+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57402+
57403+ If you are not using XFree86, you may be able to stop this additional
57404+ case by enabling the 'Disable privileged I/O' option. Though nothing
57405+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57406+ but only to video memory, which is the only writing we allow in this
57407+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57408+ not be allowed to mprotect it with PROT_WRITE later.
57409+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57410+ from working.
57411+
57412+ It is highly recommended that you say Y here if you meet all the
57413+ conditions above.
57414+
57415+config GRKERNSEC_VM86
57416+ bool "Restrict VM86 mode"
57417+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57418+ depends on X86_32
57419+
57420+ help
57421+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57422+ make use of a special execution mode on 32bit x86 processors called
57423+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57424+ video cards and will still work with this option enabled. The purpose
57425+ of the option is to prevent exploitation of emulation errors in
57426+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57427+ Nearly all users should be able to enable this option.
57428+
57429+config GRKERNSEC_IO
57430+ bool "Disable privileged I/O"
57431+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57432+ depends on X86
57433+ select RTC_CLASS
57434+ select RTC_INTF_DEV
57435+ select RTC_DRV_CMOS
57436+
57437+ help
57438+ If you say Y here, all ioperm and iopl calls will return an error.
57439+ Ioperm and iopl can be used to modify the running kernel.
57440+ Unfortunately, some programs need this access to operate properly,
57441+ the most notable of which are XFree86 and hwclock. hwclock can be
57442+ remedied by having RTC support in the kernel, so real-time
57443+ clock support is enabled if this option is enabled, to ensure
57444+ that hwclock operates correctly. XFree86 still will not
57445+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57446+ IF YOU USE XFree86. If you use XFree86 and you still want to
57447+ protect your kernel against modification, use the RBAC system.
57448+
57449+config GRKERNSEC_JIT_HARDEN
57450+ bool "Harden BPF JIT against spray attacks"
57451+ default y if GRKERNSEC_CONFIG_AUTO
57452+ depends on BPF_JIT
57453+ help
57454+ If you say Y here, the native code generated by the kernel's Berkeley
57455+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57456+ attacks that attempt to fit attacker-beneficial instructions in
57457+ 32bit immediate fields of JIT-generated native instructions. The
57458+ attacker will generally aim to cause an unintended instruction sequence
57459+ of JIT-generated native code to execute by jumping into the middle of
57460+ a generated instruction. This feature effectively randomizes the 32bit
57461+ immediate constants present in the generated code to thwart such attacks.
57462+
57463+ If you're using KERNEXEC, it's recommended that you enable this option
57464+ to supplement the hardening of the kernel.
57465+
57466+config GRKERNSEC_PERF_HARDEN
57467+ bool "Disable unprivileged PERF_EVENTS usage by default"
57468+ default y if GRKERNSEC_CONFIG_AUTO
57469+ depends on PERF_EVENTS
57470+ help
57471+ If you say Y here, the range of acceptable values for the
57472+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
57473+ default to a new value: 3. When the sysctl is set to this value, no
57474+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
57475+
57476+ Though PERF_EVENTS can be used legitimately for performance monitoring
57477+ and low-level application profiling, it is forced on regardless of
57478+ configuration, has been at fault for several vulnerabilities, and
57479+ creates new opportunities for side channels and other information leaks.
57480+
57481+ This feature puts PERF_EVENTS into a secure default state and permits
57482+ the administrator to change out of it temporarily if unprivileged
57483+ application profiling is needed.
57484+
57485+config GRKERNSEC_RAND_THREADSTACK
57486+ bool "Insert random gaps between thread stacks"
57487+ default y if GRKERNSEC_CONFIG_AUTO
57488+ depends on PAX_RANDMMAP && !PPC
57489+ help
57490+ If you say Y here, a random-sized gap will be enforced between allocated
57491+ thread stacks. Glibc's NPTL and other threading libraries that
57492+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57493+ The implementation currently provides 8 bits of entropy for the gap.
57494+
57495+ Many distributions do not compile threaded remote services with the
57496+ -fstack-check argument to GCC, causing the variable-sized stack-based
57497+ allocator, alloca(), to not probe the stack on allocation. This
57498+ permits an unbounded alloca() to skip over any guard page and potentially
57499+ modify another thread's stack reliably. An enforced random gap
57500+ reduces the reliability of such an attack and increases the chance
57501+ that such a read/write to another thread's stack instead lands in
57502+ an unmapped area, causing a crash and triggering grsecurity's
57503+ anti-bruteforcing logic.
57504+
57505+config GRKERNSEC_PROC_MEMMAP
57506+ bool "Harden ASLR against information leaks and entropy reduction"
57507+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57508+ depends on PAX_NOEXEC || PAX_ASLR
57509+ help
57510+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57511+ give no information about the addresses of its mappings if
57512+ PaX features that rely on random addresses are enabled on the task.
57513+ In addition to sanitizing this information and disabling other
57514+ dangerous sources of information, this option causes reads of sensitive
57515+ /proc/<pid> entries where the file descriptor was opened in a different
57516+ task than the one performing the read. Such attempts are logged.
57517+ This option also limits argv/env strings for suid/sgid binaries
57518+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57519+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57520+ binaries to prevent alternative mmap layouts from being abused.
57521+
57522+ If you use PaX it is essential that you say Y here as it closes up
57523+ several holes that make full ASLR useless locally.
57524+
57525+config GRKERNSEC_BRUTE
57526+ bool "Deter exploit bruteforcing"
57527+ default y if GRKERNSEC_CONFIG_AUTO
57528+ help
57529+ If you say Y here, attempts to bruteforce exploits against forking
57530+ daemons such as apache or sshd, as well as against suid/sgid binaries
57531+ will be deterred. When a child of a forking daemon is killed by PaX
57532+ or crashes due to an illegal instruction or other suspicious signal,
57533+ the parent process will be delayed 30 seconds upon every subsequent
57534+ fork until the administrator is able to assess the situation and
57535+ restart the daemon.
57536+ In the suid/sgid case, the attempt is logged, the user has all their
57537+ existing instances of the suid/sgid binary terminated and will
57538+ be unable to execute any suid/sgid binaries for 15 minutes.
57539+
57540+ It is recommended that you also enable signal logging in the auditing
57541+ section so that logs are generated when a process triggers a suspicious
57542+ signal.
57543+ If the sysctl option is enabled, a sysctl option with name
57544+ "deter_bruteforce" is created.
57545+
57546+
57547+config GRKERNSEC_MODHARDEN
57548+ bool "Harden module auto-loading"
57549+ default y if GRKERNSEC_CONFIG_AUTO
57550+ depends on MODULES
57551+ help
57552+ If you say Y here, module auto-loading in response to use of some
57553+ feature implemented by an unloaded module will be restricted to
57554+ root users. Enabling this option helps defend against attacks
57555+ by unprivileged users who abuse the auto-loading behavior to
57556+ cause a vulnerable module to load that is then exploited.
57557+
57558+ If this option prevents a legitimate use of auto-loading for a
57559+ non-root user, the administrator can execute modprobe manually
57560+ with the exact name of the module mentioned in the alert log.
57561+ Alternatively, the administrator can add the module to the list
57562+ of modules loaded at boot by modifying init scripts.
57563+
57564+ Modification of init scripts will most likely be needed on
57565+ Ubuntu servers with encrypted home directory support enabled,
57566+ as the first non-root user logging in will cause the ecb(aes),
57567+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57568+
57569+config GRKERNSEC_HIDESYM
57570+ bool "Hide kernel symbols"
57571+ default y if GRKERNSEC_CONFIG_AUTO
57572+ select PAX_USERCOPY_SLABS
57573+ help
57574+ If you say Y here, getting information on loaded modules, and
57575+ displaying all kernel symbols through a syscall will be restricted
57576+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57577+ /proc/kallsyms will be restricted to the root user. The RBAC
57578+ system can hide that entry even from root.
57579+
57580+ This option also prevents leaking of kernel addresses through
57581+ several /proc entries.
57582+
57583+ Note that this option is only effective provided the following
57584+ conditions are met:
57585+ 1) The kernel using grsecurity is not precompiled by some distribution
57586+ 2) You have also enabled GRKERNSEC_DMESG
57587+ 3) You are using the RBAC system and hiding other files such as your
57588+ kernel image and System.map. Alternatively, enabling this option
57589+ causes the permissions on /boot, /lib/modules, and the kernel
57590+ source directory to change at compile time to prevent
57591+ reading by non-root users.
57592+ If the above conditions are met, this option will aid in providing a
57593+ useful protection against local kernel exploitation of overflows
57594+ and arbitrary read/write vulnerabilities.
57595+
57596+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
57597+ in addition to this feature.
57598+
57599+config GRKERNSEC_KERN_LOCKOUT
57600+ bool "Active kernel exploit response"
57601+ default y if GRKERNSEC_CONFIG_AUTO
57602+ depends on X86 || ARM || PPC || SPARC
57603+ help
57604+ If you say Y here, when a PaX alert is triggered due to suspicious
57605+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57606+ or an OOPS occurs due to bad memory accesses, instead of just
57607+ terminating the offending process (and potentially allowing
57608+ a subsequent exploit from the same user), we will take one of two
57609+ actions:
57610+ If the user was root, we will panic the system
57611+ If the user was non-root, we will log the attempt, terminate
57612+ all processes owned by the user, then prevent them from creating
57613+ any new processes until the system is restarted
57614+ This deters repeated kernel exploitation/bruteforcing attempts
57615+ and is useful for later forensics.
57616+
57617+endmenu
57618+menu "Role Based Access Control Options"
57619+depends on GRKERNSEC
57620+
57621+config GRKERNSEC_RBAC_DEBUG
57622+ bool
57623+
57624+config GRKERNSEC_NO_RBAC
57625+ bool "Disable RBAC system"
57626+ help
57627+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57628+ preventing the RBAC system from being enabled. You should only say Y
57629+ here if you have no intention of using the RBAC system, so as to prevent
57630+ an attacker with root access from misusing the RBAC system to hide files
57631+ and processes when loadable module support and /dev/[k]mem have been
57632+ locked down.
57633+
57634+config GRKERNSEC_ACL_HIDEKERN
57635+ bool "Hide kernel processes"
57636+ help
57637+ If you say Y here, all kernel threads will be hidden to all
57638+ processes but those whose subject has the "view hidden processes"
57639+ flag.
57640+
57641+config GRKERNSEC_ACL_MAXTRIES
57642+ int "Maximum tries before password lockout"
57643+ default 3
57644+ help
57645+ This option enforces the maximum number of times a user can attempt
57646+ to authorize themselves with the grsecurity RBAC system before being
57647+ denied the ability to attempt authorization again for a specified time.
57648+ The lower the number, the harder it will be to brute-force a password.
57649+
57650+config GRKERNSEC_ACL_TIMEOUT
57651+ int "Time to wait after max password tries, in seconds"
57652+ default 30
57653+ help
57654+ This option specifies the time the user must wait after attempting to
57655+ authorize to the RBAC system with the maximum number of invalid
57656+ passwords. The higher the number, the harder it will be to brute-force
57657+ a password.
57658+
57659+endmenu
57660+menu "Filesystem Protections"
57661+depends on GRKERNSEC
57662+
57663+config GRKERNSEC_PROC
57664+ bool "Proc restrictions"
57665+ default y if GRKERNSEC_CONFIG_AUTO
57666+ help
57667+ If you say Y here, the permissions of the /proc filesystem
57668+ will be altered to enhance system security and privacy. You MUST
57669+ choose either a user only restriction or a user and group restriction.
57670+ Depending upon the option you choose, you can either restrict users to
57671+ see only the processes they themselves run, or choose a group that can
57672+ view all processes and files normally restricted to root if you choose
57673+ the "restrict to user only" option. NOTE: If you're running identd or
57674+ ntpd as a non-root user, you will have to run it as the group you
57675+ specify here.
57676+
57677+config GRKERNSEC_PROC_USER
57678+ bool "Restrict /proc to user only"
57679+ depends on GRKERNSEC_PROC
57680+ help
57681+ If you say Y here, non-root users will only be able to view their own
57682+ processes, and restricts them from viewing network-related information,
57683+ and viewing kernel symbol and module information.
57684+
57685+config GRKERNSEC_PROC_USERGROUP
57686+ bool "Allow special group"
57687+ default y if GRKERNSEC_CONFIG_AUTO
57688+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57689+ help
57690+ If you say Y here, you will be able to select a group that will be
57691+ able to view all processes and network-related information. If you've
57692+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57693+ remain hidden. This option is useful if you want to run identd as
57694+ a non-root user. The group you select may also be chosen at boot time
57695+ via "grsec_proc_gid=" on the kernel commandline.
57696+
57697+config GRKERNSEC_PROC_GID
57698+ int "GID for special group"
57699+ depends on GRKERNSEC_PROC_USERGROUP
57700+ default 1001
57701+
57702+config GRKERNSEC_PROC_ADD
57703+ bool "Additional restrictions"
57704+ default y if GRKERNSEC_CONFIG_AUTO
57705+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57706+ help
57707+ If you say Y here, additional restrictions will be placed on
57708+ /proc that keep normal users from viewing device information and
57709+ slabinfo information that could be useful for exploits.
57710+
57711+config GRKERNSEC_LINK
57712+ bool "Linking restrictions"
57713+ default y if GRKERNSEC_CONFIG_AUTO
57714+ help
57715+ If you say Y here, /tmp race exploits will be prevented, since users
57716+ will no longer be able to follow symlinks owned by other users in
57717+ world-writable +t directories (e.g. /tmp), unless the owner of the
57718+ symlink is the owner of the directory. users will also not be
57719+ able to hardlink to files they do not own. If the sysctl option is
57720+ enabled, a sysctl option with name "linking_restrictions" is created.
57721+
57722+config GRKERNSEC_SYMLINKOWN
57723+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57724+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57725+ help
57726+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57727+ that prevents it from being used as a security feature. As Apache
57728+ verifies the symlink by performing a stat() against the target of
57729+ the symlink before it is followed, an attacker can setup a symlink
57730+ to point to a same-owned file, then replace the symlink with one
57731+ that targets another user's file just after Apache "validates" the
57732+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57733+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57734+ will be in place for the group you specify. If the sysctl option
57735+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57736+ created.
57737+
57738+config GRKERNSEC_SYMLINKOWN_GID
57739+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57740+ depends on GRKERNSEC_SYMLINKOWN
57741+ default 1006
57742+ help
57743+ Setting this GID determines what group kernel-enforced
57744+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57745+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57746+
57747+config GRKERNSEC_FIFO
57748+ bool "FIFO restrictions"
57749+ default y if GRKERNSEC_CONFIG_AUTO
57750+ help
57751+ If you say Y here, users will not be able to write to FIFOs they don't
57752+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57753+ the FIFO is the same owner of the directory it's held in. If the sysctl
57754+ option is enabled, a sysctl option with name "fifo_restrictions" is
57755+ created.
57756+
57757+config GRKERNSEC_SYSFS_RESTRICT
57758+ bool "Sysfs/debugfs restriction"
57759+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57760+ depends on SYSFS
57761+ help
57762+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57763+ any filesystem normally mounted under it (e.g. debugfs) will be
57764+ mostly accessible only by root. These filesystems generally provide access
57765+ to hardware and debug information that isn't appropriate for unprivileged
57766+ users of the system. Sysfs and debugfs have also become a large source
57767+ of new vulnerabilities, ranging from infoleaks to local compromise.
57768+ There has been very little oversight with an eye toward security involved
57769+ in adding new exporters of information to these filesystems, so their
57770+ use is discouraged.
57771+ For reasons of compatibility, a few directories have been whitelisted
57772+ for access by non-root users:
57773+ /sys/fs/selinux
57774+ /sys/fs/fuse
57775+ /sys/devices/system/cpu
57776+
57777+config GRKERNSEC_ROFS
57778+ bool "Runtime read-only mount protection"
57779+ help
57780+ If you say Y here, a sysctl option with name "romount_protect" will
57781+ be created. By setting this option to 1 at runtime, filesystems
57782+ will be protected in the following ways:
57783+ * No new writable mounts will be allowed
57784+ * Existing read-only mounts won't be able to be remounted read/write
57785+ * Write operations will be denied on all block devices
57786+ This option acts independently of grsec_lock: once it is set to 1,
57787+ it cannot be turned off. Therefore, please be mindful of the resulting
57788+ behavior if this option is enabled in an init script on a read-only
57789+ filesystem. This feature is mainly intended for secure embedded systems.
57790+
57791+config GRKERNSEC_DEVICE_SIDECHANNEL
57792+ bool "Eliminate stat/notify-based device sidechannels"
57793+ default y if GRKERNSEC_CONFIG_AUTO
57794+ help
57795+ If you say Y here, timing analyses on block or character
57796+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57797+ will be thwarted for unprivileged users. If a process without
57798+ CAP_MKNOD stats such a device, the last access and last modify times
57799+ will match the device's create time. No access or modify events
57800+ will be triggered through inotify/dnotify/fanotify for such devices.
57801+ This feature will prevent attacks that may at a minimum
57802+ allow an attacker to determine the administrator's password length.
57803+
57804+config GRKERNSEC_CHROOT
57805+ bool "Chroot jail restrictions"
57806+ default y if GRKERNSEC_CONFIG_AUTO
57807+ help
57808+ If you say Y here, you will be able to choose several options that will
57809+ make breaking out of a chrooted jail much more difficult. If you
57810+ encounter no software incompatibilities with the following options, it
57811+ is recommended that you enable each one.
57812+
57813+config GRKERNSEC_CHROOT_MOUNT
57814+ bool "Deny mounts"
57815+ default y if GRKERNSEC_CONFIG_AUTO
57816+ depends on GRKERNSEC_CHROOT
57817+ help
57818+ If you say Y here, processes inside a chroot will not be able to
57819+ mount or remount filesystems. If the sysctl option is enabled, a
57820+ sysctl option with name "chroot_deny_mount" is created.
57821+
57822+config GRKERNSEC_CHROOT_DOUBLE
57823+ bool "Deny double-chroots"
57824+ default y if GRKERNSEC_CONFIG_AUTO
57825+ depends on GRKERNSEC_CHROOT
57826+ help
57827+ If you say Y here, processes inside a chroot will not be able to chroot
57828+ again outside the chroot. This is a widely used method of breaking
57829+ out of a chroot jail and should not be allowed. If the sysctl
57830+ option is enabled, a sysctl option with name
57831+ "chroot_deny_chroot" is created.
57832+
57833+config GRKERNSEC_CHROOT_PIVOT
57834+ bool "Deny pivot_root in chroot"
57835+ default y if GRKERNSEC_CONFIG_AUTO
57836+ depends on GRKERNSEC_CHROOT
57837+ help
57838+ If you say Y here, processes inside a chroot will not be able to use
57839+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57840+ works similar to chroot in that it changes the root filesystem. This
57841+ function could be misused in a chrooted process to attempt to break out
57842+ of the chroot, and therefore should not be allowed. If the sysctl
57843+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57844+ created.
57845+
57846+config GRKERNSEC_CHROOT_CHDIR
57847+ bool "Enforce chdir(\"/\") on all chroots"
57848+ default y if GRKERNSEC_CONFIG_AUTO
57849+ depends on GRKERNSEC_CHROOT
57850+ help
57851+ If you say Y here, the current working directory of all newly-chrooted
57852+ applications will be set to the the root directory of the chroot.
57853+ The man page on chroot(2) states:
57854+ Note that this call does not change the current working
57855+ directory, so that `.' can be outside the tree rooted at
57856+ `/'. In particular, the super-user can escape from a
57857+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57858+
57859+ It is recommended that you say Y here, since it's not known to break
57860+ any software. If the sysctl option is enabled, a sysctl option with
57861+ name "chroot_enforce_chdir" is created.
57862+
57863+config GRKERNSEC_CHROOT_CHMOD
57864+ bool "Deny (f)chmod +s"
57865+ default y if GRKERNSEC_CONFIG_AUTO
57866+ depends on GRKERNSEC_CHROOT
57867+ help
57868+ If you say Y here, processes inside a chroot will not be able to chmod
57869+ or fchmod files to make them have suid or sgid bits. This protects
57870+ against another published method of breaking a chroot. If the sysctl
57871+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57872+ created.
57873+
57874+config GRKERNSEC_CHROOT_FCHDIR
57875+ bool "Deny fchdir out of chroot"
57876+ default y if GRKERNSEC_CONFIG_AUTO
57877+ depends on GRKERNSEC_CHROOT
57878+ help
57879+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57880+ to a file descriptor of the chrooting process that points to a directory
57881+ outside the filesystem will be stopped. If the sysctl option
57882+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57883+
57884+config GRKERNSEC_CHROOT_MKNOD
57885+ bool "Deny mknod"
57886+ default y if GRKERNSEC_CONFIG_AUTO
57887+ depends on GRKERNSEC_CHROOT
57888+ help
57889+ If you say Y here, processes inside a chroot will not be allowed to
57890+ mknod. The problem with using mknod inside a chroot is that it
57891+ would allow an attacker to create a device entry that is the same
57892+ as one on the physical root of your system, which could range from
57893+ anything from the console device to a device for your harddrive (which
57894+ they could then use to wipe the drive or steal data). It is recommended
57895+ that you say Y here, unless you run into software incompatibilities.
57896+ If the sysctl option is enabled, a sysctl option with name
57897+ "chroot_deny_mknod" is created.
57898+
57899+config GRKERNSEC_CHROOT_SHMAT
57900+ bool "Deny shmat() out of chroot"
57901+ default y if GRKERNSEC_CONFIG_AUTO
57902+ depends on GRKERNSEC_CHROOT
57903+ help
57904+ If you say Y here, processes inside a chroot will not be able to attach
57905+ to shared memory segments that were created outside of the chroot jail.
57906+ It is recommended that you say Y here. If the sysctl option is enabled,
57907+ a sysctl option with name "chroot_deny_shmat" is created.
57908+
57909+config GRKERNSEC_CHROOT_UNIX
57910+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57911+ default y if GRKERNSEC_CONFIG_AUTO
57912+ depends on GRKERNSEC_CHROOT
57913+ help
57914+ If you say Y here, processes inside a chroot will not be able to
57915+ connect to abstract (meaning not belonging to a filesystem) Unix
57916+ domain sockets that were bound outside of a chroot. It is recommended
57917+ that you say Y here. If the sysctl option is enabled, a sysctl option
57918+ with name "chroot_deny_unix" is created.
57919+
57920+config GRKERNSEC_CHROOT_FINDTASK
57921+ bool "Protect outside processes"
57922+ default y if GRKERNSEC_CONFIG_AUTO
57923+ depends on GRKERNSEC_CHROOT
57924+ help
57925+ If you say Y here, processes inside a chroot will not be able to
57926+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57927+ getsid, or view any process outside of the chroot. If the sysctl
57928+ option is enabled, a sysctl option with name "chroot_findtask" is
57929+ created.
57930+
57931+config GRKERNSEC_CHROOT_NICE
57932+ bool "Restrict priority changes"
57933+ default y if GRKERNSEC_CONFIG_AUTO
57934+ depends on GRKERNSEC_CHROOT
57935+ help
57936+ If you say Y here, processes inside a chroot will not be able to raise
57937+ the priority of processes in the chroot, or alter the priority of
57938+ processes outside the chroot. This provides more security than simply
57939+ removing CAP_SYS_NICE from the process' capability set. If the
57940+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57941+ is created.
57942+
57943+config GRKERNSEC_CHROOT_SYSCTL
57944+ bool "Deny sysctl writes"
57945+ default y if GRKERNSEC_CONFIG_AUTO
57946+ depends on GRKERNSEC_CHROOT
57947+ help
57948+ If you say Y here, an attacker in a chroot will not be able to
57949+ write to sysctl entries, either by sysctl(2) or through a /proc
57950+ interface. It is strongly recommended that you say Y here. If the
57951+ sysctl option is enabled, a sysctl option with name
57952+ "chroot_deny_sysctl" is created.
57953+
57954+config GRKERNSEC_CHROOT_CAPS
57955+ bool "Capability restrictions"
57956+ default y if GRKERNSEC_CONFIG_AUTO
57957+ depends on GRKERNSEC_CHROOT
57958+ help
57959+ If you say Y here, the capabilities on all processes within a
57960+ chroot jail will be lowered to stop module insertion, raw i/o,
57961+ system and net admin tasks, rebooting the system, modifying immutable
57962+ files, modifying IPC owned by another, and changing the system time.
57963+ This is left an option because it can break some apps. Disable this
57964+ if your chrooted apps are having problems performing those kinds of
57965+ tasks. If the sysctl option is enabled, a sysctl option with
57966+ name "chroot_caps" is created.
57967+
57968+config GRKERNSEC_CHROOT_INITRD
57969+ bool "Exempt initrd tasks from restrictions"
57970+ default y if GRKERNSEC_CONFIG_AUTO
57971+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57972+ help
57973+ If you say Y here, tasks started prior to init will be exempted from
57974+ grsecurity's chroot restrictions. This option is mainly meant to
57975+ resolve Plymouth's performing privileged operations unnecessarily
57976+ in a chroot.
57977+
57978+endmenu
57979+menu "Kernel Auditing"
57980+depends on GRKERNSEC
57981+
57982+config GRKERNSEC_AUDIT_GROUP
57983+ bool "Single group for auditing"
57984+ help
57985+ If you say Y here, the exec and chdir logging features will only operate
57986+ on a group you specify. This option is recommended if you only want to
57987+ watch certain users instead of having a large amount of logs from the
57988+ entire system. If the sysctl option is enabled, a sysctl option with
57989+ name "audit_group" is created.
57990+
57991+config GRKERNSEC_AUDIT_GID
57992+ int "GID for auditing"
57993+ depends on GRKERNSEC_AUDIT_GROUP
57994+ default 1007
57995+
57996+config GRKERNSEC_EXECLOG
57997+ bool "Exec logging"
57998+ help
57999+ If you say Y here, all execve() calls will be logged (since the
58000+ other exec*() calls are frontends to execve(), all execution
58001+ will be logged). Useful for shell-servers that like to keep track
58002+ of their users. If the sysctl option is enabled, a sysctl option with
58003+ name "exec_logging" is created.
58004+ WARNING: This option when enabled will produce a LOT of logs, especially
58005+ on an active system.
58006+
58007+config GRKERNSEC_RESLOG
58008+ bool "Resource logging"
58009+ default y if GRKERNSEC_CONFIG_AUTO
58010+ help
58011+ If you say Y here, all attempts to overstep resource limits will
58012+ be logged with the resource name, the requested size, and the current
58013+ limit. It is highly recommended that you say Y here. If the sysctl
58014+ option is enabled, a sysctl option with name "resource_logging" is
58015+ created. If the RBAC system is enabled, the sysctl value is ignored.
58016+
58017+config GRKERNSEC_CHROOT_EXECLOG
58018+ bool "Log execs within chroot"
58019+ help
58020+ If you say Y here, all executions inside a chroot jail will be logged
58021+ to syslog. This can cause a large amount of logs if certain
58022+ applications (eg. djb's daemontools) are installed on the system, and
58023+ is therefore left as an option. If the sysctl option is enabled, a
58024+ sysctl option with name "chroot_execlog" is created.
58025+
58026+config GRKERNSEC_AUDIT_PTRACE
58027+ bool "Ptrace logging"
58028+ help
58029+ If you say Y here, all attempts to attach to a process via ptrace
58030+ will be logged. If the sysctl option is enabled, a sysctl option
58031+ with name "audit_ptrace" is created.
58032+
58033+config GRKERNSEC_AUDIT_CHDIR
58034+ bool "Chdir logging"
58035+ help
58036+ If you say Y here, all chdir() calls will be logged. If the sysctl
58037+ option is enabled, a sysctl option with name "audit_chdir" is created.
58038+
58039+config GRKERNSEC_AUDIT_MOUNT
58040+ bool "(Un)Mount logging"
58041+ help
58042+ If you say Y here, all mounts and unmounts will be logged. If the
58043+ sysctl option is enabled, a sysctl option with name "audit_mount" is
58044+ created.
58045+
58046+config GRKERNSEC_SIGNAL
58047+ bool "Signal logging"
58048+ default y if GRKERNSEC_CONFIG_AUTO
58049+ help
58050+ If you say Y here, certain important signals will be logged, such as
58051+ SIGSEGV, which will as a result inform you of when a error in a program
58052+ occurred, which in some cases could mean a possible exploit attempt.
58053+ If the sysctl option is enabled, a sysctl option with name
58054+ "signal_logging" is created.
58055+
58056+config GRKERNSEC_FORKFAIL
58057+ bool "Fork failure logging"
58058+ help
58059+ If you say Y here, all failed fork() attempts will be logged.
58060+ This could suggest a fork bomb, or someone attempting to overstep
58061+ their process limit. If the sysctl option is enabled, a sysctl option
58062+ with name "forkfail_logging" is created.
58063+
58064+config GRKERNSEC_TIME
58065+ bool "Time change logging"
58066+ default y if GRKERNSEC_CONFIG_AUTO
58067+ help
58068+ If you say Y here, any changes of the system clock will be logged.
58069+ If the sysctl option is enabled, a sysctl option with name
58070+ "timechange_logging" is created.
58071+
58072+config GRKERNSEC_PROC_IPADDR
58073+ bool "/proc/<pid>/ipaddr support"
58074+ default y if GRKERNSEC_CONFIG_AUTO
58075+ help
58076+ If you say Y here, a new entry will be added to each /proc/<pid>
58077+ directory that contains the IP address of the person using the task.
58078+ The IP is carried across local TCP and AF_UNIX stream sockets.
58079+ This information can be useful for IDS/IPSes to perform remote response
58080+ to a local attack. The entry is readable by only the owner of the
58081+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
58082+ the RBAC system), and thus does not create privacy concerns.
58083+
58084+config GRKERNSEC_RWXMAP_LOG
58085+ bool 'Denied RWX mmap/mprotect logging'
58086+ default y if GRKERNSEC_CONFIG_AUTO
58087+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
58088+ help
58089+ If you say Y here, calls to mmap() and mprotect() with explicit
58090+ usage of PROT_WRITE and PROT_EXEC together will be logged when
58091+ denied by the PAX_MPROTECT feature. This feature will also
58092+ log other problematic scenarios that can occur when PAX_MPROTECT
58093+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
58094+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
58095+ is created.
58096+
58097+endmenu
58098+
58099+menu "Executable Protections"
58100+depends on GRKERNSEC
58101+
58102+config GRKERNSEC_DMESG
58103+ bool "Dmesg(8) restriction"
58104+ default y if GRKERNSEC_CONFIG_AUTO
58105+ help
58106+ If you say Y here, non-root users will not be able to use dmesg(8)
58107+ to view the contents of the kernel's circular log buffer.
58108+ The kernel's log buffer often contains kernel addresses and other
58109+ identifying information useful to an attacker in fingerprinting a
58110+ system for a targeted exploit.
58111+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
58112+ created.
58113+
58114+config GRKERNSEC_HARDEN_PTRACE
58115+ bool "Deter ptrace-based process snooping"
58116+ default y if GRKERNSEC_CONFIG_AUTO
58117+ help
58118+ If you say Y here, TTY sniffers and other malicious monitoring
58119+ programs implemented through ptrace will be defeated. If you
58120+ have been using the RBAC system, this option has already been
58121+ enabled for several years for all users, with the ability to make
58122+ fine-grained exceptions.
58123+
58124+ This option only affects the ability of non-root users to ptrace
58125+ processes that are not a descendent of the ptracing process.
58126+ This means that strace ./binary and gdb ./binary will still work,
58127+ but attaching to arbitrary processes will not. If the sysctl
58128+ option is enabled, a sysctl option with name "harden_ptrace" is
58129+ created.
58130+
58131+config GRKERNSEC_PTRACE_READEXEC
58132+ bool "Require read access to ptrace sensitive binaries"
58133+ default y if GRKERNSEC_CONFIG_AUTO
58134+ help
58135+ If you say Y here, unprivileged users will not be able to ptrace unreadable
58136+ binaries. This option is useful in environments that
58137+ remove the read bits (e.g. file mode 4711) from suid binaries to
58138+ prevent infoleaking of their contents. This option adds
58139+ consistency to the use of that file mode, as the binary could normally
58140+ be read out when run without privileges while ptracing.
58141+
58142+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
58143+ is created.
58144+
58145+config GRKERNSEC_SETXID
58146+ bool "Enforce consistent multithreaded privileges"
58147+ default y if GRKERNSEC_CONFIG_AUTO
58148+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
58149+ help
58150+ If you say Y here, a change from a root uid to a non-root uid
58151+ in a multithreaded application will cause the resulting uids,
58152+ gids, supplementary groups, and capabilities in that thread
58153+ to be propagated to the other threads of the process. In most
58154+ cases this is unnecessary, as glibc will emulate this behavior
58155+ on behalf of the application. Other libcs do not act in the
58156+ same way, allowing the other threads of the process to continue
58157+ running with root privileges. If the sysctl option is enabled,
58158+ a sysctl option with name "consistent_setxid" is created.
58159+
58160+config GRKERNSEC_TPE
58161+ bool "Trusted Path Execution (TPE)"
58162+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
58163+ help
58164+ If you say Y here, you will be able to choose a gid to add to the
58165+ supplementary groups of users you want to mark as "untrusted."
58166+ These users will not be able to execute any files that are not in
58167+ root-owned directories writable only by root. If the sysctl option
58168+ is enabled, a sysctl option with name "tpe" is created.
58169+
58170+config GRKERNSEC_TPE_ALL
58171+ bool "Partially restrict all non-root users"
58172+ depends on GRKERNSEC_TPE
58173+ help
58174+ If you say Y here, all non-root users will be covered under
58175+ a weaker TPE restriction. This is separate from, and in addition to,
58176+ the main TPE options that you have selected elsewhere. Thus, if a
58177+ "trusted" GID is chosen, this restriction applies to even that GID.
58178+ Under this restriction, all non-root users will only be allowed to
58179+ execute files in directories they own that are not group or
58180+ world-writable, or in directories owned by root and writable only by
58181+ root. If the sysctl option is enabled, a sysctl option with name
58182+ "tpe_restrict_all" is created.
58183+
58184+config GRKERNSEC_TPE_INVERT
58185+ bool "Invert GID option"
58186+ depends on GRKERNSEC_TPE
58187+ help
58188+ If you say Y here, the group you specify in the TPE configuration will
58189+ decide what group TPE restrictions will be *disabled* for. This
58190+ option is useful if you want TPE restrictions to be applied to most
58191+ users on the system. If the sysctl option is enabled, a sysctl option
58192+ with name "tpe_invert" is created. Unlike other sysctl options, this
58193+ entry will default to on for backward-compatibility.
58194+
58195+config GRKERNSEC_TPE_GID
58196+ int
58197+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
58198+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
58199+
58200+config GRKERNSEC_TPE_UNTRUSTED_GID
58201+ int "GID for TPE-untrusted users"
58202+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
58203+ default 1005
58204+ help
58205+ Setting this GID determines what group TPE restrictions will be
58206+ *enabled* for. If the sysctl option is enabled, a sysctl option
58207+ with name "tpe_gid" is created.
58208+
58209+config GRKERNSEC_TPE_TRUSTED_GID
58210+ int "GID for TPE-trusted users"
58211+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
58212+ default 1005
58213+ help
58214+ Setting this GID determines what group TPE restrictions will be
58215+ *disabled* for. If the sysctl option is enabled, a sysctl option
58216+ with name "tpe_gid" is created.
58217+
58218+endmenu
58219+menu "Network Protections"
58220+depends on GRKERNSEC
58221+
58222+config GRKERNSEC_RANDNET
58223+ bool "Larger entropy pools"
58224+ default y if GRKERNSEC_CONFIG_AUTO
58225+ help
58226+ If you say Y here, the entropy pools used for many features of Linux
58227+ and grsecurity will be doubled in size. Since several grsecurity
58228+ features use additional randomness, it is recommended that you say Y
58229+ here. Saying Y here has a similar effect as modifying
58230+ /proc/sys/kernel/random/poolsize.
58231+
58232+config GRKERNSEC_BLACKHOLE
58233+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
58234+ default y if GRKERNSEC_CONFIG_AUTO
58235+ depends on NET
58236+ help
58237+ If you say Y here, neither TCP resets nor ICMP
58238+ destination-unreachable packets will be sent in response to packets
58239+ sent to ports for which no associated listening process exists.
58240+ This feature supports both IPV4 and IPV6 and exempts the
58241+ loopback interface from blackholing. Enabling this feature
58242+ makes a host more resilient to DoS attacks and reduces network
58243+ visibility against scanners.
58244+
58245+ The blackhole feature as-implemented is equivalent to the FreeBSD
58246+ blackhole feature, as it prevents RST responses to all packets, not
58247+ just SYNs. Under most application behavior this causes no
58248+ problems, but applications (like haproxy) may not close certain
58249+ connections in a way that cleanly terminates them on the remote
58250+ end, leaving the remote host in LAST_ACK state. Because of this
58251+ side-effect and to prevent intentional LAST_ACK DoSes, this
58252+ feature also adds automatic mitigation against such attacks.
58253+ The mitigation drastically reduces the amount of time a socket
58254+ can spend in LAST_ACK state. If you're using haproxy and not
58255+ all servers it connects to have this option enabled, consider
58256+ disabling this feature on the haproxy host.
58257+
58258+ If the sysctl option is enabled, two sysctl options with names
58259+ "ip_blackhole" and "lastack_retries" will be created.
58260+ While "ip_blackhole" takes the standard zero/non-zero on/off
58261+ toggle, "lastack_retries" uses the same kinds of values as
58262+ "tcp_retries1" and "tcp_retries2". The default value of 4
58263+ prevents a socket from lasting more than 45 seconds in LAST_ACK
58264+ state.
58265+
58266+config GRKERNSEC_NO_SIMULT_CONNECT
58267+ bool "Disable TCP Simultaneous Connect"
58268+ default y if GRKERNSEC_CONFIG_AUTO
58269+ depends on NET
58270+ help
58271+ If you say Y here, a feature by Willy Tarreau will be enabled that
58272+ removes a weakness in Linux's strict implementation of TCP that
58273+ allows two clients to connect to each other without either entering
58274+ a listening state. The weakness allows an attacker to easily prevent
58275+ a client from connecting to a known server provided the source port
58276+ for the connection is guessed correctly.
58277+
58278+ As the weakness could be used to prevent an antivirus or IPS from
58279+ fetching updates, or prevent an SSL gateway from fetching a CRL,
58280+ it should be eliminated by enabling this option. Though Linux is
58281+ one of few operating systems supporting simultaneous connect, it
58282+ has no legitimate use in practice and is rarely supported by firewalls.
58283+
58284+config GRKERNSEC_SOCKET
58285+ bool "Socket restrictions"
58286+ depends on NET
58287+ help
58288+ If you say Y here, you will be able to choose from several options.
58289+ If you assign a GID on your system and add it to the supplementary
58290+ groups of users you want to restrict socket access to, this patch
58291+ will perform up to three things, based on the option(s) you choose.
58292+
58293+config GRKERNSEC_SOCKET_ALL
58294+ bool "Deny any sockets to group"
58295+ depends on GRKERNSEC_SOCKET
58296+ help
58297+ If you say Y here, you will be able to choose a GID of whose users will
58298+ be unable to connect to other hosts from your machine or run server
58299+ applications from your machine. If the sysctl option is enabled, a
58300+ sysctl option with name "socket_all" is created.
58301+
58302+config GRKERNSEC_SOCKET_ALL_GID
58303+ int "GID to deny all sockets for"
58304+ depends on GRKERNSEC_SOCKET_ALL
58305+ default 1004
58306+ help
58307+ Here you can choose the GID to disable socket access for. Remember to
58308+ add the users you want socket access disabled for to the GID
58309+ specified here. If the sysctl option is enabled, a sysctl option
58310+ with name "socket_all_gid" is created.
58311+
58312+config GRKERNSEC_SOCKET_CLIENT
58313+ bool "Deny client sockets to group"
58314+ depends on GRKERNSEC_SOCKET
58315+ help
58316+ If you say Y here, you will be able to choose a GID of whose users will
58317+ be unable to connect to other hosts from your machine, but will be
58318+ able to run servers. If this option is enabled, all users in the group
58319+ you specify will have to use passive mode when initiating ftp transfers
58320+ from the shell on your machine. If the sysctl option is enabled, a
58321+ sysctl option with name "socket_client" is created.
58322+
58323+config GRKERNSEC_SOCKET_CLIENT_GID
58324+ int "GID to deny client sockets for"
58325+ depends on GRKERNSEC_SOCKET_CLIENT
58326+ default 1003
58327+ help
58328+ Here you can choose the GID to disable client socket access for.
58329+ Remember to add the users you want client socket access disabled for to
58330+ the GID specified here. If the sysctl option is enabled, a sysctl
58331+ option with name "socket_client_gid" is created.
58332+
58333+config GRKERNSEC_SOCKET_SERVER
58334+ bool "Deny server sockets to group"
58335+ depends on GRKERNSEC_SOCKET
58336+ help
58337+ If you say Y here, you will be able to choose a GID of whose users will
58338+ be unable to run server applications from your machine. If the sysctl
58339+ option is enabled, a sysctl option with name "socket_server" is created.
58340+
58341+config GRKERNSEC_SOCKET_SERVER_GID
58342+ int "GID to deny server sockets for"
58343+ depends on GRKERNSEC_SOCKET_SERVER
58344+ default 1002
58345+ help
58346+ Here you can choose the GID to disable server socket access for.
58347+ Remember to add the users you want server socket access disabled for to
58348+ the GID specified here. If the sysctl option is enabled, a sysctl
58349+ option with name "socket_server_gid" is created.
58350+
58351+endmenu
58352+menu "Sysctl Support"
58353+depends on GRKERNSEC && SYSCTL
58354+
58355+config GRKERNSEC_SYSCTL
58356+ bool "Sysctl support"
58357+ default y if GRKERNSEC_CONFIG_AUTO
58358+ help
58359+ If you say Y here, you will be able to change the options that
58360+ grsecurity runs with at bootup, without having to recompile your
58361+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58362+ to enable (1) or disable (0) various features. All the sysctl entries
58363+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58364+ All features enabled in the kernel configuration are disabled at boot
58365+ if you do not say Y to the "Turn on features by default" option.
58366+ All options should be set at startup, and the grsec_lock entry should
58367+ be set to a non-zero value after all the options are set.
58368+ *THIS IS EXTREMELY IMPORTANT*
58369+
58370+config GRKERNSEC_SYSCTL_DISTRO
58371+ bool "Extra sysctl support for distro makers (READ HELP)"
58372+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58373+ help
58374+ If you say Y here, additional sysctl options will be created
58375+ for features that affect processes running as root. Therefore,
58376+ it is critical when using this option that the grsec_lock entry be
58377+ enabled after boot. Only distros with prebuilt kernel packages
58378+ with this option enabled that can ensure grsec_lock is enabled
58379+ after boot should use this option.
58380+ *Failure to set grsec_lock after boot makes all grsec features
58381+ this option covers useless*
58382+
58383+ Currently this option creates the following sysctl entries:
58384+ "Disable Privileged I/O": "disable_priv_io"
58385+
58386+config GRKERNSEC_SYSCTL_ON
58387+ bool "Turn on features by default"
58388+ default y if GRKERNSEC_CONFIG_AUTO
58389+ depends on GRKERNSEC_SYSCTL
58390+ help
58391+ If you say Y here, instead of having all features enabled in the
58392+ kernel configuration disabled at boot time, the features will be
58393+ enabled at boot time. It is recommended you say Y here unless
58394+ there is some reason you would want all sysctl-tunable features to
58395+ be disabled by default. As mentioned elsewhere, it is important
58396+ to enable the grsec_lock entry once you have finished modifying
58397+ the sysctl entries.
58398+
58399+endmenu
58400+menu "Logging Options"
58401+depends on GRKERNSEC
58402+
58403+config GRKERNSEC_FLOODTIME
58404+ int "Seconds in between log messages (minimum)"
58405+ default 10
58406+ help
58407+ This option allows you to enforce the number of seconds between
58408+ grsecurity log messages. The default should be suitable for most
58409+ people, however, if you choose to change it, choose a value small enough
58410+ to allow informative logs to be produced, but large enough to
58411+ prevent flooding.
58412+
58413+config GRKERNSEC_FLOODBURST
58414+ int "Number of messages in a burst (maximum)"
58415+ default 6
58416+ help
58417+ This option allows you to choose the maximum number of messages allowed
58418+ within the flood time interval you chose in a separate option. The
58419+ default should be suitable for most people, however if you find that
58420+ many of your logs are being interpreted as flooding, you may want to
58421+ raise this value.
58422+
58423+endmenu
58424diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58425new file mode 100644
58426index 0000000..36845aa
58427--- /dev/null
58428+++ b/grsecurity/Makefile
58429@@ -0,0 +1,42 @@
58430+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58431+# during 2001-2009 it has been completely redesigned by Brad Spengler
58432+# into an RBAC system
58433+#
58434+# All code in this directory and various hooks inserted throughout the kernel
58435+# are copyright Brad Spengler - Open Source Security, Inc., and released
58436+# under the GPL v2 or higher
58437+
58438+KBUILD_CFLAGS += -Werror
58439+
58440+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58441+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58442+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58443+
58444+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58445+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58446+ gracl_learn.o grsec_log.o
58447+ifdef CONFIG_COMPAT
58448+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
58449+endif
58450+
58451+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58452+
58453+ifdef CONFIG_NET
58454+obj-y += grsec_sock.o
58455+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58456+endif
58457+
58458+ifndef CONFIG_GRKERNSEC
58459+obj-y += grsec_disabled.o
58460+endif
58461+
58462+ifdef CONFIG_GRKERNSEC_HIDESYM
58463+extra-y := grsec_hidesym.o
58464+$(obj)/grsec_hidesym.o:
58465+ @-chmod -f 500 /boot
58466+ @-chmod -f 500 /lib/modules
58467+ @-chmod -f 500 /lib64/modules
58468+ @-chmod -f 500 /lib32/modules
58469+ @-chmod -f 700 .
58470+ @echo ' grsec: protected kernel image paths'
58471+endif
58472diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58473new file mode 100644
58474index 0000000..c0793fd
58475--- /dev/null
58476+++ b/grsecurity/gracl.c
58477@@ -0,0 +1,4178 @@
58478+#include <linux/kernel.h>
58479+#include <linux/module.h>
58480+#include <linux/sched.h>
58481+#include <linux/mm.h>
58482+#include <linux/file.h>
58483+#include <linux/fs.h>
58484+#include <linux/namei.h>
58485+#include <linux/mount.h>
58486+#include <linux/tty.h>
58487+#include <linux/proc_fs.h>
58488+#include <linux/lglock.h>
58489+#include <linux/slab.h>
58490+#include <linux/vmalloc.h>
58491+#include <linux/types.h>
58492+#include <linux/sysctl.h>
58493+#include <linux/netdevice.h>
58494+#include <linux/ptrace.h>
58495+#include <linux/gracl.h>
58496+#include <linux/gralloc.h>
58497+#include <linux/security.h>
58498+#include <linux/grinternal.h>
58499+#include <linux/pid_namespace.h>
58500+#include <linux/stop_machine.h>
58501+#include <linux/fdtable.h>
58502+#include <linux/percpu.h>
58503+#include <linux/lglock.h>
58504+#include <linux/hugetlb.h>
58505+#include <linux/posix-timers.h>
58506+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58507+#include <linux/magic.h>
58508+#include <linux/pagemap.h>
58509+#include "../fs/btrfs/async-thread.h"
58510+#include "../fs/btrfs/ctree.h"
58511+#include "../fs/btrfs/btrfs_inode.h"
58512+#endif
58513+#include "../fs/mount.h"
58514+
58515+#include <asm/uaccess.h>
58516+#include <asm/errno.h>
58517+#include <asm/mman.h>
58518+
58519+extern struct lglock vfsmount_lock;
58520+
58521+static struct acl_role_db acl_role_set;
58522+static struct name_db name_set;
58523+static struct inodev_db inodev_set;
58524+
58525+/* for keeping track of userspace pointers used for subjects, so we
58526+ can share references in the kernel as well
58527+*/
58528+
58529+static struct path real_root;
58530+
58531+static struct acl_subj_map_db subj_map_set;
58532+
58533+static struct acl_role_label *default_role;
58534+
58535+static struct acl_role_label *role_list;
58536+
58537+static u16 acl_sp_role_value;
58538+
58539+extern char *gr_shared_page[4];
58540+static DEFINE_MUTEX(gr_dev_mutex);
58541+DEFINE_RWLOCK(gr_inode_lock);
58542+
58543+struct gr_arg *gr_usermode;
58544+
58545+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58546+
58547+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58548+extern void gr_clear_learn_entries(void);
58549+
58550+unsigned char *gr_system_salt;
58551+unsigned char *gr_system_sum;
58552+
58553+static struct sprole_pw **acl_special_roles = NULL;
58554+static __u16 num_sprole_pws = 0;
58555+
58556+static struct acl_role_label *kernel_role = NULL;
58557+
58558+static unsigned int gr_auth_attempts = 0;
58559+static unsigned long gr_auth_expires = 0UL;
58560+
58561+#ifdef CONFIG_NET
58562+extern struct vfsmount *sock_mnt;
58563+#endif
58564+
58565+extern struct vfsmount *pipe_mnt;
58566+extern struct vfsmount *shm_mnt;
58567+
58568+#ifdef CONFIG_HUGETLBFS
58569+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58570+#endif
58571+
58572+static struct acl_object_label *fakefs_obj_rw;
58573+static struct acl_object_label *fakefs_obj_rwx;
58574+
58575+extern int gr_init_uidset(void);
58576+extern void gr_free_uidset(void);
58577+extern void gr_remove_uid(uid_t uid);
58578+extern int gr_find_uid(uid_t uid);
58579+
58580+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
58581+{
58582+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
58583+ return -EFAULT;
58584+
58585+ return 0;
58586+}
58587+
58588+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
58589+{
58590+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
58591+ return -EFAULT;
58592+
58593+ return 0;
58594+}
58595+
58596+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
58597+{
58598+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
58599+ return -EFAULT;
58600+
58601+ return 0;
58602+}
58603+
58604+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
58605+{
58606+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
58607+ return -EFAULT;
58608+
58609+ return 0;
58610+}
58611+
58612+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
58613+{
58614+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
58615+ return -EFAULT;
58616+
58617+ return 0;
58618+}
58619+
58620+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
58621+{
58622+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
58623+ return -EFAULT;
58624+
58625+ return 0;
58626+}
58627+
58628+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
58629+{
58630+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
58631+ return -EFAULT;
58632+
58633+ return 0;
58634+}
58635+
58636+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
58637+{
58638+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
58639+ return -EFAULT;
58640+
58641+ return 0;
58642+}
58643+
58644+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
58645+{
58646+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
58647+ return -EFAULT;
58648+
58649+ return 0;
58650+}
58651+
58652+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
58653+{
58654+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
58655+ return -EFAULT;
58656+
58657+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
58658+ return -EINVAL;
58659+
58660+ return 0;
58661+}
58662+
58663+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
58664+{
58665+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
58666+ return -EFAULT;
58667+
58668+ return 0;
58669+}
58670+
58671+static size_t get_gr_arg_wrapper_size_normal(void)
58672+{
58673+ return sizeof(struct gr_arg_wrapper);
58674+}
58675+
58676+#ifdef CONFIG_COMPAT
58677+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
58678+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
58679+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
58680+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
58681+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
58682+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
58683+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
58684+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
58685+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
58686+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
58687+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
58688+extern size_t get_gr_arg_wrapper_size_compat(void);
58689+
58690+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
58691+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
58692+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
58693+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
58694+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
58695+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
58696+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
58697+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
58698+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
58699+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
58700+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
58701+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
58702+
58703+#else
58704+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
58705+#define copy_gr_arg copy_gr_arg_normal
58706+#define copy_gr_hash_struct copy_gr_hash_struct_normal
58707+#define copy_acl_object_label copy_acl_object_label_normal
58708+#define copy_acl_subject_label copy_acl_subject_label_normal
58709+#define copy_acl_role_label copy_acl_role_label_normal
58710+#define copy_acl_ip_label copy_acl_ip_label_normal
58711+#define copy_pointer_from_array copy_pointer_from_array_normal
58712+#define copy_sprole_pw copy_sprole_pw_normal
58713+#define copy_role_transition copy_role_transition_normal
58714+#define copy_role_allowed_ip copy_role_allowed_ip_normal
58715+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
58716+#endif
58717+
58718+__inline__ int
58719+gr_acl_is_enabled(void)
58720+{
58721+ return (gr_status & GR_READY);
58722+}
58723+
58724+static inline dev_t __get_dev(const struct dentry *dentry)
58725+{
58726+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58727+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
58728+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
58729+ else
58730+#endif
58731+ return dentry->d_sb->s_dev;
58732+}
58733+
58734+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58735+{
58736+ return __get_dev(dentry);
58737+}
58738+
58739+static char gr_task_roletype_to_char(struct task_struct *task)
58740+{
58741+ switch (task->role->roletype &
58742+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58743+ GR_ROLE_SPECIAL)) {
58744+ case GR_ROLE_DEFAULT:
58745+ return 'D';
58746+ case GR_ROLE_USER:
58747+ return 'U';
58748+ case GR_ROLE_GROUP:
58749+ return 'G';
58750+ case GR_ROLE_SPECIAL:
58751+ return 'S';
58752+ }
58753+
58754+ return 'X';
58755+}
58756+
58757+char gr_roletype_to_char(void)
58758+{
58759+ return gr_task_roletype_to_char(current);
58760+}
58761+
58762+__inline__ int
58763+gr_acl_tpe_check(void)
58764+{
58765+ if (unlikely(!(gr_status & GR_READY)))
58766+ return 0;
58767+ if (current->role->roletype & GR_ROLE_TPE)
58768+ return 1;
58769+ else
58770+ return 0;
58771+}
58772+
58773+int
58774+gr_handle_rawio(const struct inode *inode)
58775+{
58776+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58777+ if (inode && S_ISBLK(inode->i_mode) &&
58778+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58779+ !capable(CAP_SYS_RAWIO))
58780+ return 1;
58781+#endif
58782+ return 0;
58783+}
58784+
58785+static int
58786+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58787+{
58788+ if (likely(lena != lenb))
58789+ return 0;
58790+
58791+ return !memcmp(a, b, lena);
58792+}
58793+
58794+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58795+{
58796+ *buflen -= namelen;
58797+ if (*buflen < 0)
58798+ return -ENAMETOOLONG;
58799+ *buffer -= namelen;
58800+ memcpy(*buffer, str, namelen);
58801+ return 0;
58802+}
58803+
58804+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58805+{
58806+ return prepend(buffer, buflen, name->name, name->len);
58807+}
58808+
58809+static int prepend_path(const struct path *path, struct path *root,
58810+ char **buffer, int *buflen)
58811+{
58812+ struct dentry *dentry = path->dentry;
58813+ struct vfsmount *vfsmnt = path->mnt;
58814+ struct mount *mnt = real_mount(vfsmnt);
58815+ bool slash = false;
58816+ int error = 0;
58817+
58818+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58819+ struct dentry * parent;
58820+
58821+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58822+ /* Global root? */
58823+ if (!mnt_has_parent(mnt)) {
58824+ goto out;
58825+ }
58826+ dentry = mnt->mnt_mountpoint;
58827+ mnt = mnt->mnt_parent;
58828+ vfsmnt = &mnt->mnt;
58829+ continue;
58830+ }
58831+ parent = dentry->d_parent;
58832+ prefetch(parent);
58833+ spin_lock(&dentry->d_lock);
58834+ error = prepend_name(buffer, buflen, &dentry->d_name);
58835+ spin_unlock(&dentry->d_lock);
58836+ if (!error)
58837+ error = prepend(buffer, buflen, "/", 1);
58838+ if (error)
58839+ break;
58840+
58841+ slash = true;
58842+ dentry = parent;
58843+ }
58844+
58845+out:
58846+ if (!error && !slash)
58847+ error = prepend(buffer, buflen, "/", 1);
58848+
58849+ return error;
58850+}
58851+
58852+/* this must be called with vfsmount_lock and rename_lock held */
58853+
58854+static char *__our_d_path(const struct path *path, struct path *root,
58855+ char *buf, int buflen)
58856+{
58857+ char *res = buf + buflen;
58858+ int error;
58859+
58860+ prepend(&res, &buflen, "\0", 1);
58861+ error = prepend_path(path, root, &res, &buflen);
58862+ if (error)
58863+ return ERR_PTR(error);
58864+
58865+ return res;
58866+}
58867+
58868+static char *
58869+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58870+{
58871+ char *retval;
58872+
58873+ retval = __our_d_path(path, root, buf, buflen);
58874+ if (unlikely(IS_ERR(retval)))
58875+ retval = strcpy(buf, "<path too long>");
58876+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58877+ retval[1] = '\0';
58878+
58879+ return retval;
58880+}
58881+
58882+static char *
58883+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58884+ char *buf, int buflen)
58885+{
58886+ struct path path;
58887+ char *res;
58888+
58889+ path.dentry = (struct dentry *)dentry;
58890+ path.mnt = (struct vfsmount *)vfsmnt;
58891+
58892+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58893+ by the RBAC system */
58894+ res = gen_full_path(&path, &real_root, buf, buflen);
58895+
58896+ return res;
58897+}
58898+
58899+static char *
58900+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58901+ char *buf, int buflen)
58902+{
58903+ char *res;
58904+ struct path path;
58905+ struct path root;
58906+ struct task_struct *reaper = init_pid_ns.child_reaper;
58907+
58908+ path.dentry = (struct dentry *)dentry;
58909+ path.mnt = (struct vfsmount *)vfsmnt;
58910+
58911+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58912+ get_fs_root(reaper->fs, &root);
58913+
58914+ br_read_lock(&vfsmount_lock);
58915+ write_seqlock(&rename_lock);
58916+ res = gen_full_path(&path, &root, buf, buflen);
58917+ write_sequnlock(&rename_lock);
58918+ br_read_unlock(&vfsmount_lock);
58919+
58920+ path_put(&root);
58921+ return res;
58922+}
58923+
58924+static char *
58925+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58926+{
58927+ char *ret;
58928+ br_read_lock(&vfsmount_lock);
58929+ write_seqlock(&rename_lock);
58930+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58931+ PAGE_SIZE);
58932+ write_sequnlock(&rename_lock);
58933+ br_read_unlock(&vfsmount_lock);
58934+ return ret;
58935+}
58936+
58937+static char *
58938+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58939+{
58940+ char *ret;
58941+ char *buf;
58942+ int buflen;
58943+
58944+ br_read_lock(&vfsmount_lock);
58945+ write_seqlock(&rename_lock);
58946+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58947+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58948+ buflen = (int)(ret - buf);
58949+ if (buflen >= 5)
58950+ prepend(&ret, &buflen, "/proc", 5);
58951+ else
58952+ ret = strcpy(buf, "<path too long>");
58953+ write_sequnlock(&rename_lock);
58954+ br_read_unlock(&vfsmount_lock);
58955+ return ret;
58956+}
58957+
58958+char *
58959+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58960+{
58961+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58962+ PAGE_SIZE);
58963+}
58964+
58965+char *
58966+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58967+{
58968+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58969+ PAGE_SIZE);
58970+}
58971+
58972+char *
58973+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58974+{
58975+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58976+ PAGE_SIZE);
58977+}
58978+
58979+char *
58980+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58981+{
58982+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58983+ PAGE_SIZE);
58984+}
58985+
58986+char *
58987+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58988+{
58989+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58990+ PAGE_SIZE);
58991+}
58992+
58993+__inline__ __u32
58994+to_gr_audit(const __u32 reqmode)
58995+{
58996+ /* masks off auditable permission flags, then shifts them to create
58997+ auditing flags, and adds the special case of append auditing if
58998+ we're requesting write */
58999+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
59000+}
59001+
59002+struct acl_subject_label *
59003+lookup_subject_map(const struct acl_subject_label *userp)
59004+{
59005+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
59006+ struct subject_map *match;
59007+
59008+ match = subj_map_set.s_hash[index];
59009+
59010+ while (match && match->user != userp)
59011+ match = match->next;
59012+
59013+ if (match != NULL)
59014+ return match->kernel;
59015+ else
59016+ return NULL;
59017+}
59018+
59019+static void
59020+insert_subj_map_entry(struct subject_map *subjmap)
59021+{
59022+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
59023+ struct subject_map **curr;
59024+
59025+ subjmap->prev = NULL;
59026+
59027+ curr = &subj_map_set.s_hash[index];
59028+ if (*curr != NULL)
59029+ (*curr)->prev = subjmap;
59030+
59031+ subjmap->next = *curr;
59032+ *curr = subjmap;
59033+
59034+ return;
59035+}
59036+
59037+static struct acl_role_label *
59038+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
59039+ const gid_t gid)
59040+{
59041+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
59042+ struct acl_role_label *match;
59043+ struct role_allowed_ip *ipp;
59044+ unsigned int x;
59045+ u32 curr_ip = task->signal->curr_ip;
59046+
59047+ task->signal->saved_ip = curr_ip;
59048+
59049+ match = acl_role_set.r_hash[index];
59050+
59051+ while (match) {
59052+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
59053+ for (x = 0; x < match->domain_child_num; x++) {
59054+ if (match->domain_children[x] == uid)
59055+ goto found;
59056+ }
59057+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
59058+ break;
59059+ match = match->next;
59060+ }
59061+found:
59062+ if (match == NULL) {
59063+ try_group:
59064+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
59065+ match = acl_role_set.r_hash[index];
59066+
59067+ while (match) {
59068+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
59069+ for (x = 0; x < match->domain_child_num; x++) {
59070+ if (match->domain_children[x] == gid)
59071+ goto found2;
59072+ }
59073+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
59074+ break;
59075+ match = match->next;
59076+ }
59077+found2:
59078+ if (match == NULL)
59079+ match = default_role;
59080+ if (match->allowed_ips == NULL)
59081+ return match;
59082+ else {
59083+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
59084+ if (likely
59085+ ((ntohl(curr_ip) & ipp->netmask) ==
59086+ (ntohl(ipp->addr) & ipp->netmask)))
59087+ return match;
59088+ }
59089+ match = default_role;
59090+ }
59091+ } else if (match->allowed_ips == NULL) {
59092+ return match;
59093+ } else {
59094+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
59095+ if (likely
59096+ ((ntohl(curr_ip) & ipp->netmask) ==
59097+ (ntohl(ipp->addr) & ipp->netmask)))
59098+ return match;
59099+ }
59100+ goto try_group;
59101+ }
59102+
59103+ return match;
59104+}
59105+
59106+struct acl_subject_label *
59107+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
59108+ const struct acl_role_label *role)
59109+{
59110+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
59111+ struct acl_subject_label *match;
59112+
59113+ match = role->subj_hash[index];
59114+
59115+ while (match && (match->inode != ino || match->device != dev ||
59116+ (match->mode & GR_DELETED))) {
59117+ match = match->next;
59118+ }
59119+
59120+ if (match && !(match->mode & GR_DELETED))
59121+ return match;
59122+ else
59123+ return NULL;
59124+}
59125+
59126+struct acl_subject_label *
59127+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
59128+ const struct acl_role_label *role)
59129+{
59130+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
59131+ struct acl_subject_label *match;
59132+
59133+ match = role->subj_hash[index];
59134+
59135+ while (match && (match->inode != ino || match->device != dev ||
59136+ !(match->mode & GR_DELETED))) {
59137+ match = match->next;
59138+ }
59139+
59140+ if (match && (match->mode & GR_DELETED))
59141+ return match;
59142+ else
59143+ return NULL;
59144+}
59145+
59146+static struct acl_object_label *
59147+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
59148+ const struct acl_subject_label *subj)
59149+{
59150+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
59151+ struct acl_object_label *match;
59152+
59153+ match = subj->obj_hash[index];
59154+
59155+ while (match && (match->inode != ino || match->device != dev ||
59156+ (match->mode & GR_DELETED))) {
59157+ match = match->next;
59158+ }
59159+
59160+ if (match && !(match->mode & GR_DELETED))
59161+ return match;
59162+ else
59163+ return NULL;
59164+}
59165+
59166+static struct acl_object_label *
59167+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
59168+ const struct acl_subject_label *subj)
59169+{
59170+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
59171+ struct acl_object_label *match;
59172+
59173+ match = subj->obj_hash[index];
59174+
59175+ while (match && (match->inode != ino || match->device != dev ||
59176+ !(match->mode & GR_DELETED))) {
59177+ match = match->next;
59178+ }
59179+
59180+ if (match && (match->mode & GR_DELETED))
59181+ return match;
59182+
59183+ match = subj->obj_hash[index];
59184+
59185+ while (match && (match->inode != ino || match->device != dev ||
59186+ (match->mode & GR_DELETED))) {
59187+ match = match->next;
59188+ }
59189+
59190+ if (match && !(match->mode & GR_DELETED))
59191+ return match;
59192+ else
59193+ return NULL;
59194+}
59195+
59196+static struct name_entry *
59197+lookup_name_entry(const char *name)
59198+{
59199+ unsigned int len = strlen(name);
59200+ unsigned int key = full_name_hash(name, len);
59201+ unsigned int index = key % name_set.n_size;
59202+ struct name_entry *match;
59203+
59204+ match = name_set.n_hash[index];
59205+
59206+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
59207+ match = match->next;
59208+
59209+ return match;
59210+}
59211+
59212+static struct name_entry *
59213+lookup_name_entry_create(const char *name)
59214+{
59215+ unsigned int len = strlen(name);
59216+ unsigned int key = full_name_hash(name, len);
59217+ unsigned int index = key % name_set.n_size;
59218+ struct name_entry *match;
59219+
59220+ match = name_set.n_hash[index];
59221+
59222+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
59223+ !match->deleted))
59224+ match = match->next;
59225+
59226+ if (match && match->deleted)
59227+ return match;
59228+
59229+ match = name_set.n_hash[index];
59230+
59231+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
59232+ match->deleted))
59233+ match = match->next;
59234+
59235+ if (match && !match->deleted)
59236+ return match;
59237+ else
59238+ return NULL;
59239+}
59240+
59241+static struct inodev_entry *
59242+lookup_inodev_entry(const ino_t ino, const dev_t dev)
59243+{
59244+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
59245+ struct inodev_entry *match;
59246+
59247+ match = inodev_set.i_hash[index];
59248+
59249+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
59250+ match = match->next;
59251+
59252+ return match;
59253+}
59254+
59255+static void
59256+insert_inodev_entry(struct inodev_entry *entry)
59257+{
59258+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
59259+ inodev_set.i_size);
59260+ struct inodev_entry **curr;
59261+
59262+ entry->prev = NULL;
59263+
59264+ curr = &inodev_set.i_hash[index];
59265+ if (*curr != NULL)
59266+ (*curr)->prev = entry;
59267+
59268+ entry->next = *curr;
59269+ *curr = entry;
59270+
59271+ return;
59272+}
59273+
59274+static void
59275+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
59276+{
59277+ unsigned int index =
59278+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
59279+ struct acl_role_label **curr;
59280+ struct acl_role_label *tmp, *tmp2;
59281+
59282+ curr = &acl_role_set.r_hash[index];
59283+
59284+ /* simple case, slot is empty, just set it to our role */
59285+ if (*curr == NULL) {
59286+ *curr = role;
59287+ } else {
59288+ /* example:
59289+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
59290+ 2 -> 3
59291+ */
59292+ /* first check to see if we can already be reached via this slot */
59293+ tmp = *curr;
59294+ while (tmp && tmp != role)
59295+ tmp = tmp->next;
59296+ if (tmp == role) {
59297+ /* we don't need to add ourselves to this slot's chain */
59298+ return;
59299+ }
59300+ /* we need to add ourselves to this chain, two cases */
59301+ if (role->next == NULL) {
59302+ /* simple case, append the current chain to our role */
59303+ role->next = *curr;
59304+ *curr = role;
59305+ } else {
59306+ /* 1 -> 2 -> 3 -> 4
59307+ 2 -> 3 -> 4
59308+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
59309+ */
59310+ /* trickier case: walk our role's chain until we find
59311+ the role for the start of the current slot's chain */
59312+ tmp = role;
59313+ tmp2 = *curr;
59314+ while (tmp->next && tmp->next != tmp2)
59315+ tmp = tmp->next;
59316+ if (tmp->next == tmp2) {
59317+ /* from example above, we found 3, so just
59318+ replace this slot's chain with ours */
59319+ *curr = role;
59320+ } else {
59321+ /* we didn't find a subset of our role's chain
59322+ in the current slot's chain, so append their
59323+ chain to ours, and set us as the first role in
59324+ the slot's chain
59325+
59326+ we could fold this case with the case above,
59327+ but making it explicit for clarity
59328+ */
59329+ tmp->next = tmp2;
59330+ *curr = role;
59331+ }
59332+ }
59333+ }
59334+
59335+ return;
59336+}
59337+
59338+static void
59339+insert_acl_role_label(struct acl_role_label *role)
59340+{
59341+ int i;
59342+
59343+ if (role_list == NULL) {
59344+ role_list = role;
59345+ role->prev = NULL;
59346+ } else {
59347+ role->prev = role_list;
59348+ role_list = role;
59349+ }
59350+
59351+ /* used for hash chains */
59352+ role->next = NULL;
59353+
59354+ if (role->roletype & GR_ROLE_DOMAIN) {
59355+ for (i = 0; i < role->domain_child_num; i++)
59356+ __insert_acl_role_label(role, role->domain_children[i]);
59357+ } else
59358+ __insert_acl_role_label(role, role->uidgid);
59359+}
59360+
59361+static int
59362+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
59363+{
59364+ struct name_entry **curr, *nentry;
59365+ struct inodev_entry *ientry;
59366+ unsigned int len = strlen(name);
59367+ unsigned int key = full_name_hash(name, len);
59368+ unsigned int index = key % name_set.n_size;
59369+
59370+ curr = &name_set.n_hash[index];
59371+
59372+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
59373+ curr = &((*curr)->next);
59374+
59375+ if (*curr != NULL)
59376+ return 1;
59377+
59378+ nentry = acl_alloc(sizeof (struct name_entry));
59379+ if (nentry == NULL)
59380+ return 0;
59381+ ientry = acl_alloc(sizeof (struct inodev_entry));
59382+ if (ientry == NULL)
59383+ return 0;
59384+ ientry->nentry = nentry;
59385+
59386+ nentry->key = key;
59387+ nentry->name = name;
59388+ nentry->inode = inode;
59389+ nentry->device = device;
59390+ nentry->len = len;
59391+ nentry->deleted = deleted;
59392+
59393+ nentry->prev = NULL;
59394+ curr = &name_set.n_hash[index];
59395+ if (*curr != NULL)
59396+ (*curr)->prev = nentry;
59397+ nentry->next = *curr;
59398+ *curr = nentry;
59399+
59400+ /* insert us into the table searchable by inode/dev */
59401+ insert_inodev_entry(ientry);
59402+
59403+ return 1;
59404+}
59405+
59406+static void
59407+insert_acl_obj_label(struct acl_object_label *obj,
59408+ struct acl_subject_label *subj)
59409+{
59410+ unsigned int index =
59411+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
59412+ struct acl_object_label **curr;
59413+
59414+
59415+ obj->prev = NULL;
59416+
59417+ curr = &subj->obj_hash[index];
59418+ if (*curr != NULL)
59419+ (*curr)->prev = obj;
59420+
59421+ obj->next = *curr;
59422+ *curr = obj;
59423+
59424+ return;
59425+}
59426+
59427+static void
59428+insert_acl_subj_label(struct acl_subject_label *obj,
59429+ struct acl_role_label *role)
59430+{
59431+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
59432+ struct acl_subject_label **curr;
59433+
59434+ obj->prev = NULL;
59435+
59436+ curr = &role->subj_hash[index];
59437+ if (*curr != NULL)
59438+ (*curr)->prev = obj;
59439+
59440+ obj->next = *curr;
59441+ *curr = obj;
59442+
59443+ return;
59444+}
59445+
59446+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59447+
59448+static void *
59449+create_table(__u32 * len, int elementsize)
59450+{
59451+ unsigned int table_sizes[] = {
59452+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59453+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59454+ 4194301, 8388593, 16777213, 33554393, 67108859
59455+ };
59456+ void *newtable = NULL;
59457+ unsigned int pwr = 0;
59458+
59459+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59460+ table_sizes[pwr] <= *len)
59461+ pwr++;
59462+
59463+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59464+ return newtable;
59465+
59466+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59467+ newtable =
59468+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59469+ else
59470+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59471+
59472+ *len = table_sizes[pwr];
59473+
59474+ return newtable;
59475+}
59476+
59477+static int
59478+init_variables(const struct gr_arg *arg)
59479+{
59480+ struct task_struct *reaper = init_pid_ns.child_reaper;
59481+ unsigned int stacksize;
59482+
59483+ subj_map_set.s_size = arg->role_db.num_subjects;
59484+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59485+ name_set.n_size = arg->role_db.num_objects;
59486+ inodev_set.i_size = arg->role_db.num_objects;
59487+
59488+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59489+ !name_set.n_size || !inodev_set.i_size)
59490+ return 1;
59491+
59492+ if (!gr_init_uidset())
59493+ return 1;
59494+
59495+ /* set up the stack that holds allocation info */
59496+
59497+ stacksize = arg->role_db.num_pointers + 5;
59498+
59499+ if (!acl_alloc_stack_init(stacksize))
59500+ return 1;
59501+
59502+ /* grab reference for the real root dentry and vfsmount */
59503+ get_fs_root(reaper->fs, &real_root);
59504+
59505+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59506+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59507+#endif
59508+
59509+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59510+ if (fakefs_obj_rw == NULL)
59511+ return 1;
59512+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59513+
59514+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59515+ if (fakefs_obj_rwx == NULL)
59516+ return 1;
59517+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59518+
59519+ subj_map_set.s_hash =
59520+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59521+ acl_role_set.r_hash =
59522+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59523+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59524+ inodev_set.i_hash =
59525+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59526+
59527+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59528+ !name_set.n_hash || !inodev_set.i_hash)
59529+ return 1;
59530+
59531+ memset(subj_map_set.s_hash, 0,
59532+ sizeof(struct subject_map *) * subj_map_set.s_size);
59533+ memset(acl_role_set.r_hash, 0,
59534+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59535+ memset(name_set.n_hash, 0,
59536+ sizeof (struct name_entry *) * name_set.n_size);
59537+ memset(inodev_set.i_hash, 0,
59538+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59539+
59540+ return 0;
59541+}
59542+
59543+/* free information not needed after startup
59544+ currently contains user->kernel pointer mappings for subjects
59545+*/
59546+
59547+static void
59548+free_init_variables(void)
59549+{
59550+ __u32 i;
59551+
59552+ if (subj_map_set.s_hash) {
59553+ for (i = 0; i < subj_map_set.s_size; i++) {
59554+ if (subj_map_set.s_hash[i]) {
59555+ kfree(subj_map_set.s_hash[i]);
59556+ subj_map_set.s_hash[i] = NULL;
59557+ }
59558+ }
59559+
59560+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59561+ PAGE_SIZE)
59562+ kfree(subj_map_set.s_hash);
59563+ else
59564+ vfree(subj_map_set.s_hash);
59565+ }
59566+
59567+ return;
59568+}
59569+
59570+static void
59571+free_variables(void)
59572+{
59573+ struct acl_subject_label *s;
59574+ struct acl_role_label *r;
59575+ struct task_struct *task, *task2;
59576+ unsigned int x;
59577+
59578+ gr_clear_learn_entries();
59579+
59580+ read_lock(&tasklist_lock);
59581+ do_each_thread(task2, task) {
59582+ task->acl_sp_role = 0;
59583+ task->acl_role_id = 0;
59584+ task->acl = NULL;
59585+ task->role = NULL;
59586+ } while_each_thread(task2, task);
59587+ read_unlock(&tasklist_lock);
59588+
59589+ /* release the reference to the real root dentry and vfsmount */
59590+ path_put(&real_root);
59591+ memset(&real_root, 0, sizeof(real_root));
59592+
59593+ /* free all object hash tables */
59594+
59595+ FOR_EACH_ROLE_START(r)
59596+ if (r->subj_hash == NULL)
59597+ goto next_role;
59598+ FOR_EACH_SUBJECT_START(r, s, x)
59599+ if (s->obj_hash == NULL)
59600+ break;
59601+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59602+ kfree(s->obj_hash);
59603+ else
59604+ vfree(s->obj_hash);
59605+ FOR_EACH_SUBJECT_END(s, x)
59606+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59607+ if (s->obj_hash == NULL)
59608+ break;
59609+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59610+ kfree(s->obj_hash);
59611+ else
59612+ vfree(s->obj_hash);
59613+ FOR_EACH_NESTED_SUBJECT_END(s)
59614+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59615+ kfree(r->subj_hash);
59616+ else
59617+ vfree(r->subj_hash);
59618+ r->subj_hash = NULL;
59619+next_role:
59620+ FOR_EACH_ROLE_END(r)
59621+
59622+ acl_free_all();
59623+
59624+ if (acl_role_set.r_hash) {
59625+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59626+ PAGE_SIZE)
59627+ kfree(acl_role_set.r_hash);
59628+ else
59629+ vfree(acl_role_set.r_hash);
59630+ }
59631+ if (name_set.n_hash) {
59632+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59633+ PAGE_SIZE)
59634+ kfree(name_set.n_hash);
59635+ else
59636+ vfree(name_set.n_hash);
59637+ }
59638+
59639+ if (inodev_set.i_hash) {
59640+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59641+ PAGE_SIZE)
59642+ kfree(inodev_set.i_hash);
59643+ else
59644+ vfree(inodev_set.i_hash);
59645+ }
59646+
59647+ gr_free_uidset();
59648+
59649+ memset(&name_set, 0, sizeof (struct name_db));
59650+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59651+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59652+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59653+
59654+ default_role = NULL;
59655+ kernel_role = NULL;
59656+ role_list = NULL;
59657+
59658+ return;
59659+}
59660+
59661+static struct acl_subject_label *
59662+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59663+
59664+static int alloc_and_copy_string(char **name, unsigned int maxlen)
59665+{
59666+ unsigned int len = strnlen_user(*name, maxlen);
59667+ char *tmp;
59668+
59669+ if (!len || len >= maxlen)
59670+ return -EINVAL;
59671+
59672+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59673+ return -ENOMEM;
59674+
59675+ if (copy_from_user(tmp, *name, len))
59676+ return -EFAULT;
59677+
59678+ tmp[len-1] = '\0';
59679+ *name = tmp;
59680+
59681+ return 0;
59682+}
59683+
59684+static int
59685+copy_user_glob(struct acl_object_label *obj)
59686+{
59687+ struct acl_object_label *g_tmp, **guser;
59688+ int error;
59689+
59690+ if (obj->globbed == NULL)
59691+ return 0;
59692+
59693+ guser = &obj->globbed;
59694+ while (*guser) {
59695+ g_tmp = (struct acl_object_label *)
59696+ acl_alloc(sizeof (struct acl_object_label));
59697+ if (g_tmp == NULL)
59698+ return -ENOMEM;
59699+
59700+ if (copy_acl_object_label(g_tmp, *guser))
59701+ return -EFAULT;
59702+
59703+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
59704+ if (error)
59705+ return error;
59706+
59707+ *guser = g_tmp;
59708+ guser = &(g_tmp->next);
59709+ }
59710+
59711+ return 0;
59712+}
59713+
59714+static int
59715+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59716+ struct acl_role_label *role)
59717+{
59718+ struct acl_object_label *o_tmp;
59719+ int ret;
59720+
59721+ while (userp) {
59722+ if ((o_tmp = (struct acl_object_label *)
59723+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59724+ return -ENOMEM;
59725+
59726+ if (copy_acl_object_label(o_tmp, userp))
59727+ return -EFAULT;
59728+
59729+ userp = o_tmp->prev;
59730+
59731+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
59732+ if (ret)
59733+ return ret;
59734+
59735+ insert_acl_obj_label(o_tmp, subj);
59736+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59737+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59738+ return -ENOMEM;
59739+
59740+ ret = copy_user_glob(o_tmp);
59741+ if (ret)
59742+ return ret;
59743+
59744+ if (o_tmp->nested) {
59745+ int already_copied;
59746+
59747+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59748+ if (IS_ERR(o_tmp->nested))
59749+ return PTR_ERR(o_tmp->nested);
59750+
59751+ /* insert into nested subject list if we haven't copied this one yet
59752+ to prevent duplicate entries */
59753+ if (!already_copied) {
59754+ o_tmp->nested->next = role->hash->first;
59755+ role->hash->first = o_tmp->nested;
59756+ }
59757+ }
59758+ }
59759+
59760+ return 0;
59761+}
59762+
59763+static __u32
59764+count_user_subjs(struct acl_subject_label *userp)
59765+{
59766+ struct acl_subject_label s_tmp;
59767+ __u32 num = 0;
59768+
59769+ while (userp) {
59770+ if (copy_acl_subject_label(&s_tmp, userp))
59771+ break;
59772+
59773+ userp = s_tmp.prev;
59774+ }
59775+
59776+ return num;
59777+}
59778+
59779+static int
59780+copy_user_allowedips(struct acl_role_label *rolep)
59781+{
59782+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59783+
59784+ ruserip = rolep->allowed_ips;
59785+
59786+ while (ruserip) {
59787+ rlast = rtmp;
59788+
59789+ if ((rtmp = (struct role_allowed_ip *)
59790+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59791+ return -ENOMEM;
59792+
59793+ if (copy_role_allowed_ip(rtmp, ruserip))
59794+ return -EFAULT;
59795+
59796+ ruserip = rtmp->prev;
59797+
59798+ if (!rlast) {
59799+ rtmp->prev = NULL;
59800+ rolep->allowed_ips = rtmp;
59801+ } else {
59802+ rlast->next = rtmp;
59803+ rtmp->prev = rlast;
59804+ }
59805+
59806+ if (!ruserip)
59807+ rtmp->next = NULL;
59808+ }
59809+
59810+ return 0;
59811+}
59812+
59813+static int
59814+copy_user_transitions(struct acl_role_label *rolep)
59815+{
59816+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59817+ int error;
59818+
59819+ rusertp = rolep->transitions;
59820+
59821+ while (rusertp) {
59822+ rlast = rtmp;
59823+
59824+ if ((rtmp = (struct role_transition *)
59825+ acl_alloc(sizeof (struct role_transition))) == NULL)
59826+ return -ENOMEM;
59827+
59828+ if (copy_role_transition(rtmp, rusertp))
59829+ return -EFAULT;
59830+
59831+ rusertp = rtmp->prev;
59832+
59833+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
59834+ if (error)
59835+ return error;
59836+
59837+ if (!rlast) {
59838+ rtmp->prev = NULL;
59839+ rolep->transitions = rtmp;
59840+ } else {
59841+ rlast->next = rtmp;
59842+ rtmp->prev = rlast;
59843+ }
59844+
59845+ if (!rusertp)
59846+ rtmp->next = NULL;
59847+ }
59848+
59849+ return 0;
59850+}
59851+
59852+static __u32 count_user_objs(const struct acl_object_label __user *userp)
59853+{
59854+ struct acl_object_label o_tmp;
59855+ __u32 num = 0;
59856+
59857+ while (userp) {
59858+ if (copy_acl_object_label(&o_tmp, userp))
59859+ break;
59860+
59861+ userp = o_tmp.prev;
59862+ num++;
59863+ }
59864+
59865+ return num;
59866+}
59867+
59868+static struct acl_subject_label *
59869+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59870+{
59871+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59872+ __u32 num_objs;
59873+ struct acl_ip_label **i_tmp, *i_utmp2;
59874+ struct gr_hash_struct ghash;
59875+ struct subject_map *subjmap;
59876+ unsigned int i_num;
59877+ int err;
59878+
59879+ if (already_copied != NULL)
59880+ *already_copied = 0;
59881+
59882+ s_tmp = lookup_subject_map(userp);
59883+
59884+ /* we've already copied this subject into the kernel, just return
59885+ the reference to it, and don't copy it over again
59886+ */
59887+ if (s_tmp) {
59888+ if (already_copied != NULL)
59889+ *already_copied = 1;
59890+ return(s_tmp);
59891+ }
59892+
59893+ if ((s_tmp = (struct acl_subject_label *)
59894+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59895+ return ERR_PTR(-ENOMEM);
59896+
59897+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59898+ if (subjmap == NULL)
59899+ return ERR_PTR(-ENOMEM);
59900+
59901+ subjmap->user = userp;
59902+ subjmap->kernel = s_tmp;
59903+ insert_subj_map_entry(subjmap);
59904+
59905+ if (copy_acl_subject_label(s_tmp, userp))
59906+ return ERR_PTR(-EFAULT);
59907+
59908+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
59909+ if (err)
59910+ return ERR_PTR(err);
59911+
59912+ if (!strcmp(s_tmp->filename, "/"))
59913+ role->root_label = s_tmp;
59914+
59915+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
59916+ return ERR_PTR(-EFAULT);
59917+
59918+ /* copy user and group transition tables */
59919+
59920+ if (s_tmp->user_trans_num) {
59921+ uid_t *uidlist;
59922+
59923+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59924+ if (uidlist == NULL)
59925+ return ERR_PTR(-ENOMEM);
59926+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59927+ return ERR_PTR(-EFAULT);
59928+
59929+ s_tmp->user_transitions = uidlist;
59930+ }
59931+
59932+ if (s_tmp->group_trans_num) {
59933+ gid_t *gidlist;
59934+
59935+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59936+ if (gidlist == NULL)
59937+ return ERR_PTR(-ENOMEM);
59938+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59939+ return ERR_PTR(-EFAULT);
59940+
59941+ s_tmp->group_transitions = gidlist;
59942+ }
59943+
59944+ /* set up object hash table */
59945+ num_objs = count_user_objs(ghash.first);
59946+
59947+ s_tmp->obj_hash_size = num_objs;
59948+ s_tmp->obj_hash =
59949+ (struct acl_object_label **)
59950+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59951+
59952+ if (!s_tmp->obj_hash)
59953+ return ERR_PTR(-ENOMEM);
59954+
59955+ memset(s_tmp->obj_hash, 0,
59956+ s_tmp->obj_hash_size *
59957+ sizeof (struct acl_object_label *));
59958+
59959+ /* add in objects */
59960+ err = copy_user_objs(ghash.first, s_tmp, role);
59961+
59962+ if (err)
59963+ return ERR_PTR(err);
59964+
59965+ /* set pointer for parent subject */
59966+ if (s_tmp->parent_subject) {
59967+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59968+
59969+ if (IS_ERR(s_tmp2))
59970+ return s_tmp2;
59971+
59972+ s_tmp->parent_subject = s_tmp2;
59973+ }
59974+
59975+ /* add in ip acls */
59976+
59977+ if (!s_tmp->ip_num) {
59978+ s_tmp->ips = NULL;
59979+ goto insert;
59980+ }
59981+
59982+ i_tmp =
59983+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59984+ sizeof (struct acl_ip_label *));
59985+
59986+ if (!i_tmp)
59987+ return ERR_PTR(-ENOMEM);
59988+
59989+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59990+ *(i_tmp + i_num) =
59991+ (struct acl_ip_label *)
59992+ acl_alloc(sizeof (struct acl_ip_label));
59993+ if (!*(i_tmp + i_num))
59994+ return ERR_PTR(-ENOMEM);
59995+
59996+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
59997+ return ERR_PTR(-EFAULT);
59998+
59999+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
60000+ return ERR_PTR(-EFAULT);
60001+
60002+ if ((*(i_tmp + i_num))->iface == NULL)
60003+ continue;
60004+
60005+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
60006+ if (err)
60007+ return ERR_PTR(err);
60008+ }
60009+
60010+ s_tmp->ips = i_tmp;
60011+
60012+insert:
60013+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
60014+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
60015+ return ERR_PTR(-ENOMEM);
60016+
60017+ return s_tmp;
60018+}
60019+
60020+static int
60021+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
60022+{
60023+ struct acl_subject_label s_pre;
60024+ struct acl_subject_label * ret;
60025+ int err;
60026+
60027+ while (userp) {
60028+ if (copy_acl_subject_label(&s_pre, userp))
60029+ return -EFAULT;
60030+
60031+ ret = do_copy_user_subj(userp, role, NULL);
60032+
60033+ err = PTR_ERR(ret);
60034+ if (IS_ERR(ret))
60035+ return err;
60036+
60037+ insert_acl_subj_label(ret, role);
60038+
60039+ userp = s_pre.prev;
60040+ }
60041+
60042+ return 0;
60043+}
60044+
60045+static int
60046+copy_user_acl(struct gr_arg *arg)
60047+{
60048+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
60049+ struct acl_subject_label *subj_list;
60050+ struct sprole_pw *sptmp;
60051+ struct gr_hash_struct *ghash;
60052+ uid_t *domainlist;
60053+ unsigned int r_num;
60054+ int err = 0;
60055+ __u16 i;
60056+ __u32 num_subjs;
60057+
60058+ /* we need a default and kernel role */
60059+ if (arg->role_db.num_roles < 2)
60060+ return -EINVAL;
60061+
60062+ /* copy special role authentication info from userspace */
60063+
60064+ num_sprole_pws = arg->num_sprole_pws;
60065+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
60066+
60067+ if (!acl_special_roles && num_sprole_pws)
60068+ return -ENOMEM;
60069+
60070+ for (i = 0; i < num_sprole_pws; i++) {
60071+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
60072+ if (!sptmp)
60073+ return -ENOMEM;
60074+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
60075+ return -EFAULT;
60076+
60077+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
60078+ if (err)
60079+ return err;
60080+
60081+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60082+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
60083+#endif
60084+
60085+ acl_special_roles[i] = sptmp;
60086+ }
60087+
60088+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
60089+
60090+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
60091+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
60092+
60093+ if (!r_tmp)
60094+ return -ENOMEM;
60095+
60096+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
60097+ return -EFAULT;
60098+
60099+ if (copy_acl_role_label(r_tmp, r_utmp2))
60100+ return -EFAULT;
60101+
60102+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
60103+ if (err)
60104+ return err;
60105+
60106+ if (!strcmp(r_tmp->rolename, "default")
60107+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
60108+ default_role = r_tmp;
60109+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
60110+ kernel_role = r_tmp;
60111+ }
60112+
60113+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
60114+ return -ENOMEM;
60115+
60116+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
60117+ return -EFAULT;
60118+
60119+ r_tmp->hash = ghash;
60120+
60121+ num_subjs = count_user_subjs(r_tmp->hash->first);
60122+
60123+ r_tmp->subj_hash_size = num_subjs;
60124+ r_tmp->subj_hash =
60125+ (struct acl_subject_label **)
60126+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
60127+
60128+ if (!r_tmp->subj_hash)
60129+ return -ENOMEM;
60130+
60131+ err = copy_user_allowedips(r_tmp);
60132+ if (err)
60133+ return err;
60134+
60135+ /* copy domain info */
60136+ if (r_tmp->domain_children != NULL) {
60137+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
60138+ if (domainlist == NULL)
60139+ return -ENOMEM;
60140+
60141+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
60142+ return -EFAULT;
60143+
60144+ r_tmp->domain_children = domainlist;
60145+ }
60146+
60147+ err = copy_user_transitions(r_tmp);
60148+ if (err)
60149+ return err;
60150+
60151+ memset(r_tmp->subj_hash, 0,
60152+ r_tmp->subj_hash_size *
60153+ sizeof (struct acl_subject_label *));
60154+
60155+ /* acquire the list of subjects, then NULL out
60156+ the list prior to parsing the subjects for this role,
60157+ as during this parsing the list is replaced with a list
60158+ of *nested* subjects for the role
60159+ */
60160+ subj_list = r_tmp->hash->first;
60161+
60162+ /* set nested subject list to null */
60163+ r_tmp->hash->first = NULL;
60164+
60165+ err = copy_user_subjs(subj_list, r_tmp);
60166+
60167+ if (err)
60168+ return err;
60169+
60170+ insert_acl_role_label(r_tmp);
60171+ }
60172+
60173+ if (default_role == NULL || kernel_role == NULL)
60174+ return -EINVAL;
60175+
60176+ return err;
60177+}
60178+
60179+static int
60180+gracl_init(struct gr_arg *args)
60181+{
60182+ int error = 0;
60183+
60184+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
60185+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
60186+
60187+ if (init_variables(args)) {
60188+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
60189+ error = -ENOMEM;
60190+ free_variables();
60191+ goto out;
60192+ }
60193+
60194+ error = copy_user_acl(args);
60195+ free_init_variables();
60196+ if (error) {
60197+ free_variables();
60198+ goto out;
60199+ }
60200+
60201+ if ((error = gr_set_acls(0))) {
60202+ free_variables();
60203+ goto out;
60204+ }
60205+
60206+ pax_open_kernel();
60207+ gr_status |= GR_READY;
60208+ pax_close_kernel();
60209+
60210+ out:
60211+ return error;
60212+}
60213+
60214+/* derived from glibc fnmatch() 0: match, 1: no match*/
60215+
60216+static int
60217+glob_match(const char *p, const char *n)
60218+{
60219+ char c;
60220+
60221+ while ((c = *p++) != '\0') {
60222+ switch (c) {
60223+ case '?':
60224+ if (*n == '\0')
60225+ return 1;
60226+ else if (*n == '/')
60227+ return 1;
60228+ break;
60229+ case '\\':
60230+ if (*n != c)
60231+ return 1;
60232+ break;
60233+ case '*':
60234+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
60235+ if (*n == '/')
60236+ return 1;
60237+ else if (c == '?') {
60238+ if (*n == '\0')
60239+ return 1;
60240+ else
60241+ ++n;
60242+ }
60243+ }
60244+ if (c == '\0') {
60245+ return 0;
60246+ } else {
60247+ const char *endp;
60248+
60249+ if ((endp = strchr(n, '/')) == NULL)
60250+ endp = n + strlen(n);
60251+
60252+ if (c == '[') {
60253+ for (--p; n < endp; ++n)
60254+ if (!glob_match(p, n))
60255+ return 0;
60256+ } else if (c == '/') {
60257+ while (*n != '\0' && *n != '/')
60258+ ++n;
60259+ if (*n == '/' && !glob_match(p, n + 1))
60260+ return 0;
60261+ } else {
60262+ for (--p; n < endp; ++n)
60263+ if (*n == c && !glob_match(p, n))
60264+ return 0;
60265+ }
60266+
60267+ return 1;
60268+ }
60269+ case '[':
60270+ {
60271+ int not;
60272+ char cold;
60273+
60274+ if (*n == '\0' || *n == '/')
60275+ return 1;
60276+
60277+ not = (*p == '!' || *p == '^');
60278+ if (not)
60279+ ++p;
60280+
60281+ c = *p++;
60282+ for (;;) {
60283+ unsigned char fn = (unsigned char)*n;
60284+
60285+ if (c == '\0')
60286+ return 1;
60287+ else {
60288+ if (c == fn)
60289+ goto matched;
60290+ cold = c;
60291+ c = *p++;
60292+
60293+ if (c == '-' && *p != ']') {
60294+ unsigned char cend = *p++;
60295+
60296+ if (cend == '\0')
60297+ return 1;
60298+
60299+ if (cold <= fn && fn <= cend)
60300+ goto matched;
60301+
60302+ c = *p++;
60303+ }
60304+ }
60305+
60306+ if (c == ']')
60307+ break;
60308+ }
60309+ if (!not)
60310+ return 1;
60311+ break;
60312+ matched:
60313+ while (c != ']') {
60314+ if (c == '\0')
60315+ return 1;
60316+
60317+ c = *p++;
60318+ }
60319+ if (not)
60320+ return 1;
60321+ }
60322+ break;
60323+ default:
60324+ if (c != *n)
60325+ return 1;
60326+ }
60327+
60328+ ++n;
60329+ }
60330+
60331+ if (*n == '\0')
60332+ return 0;
60333+
60334+ if (*n == '/')
60335+ return 0;
60336+
60337+ return 1;
60338+}
60339+
60340+static struct acl_object_label *
60341+chk_glob_label(struct acl_object_label *globbed,
60342+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
60343+{
60344+ struct acl_object_label *tmp;
60345+
60346+ if (*path == NULL)
60347+ *path = gr_to_filename_nolock(dentry, mnt);
60348+
60349+ tmp = globbed;
60350+
60351+ while (tmp) {
60352+ if (!glob_match(tmp->filename, *path))
60353+ return tmp;
60354+ tmp = tmp->next;
60355+ }
60356+
60357+ return NULL;
60358+}
60359+
60360+static struct acl_object_label *
60361+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60362+ const ino_t curr_ino, const dev_t curr_dev,
60363+ const struct acl_subject_label *subj, char **path, const int checkglob)
60364+{
60365+ struct acl_subject_label *tmpsubj;
60366+ struct acl_object_label *retval;
60367+ struct acl_object_label *retval2;
60368+
60369+ tmpsubj = (struct acl_subject_label *) subj;
60370+ read_lock(&gr_inode_lock);
60371+ do {
60372+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
60373+ if (retval) {
60374+ if (checkglob && retval->globbed) {
60375+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60376+ if (retval2)
60377+ retval = retval2;
60378+ }
60379+ break;
60380+ }
60381+ } while ((tmpsubj = tmpsubj->parent_subject));
60382+ read_unlock(&gr_inode_lock);
60383+
60384+ return retval;
60385+}
60386+
60387+static __inline__ struct acl_object_label *
60388+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60389+ struct dentry *curr_dentry,
60390+ const struct acl_subject_label *subj, char **path, const int checkglob)
60391+{
60392+ int newglob = checkglob;
60393+ ino_t inode;
60394+ dev_t device;
60395+
60396+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60397+ as we don't want a / * rule to match instead of the / object
60398+ don't do this for create lookups that call this function though, since they're looking up
60399+ on the parent and thus need globbing checks on all paths
60400+ */
60401+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60402+ newglob = GR_NO_GLOB;
60403+
60404+ spin_lock(&curr_dentry->d_lock);
60405+ inode = curr_dentry->d_inode->i_ino;
60406+ device = __get_dev(curr_dentry);
60407+ spin_unlock(&curr_dentry->d_lock);
60408+
60409+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60410+}
60411+
60412+#ifdef CONFIG_HUGETLBFS
60413+static inline bool
60414+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60415+{
60416+ int i;
60417+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60418+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60419+ return true;
60420+ }
60421+
60422+ return false;
60423+}
60424+#endif
60425+
60426+static struct acl_object_label *
60427+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60428+ const struct acl_subject_label *subj, char *path, const int checkglob)
60429+{
60430+ struct dentry *dentry = (struct dentry *) l_dentry;
60431+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60432+ struct mount *real_mnt = real_mount(mnt);
60433+ struct acl_object_label *retval;
60434+ struct dentry *parent;
60435+
60436+ br_read_lock(&vfsmount_lock);
60437+ write_seqlock(&rename_lock);
60438+
60439+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60440+#ifdef CONFIG_NET
60441+ mnt == sock_mnt ||
60442+#endif
60443+#ifdef CONFIG_HUGETLBFS
60444+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60445+#endif
60446+ /* ignore Eric Biederman */
60447+ IS_PRIVATE(l_dentry->d_inode))) {
60448+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60449+ goto out;
60450+ }
60451+
60452+ for (;;) {
60453+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60454+ break;
60455+
60456+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60457+ if (!mnt_has_parent(real_mnt))
60458+ break;
60459+
60460+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60461+ if (retval != NULL)
60462+ goto out;
60463+
60464+ dentry = real_mnt->mnt_mountpoint;
60465+ real_mnt = real_mnt->mnt_parent;
60466+ mnt = &real_mnt->mnt;
60467+ continue;
60468+ }
60469+
60470+ parent = dentry->d_parent;
60471+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60472+ if (retval != NULL)
60473+ goto out;
60474+
60475+ dentry = parent;
60476+ }
60477+
60478+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60479+
60480+ /* real_root is pinned so we don't have to hold a reference */
60481+ if (retval == NULL)
60482+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60483+out:
60484+ write_sequnlock(&rename_lock);
60485+ br_read_unlock(&vfsmount_lock);
60486+
60487+ BUG_ON(retval == NULL);
60488+
60489+ return retval;
60490+}
60491+
60492+static __inline__ struct acl_object_label *
60493+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60494+ const struct acl_subject_label *subj)
60495+{
60496+ char *path = NULL;
60497+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60498+}
60499+
60500+static __inline__ struct acl_object_label *
60501+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60502+ const struct acl_subject_label *subj)
60503+{
60504+ char *path = NULL;
60505+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60506+}
60507+
60508+static __inline__ struct acl_object_label *
60509+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60510+ const struct acl_subject_label *subj, char *path)
60511+{
60512+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60513+}
60514+
60515+static struct acl_subject_label *
60516+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60517+ const struct acl_role_label *role)
60518+{
60519+ struct dentry *dentry = (struct dentry *) l_dentry;
60520+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60521+ struct mount *real_mnt = real_mount(mnt);
60522+ struct acl_subject_label *retval;
60523+ struct dentry *parent;
60524+
60525+ br_read_lock(&vfsmount_lock);
60526+ write_seqlock(&rename_lock);
60527+
60528+ for (;;) {
60529+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60530+ break;
60531+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60532+ if (!mnt_has_parent(real_mnt))
60533+ break;
60534+
60535+ spin_lock(&dentry->d_lock);
60536+ read_lock(&gr_inode_lock);
60537+ retval =
60538+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60539+ __get_dev(dentry), role);
60540+ read_unlock(&gr_inode_lock);
60541+ spin_unlock(&dentry->d_lock);
60542+ if (retval != NULL)
60543+ goto out;
60544+
60545+ dentry = real_mnt->mnt_mountpoint;
60546+ real_mnt = real_mnt->mnt_parent;
60547+ mnt = &real_mnt->mnt;
60548+ continue;
60549+ }
60550+
60551+ spin_lock(&dentry->d_lock);
60552+ read_lock(&gr_inode_lock);
60553+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60554+ __get_dev(dentry), role);
60555+ read_unlock(&gr_inode_lock);
60556+ parent = dentry->d_parent;
60557+ spin_unlock(&dentry->d_lock);
60558+
60559+ if (retval != NULL)
60560+ goto out;
60561+
60562+ dentry = parent;
60563+ }
60564+
60565+ spin_lock(&dentry->d_lock);
60566+ read_lock(&gr_inode_lock);
60567+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60568+ __get_dev(dentry), role);
60569+ read_unlock(&gr_inode_lock);
60570+ spin_unlock(&dentry->d_lock);
60571+
60572+ if (unlikely(retval == NULL)) {
60573+ /* real_root is pinned, we don't need to hold a reference */
60574+ read_lock(&gr_inode_lock);
60575+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60576+ __get_dev(real_root.dentry), role);
60577+ read_unlock(&gr_inode_lock);
60578+ }
60579+out:
60580+ write_sequnlock(&rename_lock);
60581+ br_read_unlock(&vfsmount_lock);
60582+
60583+ BUG_ON(retval == NULL);
60584+
60585+ return retval;
60586+}
60587+
60588+static void
60589+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60590+{
60591+ struct task_struct *task = current;
60592+ const struct cred *cred = current_cred();
60593+
60594+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60595+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60596+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60597+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60598+
60599+ return;
60600+}
60601+
60602+static void
60603+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60604+{
60605+ struct task_struct *task = current;
60606+ const struct cred *cred = current_cred();
60607+
60608+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60609+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60610+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60611+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60612+
60613+ return;
60614+}
60615+
60616+static void
60617+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60618+{
60619+ struct task_struct *task = current;
60620+ const struct cred *cred = current_cred();
60621+
60622+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60623+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60624+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60625+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60626+
60627+ return;
60628+}
60629+
60630+__u32
60631+gr_search_file(const struct dentry * dentry, const __u32 mode,
60632+ const struct vfsmount * mnt)
60633+{
60634+ __u32 retval = mode;
60635+ struct acl_subject_label *curracl;
60636+ struct acl_object_label *currobj;
60637+
60638+ if (unlikely(!(gr_status & GR_READY)))
60639+ return (mode & ~GR_AUDITS);
60640+
60641+ curracl = current->acl;
60642+
60643+ currobj = chk_obj_label(dentry, mnt, curracl);
60644+ retval = currobj->mode & mode;
60645+
60646+ /* if we're opening a specified transfer file for writing
60647+ (e.g. /dev/initctl), then transfer our role to init
60648+ */
60649+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60650+ current->role->roletype & GR_ROLE_PERSIST)) {
60651+ struct task_struct *task = init_pid_ns.child_reaper;
60652+
60653+ if (task->role != current->role) {
60654+ task->acl_sp_role = 0;
60655+ task->acl_role_id = current->acl_role_id;
60656+ task->role = current->role;
60657+ rcu_read_lock();
60658+ read_lock(&grsec_exec_file_lock);
60659+ gr_apply_subject_to_task(task);
60660+ read_unlock(&grsec_exec_file_lock);
60661+ rcu_read_unlock();
60662+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60663+ }
60664+ }
60665+
60666+ if (unlikely
60667+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60668+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60669+ __u32 new_mode = mode;
60670+
60671+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60672+
60673+ retval = new_mode;
60674+
60675+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60676+ new_mode |= GR_INHERIT;
60677+
60678+ if (!(mode & GR_NOLEARN))
60679+ gr_log_learn(dentry, mnt, new_mode);
60680+ }
60681+
60682+ return retval;
60683+}
60684+
60685+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60686+ const struct dentry *parent,
60687+ const struct vfsmount *mnt)
60688+{
60689+ struct name_entry *match;
60690+ struct acl_object_label *matchpo;
60691+ struct acl_subject_label *curracl;
60692+ char *path;
60693+
60694+ if (unlikely(!(gr_status & GR_READY)))
60695+ return NULL;
60696+
60697+ preempt_disable();
60698+ path = gr_to_filename_rbac(new_dentry, mnt);
60699+ match = lookup_name_entry_create(path);
60700+
60701+ curracl = current->acl;
60702+
60703+ if (match) {
60704+ read_lock(&gr_inode_lock);
60705+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60706+ read_unlock(&gr_inode_lock);
60707+
60708+ if (matchpo) {
60709+ preempt_enable();
60710+ return matchpo;
60711+ }
60712+ }
60713+
60714+ // lookup parent
60715+
60716+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60717+
60718+ preempt_enable();
60719+ return matchpo;
60720+}
60721+
60722+__u32
60723+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60724+ const struct vfsmount * mnt, const __u32 mode)
60725+{
60726+ struct acl_object_label *matchpo;
60727+ __u32 retval;
60728+
60729+ if (unlikely(!(gr_status & GR_READY)))
60730+ return (mode & ~GR_AUDITS);
60731+
60732+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60733+
60734+ retval = matchpo->mode & mode;
60735+
60736+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60737+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60738+ __u32 new_mode = mode;
60739+
60740+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60741+
60742+ gr_log_learn(new_dentry, mnt, new_mode);
60743+ return new_mode;
60744+ }
60745+
60746+ return retval;
60747+}
60748+
60749+__u32
60750+gr_check_link(const struct dentry * new_dentry,
60751+ const struct dentry * parent_dentry,
60752+ const struct vfsmount * parent_mnt,
60753+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60754+{
60755+ struct acl_object_label *obj;
60756+ __u32 oldmode, newmode;
60757+ __u32 needmode;
60758+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60759+ GR_DELETE | GR_INHERIT;
60760+
60761+ if (unlikely(!(gr_status & GR_READY)))
60762+ return (GR_CREATE | GR_LINK);
60763+
60764+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60765+ oldmode = obj->mode;
60766+
60767+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60768+ newmode = obj->mode;
60769+
60770+ needmode = newmode & checkmodes;
60771+
60772+ // old name for hardlink must have at least the permissions of the new name
60773+ if ((oldmode & needmode) != needmode)
60774+ goto bad;
60775+
60776+ // if old name had restrictions/auditing, make sure the new name does as well
60777+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60778+
60779+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60780+ if (is_privileged_binary(old_dentry))
60781+ needmode |= GR_SETID;
60782+
60783+ if ((newmode & needmode) != needmode)
60784+ goto bad;
60785+
60786+ // enforce minimum permissions
60787+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60788+ return newmode;
60789+bad:
60790+ needmode = oldmode;
60791+ if (is_privileged_binary(old_dentry))
60792+ needmode |= GR_SETID;
60793+
60794+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60795+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60796+ return (GR_CREATE | GR_LINK);
60797+ } else if (newmode & GR_SUPPRESS)
60798+ return GR_SUPPRESS;
60799+ else
60800+ return 0;
60801+}
60802+
60803+int
60804+gr_check_hidden_task(const struct task_struct *task)
60805+{
60806+ if (unlikely(!(gr_status & GR_READY)))
60807+ return 0;
60808+
60809+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60810+ return 1;
60811+
60812+ return 0;
60813+}
60814+
60815+int
60816+gr_check_protected_task(const struct task_struct *task)
60817+{
60818+ if (unlikely(!(gr_status & GR_READY) || !task))
60819+ return 0;
60820+
60821+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60822+ task->acl != current->acl)
60823+ return 1;
60824+
60825+ return 0;
60826+}
60827+
60828+int
60829+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60830+{
60831+ struct task_struct *p;
60832+ int ret = 0;
60833+
60834+ if (unlikely(!(gr_status & GR_READY) || !pid))
60835+ return ret;
60836+
60837+ read_lock(&tasklist_lock);
60838+ do_each_pid_task(pid, type, p) {
60839+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60840+ p->acl != current->acl) {
60841+ ret = 1;
60842+ goto out;
60843+ }
60844+ } while_each_pid_task(pid, type, p);
60845+out:
60846+ read_unlock(&tasklist_lock);
60847+
60848+ return ret;
60849+}
60850+
60851+void
60852+gr_copy_label(struct task_struct *tsk)
60853+{
60854+ tsk->signal->used_accept = 0;
60855+ tsk->acl_sp_role = 0;
60856+ tsk->acl_role_id = current->acl_role_id;
60857+ tsk->acl = current->acl;
60858+ tsk->role = current->role;
60859+ tsk->signal->curr_ip = current->signal->curr_ip;
60860+ tsk->signal->saved_ip = current->signal->saved_ip;
60861+ if (current->exec_file)
60862+ get_file(current->exec_file);
60863+ tsk->exec_file = current->exec_file;
60864+ tsk->is_writable = current->is_writable;
60865+ if (unlikely(current->signal->used_accept)) {
60866+ current->signal->curr_ip = 0;
60867+ current->signal->saved_ip = 0;
60868+ }
60869+
60870+ return;
60871+}
60872+
60873+static void
60874+gr_set_proc_res(struct task_struct *task)
60875+{
60876+ struct acl_subject_label *proc;
60877+ unsigned short i;
60878+
60879+ proc = task->acl;
60880+
60881+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60882+ return;
60883+
60884+ for (i = 0; i < RLIM_NLIMITS; i++) {
60885+ if (!(proc->resmask & (1U << i)))
60886+ continue;
60887+
60888+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60889+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60890+
60891+ if (i == RLIMIT_CPU)
60892+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60893+ }
60894+
60895+ return;
60896+}
60897+
60898+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
60899+
60900+int
60901+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60902+{
60903+ unsigned int i;
60904+ __u16 num;
60905+ uid_t *uidlist;
60906+ uid_t curuid;
60907+ int realok = 0;
60908+ int effectiveok = 0;
60909+ int fsok = 0;
60910+ uid_t globalreal, globaleffective, globalfs;
60911+
60912+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
60913+ struct user_struct *user;
60914+
60915+ if (!uid_valid(real))
60916+ goto skipit;
60917+
60918+ /* find user based on global namespace */
60919+
60920+ globalreal = GR_GLOBAL_UID(real);
60921+
60922+ user = find_user(make_kuid(&init_user_ns, globalreal));
60923+ if (user == NULL)
60924+ goto skipit;
60925+
60926+ if (gr_process_kernel_setuid_ban(user)) {
60927+ /* for find_user */
60928+ free_uid(user);
60929+ return 1;
60930+ }
60931+
60932+ /* for find_user */
60933+ free_uid(user);
60934+
60935+skipit:
60936+#endif
60937+
60938+ if (unlikely(!(gr_status & GR_READY)))
60939+ return 0;
60940+
60941+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60942+ gr_log_learn_uid_change(real, effective, fs);
60943+
60944+ num = current->acl->user_trans_num;
60945+ uidlist = current->acl->user_transitions;
60946+
60947+ if (uidlist == NULL)
60948+ return 0;
60949+
60950+ if (!uid_valid(real)) {
60951+ realok = 1;
60952+ globalreal = (uid_t)-1;
60953+ } else {
60954+ globalreal = GR_GLOBAL_UID(real);
60955+ }
60956+ if (!uid_valid(effective)) {
60957+ effectiveok = 1;
60958+ globaleffective = (uid_t)-1;
60959+ } else {
60960+ globaleffective = GR_GLOBAL_UID(effective);
60961+ }
60962+ if (!uid_valid(fs)) {
60963+ fsok = 1;
60964+ globalfs = (uid_t)-1;
60965+ } else {
60966+ globalfs = GR_GLOBAL_UID(fs);
60967+ }
60968+
60969+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60970+ for (i = 0; i < num; i++) {
60971+ curuid = uidlist[i];
60972+ if (globalreal == curuid)
60973+ realok = 1;
60974+ if (globaleffective == curuid)
60975+ effectiveok = 1;
60976+ if (globalfs == curuid)
60977+ fsok = 1;
60978+ }
60979+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60980+ for (i = 0; i < num; i++) {
60981+ curuid = uidlist[i];
60982+ if (globalreal == curuid)
60983+ break;
60984+ if (globaleffective == curuid)
60985+ break;
60986+ if (globalfs == curuid)
60987+ break;
60988+ }
60989+ /* not in deny list */
60990+ if (i == num) {
60991+ realok = 1;
60992+ effectiveok = 1;
60993+ fsok = 1;
60994+ }
60995+ }
60996+
60997+ if (realok && effectiveok && fsok)
60998+ return 0;
60999+ else {
61000+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
61001+ return 1;
61002+ }
61003+}
61004+
61005+int
61006+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
61007+{
61008+ unsigned int i;
61009+ __u16 num;
61010+ gid_t *gidlist;
61011+ gid_t curgid;
61012+ int realok = 0;
61013+ int effectiveok = 0;
61014+ int fsok = 0;
61015+ gid_t globalreal, globaleffective, globalfs;
61016+
61017+ if (unlikely(!(gr_status & GR_READY)))
61018+ return 0;
61019+
61020+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
61021+ gr_log_learn_gid_change(real, effective, fs);
61022+
61023+ num = current->acl->group_trans_num;
61024+ gidlist = current->acl->group_transitions;
61025+
61026+ if (gidlist == NULL)
61027+ return 0;
61028+
61029+ if (!gid_valid(real)) {
61030+ realok = 1;
61031+ globalreal = (gid_t)-1;
61032+ } else {
61033+ globalreal = GR_GLOBAL_GID(real);
61034+ }
61035+ if (!gid_valid(effective)) {
61036+ effectiveok = 1;
61037+ globaleffective = (gid_t)-1;
61038+ } else {
61039+ globaleffective = GR_GLOBAL_GID(effective);
61040+ }
61041+ if (!gid_valid(fs)) {
61042+ fsok = 1;
61043+ globalfs = (gid_t)-1;
61044+ } else {
61045+ globalfs = GR_GLOBAL_GID(fs);
61046+ }
61047+
61048+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
61049+ for (i = 0; i < num; i++) {
61050+ curgid = gidlist[i];
61051+ if (globalreal == curgid)
61052+ realok = 1;
61053+ if (globaleffective == curgid)
61054+ effectiveok = 1;
61055+ if (globalfs == curgid)
61056+ fsok = 1;
61057+ }
61058+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
61059+ for (i = 0; i < num; i++) {
61060+ curgid = gidlist[i];
61061+ if (globalreal == curgid)
61062+ break;
61063+ if (globaleffective == curgid)
61064+ break;
61065+ if (globalfs == curgid)
61066+ break;
61067+ }
61068+ /* not in deny list */
61069+ if (i == num) {
61070+ realok = 1;
61071+ effectiveok = 1;
61072+ fsok = 1;
61073+ }
61074+ }
61075+
61076+ if (realok && effectiveok && fsok)
61077+ return 0;
61078+ else {
61079+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
61080+ return 1;
61081+ }
61082+}
61083+
61084+extern int gr_acl_is_capable(const int cap);
61085+
61086+void
61087+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
61088+{
61089+ struct acl_role_label *role = task->role;
61090+ struct acl_subject_label *subj = NULL;
61091+ struct acl_object_label *obj;
61092+ struct file *filp;
61093+ uid_t uid;
61094+ gid_t gid;
61095+
61096+ if (unlikely(!(gr_status & GR_READY)))
61097+ return;
61098+
61099+ uid = GR_GLOBAL_UID(kuid);
61100+ gid = GR_GLOBAL_GID(kgid);
61101+
61102+ filp = task->exec_file;
61103+
61104+ /* kernel process, we'll give them the kernel role */
61105+ if (unlikely(!filp)) {
61106+ task->role = kernel_role;
61107+ task->acl = kernel_role->root_label;
61108+ return;
61109+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
61110+ role = lookup_acl_role_label(task, uid, gid);
61111+
61112+ /* don't change the role if we're not a privileged process */
61113+ if (role && task->role != role &&
61114+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
61115+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
61116+ return;
61117+
61118+ /* perform subject lookup in possibly new role
61119+ we can use this result below in the case where role == task->role
61120+ */
61121+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
61122+
61123+ /* if we changed uid/gid, but result in the same role
61124+ and are using inheritance, don't lose the inherited subject
61125+ if current subject is other than what normal lookup
61126+ would result in, we arrived via inheritance, don't
61127+ lose subject
61128+ */
61129+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
61130+ (subj == task->acl)))
61131+ task->acl = subj;
61132+
61133+ task->role = role;
61134+
61135+ task->is_writable = 0;
61136+
61137+ /* ignore additional mmap checks for processes that are writable
61138+ by the default ACL */
61139+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61140+ if (unlikely(obj->mode & GR_WRITE))
61141+ task->is_writable = 1;
61142+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61143+ if (unlikely(obj->mode & GR_WRITE))
61144+ task->is_writable = 1;
61145+
61146+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61147+ 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);
61148+#endif
61149+
61150+ gr_set_proc_res(task);
61151+
61152+ return;
61153+}
61154+
61155+int
61156+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
61157+ const int unsafe_flags)
61158+{
61159+ struct task_struct *task = current;
61160+ struct acl_subject_label *newacl;
61161+ struct acl_object_label *obj;
61162+ __u32 retmode;
61163+
61164+ if (unlikely(!(gr_status & GR_READY)))
61165+ return 0;
61166+
61167+ newacl = chk_subj_label(dentry, mnt, task->role);
61168+
61169+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
61170+ did an exec
61171+ */
61172+ rcu_read_lock();
61173+ read_lock(&tasklist_lock);
61174+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
61175+ (task->parent->acl->mode & GR_POVERRIDE))) {
61176+ read_unlock(&tasklist_lock);
61177+ rcu_read_unlock();
61178+ goto skip_check;
61179+ }
61180+ read_unlock(&tasklist_lock);
61181+ rcu_read_unlock();
61182+
61183+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
61184+ !(task->role->roletype & GR_ROLE_GOD) &&
61185+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
61186+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
61187+ if (unsafe_flags & LSM_UNSAFE_SHARE)
61188+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
61189+ else
61190+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
61191+ return -EACCES;
61192+ }
61193+
61194+skip_check:
61195+
61196+ obj = chk_obj_label(dentry, mnt, task->acl);
61197+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
61198+
61199+ if (!(task->acl->mode & GR_INHERITLEARN) &&
61200+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
61201+ if (obj->nested)
61202+ task->acl = obj->nested;
61203+ else
61204+ task->acl = newacl;
61205+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
61206+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
61207+
61208+ task->is_writable = 0;
61209+
61210+ /* ignore additional mmap checks for processes that are writable
61211+ by the default ACL */
61212+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
61213+ if (unlikely(obj->mode & GR_WRITE))
61214+ task->is_writable = 1;
61215+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
61216+ if (unlikely(obj->mode & GR_WRITE))
61217+ task->is_writable = 1;
61218+
61219+ gr_set_proc_res(task);
61220+
61221+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61222+ 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);
61223+#endif
61224+ return 0;
61225+}
61226+
61227+/* always called with valid inodev ptr */
61228+static void
61229+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
61230+{
61231+ struct acl_object_label *matchpo;
61232+ struct acl_subject_label *matchps;
61233+ struct acl_subject_label *subj;
61234+ struct acl_role_label *role;
61235+ unsigned int x;
61236+
61237+ FOR_EACH_ROLE_START(role)
61238+ FOR_EACH_SUBJECT_START(role, subj, x)
61239+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
61240+ matchpo->mode |= GR_DELETED;
61241+ FOR_EACH_SUBJECT_END(subj,x)
61242+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61243+ /* nested subjects aren't in the role's subj_hash table */
61244+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
61245+ matchpo->mode |= GR_DELETED;
61246+ FOR_EACH_NESTED_SUBJECT_END(subj)
61247+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
61248+ matchps->mode |= GR_DELETED;
61249+ FOR_EACH_ROLE_END(role)
61250+
61251+ inodev->nentry->deleted = 1;
61252+
61253+ return;
61254+}
61255+
61256+void
61257+gr_handle_delete(const ino_t ino, const dev_t dev)
61258+{
61259+ struct inodev_entry *inodev;
61260+
61261+ if (unlikely(!(gr_status & GR_READY)))
61262+ return;
61263+
61264+ write_lock(&gr_inode_lock);
61265+ inodev = lookup_inodev_entry(ino, dev);
61266+ if (inodev != NULL)
61267+ do_handle_delete(inodev, ino, dev);
61268+ write_unlock(&gr_inode_lock);
61269+
61270+ return;
61271+}
61272+
61273+static void
61274+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
61275+ const ino_t newinode, const dev_t newdevice,
61276+ struct acl_subject_label *subj)
61277+{
61278+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
61279+ struct acl_object_label *match;
61280+
61281+ match = subj->obj_hash[index];
61282+
61283+ while (match && (match->inode != oldinode ||
61284+ match->device != olddevice ||
61285+ !(match->mode & GR_DELETED)))
61286+ match = match->next;
61287+
61288+ if (match && (match->inode == oldinode)
61289+ && (match->device == olddevice)
61290+ && (match->mode & GR_DELETED)) {
61291+ if (match->prev == NULL) {
61292+ subj->obj_hash[index] = match->next;
61293+ if (match->next != NULL)
61294+ match->next->prev = NULL;
61295+ } else {
61296+ match->prev->next = match->next;
61297+ if (match->next != NULL)
61298+ match->next->prev = match->prev;
61299+ }
61300+ match->prev = NULL;
61301+ match->next = NULL;
61302+ match->inode = newinode;
61303+ match->device = newdevice;
61304+ match->mode &= ~GR_DELETED;
61305+
61306+ insert_acl_obj_label(match, subj);
61307+ }
61308+
61309+ return;
61310+}
61311+
61312+static void
61313+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
61314+ const ino_t newinode, const dev_t newdevice,
61315+ struct acl_role_label *role)
61316+{
61317+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
61318+ struct acl_subject_label *match;
61319+
61320+ match = role->subj_hash[index];
61321+
61322+ while (match && (match->inode != oldinode ||
61323+ match->device != olddevice ||
61324+ !(match->mode & GR_DELETED)))
61325+ match = match->next;
61326+
61327+ if (match && (match->inode == oldinode)
61328+ && (match->device == olddevice)
61329+ && (match->mode & GR_DELETED)) {
61330+ if (match->prev == NULL) {
61331+ role->subj_hash[index] = match->next;
61332+ if (match->next != NULL)
61333+ match->next->prev = NULL;
61334+ } else {
61335+ match->prev->next = match->next;
61336+ if (match->next != NULL)
61337+ match->next->prev = match->prev;
61338+ }
61339+ match->prev = NULL;
61340+ match->next = NULL;
61341+ match->inode = newinode;
61342+ match->device = newdevice;
61343+ match->mode &= ~GR_DELETED;
61344+
61345+ insert_acl_subj_label(match, role);
61346+ }
61347+
61348+ return;
61349+}
61350+
61351+static void
61352+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
61353+ const ino_t newinode, const dev_t newdevice)
61354+{
61355+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
61356+ struct inodev_entry *match;
61357+
61358+ match = inodev_set.i_hash[index];
61359+
61360+ while (match && (match->nentry->inode != oldinode ||
61361+ match->nentry->device != olddevice || !match->nentry->deleted))
61362+ match = match->next;
61363+
61364+ if (match && (match->nentry->inode == oldinode)
61365+ && (match->nentry->device == olddevice) &&
61366+ match->nentry->deleted) {
61367+ if (match->prev == NULL) {
61368+ inodev_set.i_hash[index] = match->next;
61369+ if (match->next != NULL)
61370+ match->next->prev = NULL;
61371+ } else {
61372+ match->prev->next = match->next;
61373+ if (match->next != NULL)
61374+ match->next->prev = match->prev;
61375+ }
61376+ match->prev = NULL;
61377+ match->next = NULL;
61378+ match->nentry->inode = newinode;
61379+ match->nentry->device = newdevice;
61380+ match->nentry->deleted = 0;
61381+
61382+ insert_inodev_entry(match);
61383+ }
61384+
61385+ return;
61386+}
61387+
61388+static void
61389+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61390+{
61391+ struct acl_subject_label *subj;
61392+ struct acl_role_label *role;
61393+ unsigned int x;
61394+
61395+ FOR_EACH_ROLE_START(role)
61396+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61397+
61398+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61399+ if ((subj->inode == ino) && (subj->device == dev)) {
61400+ subj->inode = ino;
61401+ subj->device = dev;
61402+ }
61403+ /* nested subjects aren't in the role's subj_hash table */
61404+ update_acl_obj_label(matchn->inode, matchn->device,
61405+ ino, dev, subj);
61406+ FOR_EACH_NESTED_SUBJECT_END(subj)
61407+ FOR_EACH_SUBJECT_START(role, subj, x)
61408+ update_acl_obj_label(matchn->inode, matchn->device,
61409+ ino, dev, subj);
61410+ FOR_EACH_SUBJECT_END(subj,x)
61411+ FOR_EACH_ROLE_END(role)
61412+
61413+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61414+
61415+ return;
61416+}
61417+
61418+static void
61419+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61420+ const struct vfsmount *mnt)
61421+{
61422+ ino_t ino = dentry->d_inode->i_ino;
61423+ dev_t dev = __get_dev(dentry);
61424+
61425+ __do_handle_create(matchn, ino, dev);
61426+
61427+ return;
61428+}
61429+
61430+void
61431+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61432+{
61433+ struct name_entry *matchn;
61434+
61435+ if (unlikely(!(gr_status & GR_READY)))
61436+ return;
61437+
61438+ preempt_disable();
61439+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61440+
61441+ if (unlikely((unsigned long)matchn)) {
61442+ write_lock(&gr_inode_lock);
61443+ do_handle_create(matchn, dentry, mnt);
61444+ write_unlock(&gr_inode_lock);
61445+ }
61446+ preempt_enable();
61447+
61448+ return;
61449+}
61450+
61451+void
61452+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61453+{
61454+ struct name_entry *matchn;
61455+
61456+ if (unlikely(!(gr_status & GR_READY)))
61457+ return;
61458+
61459+ preempt_disable();
61460+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61461+
61462+ if (unlikely((unsigned long)matchn)) {
61463+ write_lock(&gr_inode_lock);
61464+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61465+ write_unlock(&gr_inode_lock);
61466+ }
61467+ preempt_enable();
61468+
61469+ return;
61470+}
61471+
61472+void
61473+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61474+ struct dentry *old_dentry,
61475+ struct dentry *new_dentry,
61476+ struct vfsmount *mnt, const __u8 replace)
61477+{
61478+ struct name_entry *matchn;
61479+ struct inodev_entry *inodev;
61480+ struct inode *inode = new_dentry->d_inode;
61481+ ino_t old_ino = old_dentry->d_inode->i_ino;
61482+ dev_t old_dev = __get_dev(old_dentry);
61483+
61484+ /* vfs_rename swaps the name and parent link for old_dentry and
61485+ new_dentry
61486+ at this point, old_dentry has the new name, parent link, and inode
61487+ for the renamed file
61488+ if a file is being replaced by a rename, new_dentry has the inode
61489+ and name for the replaced file
61490+ */
61491+
61492+ if (unlikely(!(gr_status & GR_READY)))
61493+ return;
61494+
61495+ preempt_disable();
61496+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61497+
61498+ /* we wouldn't have to check d_inode if it weren't for
61499+ NFS silly-renaming
61500+ */
61501+
61502+ write_lock(&gr_inode_lock);
61503+ if (unlikely(replace && inode)) {
61504+ ino_t new_ino = inode->i_ino;
61505+ dev_t new_dev = __get_dev(new_dentry);
61506+
61507+ inodev = lookup_inodev_entry(new_ino, new_dev);
61508+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61509+ do_handle_delete(inodev, new_ino, new_dev);
61510+ }
61511+
61512+ inodev = lookup_inodev_entry(old_ino, old_dev);
61513+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61514+ do_handle_delete(inodev, old_ino, old_dev);
61515+
61516+ if (unlikely((unsigned long)matchn))
61517+ do_handle_create(matchn, old_dentry, mnt);
61518+
61519+ write_unlock(&gr_inode_lock);
61520+ preempt_enable();
61521+
61522+ return;
61523+}
61524+
61525+static int
61526+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61527+ unsigned char **sum)
61528+{
61529+ struct acl_role_label *r;
61530+ struct role_allowed_ip *ipp;
61531+ struct role_transition *trans;
61532+ unsigned int i;
61533+ int found = 0;
61534+ u32 curr_ip = current->signal->curr_ip;
61535+
61536+ current->signal->saved_ip = curr_ip;
61537+
61538+ /* check transition table */
61539+
61540+ for (trans = current->role->transitions; trans; trans = trans->next) {
61541+ if (!strcmp(rolename, trans->rolename)) {
61542+ found = 1;
61543+ break;
61544+ }
61545+ }
61546+
61547+ if (!found)
61548+ return 0;
61549+
61550+ /* handle special roles that do not require authentication
61551+ and check ip */
61552+
61553+ FOR_EACH_ROLE_START(r)
61554+ if (!strcmp(rolename, r->rolename) &&
61555+ (r->roletype & GR_ROLE_SPECIAL)) {
61556+ found = 0;
61557+ if (r->allowed_ips != NULL) {
61558+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61559+ if ((ntohl(curr_ip) & ipp->netmask) ==
61560+ (ntohl(ipp->addr) & ipp->netmask))
61561+ found = 1;
61562+ }
61563+ } else
61564+ found = 2;
61565+ if (!found)
61566+ return 0;
61567+
61568+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61569+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61570+ *salt = NULL;
61571+ *sum = NULL;
61572+ return 1;
61573+ }
61574+ }
61575+ FOR_EACH_ROLE_END(r)
61576+
61577+ for (i = 0; i < num_sprole_pws; i++) {
61578+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61579+ *salt = acl_special_roles[i]->salt;
61580+ *sum = acl_special_roles[i]->sum;
61581+ return 1;
61582+ }
61583+ }
61584+
61585+ return 0;
61586+}
61587+
61588+static void
61589+assign_special_role(char *rolename)
61590+{
61591+ struct acl_object_label *obj;
61592+ struct acl_role_label *r;
61593+ struct acl_role_label *assigned = NULL;
61594+ struct task_struct *tsk;
61595+ struct file *filp;
61596+
61597+ FOR_EACH_ROLE_START(r)
61598+ if (!strcmp(rolename, r->rolename) &&
61599+ (r->roletype & GR_ROLE_SPECIAL)) {
61600+ assigned = r;
61601+ break;
61602+ }
61603+ FOR_EACH_ROLE_END(r)
61604+
61605+ if (!assigned)
61606+ return;
61607+
61608+ read_lock(&tasklist_lock);
61609+ read_lock(&grsec_exec_file_lock);
61610+
61611+ tsk = current->real_parent;
61612+ if (tsk == NULL)
61613+ goto out_unlock;
61614+
61615+ filp = tsk->exec_file;
61616+ if (filp == NULL)
61617+ goto out_unlock;
61618+
61619+ tsk->is_writable = 0;
61620+
61621+ tsk->acl_sp_role = 1;
61622+ tsk->acl_role_id = ++acl_sp_role_value;
61623+ tsk->role = assigned;
61624+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61625+
61626+ /* ignore additional mmap checks for processes that are writable
61627+ by the default ACL */
61628+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61629+ if (unlikely(obj->mode & GR_WRITE))
61630+ tsk->is_writable = 1;
61631+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61632+ if (unlikely(obj->mode & GR_WRITE))
61633+ tsk->is_writable = 1;
61634+
61635+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61636+ 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));
61637+#endif
61638+
61639+out_unlock:
61640+ read_unlock(&grsec_exec_file_lock);
61641+ read_unlock(&tasklist_lock);
61642+ return;
61643+}
61644+
61645+int gr_check_secure_terminal(struct task_struct *task)
61646+{
61647+ struct task_struct *p, *p2, *p3;
61648+ struct files_struct *files;
61649+ struct fdtable *fdt;
61650+ struct file *our_file = NULL, *file;
61651+ int i;
61652+
61653+ if (task->signal->tty == NULL)
61654+ return 1;
61655+
61656+ files = get_files_struct(task);
61657+ if (files != NULL) {
61658+ rcu_read_lock();
61659+ fdt = files_fdtable(files);
61660+ for (i=0; i < fdt->max_fds; i++) {
61661+ file = fcheck_files(files, i);
61662+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61663+ get_file(file);
61664+ our_file = file;
61665+ }
61666+ }
61667+ rcu_read_unlock();
61668+ put_files_struct(files);
61669+ }
61670+
61671+ if (our_file == NULL)
61672+ return 1;
61673+
61674+ read_lock(&tasklist_lock);
61675+ do_each_thread(p2, p) {
61676+ files = get_files_struct(p);
61677+ if (files == NULL ||
61678+ (p->signal && p->signal->tty == task->signal->tty)) {
61679+ if (files != NULL)
61680+ put_files_struct(files);
61681+ continue;
61682+ }
61683+ rcu_read_lock();
61684+ fdt = files_fdtable(files);
61685+ for (i=0; i < fdt->max_fds; i++) {
61686+ file = fcheck_files(files, i);
61687+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61688+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61689+ p3 = task;
61690+ while (task_pid_nr(p3) > 0) {
61691+ if (p3 == p)
61692+ break;
61693+ p3 = p3->real_parent;
61694+ }
61695+ if (p3 == p)
61696+ break;
61697+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61698+ gr_handle_alertkill(p);
61699+ rcu_read_unlock();
61700+ put_files_struct(files);
61701+ read_unlock(&tasklist_lock);
61702+ fput(our_file);
61703+ return 0;
61704+ }
61705+ }
61706+ rcu_read_unlock();
61707+ put_files_struct(files);
61708+ } while_each_thread(p2, p);
61709+ read_unlock(&tasklist_lock);
61710+
61711+ fput(our_file);
61712+ return 1;
61713+}
61714+
61715+static int gr_rbac_disable(void *unused)
61716+{
61717+ pax_open_kernel();
61718+ gr_status &= ~GR_READY;
61719+ pax_close_kernel();
61720+
61721+ return 0;
61722+}
61723+
61724+ssize_t
61725+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
61726+{
61727+ struct gr_arg_wrapper uwrap;
61728+ unsigned char *sprole_salt = NULL;
61729+ unsigned char *sprole_sum = NULL;
61730+ int error = 0;
61731+ int error2 = 0;
61732+ size_t req_count = 0;
61733+
61734+ mutex_lock(&gr_dev_mutex);
61735+
61736+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61737+ error = -EPERM;
61738+ goto out;
61739+ }
61740+
61741+#ifdef CONFIG_COMPAT
61742+ pax_open_kernel();
61743+ if (is_compat_task()) {
61744+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
61745+ copy_gr_arg = &copy_gr_arg_compat;
61746+ copy_acl_object_label = &copy_acl_object_label_compat;
61747+ copy_acl_subject_label = &copy_acl_subject_label_compat;
61748+ copy_acl_role_label = &copy_acl_role_label_compat;
61749+ copy_acl_ip_label = &copy_acl_ip_label_compat;
61750+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
61751+ copy_role_transition = &copy_role_transition_compat;
61752+ copy_sprole_pw = &copy_sprole_pw_compat;
61753+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
61754+ copy_pointer_from_array = &copy_pointer_from_array_compat;
61755+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
61756+ } else {
61757+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
61758+ copy_gr_arg = &copy_gr_arg_normal;
61759+ copy_acl_object_label = &copy_acl_object_label_normal;
61760+ copy_acl_subject_label = &copy_acl_subject_label_normal;
61761+ copy_acl_role_label = &copy_acl_role_label_normal;
61762+ copy_acl_ip_label = &copy_acl_ip_label_normal;
61763+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
61764+ copy_role_transition = &copy_role_transition_normal;
61765+ copy_sprole_pw = &copy_sprole_pw_normal;
61766+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
61767+ copy_pointer_from_array = &copy_pointer_from_array_normal;
61768+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
61769+ }
61770+ pax_close_kernel();
61771+#endif
61772+
61773+ req_count = get_gr_arg_wrapper_size();
61774+
61775+ if (count != req_count) {
61776+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
61777+ error = -EINVAL;
61778+ goto out;
61779+ }
61780+
61781+
61782+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61783+ gr_auth_expires = 0;
61784+ gr_auth_attempts = 0;
61785+ }
61786+
61787+ error = copy_gr_arg_wrapper(buf, &uwrap);
61788+ if (error)
61789+ goto out;
61790+
61791+ error = copy_gr_arg(uwrap.arg, gr_usermode);
61792+ if (error)
61793+ goto out;
61794+
61795+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61796+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61797+ time_after(gr_auth_expires, get_seconds())) {
61798+ error = -EBUSY;
61799+ goto out;
61800+ }
61801+
61802+ /* if non-root trying to do anything other than use a special role,
61803+ do not attempt authentication, do not count towards authentication
61804+ locking
61805+ */
61806+
61807+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61808+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61809+ gr_is_global_nonroot(current_uid())) {
61810+ error = -EPERM;
61811+ goto out;
61812+ }
61813+
61814+ /* ensure pw and special role name are null terminated */
61815+
61816+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61817+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61818+
61819+ /* Okay.
61820+ * We have our enough of the argument structure..(we have yet
61821+ * to copy_from_user the tables themselves) . Copy the tables
61822+ * only if we need them, i.e. for loading operations. */
61823+
61824+ switch (gr_usermode->mode) {
61825+ case GR_STATUS:
61826+ if (gr_status & GR_READY) {
61827+ error = 1;
61828+ if (!gr_check_secure_terminal(current))
61829+ error = 3;
61830+ } else
61831+ error = 2;
61832+ goto out;
61833+ case GR_SHUTDOWN:
61834+ if ((gr_status & GR_READY)
61835+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61836+ stop_machine(gr_rbac_disable, NULL, NULL);
61837+ free_variables();
61838+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61839+ memset(gr_system_salt, 0, GR_SALT_LEN);
61840+ memset(gr_system_sum, 0, GR_SHA_LEN);
61841+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61842+ } else if (gr_status & GR_READY) {
61843+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61844+ error = -EPERM;
61845+ } else {
61846+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61847+ error = -EAGAIN;
61848+ }
61849+ break;
61850+ case GR_ENABLE:
61851+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61852+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61853+ else {
61854+ if (gr_status & GR_READY)
61855+ error = -EAGAIN;
61856+ else
61857+ error = error2;
61858+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61859+ }
61860+ break;
61861+ case GR_RELOAD:
61862+ if (!(gr_status & GR_READY)) {
61863+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61864+ error = -EAGAIN;
61865+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61866+ stop_machine(gr_rbac_disable, NULL, NULL);
61867+ free_variables();
61868+ error2 = gracl_init(gr_usermode);
61869+ if (!error2)
61870+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61871+ else {
61872+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61873+ error = error2;
61874+ }
61875+ } else {
61876+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61877+ error = -EPERM;
61878+ }
61879+ break;
61880+ case GR_SEGVMOD:
61881+ if (unlikely(!(gr_status & GR_READY))) {
61882+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61883+ error = -EAGAIN;
61884+ break;
61885+ }
61886+
61887+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61888+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61889+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61890+ struct acl_subject_label *segvacl;
61891+ segvacl =
61892+ lookup_acl_subj_label(gr_usermode->segv_inode,
61893+ gr_usermode->segv_device,
61894+ current->role);
61895+ if (segvacl) {
61896+ segvacl->crashes = 0;
61897+ segvacl->expires = 0;
61898+ }
61899+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61900+ gr_remove_uid(gr_usermode->segv_uid);
61901+ }
61902+ } else {
61903+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61904+ error = -EPERM;
61905+ }
61906+ break;
61907+ case GR_SPROLE:
61908+ case GR_SPROLEPAM:
61909+ if (unlikely(!(gr_status & GR_READY))) {
61910+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61911+ error = -EAGAIN;
61912+ break;
61913+ }
61914+
61915+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61916+ current->role->expires = 0;
61917+ current->role->auth_attempts = 0;
61918+ }
61919+
61920+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61921+ time_after(current->role->expires, get_seconds())) {
61922+ error = -EBUSY;
61923+ goto out;
61924+ }
61925+
61926+ if (lookup_special_role_auth
61927+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61928+ && ((!sprole_salt && !sprole_sum)
61929+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61930+ char *p = "";
61931+ assign_special_role(gr_usermode->sp_role);
61932+ read_lock(&tasklist_lock);
61933+ if (current->real_parent)
61934+ p = current->real_parent->role->rolename;
61935+ read_unlock(&tasklist_lock);
61936+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61937+ p, acl_sp_role_value);
61938+ } else {
61939+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61940+ error = -EPERM;
61941+ if(!(current->role->auth_attempts++))
61942+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61943+
61944+ goto out;
61945+ }
61946+ break;
61947+ case GR_UNSPROLE:
61948+ if (unlikely(!(gr_status & GR_READY))) {
61949+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61950+ error = -EAGAIN;
61951+ break;
61952+ }
61953+
61954+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61955+ char *p = "";
61956+ int i = 0;
61957+
61958+ read_lock(&tasklist_lock);
61959+ if (current->real_parent) {
61960+ p = current->real_parent->role->rolename;
61961+ i = current->real_parent->acl_role_id;
61962+ }
61963+ read_unlock(&tasklist_lock);
61964+
61965+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61966+ gr_set_acls(1);
61967+ } else {
61968+ error = -EPERM;
61969+ goto out;
61970+ }
61971+ break;
61972+ default:
61973+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61974+ error = -EINVAL;
61975+ break;
61976+ }
61977+
61978+ if (error != -EPERM)
61979+ goto out;
61980+
61981+ if(!(gr_auth_attempts++))
61982+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61983+
61984+ out:
61985+ mutex_unlock(&gr_dev_mutex);
61986+
61987+ if (!error)
61988+ error = req_count;
61989+
61990+ return error;
61991+}
61992+
61993+/* must be called with
61994+ rcu_read_lock();
61995+ read_lock(&tasklist_lock);
61996+ read_lock(&grsec_exec_file_lock);
61997+*/
61998+int gr_apply_subject_to_task(struct task_struct *task)
61999+{
62000+ struct acl_object_label *obj;
62001+ char *tmpname;
62002+ struct acl_subject_label *tmpsubj;
62003+ struct file *filp;
62004+ struct name_entry *nmatch;
62005+
62006+ filp = task->exec_file;
62007+ if (filp == NULL)
62008+ return 0;
62009+
62010+ /* the following is to apply the correct subject
62011+ on binaries running when the RBAC system
62012+ is enabled, when the binaries have been
62013+ replaced or deleted since their execution
62014+ -----
62015+ when the RBAC system starts, the inode/dev
62016+ from exec_file will be one the RBAC system
62017+ is unaware of. It only knows the inode/dev
62018+ of the present file on disk, or the absence
62019+ of it.
62020+ */
62021+ preempt_disable();
62022+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
62023+
62024+ nmatch = lookup_name_entry(tmpname);
62025+ preempt_enable();
62026+ tmpsubj = NULL;
62027+ if (nmatch) {
62028+ if (nmatch->deleted)
62029+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
62030+ else
62031+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
62032+ if (tmpsubj != NULL)
62033+ task->acl = tmpsubj;
62034+ }
62035+ if (tmpsubj == NULL)
62036+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
62037+ task->role);
62038+ if (task->acl) {
62039+ task->is_writable = 0;
62040+ /* ignore additional mmap checks for processes that are writable
62041+ by the default ACL */
62042+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
62043+ if (unlikely(obj->mode & GR_WRITE))
62044+ task->is_writable = 1;
62045+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
62046+ if (unlikely(obj->mode & GR_WRITE))
62047+ task->is_writable = 1;
62048+
62049+ gr_set_proc_res(task);
62050+
62051+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
62052+ 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);
62053+#endif
62054+ } else {
62055+ return 1;
62056+ }
62057+
62058+ return 0;
62059+}
62060+
62061+int
62062+gr_set_acls(const int type)
62063+{
62064+ struct task_struct *task, *task2;
62065+ struct acl_role_label *role = current->role;
62066+ __u16 acl_role_id = current->acl_role_id;
62067+ const struct cred *cred;
62068+ int ret;
62069+
62070+ rcu_read_lock();
62071+ read_lock(&tasklist_lock);
62072+ read_lock(&grsec_exec_file_lock);
62073+ do_each_thread(task2, task) {
62074+ /* check to see if we're called from the exit handler,
62075+ if so, only replace ACLs that have inherited the admin
62076+ ACL */
62077+
62078+ if (type && (task->role != role ||
62079+ task->acl_role_id != acl_role_id))
62080+ continue;
62081+
62082+ task->acl_role_id = 0;
62083+ task->acl_sp_role = 0;
62084+
62085+ if (task->exec_file) {
62086+ cred = __task_cred(task);
62087+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
62088+ ret = gr_apply_subject_to_task(task);
62089+ if (ret) {
62090+ read_unlock(&grsec_exec_file_lock);
62091+ read_unlock(&tasklist_lock);
62092+ rcu_read_unlock();
62093+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
62094+ return ret;
62095+ }
62096+ } else {
62097+ // it's a kernel process
62098+ task->role = kernel_role;
62099+ task->acl = kernel_role->root_label;
62100+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
62101+ task->acl->mode &= ~GR_PROCFIND;
62102+#endif
62103+ }
62104+ } while_each_thread(task2, task);
62105+ read_unlock(&grsec_exec_file_lock);
62106+ read_unlock(&tasklist_lock);
62107+ rcu_read_unlock();
62108+
62109+ return 0;
62110+}
62111+
62112+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
62113+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
62114+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
62115+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
62116+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
62117+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
62118+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
62119+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
62120+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
62121+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
62122+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
62123+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
62124+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
62125+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
62126+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
62127+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
62128+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
62129+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
62130+};
62131+
62132+void
62133+gr_learn_resource(const struct task_struct *task,
62134+ const int res, const unsigned long wanted, const int gt)
62135+{
62136+ struct acl_subject_label *acl;
62137+ const struct cred *cred;
62138+
62139+ if (unlikely((gr_status & GR_READY) &&
62140+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
62141+ goto skip_reslog;
62142+
62143+ gr_log_resource(task, res, wanted, gt);
62144+skip_reslog:
62145+
62146+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
62147+ return;
62148+
62149+ acl = task->acl;
62150+
62151+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
62152+ !(acl->resmask & (1U << (unsigned short) res))))
62153+ return;
62154+
62155+ if (wanted >= acl->res[res].rlim_cur) {
62156+ unsigned long res_add;
62157+
62158+ res_add = wanted + res_learn_bumps[res];
62159+
62160+ acl->res[res].rlim_cur = res_add;
62161+
62162+ if (wanted > acl->res[res].rlim_max)
62163+ acl->res[res].rlim_max = res_add;
62164+
62165+ /* only log the subject filename, since resource logging is supported for
62166+ single-subject learning only */
62167+ rcu_read_lock();
62168+ cred = __task_cred(task);
62169+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62170+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
62171+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
62172+ "", (unsigned long) res, &task->signal->saved_ip);
62173+ rcu_read_unlock();
62174+ }
62175+
62176+ return;
62177+}
62178+EXPORT_SYMBOL(gr_learn_resource);
62179+#endif
62180+
62181+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
62182+void
62183+pax_set_initial_flags(struct linux_binprm *bprm)
62184+{
62185+ struct task_struct *task = current;
62186+ struct acl_subject_label *proc;
62187+ unsigned long flags;
62188+
62189+ if (unlikely(!(gr_status & GR_READY)))
62190+ return;
62191+
62192+ flags = pax_get_flags(task);
62193+
62194+ proc = task->acl;
62195+
62196+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
62197+ flags &= ~MF_PAX_PAGEEXEC;
62198+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
62199+ flags &= ~MF_PAX_SEGMEXEC;
62200+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
62201+ flags &= ~MF_PAX_RANDMMAP;
62202+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
62203+ flags &= ~MF_PAX_EMUTRAMP;
62204+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
62205+ flags &= ~MF_PAX_MPROTECT;
62206+
62207+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
62208+ flags |= MF_PAX_PAGEEXEC;
62209+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
62210+ flags |= MF_PAX_SEGMEXEC;
62211+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
62212+ flags |= MF_PAX_RANDMMAP;
62213+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
62214+ flags |= MF_PAX_EMUTRAMP;
62215+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
62216+ flags |= MF_PAX_MPROTECT;
62217+
62218+ pax_set_flags(task, flags);
62219+
62220+ return;
62221+}
62222+#endif
62223+
62224+int
62225+gr_handle_proc_ptrace(struct task_struct *task)
62226+{
62227+ struct file *filp;
62228+ struct task_struct *tmp = task;
62229+ struct task_struct *curtemp = current;
62230+ __u32 retmode;
62231+
62232+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
62233+ if (unlikely(!(gr_status & GR_READY)))
62234+ return 0;
62235+#endif
62236+
62237+ read_lock(&tasklist_lock);
62238+ read_lock(&grsec_exec_file_lock);
62239+ filp = task->exec_file;
62240+
62241+ while (task_pid_nr(tmp) > 0) {
62242+ if (tmp == curtemp)
62243+ break;
62244+ tmp = tmp->real_parent;
62245+ }
62246+
62247+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
62248+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
62249+ read_unlock(&grsec_exec_file_lock);
62250+ read_unlock(&tasklist_lock);
62251+ return 1;
62252+ }
62253+
62254+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62255+ if (!(gr_status & GR_READY)) {
62256+ read_unlock(&grsec_exec_file_lock);
62257+ read_unlock(&tasklist_lock);
62258+ return 0;
62259+ }
62260+#endif
62261+
62262+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
62263+ read_unlock(&grsec_exec_file_lock);
62264+ read_unlock(&tasklist_lock);
62265+
62266+ if (retmode & GR_NOPTRACE)
62267+ return 1;
62268+
62269+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
62270+ && (current->acl != task->acl || (current->acl != current->role->root_label
62271+ && task_pid_nr(current) != task_pid_nr(task))))
62272+ return 1;
62273+
62274+ return 0;
62275+}
62276+
62277+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
62278+{
62279+ if (unlikely(!(gr_status & GR_READY)))
62280+ return;
62281+
62282+ if (!(current->role->roletype & GR_ROLE_GOD))
62283+ return;
62284+
62285+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
62286+ p->role->rolename, gr_task_roletype_to_char(p),
62287+ p->acl->filename);
62288+}
62289+
62290+int
62291+gr_handle_ptrace(struct task_struct *task, const long request)
62292+{
62293+ struct task_struct *tmp = task;
62294+ struct task_struct *curtemp = current;
62295+ __u32 retmode;
62296+
62297+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
62298+ if (unlikely(!(gr_status & GR_READY)))
62299+ return 0;
62300+#endif
62301+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
62302+ read_lock(&tasklist_lock);
62303+ while (task_pid_nr(tmp) > 0) {
62304+ if (tmp == curtemp)
62305+ break;
62306+ tmp = tmp->real_parent;
62307+ }
62308+
62309+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
62310+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
62311+ read_unlock(&tasklist_lock);
62312+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62313+ return 1;
62314+ }
62315+ read_unlock(&tasklist_lock);
62316+ }
62317+
62318+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62319+ if (!(gr_status & GR_READY))
62320+ return 0;
62321+#endif
62322+
62323+ read_lock(&grsec_exec_file_lock);
62324+ if (unlikely(!task->exec_file)) {
62325+ read_unlock(&grsec_exec_file_lock);
62326+ return 0;
62327+ }
62328+
62329+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
62330+ read_unlock(&grsec_exec_file_lock);
62331+
62332+ if (retmode & GR_NOPTRACE) {
62333+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62334+ return 1;
62335+ }
62336+
62337+ if (retmode & GR_PTRACERD) {
62338+ switch (request) {
62339+ case PTRACE_SEIZE:
62340+ case PTRACE_POKETEXT:
62341+ case PTRACE_POKEDATA:
62342+ case PTRACE_POKEUSR:
62343+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
62344+ case PTRACE_SETREGS:
62345+ case PTRACE_SETFPREGS:
62346+#endif
62347+#ifdef CONFIG_X86
62348+ case PTRACE_SETFPXREGS:
62349+#endif
62350+#ifdef CONFIG_ALTIVEC
62351+ case PTRACE_SETVRREGS:
62352+#endif
62353+ return 1;
62354+ default:
62355+ return 0;
62356+ }
62357+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
62358+ !(current->role->roletype & GR_ROLE_GOD) &&
62359+ (current->acl != task->acl)) {
62360+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62361+ return 1;
62362+ }
62363+
62364+ return 0;
62365+}
62366+
62367+static int is_writable_mmap(const struct file *filp)
62368+{
62369+ struct task_struct *task = current;
62370+ struct acl_object_label *obj, *obj2;
62371+
62372+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
62373+ !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))) {
62374+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
62375+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
62376+ task->role->root_label);
62377+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
62378+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
62379+ return 1;
62380+ }
62381+ }
62382+ return 0;
62383+}
62384+
62385+int
62386+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
62387+{
62388+ __u32 mode;
62389+
62390+ if (unlikely(!file || !(prot & PROT_EXEC)))
62391+ return 1;
62392+
62393+ if (is_writable_mmap(file))
62394+ return 0;
62395+
62396+ mode =
62397+ gr_search_file(file->f_path.dentry,
62398+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62399+ file->f_path.mnt);
62400+
62401+ if (!gr_tpe_allow(file))
62402+ return 0;
62403+
62404+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62405+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62406+ return 0;
62407+ } else if (unlikely(!(mode & GR_EXEC))) {
62408+ return 0;
62409+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62410+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62411+ return 1;
62412+ }
62413+
62414+ return 1;
62415+}
62416+
62417+int
62418+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62419+{
62420+ __u32 mode;
62421+
62422+ if (unlikely(!file || !(prot & PROT_EXEC)))
62423+ return 1;
62424+
62425+ if (is_writable_mmap(file))
62426+ return 0;
62427+
62428+ mode =
62429+ gr_search_file(file->f_path.dentry,
62430+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62431+ file->f_path.mnt);
62432+
62433+ if (!gr_tpe_allow(file))
62434+ return 0;
62435+
62436+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62437+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62438+ return 0;
62439+ } else if (unlikely(!(mode & GR_EXEC))) {
62440+ return 0;
62441+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62442+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62443+ return 1;
62444+ }
62445+
62446+ return 1;
62447+}
62448+
62449+void
62450+gr_acl_handle_psacct(struct task_struct *task, const long code)
62451+{
62452+ unsigned long runtime;
62453+ unsigned long cputime;
62454+ unsigned int wday, cday;
62455+ __u8 whr, chr;
62456+ __u8 wmin, cmin;
62457+ __u8 wsec, csec;
62458+ struct timespec timeval;
62459+
62460+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62461+ !(task->acl->mode & GR_PROCACCT)))
62462+ return;
62463+
62464+ do_posix_clock_monotonic_gettime(&timeval);
62465+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62466+ wday = runtime / (3600 * 24);
62467+ runtime -= wday * (3600 * 24);
62468+ whr = runtime / 3600;
62469+ runtime -= whr * 3600;
62470+ wmin = runtime / 60;
62471+ runtime -= wmin * 60;
62472+ wsec = runtime;
62473+
62474+ cputime = (task->utime + task->stime) / HZ;
62475+ cday = cputime / (3600 * 24);
62476+ cputime -= cday * (3600 * 24);
62477+ chr = cputime / 3600;
62478+ cputime -= chr * 3600;
62479+ cmin = cputime / 60;
62480+ cputime -= cmin * 60;
62481+ csec = cputime;
62482+
62483+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62484+
62485+ return;
62486+}
62487+
62488+void gr_set_kernel_label(struct task_struct *task)
62489+{
62490+ if (gr_status & GR_READY) {
62491+ task->role = kernel_role;
62492+ task->acl = kernel_role->root_label;
62493+ }
62494+ return;
62495+}
62496+
62497+#ifdef CONFIG_TASKSTATS
62498+int gr_is_taskstats_denied(int pid)
62499+{
62500+ struct task_struct *task;
62501+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62502+ const struct cred *cred;
62503+#endif
62504+ int ret = 0;
62505+
62506+ /* restrict taskstats viewing to un-chrooted root users
62507+ who have the 'view' subject flag if the RBAC system is enabled
62508+ */
62509+
62510+ rcu_read_lock();
62511+ read_lock(&tasklist_lock);
62512+ task = find_task_by_vpid(pid);
62513+ if (task) {
62514+#ifdef CONFIG_GRKERNSEC_CHROOT
62515+ if (proc_is_chrooted(task))
62516+ ret = -EACCES;
62517+#endif
62518+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62519+ cred = __task_cred(task);
62520+#ifdef CONFIG_GRKERNSEC_PROC_USER
62521+ if (gr_is_global_nonroot(cred->uid))
62522+ ret = -EACCES;
62523+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62524+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62525+ ret = -EACCES;
62526+#endif
62527+#endif
62528+ if (gr_status & GR_READY) {
62529+ if (!(task->acl->mode & GR_VIEW))
62530+ ret = -EACCES;
62531+ }
62532+ } else
62533+ ret = -ENOENT;
62534+
62535+ read_unlock(&tasklist_lock);
62536+ rcu_read_unlock();
62537+
62538+ return ret;
62539+}
62540+#endif
62541+
62542+/* AUXV entries are filled via a descendant of search_binary_handler
62543+ after we've already applied the subject for the target
62544+*/
62545+int gr_acl_enable_at_secure(void)
62546+{
62547+ if (unlikely(!(gr_status & GR_READY)))
62548+ return 0;
62549+
62550+ if (current->acl->mode & GR_ATSECURE)
62551+ return 1;
62552+
62553+ return 0;
62554+}
62555+
62556+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62557+{
62558+ struct task_struct *task = current;
62559+ struct dentry *dentry = file->f_path.dentry;
62560+ struct vfsmount *mnt = file->f_path.mnt;
62561+ struct acl_object_label *obj, *tmp;
62562+ struct acl_subject_label *subj;
62563+ unsigned int bufsize;
62564+ int is_not_root;
62565+ char *path;
62566+ dev_t dev = __get_dev(dentry);
62567+
62568+ if (unlikely(!(gr_status & GR_READY)))
62569+ return 1;
62570+
62571+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62572+ return 1;
62573+
62574+ /* ignore Eric Biederman */
62575+ if (IS_PRIVATE(dentry->d_inode))
62576+ return 1;
62577+
62578+ subj = task->acl;
62579+ read_lock(&gr_inode_lock);
62580+ do {
62581+ obj = lookup_acl_obj_label(ino, dev, subj);
62582+ if (obj != NULL) {
62583+ read_unlock(&gr_inode_lock);
62584+ return (obj->mode & GR_FIND) ? 1 : 0;
62585+ }
62586+ } while ((subj = subj->parent_subject));
62587+ read_unlock(&gr_inode_lock);
62588+
62589+ /* this is purely an optimization since we're looking for an object
62590+ for the directory we're doing a readdir on
62591+ if it's possible for any globbed object to match the entry we're
62592+ filling into the directory, then the object we find here will be
62593+ an anchor point with attached globbed objects
62594+ */
62595+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62596+ if (obj->globbed == NULL)
62597+ return (obj->mode & GR_FIND) ? 1 : 0;
62598+
62599+ is_not_root = ((obj->filename[0] == '/') &&
62600+ (obj->filename[1] == '\0')) ? 0 : 1;
62601+ bufsize = PAGE_SIZE - namelen - is_not_root;
62602+
62603+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62604+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62605+ return 1;
62606+
62607+ preempt_disable();
62608+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62609+ bufsize);
62610+
62611+ bufsize = strlen(path);
62612+
62613+ /* if base is "/", don't append an additional slash */
62614+ if (is_not_root)
62615+ *(path + bufsize) = '/';
62616+ memcpy(path + bufsize + is_not_root, name, namelen);
62617+ *(path + bufsize + namelen + is_not_root) = '\0';
62618+
62619+ tmp = obj->globbed;
62620+ while (tmp) {
62621+ if (!glob_match(tmp->filename, path)) {
62622+ preempt_enable();
62623+ return (tmp->mode & GR_FIND) ? 1 : 0;
62624+ }
62625+ tmp = tmp->next;
62626+ }
62627+ preempt_enable();
62628+ return (obj->mode & GR_FIND) ? 1 : 0;
62629+}
62630+
62631+void gr_put_exec_file(struct task_struct *task)
62632+{
62633+ struct file *filp;
62634+
62635+ write_lock(&grsec_exec_file_lock);
62636+ filp = task->exec_file;
62637+ task->exec_file = NULL;
62638+ write_unlock(&grsec_exec_file_lock);
62639+
62640+ if (filp)
62641+ fput(filp);
62642+
62643+ return;
62644+}
62645+
62646+
62647+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62648+EXPORT_SYMBOL(gr_acl_is_enabled);
62649+#endif
62650+EXPORT_SYMBOL(gr_set_kernel_label);
62651+#ifdef CONFIG_SECURITY
62652+EXPORT_SYMBOL(gr_check_user_change);
62653+EXPORT_SYMBOL(gr_check_group_change);
62654+#endif
62655+
62656diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62657new file mode 100644
62658index 0000000..34fefda
62659--- /dev/null
62660+++ b/grsecurity/gracl_alloc.c
62661@@ -0,0 +1,105 @@
62662+#include <linux/kernel.h>
62663+#include <linux/mm.h>
62664+#include <linux/slab.h>
62665+#include <linux/vmalloc.h>
62666+#include <linux/gracl.h>
62667+#include <linux/grsecurity.h>
62668+
62669+static unsigned long alloc_stack_next = 1;
62670+static unsigned long alloc_stack_size = 1;
62671+static void **alloc_stack;
62672+
62673+static __inline__ int
62674+alloc_pop(void)
62675+{
62676+ if (alloc_stack_next == 1)
62677+ return 0;
62678+
62679+ kfree(alloc_stack[alloc_stack_next - 2]);
62680+
62681+ alloc_stack_next--;
62682+
62683+ return 1;
62684+}
62685+
62686+static __inline__ int
62687+alloc_push(void *buf)
62688+{
62689+ if (alloc_stack_next >= alloc_stack_size)
62690+ return 1;
62691+
62692+ alloc_stack[alloc_stack_next - 1] = buf;
62693+
62694+ alloc_stack_next++;
62695+
62696+ return 0;
62697+}
62698+
62699+void *
62700+acl_alloc(unsigned long len)
62701+{
62702+ void *ret = NULL;
62703+
62704+ if (!len || len > PAGE_SIZE)
62705+ goto out;
62706+
62707+ ret = kmalloc(len, GFP_KERNEL);
62708+
62709+ if (ret) {
62710+ if (alloc_push(ret)) {
62711+ kfree(ret);
62712+ ret = NULL;
62713+ }
62714+ }
62715+
62716+out:
62717+ return ret;
62718+}
62719+
62720+void *
62721+acl_alloc_num(unsigned long num, unsigned long len)
62722+{
62723+ if (!len || (num > (PAGE_SIZE / len)))
62724+ return NULL;
62725+
62726+ return acl_alloc(num * len);
62727+}
62728+
62729+void
62730+acl_free_all(void)
62731+{
62732+ if (gr_acl_is_enabled() || !alloc_stack)
62733+ return;
62734+
62735+ while (alloc_pop()) ;
62736+
62737+ if (alloc_stack) {
62738+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62739+ kfree(alloc_stack);
62740+ else
62741+ vfree(alloc_stack);
62742+ }
62743+
62744+ alloc_stack = NULL;
62745+ alloc_stack_size = 1;
62746+ alloc_stack_next = 1;
62747+
62748+ return;
62749+}
62750+
62751+int
62752+acl_alloc_stack_init(unsigned long size)
62753+{
62754+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62755+ alloc_stack =
62756+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62757+ else
62758+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62759+
62760+ alloc_stack_size = size;
62761+
62762+ if (!alloc_stack)
62763+ return 0;
62764+ else
62765+ return 1;
62766+}
62767diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62768new file mode 100644
62769index 0000000..bdd51ea
62770--- /dev/null
62771+++ b/grsecurity/gracl_cap.c
62772@@ -0,0 +1,110 @@
62773+#include <linux/kernel.h>
62774+#include <linux/module.h>
62775+#include <linux/sched.h>
62776+#include <linux/gracl.h>
62777+#include <linux/grsecurity.h>
62778+#include <linux/grinternal.h>
62779+
62780+extern const char *captab_log[];
62781+extern int captab_log_entries;
62782+
62783+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62784+{
62785+ struct acl_subject_label *curracl;
62786+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62787+ kernel_cap_t cap_audit = __cap_empty_set;
62788+
62789+ if (!gr_acl_is_enabled())
62790+ return 1;
62791+
62792+ curracl = task->acl;
62793+
62794+ cap_drop = curracl->cap_lower;
62795+ cap_mask = curracl->cap_mask;
62796+ cap_audit = curracl->cap_invert_audit;
62797+
62798+ while ((curracl = curracl->parent_subject)) {
62799+ /* if the cap isn't specified in the current computed mask but is specified in the
62800+ current level subject, and is lowered in the current level subject, then add
62801+ it to the set of dropped capabilities
62802+ otherwise, add the current level subject's mask to the current computed mask
62803+ */
62804+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62805+ cap_raise(cap_mask, cap);
62806+ if (cap_raised(curracl->cap_lower, cap))
62807+ cap_raise(cap_drop, cap);
62808+ if (cap_raised(curracl->cap_invert_audit, cap))
62809+ cap_raise(cap_audit, cap);
62810+ }
62811+ }
62812+
62813+ if (!cap_raised(cap_drop, cap)) {
62814+ if (cap_raised(cap_audit, cap))
62815+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62816+ return 1;
62817+ }
62818+
62819+ curracl = task->acl;
62820+
62821+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62822+ && cap_raised(cred->cap_effective, cap)) {
62823+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62824+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62825+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62826+ gr_to_filename(task->exec_file->f_path.dentry,
62827+ task->exec_file->f_path.mnt) : curracl->filename,
62828+ curracl->filename, 0UL,
62829+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62830+ return 1;
62831+ }
62832+
62833+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62834+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62835+
62836+ return 0;
62837+}
62838+
62839+int
62840+gr_acl_is_capable(const int cap)
62841+{
62842+ return gr_task_acl_is_capable(current, current_cred(), cap);
62843+}
62844+
62845+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62846+{
62847+ struct acl_subject_label *curracl;
62848+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62849+
62850+ if (!gr_acl_is_enabled())
62851+ return 1;
62852+
62853+ curracl = task->acl;
62854+
62855+ cap_drop = curracl->cap_lower;
62856+ cap_mask = curracl->cap_mask;
62857+
62858+ while ((curracl = curracl->parent_subject)) {
62859+ /* if the cap isn't specified in the current computed mask but is specified in the
62860+ current level subject, and is lowered in the current level subject, then add
62861+ it to the set of dropped capabilities
62862+ otherwise, add the current level subject's mask to the current computed mask
62863+ */
62864+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62865+ cap_raise(cap_mask, cap);
62866+ if (cap_raised(curracl->cap_lower, cap))
62867+ cap_raise(cap_drop, cap);
62868+ }
62869+ }
62870+
62871+ if (!cap_raised(cap_drop, cap))
62872+ return 1;
62873+
62874+ return 0;
62875+}
62876+
62877+int
62878+gr_acl_is_capable_nolog(const int cap)
62879+{
62880+ return gr_task_acl_is_capable_nolog(current, cap);
62881+}
62882+
62883diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
62884new file mode 100644
62885index 0000000..a43dd06
62886--- /dev/null
62887+++ b/grsecurity/gracl_compat.c
62888@@ -0,0 +1,269 @@
62889+#include <linux/kernel.h>
62890+#include <linux/gracl.h>
62891+#include <linux/compat.h>
62892+#include <linux/gracl_compat.h>
62893+
62894+#include <asm/uaccess.h>
62895+
62896+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
62897+{
62898+ struct gr_arg_wrapper_compat uwrapcompat;
62899+
62900+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
62901+ return -EFAULT;
62902+
62903+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
62904+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
62905+ return -EINVAL;
62906+
62907+ uwrap->arg = compat_ptr(uwrapcompat.arg);
62908+ uwrap->version = uwrapcompat.version;
62909+ uwrap->size = sizeof(struct gr_arg);
62910+
62911+ return 0;
62912+}
62913+
62914+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
62915+{
62916+ struct gr_arg_compat argcompat;
62917+
62918+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
62919+ return -EFAULT;
62920+
62921+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
62922+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
62923+ arg->role_db.num_roles = argcompat.role_db.num_roles;
62924+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
62925+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
62926+ arg->role_db.num_objects = argcompat.role_db.num_objects;
62927+
62928+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
62929+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
62930+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
62931+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
62932+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
62933+ arg->segv_device = argcompat.segv_device;
62934+ arg->segv_inode = argcompat.segv_inode;
62935+ arg->segv_uid = argcompat.segv_uid;
62936+ arg->num_sprole_pws = argcompat.num_sprole_pws;
62937+ arg->mode = argcompat.mode;
62938+
62939+ return 0;
62940+}
62941+
62942+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
62943+{
62944+ struct acl_object_label_compat objcompat;
62945+
62946+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
62947+ return -EFAULT;
62948+
62949+ obj->filename = compat_ptr(objcompat.filename);
62950+ obj->inode = objcompat.inode;
62951+ obj->device = objcompat.device;
62952+ obj->mode = objcompat.mode;
62953+
62954+ obj->nested = compat_ptr(objcompat.nested);
62955+ obj->globbed = compat_ptr(objcompat.globbed);
62956+
62957+ obj->prev = compat_ptr(objcompat.prev);
62958+ obj->next = compat_ptr(objcompat.next);
62959+
62960+ return 0;
62961+}
62962+
62963+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62964+{
62965+ unsigned int i;
62966+ struct acl_subject_label_compat subjcompat;
62967+
62968+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
62969+ return -EFAULT;
62970+
62971+ subj->filename = compat_ptr(subjcompat.filename);
62972+ subj->inode = subjcompat.inode;
62973+ subj->device = subjcompat.device;
62974+ subj->mode = subjcompat.mode;
62975+ subj->cap_mask = subjcompat.cap_mask;
62976+ subj->cap_lower = subjcompat.cap_lower;
62977+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
62978+
62979+ for (i = 0; i < GR_NLIMITS; i++) {
62980+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
62981+ subj->res[i].rlim_cur = RLIM_INFINITY;
62982+ else
62983+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
62984+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
62985+ subj->res[i].rlim_max = RLIM_INFINITY;
62986+ else
62987+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
62988+ }
62989+ subj->resmask = subjcompat.resmask;
62990+
62991+ subj->user_trans_type = subjcompat.user_trans_type;
62992+ subj->group_trans_type = subjcompat.group_trans_type;
62993+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
62994+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
62995+ subj->user_trans_num = subjcompat.user_trans_num;
62996+ subj->group_trans_num = subjcompat.group_trans_num;
62997+
62998+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
62999+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
63000+ subj->ip_type = subjcompat.ip_type;
63001+ subj->ips = compat_ptr(subjcompat.ips);
63002+ subj->ip_num = subjcompat.ip_num;
63003+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
63004+
63005+ subj->crashes = subjcompat.crashes;
63006+ subj->expires = subjcompat.expires;
63007+
63008+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
63009+ subj->hash = compat_ptr(subjcompat.hash);
63010+ subj->prev = compat_ptr(subjcompat.prev);
63011+ subj->next = compat_ptr(subjcompat.next);
63012+
63013+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
63014+ subj->obj_hash_size = subjcompat.obj_hash_size;
63015+ subj->pax_flags = subjcompat.pax_flags;
63016+
63017+ return 0;
63018+}
63019+
63020+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
63021+{
63022+ struct acl_role_label_compat rolecompat;
63023+
63024+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
63025+ return -EFAULT;
63026+
63027+ role->rolename = compat_ptr(rolecompat.rolename);
63028+ role->uidgid = rolecompat.uidgid;
63029+ role->roletype = rolecompat.roletype;
63030+
63031+ role->auth_attempts = rolecompat.auth_attempts;
63032+ role->expires = rolecompat.expires;
63033+
63034+ role->root_label = compat_ptr(rolecompat.root_label);
63035+ role->hash = compat_ptr(rolecompat.hash);
63036+
63037+ role->prev = compat_ptr(rolecompat.prev);
63038+ role->next = compat_ptr(rolecompat.next);
63039+
63040+ role->transitions = compat_ptr(rolecompat.transitions);
63041+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
63042+ role->domain_children = compat_ptr(rolecompat.domain_children);
63043+ role->domain_child_num = rolecompat.domain_child_num;
63044+
63045+ role->umask = rolecompat.umask;
63046+
63047+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
63048+ role->subj_hash_size = rolecompat.subj_hash_size;
63049+
63050+ return 0;
63051+}
63052+
63053+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
63054+{
63055+ struct role_allowed_ip_compat roleip_compat;
63056+
63057+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
63058+ return -EFAULT;
63059+
63060+ roleip->addr = roleip_compat.addr;
63061+ roleip->netmask = roleip_compat.netmask;
63062+
63063+ roleip->prev = compat_ptr(roleip_compat.prev);
63064+ roleip->next = compat_ptr(roleip_compat.next);
63065+
63066+ return 0;
63067+}
63068+
63069+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
63070+{
63071+ struct role_transition_compat trans_compat;
63072+
63073+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
63074+ return -EFAULT;
63075+
63076+ trans->rolename = compat_ptr(trans_compat.rolename);
63077+
63078+ trans->prev = compat_ptr(trans_compat.prev);
63079+ trans->next = compat_ptr(trans_compat.next);
63080+
63081+ return 0;
63082+
63083+}
63084+
63085+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
63086+{
63087+ struct gr_hash_struct_compat hash_compat;
63088+
63089+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
63090+ return -EFAULT;
63091+
63092+ hash->table = compat_ptr(hash_compat.table);
63093+ hash->nametable = compat_ptr(hash_compat.nametable);
63094+ hash->first = compat_ptr(hash_compat.first);
63095+
63096+ hash->table_size = hash_compat.table_size;
63097+ hash->used_size = hash_compat.used_size;
63098+
63099+ hash->type = hash_compat.type;
63100+
63101+ return 0;
63102+}
63103+
63104+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
63105+{
63106+ compat_uptr_t ptrcompat;
63107+
63108+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
63109+ return -EFAULT;
63110+
63111+ *(void **)ptr = compat_ptr(ptrcompat);
63112+
63113+ return 0;
63114+}
63115+
63116+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
63117+{
63118+ struct acl_ip_label_compat ip_compat;
63119+
63120+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
63121+ return -EFAULT;
63122+
63123+ ip->iface = compat_ptr(ip_compat.iface);
63124+ ip->addr = ip_compat.addr;
63125+ ip->netmask = ip_compat.netmask;
63126+ ip->low = ip_compat.low;
63127+ ip->high = ip_compat.high;
63128+ ip->mode = ip_compat.mode;
63129+ ip->type = ip_compat.type;
63130+
63131+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
63132+
63133+ ip->prev = compat_ptr(ip_compat.prev);
63134+ ip->next = compat_ptr(ip_compat.next);
63135+
63136+ return 0;
63137+}
63138+
63139+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
63140+{
63141+ struct sprole_pw_compat pw_compat;
63142+
63143+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
63144+ return -EFAULT;
63145+
63146+ pw->rolename = compat_ptr(pw_compat.rolename);
63147+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
63148+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
63149+
63150+ return 0;
63151+}
63152+
63153+size_t get_gr_arg_wrapper_size_compat(void)
63154+{
63155+ return sizeof(struct gr_arg_wrapper_compat);
63156+}
63157+
63158diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
63159new file mode 100644
63160index 0000000..a340c17
63161--- /dev/null
63162+++ b/grsecurity/gracl_fs.c
63163@@ -0,0 +1,431 @@
63164+#include <linux/kernel.h>
63165+#include <linux/sched.h>
63166+#include <linux/types.h>
63167+#include <linux/fs.h>
63168+#include <linux/file.h>
63169+#include <linux/stat.h>
63170+#include <linux/grsecurity.h>
63171+#include <linux/grinternal.h>
63172+#include <linux/gracl.h>
63173+
63174+umode_t
63175+gr_acl_umask(void)
63176+{
63177+ if (unlikely(!gr_acl_is_enabled()))
63178+ return 0;
63179+
63180+ return current->role->umask;
63181+}
63182+
63183+__u32
63184+gr_acl_handle_hidden_file(const struct dentry * dentry,
63185+ const struct vfsmount * mnt)
63186+{
63187+ __u32 mode;
63188+
63189+ if (unlikely(!dentry->d_inode))
63190+ return GR_FIND;
63191+
63192+ mode =
63193+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
63194+
63195+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
63196+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
63197+ return mode;
63198+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
63199+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
63200+ return 0;
63201+ } else if (unlikely(!(mode & GR_FIND)))
63202+ return 0;
63203+
63204+ return GR_FIND;
63205+}
63206+
63207+__u32
63208+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63209+ int acc_mode)
63210+{
63211+ __u32 reqmode = GR_FIND;
63212+ __u32 mode;
63213+
63214+ if (unlikely(!dentry->d_inode))
63215+ return reqmode;
63216+
63217+ if (acc_mode & MAY_APPEND)
63218+ reqmode |= GR_APPEND;
63219+ else if (acc_mode & MAY_WRITE)
63220+ reqmode |= GR_WRITE;
63221+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
63222+ reqmode |= GR_READ;
63223+
63224+ mode =
63225+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
63226+ mnt);
63227+
63228+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
63229+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
63230+ reqmode & GR_READ ? " reading" : "",
63231+ reqmode & GR_WRITE ? " writing" : reqmode &
63232+ GR_APPEND ? " appending" : "");
63233+ return reqmode;
63234+ } else
63235+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
63236+ {
63237+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
63238+ reqmode & GR_READ ? " reading" : "",
63239+ reqmode & GR_WRITE ? " writing" : reqmode &
63240+ GR_APPEND ? " appending" : "");
63241+ return 0;
63242+ } else if (unlikely((mode & reqmode) != reqmode))
63243+ return 0;
63244+
63245+ return reqmode;
63246+}
63247+
63248+__u32
63249+gr_acl_handle_creat(const struct dentry * dentry,
63250+ const struct dentry * p_dentry,
63251+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63252+ const int imode)
63253+{
63254+ __u32 reqmode = GR_WRITE | GR_CREATE;
63255+ __u32 mode;
63256+
63257+ if (acc_mode & MAY_APPEND)
63258+ reqmode |= GR_APPEND;
63259+ // if a directory was required or the directory already exists, then
63260+ // don't count this open as a read
63261+ if ((acc_mode & MAY_READ) &&
63262+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
63263+ reqmode |= GR_READ;
63264+ if ((open_flags & O_CREAT) &&
63265+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
63266+ reqmode |= GR_SETID;
63267+
63268+ mode =
63269+ gr_check_create(dentry, p_dentry, p_mnt,
63270+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
63271+
63272+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
63273+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
63274+ reqmode & GR_READ ? " reading" : "",
63275+ reqmode & GR_WRITE ? " writing" : reqmode &
63276+ GR_APPEND ? " appending" : "");
63277+ return reqmode;
63278+ } else
63279+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
63280+ {
63281+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
63282+ reqmode & GR_READ ? " reading" : "",
63283+ reqmode & GR_WRITE ? " writing" : reqmode &
63284+ GR_APPEND ? " appending" : "");
63285+ return 0;
63286+ } else if (unlikely((mode & reqmode) != reqmode))
63287+ return 0;
63288+
63289+ return reqmode;
63290+}
63291+
63292+__u32
63293+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
63294+ const int fmode)
63295+{
63296+ __u32 mode, reqmode = GR_FIND;
63297+
63298+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
63299+ reqmode |= GR_EXEC;
63300+ if (fmode & S_IWOTH)
63301+ reqmode |= GR_WRITE;
63302+ if (fmode & S_IROTH)
63303+ reqmode |= GR_READ;
63304+
63305+ mode =
63306+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
63307+ mnt);
63308+
63309+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
63310+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
63311+ reqmode & GR_READ ? " reading" : "",
63312+ reqmode & GR_WRITE ? " writing" : "",
63313+ reqmode & GR_EXEC ? " executing" : "");
63314+ return reqmode;
63315+ } else
63316+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
63317+ {
63318+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
63319+ reqmode & GR_READ ? " reading" : "",
63320+ reqmode & GR_WRITE ? " writing" : "",
63321+ reqmode & GR_EXEC ? " executing" : "");
63322+ return 0;
63323+ } else if (unlikely((mode & reqmode) != reqmode))
63324+ return 0;
63325+
63326+ return reqmode;
63327+}
63328+
63329+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
63330+{
63331+ __u32 mode;
63332+
63333+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
63334+
63335+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
63336+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
63337+ return mode;
63338+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
63339+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
63340+ return 0;
63341+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
63342+ return 0;
63343+
63344+ return (reqmode);
63345+}
63346+
63347+__u32
63348+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63349+{
63350+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
63351+}
63352+
63353+__u32
63354+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
63355+{
63356+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
63357+}
63358+
63359+__u32
63360+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
63361+{
63362+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
63363+}
63364+
63365+__u32
63366+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
63367+{
63368+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
63369+}
63370+
63371+__u32
63372+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
63373+ umode_t *modeptr)
63374+{
63375+ umode_t mode;
63376+
63377+ *modeptr &= ~gr_acl_umask();
63378+ mode = *modeptr;
63379+
63380+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
63381+ return 1;
63382+
63383+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
63384+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
63385+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
63386+ GR_CHMOD_ACL_MSG);
63387+ } else {
63388+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
63389+ }
63390+}
63391+
63392+__u32
63393+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
63394+{
63395+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
63396+}
63397+
63398+__u32
63399+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
63400+{
63401+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
63402+}
63403+
63404+__u32
63405+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
63406+{
63407+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
63408+}
63409+
63410+__u32
63411+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
63412+{
63413+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
63414+ GR_UNIXCONNECT_ACL_MSG);
63415+}
63416+
63417+/* hardlinks require at minimum create and link permission,
63418+ any additional privilege required is based on the
63419+ privilege of the file being linked to
63420+*/
63421+__u32
63422+gr_acl_handle_link(const struct dentry * new_dentry,
63423+ const struct dentry * parent_dentry,
63424+ const struct vfsmount * parent_mnt,
63425+ const struct dentry * old_dentry,
63426+ const struct vfsmount * old_mnt, const struct filename *to)
63427+{
63428+ __u32 mode;
63429+ __u32 needmode = GR_CREATE | GR_LINK;
63430+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
63431+
63432+ mode =
63433+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
63434+ old_mnt);
63435+
63436+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
63437+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
63438+ return mode;
63439+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
63440+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
63441+ return 0;
63442+ } else if (unlikely((mode & needmode) != needmode))
63443+ return 0;
63444+
63445+ return 1;
63446+}
63447+
63448+__u32
63449+gr_acl_handle_symlink(const struct dentry * new_dentry,
63450+ const struct dentry * parent_dentry,
63451+ const struct vfsmount * parent_mnt, const struct filename *from)
63452+{
63453+ __u32 needmode = GR_WRITE | GR_CREATE;
63454+ __u32 mode;
63455+
63456+ mode =
63457+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
63458+ GR_CREATE | GR_AUDIT_CREATE |
63459+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
63460+
63461+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
63462+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
63463+ return mode;
63464+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
63465+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
63466+ return 0;
63467+ } else if (unlikely((mode & needmode) != needmode))
63468+ return 0;
63469+
63470+ return (GR_WRITE | GR_CREATE);
63471+}
63472+
63473+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)
63474+{
63475+ __u32 mode;
63476+
63477+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
63478+
63479+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
63480+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
63481+ return mode;
63482+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
63483+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
63484+ return 0;
63485+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
63486+ return 0;
63487+
63488+ return (reqmode);
63489+}
63490+
63491+__u32
63492+gr_acl_handle_mknod(const struct dentry * new_dentry,
63493+ const struct dentry * parent_dentry,
63494+ const struct vfsmount * parent_mnt,
63495+ const int mode)
63496+{
63497+ __u32 reqmode = GR_WRITE | GR_CREATE;
63498+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
63499+ reqmode |= GR_SETID;
63500+
63501+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
63502+ reqmode, GR_MKNOD_ACL_MSG);
63503+}
63504+
63505+__u32
63506+gr_acl_handle_mkdir(const struct dentry *new_dentry,
63507+ const struct dentry *parent_dentry,
63508+ const struct vfsmount *parent_mnt)
63509+{
63510+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
63511+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
63512+}
63513+
63514+#define RENAME_CHECK_SUCCESS(old, new) \
63515+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
63516+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
63517+
63518+int
63519+gr_acl_handle_rename(struct dentry *new_dentry,
63520+ struct dentry *parent_dentry,
63521+ const struct vfsmount *parent_mnt,
63522+ struct dentry *old_dentry,
63523+ struct inode *old_parent_inode,
63524+ struct vfsmount *old_mnt, const struct filename *newname)
63525+{
63526+ __u32 comp1, comp2;
63527+ int error = 0;
63528+
63529+ if (unlikely(!gr_acl_is_enabled()))
63530+ return 0;
63531+
63532+ if (!new_dentry->d_inode) {
63533+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
63534+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
63535+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
63536+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
63537+ GR_DELETE | GR_AUDIT_DELETE |
63538+ GR_AUDIT_READ | GR_AUDIT_WRITE |
63539+ GR_SUPPRESS, old_mnt);
63540+ } else {
63541+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
63542+ GR_CREATE | GR_DELETE |
63543+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
63544+ GR_AUDIT_READ | GR_AUDIT_WRITE |
63545+ GR_SUPPRESS, parent_mnt);
63546+ comp2 =
63547+ gr_search_file(old_dentry,
63548+ GR_READ | GR_WRITE | GR_AUDIT_READ |
63549+ GR_DELETE | GR_AUDIT_DELETE |
63550+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
63551+ }
63552+
63553+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
63554+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
63555+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
63556+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
63557+ && !(comp2 & GR_SUPPRESS)) {
63558+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
63559+ error = -EACCES;
63560+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
63561+ error = -EACCES;
63562+
63563+ return error;
63564+}
63565+
63566+void
63567+gr_acl_handle_exit(void)
63568+{
63569+ u16 id;
63570+ char *rolename;
63571+
63572+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
63573+ !(current->role->roletype & GR_ROLE_PERSIST))) {
63574+ id = current->acl_role_id;
63575+ rolename = current->role->rolename;
63576+ gr_set_acls(1);
63577+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
63578+ }
63579+
63580+ gr_put_exec_file(current);
63581+ return;
63582+}
63583+
63584+int
63585+gr_acl_handle_procpidmem(const struct task_struct *task)
63586+{
63587+ if (unlikely(!gr_acl_is_enabled()))
63588+ return 0;
63589+
63590+ if (task != current && task->acl->mode & GR_PROTPROCFD)
63591+ return -EACCES;
63592+
63593+ return 0;
63594+}
63595diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
63596new file mode 100644
63597index 0000000..8132048
63598--- /dev/null
63599+++ b/grsecurity/gracl_ip.c
63600@@ -0,0 +1,387 @@
63601+#include <linux/kernel.h>
63602+#include <asm/uaccess.h>
63603+#include <asm/errno.h>
63604+#include <net/sock.h>
63605+#include <linux/file.h>
63606+#include <linux/fs.h>
63607+#include <linux/net.h>
63608+#include <linux/in.h>
63609+#include <linux/skbuff.h>
63610+#include <linux/ip.h>
63611+#include <linux/udp.h>
63612+#include <linux/types.h>
63613+#include <linux/sched.h>
63614+#include <linux/netdevice.h>
63615+#include <linux/inetdevice.h>
63616+#include <linux/gracl.h>
63617+#include <linux/grsecurity.h>
63618+#include <linux/grinternal.h>
63619+
63620+#define GR_BIND 0x01
63621+#define GR_CONNECT 0x02
63622+#define GR_INVERT 0x04
63623+#define GR_BINDOVERRIDE 0x08
63624+#define GR_CONNECTOVERRIDE 0x10
63625+#define GR_SOCK_FAMILY 0x20
63626+
63627+static const char * gr_protocols[IPPROTO_MAX] = {
63628+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
63629+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
63630+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
63631+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
63632+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
63633+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
63634+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
63635+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
63636+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
63637+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
63638+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
63639+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
63640+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
63641+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
63642+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
63643+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
63644+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
63645+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
63646+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
63647+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
63648+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
63649+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
63650+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
63651+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
63652+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
63653+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
63654+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
63655+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
63656+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
63657+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
63658+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
63659+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
63660+ };
63661+
63662+static const char * gr_socktypes[SOCK_MAX] = {
63663+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
63664+ "unknown:7", "unknown:8", "unknown:9", "packet"
63665+ };
63666+
63667+static const char * gr_sockfamilies[AF_MAX+1] = {
63668+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
63669+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
63670+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
63671+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
63672+ };
63673+
63674+const char *
63675+gr_proto_to_name(unsigned char proto)
63676+{
63677+ return gr_protocols[proto];
63678+}
63679+
63680+const char *
63681+gr_socktype_to_name(unsigned char type)
63682+{
63683+ return gr_socktypes[type];
63684+}
63685+
63686+const char *
63687+gr_sockfamily_to_name(unsigned char family)
63688+{
63689+ return gr_sockfamilies[family];
63690+}
63691+
63692+int
63693+gr_search_socket(const int domain, const int type, const int protocol)
63694+{
63695+ struct acl_subject_label *curr;
63696+ const struct cred *cred = current_cred();
63697+
63698+ if (unlikely(!gr_acl_is_enabled()))
63699+ goto exit;
63700+
63701+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63702+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63703+ goto exit; // let the kernel handle it
63704+
63705+ curr = current->acl;
63706+
63707+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63708+ /* the family is allowed, if this is PF_INET allow it only if
63709+ the extra sock type/protocol checks pass */
63710+ if (domain == PF_INET)
63711+ goto inet_check;
63712+ goto exit;
63713+ } else {
63714+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63715+ __u32 fakeip = 0;
63716+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63717+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63718+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63719+ gr_to_filename(current->exec_file->f_path.dentry,
63720+ current->exec_file->f_path.mnt) :
63721+ curr->filename, curr->filename,
63722+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63723+ &current->signal->saved_ip);
63724+ goto exit;
63725+ }
63726+ goto exit_fail;
63727+ }
63728+
63729+inet_check:
63730+ /* the rest of this checking is for IPv4 only */
63731+ if (!curr->ips)
63732+ goto exit;
63733+
63734+ if ((curr->ip_type & (1U << type)) &&
63735+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63736+ goto exit;
63737+
63738+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63739+ /* we don't place acls on raw sockets , and sometimes
63740+ dgram/ip sockets are opened for ioctl and not
63741+ bind/connect, so we'll fake a bind learn log */
63742+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63743+ __u32 fakeip = 0;
63744+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63745+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63746+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63747+ gr_to_filename(current->exec_file->f_path.dentry,
63748+ current->exec_file->f_path.mnt) :
63749+ curr->filename, curr->filename,
63750+ &fakeip, 0, type,
63751+ protocol, GR_CONNECT, &current->signal->saved_ip);
63752+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63753+ __u32 fakeip = 0;
63754+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63755+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63756+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63757+ gr_to_filename(current->exec_file->f_path.dentry,
63758+ current->exec_file->f_path.mnt) :
63759+ curr->filename, curr->filename,
63760+ &fakeip, 0, type,
63761+ protocol, GR_BIND, &current->signal->saved_ip);
63762+ }
63763+ /* we'll log when they use connect or bind */
63764+ goto exit;
63765+ }
63766+
63767+exit_fail:
63768+ if (domain == PF_INET)
63769+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63770+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63771+ else
63772+#ifndef CONFIG_IPV6
63773+ if (domain != PF_INET6)
63774+#endif
63775+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63776+ gr_socktype_to_name(type), protocol);
63777+
63778+ return 0;
63779+exit:
63780+ return 1;
63781+}
63782+
63783+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)
63784+{
63785+ if ((ip->mode & mode) &&
63786+ (ip_port >= ip->low) &&
63787+ (ip_port <= ip->high) &&
63788+ ((ntohl(ip_addr) & our_netmask) ==
63789+ (ntohl(our_addr) & our_netmask))
63790+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63791+ && (ip->type & (1U << type))) {
63792+ if (ip->mode & GR_INVERT)
63793+ return 2; // specifically denied
63794+ else
63795+ return 1; // allowed
63796+ }
63797+
63798+ return 0; // not specifically allowed, may continue parsing
63799+}
63800+
63801+static int
63802+gr_search_connectbind(const int full_mode, struct sock *sk,
63803+ struct sockaddr_in *addr, const int type)
63804+{
63805+ char iface[IFNAMSIZ] = {0};
63806+ struct acl_subject_label *curr;
63807+ struct acl_ip_label *ip;
63808+ struct inet_sock *isk;
63809+ struct net_device *dev;
63810+ struct in_device *idev;
63811+ unsigned long i;
63812+ int ret;
63813+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63814+ __u32 ip_addr = 0;
63815+ __u32 our_addr;
63816+ __u32 our_netmask;
63817+ char *p;
63818+ __u16 ip_port = 0;
63819+ const struct cred *cred = current_cred();
63820+
63821+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63822+ return 0;
63823+
63824+ curr = current->acl;
63825+ isk = inet_sk(sk);
63826+
63827+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63828+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63829+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63830+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63831+ struct sockaddr_in saddr;
63832+ int err;
63833+
63834+ saddr.sin_family = AF_INET;
63835+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63836+ saddr.sin_port = isk->inet_sport;
63837+
63838+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63839+ if (err)
63840+ return err;
63841+
63842+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63843+ if (err)
63844+ return err;
63845+ }
63846+
63847+ if (!curr->ips)
63848+ return 0;
63849+
63850+ ip_addr = addr->sin_addr.s_addr;
63851+ ip_port = ntohs(addr->sin_port);
63852+
63853+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63854+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63855+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63856+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63857+ gr_to_filename(current->exec_file->f_path.dentry,
63858+ current->exec_file->f_path.mnt) :
63859+ curr->filename, curr->filename,
63860+ &ip_addr, ip_port, type,
63861+ sk->sk_protocol, mode, &current->signal->saved_ip);
63862+ return 0;
63863+ }
63864+
63865+ for (i = 0; i < curr->ip_num; i++) {
63866+ ip = *(curr->ips + i);
63867+ if (ip->iface != NULL) {
63868+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63869+ p = strchr(iface, ':');
63870+ if (p != NULL)
63871+ *p = '\0';
63872+ dev = dev_get_by_name(sock_net(sk), iface);
63873+ if (dev == NULL)
63874+ continue;
63875+ idev = in_dev_get(dev);
63876+ if (idev == NULL) {
63877+ dev_put(dev);
63878+ continue;
63879+ }
63880+ rcu_read_lock();
63881+ for_ifa(idev) {
63882+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63883+ our_addr = ifa->ifa_address;
63884+ our_netmask = 0xffffffff;
63885+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63886+ if (ret == 1) {
63887+ rcu_read_unlock();
63888+ in_dev_put(idev);
63889+ dev_put(dev);
63890+ return 0;
63891+ } else if (ret == 2) {
63892+ rcu_read_unlock();
63893+ in_dev_put(idev);
63894+ dev_put(dev);
63895+ goto denied;
63896+ }
63897+ }
63898+ } endfor_ifa(idev);
63899+ rcu_read_unlock();
63900+ in_dev_put(idev);
63901+ dev_put(dev);
63902+ } else {
63903+ our_addr = ip->addr;
63904+ our_netmask = ip->netmask;
63905+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63906+ if (ret == 1)
63907+ return 0;
63908+ else if (ret == 2)
63909+ goto denied;
63910+ }
63911+ }
63912+
63913+denied:
63914+ if (mode == GR_BIND)
63915+ 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));
63916+ else if (mode == GR_CONNECT)
63917+ 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));
63918+
63919+ return -EACCES;
63920+}
63921+
63922+int
63923+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63924+{
63925+ /* always allow disconnection of dgram sockets with connect */
63926+ if (addr->sin_family == AF_UNSPEC)
63927+ return 0;
63928+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63929+}
63930+
63931+int
63932+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63933+{
63934+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63935+}
63936+
63937+int gr_search_listen(struct socket *sock)
63938+{
63939+ struct sock *sk = sock->sk;
63940+ struct sockaddr_in addr;
63941+
63942+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63943+ addr.sin_port = inet_sk(sk)->inet_sport;
63944+
63945+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63946+}
63947+
63948+int gr_search_accept(struct socket *sock)
63949+{
63950+ struct sock *sk = sock->sk;
63951+ struct sockaddr_in addr;
63952+
63953+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63954+ addr.sin_port = inet_sk(sk)->inet_sport;
63955+
63956+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63957+}
63958+
63959+int
63960+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63961+{
63962+ if (addr)
63963+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63964+ else {
63965+ struct sockaddr_in sin;
63966+ const struct inet_sock *inet = inet_sk(sk);
63967+
63968+ sin.sin_addr.s_addr = inet->inet_daddr;
63969+ sin.sin_port = inet->inet_dport;
63970+
63971+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63972+ }
63973+}
63974+
63975+int
63976+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63977+{
63978+ struct sockaddr_in sin;
63979+
63980+ if (unlikely(skb->len < sizeof (struct udphdr)))
63981+ return 0; // skip this packet
63982+
63983+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63984+ sin.sin_port = udp_hdr(skb)->source;
63985+
63986+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63987+}
63988diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63989new file mode 100644
63990index 0000000..25f54ef
63991--- /dev/null
63992+++ b/grsecurity/gracl_learn.c
63993@@ -0,0 +1,207 @@
63994+#include <linux/kernel.h>
63995+#include <linux/mm.h>
63996+#include <linux/sched.h>
63997+#include <linux/poll.h>
63998+#include <linux/string.h>
63999+#include <linux/file.h>
64000+#include <linux/types.h>
64001+#include <linux/vmalloc.h>
64002+#include <linux/grinternal.h>
64003+
64004+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
64005+ size_t count, loff_t *ppos);
64006+extern int gr_acl_is_enabled(void);
64007+
64008+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
64009+static int gr_learn_attached;
64010+
64011+/* use a 512k buffer */
64012+#define LEARN_BUFFER_SIZE (512 * 1024)
64013+
64014+static DEFINE_SPINLOCK(gr_learn_lock);
64015+static DEFINE_MUTEX(gr_learn_user_mutex);
64016+
64017+/* we need to maintain two buffers, so that the kernel context of grlearn
64018+ uses a semaphore around the userspace copying, and the other kernel contexts
64019+ use a spinlock when copying into the buffer, since they cannot sleep
64020+*/
64021+static char *learn_buffer;
64022+static char *learn_buffer_user;
64023+static int learn_buffer_len;
64024+static int learn_buffer_user_len;
64025+
64026+static ssize_t
64027+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
64028+{
64029+ DECLARE_WAITQUEUE(wait, current);
64030+ ssize_t retval = 0;
64031+
64032+ add_wait_queue(&learn_wait, &wait);
64033+ set_current_state(TASK_INTERRUPTIBLE);
64034+ do {
64035+ mutex_lock(&gr_learn_user_mutex);
64036+ spin_lock(&gr_learn_lock);
64037+ if (learn_buffer_len)
64038+ break;
64039+ spin_unlock(&gr_learn_lock);
64040+ mutex_unlock(&gr_learn_user_mutex);
64041+ if (file->f_flags & O_NONBLOCK) {
64042+ retval = -EAGAIN;
64043+ goto out;
64044+ }
64045+ if (signal_pending(current)) {
64046+ retval = -ERESTARTSYS;
64047+ goto out;
64048+ }
64049+
64050+ schedule();
64051+ } while (1);
64052+
64053+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
64054+ learn_buffer_user_len = learn_buffer_len;
64055+ retval = learn_buffer_len;
64056+ learn_buffer_len = 0;
64057+
64058+ spin_unlock(&gr_learn_lock);
64059+
64060+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
64061+ retval = -EFAULT;
64062+
64063+ mutex_unlock(&gr_learn_user_mutex);
64064+out:
64065+ set_current_state(TASK_RUNNING);
64066+ remove_wait_queue(&learn_wait, &wait);
64067+ return retval;
64068+}
64069+
64070+static unsigned int
64071+poll_learn(struct file * file, poll_table * wait)
64072+{
64073+ poll_wait(file, &learn_wait, wait);
64074+
64075+ if (learn_buffer_len)
64076+ return (POLLIN | POLLRDNORM);
64077+
64078+ return 0;
64079+}
64080+
64081+void
64082+gr_clear_learn_entries(void)
64083+{
64084+ char *tmp;
64085+
64086+ mutex_lock(&gr_learn_user_mutex);
64087+ spin_lock(&gr_learn_lock);
64088+ tmp = learn_buffer;
64089+ learn_buffer = NULL;
64090+ spin_unlock(&gr_learn_lock);
64091+ if (tmp)
64092+ vfree(tmp);
64093+ if (learn_buffer_user != NULL) {
64094+ vfree(learn_buffer_user);
64095+ learn_buffer_user = NULL;
64096+ }
64097+ learn_buffer_len = 0;
64098+ mutex_unlock(&gr_learn_user_mutex);
64099+
64100+ return;
64101+}
64102+
64103+void
64104+gr_add_learn_entry(const char *fmt, ...)
64105+{
64106+ va_list args;
64107+ unsigned int len;
64108+
64109+ if (!gr_learn_attached)
64110+ return;
64111+
64112+ spin_lock(&gr_learn_lock);
64113+
64114+ /* leave a gap at the end so we know when it's "full" but don't have to
64115+ compute the exact length of the string we're trying to append
64116+ */
64117+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
64118+ spin_unlock(&gr_learn_lock);
64119+ wake_up_interruptible(&learn_wait);
64120+ return;
64121+ }
64122+ if (learn_buffer == NULL) {
64123+ spin_unlock(&gr_learn_lock);
64124+ return;
64125+ }
64126+
64127+ va_start(args, fmt);
64128+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
64129+ va_end(args);
64130+
64131+ learn_buffer_len += len + 1;
64132+
64133+ spin_unlock(&gr_learn_lock);
64134+ wake_up_interruptible(&learn_wait);
64135+
64136+ return;
64137+}
64138+
64139+static int
64140+open_learn(struct inode *inode, struct file *file)
64141+{
64142+ if (file->f_mode & FMODE_READ && gr_learn_attached)
64143+ return -EBUSY;
64144+ if (file->f_mode & FMODE_READ) {
64145+ int retval = 0;
64146+ mutex_lock(&gr_learn_user_mutex);
64147+ if (learn_buffer == NULL)
64148+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
64149+ if (learn_buffer_user == NULL)
64150+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
64151+ if (learn_buffer == NULL) {
64152+ retval = -ENOMEM;
64153+ goto out_error;
64154+ }
64155+ if (learn_buffer_user == NULL) {
64156+ retval = -ENOMEM;
64157+ goto out_error;
64158+ }
64159+ learn_buffer_len = 0;
64160+ learn_buffer_user_len = 0;
64161+ gr_learn_attached = 1;
64162+out_error:
64163+ mutex_unlock(&gr_learn_user_mutex);
64164+ return retval;
64165+ }
64166+ return 0;
64167+}
64168+
64169+static int
64170+close_learn(struct inode *inode, struct file *file)
64171+{
64172+ if (file->f_mode & FMODE_READ) {
64173+ char *tmp = NULL;
64174+ mutex_lock(&gr_learn_user_mutex);
64175+ spin_lock(&gr_learn_lock);
64176+ tmp = learn_buffer;
64177+ learn_buffer = NULL;
64178+ spin_unlock(&gr_learn_lock);
64179+ if (tmp)
64180+ vfree(tmp);
64181+ if (learn_buffer_user != NULL) {
64182+ vfree(learn_buffer_user);
64183+ learn_buffer_user = NULL;
64184+ }
64185+ learn_buffer_len = 0;
64186+ learn_buffer_user_len = 0;
64187+ gr_learn_attached = 0;
64188+ mutex_unlock(&gr_learn_user_mutex);
64189+ }
64190+
64191+ return 0;
64192+}
64193+
64194+const struct file_operations grsec_fops = {
64195+ .read = read_learn,
64196+ .write = write_grsec_handler,
64197+ .open = open_learn,
64198+ .release = close_learn,
64199+ .poll = poll_learn,
64200+};
64201diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
64202new file mode 100644
64203index 0000000..39645c9
64204--- /dev/null
64205+++ b/grsecurity/gracl_res.c
64206@@ -0,0 +1,68 @@
64207+#include <linux/kernel.h>
64208+#include <linux/sched.h>
64209+#include <linux/gracl.h>
64210+#include <linux/grinternal.h>
64211+
64212+static const char *restab_log[] = {
64213+ [RLIMIT_CPU] = "RLIMIT_CPU",
64214+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
64215+ [RLIMIT_DATA] = "RLIMIT_DATA",
64216+ [RLIMIT_STACK] = "RLIMIT_STACK",
64217+ [RLIMIT_CORE] = "RLIMIT_CORE",
64218+ [RLIMIT_RSS] = "RLIMIT_RSS",
64219+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
64220+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
64221+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
64222+ [RLIMIT_AS] = "RLIMIT_AS",
64223+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
64224+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
64225+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
64226+ [RLIMIT_NICE] = "RLIMIT_NICE",
64227+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
64228+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
64229+ [GR_CRASH_RES] = "RLIMIT_CRASH"
64230+};
64231+
64232+void
64233+gr_log_resource(const struct task_struct *task,
64234+ const int res, const unsigned long wanted, const int gt)
64235+{
64236+ const struct cred *cred;
64237+ unsigned long rlim;
64238+
64239+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
64240+ return;
64241+
64242+ // not yet supported resource
64243+ if (unlikely(!restab_log[res]))
64244+ return;
64245+
64246+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
64247+ rlim = task_rlimit_max(task, res);
64248+ else
64249+ rlim = task_rlimit(task, res);
64250+
64251+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
64252+ return;
64253+
64254+ rcu_read_lock();
64255+ cred = __task_cred(task);
64256+
64257+ if (res == RLIMIT_NPROC &&
64258+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
64259+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
64260+ goto out_rcu_unlock;
64261+ else if (res == RLIMIT_MEMLOCK &&
64262+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
64263+ goto out_rcu_unlock;
64264+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
64265+ goto out_rcu_unlock;
64266+ rcu_read_unlock();
64267+
64268+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
64269+
64270+ return;
64271+out_rcu_unlock:
64272+ rcu_read_unlock();
64273+ return;
64274+}
64275diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
64276new file mode 100644
64277index 0000000..3c38bfe
64278--- /dev/null
64279+++ b/grsecurity/gracl_segv.c
64280@@ -0,0 +1,305 @@
64281+#include <linux/kernel.h>
64282+#include <linux/mm.h>
64283+#include <asm/uaccess.h>
64284+#include <asm/errno.h>
64285+#include <asm/mman.h>
64286+#include <net/sock.h>
64287+#include <linux/file.h>
64288+#include <linux/fs.h>
64289+#include <linux/net.h>
64290+#include <linux/in.h>
64291+#include <linux/slab.h>
64292+#include <linux/types.h>
64293+#include <linux/sched.h>
64294+#include <linux/timer.h>
64295+#include <linux/gracl.h>
64296+#include <linux/grsecurity.h>
64297+#include <linux/grinternal.h>
64298+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
64299+#include <linux/magic.h>
64300+#include <linux/pagemap.h>
64301+#include "../fs/btrfs/async-thread.h"
64302+#include "../fs/btrfs/ctree.h"
64303+#include "../fs/btrfs/btrfs_inode.h"
64304+#endif
64305+
64306+static struct crash_uid *uid_set;
64307+static unsigned short uid_used;
64308+static DEFINE_SPINLOCK(gr_uid_lock);
64309+extern rwlock_t gr_inode_lock;
64310+extern struct acl_subject_label *
64311+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
64312+ struct acl_role_label *role);
64313+
64314+static inline dev_t __get_dev(const struct dentry *dentry)
64315+{
64316+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
64317+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
64318+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
64319+ else
64320+#endif
64321+ return dentry->d_sb->s_dev;
64322+}
64323+
64324+int
64325+gr_init_uidset(void)
64326+{
64327+ uid_set =
64328+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
64329+ uid_used = 0;
64330+
64331+ return uid_set ? 1 : 0;
64332+}
64333+
64334+void
64335+gr_free_uidset(void)
64336+{
64337+ if (uid_set)
64338+ kfree(uid_set);
64339+
64340+ return;
64341+}
64342+
64343+int
64344+gr_find_uid(const uid_t uid)
64345+{
64346+ struct crash_uid *tmp = uid_set;
64347+ uid_t buid;
64348+ int low = 0, high = uid_used - 1, mid;
64349+
64350+ while (high >= low) {
64351+ mid = (low + high) >> 1;
64352+ buid = tmp[mid].uid;
64353+ if (buid == uid)
64354+ return mid;
64355+ if (buid > uid)
64356+ high = mid - 1;
64357+ if (buid < uid)
64358+ low = mid + 1;
64359+ }
64360+
64361+ return -1;
64362+}
64363+
64364+static __inline__ void
64365+gr_insertsort(void)
64366+{
64367+ unsigned short i, j;
64368+ struct crash_uid index;
64369+
64370+ for (i = 1; i < uid_used; i++) {
64371+ index = uid_set[i];
64372+ j = i;
64373+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
64374+ uid_set[j] = uid_set[j - 1];
64375+ j--;
64376+ }
64377+ uid_set[j] = index;
64378+ }
64379+
64380+ return;
64381+}
64382+
64383+static __inline__ void
64384+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
64385+{
64386+ int loc;
64387+ uid_t uid = GR_GLOBAL_UID(kuid);
64388+
64389+ if (uid_used == GR_UIDTABLE_MAX)
64390+ return;
64391+
64392+ loc = gr_find_uid(uid);
64393+
64394+ if (loc >= 0) {
64395+ uid_set[loc].expires = expires;
64396+ return;
64397+ }
64398+
64399+ uid_set[uid_used].uid = uid;
64400+ uid_set[uid_used].expires = expires;
64401+ uid_used++;
64402+
64403+ gr_insertsort();
64404+
64405+ return;
64406+}
64407+
64408+void
64409+gr_remove_uid(const unsigned short loc)
64410+{
64411+ unsigned short i;
64412+
64413+ for (i = loc + 1; i < uid_used; i++)
64414+ uid_set[i - 1] = uid_set[i];
64415+
64416+ uid_used--;
64417+
64418+ return;
64419+}
64420+
64421+int
64422+gr_check_crash_uid(const kuid_t kuid)
64423+{
64424+ int loc;
64425+ int ret = 0;
64426+ uid_t uid;
64427+
64428+ if (unlikely(!gr_acl_is_enabled()))
64429+ return 0;
64430+
64431+ uid = GR_GLOBAL_UID(kuid);
64432+
64433+ spin_lock(&gr_uid_lock);
64434+ loc = gr_find_uid(uid);
64435+
64436+ if (loc < 0)
64437+ goto out_unlock;
64438+
64439+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
64440+ gr_remove_uid(loc);
64441+ else
64442+ ret = 1;
64443+
64444+out_unlock:
64445+ spin_unlock(&gr_uid_lock);
64446+ return ret;
64447+}
64448+
64449+static __inline__ int
64450+proc_is_setxid(const struct cred *cred)
64451+{
64452+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
64453+ !uid_eq(cred->uid, cred->fsuid))
64454+ return 1;
64455+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
64456+ !gid_eq(cred->gid, cred->fsgid))
64457+ return 1;
64458+
64459+ return 0;
64460+}
64461+
64462+extern int gr_fake_force_sig(int sig, struct task_struct *t);
64463+
64464+void
64465+gr_handle_crash(struct task_struct *task, const int sig)
64466+{
64467+ struct acl_subject_label *curr;
64468+ struct task_struct *tsk, *tsk2;
64469+ const struct cred *cred;
64470+ const struct cred *cred2;
64471+
64472+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
64473+ return;
64474+
64475+ if (unlikely(!gr_acl_is_enabled()))
64476+ return;
64477+
64478+ curr = task->acl;
64479+
64480+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
64481+ return;
64482+
64483+ if (time_before_eq(curr->expires, get_seconds())) {
64484+ curr->expires = 0;
64485+ curr->crashes = 0;
64486+ }
64487+
64488+ curr->crashes++;
64489+
64490+ if (!curr->expires)
64491+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
64492+
64493+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
64494+ time_after(curr->expires, get_seconds())) {
64495+ rcu_read_lock();
64496+ cred = __task_cred(task);
64497+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
64498+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
64499+ spin_lock(&gr_uid_lock);
64500+ gr_insert_uid(cred->uid, curr->expires);
64501+ spin_unlock(&gr_uid_lock);
64502+ curr->expires = 0;
64503+ curr->crashes = 0;
64504+ read_lock(&tasklist_lock);
64505+ do_each_thread(tsk2, tsk) {
64506+ cred2 = __task_cred(tsk);
64507+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
64508+ gr_fake_force_sig(SIGKILL, tsk);
64509+ } while_each_thread(tsk2, tsk);
64510+ read_unlock(&tasklist_lock);
64511+ } else {
64512+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
64513+ read_lock(&tasklist_lock);
64514+ read_lock(&grsec_exec_file_lock);
64515+ do_each_thread(tsk2, tsk) {
64516+ if (likely(tsk != task)) {
64517+ // if this thread has the same subject as the one that triggered
64518+ // RES_CRASH and it's the same binary, kill it
64519+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
64520+ gr_fake_force_sig(SIGKILL, tsk);
64521+ }
64522+ } while_each_thread(tsk2, tsk);
64523+ read_unlock(&grsec_exec_file_lock);
64524+ read_unlock(&tasklist_lock);
64525+ }
64526+ rcu_read_unlock();
64527+ }
64528+
64529+ return;
64530+}
64531+
64532+int
64533+gr_check_crash_exec(const struct file *filp)
64534+{
64535+ struct acl_subject_label *curr;
64536+
64537+ if (unlikely(!gr_acl_is_enabled()))
64538+ return 0;
64539+
64540+ read_lock(&gr_inode_lock);
64541+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
64542+ __get_dev(filp->f_path.dentry),
64543+ current->role);
64544+ read_unlock(&gr_inode_lock);
64545+
64546+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
64547+ (!curr->crashes && !curr->expires))
64548+ return 0;
64549+
64550+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
64551+ time_after(curr->expires, get_seconds()))
64552+ return 1;
64553+ else if (time_before_eq(curr->expires, get_seconds())) {
64554+ curr->crashes = 0;
64555+ curr->expires = 0;
64556+ }
64557+
64558+ return 0;
64559+}
64560+
64561+void
64562+gr_handle_alertkill(struct task_struct *task)
64563+{
64564+ struct acl_subject_label *curracl;
64565+ __u32 curr_ip;
64566+ struct task_struct *p, *p2;
64567+
64568+ if (unlikely(!gr_acl_is_enabled()))
64569+ return;
64570+
64571+ curracl = task->acl;
64572+ curr_ip = task->signal->curr_ip;
64573+
64574+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
64575+ read_lock(&tasklist_lock);
64576+ do_each_thread(p2, p) {
64577+ if (p->signal->curr_ip == curr_ip)
64578+ gr_fake_force_sig(SIGKILL, p);
64579+ } while_each_thread(p2, p);
64580+ read_unlock(&tasklist_lock);
64581+ } else if (curracl->mode & GR_KILLPROC)
64582+ gr_fake_force_sig(SIGKILL, task);
64583+
64584+ return;
64585+}
64586diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
64587new file mode 100644
64588index 0000000..98011b0
64589--- /dev/null
64590+++ b/grsecurity/gracl_shm.c
64591@@ -0,0 +1,40 @@
64592+#include <linux/kernel.h>
64593+#include <linux/mm.h>
64594+#include <linux/sched.h>
64595+#include <linux/file.h>
64596+#include <linux/ipc.h>
64597+#include <linux/gracl.h>
64598+#include <linux/grsecurity.h>
64599+#include <linux/grinternal.h>
64600+
64601+int
64602+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64603+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64604+{
64605+ struct task_struct *task;
64606+
64607+ if (!gr_acl_is_enabled())
64608+ return 1;
64609+
64610+ rcu_read_lock();
64611+ read_lock(&tasklist_lock);
64612+
64613+ task = find_task_by_vpid(shm_cprid);
64614+
64615+ if (unlikely(!task))
64616+ task = find_task_by_vpid(shm_lapid);
64617+
64618+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
64619+ (task_pid_nr(task) == shm_lapid)) &&
64620+ (task->acl->mode & GR_PROTSHM) &&
64621+ (task->acl != current->acl))) {
64622+ read_unlock(&tasklist_lock);
64623+ rcu_read_unlock();
64624+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
64625+ return 0;
64626+ }
64627+ read_unlock(&tasklist_lock);
64628+ rcu_read_unlock();
64629+
64630+ return 1;
64631+}
64632diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
64633new file mode 100644
64634index 0000000..bc0be01
64635--- /dev/null
64636+++ b/grsecurity/grsec_chdir.c
64637@@ -0,0 +1,19 @@
64638+#include <linux/kernel.h>
64639+#include <linux/sched.h>
64640+#include <linux/fs.h>
64641+#include <linux/file.h>
64642+#include <linux/grsecurity.h>
64643+#include <linux/grinternal.h>
64644+
64645+void
64646+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
64647+{
64648+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64649+ if ((grsec_enable_chdir && grsec_enable_group &&
64650+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
64651+ !grsec_enable_group)) {
64652+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
64653+ }
64654+#endif
64655+ return;
64656+}
64657diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
64658new file mode 100644
64659index 0000000..bd6e105
64660--- /dev/null
64661+++ b/grsecurity/grsec_chroot.c
64662@@ -0,0 +1,370 @@
64663+#include <linux/kernel.h>
64664+#include <linux/module.h>
64665+#include <linux/sched.h>
64666+#include <linux/file.h>
64667+#include <linux/fs.h>
64668+#include <linux/mount.h>
64669+#include <linux/types.h>
64670+#include "../fs/mount.h"
64671+#include <linux/grsecurity.h>
64672+#include <linux/grinternal.h>
64673+
64674+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64675+static int gr_init_ran;
64676+#endif
64677+
64678+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
64679+{
64680+#ifdef CONFIG_GRKERNSEC
64681+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64682+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
64683+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64684+ && gr_init_ran
64685+#endif
64686+ )
64687+ task->gr_is_chrooted = 1;
64688+ else {
64689+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64690+ if (task_pid_nr(task) == 1 && !gr_init_ran)
64691+ gr_init_ran = 1;
64692+#endif
64693+ task->gr_is_chrooted = 0;
64694+ }
64695+
64696+ task->gr_chroot_dentry = path->dentry;
64697+#endif
64698+ return;
64699+}
64700+
64701+void gr_clear_chroot_entries(struct task_struct *task)
64702+{
64703+#ifdef CONFIG_GRKERNSEC
64704+ task->gr_is_chrooted = 0;
64705+ task->gr_chroot_dentry = NULL;
64706+#endif
64707+ return;
64708+}
64709+
64710+int
64711+gr_handle_chroot_unix(const pid_t pid)
64712+{
64713+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64714+ struct task_struct *p;
64715+
64716+ if (unlikely(!grsec_enable_chroot_unix))
64717+ return 1;
64718+
64719+ if (likely(!proc_is_chrooted(current)))
64720+ return 1;
64721+
64722+ rcu_read_lock();
64723+ read_lock(&tasklist_lock);
64724+ p = find_task_by_vpid_unrestricted(pid);
64725+ if (unlikely(p && !have_same_root(current, p))) {
64726+ read_unlock(&tasklist_lock);
64727+ rcu_read_unlock();
64728+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64729+ return 0;
64730+ }
64731+ read_unlock(&tasklist_lock);
64732+ rcu_read_unlock();
64733+#endif
64734+ return 1;
64735+}
64736+
64737+int
64738+gr_handle_chroot_nice(void)
64739+{
64740+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64741+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64742+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64743+ return -EPERM;
64744+ }
64745+#endif
64746+ return 0;
64747+}
64748+
64749+int
64750+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64751+{
64752+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64753+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64754+ && proc_is_chrooted(current)) {
64755+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64756+ return -EACCES;
64757+ }
64758+#endif
64759+ return 0;
64760+}
64761+
64762+int
64763+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64764+{
64765+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64766+ struct task_struct *p;
64767+ int ret = 0;
64768+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64769+ return ret;
64770+
64771+ read_lock(&tasklist_lock);
64772+ do_each_pid_task(pid, type, p) {
64773+ if (!have_same_root(current, p)) {
64774+ ret = 1;
64775+ goto out;
64776+ }
64777+ } while_each_pid_task(pid, type, p);
64778+out:
64779+ read_unlock(&tasklist_lock);
64780+ return ret;
64781+#endif
64782+ return 0;
64783+}
64784+
64785+int
64786+gr_pid_is_chrooted(struct task_struct *p)
64787+{
64788+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64789+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64790+ return 0;
64791+
64792+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64793+ !have_same_root(current, p)) {
64794+ return 1;
64795+ }
64796+#endif
64797+ return 0;
64798+}
64799+
64800+EXPORT_SYMBOL(gr_pid_is_chrooted);
64801+
64802+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64803+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64804+{
64805+ struct path path, currentroot;
64806+ int ret = 0;
64807+
64808+ path.dentry = (struct dentry *)u_dentry;
64809+ path.mnt = (struct vfsmount *)u_mnt;
64810+ get_fs_root(current->fs, &currentroot);
64811+ if (path_is_under(&path, &currentroot))
64812+ ret = 1;
64813+ path_put(&currentroot);
64814+
64815+ return ret;
64816+}
64817+#endif
64818+
64819+int
64820+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64821+{
64822+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64823+ if (!grsec_enable_chroot_fchdir)
64824+ return 1;
64825+
64826+ if (!proc_is_chrooted(current))
64827+ return 1;
64828+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64829+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64830+ return 0;
64831+ }
64832+#endif
64833+ return 1;
64834+}
64835+
64836+int
64837+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64838+ const time_t shm_createtime)
64839+{
64840+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64841+ struct task_struct *p;
64842+ time_t starttime;
64843+
64844+ if (unlikely(!grsec_enable_chroot_shmat))
64845+ return 1;
64846+
64847+ if (likely(!proc_is_chrooted(current)))
64848+ return 1;
64849+
64850+ rcu_read_lock();
64851+ read_lock(&tasklist_lock);
64852+
64853+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64854+ starttime = p->start_time.tv_sec;
64855+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64856+ if (have_same_root(current, p)) {
64857+ goto allow;
64858+ } else {
64859+ read_unlock(&tasklist_lock);
64860+ rcu_read_unlock();
64861+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64862+ return 0;
64863+ }
64864+ }
64865+ /* creator exited, pid reuse, fall through to next check */
64866+ }
64867+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64868+ if (unlikely(!have_same_root(current, p))) {
64869+ read_unlock(&tasklist_lock);
64870+ rcu_read_unlock();
64871+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64872+ return 0;
64873+ }
64874+ }
64875+
64876+allow:
64877+ read_unlock(&tasklist_lock);
64878+ rcu_read_unlock();
64879+#endif
64880+ return 1;
64881+}
64882+
64883+void
64884+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64885+{
64886+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64887+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64888+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64889+#endif
64890+ return;
64891+}
64892+
64893+int
64894+gr_handle_chroot_mknod(const struct dentry *dentry,
64895+ const struct vfsmount *mnt, const int mode)
64896+{
64897+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64898+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64899+ proc_is_chrooted(current)) {
64900+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64901+ return -EPERM;
64902+ }
64903+#endif
64904+ return 0;
64905+}
64906+
64907+int
64908+gr_handle_chroot_mount(const struct dentry *dentry,
64909+ const struct vfsmount *mnt, const char *dev_name)
64910+{
64911+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64912+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64913+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64914+ return -EPERM;
64915+ }
64916+#endif
64917+ return 0;
64918+}
64919+
64920+int
64921+gr_handle_chroot_pivot(void)
64922+{
64923+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64924+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64925+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64926+ return -EPERM;
64927+ }
64928+#endif
64929+ return 0;
64930+}
64931+
64932+int
64933+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64934+{
64935+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64936+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64937+ !gr_is_outside_chroot(dentry, mnt)) {
64938+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64939+ return -EPERM;
64940+ }
64941+#endif
64942+ return 0;
64943+}
64944+
64945+extern const char *captab_log[];
64946+extern int captab_log_entries;
64947+
64948+int
64949+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64950+{
64951+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64952+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64953+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64954+ if (cap_raised(chroot_caps, cap)) {
64955+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64956+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64957+ }
64958+ return 0;
64959+ }
64960+ }
64961+#endif
64962+ return 1;
64963+}
64964+
64965+int
64966+gr_chroot_is_capable(const int cap)
64967+{
64968+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64969+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64970+#endif
64971+ return 1;
64972+}
64973+
64974+int
64975+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64976+{
64977+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64978+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64979+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64980+ if (cap_raised(chroot_caps, cap)) {
64981+ return 0;
64982+ }
64983+ }
64984+#endif
64985+ return 1;
64986+}
64987+
64988+int
64989+gr_chroot_is_capable_nolog(const int cap)
64990+{
64991+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64992+ return gr_task_chroot_is_capable_nolog(current, cap);
64993+#endif
64994+ return 1;
64995+}
64996+
64997+int
64998+gr_handle_chroot_sysctl(const int op)
64999+{
65000+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65001+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
65002+ proc_is_chrooted(current))
65003+ return -EACCES;
65004+#endif
65005+ return 0;
65006+}
65007+
65008+void
65009+gr_handle_chroot_chdir(const struct path *path)
65010+{
65011+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65012+ if (grsec_enable_chroot_chdir)
65013+ set_fs_pwd(current->fs, path);
65014+#endif
65015+ return;
65016+}
65017+
65018+int
65019+gr_handle_chroot_chmod(const struct dentry *dentry,
65020+ const struct vfsmount *mnt, const int mode)
65021+{
65022+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65023+ /* allow chmod +s on directories, but not files */
65024+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
65025+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
65026+ proc_is_chrooted(current)) {
65027+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
65028+ return -EPERM;
65029+ }
65030+#endif
65031+ return 0;
65032+}
65033diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
65034new file mode 100644
65035index 0000000..ce65ceb
65036--- /dev/null
65037+++ b/grsecurity/grsec_disabled.c
65038@@ -0,0 +1,434 @@
65039+#include <linux/kernel.h>
65040+#include <linux/module.h>
65041+#include <linux/sched.h>
65042+#include <linux/file.h>
65043+#include <linux/fs.h>
65044+#include <linux/kdev_t.h>
65045+#include <linux/net.h>
65046+#include <linux/in.h>
65047+#include <linux/ip.h>
65048+#include <linux/skbuff.h>
65049+#include <linux/sysctl.h>
65050+
65051+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
65052+void
65053+pax_set_initial_flags(struct linux_binprm *bprm)
65054+{
65055+ return;
65056+}
65057+#endif
65058+
65059+#ifdef CONFIG_SYSCTL
65060+__u32
65061+gr_handle_sysctl(const struct ctl_table * table, const int op)
65062+{
65063+ return 0;
65064+}
65065+#endif
65066+
65067+#ifdef CONFIG_TASKSTATS
65068+int gr_is_taskstats_denied(int pid)
65069+{
65070+ return 0;
65071+}
65072+#endif
65073+
65074+int
65075+gr_acl_is_enabled(void)
65076+{
65077+ return 0;
65078+}
65079+
65080+void
65081+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65082+{
65083+ return;
65084+}
65085+
65086+int
65087+gr_handle_rawio(const struct inode *inode)
65088+{
65089+ return 0;
65090+}
65091+
65092+void
65093+gr_acl_handle_psacct(struct task_struct *task, const long code)
65094+{
65095+ return;
65096+}
65097+
65098+int
65099+gr_handle_ptrace(struct task_struct *task, const long request)
65100+{
65101+ return 0;
65102+}
65103+
65104+int
65105+gr_handle_proc_ptrace(struct task_struct *task)
65106+{
65107+ return 0;
65108+}
65109+
65110+int
65111+gr_set_acls(const int type)
65112+{
65113+ return 0;
65114+}
65115+
65116+int
65117+gr_check_hidden_task(const struct task_struct *tsk)
65118+{
65119+ return 0;
65120+}
65121+
65122+int
65123+gr_check_protected_task(const struct task_struct *task)
65124+{
65125+ return 0;
65126+}
65127+
65128+int
65129+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
65130+{
65131+ return 0;
65132+}
65133+
65134+void
65135+gr_copy_label(struct task_struct *tsk)
65136+{
65137+ return;
65138+}
65139+
65140+void
65141+gr_set_pax_flags(struct task_struct *task)
65142+{
65143+ return;
65144+}
65145+
65146+int
65147+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
65148+ const int unsafe_share)
65149+{
65150+ return 0;
65151+}
65152+
65153+void
65154+gr_handle_delete(const ino_t ino, const dev_t dev)
65155+{
65156+ return;
65157+}
65158+
65159+void
65160+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65161+{
65162+ return;
65163+}
65164+
65165+void
65166+gr_handle_crash(struct task_struct *task, const int sig)
65167+{
65168+ return;
65169+}
65170+
65171+int
65172+gr_check_crash_exec(const struct file *filp)
65173+{
65174+ return 0;
65175+}
65176+
65177+int
65178+gr_check_crash_uid(const kuid_t uid)
65179+{
65180+ return 0;
65181+}
65182+
65183+void
65184+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65185+ struct dentry *old_dentry,
65186+ struct dentry *new_dentry,
65187+ struct vfsmount *mnt, const __u8 replace)
65188+{
65189+ return;
65190+}
65191+
65192+int
65193+gr_search_socket(const int family, const int type, const int protocol)
65194+{
65195+ return 1;
65196+}
65197+
65198+int
65199+gr_search_connectbind(const int mode, const struct socket *sock,
65200+ const struct sockaddr_in *addr)
65201+{
65202+ return 0;
65203+}
65204+
65205+void
65206+gr_handle_alertkill(struct task_struct *task)
65207+{
65208+ return;
65209+}
65210+
65211+__u32
65212+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
65213+{
65214+ return 1;
65215+}
65216+
65217+__u32
65218+gr_acl_handle_hidden_file(const struct dentry * dentry,
65219+ const struct vfsmount * mnt)
65220+{
65221+ return 1;
65222+}
65223+
65224+__u32
65225+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
65226+ int acc_mode)
65227+{
65228+ return 1;
65229+}
65230+
65231+__u32
65232+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
65233+{
65234+ return 1;
65235+}
65236+
65237+__u32
65238+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
65239+{
65240+ return 1;
65241+}
65242+
65243+int
65244+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
65245+ unsigned int *vm_flags)
65246+{
65247+ return 1;
65248+}
65249+
65250+__u32
65251+gr_acl_handle_truncate(const struct dentry * dentry,
65252+ const struct vfsmount * mnt)
65253+{
65254+ return 1;
65255+}
65256+
65257+__u32
65258+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
65259+{
65260+ return 1;
65261+}
65262+
65263+__u32
65264+gr_acl_handle_access(const struct dentry * dentry,
65265+ const struct vfsmount * mnt, const int fmode)
65266+{
65267+ return 1;
65268+}
65269+
65270+__u32
65271+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
65272+ umode_t *mode)
65273+{
65274+ return 1;
65275+}
65276+
65277+__u32
65278+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
65279+{
65280+ return 1;
65281+}
65282+
65283+__u32
65284+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
65285+{
65286+ return 1;
65287+}
65288+
65289+void
65290+grsecurity_init(void)
65291+{
65292+ return;
65293+}
65294+
65295+umode_t gr_acl_umask(void)
65296+{
65297+ return 0;
65298+}
65299+
65300+__u32
65301+gr_acl_handle_mknod(const struct dentry * new_dentry,
65302+ const struct dentry * parent_dentry,
65303+ const struct vfsmount * parent_mnt,
65304+ const int mode)
65305+{
65306+ return 1;
65307+}
65308+
65309+__u32
65310+gr_acl_handle_mkdir(const struct dentry * new_dentry,
65311+ const struct dentry * parent_dentry,
65312+ const struct vfsmount * parent_mnt)
65313+{
65314+ return 1;
65315+}
65316+
65317+__u32
65318+gr_acl_handle_symlink(const struct dentry * new_dentry,
65319+ const struct dentry * parent_dentry,
65320+ const struct vfsmount * parent_mnt, const struct filename *from)
65321+{
65322+ return 1;
65323+}
65324+
65325+__u32
65326+gr_acl_handle_link(const struct dentry * new_dentry,
65327+ const struct dentry * parent_dentry,
65328+ const struct vfsmount * parent_mnt,
65329+ const struct dentry * old_dentry,
65330+ const struct vfsmount * old_mnt, const struct filename *to)
65331+{
65332+ return 1;
65333+}
65334+
65335+int
65336+gr_acl_handle_rename(const struct dentry *new_dentry,
65337+ const struct dentry *parent_dentry,
65338+ const struct vfsmount *parent_mnt,
65339+ const struct dentry *old_dentry,
65340+ const struct inode *old_parent_inode,
65341+ const struct vfsmount *old_mnt, const struct filename *newname)
65342+{
65343+ return 0;
65344+}
65345+
65346+int
65347+gr_acl_handle_filldir(const struct file *file, const char *name,
65348+ const int namelen, const ino_t ino)
65349+{
65350+ return 1;
65351+}
65352+
65353+int
65354+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
65355+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
65356+{
65357+ return 1;
65358+}
65359+
65360+int
65361+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
65362+{
65363+ return 0;
65364+}
65365+
65366+int
65367+gr_search_accept(const struct socket *sock)
65368+{
65369+ return 0;
65370+}
65371+
65372+int
65373+gr_search_listen(const struct socket *sock)
65374+{
65375+ return 0;
65376+}
65377+
65378+int
65379+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
65380+{
65381+ return 0;
65382+}
65383+
65384+__u32
65385+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
65386+{
65387+ return 1;
65388+}
65389+
65390+__u32
65391+gr_acl_handle_creat(const struct dentry * dentry,
65392+ const struct dentry * p_dentry,
65393+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
65394+ const int imode)
65395+{
65396+ return 1;
65397+}
65398+
65399+void
65400+gr_acl_handle_exit(void)
65401+{
65402+ return;
65403+}
65404+
65405+int
65406+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
65407+{
65408+ return 1;
65409+}
65410+
65411+void
65412+gr_set_role_label(const kuid_t uid, const kgid_t gid)
65413+{
65414+ return;
65415+}
65416+
65417+int
65418+gr_acl_handle_procpidmem(const struct task_struct *task)
65419+{
65420+ return 0;
65421+}
65422+
65423+int
65424+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
65425+{
65426+ return 0;
65427+}
65428+
65429+int
65430+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
65431+{
65432+ return 0;
65433+}
65434+
65435+void
65436+gr_set_kernel_label(struct task_struct *task)
65437+{
65438+ return;
65439+}
65440+
65441+int
65442+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
65443+{
65444+ return 0;
65445+}
65446+
65447+int
65448+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
65449+{
65450+ return 0;
65451+}
65452+
65453+int gr_acl_enable_at_secure(void)
65454+{
65455+ return 0;
65456+}
65457+
65458+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65459+{
65460+ return dentry->d_sb->s_dev;
65461+}
65462+
65463+void gr_put_exec_file(struct task_struct *task)
65464+{
65465+ return;
65466+}
65467+
65468+EXPORT_SYMBOL(gr_set_kernel_label);
65469+#ifdef CONFIG_SECURITY
65470+EXPORT_SYMBOL(gr_check_user_change);
65471+EXPORT_SYMBOL(gr_check_group_change);
65472+#endif
65473diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
65474new file mode 100644
65475index 0000000..387032b
65476--- /dev/null
65477+++ b/grsecurity/grsec_exec.c
65478@@ -0,0 +1,187 @@
65479+#include <linux/kernel.h>
65480+#include <linux/sched.h>
65481+#include <linux/file.h>
65482+#include <linux/binfmts.h>
65483+#include <linux/fs.h>
65484+#include <linux/types.h>
65485+#include <linux/grdefs.h>
65486+#include <linux/grsecurity.h>
65487+#include <linux/grinternal.h>
65488+#include <linux/capability.h>
65489+#include <linux/module.h>
65490+#include <linux/compat.h>
65491+
65492+#include <asm/uaccess.h>
65493+
65494+#ifdef CONFIG_GRKERNSEC_EXECLOG
65495+static char gr_exec_arg_buf[132];
65496+static DEFINE_MUTEX(gr_exec_arg_mutex);
65497+#endif
65498+
65499+struct user_arg_ptr {
65500+#ifdef CONFIG_COMPAT
65501+ bool is_compat;
65502+#endif
65503+ union {
65504+ const char __user *const __user *native;
65505+#ifdef CONFIG_COMPAT
65506+ const compat_uptr_t __user *compat;
65507+#endif
65508+ } ptr;
65509+};
65510+
65511+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
65512+
65513+void
65514+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
65515+{
65516+#ifdef CONFIG_GRKERNSEC_EXECLOG
65517+ char *grarg = gr_exec_arg_buf;
65518+ unsigned int i, x, execlen = 0;
65519+ char c;
65520+
65521+ if (!((grsec_enable_execlog && grsec_enable_group &&
65522+ in_group_p(grsec_audit_gid))
65523+ || (grsec_enable_execlog && !grsec_enable_group)))
65524+ return;
65525+
65526+ mutex_lock(&gr_exec_arg_mutex);
65527+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
65528+
65529+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
65530+ const char __user *p;
65531+ unsigned int len;
65532+
65533+ p = get_user_arg_ptr(argv, i);
65534+ if (IS_ERR(p))
65535+ goto log;
65536+
65537+ len = strnlen_user(p, 128 - execlen);
65538+ if (len > 128 - execlen)
65539+ len = 128 - execlen;
65540+ else if (len > 0)
65541+ len--;
65542+ if (copy_from_user(grarg + execlen, p, len))
65543+ goto log;
65544+
65545+ /* rewrite unprintable characters */
65546+ for (x = 0; x < len; x++) {
65547+ c = *(grarg + execlen + x);
65548+ if (c < 32 || c > 126)
65549+ *(grarg + execlen + x) = ' ';
65550+ }
65551+
65552+ execlen += len;
65553+ *(grarg + execlen) = ' ';
65554+ *(grarg + execlen + 1) = '\0';
65555+ execlen++;
65556+ }
65557+
65558+ log:
65559+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
65560+ bprm->file->f_path.mnt, grarg);
65561+ mutex_unlock(&gr_exec_arg_mutex);
65562+#endif
65563+ return;
65564+}
65565+
65566+#ifdef CONFIG_GRKERNSEC
65567+extern int gr_acl_is_capable(const int cap);
65568+extern int gr_acl_is_capable_nolog(const int cap);
65569+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65570+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
65571+extern int gr_chroot_is_capable(const int cap);
65572+extern int gr_chroot_is_capable_nolog(const int cap);
65573+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65574+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
65575+#endif
65576+
65577+const char *captab_log[] = {
65578+ "CAP_CHOWN",
65579+ "CAP_DAC_OVERRIDE",
65580+ "CAP_DAC_READ_SEARCH",
65581+ "CAP_FOWNER",
65582+ "CAP_FSETID",
65583+ "CAP_KILL",
65584+ "CAP_SETGID",
65585+ "CAP_SETUID",
65586+ "CAP_SETPCAP",
65587+ "CAP_LINUX_IMMUTABLE",
65588+ "CAP_NET_BIND_SERVICE",
65589+ "CAP_NET_BROADCAST",
65590+ "CAP_NET_ADMIN",
65591+ "CAP_NET_RAW",
65592+ "CAP_IPC_LOCK",
65593+ "CAP_IPC_OWNER",
65594+ "CAP_SYS_MODULE",
65595+ "CAP_SYS_RAWIO",
65596+ "CAP_SYS_CHROOT",
65597+ "CAP_SYS_PTRACE",
65598+ "CAP_SYS_PACCT",
65599+ "CAP_SYS_ADMIN",
65600+ "CAP_SYS_BOOT",
65601+ "CAP_SYS_NICE",
65602+ "CAP_SYS_RESOURCE",
65603+ "CAP_SYS_TIME",
65604+ "CAP_SYS_TTY_CONFIG",
65605+ "CAP_MKNOD",
65606+ "CAP_LEASE",
65607+ "CAP_AUDIT_WRITE",
65608+ "CAP_AUDIT_CONTROL",
65609+ "CAP_SETFCAP",
65610+ "CAP_MAC_OVERRIDE",
65611+ "CAP_MAC_ADMIN",
65612+ "CAP_SYSLOG",
65613+ "CAP_WAKE_ALARM"
65614+};
65615+
65616+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
65617+
65618+int gr_is_capable(const int cap)
65619+{
65620+#ifdef CONFIG_GRKERNSEC
65621+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
65622+ return 1;
65623+ return 0;
65624+#else
65625+ return 1;
65626+#endif
65627+}
65628+
65629+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
65630+{
65631+#ifdef CONFIG_GRKERNSEC
65632+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
65633+ return 1;
65634+ return 0;
65635+#else
65636+ return 1;
65637+#endif
65638+}
65639+
65640+int gr_is_capable_nolog(const int cap)
65641+{
65642+#ifdef CONFIG_GRKERNSEC
65643+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
65644+ return 1;
65645+ return 0;
65646+#else
65647+ return 1;
65648+#endif
65649+}
65650+
65651+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
65652+{
65653+#ifdef CONFIG_GRKERNSEC
65654+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
65655+ return 1;
65656+ return 0;
65657+#else
65658+ return 1;
65659+#endif
65660+}
65661+
65662+EXPORT_SYMBOL(gr_is_capable);
65663+EXPORT_SYMBOL(gr_is_capable_nolog);
65664+EXPORT_SYMBOL(gr_task_is_capable);
65665+EXPORT_SYMBOL(gr_task_is_capable_nolog);
65666diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
65667new file mode 100644
65668index 0000000..06cc6ea
65669--- /dev/null
65670+++ b/grsecurity/grsec_fifo.c
65671@@ -0,0 +1,24 @@
65672+#include <linux/kernel.h>
65673+#include <linux/sched.h>
65674+#include <linux/fs.h>
65675+#include <linux/file.h>
65676+#include <linux/grinternal.h>
65677+
65678+int
65679+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
65680+ const struct dentry *dir, const int flag, const int acc_mode)
65681+{
65682+#ifdef CONFIG_GRKERNSEC_FIFO
65683+ const struct cred *cred = current_cred();
65684+
65685+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65686+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65687+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65688+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65689+ if (!inode_permission(dentry->d_inode, acc_mode))
65690+ 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));
65691+ return -EACCES;
65692+ }
65693+#endif
65694+ return 0;
65695+}
65696diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65697new file mode 100644
65698index 0000000..8ca18bf
65699--- /dev/null
65700+++ b/grsecurity/grsec_fork.c
65701@@ -0,0 +1,23 @@
65702+#include <linux/kernel.h>
65703+#include <linux/sched.h>
65704+#include <linux/grsecurity.h>
65705+#include <linux/grinternal.h>
65706+#include <linux/errno.h>
65707+
65708+void
65709+gr_log_forkfail(const int retval)
65710+{
65711+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65712+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65713+ switch (retval) {
65714+ case -EAGAIN:
65715+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65716+ break;
65717+ case -ENOMEM:
65718+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65719+ break;
65720+ }
65721+ }
65722+#endif
65723+ return;
65724+}
65725diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65726new file mode 100644
65727index 0000000..ab2d875
65728--- /dev/null
65729+++ b/grsecurity/grsec_init.c
65730@@ -0,0 +1,279 @@
65731+#include <linux/kernel.h>
65732+#include <linux/sched.h>
65733+#include <linux/mm.h>
65734+#include <linux/gracl.h>
65735+#include <linux/slab.h>
65736+#include <linux/vmalloc.h>
65737+#include <linux/percpu.h>
65738+#include <linux/module.h>
65739+
65740+int grsec_enable_ptrace_readexec;
65741+int grsec_enable_setxid;
65742+int grsec_enable_symlinkown;
65743+kgid_t grsec_symlinkown_gid;
65744+int grsec_enable_brute;
65745+int grsec_enable_link;
65746+int grsec_enable_dmesg;
65747+int grsec_enable_harden_ptrace;
65748+int grsec_enable_fifo;
65749+int grsec_enable_execlog;
65750+int grsec_enable_signal;
65751+int grsec_enable_forkfail;
65752+int grsec_enable_audit_ptrace;
65753+int grsec_enable_time;
65754+int grsec_enable_group;
65755+kgid_t grsec_audit_gid;
65756+int grsec_enable_chdir;
65757+int grsec_enable_mount;
65758+int grsec_enable_rofs;
65759+int grsec_enable_chroot_findtask;
65760+int grsec_enable_chroot_mount;
65761+int grsec_enable_chroot_shmat;
65762+int grsec_enable_chroot_fchdir;
65763+int grsec_enable_chroot_double;
65764+int grsec_enable_chroot_pivot;
65765+int grsec_enable_chroot_chdir;
65766+int grsec_enable_chroot_chmod;
65767+int grsec_enable_chroot_mknod;
65768+int grsec_enable_chroot_nice;
65769+int grsec_enable_chroot_execlog;
65770+int grsec_enable_chroot_caps;
65771+int grsec_enable_chroot_sysctl;
65772+int grsec_enable_chroot_unix;
65773+int grsec_enable_tpe;
65774+kgid_t grsec_tpe_gid;
65775+int grsec_enable_blackhole;
65776+#ifdef CONFIG_IPV6_MODULE
65777+EXPORT_SYMBOL(grsec_enable_blackhole);
65778+#endif
65779+int grsec_lastack_retries;
65780+int grsec_enable_tpe_all;
65781+int grsec_enable_tpe_invert;
65782+int grsec_enable_socket_all;
65783+kgid_t grsec_socket_all_gid;
65784+int grsec_enable_socket_client;
65785+kgid_t grsec_socket_client_gid;
65786+int grsec_enable_socket_server;
65787+kgid_t grsec_socket_server_gid;
65788+int grsec_resource_logging;
65789+int grsec_disable_privio;
65790+int grsec_enable_log_rwxmaps;
65791+int grsec_lock;
65792+
65793+DEFINE_SPINLOCK(grsec_alert_lock);
65794+unsigned long grsec_alert_wtime = 0;
65795+unsigned long grsec_alert_fyet = 0;
65796+
65797+DEFINE_SPINLOCK(grsec_audit_lock);
65798+
65799+DEFINE_RWLOCK(grsec_exec_file_lock);
65800+
65801+char *gr_shared_page[4];
65802+
65803+char *gr_alert_log_fmt;
65804+char *gr_audit_log_fmt;
65805+char *gr_alert_log_buf;
65806+char *gr_audit_log_buf;
65807+
65808+extern struct gr_arg *gr_usermode;
65809+extern unsigned char *gr_system_salt;
65810+extern unsigned char *gr_system_sum;
65811+
65812+void __init
65813+grsecurity_init(void)
65814+{
65815+ int j;
65816+ /* create the per-cpu shared pages */
65817+
65818+#ifdef CONFIG_X86
65819+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65820+#endif
65821+
65822+ for (j = 0; j < 4; j++) {
65823+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65824+ if (gr_shared_page[j] == NULL) {
65825+ panic("Unable to allocate grsecurity shared page");
65826+ return;
65827+ }
65828+ }
65829+
65830+ /* allocate log buffers */
65831+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65832+ if (!gr_alert_log_fmt) {
65833+ panic("Unable to allocate grsecurity alert log format buffer");
65834+ return;
65835+ }
65836+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65837+ if (!gr_audit_log_fmt) {
65838+ panic("Unable to allocate grsecurity audit log format buffer");
65839+ return;
65840+ }
65841+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65842+ if (!gr_alert_log_buf) {
65843+ panic("Unable to allocate grsecurity alert log buffer");
65844+ return;
65845+ }
65846+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65847+ if (!gr_audit_log_buf) {
65848+ panic("Unable to allocate grsecurity audit log buffer");
65849+ return;
65850+ }
65851+
65852+ /* allocate memory for authentication structure */
65853+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65854+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65855+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65856+
65857+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65858+ panic("Unable to allocate grsecurity authentication structure");
65859+ return;
65860+ }
65861+
65862+
65863+#ifdef CONFIG_GRKERNSEC_IO
65864+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65865+ grsec_disable_privio = 1;
65866+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65867+ grsec_disable_privio = 1;
65868+#else
65869+ grsec_disable_privio = 0;
65870+#endif
65871+#endif
65872+
65873+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65874+ /* for backward compatibility, tpe_invert always defaults to on if
65875+ enabled in the kernel
65876+ */
65877+ grsec_enable_tpe_invert = 1;
65878+#endif
65879+
65880+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65881+#ifndef CONFIG_GRKERNSEC_SYSCTL
65882+ grsec_lock = 1;
65883+#endif
65884+
65885+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65886+ grsec_enable_log_rwxmaps = 1;
65887+#endif
65888+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65889+ grsec_enable_group = 1;
65890+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65891+#endif
65892+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65893+ grsec_enable_ptrace_readexec = 1;
65894+#endif
65895+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65896+ grsec_enable_chdir = 1;
65897+#endif
65898+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65899+ grsec_enable_harden_ptrace = 1;
65900+#endif
65901+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65902+ grsec_enable_mount = 1;
65903+#endif
65904+#ifdef CONFIG_GRKERNSEC_LINK
65905+ grsec_enable_link = 1;
65906+#endif
65907+#ifdef CONFIG_GRKERNSEC_BRUTE
65908+ grsec_enable_brute = 1;
65909+#endif
65910+#ifdef CONFIG_GRKERNSEC_DMESG
65911+ grsec_enable_dmesg = 1;
65912+#endif
65913+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65914+ grsec_enable_blackhole = 1;
65915+ grsec_lastack_retries = 4;
65916+#endif
65917+#ifdef CONFIG_GRKERNSEC_FIFO
65918+ grsec_enable_fifo = 1;
65919+#endif
65920+#ifdef CONFIG_GRKERNSEC_EXECLOG
65921+ grsec_enable_execlog = 1;
65922+#endif
65923+#ifdef CONFIG_GRKERNSEC_SETXID
65924+ grsec_enable_setxid = 1;
65925+#endif
65926+#ifdef CONFIG_GRKERNSEC_SIGNAL
65927+ grsec_enable_signal = 1;
65928+#endif
65929+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65930+ grsec_enable_forkfail = 1;
65931+#endif
65932+#ifdef CONFIG_GRKERNSEC_TIME
65933+ grsec_enable_time = 1;
65934+#endif
65935+#ifdef CONFIG_GRKERNSEC_RESLOG
65936+ grsec_resource_logging = 1;
65937+#endif
65938+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65939+ grsec_enable_chroot_findtask = 1;
65940+#endif
65941+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65942+ grsec_enable_chroot_unix = 1;
65943+#endif
65944+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65945+ grsec_enable_chroot_mount = 1;
65946+#endif
65947+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65948+ grsec_enable_chroot_fchdir = 1;
65949+#endif
65950+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65951+ grsec_enable_chroot_shmat = 1;
65952+#endif
65953+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65954+ grsec_enable_audit_ptrace = 1;
65955+#endif
65956+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65957+ grsec_enable_chroot_double = 1;
65958+#endif
65959+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65960+ grsec_enable_chroot_pivot = 1;
65961+#endif
65962+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65963+ grsec_enable_chroot_chdir = 1;
65964+#endif
65965+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65966+ grsec_enable_chroot_chmod = 1;
65967+#endif
65968+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65969+ grsec_enable_chroot_mknod = 1;
65970+#endif
65971+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65972+ grsec_enable_chroot_nice = 1;
65973+#endif
65974+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65975+ grsec_enable_chroot_execlog = 1;
65976+#endif
65977+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65978+ grsec_enable_chroot_caps = 1;
65979+#endif
65980+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65981+ grsec_enable_chroot_sysctl = 1;
65982+#endif
65983+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65984+ grsec_enable_symlinkown = 1;
65985+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65986+#endif
65987+#ifdef CONFIG_GRKERNSEC_TPE
65988+ grsec_enable_tpe = 1;
65989+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65990+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65991+ grsec_enable_tpe_all = 1;
65992+#endif
65993+#endif
65994+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65995+ grsec_enable_socket_all = 1;
65996+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65997+#endif
65998+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65999+ grsec_enable_socket_client = 1;
66000+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
66001+#endif
66002+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66003+ grsec_enable_socket_server = 1;
66004+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
66005+#endif
66006+#endif
66007+
66008+ return;
66009+}
66010diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
66011new file mode 100644
66012index 0000000..5e05e20
66013--- /dev/null
66014+++ b/grsecurity/grsec_link.c
66015@@ -0,0 +1,58 @@
66016+#include <linux/kernel.h>
66017+#include <linux/sched.h>
66018+#include <linux/fs.h>
66019+#include <linux/file.h>
66020+#include <linux/grinternal.h>
66021+
66022+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
66023+{
66024+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66025+ const struct inode *link_inode = link->dentry->d_inode;
66026+
66027+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
66028+ /* ignore root-owned links, e.g. /proc/self */
66029+ gr_is_global_nonroot(link_inode->i_uid) && target &&
66030+ !uid_eq(link_inode->i_uid, target->i_uid)) {
66031+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
66032+ return 1;
66033+ }
66034+#endif
66035+ return 0;
66036+}
66037+
66038+int
66039+gr_handle_follow_link(const struct inode *parent,
66040+ const struct inode *inode,
66041+ const struct dentry *dentry, const struct vfsmount *mnt)
66042+{
66043+#ifdef CONFIG_GRKERNSEC_LINK
66044+ const struct cred *cred = current_cred();
66045+
66046+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
66047+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
66048+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
66049+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
66050+ return -EACCES;
66051+ }
66052+#endif
66053+ return 0;
66054+}
66055+
66056+int
66057+gr_handle_hardlink(const struct dentry *dentry,
66058+ const struct vfsmount *mnt,
66059+ struct inode *inode, const int mode, const struct filename *to)
66060+{
66061+#ifdef CONFIG_GRKERNSEC_LINK
66062+ const struct cred *cred = current_cred();
66063+
66064+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
66065+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
66066+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
66067+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
66068+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
66069+ return -EPERM;
66070+ }
66071+#endif
66072+ return 0;
66073+}
66074diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
66075new file mode 100644
66076index 0000000..dbe0a6b
66077--- /dev/null
66078+++ b/grsecurity/grsec_log.c
66079@@ -0,0 +1,341 @@
66080+#include <linux/kernel.h>
66081+#include <linux/sched.h>
66082+#include <linux/file.h>
66083+#include <linux/tty.h>
66084+#include <linux/fs.h>
66085+#include <linux/mm.h>
66086+#include <linux/grinternal.h>
66087+
66088+#ifdef CONFIG_TREE_PREEMPT_RCU
66089+#define DISABLE_PREEMPT() preempt_disable()
66090+#define ENABLE_PREEMPT() preempt_enable()
66091+#else
66092+#define DISABLE_PREEMPT()
66093+#define ENABLE_PREEMPT()
66094+#endif
66095+
66096+#define BEGIN_LOCKS(x) \
66097+ DISABLE_PREEMPT(); \
66098+ rcu_read_lock(); \
66099+ read_lock(&tasklist_lock); \
66100+ read_lock(&grsec_exec_file_lock); \
66101+ if (x != GR_DO_AUDIT) \
66102+ spin_lock(&grsec_alert_lock); \
66103+ else \
66104+ spin_lock(&grsec_audit_lock)
66105+
66106+#define END_LOCKS(x) \
66107+ if (x != GR_DO_AUDIT) \
66108+ spin_unlock(&grsec_alert_lock); \
66109+ else \
66110+ spin_unlock(&grsec_audit_lock); \
66111+ read_unlock(&grsec_exec_file_lock); \
66112+ read_unlock(&tasklist_lock); \
66113+ rcu_read_unlock(); \
66114+ ENABLE_PREEMPT(); \
66115+ if (x == GR_DONT_AUDIT) \
66116+ gr_handle_alertkill(current)
66117+
66118+enum {
66119+ FLOODING,
66120+ NO_FLOODING
66121+};
66122+
66123+extern char *gr_alert_log_fmt;
66124+extern char *gr_audit_log_fmt;
66125+extern char *gr_alert_log_buf;
66126+extern char *gr_audit_log_buf;
66127+
66128+static int gr_log_start(int audit)
66129+{
66130+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
66131+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
66132+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
66133+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
66134+ unsigned long curr_secs = get_seconds();
66135+
66136+ if (audit == GR_DO_AUDIT)
66137+ goto set_fmt;
66138+
66139+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
66140+ grsec_alert_wtime = curr_secs;
66141+ grsec_alert_fyet = 0;
66142+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
66143+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
66144+ grsec_alert_fyet++;
66145+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
66146+ grsec_alert_wtime = curr_secs;
66147+ grsec_alert_fyet++;
66148+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
66149+ return FLOODING;
66150+ }
66151+ else return FLOODING;
66152+
66153+set_fmt:
66154+#endif
66155+ memset(buf, 0, PAGE_SIZE);
66156+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
66157+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
66158+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
66159+ } else if (current->signal->curr_ip) {
66160+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
66161+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
66162+ } else if (gr_acl_is_enabled()) {
66163+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
66164+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
66165+ } else {
66166+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
66167+ strcpy(buf, fmt);
66168+ }
66169+
66170+ return NO_FLOODING;
66171+}
66172+
66173+static void gr_log_middle(int audit, const char *msg, va_list ap)
66174+ __attribute__ ((format (printf, 2, 0)));
66175+
66176+static void gr_log_middle(int audit, const char *msg, va_list ap)
66177+{
66178+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
66179+ unsigned int len = strlen(buf);
66180+
66181+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
66182+
66183+ return;
66184+}
66185+
66186+static void gr_log_middle_varargs(int audit, const char *msg, ...)
66187+ __attribute__ ((format (printf, 2, 3)));
66188+
66189+static void gr_log_middle_varargs(int audit, const char *msg, ...)
66190+{
66191+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
66192+ unsigned int len = strlen(buf);
66193+ va_list ap;
66194+
66195+ va_start(ap, msg);
66196+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
66197+ va_end(ap);
66198+
66199+ return;
66200+}
66201+
66202+static void gr_log_end(int audit, int append_default)
66203+{
66204+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
66205+ if (append_default) {
66206+ struct task_struct *task = current;
66207+ struct task_struct *parent = task->real_parent;
66208+ const struct cred *cred = __task_cred(task);
66209+ const struct cred *pcred = __task_cred(parent);
66210+ unsigned int len = strlen(buf);
66211+
66212+ 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));
66213+ }
66214+
66215+ printk("%s\n", buf);
66216+
66217+ return;
66218+}
66219+
66220+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
66221+{
66222+ int logtype;
66223+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
66224+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
66225+ void *voidptr = NULL;
66226+ int num1 = 0, num2 = 0;
66227+ unsigned long ulong1 = 0, ulong2 = 0;
66228+ struct dentry *dentry = NULL;
66229+ struct vfsmount *mnt = NULL;
66230+ struct file *file = NULL;
66231+ struct task_struct *task = NULL;
66232+ struct vm_area_struct *vma = NULL;
66233+ const struct cred *cred, *pcred;
66234+ va_list ap;
66235+
66236+ BEGIN_LOCKS(audit);
66237+ logtype = gr_log_start(audit);
66238+ if (logtype == FLOODING) {
66239+ END_LOCKS(audit);
66240+ return;
66241+ }
66242+ va_start(ap, argtypes);
66243+ switch (argtypes) {
66244+ case GR_TTYSNIFF:
66245+ task = va_arg(ap, struct task_struct *);
66246+ 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));
66247+ break;
66248+ case GR_SYSCTL_HIDDEN:
66249+ str1 = va_arg(ap, char *);
66250+ gr_log_middle_varargs(audit, msg, result, str1);
66251+ break;
66252+ case GR_RBAC:
66253+ dentry = va_arg(ap, struct dentry *);
66254+ mnt = va_arg(ap, struct vfsmount *);
66255+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
66256+ break;
66257+ case GR_RBAC_STR:
66258+ dentry = va_arg(ap, struct dentry *);
66259+ mnt = va_arg(ap, struct vfsmount *);
66260+ str1 = va_arg(ap, char *);
66261+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
66262+ break;
66263+ case GR_STR_RBAC:
66264+ str1 = va_arg(ap, char *);
66265+ dentry = va_arg(ap, struct dentry *);
66266+ mnt = va_arg(ap, struct vfsmount *);
66267+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
66268+ break;
66269+ case GR_RBAC_MODE2:
66270+ dentry = va_arg(ap, struct dentry *);
66271+ mnt = va_arg(ap, struct vfsmount *);
66272+ str1 = va_arg(ap, char *);
66273+ str2 = va_arg(ap, char *);
66274+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
66275+ break;
66276+ case GR_RBAC_MODE3:
66277+ dentry = va_arg(ap, struct dentry *);
66278+ mnt = va_arg(ap, struct vfsmount *);
66279+ str1 = va_arg(ap, char *);
66280+ str2 = va_arg(ap, char *);
66281+ str3 = va_arg(ap, char *);
66282+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
66283+ break;
66284+ case GR_FILENAME:
66285+ dentry = va_arg(ap, struct dentry *);
66286+ mnt = va_arg(ap, struct vfsmount *);
66287+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
66288+ break;
66289+ case GR_STR_FILENAME:
66290+ str1 = va_arg(ap, char *);
66291+ dentry = va_arg(ap, struct dentry *);
66292+ mnt = va_arg(ap, struct vfsmount *);
66293+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
66294+ break;
66295+ case GR_FILENAME_STR:
66296+ dentry = va_arg(ap, struct dentry *);
66297+ mnt = va_arg(ap, struct vfsmount *);
66298+ str1 = va_arg(ap, char *);
66299+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
66300+ break;
66301+ case GR_FILENAME_TWO_INT:
66302+ dentry = va_arg(ap, struct dentry *);
66303+ mnt = va_arg(ap, struct vfsmount *);
66304+ num1 = va_arg(ap, int);
66305+ num2 = va_arg(ap, int);
66306+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
66307+ break;
66308+ case GR_FILENAME_TWO_INT_STR:
66309+ dentry = va_arg(ap, struct dentry *);
66310+ mnt = va_arg(ap, struct vfsmount *);
66311+ num1 = va_arg(ap, int);
66312+ num2 = va_arg(ap, int);
66313+ str1 = va_arg(ap, char *);
66314+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
66315+ break;
66316+ case GR_TEXTREL:
66317+ file = va_arg(ap, struct file *);
66318+ ulong1 = va_arg(ap, unsigned long);
66319+ ulong2 = va_arg(ap, unsigned long);
66320+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
66321+ break;
66322+ case GR_PTRACE:
66323+ task = va_arg(ap, struct task_struct *);
66324+ 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));
66325+ break;
66326+ case GR_RESOURCE:
66327+ task = va_arg(ap, struct task_struct *);
66328+ cred = __task_cred(task);
66329+ pcred = __task_cred(task->real_parent);
66330+ ulong1 = va_arg(ap, unsigned long);
66331+ str1 = va_arg(ap, char *);
66332+ ulong2 = va_arg(ap, unsigned long);
66333+ 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));
66334+ break;
66335+ case GR_CAP:
66336+ task = va_arg(ap, struct task_struct *);
66337+ cred = __task_cred(task);
66338+ pcred = __task_cred(task->real_parent);
66339+ str1 = va_arg(ap, char *);
66340+ 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));
66341+ break;
66342+ case GR_SIG:
66343+ str1 = va_arg(ap, char *);
66344+ voidptr = va_arg(ap, void *);
66345+ gr_log_middle_varargs(audit, msg, str1, voidptr);
66346+ break;
66347+ case GR_SIG2:
66348+ task = va_arg(ap, struct task_struct *);
66349+ cred = __task_cred(task);
66350+ pcred = __task_cred(task->real_parent);
66351+ num1 = va_arg(ap, int);
66352+ 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));
66353+ break;
66354+ case GR_CRASH1:
66355+ task = va_arg(ap, struct task_struct *);
66356+ cred = __task_cred(task);
66357+ pcred = __task_cred(task->real_parent);
66358+ ulong1 = va_arg(ap, unsigned long);
66359+ 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);
66360+ break;
66361+ case GR_CRASH2:
66362+ task = va_arg(ap, struct task_struct *);
66363+ cred = __task_cred(task);
66364+ pcred = __task_cred(task->real_parent);
66365+ ulong1 = va_arg(ap, unsigned long);
66366+ 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);
66367+ break;
66368+ case GR_RWXMAP:
66369+ file = va_arg(ap, struct file *);
66370+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
66371+ break;
66372+ case GR_RWXMAPVMA:
66373+ vma = va_arg(ap, struct vm_area_struct *);
66374+ if (vma->vm_file)
66375+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
66376+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
66377+ str1 = "<stack>";
66378+ else if (vma->vm_start <= current->mm->brk &&
66379+ vma->vm_end >= current->mm->start_brk)
66380+ str1 = "<heap>";
66381+ else
66382+ str1 = "<anonymous mapping>";
66383+ gr_log_middle_varargs(audit, msg, str1);
66384+ break;
66385+ case GR_PSACCT:
66386+ {
66387+ unsigned int wday, cday;
66388+ __u8 whr, chr;
66389+ __u8 wmin, cmin;
66390+ __u8 wsec, csec;
66391+ char cur_tty[64] = { 0 };
66392+ char parent_tty[64] = { 0 };
66393+
66394+ task = va_arg(ap, struct task_struct *);
66395+ wday = va_arg(ap, unsigned int);
66396+ cday = va_arg(ap, unsigned int);
66397+ whr = va_arg(ap, int);
66398+ chr = va_arg(ap, int);
66399+ wmin = va_arg(ap, int);
66400+ cmin = va_arg(ap, int);
66401+ wsec = va_arg(ap, int);
66402+ csec = va_arg(ap, int);
66403+ ulong1 = va_arg(ap, unsigned long);
66404+ cred = __task_cred(task);
66405+ pcred = __task_cred(task->real_parent);
66406+
66407+ 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));
66408+ }
66409+ break;
66410+ default:
66411+ gr_log_middle(audit, msg, ap);
66412+ }
66413+ va_end(ap);
66414+ // these don't need DEFAULTSECARGS printed on the end
66415+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
66416+ gr_log_end(audit, 0);
66417+ else
66418+ gr_log_end(audit, 1);
66419+ END_LOCKS(audit);
66420+}
66421diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
66422new file mode 100644
66423index 0000000..f536303
66424--- /dev/null
66425+++ b/grsecurity/grsec_mem.c
66426@@ -0,0 +1,40 @@
66427+#include <linux/kernel.h>
66428+#include <linux/sched.h>
66429+#include <linux/mm.h>
66430+#include <linux/mman.h>
66431+#include <linux/grinternal.h>
66432+
66433+void
66434+gr_handle_ioperm(void)
66435+{
66436+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
66437+ return;
66438+}
66439+
66440+void
66441+gr_handle_iopl(void)
66442+{
66443+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
66444+ return;
66445+}
66446+
66447+void
66448+gr_handle_mem_readwrite(u64 from, u64 to)
66449+{
66450+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
66451+ return;
66452+}
66453+
66454+void
66455+gr_handle_vm86(void)
66456+{
66457+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
66458+ return;
66459+}
66460+
66461+void
66462+gr_log_badprocpid(const char *entry)
66463+{
66464+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
66465+ return;
66466+}
66467diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
66468new file mode 100644
66469index 0000000..2131422
66470--- /dev/null
66471+++ b/grsecurity/grsec_mount.c
66472@@ -0,0 +1,62 @@
66473+#include <linux/kernel.h>
66474+#include <linux/sched.h>
66475+#include <linux/mount.h>
66476+#include <linux/grsecurity.h>
66477+#include <linux/grinternal.h>
66478+
66479+void
66480+gr_log_remount(const char *devname, const int retval)
66481+{
66482+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66483+ if (grsec_enable_mount && (retval >= 0))
66484+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
66485+#endif
66486+ return;
66487+}
66488+
66489+void
66490+gr_log_unmount(const char *devname, const int retval)
66491+{
66492+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66493+ if (grsec_enable_mount && (retval >= 0))
66494+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
66495+#endif
66496+ return;
66497+}
66498+
66499+void
66500+gr_log_mount(const char *from, const char *to, const int retval)
66501+{
66502+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66503+ if (grsec_enable_mount && (retval >= 0))
66504+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
66505+#endif
66506+ return;
66507+}
66508+
66509+int
66510+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
66511+{
66512+#ifdef CONFIG_GRKERNSEC_ROFS
66513+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
66514+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
66515+ return -EPERM;
66516+ } else
66517+ return 0;
66518+#endif
66519+ return 0;
66520+}
66521+
66522+int
66523+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
66524+{
66525+#ifdef CONFIG_GRKERNSEC_ROFS
66526+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
66527+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
66528+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
66529+ return -EPERM;
66530+ } else
66531+ return 0;
66532+#endif
66533+ return 0;
66534+}
66535diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
66536new file mode 100644
66537index 0000000..6ee9d50
66538--- /dev/null
66539+++ b/grsecurity/grsec_pax.c
66540@@ -0,0 +1,45 @@
66541+#include <linux/kernel.h>
66542+#include <linux/sched.h>
66543+#include <linux/mm.h>
66544+#include <linux/file.h>
66545+#include <linux/grinternal.h>
66546+#include <linux/grsecurity.h>
66547+
66548+void
66549+gr_log_textrel(struct vm_area_struct * vma)
66550+{
66551+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66552+ if (grsec_enable_log_rwxmaps)
66553+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
66554+#endif
66555+ return;
66556+}
66557+
66558+void gr_log_ptgnustack(struct file *file)
66559+{
66560+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66561+ if (grsec_enable_log_rwxmaps)
66562+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
66563+#endif
66564+ return;
66565+}
66566+
66567+void
66568+gr_log_rwxmmap(struct file *file)
66569+{
66570+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66571+ if (grsec_enable_log_rwxmaps)
66572+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
66573+#endif
66574+ return;
66575+}
66576+
66577+void
66578+gr_log_rwxmprotect(struct vm_area_struct *vma)
66579+{
66580+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66581+ if (grsec_enable_log_rwxmaps)
66582+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
66583+#endif
66584+ return;
66585+}
66586diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
66587new file mode 100644
66588index 0000000..f7f29aa
66589--- /dev/null
66590+++ b/grsecurity/grsec_ptrace.c
66591@@ -0,0 +1,30 @@
66592+#include <linux/kernel.h>
66593+#include <linux/sched.h>
66594+#include <linux/grinternal.h>
66595+#include <linux/security.h>
66596+
66597+void
66598+gr_audit_ptrace(struct task_struct *task)
66599+{
66600+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66601+ if (grsec_enable_audit_ptrace)
66602+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
66603+#endif
66604+ return;
66605+}
66606+
66607+int
66608+gr_ptrace_readexec(struct file *file, int unsafe_flags)
66609+{
66610+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66611+ const struct dentry *dentry = file->f_path.dentry;
66612+ const struct vfsmount *mnt = file->f_path.mnt;
66613+
66614+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
66615+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
66616+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
66617+ return -EACCES;
66618+ }
66619+#endif
66620+ return 0;
66621+}
66622diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
66623new file mode 100644
66624index 0000000..4e29cc7
66625--- /dev/null
66626+++ b/grsecurity/grsec_sig.c
66627@@ -0,0 +1,246 @@
66628+#include <linux/kernel.h>
66629+#include <linux/sched.h>
66630+#include <linux/fs.h>
66631+#include <linux/delay.h>
66632+#include <linux/grsecurity.h>
66633+#include <linux/grinternal.h>
66634+#include <linux/hardirq.h>
66635+
66636+char *signames[] = {
66637+ [SIGSEGV] = "Segmentation fault",
66638+ [SIGILL] = "Illegal instruction",
66639+ [SIGABRT] = "Abort",
66640+ [SIGBUS] = "Invalid alignment/Bus error"
66641+};
66642+
66643+void
66644+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
66645+{
66646+#ifdef CONFIG_GRKERNSEC_SIGNAL
66647+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
66648+ (sig == SIGABRT) || (sig == SIGBUS))) {
66649+ if (task_pid_nr(t) == task_pid_nr(current)) {
66650+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
66651+ } else {
66652+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
66653+ }
66654+ }
66655+#endif
66656+ return;
66657+}
66658+
66659+int
66660+gr_handle_signal(const struct task_struct *p, const int sig)
66661+{
66662+#ifdef CONFIG_GRKERNSEC
66663+ /* ignore the 0 signal for protected task checks */
66664+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
66665+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
66666+ return -EPERM;
66667+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
66668+ return -EPERM;
66669+ }
66670+#endif
66671+ return 0;
66672+}
66673+
66674+#ifdef CONFIG_GRKERNSEC
66675+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
66676+
66677+int gr_fake_force_sig(int sig, struct task_struct *t)
66678+{
66679+ unsigned long int flags;
66680+ int ret, blocked, ignored;
66681+ struct k_sigaction *action;
66682+
66683+ spin_lock_irqsave(&t->sighand->siglock, flags);
66684+ action = &t->sighand->action[sig-1];
66685+ ignored = action->sa.sa_handler == SIG_IGN;
66686+ blocked = sigismember(&t->blocked, sig);
66687+ if (blocked || ignored) {
66688+ action->sa.sa_handler = SIG_DFL;
66689+ if (blocked) {
66690+ sigdelset(&t->blocked, sig);
66691+ recalc_sigpending_and_wake(t);
66692+ }
66693+ }
66694+ if (action->sa.sa_handler == SIG_DFL)
66695+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
66696+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
66697+
66698+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
66699+
66700+ return ret;
66701+}
66702+#endif
66703+
66704+#ifdef CONFIG_GRKERNSEC_BRUTE
66705+#define GR_USER_BAN_TIME (15 * 60)
66706+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66707+
66708+static int __get_dumpable(unsigned long mm_flags)
66709+{
66710+ int ret;
66711+
66712+ ret = mm_flags & MMF_DUMPABLE_MASK;
66713+ return (ret >= 2) ? 2 : ret;
66714+}
66715+#endif
66716+
66717+void gr_handle_brute_attach(unsigned long mm_flags)
66718+{
66719+#ifdef CONFIG_GRKERNSEC_BRUTE
66720+ struct task_struct *p = current;
66721+ kuid_t uid = GLOBAL_ROOT_UID;
66722+ int daemon = 0;
66723+
66724+ if (!grsec_enable_brute)
66725+ return;
66726+
66727+ rcu_read_lock();
66728+ read_lock(&tasklist_lock);
66729+ read_lock(&grsec_exec_file_lock);
66730+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
66731+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66732+ p->real_parent->brute = 1;
66733+ daemon = 1;
66734+ } else {
66735+ const struct cred *cred = __task_cred(p), *cred2;
66736+ struct task_struct *tsk, *tsk2;
66737+
66738+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66739+ struct user_struct *user;
66740+
66741+ uid = cred->uid;
66742+
66743+ /* this is put upon execution past expiration */
66744+ user = find_user(uid);
66745+ if (user == NULL)
66746+ goto unlock;
66747+ user->suid_banned = 1;
66748+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
66749+ if (user->suid_ban_expires == ~0UL)
66750+ user->suid_ban_expires--;
66751+
66752+ /* only kill other threads of the same binary, from the same user */
66753+ do_each_thread(tsk2, tsk) {
66754+ cred2 = __task_cred(tsk);
66755+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
66756+ gr_fake_force_sig(SIGKILL, tsk);
66757+ } while_each_thread(tsk2, tsk);
66758+ }
66759+ }
66760+unlock:
66761+ read_unlock(&grsec_exec_file_lock);
66762+ read_unlock(&tasklist_lock);
66763+ rcu_read_unlock();
66764+
66765+ if (gr_is_global_nonroot(uid))
66766+ gr_log_fs_int2(GR_DONT_AUDIT, GR_BRUTE_SUID_MSG, p->exec_file->f_path.dentry, p->exec_file->f_path.mnt, GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
66767+ else if (daemon)
66768+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66769+
66770+#endif
66771+ return;
66772+}
66773+
66774+void gr_handle_brute_check(void)
66775+{
66776+#ifdef CONFIG_GRKERNSEC_BRUTE
66777+ struct task_struct *p = current;
66778+
66779+ if (unlikely(p->brute)) {
66780+ if (!grsec_enable_brute)
66781+ p->brute = 0;
66782+ else if (time_before(get_seconds(), p->brute_expires))
66783+ msleep(30 * 1000);
66784+ }
66785+#endif
66786+ return;
66787+}
66788+
66789+void gr_handle_kernel_exploit(void)
66790+{
66791+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66792+ const struct cred *cred;
66793+ struct task_struct *tsk, *tsk2;
66794+ struct user_struct *user;
66795+ kuid_t uid;
66796+
66797+ if (in_irq() || in_serving_softirq() || in_nmi())
66798+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66799+
66800+ uid = current_uid();
66801+
66802+ if (gr_is_global_root(uid))
66803+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66804+ else {
66805+ /* kill all the processes of this user, hold a reference
66806+ to their creds struct, and prevent them from creating
66807+ another process until system reset
66808+ */
66809+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66810+ GR_GLOBAL_UID(uid));
66811+ /* we intentionally leak this ref */
66812+ user = get_uid(current->cred->user);
66813+ if (user)
66814+ user->kernel_banned = 1;
66815+
66816+ /* kill all processes of this user */
66817+ read_lock(&tasklist_lock);
66818+ do_each_thread(tsk2, tsk) {
66819+ cred = __task_cred(tsk);
66820+ if (uid_eq(cred->uid, uid))
66821+ gr_fake_force_sig(SIGKILL, tsk);
66822+ } while_each_thread(tsk2, tsk);
66823+ read_unlock(&tasklist_lock);
66824+ }
66825+#endif
66826+}
66827+
66828+#ifdef CONFIG_GRKERNSEC_BRUTE
66829+static bool suid_ban_expired(struct user_struct *user)
66830+{
66831+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
66832+ user->suid_banned = 0;
66833+ user->suid_ban_expires = 0;
66834+ free_uid(user);
66835+ return true;
66836+ }
66837+
66838+ return false;
66839+}
66840+#endif
66841+
66842+int gr_process_kernel_exec_ban(void)
66843+{
66844+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66845+ if (unlikely(current->cred->user->kernel_banned))
66846+ return -EPERM;
66847+#endif
66848+ return 0;
66849+}
66850+
66851+int gr_process_kernel_setuid_ban(struct user_struct *user)
66852+{
66853+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66854+ if (unlikely(user->kernel_banned))
66855+ gr_fake_force_sig(SIGKILL, current);
66856+#endif
66857+ return 0;
66858+}
66859+
66860+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
66861+{
66862+#ifdef CONFIG_GRKERNSEC_BRUTE
66863+ struct user_struct *user = current->cred->user;
66864+ if (unlikely(user->suid_banned)) {
66865+ if (suid_ban_expired(user))
66866+ return 0;
66867+ /* disallow execution of suid binaries only */
66868+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
66869+ return -EPERM;
66870+ }
66871+#endif
66872+ return 0;
66873+}
66874diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66875new file mode 100644
66876index 0000000..4030d57
66877--- /dev/null
66878+++ b/grsecurity/grsec_sock.c
66879@@ -0,0 +1,244 @@
66880+#include <linux/kernel.h>
66881+#include <linux/module.h>
66882+#include <linux/sched.h>
66883+#include <linux/file.h>
66884+#include <linux/net.h>
66885+#include <linux/in.h>
66886+#include <linux/ip.h>
66887+#include <net/sock.h>
66888+#include <net/inet_sock.h>
66889+#include <linux/grsecurity.h>
66890+#include <linux/grinternal.h>
66891+#include <linux/gracl.h>
66892+
66893+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66894+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66895+
66896+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66897+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66898+
66899+#ifdef CONFIG_UNIX_MODULE
66900+EXPORT_SYMBOL(gr_acl_handle_unix);
66901+EXPORT_SYMBOL(gr_acl_handle_mknod);
66902+EXPORT_SYMBOL(gr_handle_chroot_unix);
66903+EXPORT_SYMBOL(gr_handle_create);
66904+#endif
66905+
66906+#ifdef CONFIG_GRKERNSEC
66907+#define gr_conn_table_size 32749
66908+struct conn_table_entry {
66909+ struct conn_table_entry *next;
66910+ struct signal_struct *sig;
66911+};
66912+
66913+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66914+DEFINE_SPINLOCK(gr_conn_table_lock);
66915+
66916+extern const char * gr_socktype_to_name(unsigned char type);
66917+extern const char * gr_proto_to_name(unsigned char proto);
66918+extern const char * gr_sockfamily_to_name(unsigned char family);
66919+
66920+static __inline__ int
66921+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66922+{
66923+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66924+}
66925+
66926+static __inline__ int
66927+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66928+ __u16 sport, __u16 dport)
66929+{
66930+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66931+ sig->gr_sport == sport && sig->gr_dport == dport))
66932+ return 1;
66933+ else
66934+ return 0;
66935+}
66936+
66937+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66938+{
66939+ struct conn_table_entry **match;
66940+ unsigned int index;
66941+
66942+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66943+ sig->gr_sport, sig->gr_dport,
66944+ gr_conn_table_size);
66945+
66946+ newent->sig = sig;
66947+
66948+ match = &gr_conn_table[index];
66949+ newent->next = *match;
66950+ *match = newent;
66951+
66952+ return;
66953+}
66954+
66955+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66956+{
66957+ struct conn_table_entry *match, *last = NULL;
66958+ unsigned int index;
66959+
66960+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66961+ sig->gr_sport, sig->gr_dport,
66962+ gr_conn_table_size);
66963+
66964+ match = gr_conn_table[index];
66965+ while (match && !conn_match(match->sig,
66966+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66967+ sig->gr_dport)) {
66968+ last = match;
66969+ match = match->next;
66970+ }
66971+
66972+ if (match) {
66973+ if (last)
66974+ last->next = match->next;
66975+ else
66976+ gr_conn_table[index] = NULL;
66977+ kfree(match);
66978+ }
66979+
66980+ return;
66981+}
66982+
66983+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66984+ __u16 sport, __u16 dport)
66985+{
66986+ struct conn_table_entry *match;
66987+ unsigned int index;
66988+
66989+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66990+
66991+ match = gr_conn_table[index];
66992+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66993+ match = match->next;
66994+
66995+ if (match)
66996+ return match->sig;
66997+ else
66998+ return NULL;
66999+}
67000+
67001+#endif
67002+
67003+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
67004+{
67005+#ifdef CONFIG_GRKERNSEC
67006+ struct signal_struct *sig = task->signal;
67007+ struct conn_table_entry *newent;
67008+
67009+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
67010+ if (newent == NULL)
67011+ return;
67012+ /* no bh lock needed since we are called with bh disabled */
67013+ spin_lock(&gr_conn_table_lock);
67014+ gr_del_task_from_ip_table_nolock(sig);
67015+ sig->gr_saddr = inet->inet_rcv_saddr;
67016+ sig->gr_daddr = inet->inet_daddr;
67017+ sig->gr_sport = inet->inet_sport;
67018+ sig->gr_dport = inet->inet_dport;
67019+ gr_add_to_task_ip_table_nolock(sig, newent);
67020+ spin_unlock(&gr_conn_table_lock);
67021+#endif
67022+ return;
67023+}
67024+
67025+void gr_del_task_from_ip_table(struct task_struct *task)
67026+{
67027+#ifdef CONFIG_GRKERNSEC
67028+ spin_lock_bh(&gr_conn_table_lock);
67029+ gr_del_task_from_ip_table_nolock(task->signal);
67030+ spin_unlock_bh(&gr_conn_table_lock);
67031+#endif
67032+ return;
67033+}
67034+
67035+void
67036+gr_attach_curr_ip(const struct sock *sk)
67037+{
67038+#ifdef CONFIG_GRKERNSEC
67039+ struct signal_struct *p, *set;
67040+ const struct inet_sock *inet = inet_sk(sk);
67041+
67042+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
67043+ return;
67044+
67045+ set = current->signal;
67046+
67047+ spin_lock_bh(&gr_conn_table_lock);
67048+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
67049+ inet->inet_dport, inet->inet_sport);
67050+ if (unlikely(p != NULL)) {
67051+ set->curr_ip = p->curr_ip;
67052+ set->used_accept = 1;
67053+ gr_del_task_from_ip_table_nolock(p);
67054+ spin_unlock_bh(&gr_conn_table_lock);
67055+ return;
67056+ }
67057+ spin_unlock_bh(&gr_conn_table_lock);
67058+
67059+ set->curr_ip = inet->inet_daddr;
67060+ set->used_accept = 1;
67061+#endif
67062+ return;
67063+}
67064+
67065+int
67066+gr_handle_sock_all(const int family, const int type, const int protocol)
67067+{
67068+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
67069+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
67070+ (family != AF_UNIX)) {
67071+ if (family == AF_INET)
67072+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
67073+ else
67074+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
67075+ return -EACCES;
67076+ }
67077+#endif
67078+ return 0;
67079+}
67080+
67081+int
67082+gr_handle_sock_server(const struct sockaddr *sck)
67083+{
67084+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
67085+ if (grsec_enable_socket_server &&
67086+ in_group_p(grsec_socket_server_gid) &&
67087+ sck && (sck->sa_family != AF_UNIX) &&
67088+ (sck->sa_family != AF_LOCAL)) {
67089+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
67090+ return -EACCES;
67091+ }
67092+#endif
67093+ return 0;
67094+}
67095+
67096+int
67097+gr_handle_sock_server_other(const struct sock *sck)
67098+{
67099+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
67100+ if (grsec_enable_socket_server &&
67101+ in_group_p(grsec_socket_server_gid) &&
67102+ sck && (sck->sk_family != AF_UNIX) &&
67103+ (sck->sk_family != AF_LOCAL)) {
67104+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
67105+ return -EACCES;
67106+ }
67107+#endif
67108+ return 0;
67109+}
67110+
67111+int
67112+gr_handle_sock_client(const struct sockaddr *sck)
67113+{
67114+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
67115+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
67116+ sck && (sck->sa_family != AF_UNIX) &&
67117+ (sck->sa_family != AF_LOCAL)) {
67118+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
67119+ return -EACCES;
67120+ }
67121+#endif
67122+ return 0;
67123+}
67124diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
67125new file mode 100644
67126index 0000000..7624d1c
67127--- /dev/null
67128+++ b/grsecurity/grsec_sysctl.c
67129@@ -0,0 +1,460 @@
67130+#include <linux/kernel.h>
67131+#include <linux/sched.h>
67132+#include <linux/sysctl.h>
67133+#include <linux/grsecurity.h>
67134+#include <linux/grinternal.h>
67135+
67136+int
67137+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
67138+{
67139+#ifdef CONFIG_GRKERNSEC_SYSCTL
67140+ if (dirname == NULL || name == NULL)
67141+ return 0;
67142+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
67143+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
67144+ return -EACCES;
67145+ }
67146+#endif
67147+ return 0;
67148+}
67149+
67150+#ifdef CONFIG_GRKERNSEC_ROFS
67151+static int __maybe_unused one = 1;
67152+#endif
67153+
67154+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
67155+struct ctl_table grsecurity_table[] = {
67156+#ifdef CONFIG_GRKERNSEC_SYSCTL
67157+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
67158+#ifdef CONFIG_GRKERNSEC_IO
67159+ {
67160+ .procname = "disable_priv_io",
67161+ .data = &grsec_disable_privio,
67162+ .maxlen = sizeof(int),
67163+ .mode = 0600,
67164+ .proc_handler = &proc_dointvec,
67165+ },
67166+#endif
67167+#endif
67168+#ifdef CONFIG_GRKERNSEC_LINK
67169+ {
67170+ .procname = "linking_restrictions",
67171+ .data = &grsec_enable_link,
67172+ .maxlen = sizeof(int),
67173+ .mode = 0600,
67174+ .proc_handler = &proc_dointvec,
67175+ },
67176+#endif
67177+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
67178+ {
67179+ .procname = "enforce_symlinksifowner",
67180+ .data = &grsec_enable_symlinkown,
67181+ .maxlen = sizeof(int),
67182+ .mode = 0600,
67183+ .proc_handler = &proc_dointvec,
67184+ },
67185+ {
67186+ .procname = "symlinkown_gid",
67187+ .data = &grsec_symlinkown_gid,
67188+ .maxlen = sizeof(int),
67189+ .mode = 0600,
67190+ .proc_handler = &proc_dointvec,
67191+ },
67192+#endif
67193+#ifdef CONFIG_GRKERNSEC_BRUTE
67194+ {
67195+ .procname = "deter_bruteforce",
67196+ .data = &grsec_enable_brute,
67197+ .maxlen = sizeof(int),
67198+ .mode = 0600,
67199+ .proc_handler = &proc_dointvec,
67200+ },
67201+#endif
67202+#ifdef CONFIG_GRKERNSEC_FIFO
67203+ {
67204+ .procname = "fifo_restrictions",
67205+ .data = &grsec_enable_fifo,
67206+ .maxlen = sizeof(int),
67207+ .mode = 0600,
67208+ .proc_handler = &proc_dointvec,
67209+ },
67210+#endif
67211+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
67212+ {
67213+ .procname = "ptrace_readexec",
67214+ .data = &grsec_enable_ptrace_readexec,
67215+ .maxlen = sizeof(int),
67216+ .mode = 0600,
67217+ .proc_handler = &proc_dointvec,
67218+ },
67219+#endif
67220+#ifdef CONFIG_GRKERNSEC_SETXID
67221+ {
67222+ .procname = "consistent_setxid",
67223+ .data = &grsec_enable_setxid,
67224+ .maxlen = sizeof(int),
67225+ .mode = 0600,
67226+ .proc_handler = &proc_dointvec,
67227+ },
67228+#endif
67229+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
67230+ {
67231+ .procname = "ip_blackhole",
67232+ .data = &grsec_enable_blackhole,
67233+ .maxlen = sizeof(int),
67234+ .mode = 0600,
67235+ .proc_handler = &proc_dointvec,
67236+ },
67237+ {
67238+ .procname = "lastack_retries",
67239+ .data = &grsec_lastack_retries,
67240+ .maxlen = sizeof(int),
67241+ .mode = 0600,
67242+ .proc_handler = &proc_dointvec,
67243+ },
67244+#endif
67245+#ifdef CONFIG_GRKERNSEC_EXECLOG
67246+ {
67247+ .procname = "exec_logging",
67248+ .data = &grsec_enable_execlog,
67249+ .maxlen = sizeof(int),
67250+ .mode = 0600,
67251+ .proc_handler = &proc_dointvec,
67252+ },
67253+#endif
67254+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
67255+ {
67256+ .procname = "rwxmap_logging",
67257+ .data = &grsec_enable_log_rwxmaps,
67258+ .maxlen = sizeof(int),
67259+ .mode = 0600,
67260+ .proc_handler = &proc_dointvec,
67261+ },
67262+#endif
67263+#ifdef CONFIG_GRKERNSEC_SIGNAL
67264+ {
67265+ .procname = "signal_logging",
67266+ .data = &grsec_enable_signal,
67267+ .maxlen = sizeof(int),
67268+ .mode = 0600,
67269+ .proc_handler = &proc_dointvec,
67270+ },
67271+#endif
67272+#ifdef CONFIG_GRKERNSEC_FORKFAIL
67273+ {
67274+ .procname = "forkfail_logging",
67275+ .data = &grsec_enable_forkfail,
67276+ .maxlen = sizeof(int),
67277+ .mode = 0600,
67278+ .proc_handler = &proc_dointvec,
67279+ },
67280+#endif
67281+#ifdef CONFIG_GRKERNSEC_TIME
67282+ {
67283+ .procname = "timechange_logging",
67284+ .data = &grsec_enable_time,
67285+ .maxlen = sizeof(int),
67286+ .mode = 0600,
67287+ .proc_handler = &proc_dointvec,
67288+ },
67289+#endif
67290+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
67291+ {
67292+ .procname = "chroot_deny_shmat",
67293+ .data = &grsec_enable_chroot_shmat,
67294+ .maxlen = sizeof(int),
67295+ .mode = 0600,
67296+ .proc_handler = &proc_dointvec,
67297+ },
67298+#endif
67299+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
67300+ {
67301+ .procname = "chroot_deny_unix",
67302+ .data = &grsec_enable_chroot_unix,
67303+ .maxlen = sizeof(int),
67304+ .mode = 0600,
67305+ .proc_handler = &proc_dointvec,
67306+ },
67307+#endif
67308+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
67309+ {
67310+ .procname = "chroot_deny_mount",
67311+ .data = &grsec_enable_chroot_mount,
67312+ .maxlen = sizeof(int),
67313+ .mode = 0600,
67314+ .proc_handler = &proc_dointvec,
67315+ },
67316+#endif
67317+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
67318+ {
67319+ .procname = "chroot_deny_fchdir",
67320+ .data = &grsec_enable_chroot_fchdir,
67321+ .maxlen = sizeof(int),
67322+ .mode = 0600,
67323+ .proc_handler = &proc_dointvec,
67324+ },
67325+#endif
67326+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
67327+ {
67328+ .procname = "chroot_deny_chroot",
67329+ .data = &grsec_enable_chroot_double,
67330+ .maxlen = sizeof(int),
67331+ .mode = 0600,
67332+ .proc_handler = &proc_dointvec,
67333+ },
67334+#endif
67335+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
67336+ {
67337+ .procname = "chroot_deny_pivot",
67338+ .data = &grsec_enable_chroot_pivot,
67339+ .maxlen = sizeof(int),
67340+ .mode = 0600,
67341+ .proc_handler = &proc_dointvec,
67342+ },
67343+#endif
67344+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
67345+ {
67346+ .procname = "chroot_enforce_chdir",
67347+ .data = &grsec_enable_chroot_chdir,
67348+ .maxlen = sizeof(int),
67349+ .mode = 0600,
67350+ .proc_handler = &proc_dointvec,
67351+ },
67352+#endif
67353+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
67354+ {
67355+ .procname = "chroot_deny_chmod",
67356+ .data = &grsec_enable_chroot_chmod,
67357+ .maxlen = sizeof(int),
67358+ .mode = 0600,
67359+ .proc_handler = &proc_dointvec,
67360+ },
67361+#endif
67362+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
67363+ {
67364+ .procname = "chroot_deny_mknod",
67365+ .data = &grsec_enable_chroot_mknod,
67366+ .maxlen = sizeof(int),
67367+ .mode = 0600,
67368+ .proc_handler = &proc_dointvec,
67369+ },
67370+#endif
67371+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
67372+ {
67373+ .procname = "chroot_restrict_nice",
67374+ .data = &grsec_enable_chroot_nice,
67375+ .maxlen = sizeof(int),
67376+ .mode = 0600,
67377+ .proc_handler = &proc_dointvec,
67378+ },
67379+#endif
67380+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
67381+ {
67382+ .procname = "chroot_execlog",
67383+ .data = &grsec_enable_chroot_execlog,
67384+ .maxlen = sizeof(int),
67385+ .mode = 0600,
67386+ .proc_handler = &proc_dointvec,
67387+ },
67388+#endif
67389+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67390+ {
67391+ .procname = "chroot_caps",
67392+ .data = &grsec_enable_chroot_caps,
67393+ .maxlen = sizeof(int),
67394+ .mode = 0600,
67395+ .proc_handler = &proc_dointvec,
67396+ },
67397+#endif
67398+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
67399+ {
67400+ .procname = "chroot_deny_sysctl",
67401+ .data = &grsec_enable_chroot_sysctl,
67402+ .maxlen = sizeof(int),
67403+ .mode = 0600,
67404+ .proc_handler = &proc_dointvec,
67405+ },
67406+#endif
67407+#ifdef CONFIG_GRKERNSEC_TPE
67408+ {
67409+ .procname = "tpe",
67410+ .data = &grsec_enable_tpe,
67411+ .maxlen = sizeof(int),
67412+ .mode = 0600,
67413+ .proc_handler = &proc_dointvec,
67414+ },
67415+ {
67416+ .procname = "tpe_gid",
67417+ .data = &grsec_tpe_gid,
67418+ .maxlen = sizeof(int),
67419+ .mode = 0600,
67420+ .proc_handler = &proc_dointvec,
67421+ },
67422+#endif
67423+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
67424+ {
67425+ .procname = "tpe_invert",
67426+ .data = &grsec_enable_tpe_invert,
67427+ .maxlen = sizeof(int),
67428+ .mode = 0600,
67429+ .proc_handler = &proc_dointvec,
67430+ },
67431+#endif
67432+#ifdef CONFIG_GRKERNSEC_TPE_ALL
67433+ {
67434+ .procname = "tpe_restrict_all",
67435+ .data = &grsec_enable_tpe_all,
67436+ .maxlen = sizeof(int),
67437+ .mode = 0600,
67438+ .proc_handler = &proc_dointvec,
67439+ },
67440+#endif
67441+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
67442+ {
67443+ .procname = "socket_all",
67444+ .data = &grsec_enable_socket_all,
67445+ .maxlen = sizeof(int),
67446+ .mode = 0600,
67447+ .proc_handler = &proc_dointvec,
67448+ },
67449+ {
67450+ .procname = "socket_all_gid",
67451+ .data = &grsec_socket_all_gid,
67452+ .maxlen = sizeof(int),
67453+ .mode = 0600,
67454+ .proc_handler = &proc_dointvec,
67455+ },
67456+#endif
67457+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
67458+ {
67459+ .procname = "socket_client",
67460+ .data = &grsec_enable_socket_client,
67461+ .maxlen = sizeof(int),
67462+ .mode = 0600,
67463+ .proc_handler = &proc_dointvec,
67464+ },
67465+ {
67466+ .procname = "socket_client_gid",
67467+ .data = &grsec_socket_client_gid,
67468+ .maxlen = sizeof(int),
67469+ .mode = 0600,
67470+ .proc_handler = &proc_dointvec,
67471+ },
67472+#endif
67473+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
67474+ {
67475+ .procname = "socket_server",
67476+ .data = &grsec_enable_socket_server,
67477+ .maxlen = sizeof(int),
67478+ .mode = 0600,
67479+ .proc_handler = &proc_dointvec,
67480+ },
67481+ {
67482+ .procname = "socket_server_gid",
67483+ .data = &grsec_socket_server_gid,
67484+ .maxlen = sizeof(int),
67485+ .mode = 0600,
67486+ .proc_handler = &proc_dointvec,
67487+ },
67488+#endif
67489+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
67490+ {
67491+ .procname = "audit_group",
67492+ .data = &grsec_enable_group,
67493+ .maxlen = sizeof(int),
67494+ .mode = 0600,
67495+ .proc_handler = &proc_dointvec,
67496+ },
67497+ {
67498+ .procname = "audit_gid",
67499+ .data = &grsec_audit_gid,
67500+ .maxlen = sizeof(int),
67501+ .mode = 0600,
67502+ .proc_handler = &proc_dointvec,
67503+ },
67504+#endif
67505+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
67506+ {
67507+ .procname = "audit_chdir",
67508+ .data = &grsec_enable_chdir,
67509+ .maxlen = sizeof(int),
67510+ .mode = 0600,
67511+ .proc_handler = &proc_dointvec,
67512+ },
67513+#endif
67514+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
67515+ {
67516+ .procname = "audit_mount",
67517+ .data = &grsec_enable_mount,
67518+ .maxlen = sizeof(int),
67519+ .mode = 0600,
67520+ .proc_handler = &proc_dointvec,
67521+ },
67522+#endif
67523+#ifdef CONFIG_GRKERNSEC_DMESG
67524+ {
67525+ .procname = "dmesg",
67526+ .data = &grsec_enable_dmesg,
67527+ .maxlen = sizeof(int),
67528+ .mode = 0600,
67529+ .proc_handler = &proc_dointvec,
67530+ },
67531+#endif
67532+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
67533+ {
67534+ .procname = "chroot_findtask",
67535+ .data = &grsec_enable_chroot_findtask,
67536+ .maxlen = sizeof(int),
67537+ .mode = 0600,
67538+ .proc_handler = &proc_dointvec,
67539+ },
67540+#endif
67541+#ifdef CONFIG_GRKERNSEC_RESLOG
67542+ {
67543+ .procname = "resource_logging",
67544+ .data = &grsec_resource_logging,
67545+ .maxlen = sizeof(int),
67546+ .mode = 0600,
67547+ .proc_handler = &proc_dointvec,
67548+ },
67549+#endif
67550+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
67551+ {
67552+ .procname = "audit_ptrace",
67553+ .data = &grsec_enable_audit_ptrace,
67554+ .maxlen = sizeof(int),
67555+ .mode = 0600,
67556+ .proc_handler = &proc_dointvec,
67557+ },
67558+#endif
67559+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67560+ {
67561+ .procname = "harden_ptrace",
67562+ .data = &grsec_enable_harden_ptrace,
67563+ .maxlen = sizeof(int),
67564+ .mode = 0600,
67565+ .proc_handler = &proc_dointvec,
67566+ },
67567+#endif
67568+ {
67569+ .procname = "grsec_lock",
67570+ .data = &grsec_lock,
67571+ .maxlen = sizeof(int),
67572+ .mode = 0600,
67573+ .proc_handler = &proc_dointvec,
67574+ },
67575+#endif
67576+#ifdef CONFIG_GRKERNSEC_ROFS
67577+ {
67578+ .procname = "romount_protect",
67579+ .data = &grsec_enable_rofs,
67580+ .maxlen = sizeof(int),
67581+ .mode = 0600,
67582+ .proc_handler = &proc_dointvec_minmax,
67583+ .extra1 = &one,
67584+ .extra2 = &one,
67585+ },
67586+#endif
67587+ { }
67588+};
67589+#endif
67590diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
67591new file mode 100644
67592index 0000000..0dc13c3
67593--- /dev/null
67594+++ b/grsecurity/grsec_time.c
67595@@ -0,0 +1,16 @@
67596+#include <linux/kernel.h>
67597+#include <linux/sched.h>
67598+#include <linux/grinternal.h>
67599+#include <linux/module.h>
67600+
67601+void
67602+gr_log_timechange(void)
67603+{
67604+#ifdef CONFIG_GRKERNSEC_TIME
67605+ if (grsec_enable_time)
67606+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
67607+#endif
67608+ return;
67609+}
67610+
67611+EXPORT_SYMBOL(gr_log_timechange);
67612diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
67613new file mode 100644
67614index 0000000..ee57dcf
67615--- /dev/null
67616+++ b/grsecurity/grsec_tpe.c
67617@@ -0,0 +1,73 @@
67618+#include <linux/kernel.h>
67619+#include <linux/sched.h>
67620+#include <linux/file.h>
67621+#include <linux/fs.h>
67622+#include <linux/grinternal.h>
67623+
67624+extern int gr_acl_tpe_check(void);
67625+
67626+int
67627+gr_tpe_allow(const struct file *file)
67628+{
67629+#ifdef CONFIG_GRKERNSEC
67630+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
67631+ const struct cred *cred = current_cred();
67632+ char *msg = NULL;
67633+ char *msg2 = NULL;
67634+
67635+ // never restrict root
67636+ if (gr_is_global_root(cred->uid))
67637+ return 1;
67638+
67639+ if (grsec_enable_tpe) {
67640+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
67641+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
67642+ msg = "not being in trusted group";
67643+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
67644+ msg = "being in untrusted group";
67645+#else
67646+ if (in_group_p(grsec_tpe_gid))
67647+ msg = "being in untrusted group";
67648+#endif
67649+ }
67650+ if (!msg && gr_acl_tpe_check())
67651+ msg = "being in untrusted role";
67652+
67653+ // not in any affected group/role
67654+ if (!msg)
67655+ goto next_check;
67656+
67657+ if (gr_is_global_nonroot(inode->i_uid))
67658+ msg2 = "file in non-root-owned directory";
67659+ else if (inode->i_mode & S_IWOTH)
67660+ msg2 = "file in world-writable directory";
67661+ else if (inode->i_mode & S_IWGRP)
67662+ msg2 = "file in group-writable directory";
67663+
67664+ if (msg && msg2) {
67665+ char fullmsg[70] = {0};
67666+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
67667+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
67668+ return 0;
67669+ }
67670+ msg = NULL;
67671+next_check:
67672+#ifdef CONFIG_GRKERNSEC_TPE_ALL
67673+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
67674+ return 1;
67675+
67676+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
67677+ msg = "directory not owned by user";
67678+ else if (inode->i_mode & S_IWOTH)
67679+ msg = "file in world-writable directory";
67680+ else if (inode->i_mode & S_IWGRP)
67681+ msg = "file in group-writable directory";
67682+
67683+ if (msg) {
67684+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
67685+ return 0;
67686+ }
67687+#endif
67688+#endif
67689+ return 1;
67690+}
67691diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
67692new file mode 100644
67693index 0000000..9f7b1ac
67694--- /dev/null
67695+++ b/grsecurity/grsum.c
67696@@ -0,0 +1,61 @@
67697+#include <linux/err.h>
67698+#include <linux/kernel.h>
67699+#include <linux/sched.h>
67700+#include <linux/mm.h>
67701+#include <linux/scatterlist.h>
67702+#include <linux/crypto.h>
67703+#include <linux/gracl.h>
67704+
67705+
67706+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
67707+#error "crypto and sha256 must be built into the kernel"
67708+#endif
67709+
67710+int
67711+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
67712+{
67713+ char *p;
67714+ struct crypto_hash *tfm;
67715+ struct hash_desc desc;
67716+ struct scatterlist sg;
67717+ unsigned char temp_sum[GR_SHA_LEN];
67718+ volatile int retval = 0;
67719+ volatile int dummy = 0;
67720+ unsigned int i;
67721+
67722+ sg_init_table(&sg, 1);
67723+
67724+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
67725+ if (IS_ERR(tfm)) {
67726+ /* should never happen, since sha256 should be built in */
67727+ return 1;
67728+ }
67729+
67730+ desc.tfm = tfm;
67731+ desc.flags = 0;
67732+
67733+ crypto_hash_init(&desc);
67734+
67735+ p = salt;
67736+ sg_set_buf(&sg, p, GR_SALT_LEN);
67737+ crypto_hash_update(&desc, &sg, sg.length);
67738+
67739+ p = entry->pw;
67740+ sg_set_buf(&sg, p, strlen(p));
67741+
67742+ crypto_hash_update(&desc, &sg, sg.length);
67743+
67744+ crypto_hash_final(&desc, temp_sum);
67745+
67746+ memset(entry->pw, 0, GR_PW_LEN);
67747+
67748+ for (i = 0; i < GR_SHA_LEN; i++)
67749+ if (sum[i] != temp_sum[i])
67750+ retval = 1;
67751+ else
67752+ dummy = 1; // waste a cycle
67753+
67754+ crypto_free_hash(tfm);
67755+
67756+ return retval;
67757+}
67758diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67759index 77ff547..181834f 100644
67760--- a/include/asm-generic/4level-fixup.h
67761+++ b/include/asm-generic/4level-fixup.h
67762@@ -13,8 +13,10 @@
67763 #define pmd_alloc(mm, pud, address) \
67764 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67765 NULL: pmd_offset(pud, address))
67766+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67767
67768 #define pud_alloc(mm, pgd, address) (pgd)
67769+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67770 #define pud_offset(pgd, start) (pgd)
67771 #define pud_none(pud) 0
67772 #define pud_bad(pud) 0
67773diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67774index b7babf0..04ad282 100644
67775--- a/include/asm-generic/atomic-long.h
67776+++ b/include/asm-generic/atomic-long.h
67777@@ -22,6 +22,12 @@
67778
67779 typedef atomic64_t atomic_long_t;
67780
67781+#ifdef CONFIG_PAX_REFCOUNT
67782+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67783+#else
67784+typedef atomic64_t atomic_long_unchecked_t;
67785+#endif
67786+
67787 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67788
67789 static inline long atomic_long_read(atomic_long_t *l)
67790@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67791 return (long)atomic64_read(v);
67792 }
67793
67794+#ifdef CONFIG_PAX_REFCOUNT
67795+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67796+{
67797+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67798+
67799+ return (long)atomic64_read_unchecked(v);
67800+}
67801+#endif
67802+
67803 static inline void atomic_long_set(atomic_long_t *l, long i)
67804 {
67805 atomic64_t *v = (atomic64_t *)l;
67806@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67807 atomic64_set(v, i);
67808 }
67809
67810+#ifdef CONFIG_PAX_REFCOUNT
67811+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67812+{
67813+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67814+
67815+ atomic64_set_unchecked(v, i);
67816+}
67817+#endif
67818+
67819 static inline void atomic_long_inc(atomic_long_t *l)
67820 {
67821 atomic64_t *v = (atomic64_t *)l;
67822@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67823 atomic64_inc(v);
67824 }
67825
67826+#ifdef CONFIG_PAX_REFCOUNT
67827+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67828+{
67829+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67830+
67831+ atomic64_inc_unchecked(v);
67832+}
67833+#endif
67834+
67835 static inline void atomic_long_dec(atomic_long_t *l)
67836 {
67837 atomic64_t *v = (atomic64_t *)l;
67838@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67839 atomic64_dec(v);
67840 }
67841
67842+#ifdef CONFIG_PAX_REFCOUNT
67843+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67844+{
67845+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67846+
67847+ atomic64_dec_unchecked(v);
67848+}
67849+#endif
67850+
67851 static inline void atomic_long_add(long i, atomic_long_t *l)
67852 {
67853 atomic64_t *v = (atomic64_t *)l;
67854@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67855 atomic64_add(i, v);
67856 }
67857
67858+#ifdef CONFIG_PAX_REFCOUNT
67859+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67860+{
67861+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67862+
67863+ atomic64_add_unchecked(i, v);
67864+}
67865+#endif
67866+
67867 static inline void atomic_long_sub(long i, atomic_long_t *l)
67868 {
67869 atomic64_t *v = (atomic64_t *)l;
67870@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67871 atomic64_sub(i, v);
67872 }
67873
67874+#ifdef CONFIG_PAX_REFCOUNT
67875+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67876+{
67877+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67878+
67879+ atomic64_sub_unchecked(i, v);
67880+}
67881+#endif
67882+
67883 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67884 {
67885 atomic64_t *v = (atomic64_t *)l;
67886@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67887 return (long)atomic64_add_return(i, v);
67888 }
67889
67890+#ifdef CONFIG_PAX_REFCOUNT
67891+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67892+{
67893+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67894+
67895+ return (long)atomic64_add_return_unchecked(i, v);
67896+}
67897+#endif
67898+
67899 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67900 {
67901 atomic64_t *v = (atomic64_t *)l;
67902@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67903 return (long)atomic64_inc_return(v);
67904 }
67905
67906+#ifdef CONFIG_PAX_REFCOUNT
67907+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67908+{
67909+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67910+
67911+ return (long)atomic64_inc_return_unchecked(v);
67912+}
67913+#endif
67914+
67915 static inline long atomic_long_dec_return(atomic_long_t *l)
67916 {
67917 atomic64_t *v = (atomic64_t *)l;
67918@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67919
67920 typedef atomic_t atomic_long_t;
67921
67922+#ifdef CONFIG_PAX_REFCOUNT
67923+typedef atomic_unchecked_t atomic_long_unchecked_t;
67924+#else
67925+typedef atomic_t atomic_long_unchecked_t;
67926+#endif
67927+
67928 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67929 static inline long atomic_long_read(atomic_long_t *l)
67930 {
67931@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67932 return (long)atomic_read(v);
67933 }
67934
67935+#ifdef CONFIG_PAX_REFCOUNT
67936+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67937+{
67938+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67939+
67940+ return (long)atomic_read_unchecked(v);
67941+}
67942+#endif
67943+
67944 static inline void atomic_long_set(atomic_long_t *l, long i)
67945 {
67946 atomic_t *v = (atomic_t *)l;
67947@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67948 atomic_set(v, i);
67949 }
67950
67951+#ifdef CONFIG_PAX_REFCOUNT
67952+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67953+{
67954+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67955+
67956+ atomic_set_unchecked(v, i);
67957+}
67958+#endif
67959+
67960 static inline void atomic_long_inc(atomic_long_t *l)
67961 {
67962 atomic_t *v = (atomic_t *)l;
67963@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67964 atomic_inc(v);
67965 }
67966
67967+#ifdef CONFIG_PAX_REFCOUNT
67968+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67969+{
67970+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67971+
67972+ atomic_inc_unchecked(v);
67973+}
67974+#endif
67975+
67976 static inline void atomic_long_dec(atomic_long_t *l)
67977 {
67978 atomic_t *v = (atomic_t *)l;
67979@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67980 atomic_dec(v);
67981 }
67982
67983+#ifdef CONFIG_PAX_REFCOUNT
67984+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67985+{
67986+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67987+
67988+ atomic_dec_unchecked(v);
67989+}
67990+#endif
67991+
67992 static inline void atomic_long_add(long i, atomic_long_t *l)
67993 {
67994 atomic_t *v = (atomic_t *)l;
67995@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67996 atomic_add(i, v);
67997 }
67998
67999+#ifdef CONFIG_PAX_REFCOUNT
68000+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
68001+{
68002+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
68003+
68004+ atomic_add_unchecked(i, v);
68005+}
68006+#endif
68007+
68008 static inline void atomic_long_sub(long i, atomic_long_t *l)
68009 {
68010 atomic_t *v = (atomic_t *)l;
68011@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
68012 atomic_sub(i, v);
68013 }
68014
68015+#ifdef CONFIG_PAX_REFCOUNT
68016+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
68017+{
68018+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
68019+
68020+ atomic_sub_unchecked(i, v);
68021+}
68022+#endif
68023+
68024 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
68025 {
68026 atomic_t *v = (atomic_t *)l;
68027@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
68028 return (long)atomic_add_return(i, v);
68029 }
68030
68031+#ifdef CONFIG_PAX_REFCOUNT
68032+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
68033+{
68034+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
68035+
68036+ return (long)atomic_add_return_unchecked(i, v);
68037+}
68038+
68039+#endif
68040+
68041 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
68042 {
68043 atomic_t *v = (atomic_t *)l;
68044@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
68045 return (long)atomic_inc_return(v);
68046 }
68047
68048+#ifdef CONFIG_PAX_REFCOUNT
68049+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
68050+{
68051+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
68052+
68053+ return (long)atomic_inc_return_unchecked(v);
68054+}
68055+#endif
68056+
68057 static inline long atomic_long_dec_return(atomic_long_t *l)
68058 {
68059 atomic_t *v = (atomic_t *)l;
68060@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
68061
68062 #endif /* BITS_PER_LONG == 64 */
68063
68064+#ifdef CONFIG_PAX_REFCOUNT
68065+static inline void pax_refcount_needs_these_functions(void)
68066+{
68067+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
68068+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
68069+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
68070+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
68071+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
68072+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
68073+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
68074+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
68075+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
68076+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
68077+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
68078+#ifdef CONFIG_X86
68079+ atomic_clear_mask_unchecked(0, NULL);
68080+ atomic_set_mask_unchecked(0, NULL);
68081+#endif
68082+
68083+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
68084+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
68085+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
68086+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
68087+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
68088+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
68089+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
68090+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
68091+}
68092+#else
68093+#define atomic_read_unchecked(v) atomic_read(v)
68094+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
68095+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
68096+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
68097+#define atomic_inc_unchecked(v) atomic_inc(v)
68098+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
68099+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
68100+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
68101+#define atomic_dec_unchecked(v) atomic_dec(v)
68102+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
68103+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
68104+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
68105+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
68106+
68107+#define atomic_long_read_unchecked(v) atomic_long_read(v)
68108+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
68109+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
68110+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
68111+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
68112+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
68113+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
68114+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
68115+#endif
68116+
68117 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
68118diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
68119index 33bd2de..f31bff97 100644
68120--- a/include/asm-generic/atomic.h
68121+++ b/include/asm-generic/atomic.h
68122@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
68123 * Atomically clears the bits set in @mask from @v
68124 */
68125 #ifndef atomic_clear_mask
68126-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
68127+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
68128 {
68129 unsigned long flags;
68130
68131diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
68132index b18ce4f..2ee2843 100644
68133--- a/include/asm-generic/atomic64.h
68134+++ b/include/asm-generic/atomic64.h
68135@@ -16,6 +16,8 @@ typedef struct {
68136 long long counter;
68137 } atomic64_t;
68138
68139+typedef atomic64_t atomic64_unchecked_t;
68140+
68141 #define ATOMIC64_INIT(i) { (i) }
68142
68143 extern long long atomic64_read(const atomic64_t *v);
68144@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
68145 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
68146 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
68147
68148+#define atomic64_read_unchecked(v) atomic64_read(v)
68149+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
68150+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
68151+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
68152+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
68153+#define atomic64_inc_unchecked(v) atomic64_inc(v)
68154+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
68155+#define atomic64_dec_unchecked(v) atomic64_dec(v)
68156+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
68157+
68158 #endif /* _ASM_GENERIC_ATOMIC64_H */
68159diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
68160index 1bfcfe5..e04c5c9 100644
68161--- a/include/asm-generic/cache.h
68162+++ b/include/asm-generic/cache.h
68163@@ -6,7 +6,7 @@
68164 * cache lines need to provide their own cache.h.
68165 */
68166
68167-#define L1_CACHE_SHIFT 5
68168-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
68169+#define L1_CACHE_SHIFT 5UL
68170+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
68171
68172 #endif /* __ASM_GENERIC_CACHE_H */
68173diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
68174index 0d68a1e..b74a761 100644
68175--- a/include/asm-generic/emergency-restart.h
68176+++ b/include/asm-generic/emergency-restart.h
68177@@ -1,7 +1,7 @@
68178 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
68179 #define _ASM_GENERIC_EMERGENCY_RESTART_H
68180
68181-static inline void machine_emergency_restart(void)
68182+static inline __noreturn void machine_emergency_restart(void)
68183 {
68184 machine_restart(NULL);
68185 }
68186diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
68187index 90f99c7..00ce236 100644
68188--- a/include/asm-generic/kmap_types.h
68189+++ b/include/asm-generic/kmap_types.h
68190@@ -2,9 +2,9 @@
68191 #define _ASM_GENERIC_KMAP_TYPES_H
68192
68193 #ifdef __WITH_KM_FENCE
68194-# define KM_TYPE_NR 41
68195+# define KM_TYPE_NR 42
68196 #else
68197-# define KM_TYPE_NR 20
68198+# define KM_TYPE_NR 21
68199 #endif
68200
68201 #endif
68202diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
68203index 9ceb03b..62b0b8f 100644
68204--- a/include/asm-generic/local.h
68205+++ b/include/asm-generic/local.h
68206@@ -23,24 +23,37 @@ typedef struct
68207 atomic_long_t a;
68208 } local_t;
68209
68210+typedef struct {
68211+ atomic_long_unchecked_t a;
68212+} local_unchecked_t;
68213+
68214 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
68215
68216 #define local_read(l) atomic_long_read(&(l)->a)
68217+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
68218 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
68219+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
68220 #define local_inc(l) atomic_long_inc(&(l)->a)
68221+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
68222 #define local_dec(l) atomic_long_dec(&(l)->a)
68223+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
68224 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
68225+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
68226 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
68227+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
68228
68229 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
68230 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
68231 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
68232 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
68233 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
68234+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
68235 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
68236 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
68237+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
68238
68239 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
68240+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
68241 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
68242 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
68243 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
68244diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
68245index 725612b..9cc513a 100644
68246--- a/include/asm-generic/pgtable-nopmd.h
68247+++ b/include/asm-generic/pgtable-nopmd.h
68248@@ -1,14 +1,19 @@
68249 #ifndef _PGTABLE_NOPMD_H
68250 #define _PGTABLE_NOPMD_H
68251
68252-#ifndef __ASSEMBLY__
68253-
68254 #include <asm-generic/pgtable-nopud.h>
68255
68256-struct mm_struct;
68257-
68258 #define __PAGETABLE_PMD_FOLDED
68259
68260+#define PMD_SHIFT PUD_SHIFT
68261+#define PTRS_PER_PMD 1
68262+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
68263+#define PMD_MASK (~(PMD_SIZE-1))
68264+
68265+#ifndef __ASSEMBLY__
68266+
68267+struct mm_struct;
68268+
68269 /*
68270 * Having the pmd type consist of a pud gets the size right, and allows
68271 * us to conceptually access the pud entry that this pmd is folded into
68272@@ -16,11 +21,6 @@ struct mm_struct;
68273 */
68274 typedef struct { pud_t pud; } pmd_t;
68275
68276-#define PMD_SHIFT PUD_SHIFT
68277-#define PTRS_PER_PMD 1
68278-#define PMD_SIZE (1UL << PMD_SHIFT)
68279-#define PMD_MASK (~(PMD_SIZE-1))
68280-
68281 /*
68282 * The "pud_xxx()" functions here are trivial for a folded two-level
68283 * setup: the pmd is never bad, and a pmd always exists (as it's folded
68284diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
68285index 810431d..0ec4804f 100644
68286--- a/include/asm-generic/pgtable-nopud.h
68287+++ b/include/asm-generic/pgtable-nopud.h
68288@@ -1,10 +1,15 @@
68289 #ifndef _PGTABLE_NOPUD_H
68290 #define _PGTABLE_NOPUD_H
68291
68292-#ifndef __ASSEMBLY__
68293-
68294 #define __PAGETABLE_PUD_FOLDED
68295
68296+#define PUD_SHIFT PGDIR_SHIFT
68297+#define PTRS_PER_PUD 1
68298+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
68299+#define PUD_MASK (~(PUD_SIZE-1))
68300+
68301+#ifndef __ASSEMBLY__
68302+
68303 /*
68304 * Having the pud type consist of a pgd gets the size right, and allows
68305 * us to conceptually access the pgd entry that this pud is folded into
68306@@ -12,11 +17,6 @@
68307 */
68308 typedef struct { pgd_t pgd; } pud_t;
68309
68310-#define PUD_SHIFT PGDIR_SHIFT
68311-#define PTRS_PER_PUD 1
68312-#define PUD_SIZE (1UL << PUD_SHIFT)
68313-#define PUD_MASK (~(PUD_SIZE-1))
68314-
68315 /*
68316 * The "pgd_xxx()" functions here are trivial for a folded two-level
68317 * setup: the pud is never bad, and a pud always exists (as it's folded
68318@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
68319 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
68320
68321 #define pgd_populate(mm, pgd, pud) do { } while (0)
68322+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
68323 /*
68324 * (puds are folded into pgds so this doesn't get actually called,
68325 * but the define is needed for a generic inline function.)
68326diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
68327index a59ff51..2594a70 100644
68328--- a/include/asm-generic/pgtable.h
68329+++ b/include/asm-generic/pgtable.h
68330@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
68331 }
68332 #endif /* CONFIG_NUMA_BALANCING */
68333
68334+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
68335+static inline unsigned long pax_open_kernel(void) { return 0; }
68336+#endif
68337+
68338+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
68339+static inline unsigned long pax_close_kernel(void) { return 0; }
68340+#endif
68341+
68342 #endif /* CONFIG_MMU */
68343
68344 #endif /* !__ASSEMBLY__ */
68345diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
68346index eb58d2d..df131bf 100644
68347--- a/include/asm-generic/vmlinux.lds.h
68348+++ b/include/asm-generic/vmlinux.lds.h
68349@@ -239,6 +239,7 @@
68350 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
68351 VMLINUX_SYMBOL(__start_rodata) = .; \
68352 *(.rodata) *(.rodata.*) \
68353+ *(.data..read_only) \
68354 *(__vermagic) /* Kernel version magic */ \
68355 . = ALIGN(8); \
68356 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
68357@@ -749,17 +750,18 @@
68358 * section in the linker script will go there too. @phdr should have
68359 * a leading colon.
68360 *
68361- * Note that this macros defines __per_cpu_load as an absolute symbol.
68362+ * Note that this macros defines per_cpu_load as an absolute symbol.
68363 * If there is no need to put the percpu section at a predetermined
68364 * address, use PERCPU_SECTION.
68365 */
68366 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
68367- VMLINUX_SYMBOL(__per_cpu_load) = .; \
68368- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
68369+ per_cpu_load = .; \
68370+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
68371 - LOAD_OFFSET) { \
68372+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
68373 PERCPU_INPUT(cacheline) \
68374 } phdr \
68375- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
68376+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
68377
68378 /**
68379 * PERCPU_SECTION - define output section for percpu area, simple version
68380diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
68381index 418d270..bfd2794 100644
68382--- a/include/crypto/algapi.h
68383+++ b/include/crypto/algapi.h
68384@@ -34,7 +34,7 @@ struct crypto_type {
68385 unsigned int maskclear;
68386 unsigned int maskset;
68387 unsigned int tfmsize;
68388-};
68389+} __do_const;
68390
68391 struct crypto_instance {
68392 struct crypto_alg alg;
68393diff --git a/include/drm/drmP.h b/include/drm/drmP.h
68394index 63d17ee..716de2b 100644
68395--- a/include/drm/drmP.h
68396+++ b/include/drm/drmP.h
68397@@ -72,6 +72,7 @@
68398 #include <linux/workqueue.h>
68399 #include <linux/poll.h>
68400 #include <asm/pgalloc.h>
68401+#include <asm/local.h>
68402 #include <drm/drm.h>
68403 #include <drm/drm_sarea.h>
68404
68405@@ -296,10 +297,12 @@ do { \
68406 * \param cmd command.
68407 * \param arg argument.
68408 */
68409-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
68410+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
68411+ struct drm_file *file_priv);
68412+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
68413 struct drm_file *file_priv);
68414
68415-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
68416+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
68417 unsigned long arg);
68418
68419 #define DRM_IOCTL_NR(n) _IOC_NR(n)
68420@@ -314,10 +317,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
68421 struct drm_ioctl_desc {
68422 unsigned int cmd;
68423 int flags;
68424- drm_ioctl_t *func;
68425+ drm_ioctl_t func;
68426 unsigned int cmd_drv;
68427 const char *name;
68428-};
68429+} __do_const;
68430
68431 /**
68432 * Creates a driver or general drm_ioctl_desc array entry for the given
68433@@ -1015,7 +1018,7 @@ struct drm_info_list {
68434 int (*show)(struct seq_file*, void*); /** show callback */
68435 u32 driver_features; /**< Required driver features for this entry */
68436 void *data;
68437-};
68438+} __do_const;
68439
68440 /**
68441 * debugfs node structure. This structure represents a debugfs file.
68442@@ -1088,7 +1091,7 @@ struct drm_device {
68443
68444 /** \name Usage Counters */
68445 /*@{ */
68446- int open_count; /**< Outstanding files open */
68447+ local_t open_count; /**< Outstanding files open */
68448 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
68449 atomic_t vma_count; /**< Outstanding vma areas open */
68450 int buf_use; /**< Buffers in use -- cannot alloc */
68451@@ -1099,7 +1102,7 @@ struct drm_device {
68452 /*@{ */
68453 unsigned long counters;
68454 enum drm_stat_type types[15];
68455- atomic_t counts[15];
68456+ atomic_unchecked_t counts[15];
68457 /*@} */
68458
68459 struct list_head filelist;
68460diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
68461index f43d556..94d9343 100644
68462--- a/include/drm/drm_crtc_helper.h
68463+++ b/include/drm/drm_crtc_helper.h
68464@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
68465 struct drm_connector *connector);
68466 /* disable encoder when not in use - more explicit than dpms off */
68467 void (*disable)(struct drm_encoder *encoder);
68468-};
68469+} __no_const;
68470
68471 /**
68472 * drm_connector_helper_funcs - helper operations for connectors
68473diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
68474index 72dcbe8..8db58d7 100644
68475--- a/include/drm/ttm/ttm_memory.h
68476+++ b/include/drm/ttm/ttm_memory.h
68477@@ -48,7 +48,7 @@
68478
68479 struct ttm_mem_shrink {
68480 int (*do_shrink) (struct ttm_mem_shrink *);
68481-};
68482+} __no_const;
68483
68484 /**
68485 * struct ttm_mem_global - Global memory accounting structure.
68486diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
68487index 4b840e8..155d235 100644
68488--- a/include/keys/asymmetric-subtype.h
68489+++ b/include/keys/asymmetric-subtype.h
68490@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
68491 /* Verify the signature on a key of this subtype (optional) */
68492 int (*verify_signature)(const struct key *key,
68493 const struct public_key_signature *sig);
68494-};
68495+} __do_const;
68496
68497 /**
68498 * asymmetric_key_subtype - Get the subtype from an asymmetric key
68499diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
68500index c1da539..1dcec55 100644
68501--- a/include/linux/atmdev.h
68502+++ b/include/linux/atmdev.h
68503@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
68504 #endif
68505
68506 struct k_atm_aal_stats {
68507-#define __HANDLE_ITEM(i) atomic_t i
68508+#define __HANDLE_ITEM(i) atomic_unchecked_t i
68509 __AAL_STAT_ITEMS
68510 #undef __HANDLE_ITEM
68511 };
68512@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
68513 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
68514 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
68515 struct module *owner;
68516-};
68517+} __do_const ;
68518
68519 struct atmphy_ops {
68520 int (*start)(struct atm_dev *dev);
68521diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
68522index 70cf138..0418ee2 100644
68523--- a/include/linux/binfmts.h
68524+++ b/include/linux/binfmts.h
68525@@ -73,8 +73,10 @@ struct linux_binfmt {
68526 int (*load_binary)(struct linux_binprm *);
68527 int (*load_shlib)(struct file *);
68528 int (*core_dump)(struct coredump_params *cprm);
68529+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
68530+ void (*handle_mmap)(struct file *);
68531 unsigned long min_coredump; /* minimal dump size */
68532-};
68533+} __do_const;
68534
68535 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
68536
68537diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
68538index 2fdb4a4..54aad7e 100644
68539--- a/include/linux/blkdev.h
68540+++ b/include/linux/blkdev.h
68541@@ -1526,7 +1526,7 @@ struct block_device_operations {
68542 /* this callback is with swap_lock and sometimes page table lock held */
68543 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
68544 struct module *owner;
68545-};
68546+} __do_const;
68547
68548 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
68549 unsigned long);
68550diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
68551index 7c2e030..b72475d 100644
68552--- a/include/linux/blktrace_api.h
68553+++ b/include/linux/blktrace_api.h
68554@@ -23,7 +23,7 @@ struct blk_trace {
68555 struct dentry *dir;
68556 struct dentry *dropped_file;
68557 struct dentry *msg_file;
68558- atomic_t dropped;
68559+ atomic_unchecked_t dropped;
68560 };
68561
68562 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
68563diff --git a/include/linux/cache.h b/include/linux/cache.h
68564index 4c57065..4307975 100644
68565--- a/include/linux/cache.h
68566+++ b/include/linux/cache.h
68567@@ -16,6 +16,10 @@
68568 #define __read_mostly
68569 #endif
68570
68571+#ifndef __read_only
68572+#define __read_only __read_mostly
68573+#endif
68574+
68575 #ifndef ____cacheline_aligned
68576 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
68577 #endif
68578diff --git a/include/linux/capability.h b/include/linux/capability.h
68579index d9a4f7f4..19f77d6 100644
68580--- a/include/linux/capability.h
68581+++ b/include/linux/capability.h
68582@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
68583 extern bool nsown_capable(int cap);
68584 extern bool inode_capable(const struct inode *inode, int cap);
68585 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
68586+extern bool capable_nolog(int cap);
68587+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
68588+extern bool inode_capable_nolog(const struct inode *inode, int cap);
68589
68590 /* audit system wants to get cap info from files as well */
68591 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
68592
68593+extern int is_privileged_binary(const struct dentry *dentry);
68594+
68595 #endif /* !_LINUX_CAPABILITY_H */
68596diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
68597index 8609d57..86e4d79 100644
68598--- a/include/linux/cdrom.h
68599+++ b/include/linux/cdrom.h
68600@@ -87,7 +87,6 @@ struct cdrom_device_ops {
68601
68602 /* driver specifications */
68603 const int capability; /* capability flags */
68604- int n_minors; /* number of active minor devices */
68605 /* handle uniform packets for scsi type devices (scsi,atapi) */
68606 int (*generic_packet) (struct cdrom_device_info *,
68607 struct packet_command *);
68608diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
68609index 4ce9056..86caac6 100644
68610--- a/include/linux/cleancache.h
68611+++ b/include/linux/cleancache.h
68612@@ -31,7 +31,7 @@ struct cleancache_ops {
68613 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
68614 void (*invalidate_inode)(int, struct cleancache_filekey);
68615 void (*invalidate_fs)(int);
68616-};
68617+} __no_const;
68618
68619 extern struct cleancache_ops *
68620 cleancache_register_ops(struct cleancache_ops *ops);
68621diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
68622index 1186098..f87e53d 100644
68623--- a/include/linux/clk-provider.h
68624+++ b/include/linux/clk-provider.h
68625@@ -132,6 +132,7 @@ struct clk_ops {
68626 unsigned long);
68627 void (*init)(struct clk_hw *hw);
68628 };
68629+typedef struct clk_ops __no_const clk_ops_no_const;
68630
68631 /**
68632 * struct clk_init_data - holds init data that's common to all clocks and is
68633diff --git a/include/linux/compat.h b/include/linux/compat.h
68634index 7f0c1dd..b5729c6 100644
68635--- a/include/linux/compat.h
68636+++ b/include/linux/compat.h
68637@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
68638 compat_size_t __user *len_ptr);
68639
68640 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
68641-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
68642+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
68643 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
68644 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
68645 compat_ssize_t msgsz, int msgflg);
68646@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
68647 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
68648 compat_ulong_t addr, compat_ulong_t data);
68649 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68650- compat_long_t addr, compat_long_t data);
68651+ compat_ulong_t addr, compat_ulong_t data);
68652
68653 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
68654 /*
68655diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
68656index 842de22..7f3a41f 100644
68657--- a/include/linux/compiler-gcc4.h
68658+++ b/include/linux/compiler-gcc4.h
68659@@ -39,9 +39,29 @@
68660 # define __compiletime_warning(message) __attribute__((warning(message)))
68661 # define __compiletime_error(message) __attribute__((error(message)))
68662 #endif /* __CHECKER__ */
68663+
68664+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
68665+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
68666+#define __bos0(ptr) __bos((ptr), 0)
68667+#define __bos1(ptr) __bos((ptr), 1)
68668 #endif /* GCC_VERSION >= 40300 */
68669
68670 #if GCC_VERSION >= 40500
68671+
68672+#ifdef CONSTIFY_PLUGIN
68673+#define __no_const __attribute__((no_const))
68674+#define __do_const __attribute__((do_const))
68675+#endif
68676+
68677+#ifdef SIZE_OVERFLOW_PLUGIN
68678+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
68679+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
68680+#endif
68681+
68682+#ifdef LATENT_ENTROPY_PLUGIN
68683+#define __latent_entropy __attribute__((latent_entropy))
68684+#endif
68685+
68686 /*
68687 * Mark a position in code as unreachable. This can be used to
68688 * suppress control flow warnings after asm blocks that transfer
68689diff --git a/include/linux/compiler.h b/include/linux/compiler.h
68690index 92669cd..1771a15 100644
68691--- a/include/linux/compiler.h
68692+++ b/include/linux/compiler.h
68693@@ -5,11 +5,14 @@
68694
68695 #ifdef __CHECKER__
68696 # define __user __attribute__((noderef, address_space(1)))
68697+# define __force_user __force __user
68698 # define __kernel __attribute__((address_space(0)))
68699+# define __force_kernel __force __kernel
68700 # define __safe __attribute__((safe))
68701 # define __force __attribute__((force))
68702 # define __nocast __attribute__((nocast))
68703 # define __iomem __attribute__((noderef, address_space(2)))
68704+# define __force_iomem __force __iomem
68705 # define __must_hold(x) __attribute__((context(x,1,1)))
68706 # define __acquires(x) __attribute__((context(x,0,1)))
68707 # define __releases(x) __attribute__((context(x,1,0)))
68708@@ -17,20 +20,37 @@
68709 # define __release(x) __context__(x,-1)
68710 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
68711 # define __percpu __attribute__((noderef, address_space(3)))
68712+# define __force_percpu __force __percpu
68713 #ifdef CONFIG_SPARSE_RCU_POINTER
68714 # define __rcu __attribute__((noderef, address_space(4)))
68715+# define __force_rcu __force __rcu
68716 #else
68717 # define __rcu
68718+# define __force_rcu
68719 #endif
68720 extern void __chk_user_ptr(const volatile void __user *);
68721 extern void __chk_io_ptr(const volatile void __iomem *);
68722 #else
68723-# define __user
68724-# define __kernel
68725+# ifdef CHECKER_PLUGIN
68726+//# define __user
68727+//# define __force_user
68728+//# define __kernel
68729+//# define __force_kernel
68730+# else
68731+# ifdef STRUCTLEAK_PLUGIN
68732+# define __user __attribute__((user))
68733+# else
68734+# define __user
68735+# endif
68736+# define __force_user
68737+# define __kernel
68738+# define __force_kernel
68739+# endif
68740 # define __safe
68741 # define __force
68742 # define __nocast
68743 # define __iomem
68744+# define __force_iomem
68745 # define __chk_user_ptr(x) (void)0
68746 # define __chk_io_ptr(x) (void)0
68747 # define __builtin_warning(x, y...) (1)
68748@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68749 # define __release(x) (void)0
68750 # define __cond_lock(x,c) (c)
68751 # define __percpu
68752+# define __force_percpu
68753 # define __rcu
68754+# define __force_rcu
68755 #endif
68756
68757 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68758@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68759 # define __attribute_const__ /* unimplemented */
68760 #endif
68761
68762+#ifndef __no_const
68763+# define __no_const
68764+#endif
68765+
68766+#ifndef __do_const
68767+# define __do_const
68768+#endif
68769+
68770+#ifndef __size_overflow
68771+# define __size_overflow(...)
68772+#endif
68773+
68774+#ifndef __intentional_overflow
68775+# define __intentional_overflow(...)
68776+#endif
68777+
68778+#ifndef __latent_entropy
68779+# define __latent_entropy
68780+#endif
68781+
68782 /*
68783 * Tell gcc if a function is cold. The compiler will assume any path
68784 * directly leading to the call is unlikely.
68785@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68786 #define __cold
68787 #endif
68788
68789+#ifndef __alloc_size
68790+#define __alloc_size(...)
68791+#endif
68792+
68793+#ifndef __bos
68794+#define __bos(ptr, arg)
68795+#endif
68796+
68797+#ifndef __bos0
68798+#define __bos0(ptr)
68799+#endif
68800+
68801+#ifndef __bos1
68802+#define __bos1(ptr)
68803+#endif
68804+
68805 /* Simple shorthand for a section definition */
68806 #ifndef __section
68807 # define __section(S) __attribute__ ((__section__(#S)))
68808@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68809 * use is to mediate communication between process-level code and irq/NMI
68810 * handlers, all running on the same CPU.
68811 */
68812-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68813+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68814+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68815
68816 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
68817 #ifdef CONFIG_KPROBES
68818diff --git a/include/linux/completion.h b/include/linux/completion.h
68819index 33f0280..35c6568 100644
68820--- a/include/linux/completion.h
68821+++ b/include/linux/completion.h
68822@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
68823 extern void wait_for_completion(struct completion *);
68824 extern void wait_for_completion_io(struct completion *);
68825 extern int wait_for_completion_interruptible(struct completion *x);
68826-extern int wait_for_completion_killable(struct completion *x);
68827+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68828 extern unsigned long wait_for_completion_timeout(struct completion *x,
68829 unsigned long timeout);
68830 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
68831 unsigned long timeout);
68832 extern long wait_for_completion_interruptible_timeout(
68833- struct completion *x, unsigned long timeout);
68834+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68835 extern long wait_for_completion_killable_timeout(
68836- struct completion *x, unsigned long timeout);
68837+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68838 extern bool try_wait_for_completion(struct completion *x);
68839 extern bool completion_done(struct completion *x);
68840
68841diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68842index 34025df..d94bbbc 100644
68843--- a/include/linux/configfs.h
68844+++ b/include/linux/configfs.h
68845@@ -125,7 +125,7 @@ struct configfs_attribute {
68846 const char *ca_name;
68847 struct module *ca_owner;
68848 umode_t ca_mode;
68849-};
68850+} __do_const;
68851
68852 /*
68853 * Users often need to create attribute structures for their configurable
68854diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68855index 9f3c7e8..a18c7b6 100644
68856--- a/include/linux/cpu.h
68857+++ b/include/linux/cpu.h
68858@@ -115,7 +115,7 @@ enum {
68859 /* Need to know about CPUs going up/down? */
68860 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68861 #define cpu_notifier(fn, pri) { \
68862- static struct notifier_block fn##_nb __cpuinitdata = \
68863+ static struct notifier_block fn##_nb = \
68864 { .notifier_call = fn, .priority = pri }; \
68865 register_cpu_notifier(&fn##_nb); \
68866 }
68867diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68868index 037d36a..ca5fe6e 100644
68869--- a/include/linux/cpufreq.h
68870+++ b/include/linux/cpufreq.h
68871@@ -262,7 +262,7 @@ struct cpufreq_driver {
68872 int (*suspend) (struct cpufreq_policy *policy);
68873 int (*resume) (struct cpufreq_policy *policy);
68874 struct freq_attr **attr;
68875-};
68876+} __do_const;
68877
68878 /* flags */
68879
68880@@ -321,6 +321,7 @@ struct global_attr {
68881 ssize_t (*store)(struct kobject *a, struct attribute *b,
68882 const char *c, size_t count);
68883 };
68884+typedef struct global_attr __no_const global_attr_no_const;
68885
68886 #define define_one_global_ro(_name) \
68887 static struct global_attr _name = \
68888diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68889index 8f04062..900239a 100644
68890--- a/include/linux/cpuidle.h
68891+++ b/include/linux/cpuidle.h
68892@@ -52,7 +52,8 @@ struct cpuidle_state {
68893 int index);
68894
68895 int (*enter_dead) (struct cpuidle_device *dev, int index);
68896-};
68897+} __do_const;
68898+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68899
68900 /* Idle State Flags */
68901 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68902@@ -191,7 +192,7 @@ struct cpuidle_governor {
68903 void (*reflect) (struct cpuidle_device *dev, int index);
68904
68905 struct module *owner;
68906-};
68907+} __do_const;
68908
68909 #ifdef CONFIG_CPU_IDLE
68910
68911diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68912index d08e4d2..95fad61 100644
68913--- a/include/linux/cpumask.h
68914+++ b/include/linux/cpumask.h
68915@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68916 }
68917
68918 /* Valid inputs for n are -1 and 0. */
68919-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68920+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68921 {
68922 return n+1;
68923 }
68924
68925-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68926+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68927 {
68928 return n+1;
68929 }
68930
68931-static inline unsigned int cpumask_next_and(int n,
68932+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68933 const struct cpumask *srcp,
68934 const struct cpumask *andp)
68935 {
68936@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68937 *
68938 * Returns >= nr_cpu_ids if no further cpus set.
68939 */
68940-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68941+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68942 {
68943 /* -1 is a legal arg here. */
68944 if (n != -1)
68945@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68946 *
68947 * Returns >= nr_cpu_ids if no further cpus unset.
68948 */
68949-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68950+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68951 {
68952 /* -1 is a legal arg here. */
68953 if (n != -1)
68954@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68955 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68956 }
68957
68958-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68959+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68960 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68961
68962 /**
68963diff --git a/include/linux/cred.h b/include/linux/cred.h
68964index 04421e8..6bce4ef 100644
68965--- a/include/linux/cred.h
68966+++ b/include/linux/cred.h
68967@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68968 static inline void validate_process_creds(void)
68969 {
68970 }
68971+static inline void validate_task_creds(struct task_struct *task)
68972+{
68973+}
68974 #endif
68975
68976 /**
68977diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68978index b92eadf..b4ecdc1 100644
68979--- a/include/linux/crypto.h
68980+++ b/include/linux/crypto.h
68981@@ -373,7 +373,7 @@ struct cipher_tfm {
68982 const u8 *key, unsigned int keylen);
68983 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68984 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68985-};
68986+} __no_const;
68987
68988 struct hash_tfm {
68989 int (*init)(struct hash_desc *desc);
68990@@ -394,13 +394,13 @@ struct compress_tfm {
68991 int (*cot_decompress)(struct crypto_tfm *tfm,
68992 const u8 *src, unsigned int slen,
68993 u8 *dst, unsigned int *dlen);
68994-};
68995+} __no_const;
68996
68997 struct rng_tfm {
68998 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68999 unsigned int dlen);
69000 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
69001-};
69002+} __no_const;
69003
69004 #define crt_ablkcipher crt_u.ablkcipher
69005 #define crt_aead crt_u.aead
69006diff --git a/include/linux/ctype.h b/include/linux/ctype.h
69007index 653589e..4ef254a 100644
69008--- a/include/linux/ctype.h
69009+++ b/include/linux/ctype.h
69010@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
69011 * Fast implementation of tolower() for internal usage. Do not use in your
69012 * code.
69013 */
69014-static inline char _tolower(const char c)
69015+static inline unsigned char _tolower(const unsigned char c)
69016 {
69017 return c | 0x20;
69018 }
69019diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
69020index 7925bf0..d5143d2 100644
69021--- a/include/linux/decompress/mm.h
69022+++ b/include/linux/decompress/mm.h
69023@@ -77,7 +77,7 @@ static void free(void *where)
69024 * warnings when not needed (indeed large_malloc / large_free are not
69025 * needed by inflate */
69026
69027-#define malloc(a) kmalloc(a, GFP_KERNEL)
69028+#define malloc(a) kmalloc((a), GFP_KERNEL)
69029 #define free(a) kfree(a)
69030
69031 #define large_malloc(a) vmalloc(a)
69032diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
69033index fe8c447..bdc1f33 100644
69034--- a/include/linux/devfreq.h
69035+++ b/include/linux/devfreq.h
69036@@ -114,7 +114,7 @@ struct devfreq_governor {
69037 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
69038 int (*event_handler)(struct devfreq *devfreq,
69039 unsigned int event, void *data);
69040-};
69041+} __do_const;
69042
69043 /**
69044 * struct devfreq - Device devfreq structure
69045diff --git a/include/linux/device.h b/include/linux/device.h
69046index c0a1261..dba7569 100644
69047--- a/include/linux/device.h
69048+++ b/include/linux/device.h
69049@@ -290,7 +290,7 @@ struct subsys_interface {
69050 struct list_head node;
69051 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
69052 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
69053-};
69054+} __do_const;
69055
69056 int subsys_interface_register(struct subsys_interface *sif);
69057 void subsys_interface_unregister(struct subsys_interface *sif);
69058@@ -473,7 +473,7 @@ struct device_type {
69059 void (*release)(struct device *dev);
69060
69061 const struct dev_pm_ops *pm;
69062-};
69063+} __do_const;
69064
69065 /* interface for exporting device attributes */
69066 struct device_attribute {
69067@@ -483,11 +483,12 @@ struct device_attribute {
69068 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
69069 const char *buf, size_t count);
69070 };
69071+typedef struct device_attribute __no_const device_attribute_no_const;
69072
69073 struct dev_ext_attribute {
69074 struct device_attribute attr;
69075 void *var;
69076-};
69077+} __do_const;
69078
69079 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
69080 char *buf);
69081diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
69082index 94af418..b1ca7a2 100644
69083--- a/include/linux/dma-mapping.h
69084+++ b/include/linux/dma-mapping.h
69085@@ -54,7 +54,7 @@ struct dma_map_ops {
69086 u64 (*get_required_mask)(struct device *dev);
69087 #endif
69088 int is_phys;
69089-};
69090+} __do_const;
69091
69092 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
69093
69094diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
69095index 96d3e4a..dc36433 100644
69096--- a/include/linux/dmaengine.h
69097+++ b/include/linux/dmaengine.h
69098@@ -1035,9 +1035,9 @@ struct dma_pinned_list {
69099 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
69100 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
69101
69102-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
69103+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
69104 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
69105-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
69106+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
69107 struct dma_pinned_list *pinned_list, struct page *page,
69108 unsigned int offset, size_t len);
69109
69110diff --git a/include/linux/efi.h b/include/linux/efi.h
69111index 2bc0ad7..3f7b006 100644
69112--- a/include/linux/efi.h
69113+++ b/include/linux/efi.h
69114@@ -745,6 +745,7 @@ struct efivar_operations {
69115 efi_set_variable_t *set_variable;
69116 efi_query_variable_store_t *query_variable_store;
69117 };
69118+typedef struct efivar_operations __no_const efivar_operations_no_const;
69119
69120 struct efivars {
69121 /*
69122diff --git a/include/linux/elf.h b/include/linux/elf.h
69123index 40a3c0e..4c45a38 100644
69124--- a/include/linux/elf.h
69125+++ b/include/linux/elf.h
69126@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
69127 #define elf_note elf32_note
69128 #define elf_addr_t Elf32_Off
69129 #define Elf_Half Elf32_Half
69130+#define elf_dyn Elf32_Dyn
69131
69132 #else
69133
69134@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
69135 #define elf_note elf64_note
69136 #define elf_addr_t Elf64_Off
69137 #define Elf_Half Elf64_Half
69138+#define elf_dyn Elf64_Dyn
69139
69140 #endif
69141
69142diff --git a/include/linux/err.h b/include/linux/err.h
69143index f2edce2..cc2082c 100644
69144--- a/include/linux/err.h
69145+++ b/include/linux/err.h
69146@@ -19,12 +19,12 @@
69147
69148 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
69149
69150-static inline void * __must_check ERR_PTR(long error)
69151+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
69152 {
69153 return (void *) error;
69154 }
69155
69156-static inline long __must_check PTR_ERR(const void *ptr)
69157+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
69158 {
69159 return (long) ptr;
69160 }
69161diff --git a/include/linux/extcon.h b/include/linux/extcon.h
69162index fcb51c8..bdafcf6 100644
69163--- a/include/linux/extcon.h
69164+++ b/include/linux/extcon.h
69165@@ -134,7 +134,7 @@ struct extcon_dev {
69166 /* /sys/class/extcon/.../mutually_exclusive/... */
69167 struct attribute_group attr_g_muex;
69168 struct attribute **attrs_muex;
69169- struct device_attribute *d_attrs_muex;
69170+ device_attribute_no_const *d_attrs_muex;
69171 };
69172
69173 /**
69174diff --git a/include/linux/fb.h b/include/linux/fb.h
69175index d49c60f..2834fbe 100644
69176--- a/include/linux/fb.h
69177+++ b/include/linux/fb.h
69178@@ -304,7 +304,7 @@ struct fb_ops {
69179 /* called at KDB enter and leave time to prepare the console */
69180 int (*fb_debug_enter)(struct fb_info *info);
69181 int (*fb_debug_leave)(struct fb_info *info);
69182-};
69183+} __do_const;
69184
69185 #ifdef CONFIG_FB_TILEBLITTING
69186 #define FB_TILE_CURSOR_NONE 0
69187diff --git a/include/linux/filter.h b/include/linux/filter.h
69188index f65f5a6..2f4f93a 100644
69189--- a/include/linux/filter.h
69190+++ b/include/linux/filter.h
69191@@ -20,6 +20,7 @@ struct compat_sock_fprog {
69192
69193 struct sk_buff;
69194 struct sock;
69195+struct bpf_jit_work;
69196
69197 struct sk_filter
69198 {
69199@@ -27,6 +28,9 @@ struct sk_filter
69200 unsigned int len; /* Number of filter blocks */
69201 unsigned int (*bpf_func)(const struct sk_buff *skb,
69202 const struct sock_filter *filter);
69203+#ifdef CONFIG_BPF_JIT
69204+ struct bpf_jit_work *work;
69205+#endif
69206 struct rcu_head rcu;
69207 struct sock_filter insns[0];
69208 };
69209diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
69210index 8293262..2b3b8bd 100644
69211--- a/include/linux/frontswap.h
69212+++ b/include/linux/frontswap.h
69213@@ -11,7 +11,7 @@ struct frontswap_ops {
69214 int (*load)(unsigned, pgoff_t, struct page *);
69215 void (*invalidate_page)(unsigned, pgoff_t);
69216 void (*invalidate_area)(unsigned);
69217-};
69218+} __no_const;
69219
69220 extern bool frontswap_enabled;
69221 extern struct frontswap_ops *
69222diff --git a/include/linux/fs.h b/include/linux/fs.h
69223index 65c2be2..4c53f6e 100644
69224--- a/include/linux/fs.h
69225+++ b/include/linux/fs.h
69226@@ -1543,7 +1543,8 @@ struct file_operations {
69227 long (*fallocate)(struct file *file, int mode, loff_t offset,
69228 loff_t len);
69229 int (*show_fdinfo)(struct seq_file *m, struct file *f);
69230-};
69231+} __do_const;
69232+typedef struct file_operations __no_const file_operations_no_const;
69233
69234 struct inode_operations {
69235 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
69236@@ -2688,4 +2689,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
69237 inode->i_flags |= S_NOSEC;
69238 }
69239
69240+static inline bool is_sidechannel_device(const struct inode *inode)
69241+{
69242+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
69243+ umode_t mode = inode->i_mode;
69244+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
69245+#else
69246+ return false;
69247+#endif
69248+}
69249+
69250 #endif /* _LINUX_FS_H */
69251diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
69252index 2b93a9a..855d94a 100644
69253--- a/include/linux/fs_struct.h
69254+++ b/include/linux/fs_struct.h
69255@@ -6,7 +6,7 @@
69256 #include <linux/seqlock.h>
69257
69258 struct fs_struct {
69259- int users;
69260+ atomic_t users;
69261 spinlock_t lock;
69262 seqcount_t seq;
69263 int umask;
69264diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
69265index 5dfa0aa..6acf322 100644
69266--- a/include/linux/fscache-cache.h
69267+++ b/include/linux/fscache-cache.h
69268@@ -112,7 +112,7 @@ struct fscache_operation {
69269 fscache_operation_release_t release;
69270 };
69271
69272-extern atomic_t fscache_op_debug_id;
69273+extern atomic_unchecked_t fscache_op_debug_id;
69274 extern void fscache_op_work_func(struct work_struct *work);
69275
69276 extern void fscache_enqueue_operation(struct fscache_operation *);
69277@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
69278 INIT_WORK(&op->work, fscache_op_work_func);
69279 atomic_set(&op->usage, 1);
69280 op->state = FSCACHE_OP_ST_INITIALISED;
69281- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
69282+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
69283 op->processor = processor;
69284 op->release = release;
69285 INIT_LIST_HEAD(&op->pend_link);
69286diff --git a/include/linux/fscache.h b/include/linux/fscache.h
69287index 7a08623..4c07b0f 100644
69288--- a/include/linux/fscache.h
69289+++ b/include/linux/fscache.h
69290@@ -152,7 +152,7 @@ struct fscache_cookie_def {
69291 * - this is mandatory for any object that may have data
69292 */
69293 void (*now_uncached)(void *cookie_netfs_data);
69294-};
69295+} __do_const;
69296
69297 /*
69298 * fscache cached network filesystem type
69299diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
69300index a78680a..87bd73e 100644
69301--- a/include/linux/fsnotify.h
69302+++ b/include/linux/fsnotify.h
69303@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
69304 struct inode *inode = path->dentry->d_inode;
69305 __u32 mask = FS_ACCESS;
69306
69307+ if (is_sidechannel_device(inode))
69308+ return;
69309+
69310 if (S_ISDIR(inode->i_mode))
69311 mask |= FS_ISDIR;
69312
69313@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
69314 struct inode *inode = path->dentry->d_inode;
69315 __u32 mask = FS_MODIFY;
69316
69317+ if (is_sidechannel_device(inode))
69318+ return;
69319+
69320 if (S_ISDIR(inode->i_mode))
69321 mask |= FS_ISDIR;
69322
69323@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
69324 */
69325 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
69326 {
69327- return kstrdup(name, GFP_KERNEL);
69328+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
69329 }
69330
69331 /*
69332diff --git a/include/linux/genhd.h b/include/linux/genhd.h
69333index 9f3c275..911b591 100644
69334--- a/include/linux/genhd.h
69335+++ b/include/linux/genhd.h
69336@@ -194,7 +194,7 @@ struct gendisk {
69337 struct kobject *slave_dir;
69338
69339 struct timer_rand_state *random;
69340- atomic_t sync_io; /* RAID */
69341+ atomic_unchecked_t sync_io; /* RAID */
69342 struct disk_events *ev;
69343 #ifdef CONFIG_BLK_DEV_INTEGRITY
69344 struct blk_integrity *integrity;
69345diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
69346index 023bc34..b02b46a 100644
69347--- a/include/linux/genl_magic_func.h
69348+++ b/include/linux/genl_magic_func.h
69349@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
69350 },
69351
69352 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
69353-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
69354+static struct genl_ops ZZZ_genl_ops[] = {
69355 #include GENL_MAGIC_INCLUDE_FILE
69356 };
69357
69358diff --git a/include/linux/gfp.h b/include/linux/gfp.h
69359index 0f615eb..5c3832f 100644
69360--- a/include/linux/gfp.h
69361+++ b/include/linux/gfp.h
69362@@ -35,6 +35,13 @@ struct vm_area_struct;
69363 #define ___GFP_NO_KSWAPD 0x400000u
69364 #define ___GFP_OTHER_NODE 0x800000u
69365 #define ___GFP_WRITE 0x1000000u
69366+
69367+#ifdef CONFIG_PAX_USERCOPY_SLABS
69368+#define ___GFP_USERCOPY 0x2000000u
69369+#else
69370+#define ___GFP_USERCOPY 0
69371+#endif
69372+
69373 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
69374
69375 /*
69376@@ -92,6 +99,7 @@ struct vm_area_struct;
69377 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
69378 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
69379 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
69380+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
69381
69382 /*
69383 * This may seem redundant, but it's a way of annotating false positives vs.
69384@@ -99,7 +107,7 @@ struct vm_area_struct;
69385 */
69386 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
69387
69388-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
69389+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
69390 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
69391
69392 /* This equals 0, but use constants in case they ever change */
69393@@ -153,6 +161,8 @@ struct vm_area_struct;
69394 /* 4GB DMA on some platforms */
69395 #define GFP_DMA32 __GFP_DMA32
69396
69397+#define GFP_USERCOPY __GFP_USERCOPY
69398+
69399 /* Convert GFP flags to their corresponding migrate type */
69400 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
69401 {
69402diff --git a/include/linux/gracl.h b/include/linux/gracl.h
69403new file mode 100644
69404index 0000000..ebe6d72
69405--- /dev/null
69406+++ b/include/linux/gracl.h
69407@@ -0,0 +1,319 @@
69408+#ifndef GR_ACL_H
69409+#define GR_ACL_H
69410+
69411+#include <linux/grdefs.h>
69412+#include <linux/resource.h>
69413+#include <linux/capability.h>
69414+#include <linux/dcache.h>
69415+#include <asm/resource.h>
69416+
69417+/* Major status information */
69418+
69419+#define GR_VERSION "grsecurity 2.9.1"
69420+#define GRSECURITY_VERSION 0x2901
69421+
69422+enum {
69423+ GR_SHUTDOWN = 0,
69424+ GR_ENABLE = 1,
69425+ GR_SPROLE = 2,
69426+ GR_RELOAD = 3,
69427+ GR_SEGVMOD = 4,
69428+ GR_STATUS = 5,
69429+ GR_UNSPROLE = 6,
69430+ GR_PASSSET = 7,
69431+ GR_SPROLEPAM = 8,
69432+};
69433+
69434+/* Password setup definitions
69435+ * kernel/grhash.c */
69436+enum {
69437+ GR_PW_LEN = 128,
69438+ GR_SALT_LEN = 16,
69439+ GR_SHA_LEN = 32,
69440+};
69441+
69442+enum {
69443+ GR_SPROLE_LEN = 64,
69444+};
69445+
69446+enum {
69447+ GR_NO_GLOB = 0,
69448+ GR_REG_GLOB,
69449+ GR_CREATE_GLOB
69450+};
69451+
69452+#define GR_NLIMITS 32
69453+
69454+/* Begin Data Structures */
69455+
69456+struct sprole_pw {
69457+ unsigned char *rolename;
69458+ unsigned char salt[GR_SALT_LEN];
69459+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
69460+};
69461+
69462+struct name_entry {
69463+ __u32 key;
69464+ ino_t inode;
69465+ dev_t device;
69466+ char *name;
69467+ __u16 len;
69468+ __u8 deleted;
69469+ struct name_entry *prev;
69470+ struct name_entry *next;
69471+};
69472+
69473+struct inodev_entry {
69474+ struct name_entry *nentry;
69475+ struct inodev_entry *prev;
69476+ struct inodev_entry *next;
69477+};
69478+
69479+struct acl_role_db {
69480+ struct acl_role_label **r_hash;
69481+ __u32 r_size;
69482+};
69483+
69484+struct inodev_db {
69485+ struct inodev_entry **i_hash;
69486+ __u32 i_size;
69487+};
69488+
69489+struct name_db {
69490+ struct name_entry **n_hash;
69491+ __u32 n_size;
69492+};
69493+
69494+struct crash_uid {
69495+ uid_t uid;
69496+ unsigned long expires;
69497+};
69498+
69499+struct gr_hash_struct {
69500+ void **table;
69501+ void **nametable;
69502+ void *first;
69503+ __u32 table_size;
69504+ __u32 used_size;
69505+ int type;
69506+};
69507+
69508+/* Userspace Grsecurity ACL data structures */
69509+
69510+struct acl_subject_label {
69511+ char *filename;
69512+ ino_t inode;
69513+ dev_t device;
69514+ __u32 mode;
69515+ kernel_cap_t cap_mask;
69516+ kernel_cap_t cap_lower;
69517+ kernel_cap_t cap_invert_audit;
69518+
69519+ struct rlimit res[GR_NLIMITS];
69520+ __u32 resmask;
69521+
69522+ __u8 user_trans_type;
69523+ __u8 group_trans_type;
69524+ uid_t *user_transitions;
69525+ gid_t *group_transitions;
69526+ __u16 user_trans_num;
69527+ __u16 group_trans_num;
69528+
69529+ __u32 sock_families[2];
69530+ __u32 ip_proto[8];
69531+ __u32 ip_type;
69532+ struct acl_ip_label **ips;
69533+ __u32 ip_num;
69534+ __u32 inaddr_any_override;
69535+
69536+ __u32 crashes;
69537+ unsigned long expires;
69538+
69539+ struct acl_subject_label *parent_subject;
69540+ struct gr_hash_struct *hash;
69541+ struct acl_subject_label *prev;
69542+ struct acl_subject_label *next;
69543+
69544+ struct acl_object_label **obj_hash;
69545+ __u32 obj_hash_size;
69546+ __u16 pax_flags;
69547+};
69548+
69549+struct role_allowed_ip {
69550+ __u32 addr;
69551+ __u32 netmask;
69552+
69553+ struct role_allowed_ip *prev;
69554+ struct role_allowed_ip *next;
69555+};
69556+
69557+struct role_transition {
69558+ char *rolename;
69559+
69560+ struct role_transition *prev;
69561+ struct role_transition *next;
69562+};
69563+
69564+struct acl_role_label {
69565+ char *rolename;
69566+ uid_t uidgid;
69567+ __u16 roletype;
69568+
69569+ __u16 auth_attempts;
69570+ unsigned long expires;
69571+
69572+ struct acl_subject_label *root_label;
69573+ struct gr_hash_struct *hash;
69574+
69575+ struct acl_role_label *prev;
69576+ struct acl_role_label *next;
69577+
69578+ struct role_transition *transitions;
69579+ struct role_allowed_ip *allowed_ips;
69580+ uid_t *domain_children;
69581+ __u16 domain_child_num;
69582+
69583+ umode_t umask;
69584+
69585+ struct acl_subject_label **subj_hash;
69586+ __u32 subj_hash_size;
69587+};
69588+
69589+struct user_acl_role_db {
69590+ struct acl_role_label **r_table;
69591+ __u32 num_pointers; /* Number of allocations to track */
69592+ __u32 num_roles; /* Number of roles */
69593+ __u32 num_domain_children; /* Number of domain children */
69594+ __u32 num_subjects; /* Number of subjects */
69595+ __u32 num_objects; /* Number of objects */
69596+};
69597+
69598+struct acl_object_label {
69599+ char *filename;
69600+ ino_t inode;
69601+ dev_t device;
69602+ __u32 mode;
69603+
69604+ struct acl_subject_label *nested;
69605+ struct acl_object_label *globbed;
69606+
69607+ /* next two structures not used */
69608+
69609+ struct acl_object_label *prev;
69610+ struct acl_object_label *next;
69611+};
69612+
69613+struct acl_ip_label {
69614+ char *iface;
69615+ __u32 addr;
69616+ __u32 netmask;
69617+ __u16 low, high;
69618+ __u8 mode;
69619+ __u32 type;
69620+ __u32 proto[8];
69621+
69622+ /* next two structures not used */
69623+
69624+ struct acl_ip_label *prev;
69625+ struct acl_ip_label *next;
69626+};
69627+
69628+struct gr_arg {
69629+ struct user_acl_role_db role_db;
69630+ unsigned char pw[GR_PW_LEN];
69631+ unsigned char salt[GR_SALT_LEN];
69632+ unsigned char sum[GR_SHA_LEN];
69633+ unsigned char sp_role[GR_SPROLE_LEN];
69634+ struct sprole_pw *sprole_pws;
69635+ dev_t segv_device;
69636+ ino_t segv_inode;
69637+ uid_t segv_uid;
69638+ __u16 num_sprole_pws;
69639+ __u16 mode;
69640+};
69641+
69642+struct gr_arg_wrapper {
69643+ struct gr_arg *arg;
69644+ __u32 version;
69645+ __u32 size;
69646+};
69647+
69648+struct subject_map {
69649+ struct acl_subject_label *user;
69650+ struct acl_subject_label *kernel;
69651+ struct subject_map *prev;
69652+ struct subject_map *next;
69653+};
69654+
69655+struct acl_subj_map_db {
69656+ struct subject_map **s_hash;
69657+ __u32 s_size;
69658+};
69659+
69660+/* End Data Structures Section */
69661+
69662+/* Hash functions generated by empirical testing by Brad Spengler
69663+ Makes good use of the low bits of the inode. Generally 0-1 times
69664+ in loop for successful match. 0-3 for unsuccessful match.
69665+ Shift/add algorithm with modulus of table size and an XOR*/
69666+
69667+static __inline__ unsigned int
69668+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
69669+{
69670+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
69671+}
69672+
69673+ static __inline__ unsigned int
69674+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
69675+{
69676+ return ((const unsigned long)userp % sz);
69677+}
69678+
69679+static __inline__ unsigned int
69680+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
69681+{
69682+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
69683+}
69684+
69685+static __inline__ unsigned int
69686+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
69687+{
69688+ return full_name_hash((const unsigned char *)name, len) % sz;
69689+}
69690+
69691+#define FOR_EACH_ROLE_START(role) \
69692+ role = role_list; \
69693+ while (role) {
69694+
69695+#define FOR_EACH_ROLE_END(role) \
69696+ role = role->prev; \
69697+ }
69698+
69699+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
69700+ subj = NULL; \
69701+ iter = 0; \
69702+ while (iter < role->subj_hash_size) { \
69703+ if (subj == NULL) \
69704+ subj = role->subj_hash[iter]; \
69705+ if (subj == NULL) { \
69706+ iter++; \
69707+ continue; \
69708+ }
69709+
69710+#define FOR_EACH_SUBJECT_END(subj,iter) \
69711+ subj = subj->next; \
69712+ if (subj == NULL) \
69713+ iter++; \
69714+ }
69715+
69716+
69717+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
69718+ subj = role->hash->first; \
69719+ while (subj != NULL) {
69720+
69721+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
69722+ subj = subj->next; \
69723+ }
69724+
69725+#endif
69726+
69727diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
69728new file mode 100644
69729index 0000000..33ebd1f
69730--- /dev/null
69731+++ b/include/linux/gracl_compat.h
69732@@ -0,0 +1,156 @@
69733+#ifndef GR_ACL_COMPAT_H
69734+#define GR_ACL_COMPAT_H
69735+
69736+#include <linux/resource.h>
69737+#include <asm/resource.h>
69738+
69739+struct sprole_pw_compat {
69740+ compat_uptr_t rolename;
69741+ unsigned char salt[GR_SALT_LEN];
69742+ unsigned char sum[GR_SHA_LEN];
69743+};
69744+
69745+struct gr_hash_struct_compat {
69746+ compat_uptr_t table;
69747+ compat_uptr_t nametable;
69748+ compat_uptr_t first;
69749+ __u32 table_size;
69750+ __u32 used_size;
69751+ int type;
69752+};
69753+
69754+struct acl_subject_label_compat {
69755+ compat_uptr_t filename;
69756+ compat_ino_t inode;
69757+ __u32 device;
69758+ __u32 mode;
69759+ kernel_cap_t cap_mask;
69760+ kernel_cap_t cap_lower;
69761+ kernel_cap_t cap_invert_audit;
69762+
69763+ struct compat_rlimit res[GR_NLIMITS];
69764+ __u32 resmask;
69765+
69766+ __u8 user_trans_type;
69767+ __u8 group_trans_type;
69768+ compat_uptr_t user_transitions;
69769+ compat_uptr_t group_transitions;
69770+ __u16 user_trans_num;
69771+ __u16 group_trans_num;
69772+
69773+ __u32 sock_families[2];
69774+ __u32 ip_proto[8];
69775+ __u32 ip_type;
69776+ compat_uptr_t ips;
69777+ __u32 ip_num;
69778+ __u32 inaddr_any_override;
69779+
69780+ __u32 crashes;
69781+ compat_ulong_t expires;
69782+
69783+ compat_uptr_t parent_subject;
69784+ compat_uptr_t hash;
69785+ compat_uptr_t prev;
69786+ compat_uptr_t next;
69787+
69788+ compat_uptr_t obj_hash;
69789+ __u32 obj_hash_size;
69790+ __u16 pax_flags;
69791+};
69792+
69793+struct role_allowed_ip_compat {
69794+ __u32 addr;
69795+ __u32 netmask;
69796+
69797+ compat_uptr_t prev;
69798+ compat_uptr_t next;
69799+};
69800+
69801+struct role_transition_compat {
69802+ compat_uptr_t rolename;
69803+
69804+ compat_uptr_t prev;
69805+ compat_uptr_t next;
69806+};
69807+
69808+struct acl_role_label_compat {
69809+ compat_uptr_t rolename;
69810+ uid_t uidgid;
69811+ __u16 roletype;
69812+
69813+ __u16 auth_attempts;
69814+ compat_ulong_t expires;
69815+
69816+ compat_uptr_t root_label;
69817+ compat_uptr_t hash;
69818+
69819+ compat_uptr_t prev;
69820+ compat_uptr_t next;
69821+
69822+ compat_uptr_t transitions;
69823+ compat_uptr_t allowed_ips;
69824+ compat_uptr_t domain_children;
69825+ __u16 domain_child_num;
69826+
69827+ umode_t umask;
69828+
69829+ compat_uptr_t subj_hash;
69830+ __u32 subj_hash_size;
69831+};
69832+
69833+struct user_acl_role_db_compat {
69834+ compat_uptr_t r_table;
69835+ __u32 num_pointers;
69836+ __u32 num_roles;
69837+ __u32 num_domain_children;
69838+ __u32 num_subjects;
69839+ __u32 num_objects;
69840+};
69841+
69842+struct acl_object_label_compat {
69843+ compat_uptr_t filename;
69844+ compat_ino_t inode;
69845+ __u32 device;
69846+ __u32 mode;
69847+
69848+ compat_uptr_t nested;
69849+ compat_uptr_t globbed;
69850+
69851+ compat_uptr_t prev;
69852+ compat_uptr_t next;
69853+};
69854+
69855+struct acl_ip_label_compat {
69856+ compat_uptr_t iface;
69857+ __u32 addr;
69858+ __u32 netmask;
69859+ __u16 low, high;
69860+ __u8 mode;
69861+ __u32 type;
69862+ __u32 proto[8];
69863+
69864+ compat_uptr_t prev;
69865+ compat_uptr_t next;
69866+};
69867+
69868+struct gr_arg_compat {
69869+ struct user_acl_role_db_compat role_db;
69870+ unsigned char pw[GR_PW_LEN];
69871+ unsigned char salt[GR_SALT_LEN];
69872+ unsigned char sum[GR_SHA_LEN];
69873+ unsigned char sp_role[GR_SPROLE_LEN];
69874+ compat_uptr_t sprole_pws;
69875+ __u32 segv_device;
69876+ compat_ino_t segv_inode;
69877+ uid_t segv_uid;
69878+ __u16 num_sprole_pws;
69879+ __u16 mode;
69880+};
69881+
69882+struct gr_arg_wrapper_compat {
69883+ compat_uptr_t arg;
69884+ __u32 version;
69885+ __u32 size;
69886+};
69887+
69888+#endif
69889diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69890new file mode 100644
69891index 0000000..323ecf2
69892--- /dev/null
69893+++ b/include/linux/gralloc.h
69894@@ -0,0 +1,9 @@
69895+#ifndef __GRALLOC_H
69896+#define __GRALLOC_H
69897+
69898+void acl_free_all(void);
69899+int acl_alloc_stack_init(unsigned long size);
69900+void *acl_alloc(unsigned long len);
69901+void *acl_alloc_num(unsigned long num, unsigned long len);
69902+
69903+#endif
69904diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69905new file mode 100644
69906index 0000000..be66033
69907--- /dev/null
69908+++ b/include/linux/grdefs.h
69909@@ -0,0 +1,140 @@
69910+#ifndef GRDEFS_H
69911+#define GRDEFS_H
69912+
69913+/* Begin grsecurity status declarations */
69914+
69915+enum {
69916+ GR_READY = 0x01,
69917+ GR_STATUS_INIT = 0x00 // disabled state
69918+};
69919+
69920+/* Begin ACL declarations */
69921+
69922+/* Role flags */
69923+
69924+enum {
69925+ GR_ROLE_USER = 0x0001,
69926+ GR_ROLE_GROUP = 0x0002,
69927+ GR_ROLE_DEFAULT = 0x0004,
69928+ GR_ROLE_SPECIAL = 0x0008,
69929+ GR_ROLE_AUTH = 0x0010,
69930+ GR_ROLE_NOPW = 0x0020,
69931+ GR_ROLE_GOD = 0x0040,
69932+ GR_ROLE_LEARN = 0x0080,
69933+ GR_ROLE_TPE = 0x0100,
69934+ GR_ROLE_DOMAIN = 0x0200,
69935+ GR_ROLE_PAM = 0x0400,
69936+ GR_ROLE_PERSIST = 0x0800
69937+};
69938+
69939+/* ACL Subject and Object mode flags */
69940+enum {
69941+ GR_DELETED = 0x80000000
69942+};
69943+
69944+/* ACL Object-only mode flags */
69945+enum {
69946+ GR_READ = 0x00000001,
69947+ GR_APPEND = 0x00000002,
69948+ GR_WRITE = 0x00000004,
69949+ GR_EXEC = 0x00000008,
69950+ GR_FIND = 0x00000010,
69951+ GR_INHERIT = 0x00000020,
69952+ GR_SETID = 0x00000040,
69953+ GR_CREATE = 0x00000080,
69954+ GR_DELETE = 0x00000100,
69955+ GR_LINK = 0x00000200,
69956+ GR_AUDIT_READ = 0x00000400,
69957+ GR_AUDIT_APPEND = 0x00000800,
69958+ GR_AUDIT_WRITE = 0x00001000,
69959+ GR_AUDIT_EXEC = 0x00002000,
69960+ GR_AUDIT_FIND = 0x00004000,
69961+ GR_AUDIT_INHERIT= 0x00008000,
69962+ GR_AUDIT_SETID = 0x00010000,
69963+ GR_AUDIT_CREATE = 0x00020000,
69964+ GR_AUDIT_DELETE = 0x00040000,
69965+ GR_AUDIT_LINK = 0x00080000,
69966+ GR_PTRACERD = 0x00100000,
69967+ GR_NOPTRACE = 0x00200000,
69968+ GR_SUPPRESS = 0x00400000,
69969+ GR_NOLEARN = 0x00800000,
69970+ GR_INIT_TRANSFER= 0x01000000
69971+};
69972+
69973+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69974+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69975+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69976+
69977+/* ACL subject-only mode flags */
69978+enum {
69979+ GR_KILL = 0x00000001,
69980+ GR_VIEW = 0x00000002,
69981+ GR_PROTECTED = 0x00000004,
69982+ GR_LEARN = 0x00000008,
69983+ GR_OVERRIDE = 0x00000010,
69984+ /* just a placeholder, this mode is only used in userspace */
69985+ GR_DUMMY = 0x00000020,
69986+ GR_PROTSHM = 0x00000040,
69987+ GR_KILLPROC = 0x00000080,
69988+ GR_KILLIPPROC = 0x00000100,
69989+ /* just a placeholder, this mode is only used in userspace */
69990+ GR_NOTROJAN = 0x00000200,
69991+ GR_PROTPROCFD = 0x00000400,
69992+ GR_PROCACCT = 0x00000800,
69993+ GR_RELAXPTRACE = 0x00001000,
69994+ //GR_NESTED = 0x00002000,
69995+ GR_INHERITLEARN = 0x00004000,
69996+ GR_PROCFIND = 0x00008000,
69997+ GR_POVERRIDE = 0x00010000,
69998+ GR_KERNELAUTH = 0x00020000,
69999+ GR_ATSECURE = 0x00040000,
70000+ GR_SHMEXEC = 0x00080000
70001+};
70002+
70003+enum {
70004+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
70005+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
70006+ GR_PAX_ENABLE_MPROTECT = 0x0004,
70007+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
70008+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
70009+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
70010+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
70011+ GR_PAX_DISABLE_MPROTECT = 0x0400,
70012+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
70013+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
70014+};
70015+
70016+enum {
70017+ GR_ID_USER = 0x01,
70018+ GR_ID_GROUP = 0x02,
70019+};
70020+
70021+enum {
70022+ GR_ID_ALLOW = 0x01,
70023+ GR_ID_DENY = 0x02,
70024+};
70025+
70026+#define GR_CRASH_RES 31
70027+#define GR_UIDTABLE_MAX 500
70028+
70029+/* begin resource learning section */
70030+enum {
70031+ GR_RLIM_CPU_BUMP = 60,
70032+ GR_RLIM_FSIZE_BUMP = 50000,
70033+ GR_RLIM_DATA_BUMP = 10000,
70034+ GR_RLIM_STACK_BUMP = 1000,
70035+ GR_RLIM_CORE_BUMP = 10000,
70036+ GR_RLIM_RSS_BUMP = 500000,
70037+ GR_RLIM_NPROC_BUMP = 1,
70038+ GR_RLIM_NOFILE_BUMP = 5,
70039+ GR_RLIM_MEMLOCK_BUMP = 50000,
70040+ GR_RLIM_AS_BUMP = 500000,
70041+ GR_RLIM_LOCKS_BUMP = 2,
70042+ GR_RLIM_SIGPENDING_BUMP = 5,
70043+ GR_RLIM_MSGQUEUE_BUMP = 10000,
70044+ GR_RLIM_NICE_BUMP = 1,
70045+ GR_RLIM_RTPRIO_BUMP = 1,
70046+ GR_RLIM_RTTIME_BUMP = 1000000
70047+};
70048+
70049+#endif
70050diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
70051new file mode 100644
70052index 0000000..fd8598b
70053--- /dev/null
70054+++ b/include/linux/grinternal.h
70055@@ -0,0 +1,228 @@
70056+#ifndef __GRINTERNAL_H
70057+#define __GRINTERNAL_H
70058+
70059+#ifdef CONFIG_GRKERNSEC
70060+
70061+#include <linux/fs.h>
70062+#include <linux/mnt_namespace.h>
70063+#include <linux/nsproxy.h>
70064+#include <linux/gracl.h>
70065+#include <linux/grdefs.h>
70066+#include <linux/grmsg.h>
70067+
70068+void gr_add_learn_entry(const char *fmt, ...)
70069+ __attribute__ ((format (printf, 1, 2)));
70070+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
70071+ const struct vfsmount *mnt);
70072+__u32 gr_check_create(const struct dentry *new_dentry,
70073+ const struct dentry *parent,
70074+ const struct vfsmount *mnt, const __u32 mode);
70075+int gr_check_protected_task(const struct task_struct *task);
70076+__u32 to_gr_audit(const __u32 reqmode);
70077+int gr_set_acls(const int type);
70078+int gr_apply_subject_to_task(struct task_struct *task);
70079+int gr_acl_is_enabled(void);
70080+char gr_roletype_to_char(void);
70081+
70082+void gr_handle_alertkill(struct task_struct *task);
70083+char *gr_to_filename(const struct dentry *dentry,
70084+ const struct vfsmount *mnt);
70085+char *gr_to_filename1(const struct dentry *dentry,
70086+ const struct vfsmount *mnt);
70087+char *gr_to_filename2(const struct dentry *dentry,
70088+ const struct vfsmount *mnt);
70089+char *gr_to_filename3(const struct dentry *dentry,
70090+ const struct vfsmount *mnt);
70091+
70092+extern int grsec_enable_ptrace_readexec;
70093+extern int grsec_enable_harden_ptrace;
70094+extern int grsec_enable_link;
70095+extern int grsec_enable_fifo;
70096+extern int grsec_enable_execve;
70097+extern int grsec_enable_shm;
70098+extern int grsec_enable_execlog;
70099+extern int grsec_enable_signal;
70100+extern int grsec_enable_audit_ptrace;
70101+extern int grsec_enable_forkfail;
70102+extern int grsec_enable_time;
70103+extern int grsec_enable_rofs;
70104+extern int grsec_enable_chroot_shmat;
70105+extern int grsec_enable_chroot_mount;
70106+extern int grsec_enable_chroot_double;
70107+extern int grsec_enable_chroot_pivot;
70108+extern int grsec_enable_chroot_chdir;
70109+extern int grsec_enable_chroot_chmod;
70110+extern int grsec_enable_chroot_mknod;
70111+extern int grsec_enable_chroot_fchdir;
70112+extern int grsec_enable_chroot_nice;
70113+extern int grsec_enable_chroot_execlog;
70114+extern int grsec_enable_chroot_caps;
70115+extern int grsec_enable_chroot_sysctl;
70116+extern int grsec_enable_chroot_unix;
70117+extern int grsec_enable_symlinkown;
70118+extern kgid_t grsec_symlinkown_gid;
70119+extern int grsec_enable_tpe;
70120+extern kgid_t grsec_tpe_gid;
70121+extern int grsec_enable_tpe_all;
70122+extern int grsec_enable_tpe_invert;
70123+extern int grsec_enable_socket_all;
70124+extern kgid_t grsec_socket_all_gid;
70125+extern int grsec_enable_socket_client;
70126+extern kgid_t grsec_socket_client_gid;
70127+extern int grsec_enable_socket_server;
70128+extern kgid_t grsec_socket_server_gid;
70129+extern kgid_t grsec_audit_gid;
70130+extern int grsec_enable_group;
70131+extern int grsec_enable_log_rwxmaps;
70132+extern int grsec_enable_mount;
70133+extern int grsec_enable_chdir;
70134+extern int grsec_resource_logging;
70135+extern int grsec_enable_blackhole;
70136+extern int grsec_lastack_retries;
70137+extern int grsec_enable_brute;
70138+extern int grsec_lock;
70139+
70140+extern spinlock_t grsec_alert_lock;
70141+extern unsigned long grsec_alert_wtime;
70142+extern unsigned long grsec_alert_fyet;
70143+
70144+extern spinlock_t grsec_audit_lock;
70145+
70146+extern rwlock_t grsec_exec_file_lock;
70147+
70148+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
70149+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
70150+ (tsk)->exec_file->f_path.mnt) : "/")
70151+
70152+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
70153+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
70154+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
70155+
70156+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
70157+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
70158+ (tsk)->exec_file->f_path.mnt) : "/")
70159+
70160+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
70161+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
70162+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
70163+
70164+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
70165+
70166+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
70167+
70168+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
70169+{
70170+ if (file1 && file2) {
70171+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
70172+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
70173+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
70174+ return true;
70175+ }
70176+
70177+ return false;
70178+}
70179+
70180+#define GR_CHROOT_CAPS {{ \
70181+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
70182+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
70183+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
70184+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
70185+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
70186+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
70187+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
70188+
70189+#define security_learn(normal_msg,args...) \
70190+({ \
70191+ read_lock(&grsec_exec_file_lock); \
70192+ gr_add_learn_entry(normal_msg "\n", ## args); \
70193+ read_unlock(&grsec_exec_file_lock); \
70194+})
70195+
70196+enum {
70197+ GR_DO_AUDIT,
70198+ GR_DONT_AUDIT,
70199+ /* used for non-audit messages that we shouldn't kill the task on */
70200+ GR_DONT_AUDIT_GOOD
70201+};
70202+
70203+enum {
70204+ GR_TTYSNIFF,
70205+ GR_RBAC,
70206+ GR_RBAC_STR,
70207+ GR_STR_RBAC,
70208+ GR_RBAC_MODE2,
70209+ GR_RBAC_MODE3,
70210+ GR_FILENAME,
70211+ GR_SYSCTL_HIDDEN,
70212+ GR_NOARGS,
70213+ GR_ONE_INT,
70214+ GR_ONE_INT_TWO_STR,
70215+ GR_ONE_STR,
70216+ GR_STR_INT,
70217+ GR_TWO_STR_INT,
70218+ GR_TWO_INT,
70219+ GR_TWO_U64,
70220+ GR_THREE_INT,
70221+ GR_FIVE_INT_TWO_STR,
70222+ GR_TWO_STR,
70223+ GR_THREE_STR,
70224+ GR_FOUR_STR,
70225+ GR_STR_FILENAME,
70226+ GR_FILENAME_STR,
70227+ GR_FILENAME_TWO_INT,
70228+ GR_FILENAME_TWO_INT_STR,
70229+ GR_TEXTREL,
70230+ GR_PTRACE,
70231+ GR_RESOURCE,
70232+ GR_CAP,
70233+ GR_SIG,
70234+ GR_SIG2,
70235+ GR_CRASH1,
70236+ GR_CRASH2,
70237+ GR_PSACCT,
70238+ GR_RWXMAP,
70239+ GR_RWXMAPVMA
70240+};
70241+
70242+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
70243+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
70244+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
70245+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
70246+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
70247+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
70248+#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)
70249+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
70250+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
70251+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
70252+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
70253+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
70254+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
70255+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
70256+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
70257+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
70258+#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)
70259+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
70260+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
70261+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
70262+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
70263+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
70264+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
70265+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
70266+#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)
70267+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
70268+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
70269+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
70270+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
70271+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
70272+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
70273+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
70274+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
70275+#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)
70276+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
70277+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
70278+
70279+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
70280+
70281+#endif
70282+
70283+#endif
70284diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
70285new file mode 100644
70286index 0000000..a4396b5
70287--- /dev/null
70288+++ b/include/linux/grmsg.h
70289@@ -0,0 +1,113 @@
70290+#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"
70291+#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"
70292+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
70293+#define GR_STOPMOD_MSG "denied modification of module state by "
70294+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
70295+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
70296+#define GR_IOPERM_MSG "denied use of ioperm() by "
70297+#define GR_IOPL_MSG "denied use of iopl() by "
70298+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
70299+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
70300+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
70301+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
70302+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
70303+#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"
70304+#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"
70305+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
70306+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
70307+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
70308+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
70309+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
70310+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
70311+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
70312+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
70313+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
70314+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
70315+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
70316+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
70317+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
70318+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
70319+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
70320+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
70321+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
70322+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
70323+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
70324+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
70325+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
70326+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
70327+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
70328+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
70329+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
70330+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
70331+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
70332+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
70333+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
70334+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
70335+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
70336+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
70337+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
70338+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
70339+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
70340+#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"
70341+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
70342+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
70343+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
70344+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
70345+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
70346+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
70347+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
70348+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
70349+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
70350+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
70351+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
70352+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
70353+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
70354+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
70355+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
70356+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
70357+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
70358+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
70359+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
70360+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
70361+#define GR_FAILFORK_MSG "failed fork with errno %s by "
70362+#define GR_NICE_CHROOT_MSG "denied priority change by "
70363+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
70364+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
70365+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
70366+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
70367+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
70368+#define GR_TIME_MSG "time set by "
70369+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
70370+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
70371+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
70372+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
70373+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
70374+#define GR_BIND_MSG "denied bind() by "
70375+#define GR_CONNECT_MSG "denied connect() by "
70376+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
70377+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
70378+#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"
70379+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
70380+#define GR_CAP_ACL_MSG "use of %s denied for "
70381+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
70382+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
70383+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
70384+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
70385+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
70386+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
70387+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
70388+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
70389+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
70390+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
70391+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
70392+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
70393+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
70394+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
70395+#define GR_VM86_MSG "denied use of vm86 by "
70396+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
70397+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
70398+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
70399+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
70400+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
70401+#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 "
70402+#define GR_BRUTE_SUID_MSG "bruteforce prevention initiated due to crash of %.950s against uid %u, banning suid/sgid execs for %u minutes. Please investigate the crash report for "
70403diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
70404new file mode 100644
70405index 0000000..3676b0b
70406--- /dev/null
70407+++ b/include/linux/grsecurity.h
70408@@ -0,0 +1,242 @@
70409+#ifndef GR_SECURITY_H
70410+#define GR_SECURITY_H
70411+#include <linux/fs.h>
70412+#include <linux/fs_struct.h>
70413+#include <linux/binfmts.h>
70414+#include <linux/gracl.h>
70415+
70416+/* notify of brain-dead configs */
70417+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70418+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
70419+#endif
70420+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
70421+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
70422+#endif
70423+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
70424+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
70425+#endif
70426+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
70427+#error "CONFIG_PAX enabled, but no PaX options are enabled."
70428+#endif
70429+
70430+void gr_handle_brute_attach(unsigned long mm_flags);
70431+void gr_handle_brute_check(void);
70432+void gr_handle_kernel_exploit(void);
70433+
70434+char gr_roletype_to_char(void);
70435+
70436+int gr_acl_enable_at_secure(void);
70437+
70438+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
70439+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
70440+
70441+void gr_del_task_from_ip_table(struct task_struct *p);
70442+
70443+int gr_pid_is_chrooted(struct task_struct *p);
70444+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
70445+int gr_handle_chroot_nice(void);
70446+int gr_handle_chroot_sysctl(const int op);
70447+int gr_handle_chroot_setpriority(struct task_struct *p,
70448+ const int niceval);
70449+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
70450+int gr_handle_chroot_chroot(const struct dentry *dentry,
70451+ const struct vfsmount *mnt);
70452+void gr_handle_chroot_chdir(const struct path *path);
70453+int gr_handle_chroot_chmod(const struct dentry *dentry,
70454+ const struct vfsmount *mnt, const int mode);
70455+int gr_handle_chroot_mknod(const struct dentry *dentry,
70456+ const struct vfsmount *mnt, const int mode);
70457+int gr_handle_chroot_mount(const struct dentry *dentry,
70458+ const struct vfsmount *mnt,
70459+ const char *dev_name);
70460+int gr_handle_chroot_pivot(void);
70461+int gr_handle_chroot_unix(const pid_t pid);
70462+
70463+int gr_handle_rawio(const struct inode *inode);
70464+
70465+void gr_handle_ioperm(void);
70466+void gr_handle_iopl(void);
70467+
70468+umode_t gr_acl_umask(void);
70469+
70470+int gr_tpe_allow(const struct file *file);
70471+
70472+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
70473+void gr_clear_chroot_entries(struct task_struct *task);
70474+
70475+void gr_log_forkfail(const int retval);
70476+void gr_log_timechange(void);
70477+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
70478+void gr_log_chdir(const struct dentry *dentry,
70479+ const struct vfsmount *mnt);
70480+void gr_log_chroot_exec(const struct dentry *dentry,
70481+ const struct vfsmount *mnt);
70482+void gr_log_remount(const char *devname, const int retval);
70483+void gr_log_unmount(const char *devname, const int retval);
70484+void gr_log_mount(const char *from, const char *to, const int retval);
70485+void gr_log_textrel(struct vm_area_struct *vma);
70486+void gr_log_ptgnustack(struct file *file);
70487+void gr_log_rwxmmap(struct file *file);
70488+void gr_log_rwxmprotect(struct vm_area_struct *vma);
70489+
70490+int gr_handle_follow_link(const struct inode *parent,
70491+ const struct inode *inode,
70492+ const struct dentry *dentry,
70493+ const struct vfsmount *mnt);
70494+int gr_handle_fifo(const struct dentry *dentry,
70495+ const struct vfsmount *mnt,
70496+ const struct dentry *dir, const int flag,
70497+ const int acc_mode);
70498+int gr_handle_hardlink(const struct dentry *dentry,
70499+ const struct vfsmount *mnt,
70500+ struct inode *inode,
70501+ const int mode, const struct filename *to);
70502+
70503+int gr_is_capable(const int cap);
70504+int gr_is_capable_nolog(const int cap);
70505+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
70506+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
70507+
70508+void gr_copy_label(struct task_struct *tsk);
70509+void gr_handle_crash(struct task_struct *task, const int sig);
70510+int gr_handle_signal(const struct task_struct *p, const int sig);
70511+int gr_check_crash_uid(const kuid_t uid);
70512+int gr_check_protected_task(const struct task_struct *task);
70513+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
70514+int gr_acl_handle_mmap(const struct file *file,
70515+ const unsigned long prot);
70516+int gr_acl_handle_mprotect(const struct file *file,
70517+ const unsigned long prot);
70518+int gr_check_hidden_task(const struct task_struct *tsk);
70519+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
70520+ const struct vfsmount *mnt);
70521+__u32 gr_acl_handle_utime(const struct dentry *dentry,
70522+ const struct vfsmount *mnt);
70523+__u32 gr_acl_handle_access(const struct dentry *dentry,
70524+ const struct vfsmount *mnt, const int fmode);
70525+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
70526+ const struct vfsmount *mnt, umode_t *mode);
70527+__u32 gr_acl_handle_chown(const struct dentry *dentry,
70528+ const struct vfsmount *mnt);
70529+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
70530+ const struct vfsmount *mnt);
70531+int gr_handle_ptrace(struct task_struct *task, const long request);
70532+int gr_handle_proc_ptrace(struct task_struct *task);
70533+__u32 gr_acl_handle_execve(const struct dentry *dentry,
70534+ const struct vfsmount *mnt);
70535+int gr_check_crash_exec(const struct file *filp);
70536+int gr_acl_is_enabled(void);
70537+void gr_set_kernel_label(struct task_struct *task);
70538+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
70539+ const kgid_t gid);
70540+int gr_set_proc_label(const struct dentry *dentry,
70541+ const struct vfsmount *mnt,
70542+ const int unsafe_flags);
70543+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
70544+ const struct vfsmount *mnt);
70545+__u32 gr_acl_handle_open(const struct dentry *dentry,
70546+ const struct vfsmount *mnt, int acc_mode);
70547+__u32 gr_acl_handle_creat(const struct dentry *dentry,
70548+ const struct dentry *p_dentry,
70549+ const struct vfsmount *p_mnt,
70550+ int open_flags, int acc_mode, const int imode);
70551+void gr_handle_create(const struct dentry *dentry,
70552+ const struct vfsmount *mnt);
70553+void gr_handle_proc_create(const struct dentry *dentry,
70554+ const struct inode *inode);
70555+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
70556+ const struct dentry *parent_dentry,
70557+ const struct vfsmount *parent_mnt,
70558+ const int mode);
70559+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
70560+ const struct dentry *parent_dentry,
70561+ const struct vfsmount *parent_mnt);
70562+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
70563+ const struct vfsmount *mnt);
70564+void gr_handle_delete(const ino_t ino, const dev_t dev);
70565+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
70566+ const struct vfsmount *mnt);
70567+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
70568+ const struct dentry *parent_dentry,
70569+ const struct vfsmount *parent_mnt,
70570+ const struct filename *from);
70571+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
70572+ const struct dentry *parent_dentry,
70573+ const struct vfsmount *parent_mnt,
70574+ const struct dentry *old_dentry,
70575+ const struct vfsmount *old_mnt, const struct filename *to);
70576+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
70577+int gr_acl_handle_rename(struct dentry *new_dentry,
70578+ struct dentry *parent_dentry,
70579+ const struct vfsmount *parent_mnt,
70580+ struct dentry *old_dentry,
70581+ struct inode *old_parent_inode,
70582+ struct vfsmount *old_mnt, const struct filename *newname);
70583+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
70584+ struct dentry *old_dentry,
70585+ struct dentry *new_dentry,
70586+ struct vfsmount *mnt, const __u8 replace);
70587+__u32 gr_check_link(const struct dentry *new_dentry,
70588+ const struct dentry *parent_dentry,
70589+ const struct vfsmount *parent_mnt,
70590+ const struct dentry *old_dentry,
70591+ const struct vfsmount *old_mnt);
70592+int gr_acl_handle_filldir(const struct file *file, const char *name,
70593+ const unsigned int namelen, const ino_t ino);
70594+
70595+__u32 gr_acl_handle_unix(const struct dentry *dentry,
70596+ const struct vfsmount *mnt);
70597+void gr_acl_handle_exit(void);
70598+void gr_acl_handle_psacct(struct task_struct *task, const long code);
70599+int gr_acl_handle_procpidmem(const struct task_struct *task);
70600+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
70601+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
70602+void gr_audit_ptrace(struct task_struct *task);
70603+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
70604+void gr_put_exec_file(struct task_struct *task);
70605+
70606+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
70607+
70608+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
70609+extern void gr_learn_resource(const struct task_struct *task, const int res,
70610+ const unsigned long wanted, const int gt);
70611+#else
70612+static inline void gr_learn_resource(const struct task_struct *task, const int res,
70613+ const unsigned long wanted, const int gt)
70614+{
70615+}
70616+#endif
70617+
70618+#ifdef CONFIG_GRKERNSEC_RESLOG
70619+extern void gr_log_resource(const struct task_struct *task, const int res,
70620+ const unsigned long wanted, const int gt);
70621+#else
70622+static inline void gr_log_resource(const struct task_struct *task, const int res,
70623+ const unsigned long wanted, const int gt)
70624+{
70625+}
70626+#endif
70627+
70628+#ifdef CONFIG_GRKERNSEC
70629+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
70630+void gr_handle_vm86(void);
70631+void gr_handle_mem_readwrite(u64 from, u64 to);
70632+
70633+void gr_log_badprocpid(const char *entry);
70634+
70635+extern int grsec_enable_dmesg;
70636+extern int grsec_disable_privio;
70637+
70638+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
70639+extern kgid_t grsec_proc_gid;
70640+#endif
70641+
70642+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70643+extern int grsec_enable_chroot_findtask;
70644+#endif
70645+#ifdef CONFIG_GRKERNSEC_SETXID
70646+extern int grsec_enable_setxid;
70647+#endif
70648+#endif
70649+
70650+#endif
70651diff --git a/include/linux/grsock.h b/include/linux/grsock.h
70652new file mode 100644
70653index 0000000..e7ffaaf
70654--- /dev/null
70655+++ b/include/linux/grsock.h
70656@@ -0,0 +1,19 @@
70657+#ifndef __GRSOCK_H
70658+#define __GRSOCK_H
70659+
70660+extern void gr_attach_curr_ip(const struct sock *sk);
70661+extern int gr_handle_sock_all(const int family, const int type,
70662+ const int protocol);
70663+extern int gr_handle_sock_server(const struct sockaddr *sck);
70664+extern int gr_handle_sock_server_other(const struct sock *sck);
70665+extern int gr_handle_sock_client(const struct sockaddr *sck);
70666+extern int gr_search_connect(struct socket * sock,
70667+ struct sockaddr_in * addr);
70668+extern int gr_search_bind(struct socket * sock,
70669+ struct sockaddr_in * addr);
70670+extern int gr_search_listen(struct socket * sock);
70671+extern int gr_search_accept(struct socket * sock);
70672+extern int gr_search_socket(const int domain, const int type,
70673+ const int protocol);
70674+
70675+#endif
70676diff --git a/include/linux/highmem.h b/include/linux/highmem.h
70677index 7fb31da..08b5114 100644
70678--- a/include/linux/highmem.h
70679+++ b/include/linux/highmem.h
70680@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
70681 kunmap_atomic(kaddr);
70682 }
70683
70684+static inline void sanitize_highpage(struct page *page)
70685+{
70686+ void *kaddr;
70687+ unsigned long flags;
70688+
70689+ local_irq_save(flags);
70690+ kaddr = kmap_atomic(page);
70691+ clear_page(kaddr);
70692+ kunmap_atomic(kaddr);
70693+ local_irq_restore(flags);
70694+}
70695+
70696 static inline void zero_user_segments(struct page *page,
70697 unsigned start1, unsigned end1,
70698 unsigned start2, unsigned end2)
70699diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
70700index 1c7b89a..7f52502 100644
70701--- a/include/linux/hwmon-sysfs.h
70702+++ b/include/linux/hwmon-sysfs.h
70703@@ -25,7 +25,8 @@
70704 struct sensor_device_attribute{
70705 struct device_attribute dev_attr;
70706 int index;
70707-};
70708+} __do_const;
70709+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
70710 #define to_sensor_dev_attr(_dev_attr) \
70711 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
70712
70713@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
70714 struct device_attribute dev_attr;
70715 u8 index;
70716 u8 nr;
70717-};
70718+} __do_const;
70719 #define to_sensor_dev_attr_2(_dev_attr) \
70720 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
70721
70722diff --git a/include/linux/i2c.h b/include/linux/i2c.h
70723index e988fa9..ff9f17e 100644
70724--- a/include/linux/i2c.h
70725+++ b/include/linux/i2c.h
70726@@ -366,6 +366,7 @@ struct i2c_algorithm {
70727 /* To determine what the adapter supports */
70728 u32 (*functionality) (struct i2c_adapter *);
70729 };
70730+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
70731
70732 /**
70733 * struct i2c_bus_recovery_info - I2C bus recovery information
70734diff --git a/include/linux/i2o.h b/include/linux/i2o.h
70735index d23c3c2..eb63c81 100644
70736--- a/include/linux/i2o.h
70737+++ b/include/linux/i2o.h
70738@@ -565,7 +565,7 @@ struct i2o_controller {
70739 struct i2o_device *exec; /* Executive */
70740 #if BITS_PER_LONG == 64
70741 spinlock_t context_list_lock; /* lock for context_list */
70742- atomic_t context_list_counter; /* needed for unique contexts */
70743+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
70744 struct list_head context_list; /* list of context id's
70745 and pointers */
70746 #endif
70747diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
70748index aff7ad8..3942bbd 100644
70749--- a/include/linux/if_pppox.h
70750+++ b/include/linux/if_pppox.h
70751@@ -76,7 +76,7 @@ struct pppox_proto {
70752 int (*ioctl)(struct socket *sock, unsigned int cmd,
70753 unsigned long arg);
70754 struct module *owner;
70755-};
70756+} __do_const;
70757
70758 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
70759 extern void unregister_pppox_proto(int proto_num);
70760diff --git a/include/linux/init.h b/include/linux/init.h
70761index 8618147..0821126 100644
70762--- a/include/linux/init.h
70763+++ b/include/linux/init.h
70764@@ -39,9 +39,36 @@
70765 * Also note, that this data cannot be "const".
70766 */
70767
70768+#ifdef MODULE
70769+#define add_init_latent_entropy
70770+#define add_devinit_latent_entropy
70771+#define add_cpuinit_latent_entropy
70772+#define add_meminit_latent_entropy
70773+#else
70774+#define add_init_latent_entropy __latent_entropy
70775+
70776+#ifdef CONFIG_HOTPLUG
70777+#define add_devinit_latent_entropy
70778+#else
70779+#define add_devinit_latent_entropy __latent_entropy
70780+#endif
70781+
70782+#ifdef CONFIG_HOTPLUG_CPU
70783+#define add_cpuinit_latent_entropy
70784+#else
70785+#define add_cpuinit_latent_entropy __latent_entropy
70786+#endif
70787+
70788+#ifdef CONFIG_MEMORY_HOTPLUG
70789+#define add_meminit_latent_entropy
70790+#else
70791+#define add_meminit_latent_entropy __latent_entropy
70792+#endif
70793+#endif
70794+
70795 /* These are for everybody (although not all archs will actually
70796 discard it in modules) */
70797-#define __init __section(.init.text) __cold notrace
70798+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
70799 #define __initdata __section(.init.data)
70800 #define __initconst __constsection(.init.rodata)
70801 #define __exitdata __section(.exit.data)
70802@@ -94,7 +121,7 @@
70803 #define __exit __section(.exit.text) __exitused __cold notrace
70804
70805 /* Used for HOTPLUG_CPU */
70806-#define __cpuinit __section(.cpuinit.text) __cold notrace
70807+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
70808 #define __cpuinitdata __section(.cpuinit.data)
70809 #define __cpuinitconst __constsection(.cpuinit.rodata)
70810 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
70811@@ -102,7 +129,7 @@
70812 #define __cpuexitconst __constsection(.cpuexit.rodata)
70813
70814 /* Used for MEMORY_HOTPLUG */
70815-#define __meminit __section(.meminit.text) __cold notrace
70816+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
70817 #define __meminitdata __section(.meminit.data)
70818 #define __meminitconst __constsection(.meminit.rodata)
70819 #define __memexit __section(.memexit.text) __exitused __cold notrace
70820diff --git a/include/linux/init_task.h b/include/linux/init_task.h
70821index 5cd0f09..c9f67cc 100644
70822--- a/include/linux/init_task.h
70823+++ b/include/linux/init_task.h
70824@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
70825
70826 #define INIT_TASK_COMM "swapper"
70827
70828+#ifdef CONFIG_X86
70829+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
70830+#else
70831+#define INIT_TASK_THREAD_INFO
70832+#endif
70833+
70834 /*
70835 * INIT_TASK is used to set up the first task table, touch at
70836 * your own risk!. Base=0, limit=0x1fffff (=2MB)
70837@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
70838 RCU_POINTER_INITIALIZER(cred, &init_cred), \
70839 .comm = INIT_TASK_COMM, \
70840 .thread = INIT_THREAD, \
70841+ INIT_TASK_THREAD_INFO \
70842 .fs = &init_fs, \
70843 .files = &init_files, \
70844 .signal = &init_signals, \
70845diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
70846index 5fa5afe..ac55b25 100644
70847--- a/include/linux/interrupt.h
70848+++ b/include/linux/interrupt.h
70849@@ -430,7 +430,7 @@ enum
70850 /* map softirq index to softirq name. update 'softirq_to_name' in
70851 * kernel/softirq.c when adding a new softirq.
70852 */
70853-extern char *softirq_to_name[NR_SOFTIRQS];
70854+extern const char * const softirq_to_name[NR_SOFTIRQS];
70855
70856 /* softirq mask and active fields moved to irq_cpustat_t in
70857 * asm/hardirq.h to get better cache usage. KAO
70858@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
70859
70860 struct softirq_action
70861 {
70862- void (*action)(struct softirq_action *);
70863-};
70864+ void (*action)(void);
70865+} __no_const;
70866
70867 asmlinkage void do_softirq(void);
70868 asmlinkage void __do_softirq(void);
70869-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
70870+extern void open_softirq(int nr, void (*action)(void));
70871 extern void softirq_init(void);
70872 extern void __raise_softirq_irqoff(unsigned int nr);
70873
70874diff --git a/include/linux/iommu.h b/include/linux/iommu.h
70875index 3aeb730..2177f39 100644
70876--- a/include/linux/iommu.h
70877+++ b/include/linux/iommu.h
70878@@ -113,7 +113,7 @@ struct iommu_ops {
70879 u32 (*domain_get_windows)(struct iommu_domain *domain);
70880
70881 unsigned long pgsize_bitmap;
70882-};
70883+} __do_const;
70884
70885 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70886 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70887diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70888index 89b7c24..382af74 100644
70889--- a/include/linux/ioport.h
70890+++ b/include/linux/ioport.h
70891@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70892 int adjust_resource(struct resource *res, resource_size_t start,
70893 resource_size_t size);
70894 resource_size_t resource_alignment(struct resource *res);
70895-static inline resource_size_t resource_size(const struct resource *res)
70896+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70897 {
70898 return res->end - res->start + 1;
70899 }
70900diff --git a/include/linux/irq.h b/include/linux/irq.h
70901index bc4e066..50468a9 100644
70902--- a/include/linux/irq.h
70903+++ b/include/linux/irq.h
70904@@ -328,7 +328,8 @@ struct irq_chip {
70905 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70906
70907 unsigned long flags;
70908-};
70909+} __do_const;
70910+typedef struct irq_chip __no_const irq_chip_no_const;
70911
70912 /*
70913 * irq_chip specific flags
70914diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
70915index 3e203eb..3fe68d0 100644
70916--- a/include/linux/irqchip/arm-gic.h
70917+++ b/include/linux/irqchip/arm-gic.h
70918@@ -59,9 +59,11 @@
70919
70920 #ifndef __ASSEMBLY__
70921
70922+#include <linux/irq.h>
70923+
70924 struct device_node;
70925
70926-extern struct irq_chip gic_arch_extn;
70927+extern irq_chip_no_const gic_arch_extn;
70928
70929 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
70930 u32 offset, struct device_node *);
70931diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70932index 6883e19..06992b1 100644
70933--- a/include/linux/kallsyms.h
70934+++ b/include/linux/kallsyms.h
70935@@ -15,7 +15,8 @@
70936
70937 struct module;
70938
70939-#ifdef CONFIG_KALLSYMS
70940+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70941+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70942 /* Lookup the address for a symbol. Returns 0 if not found. */
70943 unsigned long kallsyms_lookup_name(const char *name);
70944
70945@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70946 /* Stupid that this does nothing, but I didn't create this mess. */
70947 #define __print_symbol(fmt, addr)
70948 #endif /*CONFIG_KALLSYMS*/
70949+#else /* when included by kallsyms.c, vsnprintf.c, or
70950+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70951+extern void __print_symbol(const char *fmt, unsigned long address);
70952+extern int sprint_backtrace(char *buffer, unsigned long address);
70953+extern int sprint_symbol(char *buffer, unsigned long address);
70954+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70955+const char *kallsyms_lookup(unsigned long addr,
70956+ unsigned long *symbolsize,
70957+ unsigned long *offset,
70958+ char **modname, char *namebuf);
70959+#endif
70960
70961 /* This macro allows us to keep printk typechecking */
70962 static __printf(1, 2)
70963diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70964index 518a53a..5e28358 100644
70965--- a/include/linux/key-type.h
70966+++ b/include/linux/key-type.h
70967@@ -125,7 +125,7 @@ struct key_type {
70968 /* internal fields */
70969 struct list_head link; /* link in types list */
70970 struct lock_class_key lock_class; /* key->sem lock class */
70971-};
70972+} __do_const;
70973
70974 extern struct key_type key_type_keyring;
70975
70976diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70977index c6e091b..a940adf 100644
70978--- a/include/linux/kgdb.h
70979+++ b/include/linux/kgdb.h
70980@@ -52,7 +52,7 @@ extern int kgdb_connected;
70981 extern int kgdb_io_module_registered;
70982
70983 extern atomic_t kgdb_setting_breakpoint;
70984-extern atomic_t kgdb_cpu_doing_single_step;
70985+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70986
70987 extern struct task_struct *kgdb_usethread;
70988 extern struct task_struct *kgdb_contthread;
70989@@ -254,7 +254,7 @@ struct kgdb_arch {
70990 void (*correct_hw_break)(void);
70991
70992 void (*enable_nmi)(bool on);
70993-};
70994+} __do_const;
70995
70996 /**
70997 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70998@@ -279,7 +279,7 @@ struct kgdb_io {
70999 void (*pre_exception) (void);
71000 void (*post_exception) (void);
71001 int is_console;
71002-};
71003+} __do_const;
71004
71005 extern struct kgdb_arch arch_kgdb_ops;
71006
71007diff --git a/include/linux/kmod.h b/include/linux/kmod.h
71008index 0555cc6..b16a7a4 100644
71009--- a/include/linux/kmod.h
71010+++ b/include/linux/kmod.h
71011@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
71012 * usually useless though. */
71013 extern __printf(2, 3)
71014 int __request_module(bool wait, const char *name, ...);
71015+extern __printf(3, 4)
71016+int ___request_module(bool wait, char *param_name, const char *name, ...);
71017 #define request_module(mod...) __request_module(true, mod)
71018 #define request_module_nowait(mod...) __request_module(false, mod)
71019 #define try_then_request_module(x, mod...) \
71020diff --git a/include/linux/kobject.h b/include/linux/kobject.h
71021index 939b112..ed6ed51 100644
71022--- a/include/linux/kobject.h
71023+++ b/include/linux/kobject.h
71024@@ -111,7 +111,7 @@ struct kobj_type {
71025 struct attribute **default_attrs;
71026 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
71027 const void *(*namespace)(struct kobject *kobj);
71028-};
71029+} __do_const;
71030
71031 struct kobj_uevent_env {
71032 char *envp[UEVENT_NUM_ENVP];
71033@@ -134,6 +134,7 @@ struct kobj_attribute {
71034 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
71035 const char *buf, size_t count);
71036 };
71037+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
71038
71039 extern const struct sysfs_ops kobj_sysfs_ops;
71040
71041diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
71042index f66b065..c2c29b4 100644
71043--- a/include/linux/kobject_ns.h
71044+++ b/include/linux/kobject_ns.h
71045@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
71046 const void *(*netlink_ns)(struct sock *sk);
71047 const void *(*initial_ns)(void);
71048 void (*drop_ns)(void *);
71049-};
71050+} __do_const;
71051
71052 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
71053 int kobj_ns_type_registered(enum kobj_ns_type type);
71054diff --git a/include/linux/kref.h b/include/linux/kref.h
71055index 484604d..0f6c5b6 100644
71056--- a/include/linux/kref.h
71057+++ b/include/linux/kref.h
71058@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
71059 static inline int kref_sub(struct kref *kref, unsigned int count,
71060 void (*release)(struct kref *kref))
71061 {
71062- WARN_ON(release == NULL);
71063+ BUG_ON(release == NULL);
71064
71065 if (atomic_sub_and_test((int) count, &kref->refcount)) {
71066 release(kref);
71067diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
71068index 8db53cf..c21121d 100644
71069--- a/include/linux/kvm_host.h
71070+++ b/include/linux/kvm_host.h
71071@@ -444,7 +444,7 @@ static inline void kvm_irqfd_exit(void)
71072 {
71073 }
71074 #endif
71075-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
71076+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
71077 struct module *module);
71078 void kvm_exit(void);
71079
71080@@ -616,7 +616,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
71081 struct kvm_guest_debug *dbg);
71082 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
71083
71084-int kvm_arch_init(void *opaque);
71085+int kvm_arch_init(const void *opaque);
71086 void kvm_arch_exit(void);
71087
71088 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
71089diff --git a/include/linux/libata.h b/include/linux/libata.h
71090index eae7a05..2cdd875 100644
71091--- a/include/linux/libata.h
71092+++ b/include/linux/libata.h
71093@@ -919,7 +919,7 @@ struct ata_port_operations {
71094 * fields must be pointers.
71095 */
71096 const struct ata_port_operations *inherits;
71097-};
71098+} __do_const;
71099
71100 struct ata_port_info {
71101 unsigned long flags;
71102diff --git a/include/linux/list.h b/include/linux/list.h
71103index b83e565..baa6c1d 100644
71104--- a/include/linux/list.h
71105+++ b/include/linux/list.h
71106@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
71107 extern void list_del(struct list_head *entry);
71108 #endif
71109
71110+extern void __pax_list_add(struct list_head *new,
71111+ struct list_head *prev,
71112+ struct list_head *next);
71113+static inline void pax_list_add(struct list_head *new, struct list_head *head)
71114+{
71115+ __pax_list_add(new, head, head->next);
71116+}
71117+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
71118+{
71119+ __pax_list_add(new, head->prev, head);
71120+}
71121+extern void pax_list_del(struct list_head *entry);
71122+
71123 /**
71124 * list_replace - replace old entry by new one
71125 * @old : the element to be replaced
71126@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
71127 INIT_LIST_HEAD(entry);
71128 }
71129
71130+extern void pax_list_del_init(struct list_head *entry);
71131+
71132 /**
71133 * list_move - delete from one list and add as another's head
71134 * @list: the entry to move
71135diff --git a/include/linux/math64.h b/include/linux/math64.h
71136index 2913b86..4209244 100644
71137--- a/include/linux/math64.h
71138+++ b/include/linux/math64.h
71139@@ -15,7 +15,7 @@
71140 * This is commonly provided by 32bit archs to provide an optimized 64bit
71141 * divide.
71142 */
71143-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
71144+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
71145 {
71146 *remainder = dividend % divisor;
71147 return dividend / divisor;
71148@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
71149 #define div64_ul(x, y) div_u64((x), (y))
71150
71151 #ifndef div_u64_rem
71152-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
71153+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
71154 {
71155 *remainder = do_div(dividend, divisor);
71156 return dividend;
71157@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
71158 * divide.
71159 */
71160 #ifndef div_u64
71161-static inline u64 div_u64(u64 dividend, u32 divisor)
71162+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
71163 {
71164 u32 remainder;
71165 return div_u64_rem(dividend, divisor, &remainder);
71166diff --git a/include/linux/mm.h b/include/linux/mm.h
71167index e0c8528..bcf0c29 100644
71168--- a/include/linux/mm.h
71169+++ b/include/linux/mm.h
71170@@ -104,6 +104,11 @@ extern unsigned int kobjsize(const void *objp);
71171 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
71172 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
71173 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
71174+
71175+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
71176+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
71177+#endif
71178+
71179 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
71180
71181 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
71182@@ -205,8 +210,8 @@ struct vm_operations_struct {
71183 /* called by access_process_vm when get_user_pages() fails, typically
71184 * for use by special VMAs that can switch between memory and hardware
71185 */
71186- int (*access)(struct vm_area_struct *vma, unsigned long addr,
71187- void *buf, int len, int write);
71188+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
71189+ void *buf, size_t len, int write);
71190 #ifdef CONFIG_NUMA
71191 /*
71192 * set_policy() op must add a reference to any non-NULL @new mempolicy
71193@@ -236,6 +241,7 @@ struct vm_operations_struct {
71194 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
71195 unsigned long size, pgoff_t pgoff);
71196 };
71197+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
71198
71199 struct mmu_gather;
71200 struct inode;
71201@@ -980,8 +986,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
71202 unsigned long *pfn);
71203 int follow_phys(struct vm_area_struct *vma, unsigned long address,
71204 unsigned int flags, unsigned long *prot, resource_size_t *phys);
71205-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
71206- void *buf, int len, int write);
71207+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
71208+ void *buf, size_t len, int write);
71209
71210 static inline void unmap_shared_mapping_range(struct address_space *mapping,
71211 loff_t const holebegin, loff_t const holelen)
71212@@ -1020,9 +1026,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
71213 }
71214 #endif
71215
71216-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
71217-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
71218- void *buf, int len, int write);
71219+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
71220+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
71221+ void *buf, size_t len, int write);
71222
71223 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71224 unsigned long start, unsigned long nr_pages,
71225@@ -1053,34 +1059,6 @@ int set_page_dirty(struct page *page);
71226 int set_page_dirty_lock(struct page *page);
71227 int clear_page_dirty_for_io(struct page *page);
71228
71229-/* Is the vma a continuation of the stack vma above it? */
71230-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
71231-{
71232- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
71233-}
71234-
71235-static inline int stack_guard_page_start(struct vm_area_struct *vma,
71236- unsigned long addr)
71237-{
71238- return (vma->vm_flags & VM_GROWSDOWN) &&
71239- (vma->vm_start == addr) &&
71240- !vma_growsdown(vma->vm_prev, addr);
71241-}
71242-
71243-/* Is the vma a continuation of the stack vma below it? */
71244-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
71245-{
71246- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
71247-}
71248-
71249-static inline int stack_guard_page_end(struct vm_area_struct *vma,
71250- unsigned long addr)
71251-{
71252- return (vma->vm_flags & VM_GROWSUP) &&
71253- (vma->vm_end == addr) &&
71254- !vma_growsup(vma->vm_next, addr);
71255-}
71256-
71257 extern pid_t
71258 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
71259
71260@@ -1180,6 +1158,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
71261 }
71262 #endif
71263
71264+#ifdef CONFIG_MMU
71265+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
71266+#else
71267+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
71268+{
71269+ return __pgprot(0);
71270+}
71271+#endif
71272+
71273 int vma_wants_writenotify(struct vm_area_struct *vma);
71274
71275 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
71276@@ -1198,8 +1185,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
71277 {
71278 return 0;
71279 }
71280+
71281+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
71282+ unsigned long address)
71283+{
71284+ return 0;
71285+}
71286 #else
71287 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
71288+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
71289 #endif
71290
71291 #ifdef __PAGETABLE_PMD_FOLDED
71292@@ -1208,8 +1202,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
71293 {
71294 return 0;
71295 }
71296+
71297+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
71298+ unsigned long address)
71299+{
71300+ return 0;
71301+}
71302 #else
71303 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
71304+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
71305 #endif
71306
71307 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
71308@@ -1227,11 +1228,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
71309 NULL: pud_offset(pgd, address);
71310 }
71311
71312+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
71313+{
71314+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
71315+ NULL: pud_offset(pgd, address);
71316+}
71317+
71318 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
71319 {
71320 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
71321 NULL: pmd_offset(pud, address);
71322 }
71323+
71324+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
71325+{
71326+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
71327+ NULL: pmd_offset(pud, address);
71328+}
71329 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
71330
71331 #if USE_SPLIT_PTLOCKS
71332@@ -1517,6 +1530,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
71333 unsigned long len, unsigned long prot, unsigned long flags,
71334 unsigned long pgoff, unsigned long *populate);
71335 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
71336+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
71337
71338 #ifdef CONFIG_MMU
71339 extern int __mm_populate(unsigned long addr, unsigned long len,
71340@@ -1545,10 +1559,11 @@ struct vm_unmapped_area_info {
71341 unsigned long high_limit;
71342 unsigned long align_mask;
71343 unsigned long align_offset;
71344+ unsigned long threadstack_offset;
71345 };
71346
71347-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
71348-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
71349+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
71350+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
71351
71352 /*
71353 * Search for an unmapped address range.
71354@@ -1560,7 +1575,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
71355 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
71356 */
71357 static inline unsigned long
71358-vm_unmapped_area(struct vm_unmapped_area_info *info)
71359+vm_unmapped_area(const struct vm_unmapped_area_info *info)
71360 {
71361 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
71362 return unmapped_area(info);
71363@@ -1623,6 +1638,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
71364 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
71365 struct vm_area_struct **pprev);
71366
71367+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
71368+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
71369+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
71370+
71371 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
71372 NULL if none. Assume start_addr < end_addr. */
71373 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
71374@@ -1651,15 +1670,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
71375 return vma;
71376 }
71377
71378-#ifdef CONFIG_MMU
71379-pgprot_t vm_get_page_prot(unsigned long vm_flags);
71380-#else
71381-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
71382-{
71383- return __pgprot(0);
71384-}
71385-#endif
71386-
71387 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
71388 unsigned long change_prot_numa(struct vm_area_struct *vma,
71389 unsigned long start, unsigned long end);
71390@@ -1711,6 +1721,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
71391 static inline void vm_stat_account(struct mm_struct *mm,
71392 unsigned long flags, struct file *file, long pages)
71393 {
71394+
71395+#ifdef CONFIG_PAX_RANDMMAP
71396+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
71397+#endif
71398+
71399 mm->total_vm += pages;
71400 }
71401 #endif /* CONFIG_PROC_FS */
71402@@ -1791,7 +1806,7 @@ extern int unpoison_memory(unsigned long pfn);
71403 extern int sysctl_memory_failure_early_kill;
71404 extern int sysctl_memory_failure_recovery;
71405 extern void shake_page(struct page *p, int access);
71406-extern atomic_long_t num_poisoned_pages;
71407+extern atomic_long_unchecked_t num_poisoned_pages;
71408 extern int soft_offline_page(struct page *page, int flags);
71409
71410 extern void dump_page(struct page *page);
71411@@ -1828,5 +1843,11 @@ void __init setup_nr_node_ids(void);
71412 static inline void setup_nr_node_ids(void) {}
71413 #endif
71414
71415+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
71416+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
71417+#else
71418+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
71419+#endif
71420+
71421 #endif /* __KERNEL__ */
71422 #endif /* _LINUX_MM_H */
71423diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
71424index ace9a5f..81bdb59 100644
71425--- a/include/linux/mm_types.h
71426+++ b/include/linux/mm_types.h
71427@@ -289,6 +289,8 @@ struct vm_area_struct {
71428 #ifdef CONFIG_NUMA
71429 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
71430 #endif
71431+
71432+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
71433 };
71434
71435 struct core_thread {
71436@@ -437,6 +439,24 @@ struct mm_struct {
71437 int first_nid;
71438 #endif
71439 struct uprobes_state uprobes_state;
71440+
71441+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71442+ unsigned long pax_flags;
71443+#endif
71444+
71445+#ifdef CONFIG_PAX_DLRESOLVE
71446+ unsigned long call_dl_resolve;
71447+#endif
71448+
71449+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
71450+ unsigned long call_syscall;
71451+#endif
71452+
71453+#ifdef CONFIG_PAX_ASLR
71454+ unsigned long delta_mmap; /* randomized offset */
71455+ unsigned long delta_stack; /* randomized offset */
71456+#endif
71457+
71458 };
71459
71460 /* first nid will either be a valid NID or one of these values */
71461diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
71462index c5d5278..f0b68c8 100644
71463--- a/include/linux/mmiotrace.h
71464+++ b/include/linux/mmiotrace.h
71465@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
71466 /* Called from ioremap.c */
71467 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
71468 void __iomem *addr);
71469-extern void mmiotrace_iounmap(volatile void __iomem *addr);
71470+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
71471
71472 /* For anyone to insert markers. Remember trailing newline. */
71473 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
71474@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
71475 {
71476 }
71477
71478-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
71479+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
71480 {
71481 }
71482
71483diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
71484index 5c76737..61f518e 100644
71485--- a/include/linux/mmzone.h
71486+++ b/include/linux/mmzone.h
71487@@ -396,7 +396,7 @@ struct zone {
71488 unsigned long flags; /* zone flags, see below */
71489
71490 /* Zone statistics */
71491- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71492+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
71493
71494 /*
71495 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
71496diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
71497index b508016..237cfe5 100644
71498--- a/include/linux/mod_devicetable.h
71499+++ b/include/linux/mod_devicetable.h
71500@@ -13,7 +13,7 @@
71501 typedef unsigned long kernel_ulong_t;
71502 #endif
71503
71504-#define PCI_ANY_ID (~0)
71505+#define PCI_ANY_ID ((__u16)~0)
71506
71507 struct pci_device_id {
71508 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
71509@@ -139,7 +139,7 @@ struct usb_device_id {
71510 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
71511 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
71512
71513-#define HID_ANY_ID (~0)
71514+#define HID_ANY_ID (~0U)
71515 #define HID_BUS_ANY 0xffff
71516 #define HID_GROUP_ANY 0x0000
71517
71518@@ -465,7 +465,7 @@ struct dmi_system_id {
71519 const char *ident;
71520 struct dmi_strmatch matches[4];
71521 void *driver_data;
71522-};
71523+} __do_const;
71524 /*
71525 * struct dmi_device_id appears during expansion of
71526 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
71527diff --git a/include/linux/module.h b/include/linux/module.h
71528index 46f1ea0..a34ca37 100644
71529--- a/include/linux/module.h
71530+++ b/include/linux/module.h
71531@@ -17,9 +17,11 @@
71532 #include <linux/moduleparam.h>
71533 #include <linux/tracepoint.h>
71534 #include <linux/export.h>
71535+#include <linux/fs.h>
71536
71537 #include <linux/percpu.h>
71538 #include <asm/module.h>
71539+#include <asm/pgtable.h>
71540
71541 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
71542 #define MODULE_SIG_STRING "~Module signature appended~\n"
71543@@ -54,12 +56,13 @@ struct module_attribute {
71544 int (*test)(struct module *);
71545 void (*free)(struct module *);
71546 };
71547+typedef struct module_attribute __no_const module_attribute_no_const;
71548
71549 struct module_version_attribute {
71550 struct module_attribute mattr;
71551 const char *module_name;
71552 const char *version;
71553-} __attribute__ ((__aligned__(sizeof(void *))));
71554+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
71555
71556 extern ssize_t __modver_version_show(struct module_attribute *,
71557 struct module_kobject *, char *);
71558@@ -232,7 +235,7 @@ struct module
71559
71560 /* Sysfs stuff. */
71561 struct module_kobject mkobj;
71562- struct module_attribute *modinfo_attrs;
71563+ module_attribute_no_const *modinfo_attrs;
71564 const char *version;
71565 const char *srcversion;
71566 struct kobject *holders_dir;
71567@@ -281,19 +284,16 @@ struct module
71568 int (*init)(void);
71569
71570 /* If this is non-NULL, vfree after init() returns */
71571- void *module_init;
71572+ void *module_init_rx, *module_init_rw;
71573
71574 /* Here is the actual code + data, vfree'd on unload. */
71575- void *module_core;
71576+ void *module_core_rx, *module_core_rw;
71577
71578 /* Here are the sizes of the init and core sections */
71579- unsigned int init_size, core_size;
71580+ unsigned int init_size_rw, core_size_rw;
71581
71582 /* The size of the executable code in each section. */
71583- unsigned int init_text_size, core_text_size;
71584-
71585- /* Size of RO sections of the module (text+rodata) */
71586- unsigned int init_ro_size, core_ro_size;
71587+ unsigned int init_size_rx, core_size_rx;
71588
71589 /* Arch-specific module values */
71590 struct mod_arch_specific arch;
71591@@ -349,6 +349,10 @@ struct module
71592 #ifdef CONFIG_EVENT_TRACING
71593 struct ftrace_event_call **trace_events;
71594 unsigned int num_trace_events;
71595+ struct file_operations trace_id;
71596+ struct file_operations trace_enable;
71597+ struct file_operations trace_format;
71598+ struct file_operations trace_filter;
71599 #endif
71600 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
71601 unsigned int num_ftrace_callsites;
71602@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
71603 bool is_module_percpu_address(unsigned long addr);
71604 bool is_module_text_address(unsigned long addr);
71605
71606+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
71607+{
71608+
71609+#ifdef CONFIG_PAX_KERNEXEC
71610+ if (ktla_ktva(addr) >= (unsigned long)start &&
71611+ ktla_ktva(addr) < (unsigned long)start + size)
71612+ return 1;
71613+#endif
71614+
71615+ return ((void *)addr >= start && (void *)addr < start + size);
71616+}
71617+
71618+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
71619+{
71620+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
71621+}
71622+
71623+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
71624+{
71625+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
71626+}
71627+
71628+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
71629+{
71630+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
71631+}
71632+
71633+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
71634+{
71635+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
71636+}
71637+
71638 static inline int within_module_core(unsigned long addr, const struct module *mod)
71639 {
71640- return (unsigned long)mod->module_core <= addr &&
71641- addr < (unsigned long)mod->module_core + mod->core_size;
71642+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
71643 }
71644
71645 static inline int within_module_init(unsigned long addr, const struct module *mod)
71646 {
71647- return (unsigned long)mod->module_init <= addr &&
71648- addr < (unsigned long)mod->module_init + mod->init_size;
71649+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
71650 }
71651
71652 /* Search for module by name: must hold module_mutex. */
71653diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
71654index 560ca53..ef621ef 100644
71655--- a/include/linux/moduleloader.h
71656+++ b/include/linux/moduleloader.h
71657@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
71658 sections. Returns NULL on failure. */
71659 void *module_alloc(unsigned long size);
71660
71661+#ifdef CONFIG_PAX_KERNEXEC
71662+void *module_alloc_exec(unsigned long size);
71663+#else
71664+#define module_alloc_exec(x) module_alloc(x)
71665+#endif
71666+
71667 /* Free memory returned from module_alloc. */
71668 void module_free(struct module *mod, void *module_region);
71669
71670+#ifdef CONFIG_PAX_KERNEXEC
71671+void module_free_exec(struct module *mod, void *module_region);
71672+#else
71673+#define module_free_exec(x, y) module_free((x), (y))
71674+#endif
71675+
71676 /*
71677 * Apply the given relocation to the (simplified) ELF. Return -error
71678 * or 0.
71679@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
71680 unsigned int relsec,
71681 struct module *me)
71682 {
71683+#ifdef CONFIG_MODULES
71684 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
71685+#endif
71686 return -ENOEXEC;
71687 }
71688 #endif
71689@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
71690 unsigned int relsec,
71691 struct module *me)
71692 {
71693+#ifdef CONFIG_MODULES
71694 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
71695+#endif
71696 return -ENOEXEC;
71697 }
71698 #endif
71699diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
71700index 137b419..fe663ec 100644
71701--- a/include/linux/moduleparam.h
71702+++ b/include/linux/moduleparam.h
71703@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
71704 * @len is usually just sizeof(string).
71705 */
71706 #define module_param_string(name, string, len, perm) \
71707- static const struct kparam_string __param_string_##name \
71708+ static const struct kparam_string __param_string_##name __used \
71709 = { len, string }; \
71710 __module_param_call(MODULE_PARAM_PREFIX, name, \
71711 &param_ops_string, \
71712@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
71713 */
71714 #define module_param_array_named(name, array, type, nump, perm) \
71715 param_check_##type(name, &(array)[0]); \
71716- static const struct kparam_array __param_arr_##name \
71717+ static const struct kparam_array __param_arr_##name __used \
71718 = { .max = ARRAY_SIZE(array), .num = nump, \
71719 .ops = &param_ops_##type, \
71720 .elemsize = sizeof(array[0]), .elem = array }; \
71721diff --git a/include/linux/namei.h b/include/linux/namei.h
71722index 5a5ff57..5ae5070 100644
71723--- a/include/linux/namei.h
71724+++ b/include/linux/namei.h
71725@@ -19,7 +19,7 @@ struct nameidata {
71726 unsigned seq;
71727 int last_type;
71728 unsigned depth;
71729- char *saved_names[MAX_NESTED_LINKS + 1];
71730+ const char *saved_names[MAX_NESTED_LINKS + 1];
71731 };
71732
71733 /*
71734@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
71735
71736 extern void nd_jump_link(struct nameidata *nd, struct path *path);
71737
71738-static inline void nd_set_link(struct nameidata *nd, char *path)
71739+static inline void nd_set_link(struct nameidata *nd, const char *path)
71740 {
71741 nd->saved_names[nd->depth] = path;
71742 }
71743
71744-static inline char *nd_get_link(struct nameidata *nd)
71745+static inline const char *nd_get_link(const struct nameidata *nd)
71746 {
71747 return nd->saved_names[nd->depth];
71748 }
71749diff --git a/include/linux/net.h b/include/linux/net.h
71750index 99c9f0c..e1cf296 100644
71751--- a/include/linux/net.h
71752+++ b/include/linux/net.h
71753@@ -183,7 +183,7 @@ struct net_proto_family {
71754 int (*create)(struct net *net, struct socket *sock,
71755 int protocol, int kern);
71756 struct module *owner;
71757-};
71758+} __do_const;
71759
71760 struct iovec;
71761 struct kvec;
71762diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
71763index 96e4c21..9cc8278 100644
71764--- a/include/linux/netdevice.h
71765+++ b/include/linux/netdevice.h
71766@@ -1026,6 +1026,7 @@ struct net_device_ops {
71767 int (*ndo_change_carrier)(struct net_device *dev,
71768 bool new_carrier);
71769 };
71770+typedef struct net_device_ops __no_const net_device_ops_no_const;
71771
71772 /*
71773 * The DEVICE structure.
71774@@ -1094,7 +1095,7 @@ struct net_device {
71775 int iflink;
71776
71777 struct net_device_stats stats;
71778- atomic_long_t rx_dropped; /* dropped packets by core network
71779+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
71780 * Do not use this in drivers.
71781 */
71782
71783diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
71784index 0060fde..481c6ae 100644
71785--- a/include/linux/netfilter.h
71786+++ b/include/linux/netfilter.h
71787@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
71788 #endif
71789 /* Use the module struct to lock set/get code in place */
71790 struct module *owner;
71791-};
71792+} __do_const;
71793
71794 /* Function to register/unregister hook points. */
71795 int nf_register_hook(struct nf_hook_ops *reg);
71796diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
71797index d80e275..c3510b8 100644
71798--- a/include/linux/netfilter/ipset/ip_set.h
71799+++ b/include/linux/netfilter/ipset/ip_set.h
71800@@ -124,7 +124,7 @@ struct ip_set_type_variant {
71801 /* Return true if "b" set is the same as "a"
71802 * according to the create set parameters */
71803 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
71804-};
71805+} __do_const;
71806
71807 /* The core set type structure */
71808 struct ip_set_type {
71809diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
71810index cadb740..d7c37c0 100644
71811--- a/include/linux/netfilter/nfnetlink.h
71812+++ b/include/linux/netfilter/nfnetlink.h
71813@@ -16,7 +16,7 @@ struct nfnl_callback {
71814 const struct nlattr * const cda[]);
71815 const struct nla_policy *policy; /* netlink attribute policy */
71816 const u_int16_t attr_count; /* number of nlattr's */
71817-};
71818+} __do_const;
71819
71820 struct nfnetlink_subsystem {
71821 const char *name;
71822diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
71823new file mode 100644
71824index 0000000..33f4af8
71825--- /dev/null
71826+++ b/include/linux/netfilter/xt_gradm.h
71827@@ -0,0 +1,9 @@
71828+#ifndef _LINUX_NETFILTER_XT_GRADM_H
71829+#define _LINUX_NETFILTER_XT_GRADM_H 1
71830+
71831+struct xt_gradm_mtinfo {
71832+ __u16 flags;
71833+ __u16 invflags;
71834+};
71835+
71836+#endif
71837diff --git a/include/linux/nls.h b/include/linux/nls.h
71838index 5dc635f..35f5e11 100644
71839--- a/include/linux/nls.h
71840+++ b/include/linux/nls.h
71841@@ -31,7 +31,7 @@ struct nls_table {
71842 const unsigned char *charset2upper;
71843 struct module *owner;
71844 struct nls_table *next;
71845-};
71846+} __do_const;
71847
71848 /* this value hold the maximum octet of charset */
71849 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
71850diff --git a/include/linux/notifier.h b/include/linux/notifier.h
71851index d14a4c3..a078786 100644
71852--- a/include/linux/notifier.h
71853+++ b/include/linux/notifier.h
71854@@ -54,7 +54,8 @@ struct notifier_block {
71855 notifier_fn_t notifier_call;
71856 struct notifier_block __rcu *next;
71857 int priority;
71858-};
71859+} __do_const;
71860+typedef struct notifier_block __no_const notifier_block_no_const;
71861
71862 struct atomic_notifier_head {
71863 spinlock_t lock;
71864diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
71865index a4c5624..79d6d88 100644
71866--- a/include/linux/oprofile.h
71867+++ b/include/linux/oprofile.h
71868@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
71869 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
71870 char const * name, ulong * val);
71871
71872-/** Create a file for read-only access to an atomic_t. */
71873+/** Create a file for read-only access to an atomic_unchecked_t. */
71874 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
71875- char const * name, atomic_t * val);
71876+ char const * name, atomic_unchecked_t * val);
71877
71878 /** create a directory */
71879 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
71880diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
71881index 8db71dc..a76bf2c 100644
71882--- a/include/linux/pci_hotplug.h
71883+++ b/include/linux/pci_hotplug.h
71884@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
71885 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
71886 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
71887 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
71888-};
71889+} __do_const;
71890+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
71891
71892 /**
71893 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
71894diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
71895index c5b6dbf..b124155 100644
71896--- a/include/linux/perf_event.h
71897+++ b/include/linux/perf_event.h
71898@@ -318,8 +318,8 @@ struct perf_event {
71899
71900 enum perf_event_active_state state;
71901 unsigned int attach_state;
71902- local64_t count;
71903- atomic64_t child_count;
71904+ local64_t count; /* PaX: fix it one day */
71905+ atomic64_unchecked_t child_count;
71906
71907 /*
71908 * These are the total time in nanoseconds that the event
71909@@ -370,8 +370,8 @@ struct perf_event {
71910 * These accumulate total time (in nanoseconds) that children
71911 * events have been enabled and running, respectively.
71912 */
71913- atomic64_t child_total_time_enabled;
71914- atomic64_t child_total_time_running;
71915+ atomic64_unchecked_t child_total_time_enabled;
71916+ atomic64_unchecked_t child_total_time_running;
71917
71918 /*
71919 * Protect attach/detach and child_list:
71920@@ -692,7 +692,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
71921 entry->ip[entry->nr++] = ip;
71922 }
71923
71924-extern int sysctl_perf_event_paranoid;
71925+extern int sysctl_perf_event_legitimately_concerned;
71926 extern int sysctl_perf_event_mlock;
71927 extern int sysctl_perf_event_sample_rate;
71928
71929@@ -700,19 +700,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
71930 void __user *buffer, size_t *lenp,
71931 loff_t *ppos);
71932
71933+static inline bool perf_paranoid_any(void)
71934+{
71935+ return sysctl_perf_event_legitimately_concerned > 2;
71936+}
71937+
71938 static inline bool perf_paranoid_tracepoint_raw(void)
71939 {
71940- return sysctl_perf_event_paranoid > -1;
71941+ return sysctl_perf_event_legitimately_concerned > -1;
71942 }
71943
71944 static inline bool perf_paranoid_cpu(void)
71945 {
71946- return sysctl_perf_event_paranoid > 0;
71947+ return sysctl_perf_event_legitimately_concerned > 0;
71948 }
71949
71950 static inline bool perf_paranoid_kernel(void)
71951 {
71952- return sysctl_perf_event_paranoid > 1;
71953+ return sysctl_perf_event_legitimately_concerned > 1;
71954 }
71955
71956 extern void perf_event_init(void);
71957@@ -806,7 +811,7 @@ static inline void perf_restore_debug_store(void) { }
71958 */
71959 #define perf_cpu_notifier(fn) \
71960 do { \
71961- static struct notifier_block fn##_nb __cpuinitdata = \
71962+ static struct notifier_block fn##_nb = \
71963 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71964 unsigned long cpu = smp_processor_id(); \
71965 unsigned long flags; \
71966@@ -826,7 +831,7 @@ struct perf_pmu_events_attr {
71967 struct device_attribute attr;
71968 u64 id;
71969 const char *event_str;
71970-};
71971+} __do_const;
71972
71973 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
71974 static struct perf_pmu_events_attr _var = { \
71975diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71976index b8809fe..ae4ccd0 100644
71977--- a/include/linux/pipe_fs_i.h
71978+++ b/include/linux/pipe_fs_i.h
71979@@ -47,10 +47,10 @@ struct pipe_inode_info {
71980 struct mutex mutex;
71981 wait_queue_head_t wait;
71982 unsigned int nrbufs, curbuf, buffers;
71983- unsigned int readers;
71984- unsigned int writers;
71985- unsigned int files;
71986- unsigned int waiting_writers;
71987+ atomic_t readers;
71988+ atomic_t writers;
71989+ atomic_t files;
71990+ atomic_t waiting_writers;
71991 unsigned int r_counter;
71992 unsigned int w_counter;
71993 struct page *tmp_page;
71994diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71995index 5f28cae..3d23723 100644
71996--- a/include/linux/platform_data/usb-ehci-s5p.h
71997+++ b/include/linux/platform_data/usb-ehci-s5p.h
71998@@ -14,7 +14,7 @@
71999 struct s5p_ehci_platdata {
72000 int (*phy_init)(struct platform_device *pdev, int type);
72001 int (*phy_exit)(struct platform_device *pdev, int type);
72002-};
72003+} __no_const;
72004
72005 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
72006
72007diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
72008index c256c59..8ea94c7 100644
72009--- a/include/linux/platform_data/usb-ohci-exynos.h
72010+++ b/include/linux/platform_data/usb-ohci-exynos.h
72011@@ -14,7 +14,7 @@
72012 struct exynos4_ohci_platdata {
72013 int (*phy_init)(struct platform_device *pdev, int type);
72014 int (*phy_exit)(struct platform_device *pdev, int type);
72015-};
72016+} __no_const;
72017
72018 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
72019
72020diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
72021index 7c1d252..c5c773e 100644
72022--- a/include/linux/pm_domain.h
72023+++ b/include/linux/pm_domain.h
72024@@ -48,7 +48,7 @@ struct gpd_dev_ops {
72025
72026 struct gpd_cpu_data {
72027 unsigned int saved_exit_latency;
72028- struct cpuidle_state *idle_state;
72029+ cpuidle_state_no_const *idle_state;
72030 };
72031
72032 struct generic_pm_domain {
72033diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
72034index 7d7e09e..8671ef8 100644
72035--- a/include/linux/pm_runtime.h
72036+++ b/include/linux/pm_runtime.h
72037@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
72038
72039 static inline void pm_runtime_mark_last_busy(struct device *dev)
72040 {
72041- ACCESS_ONCE(dev->power.last_busy) = jiffies;
72042+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
72043 }
72044
72045 #else /* !CONFIG_PM_RUNTIME */
72046diff --git a/include/linux/pnp.h b/include/linux/pnp.h
72047index 195aafc..49a7bc2 100644
72048--- a/include/linux/pnp.h
72049+++ b/include/linux/pnp.h
72050@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
72051 struct pnp_fixup {
72052 char id[7];
72053 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
72054-};
72055+} __do_const;
72056
72057 /* config parameters */
72058 #define PNP_CONFIG_NORMAL 0x0001
72059diff --git a/include/linux/poison.h b/include/linux/poison.h
72060index 2110a81..13a11bb 100644
72061--- a/include/linux/poison.h
72062+++ b/include/linux/poison.h
72063@@ -19,8 +19,8 @@
72064 * under normal circumstances, used to verify that nobody uses
72065 * non-initialized list entries.
72066 */
72067-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
72068-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
72069+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
72070+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
72071
72072 /********** include/linux/timer.h **********/
72073 /*
72074diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
72075index c0f44c2..1572583 100644
72076--- a/include/linux/power/smartreflex.h
72077+++ b/include/linux/power/smartreflex.h
72078@@ -238,7 +238,7 @@ struct omap_sr_class_data {
72079 int (*notify)(struct omap_sr *sr, u32 status);
72080 u8 notify_flags;
72081 u8 class_type;
72082-};
72083+} __do_const;
72084
72085 /**
72086 * struct omap_sr_nvalue_table - Smartreflex n-target value info
72087diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
72088index 4ea1d37..80f4b33 100644
72089--- a/include/linux/ppp-comp.h
72090+++ b/include/linux/ppp-comp.h
72091@@ -84,7 +84,7 @@ struct compressor {
72092 struct module *owner;
72093 /* Extra skb space needed by the compressor algorithm */
72094 unsigned int comp_extra;
72095-};
72096+} __do_const;
72097
72098 /*
72099 * The return value from decompress routine is the length of the
72100diff --git a/include/linux/printk.h b/include/linux/printk.h
72101index 22c7052..ad3fa0a 100644
72102--- a/include/linux/printk.h
72103+++ b/include/linux/printk.h
72104@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
72105 void early_printk(const char *s, ...) { }
72106 #endif
72107
72108+extern int kptr_restrict;
72109+
72110 #ifdef CONFIG_PRINTK
72111 asmlinkage __printf(5, 0)
72112 int vprintk_emit(int facility, int level,
72113@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
72114
72115 extern int printk_delay_msec;
72116 extern int dmesg_restrict;
72117-extern int kptr_restrict;
72118
72119 extern void wake_up_klogd(void);
72120
72121diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
72122index 608e60a..c26f864 100644
72123--- a/include/linux/proc_fs.h
72124+++ b/include/linux/proc_fs.h
72125@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
72126 return proc_create_data(name, mode, parent, proc_fops, NULL);
72127 }
72128
72129+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
72130+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
72131+{
72132+#ifdef CONFIG_GRKERNSEC_PROC_USER
72133+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
72134+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72135+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
72136+#else
72137+ return proc_create_data(name, mode, parent, proc_fops, NULL);
72138+#endif
72139+}
72140+
72141+
72142 extern void proc_set_size(struct proc_dir_entry *, loff_t);
72143 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
72144 extern void *PDE_DATA(const struct inode *);
72145diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
72146index 34a1e10..03a6d03 100644
72147--- a/include/linux/proc_ns.h
72148+++ b/include/linux/proc_ns.h
72149@@ -14,7 +14,7 @@ struct proc_ns_operations {
72150 void (*put)(void *ns);
72151 int (*install)(struct nsproxy *nsproxy, void *ns);
72152 unsigned int (*inum)(void *ns);
72153-};
72154+} __do_const;
72155
72156 struct proc_ns {
72157 void *ns;
72158diff --git a/include/linux/random.h b/include/linux/random.h
72159index 3b9377d..61b506a 100644
72160--- a/include/linux/random.h
72161+++ b/include/linux/random.h
72162@@ -32,6 +32,11 @@ void prandom_seed(u32 seed);
72163 u32 prandom_u32_state(struct rnd_state *);
72164 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
72165
72166+static inline unsigned long pax_get_random_long(void)
72167+{
72168+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
72169+}
72170+
72171 /*
72172 * Handle minimum values for seeds
72173 */
72174diff --git a/include/linux/rculist.h b/include/linux/rculist.h
72175index f4b1001..8ddb2b6 100644
72176--- a/include/linux/rculist.h
72177+++ b/include/linux/rculist.h
72178@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
72179 struct list_head *prev, struct list_head *next);
72180 #endif
72181
72182+extern void __pax_list_add_rcu(struct list_head *new,
72183+ struct list_head *prev, struct list_head *next);
72184+
72185 /**
72186 * list_add_rcu - add a new entry to rcu-protected list
72187 * @new: new entry to be added
72188@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
72189 __list_add_rcu(new, head, head->next);
72190 }
72191
72192+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
72193+{
72194+ __pax_list_add_rcu(new, head, head->next);
72195+}
72196+
72197 /**
72198 * list_add_tail_rcu - add a new entry to rcu-protected list
72199 * @new: new entry to be added
72200@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
72201 __list_add_rcu(new, head->prev, head);
72202 }
72203
72204+static inline void pax_list_add_tail_rcu(struct list_head *new,
72205+ struct list_head *head)
72206+{
72207+ __pax_list_add_rcu(new, head->prev, head);
72208+}
72209+
72210 /**
72211 * list_del_rcu - deletes entry from list without re-initialization
72212 * @entry: the element to delete from the list.
72213@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
72214 entry->prev = LIST_POISON2;
72215 }
72216
72217+extern void pax_list_del_rcu(struct list_head *entry);
72218+
72219 /**
72220 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
72221 * @n: the element to delete from the hash list.
72222diff --git a/include/linux/reboot.h b/include/linux/reboot.h
72223index 23b3630..e1bc12b 100644
72224--- a/include/linux/reboot.h
72225+++ b/include/linux/reboot.h
72226@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
72227 * Architecture-specific implementations of sys_reboot commands.
72228 */
72229
72230-extern void machine_restart(char *cmd);
72231-extern void machine_halt(void);
72232-extern void machine_power_off(void);
72233+extern void machine_restart(char *cmd) __noreturn;
72234+extern void machine_halt(void) __noreturn;
72235+extern void machine_power_off(void) __noreturn;
72236
72237 extern void machine_shutdown(void);
72238 struct pt_regs;
72239@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
72240 */
72241
72242 extern void kernel_restart_prepare(char *cmd);
72243-extern void kernel_restart(char *cmd);
72244-extern void kernel_halt(void);
72245-extern void kernel_power_off(void);
72246+extern void kernel_restart(char *cmd) __noreturn;
72247+extern void kernel_halt(void) __noreturn;
72248+extern void kernel_power_off(void) __noreturn;
72249
72250 extern int C_A_D; /* for sysctl */
72251 void ctrl_alt_del(void);
72252@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
72253 * Emergency restart, callable from an interrupt handler.
72254 */
72255
72256-extern void emergency_restart(void);
72257+extern void emergency_restart(void) __noreturn;
72258 #include <asm/emergency-restart.h>
72259
72260 #endif /* _LINUX_REBOOT_H */
72261diff --git a/include/linux/regset.h b/include/linux/regset.h
72262index 8e0c9fe..ac4d221 100644
72263--- a/include/linux/regset.h
72264+++ b/include/linux/regset.h
72265@@ -161,7 +161,8 @@ struct user_regset {
72266 unsigned int align;
72267 unsigned int bias;
72268 unsigned int core_note_type;
72269-};
72270+} __do_const;
72271+typedef struct user_regset __no_const user_regset_no_const;
72272
72273 /**
72274 * struct user_regset_view - available regsets
72275diff --git a/include/linux/relay.h b/include/linux/relay.h
72276index d7c8359..818daf5 100644
72277--- a/include/linux/relay.h
72278+++ b/include/linux/relay.h
72279@@ -157,7 +157,7 @@ struct rchan_callbacks
72280 * The callback should return 0 if successful, negative if not.
72281 */
72282 int (*remove_buf_file)(struct dentry *dentry);
72283-};
72284+} __no_const;
72285
72286 /*
72287 * CONFIG_RELAY kernel API, kernel/relay.c
72288diff --git a/include/linux/rio.h b/include/linux/rio.h
72289index 18e0993..8ab5b21 100644
72290--- a/include/linux/rio.h
72291+++ b/include/linux/rio.h
72292@@ -345,7 +345,7 @@ struct rio_ops {
72293 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
72294 u64 rstart, u32 size, u32 flags);
72295 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
72296-};
72297+} __no_const;
72298
72299 #define RIO_RESOURCE_MEM 0x00000100
72300 #define RIO_RESOURCE_DOORBELL 0x00000200
72301diff --git a/include/linux/rmap.h b/include/linux/rmap.h
72302index 6dacb93..6174423 100644
72303--- a/include/linux/rmap.h
72304+++ b/include/linux/rmap.h
72305@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
72306 void anon_vma_init(void); /* create anon_vma_cachep */
72307 int anon_vma_prepare(struct vm_area_struct *);
72308 void unlink_anon_vmas(struct vm_area_struct *);
72309-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
72310-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
72311+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
72312+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
72313
72314 static inline void anon_vma_merge(struct vm_area_struct *vma,
72315 struct vm_area_struct *next)
72316diff --git a/include/linux/sched.h b/include/linux/sched.h
72317index 178a8d9..450bf11 100644
72318--- a/include/linux/sched.h
72319+++ b/include/linux/sched.h
72320@@ -62,6 +62,7 @@ struct bio_list;
72321 struct fs_struct;
72322 struct perf_event_context;
72323 struct blk_plug;
72324+struct linux_binprm;
72325
72326 /*
72327 * List of flags we want to share for kernel threads,
72328@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
72329 extern int in_sched_functions(unsigned long addr);
72330
72331 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
72332-extern signed long schedule_timeout(signed long timeout);
72333+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
72334 extern signed long schedule_timeout_interruptible(signed long timeout);
72335 extern signed long schedule_timeout_killable(signed long timeout);
72336 extern signed long schedule_timeout_uninterruptible(signed long timeout);
72337@@ -314,6 +315,19 @@ struct nsproxy;
72338 struct user_namespace;
72339
72340 #ifdef CONFIG_MMU
72341+
72342+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
72343+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
72344+#else
72345+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
72346+{
72347+ return 0;
72348+}
72349+#endif
72350+
72351+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
72352+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
72353+
72354 extern void arch_pick_mmap_layout(struct mm_struct *mm);
72355 extern unsigned long
72356 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
72357@@ -591,6 +605,17 @@ struct signal_struct {
72358 #ifdef CONFIG_TASKSTATS
72359 struct taskstats *stats;
72360 #endif
72361+
72362+#ifdef CONFIG_GRKERNSEC
72363+ u32 curr_ip;
72364+ u32 saved_ip;
72365+ u32 gr_saddr;
72366+ u32 gr_daddr;
72367+ u16 gr_sport;
72368+ u16 gr_dport;
72369+ u8 used_accept:1;
72370+#endif
72371+
72372 #ifdef CONFIG_AUDIT
72373 unsigned audit_tty;
72374 unsigned audit_tty_log_passwd;
72375@@ -671,6 +696,14 @@ struct user_struct {
72376 struct key *session_keyring; /* UID's default session keyring */
72377 #endif
72378
72379+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
72380+ unsigned char kernel_banned;
72381+#endif
72382+#ifdef CONFIG_GRKERNSEC_BRUTE
72383+ unsigned char suid_banned;
72384+ unsigned long suid_ban_expires;
72385+#endif
72386+
72387 /* Hash table maintenance information */
72388 struct hlist_node uidhash_node;
72389 kuid_t uid;
72390@@ -1158,8 +1191,8 @@ struct task_struct {
72391 struct list_head thread_group;
72392
72393 struct completion *vfork_done; /* for vfork() */
72394- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
72395- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
72396+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
72397+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
72398
72399 cputime_t utime, stime, utimescaled, stimescaled;
72400 cputime_t gtime;
72401@@ -1184,11 +1217,6 @@ struct task_struct {
72402 struct task_cputime cputime_expires;
72403 struct list_head cpu_timers[3];
72404
72405-/* process credentials */
72406- const struct cred __rcu *real_cred; /* objective and real subjective task
72407- * credentials (COW) */
72408- const struct cred __rcu *cred; /* effective (overridable) subjective task
72409- * credentials (COW) */
72410 char comm[TASK_COMM_LEN]; /* executable name excluding path
72411 - access with [gs]et_task_comm (which lock
72412 it with task_lock())
72413@@ -1205,6 +1233,10 @@ struct task_struct {
72414 #endif
72415 /* CPU-specific state of this task */
72416 struct thread_struct thread;
72417+/* thread_info moved to task_struct */
72418+#ifdef CONFIG_X86
72419+ struct thread_info tinfo;
72420+#endif
72421 /* filesystem information */
72422 struct fs_struct *fs;
72423 /* open file information */
72424@@ -1278,6 +1310,10 @@ struct task_struct {
72425 gfp_t lockdep_reclaim_gfp;
72426 #endif
72427
72428+/* process credentials */
72429+ const struct cred __rcu *real_cred; /* objective and real subjective task
72430+ * credentials (COW) */
72431+
72432 /* journalling filesystem info */
72433 void *journal_info;
72434
72435@@ -1316,6 +1352,10 @@ struct task_struct {
72436 /* cg_list protected by css_set_lock and tsk->alloc_lock */
72437 struct list_head cg_list;
72438 #endif
72439+
72440+ const struct cred __rcu *cred; /* effective (overridable) subjective task
72441+ * credentials (COW) */
72442+
72443 #ifdef CONFIG_FUTEX
72444 struct robust_list_head __user *robust_list;
72445 #ifdef CONFIG_COMPAT
72446@@ -1416,8 +1456,76 @@ struct task_struct {
72447 unsigned int sequential_io;
72448 unsigned int sequential_io_avg;
72449 #endif
72450+
72451+#ifdef CONFIG_GRKERNSEC
72452+ /* grsecurity */
72453+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72454+ u64 exec_id;
72455+#endif
72456+#ifdef CONFIG_GRKERNSEC_SETXID
72457+ const struct cred *delayed_cred;
72458+#endif
72459+ struct dentry *gr_chroot_dentry;
72460+ struct acl_subject_label *acl;
72461+ struct acl_role_label *role;
72462+ struct file *exec_file;
72463+ unsigned long brute_expires;
72464+ u16 acl_role_id;
72465+ /* is this the task that authenticated to the special role */
72466+ u8 acl_sp_role;
72467+ u8 is_writable;
72468+ u8 brute;
72469+ u8 gr_is_chrooted;
72470+#endif
72471+
72472 };
72473
72474+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
72475+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
72476+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
72477+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
72478+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
72479+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
72480+
72481+#ifdef CONFIG_PAX_SOFTMODE
72482+extern int pax_softmode;
72483+#endif
72484+
72485+extern int pax_check_flags(unsigned long *);
72486+
72487+/* if tsk != current then task_lock must be held on it */
72488+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
72489+static inline unsigned long pax_get_flags(struct task_struct *tsk)
72490+{
72491+ if (likely(tsk->mm))
72492+ return tsk->mm->pax_flags;
72493+ else
72494+ return 0UL;
72495+}
72496+
72497+/* if tsk != current then task_lock must be held on it */
72498+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
72499+{
72500+ if (likely(tsk->mm)) {
72501+ tsk->mm->pax_flags = flags;
72502+ return 0;
72503+ }
72504+ return -EINVAL;
72505+}
72506+#endif
72507+
72508+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
72509+extern void pax_set_initial_flags(struct linux_binprm *bprm);
72510+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
72511+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
72512+#endif
72513+
72514+struct path;
72515+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
72516+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
72517+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
72518+extern void pax_report_refcount_overflow(struct pt_regs *regs);
72519+
72520 /* Future-safe accessor for struct task_struct's cpus_allowed. */
72521 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
72522
72523@@ -1476,7 +1584,7 @@ struct pid_namespace;
72524 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
72525 struct pid_namespace *ns);
72526
72527-static inline pid_t task_pid_nr(struct task_struct *tsk)
72528+static inline pid_t task_pid_nr(const struct task_struct *tsk)
72529 {
72530 return tsk->pid;
72531 }
72532@@ -1919,7 +2027,9 @@ void yield(void);
72533 extern struct exec_domain default_exec_domain;
72534
72535 union thread_union {
72536+#ifndef CONFIG_X86
72537 struct thread_info thread_info;
72538+#endif
72539 unsigned long stack[THREAD_SIZE/sizeof(long)];
72540 };
72541
72542@@ -1952,6 +2062,7 @@ extern struct pid_namespace init_pid_ns;
72543 */
72544
72545 extern struct task_struct *find_task_by_vpid(pid_t nr);
72546+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
72547 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
72548 struct pid_namespace *ns);
72549
72550@@ -2118,7 +2229,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
72551 extern void exit_itimers(struct signal_struct *);
72552 extern void flush_itimer_signals(void);
72553
72554-extern void do_group_exit(int);
72555+extern __noreturn void do_group_exit(int);
72556
72557 extern int allow_signal(int);
72558 extern int disallow_signal(int);
72559@@ -2309,9 +2420,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
72560
72561 #endif
72562
72563-static inline int object_is_on_stack(void *obj)
72564+static inline int object_starts_on_stack(void *obj)
72565 {
72566- void *stack = task_stack_page(current);
72567+ const void *stack = task_stack_page(current);
72568
72569 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
72570 }
72571diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
72572index bf8086b..962b035 100644
72573--- a/include/linux/sched/sysctl.h
72574+++ b/include/linux/sched/sysctl.h
72575@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
72576 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
72577
72578 extern int sysctl_max_map_count;
72579+extern unsigned long sysctl_heap_stack_gap;
72580
72581 extern unsigned int sysctl_sched_latency;
72582 extern unsigned int sysctl_sched_min_granularity;
72583diff --git a/include/linux/security.h b/include/linux/security.h
72584index 4686491..2bd210e 100644
72585--- a/include/linux/security.h
72586+++ b/include/linux/security.h
72587@@ -26,6 +26,7 @@
72588 #include <linux/capability.h>
72589 #include <linux/slab.h>
72590 #include <linux/err.h>
72591+#include <linux/grsecurity.h>
72592
72593 struct linux_binprm;
72594 struct cred;
72595diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
72596index 2da29ac..aac448ec 100644
72597--- a/include/linux/seq_file.h
72598+++ b/include/linux/seq_file.h
72599@@ -26,6 +26,9 @@ struct seq_file {
72600 struct mutex lock;
72601 const struct seq_operations *op;
72602 int poll_event;
72603+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72604+ u64 exec_id;
72605+#endif
72606 #ifdef CONFIG_USER_NS
72607 struct user_namespace *user_ns;
72608 #endif
72609@@ -38,6 +41,7 @@ struct seq_operations {
72610 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
72611 int (*show) (struct seq_file *m, void *v);
72612 };
72613+typedef struct seq_operations __no_const seq_operations_no_const;
72614
72615 #define SEQ_SKIP 1
72616
72617diff --git a/include/linux/shm.h b/include/linux/shm.h
72618index 429c199..4d42e38 100644
72619--- a/include/linux/shm.h
72620+++ b/include/linux/shm.h
72621@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
72622
72623 /* The task created the shm object. NULL if the task is dead. */
72624 struct task_struct *shm_creator;
72625+#ifdef CONFIG_GRKERNSEC
72626+ time_t shm_createtime;
72627+ pid_t shm_lapid;
72628+#endif
72629 };
72630
72631 /* shm_mode upper byte flags */
72632diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
72633index dec1748..112c1f9 100644
72634--- a/include/linux/skbuff.h
72635+++ b/include/linux/skbuff.h
72636@@ -640,7 +640,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
72637 extern struct sk_buff *__alloc_skb(unsigned int size,
72638 gfp_t priority, int flags, int node);
72639 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
72640-static inline struct sk_buff *alloc_skb(unsigned int size,
72641+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
72642 gfp_t priority)
72643 {
72644 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
72645@@ -756,7 +756,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
72646 */
72647 static inline int skb_queue_empty(const struct sk_buff_head *list)
72648 {
72649- return list->next == (struct sk_buff *)list;
72650+ return list->next == (const struct sk_buff *)list;
72651 }
72652
72653 /**
72654@@ -769,7 +769,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
72655 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
72656 const struct sk_buff *skb)
72657 {
72658- return skb->next == (struct sk_buff *)list;
72659+ return skb->next == (const struct sk_buff *)list;
72660 }
72661
72662 /**
72663@@ -782,7 +782,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
72664 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
72665 const struct sk_buff *skb)
72666 {
72667- return skb->prev == (struct sk_buff *)list;
72668+ return skb->prev == (const struct sk_buff *)list;
72669 }
72670
72671 /**
72672@@ -1848,7 +1848,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
72673 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
72674 */
72675 #ifndef NET_SKB_PAD
72676-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
72677+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
72678 #endif
72679
72680 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
72681@@ -2443,7 +2443,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
72682 int noblock, int *err);
72683 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
72684 struct poll_table_struct *wait);
72685-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
72686+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
72687 int offset, struct iovec *to,
72688 int size);
72689 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
72690@@ -2733,6 +2733,9 @@ static inline void nf_reset(struct sk_buff *skb)
72691 nf_bridge_put(skb->nf_bridge);
72692 skb->nf_bridge = NULL;
72693 #endif
72694+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
72695+ skb->nf_trace = 0;
72696+#endif
72697 }
72698
72699 static inline void nf_reset_trace(struct sk_buff *skb)
72700diff --git a/include/linux/slab.h b/include/linux/slab.h
72701index 0c62175..f016ac1 100644
72702--- a/include/linux/slab.h
72703+++ b/include/linux/slab.h
72704@@ -12,15 +12,29 @@
72705 #include <linux/gfp.h>
72706 #include <linux/types.h>
72707 #include <linux/workqueue.h>
72708-
72709+#include <linux/err.h>
72710
72711 /*
72712 * Flags to pass to kmem_cache_create().
72713 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
72714 */
72715 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
72716+
72717+#ifdef CONFIG_PAX_USERCOPY_SLABS
72718+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
72719+#else
72720+#define SLAB_USERCOPY 0x00000000UL
72721+#endif
72722+
72723 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
72724 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
72725+
72726+#ifdef CONFIG_PAX_MEMORY_SANITIZE
72727+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
72728+#else
72729+#define SLAB_NO_SANITIZE 0x00000000UL
72730+#endif
72731+
72732 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
72733 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
72734 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
72735@@ -89,10 +103,13 @@
72736 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
72737 * Both make kfree a no-op.
72738 */
72739-#define ZERO_SIZE_PTR ((void *)16)
72740+#define ZERO_SIZE_PTR \
72741+({ \
72742+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
72743+ (void *)(-MAX_ERRNO-1L); \
72744+})
72745
72746-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
72747- (unsigned long)ZERO_SIZE_PTR)
72748+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
72749
72750
72751 struct mem_cgroup;
72752@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
72753 void kfree(const void *);
72754 void kzfree(const void *);
72755 size_t ksize(const void *);
72756+const char *check_heap_object(const void *ptr, unsigned long n);
72757+bool is_usercopy_object(const void *ptr);
72758
72759 /*
72760 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
72761@@ -164,7 +183,7 @@ struct kmem_cache {
72762 unsigned int align; /* Alignment as calculated */
72763 unsigned long flags; /* Active flags on the slab */
72764 const char *name; /* Slab name for sysfs */
72765- int refcount; /* Use counter */
72766+ atomic_t refcount; /* Use counter */
72767 void (*ctor)(void *); /* Called on object slot creation */
72768 struct list_head list; /* List of all slab caches on the system */
72769 };
72770@@ -226,6 +245,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
72771 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
72772 #endif
72773
72774+#ifdef CONFIG_PAX_USERCOPY_SLABS
72775+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
72776+#endif
72777+
72778 /*
72779 * Figure out which kmalloc slab an allocation of a certain size
72780 * belongs to.
72781@@ -234,7 +257,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
72782 * 2 = 120 .. 192 bytes
72783 * n = 2^(n-1) .. 2^n -1
72784 */
72785-static __always_inline int kmalloc_index(size_t size)
72786+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
72787 {
72788 if (!size)
72789 return 0;
72790@@ -406,6 +429,7 @@ void print_slabinfo_header(struct seq_file *m);
72791 * for general use, and so are not documented here. For a full list of
72792 * potential flags, always refer to linux/gfp.h.
72793 */
72794+
72795 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
72796 {
72797 if (size != 0 && n > SIZE_MAX / size)
72798@@ -465,7 +489,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
72799 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72800 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72801 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72802-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72803+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
72804 #define kmalloc_track_caller(size, flags) \
72805 __kmalloc_track_caller(size, flags, _RET_IP_)
72806 #else
72807@@ -485,7 +509,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72808 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72809 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72810 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72811-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
72812+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
72813 #define kmalloc_node_track_caller(size, flags, node) \
72814 __kmalloc_node_track_caller(size, flags, node, \
72815 _RET_IP_)
72816diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
72817index cd40158..4e2f7af 100644
72818--- a/include/linux/slab_def.h
72819+++ b/include/linux/slab_def.h
72820@@ -50,7 +50,7 @@ struct kmem_cache {
72821 /* 4) cache creation/removal */
72822 const char *name;
72823 struct list_head list;
72824- int refcount;
72825+ atomic_t refcount;
72826 int object_size;
72827 int align;
72828
72829@@ -66,10 +66,14 @@ struct kmem_cache {
72830 unsigned long node_allocs;
72831 unsigned long node_frees;
72832 unsigned long node_overflow;
72833- atomic_t allochit;
72834- atomic_t allocmiss;
72835- atomic_t freehit;
72836- atomic_t freemiss;
72837+ atomic_unchecked_t allochit;
72838+ atomic_unchecked_t allocmiss;
72839+ atomic_unchecked_t freehit;
72840+ atomic_unchecked_t freemiss;
72841+#ifdef CONFIG_PAX_MEMORY_SANITIZE
72842+ atomic_unchecked_t sanitized;
72843+ atomic_unchecked_t not_sanitized;
72844+#endif
72845
72846 /*
72847 * If debugging is enabled, then the allocator can add additional
72848@@ -103,7 +107,7 @@ struct kmem_cache {
72849 };
72850
72851 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72852-void *__kmalloc(size_t size, gfp_t flags);
72853+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
72854
72855 #ifdef CONFIG_TRACING
72856 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
72857@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72858 cachep = kmalloc_dma_caches[i];
72859 else
72860 #endif
72861+
72862+#ifdef CONFIG_PAX_USERCOPY_SLABS
72863+ if (flags & GFP_USERCOPY)
72864+ cachep = kmalloc_usercopy_caches[i];
72865+ else
72866+#endif
72867+
72868 cachep = kmalloc_caches[i];
72869
72870 ret = kmem_cache_alloc_trace(cachep, flags, size);
72871@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72872 }
72873
72874 #ifdef CONFIG_NUMA
72875-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
72876+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72877 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72878
72879 #ifdef CONFIG_TRACING
72880@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72881 cachep = kmalloc_dma_caches[i];
72882 else
72883 #endif
72884+
72885+#ifdef CONFIG_PAX_USERCOPY_SLABS
72886+ if (flags & GFP_USERCOPY)
72887+ cachep = kmalloc_usercopy_caches[i];
72888+ else
72889+#endif
72890+
72891 cachep = kmalloc_caches[i];
72892
72893 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
72894diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
72895index f28e14a..7831211 100644
72896--- a/include/linux/slob_def.h
72897+++ b/include/linux/slob_def.h
72898@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
72899 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
72900 }
72901
72902-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72903+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72904
72905 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72906 {
72907@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72908 return __kmalloc_node(size, flags, NUMA_NO_NODE);
72909 }
72910
72911-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
72912+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
72913 {
72914 return kmalloc(size, flags);
72915 }
72916diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
72917index 027276f..092bfe8 100644
72918--- a/include/linux/slub_def.h
72919+++ b/include/linux/slub_def.h
72920@@ -80,7 +80,7 @@ struct kmem_cache {
72921 struct kmem_cache_order_objects max;
72922 struct kmem_cache_order_objects min;
72923 gfp_t allocflags; /* gfp flags to use on each alloc */
72924- int refcount; /* Refcount for slab cache destroy */
72925+ atomic_t refcount; /* Refcount for slab cache destroy */
72926 void (*ctor)(void *);
72927 int inuse; /* Offset to metadata */
72928 int align; /* Alignment */
72929@@ -105,7 +105,7 @@ struct kmem_cache {
72930 };
72931
72932 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72933-void *__kmalloc(size_t size, gfp_t flags);
72934+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
72935
72936 static __always_inline void *
72937 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
72938@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
72939 }
72940 #endif
72941
72942-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
72943+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
72944 {
72945 unsigned int order = get_order(size);
72946 return kmalloc_order_trace(size, flags, order);
72947@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72948 }
72949
72950 #ifdef CONFIG_NUMA
72951-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72952+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72953 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72954
72955 #ifdef CONFIG_TRACING
72956diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
72957index 54f91d3..be2c379 100644
72958--- a/include/linux/sock_diag.h
72959+++ b/include/linux/sock_diag.h
72960@@ -11,7 +11,7 @@ struct sock;
72961 struct sock_diag_handler {
72962 __u8 family;
72963 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
72964-};
72965+} __do_const;
72966
72967 int sock_diag_register(const struct sock_diag_handler *h);
72968 void sock_diag_unregister(const struct sock_diag_handler *h);
72969diff --git a/include/linux/sonet.h b/include/linux/sonet.h
72970index 680f9a3..f13aeb0 100644
72971--- a/include/linux/sonet.h
72972+++ b/include/linux/sonet.h
72973@@ -7,7 +7,7 @@
72974 #include <uapi/linux/sonet.h>
72975
72976 struct k_sonet_stats {
72977-#define __HANDLE_ITEM(i) atomic_t i
72978+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72979 __SONET_ITEMS
72980 #undef __HANDLE_ITEM
72981 };
72982diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
72983index 07d8e53..dc934c9 100644
72984--- a/include/linux/sunrpc/addr.h
72985+++ b/include/linux/sunrpc/addr.h
72986@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72987 {
72988 switch (sap->sa_family) {
72989 case AF_INET:
72990- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72991+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72992 case AF_INET6:
72993- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72994+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72995 }
72996 return 0;
72997 }
72998@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72999 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
73000 const struct sockaddr *src)
73001 {
73002- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
73003+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
73004 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
73005
73006 dsin->sin_family = ssin->sin_family;
73007@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
73008 if (sa->sa_family != AF_INET6)
73009 return 0;
73010
73011- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
73012+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
73013 }
73014
73015 #endif /* _LINUX_SUNRPC_ADDR_H */
73016diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
73017index bfe11be..12bc8c4 100644
73018--- a/include/linux/sunrpc/clnt.h
73019+++ b/include/linux/sunrpc/clnt.h
73020@@ -96,7 +96,7 @@ struct rpc_procinfo {
73021 unsigned int p_timer; /* Which RTT timer to use */
73022 u32 p_statidx; /* Which procedure to account */
73023 const char * p_name; /* name of procedure */
73024-};
73025+} __do_const;
73026
73027 #ifdef __KERNEL__
73028
73029diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
73030index 1f0216b..6a4fa50 100644
73031--- a/include/linux/sunrpc/svc.h
73032+++ b/include/linux/sunrpc/svc.h
73033@@ -411,7 +411,7 @@ struct svc_procedure {
73034 unsigned int pc_count; /* call count */
73035 unsigned int pc_cachetype; /* cache info (NFS) */
73036 unsigned int pc_xdrressize; /* maximum size of XDR reply */
73037-};
73038+} __do_const;
73039
73040 /*
73041 * Function prototypes.
73042diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
73043index 0b8e3e6..33e0a01 100644
73044--- a/include/linux/sunrpc/svc_rdma.h
73045+++ b/include/linux/sunrpc/svc_rdma.h
73046@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
73047 extern unsigned int svcrdma_max_requests;
73048 extern unsigned int svcrdma_max_req_size;
73049
73050-extern atomic_t rdma_stat_recv;
73051-extern atomic_t rdma_stat_read;
73052-extern atomic_t rdma_stat_write;
73053-extern atomic_t rdma_stat_sq_starve;
73054-extern atomic_t rdma_stat_rq_starve;
73055-extern atomic_t rdma_stat_rq_poll;
73056-extern atomic_t rdma_stat_rq_prod;
73057-extern atomic_t rdma_stat_sq_poll;
73058-extern atomic_t rdma_stat_sq_prod;
73059+extern atomic_unchecked_t rdma_stat_recv;
73060+extern atomic_unchecked_t rdma_stat_read;
73061+extern atomic_unchecked_t rdma_stat_write;
73062+extern atomic_unchecked_t rdma_stat_sq_starve;
73063+extern atomic_unchecked_t rdma_stat_rq_starve;
73064+extern atomic_unchecked_t rdma_stat_rq_poll;
73065+extern atomic_unchecked_t rdma_stat_rq_prod;
73066+extern atomic_unchecked_t rdma_stat_sq_poll;
73067+extern atomic_unchecked_t rdma_stat_sq_prod;
73068
73069 #define RPCRDMA_VERSION 1
73070
73071diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
73072index ff374ab..7fd2ecb 100644
73073--- a/include/linux/sunrpc/svcauth.h
73074+++ b/include/linux/sunrpc/svcauth.h
73075@@ -109,7 +109,7 @@ struct auth_ops {
73076 int (*release)(struct svc_rqst *rq);
73077 void (*domain_release)(struct auth_domain *);
73078 int (*set_client)(struct svc_rqst *rq);
73079-};
73080+} __do_const;
73081
73082 #define SVC_GARBAGE 1
73083 #define SVC_SYSERR 2
73084diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
73085index a5ffd32..0935dea 100644
73086--- a/include/linux/swiotlb.h
73087+++ b/include/linux/swiotlb.h
73088@@ -60,7 +60,8 @@ extern void
73089
73090 extern void
73091 swiotlb_free_coherent(struct device *hwdev, size_t size,
73092- void *vaddr, dma_addr_t dma_handle);
73093+ void *vaddr, dma_addr_t dma_handle,
73094+ struct dma_attrs *attrs);
73095
73096 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
73097 unsigned long offset, size_t size,
73098diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
73099index 4147d70..d356a10 100644
73100--- a/include/linux/syscalls.h
73101+++ b/include/linux/syscalls.h
73102@@ -97,8 +97,12 @@ struct sigaltstack;
73103 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
73104
73105 #define __SC_DECL(t, a) t a
73106-#define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
73107-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
73108+#define __TYPE_IS_SL(t) (__same_type((t)0, 0L))
73109+#define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
73110+#define __TYPE_IS_SLL(t) (__same_type((t)0, 0LL))
73111+#define __TYPE_IS_ULL(t) (__same_type((t)0, 0ULL))
73112+#define __TYPE_IS_LL(t) (__TYPE_IS_SLL(t) || __TYPE_IS_ULL(t))
73113+#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), __builtin_choose_expr(__TYPE_IS_ULL(t), 0ULL, 0LL), __builtin_choose_expr(__TYPE_IS_UL(t), 0UL, 0L))) a
73114 #define __SC_CAST(t, a) (t) a
73115 #define __SC_ARGS(t, a) a
73116 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
73117@@ -362,11 +366,11 @@ asmlinkage long sys_sync(void);
73118 asmlinkage long sys_fsync(unsigned int fd);
73119 asmlinkage long sys_fdatasync(unsigned int fd);
73120 asmlinkage long sys_bdflush(int func, long data);
73121-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
73122- char __user *type, unsigned long flags,
73123+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
73124+ const char __user *type, unsigned long flags,
73125 void __user *data);
73126-asmlinkage long sys_umount(char __user *name, int flags);
73127-asmlinkage long sys_oldumount(char __user *name);
73128+asmlinkage long sys_umount(const char __user *name, int flags);
73129+asmlinkage long sys_oldumount(const char __user *name);
73130 asmlinkage long sys_truncate(const char __user *path, long length);
73131 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
73132 asmlinkage long sys_stat(const char __user *filename,
73133@@ -578,7 +582,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
73134 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
73135 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
73136 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
73137- struct sockaddr __user *, int);
73138+ struct sockaddr __user *, int) __intentional_overflow(0);
73139 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
73140 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
73141 unsigned int vlen, unsigned flags);
73142diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
73143index 27b3b0b..e093dd9 100644
73144--- a/include/linux/syscore_ops.h
73145+++ b/include/linux/syscore_ops.h
73146@@ -16,7 +16,7 @@ struct syscore_ops {
73147 int (*suspend)(void);
73148 void (*resume)(void);
73149 void (*shutdown)(void);
73150-};
73151+} __do_const;
73152
73153 extern void register_syscore_ops(struct syscore_ops *ops);
73154 extern void unregister_syscore_ops(struct syscore_ops *ops);
73155diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
73156index 14a8ff2..af52bad 100644
73157--- a/include/linux/sysctl.h
73158+++ b/include/linux/sysctl.h
73159@@ -34,13 +34,13 @@ struct ctl_table_root;
73160 struct ctl_table_header;
73161 struct ctl_dir;
73162
73163-typedef struct ctl_table ctl_table;
73164-
73165 typedef int proc_handler (struct ctl_table *ctl, int write,
73166 void __user *buffer, size_t *lenp, loff_t *ppos);
73167
73168 extern int proc_dostring(struct ctl_table *, int,
73169 void __user *, size_t *, loff_t *);
73170+extern int proc_dostring_modpriv(struct ctl_table *, int,
73171+ void __user *, size_t *, loff_t *);
73172 extern int proc_dointvec(struct ctl_table *, int,
73173 void __user *, size_t *, loff_t *);
73174 extern int proc_dointvec_minmax(struct ctl_table *, int,
73175@@ -115,7 +115,9 @@ struct ctl_table
73176 struct ctl_table_poll *poll;
73177 void *extra1;
73178 void *extra2;
73179-};
73180+} __do_const;
73181+typedef struct ctl_table __no_const ctl_table_no_const;
73182+typedef struct ctl_table ctl_table;
73183
73184 struct ctl_node {
73185 struct rb_node node;
73186diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
73187index e2cee22..3ddb921 100644
73188--- a/include/linux/sysfs.h
73189+++ b/include/linux/sysfs.h
73190@@ -31,7 +31,8 @@ struct attribute {
73191 struct lock_class_key *key;
73192 struct lock_class_key skey;
73193 #endif
73194-};
73195+} __do_const;
73196+typedef struct attribute __no_const attribute_no_const;
73197
73198 /**
73199 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
73200@@ -59,8 +60,8 @@ struct attribute_group {
73201 umode_t (*is_visible)(struct kobject *,
73202 struct attribute *, int);
73203 struct attribute **attrs;
73204-};
73205-
73206+} __do_const;
73207+typedef struct attribute_group __no_const attribute_group_no_const;
73208
73209
73210 /**
73211@@ -107,7 +108,8 @@ struct bin_attribute {
73212 char *, loff_t, size_t);
73213 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
73214 struct vm_area_struct *vma);
73215-};
73216+} __do_const;
73217+typedef struct bin_attribute __no_const bin_attribute_no_const;
73218
73219 /**
73220 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
73221diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
73222index 7faf933..9b85a0c 100644
73223--- a/include/linux/sysrq.h
73224+++ b/include/linux/sysrq.h
73225@@ -16,6 +16,7 @@
73226
73227 #include <linux/errno.h>
73228 #include <linux/types.h>
73229+#include <linux/compiler.h>
73230
73231 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
73232 #define SYSRQ_DEFAULT_ENABLE 1
73233@@ -36,7 +37,7 @@ struct sysrq_key_op {
73234 char *help_msg;
73235 char *action_msg;
73236 int enable_mask;
73237-};
73238+} __do_const;
73239
73240 #ifdef CONFIG_MAGIC_SYSRQ
73241
73242diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
73243index e7e0473..7989295 100644
73244--- a/include/linux/thread_info.h
73245+++ b/include/linux/thread_info.h
73246@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
73247 #error "no set_restore_sigmask() provided and default one won't work"
73248 #endif
73249
73250+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
73251+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
73252+{
73253+#ifndef CONFIG_PAX_USERCOPY_DEBUG
73254+ if (!__builtin_constant_p(n))
73255+#endif
73256+ __check_object_size(ptr, n, to_user);
73257+}
73258+
73259 #endif /* __KERNEL__ */
73260
73261 #endif /* _LINUX_THREAD_INFO_H */
73262diff --git a/include/linux/tty.h b/include/linux/tty.h
73263index 8780bd2..d1ae08b 100644
73264--- a/include/linux/tty.h
73265+++ b/include/linux/tty.h
73266@@ -194,7 +194,7 @@ struct tty_port {
73267 const struct tty_port_operations *ops; /* Port operations */
73268 spinlock_t lock; /* Lock protecting tty field */
73269 int blocked_open; /* Waiting to open */
73270- int count; /* Usage count */
73271+ atomic_t count; /* Usage count */
73272 wait_queue_head_t open_wait; /* Open waiters */
73273 wait_queue_head_t close_wait; /* Close waiters */
73274 wait_queue_head_t delta_msr_wait; /* Modem status change */
73275@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
73276 struct tty_struct *tty, struct file *filp);
73277 static inline int tty_port_users(struct tty_port *port)
73278 {
73279- return port->count + port->blocked_open;
73280+ return atomic_read(&port->count) + port->blocked_open;
73281 }
73282
73283 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
73284diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
73285index 756a609..b302dd6 100644
73286--- a/include/linux/tty_driver.h
73287+++ b/include/linux/tty_driver.h
73288@@ -285,7 +285,7 @@ struct tty_operations {
73289 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
73290 #endif
73291 const struct file_operations *proc_fops;
73292-};
73293+} __do_const;
73294
73295 struct tty_driver {
73296 int magic; /* magic number for this structure */
73297diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
73298index 58390c7..95e214c 100644
73299--- a/include/linux/tty_ldisc.h
73300+++ b/include/linux/tty_ldisc.h
73301@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
73302
73303 struct module *owner;
73304
73305- int refcount;
73306+ atomic_t refcount;
73307 };
73308
73309 struct tty_ldisc {
73310diff --git a/include/linux/types.h b/include/linux/types.h
73311index 4d118ba..c3ee9bf 100644
73312--- a/include/linux/types.h
73313+++ b/include/linux/types.h
73314@@ -176,10 +176,26 @@ typedef struct {
73315 int counter;
73316 } atomic_t;
73317
73318+#ifdef CONFIG_PAX_REFCOUNT
73319+typedef struct {
73320+ int counter;
73321+} atomic_unchecked_t;
73322+#else
73323+typedef atomic_t atomic_unchecked_t;
73324+#endif
73325+
73326 #ifdef CONFIG_64BIT
73327 typedef struct {
73328 long counter;
73329 } atomic64_t;
73330+
73331+#ifdef CONFIG_PAX_REFCOUNT
73332+typedef struct {
73333+ long counter;
73334+} atomic64_unchecked_t;
73335+#else
73336+typedef atomic64_t atomic64_unchecked_t;
73337+#endif
73338 #endif
73339
73340 struct list_head {
73341diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
73342index 5ca0951..ab496a5 100644
73343--- a/include/linux/uaccess.h
73344+++ b/include/linux/uaccess.h
73345@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
73346 long ret; \
73347 mm_segment_t old_fs = get_fs(); \
73348 \
73349- set_fs(KERNEL_DS); \
73350 pagefault_disable(); \
73351- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
73352- pagefault_enable(); \
73353+ set_fs(KERNEL_DS); \
73354+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
73355 set_fs(old_fs); \
73356+ pagefault_enable(); \
73357 ret; \
73358 })
73359
73360diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
73361index 8e522cbc..aa8572d 100644
73362--- a/include/linux/uidgid.h
73363+++ b/include/linux/uidgid.h
73364@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
73365
73366 #endif /* CONFIG_USER_NS */
73367
73368+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
73369+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
73370+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
73371+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
73372+
73373 #endif /* _LINUX_UIDGID_H */
73374diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
73375index 99c1b4d..562e6f3 100644
73376--- a/include/linux/unaligned/access_ok.h
73377+++ b/include/linux/unaligned/access_ok.h
73378@@ -4,34 +4,34 @@
73379 #include <linux/kernel.h>
73380 #include <asm/byteorder.h>
73381
73382-static inline u16 get_unaligned_le16(const void *p)
73383+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
73384 {
73385- return le16_to_cpup((__le16 *)p);
73386+ return le16_to_cpup((const __le16 *)p);
73387 }
73388
73389-static inline u32 get_unaligned_le32(const void *p)
73390+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
73391 {
73392- return le32_to_cpup((__le32 *)p);
73393+ return le32_to_cpup((const __le32 *)p);
73394 }
73395
73396-static inline u64 get_unaligned_le64(const void *p)
73397+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
73398 {
73399- return le64_to_cpup((__le64 *)p);
73400+ return le64_to_cpup((const __le64 *)p);
73401 }
73402
73403-static inline u16 get_unaligned_be16(const void *p)
73404+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
73405 {
73406- return be16_to_cpup((__be16 *)p);
73407+ return be16_to_cpup((const __be16 *)p);
73408 }
73409
73410-static inline u32 get_unaligned_be32(const void *p)
73411+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
73412 {
73413- return be32_to_cpup((__be32 *)p);
73414+ return be32_to_cpup((const __be32 *)p);
73415 }
73416
73417-static inline u64 get_unaligned_be64(const void *p)
73418+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
73419 {
73420- return be64_to_cpup((__be64 *)p);
73421+ return be64_to_cpup((const __be64 *)p);
73422 }
73423
73424 static inline void put_unaligned_le16(u16 val, void *p)
73425diff --git a/include/linux/usb.h b/include/linux/usb.h
73426index a0bee5a..5533a52 100644
73427--- a/include/linux/usb.h
73428+++ b/include/linux/usb.h
73429@@ -552,7 +552,7 @@ struct usb_device {
73430 int maxchild;
73431
73432 u32 quirks;
73433- atomic_t urbnum;
73434+ atomic_unchecked_t urbnum;
73435
73436 unsigned long active_duration;
73437
73438@@ -1607,7 +1607,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
73439
73440 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
73441 __u8 request, __u8 requesttype, __u16 value, __u16 index,
73442- void *data, __u16 size, int timeout);
73443+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
73444 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
73445 void *data, int len, int *actual_length, int timeout);
73446 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
73447diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
73448index e452ba6..78f8e80 100644
73449--- a/include/linux/usb/renesas_usbhs.h
73450+++ b/include/linux/usb/renesas_usbhs.h
73451@@ -39,7 +39,7 @@ enum {
73452 */
73453 struct renesas_usbhs_driver_callback {
73454 int (*notify_hotplug)(struct platform_device *pdev);
73455-};
73456+} __no_const;
73457
73458 /*
73459 * callback functions for platform
73460diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
73461index 6f8fbcf..8259001 100644
73462--- a/include/linux/vermagic.h
73463+++ b/include/linux/vermagic.h
73464@@ -25,9 +25,35 @@
73465 #define MODULE_ARCH_VERMAGIC ""
73466 #endif
73467
73468+#ifdef CONFIG_PAX_REFCOUNT
73469+#define MODULE_PAX_REFCOUNT "REFCOUNT "
73470+#else
73471+#define MODULE_PAX_REFCOUNT ""
73472+#endif
73473+
73474+#ifdef CONSTIFY_PLUGIN
73475+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
73476+#else
73477+#define MODULE_CONSTIFY_PLUGIN ""
73478+#endif
73479+
73480+#ifdef STACKLEAK_PLUGIN
73481+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
73482+#else
73483+#define MODULE_STACKLEAK_PLUGIN ""
73484+#endif
73485+
73486+#ifdef CONFIG_GRKERNSEC
73487+#define MODULE_GRSEC "GRSEC "
73488+#else
73489+#define MODULE_GRSEC ""
73490+#endif
73491+
73492 #define VERMAGIC_STRING \
73493 UTS_RELEASE " " \
73494 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
73495 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
73496- MODULE_ARCH_VERMAGIC
73497+ MODULE_ARCH_VERMAGIC \
73498+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
73499+ MODULE_GRSEC
73500
73501diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
73502index 7d5773a..541c01c 100644
73503--- a/include/linux/vmalloc.h
73504+++ b/include/linux/vmalloc.h
73505@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
73506 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
73507 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
73508 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
73509+
73510+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
73511+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
73512+#endif
73513+
73514 /* bits [20..32] reserved for arch specific ioremap internals */
73515
73516 /*
73517@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
73518 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
73519 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
73520 unsigned long start, unsigned long end, gfp_t gfp_mask,
73521- pgprot_t prot, int node, const void *caller);
73522+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
73523 extern void vfree(const void *addr);
73524
73525 extern void *vmap(struct page **pages, unsigned int count,
73526@@ -137,8 +142,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
73527 extern void free_vm_area(struct vm_struct *area);
73528
73529 /* for /dev/kmem */
73530-extern long vread(char *buf, char *addr, unsigned long count);
73531-extern long vwrite(char *buf, char *addr, unsigned long count);
73532+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
73533+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
73534
73535 /*
73536 * Internals. Dont't use..
73537diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
73538index c586679..f06b389 100644
73539--- a/include/linux/vmstat.h
73540+++ b/include/linux/vmstat.h
73541@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
73542 /*
73543 * Zone based page accounting with per cpu differentials.
73544 */
73545-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
73546+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
73547
73548 static inline void zone_page_state_add(long x, struct zone *zone,
73549 enum zone_stat_item item)
73550 {
73551- atomic_long_add(x, &zone->vm_stat[item]);
73552- atomic_long_add(x, &vm_stat[item]);
73553+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
73554+ atomic_long_add_unchecked(x, &vm_stat[item]);
73555 }
73556
73557 static inline unsigned long global_page_state(enum zone_stat_item item)
73558 {
73559- long x = atomic_long_read(&vm_stat[item]);
73560+ long x = atomic_long_read_unchecked(&vm_stat[item]);
73561 #ifdef CONFIG_SMP
73562 if (x < 0)
73563 x = 0;
73564@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
73565 static inline unsigned long zone_page_state(struct zone *zone,
73566 enum zone_stat_item item)
73567 {
73568- long x = atomic_long_read(&zone->vm_stat[item]);
73569+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
73570 #ifdef CONFIG_SMP
73571 if (x < 0)
73572 x = 0;
73573@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
73574 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
73575 enum zone_stat_item item)
73576 {
73577- long x = atomic_long_read(&zone->vm_stat[item]);
73578+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
73579
73580 #ifdef CONFIG_SMP
73581 int cpu;
73582@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
73583
73584 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
73585 {
73586- atomic_long_inc(&zone->vm_stat[item]);
73587- atomic_long_inc(&vm_stat[item]);
73588+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
73589+ atomic_long_inc_unchecked(&vm_stat[item]);
73590 }
73591
73592 static inline void __inc_zone_page_state(struct page *page,
73593@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
73594
73595 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
73596 {
73597- atomic_long_dec(&zone->vm_stat[item]);
73598- atomic_long_dec(&vm_stat[item]);
73599+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
73600+ atomic_long_dec_unchecked(&vm_stat[item]);
73601 }
73602
73603 static inline void __dec_zone_page_state(struct page *page,
73604diff --git a/include/linux/xattr.h b/include/linux/xattr.h
73605index fdbafc6..49dfe4f 100644
73606--- a/include/linux/xattr.h
73607+++ b/include/linux/xattr.h
73608@@ -28,7 +28,7 @@ struct xattr_handler {
73609 size_t size, int handler_flags);
73610 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
73611 size_t size, int flags, int handler_flags);
73612-};
73613+} __do_const;
73614
73615 struct xattr {
73616 char *name;
73617@@ -37,6 +37,9 @@ struct xattr {
73618 };
73619
73620 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
73621+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
73622+ssize_t pax_getxattr(struct dentry *, void *, size_t);
73623+#endif
73624 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
73625 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
73626 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
73627diff --git a/include/linux/zlib.h b/include/linux/zlib.h
73628index 9c5a6b4..09c9438 100644
73629--- a/include/linux/zlib.h
73630+++ b/include/linux/zlib.h
73631@@ -31,6 +31,7 @@
73632 #define _ZLIB_H
73633
73634 #include <linux/zconf.h>
73635+#include <linux/compiler.h>
73636
73637 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
73638 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
73639@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
73640
73641 /* basic functions */
73642
73643-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
73644+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
73645 /*
73646 Returns the number of bytes that needs to be allocated for a per-
73647 stream workspace with the specified parameters. A pointer to this
73648diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
73649index 95d1c91..6798cca 100644
73650--- a/include/media/v4l2-dev.h
73651+++ b/include/media/v4l2-dev.h
73652@@ -76,7 +76,7 @@ struct v4l2_file_operations {
73653 int (*mmap) (struct file *, struct vm_area_struct *);
73654 int (*open) (struct file *);
73655 int (*release) (struct file *);
73656-};
73657+} __do_const;
73658
73659 /*
73660 * Newer version of video_device, handled by videodev2.c
73661diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
73662index adcbb20..62c2559 100644
73663--- a/include/net/9p/transport.h
73664+++ b/include/net/9p/transport.h
73665@@ -57,7 +57,7 @@ struct p9_trans_module {
73666 int (*cancel) (struct p9_client *, struct p9_req_t *req);
73667 int (*zc_request)(struct p9_client *, struct p9_req_t *,
73668 char *, char *, int , int, int, int);
73669-};
73670+} __do_const;
73671
73672 void v9fs_register_trans(struct p9_trans_module *m);
73673 void v9fs_unregister_trans(struct p9_trans_module *m);
73674diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
73675index fb94cf1..7c0c987 100644
73676--- a/include/net/bluetooth/l2cap.h
73677+++ b/include/net/bluetooth/l2cap.h
73678@@ -551,7 +551,7 @@ struct l2cap_ops {
73679 void (*defer) (struct l2cap_chan *chan);
73680 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
73681 unsigned long len, int nb);
73682-};
73683+} __do_const;
73684
73685 struct l2cap_conn {
73686 struct hci_conn *hcon;
73687diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
73688index f2ae33d..c457cf0 100644
73689--- a/include/net/caif/cfctrl.h
73690+++ b/include/net/caif/cfctrl.h
73691@@ -52,7 +52,7 @@ struct cfctrl_rsp {
73692 void (*radioset_rsp)(void);
73693 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
73694 struct cflayer *client_layer);
73695-};
73696+} __no_const;
73697
73698 /* Link Setup Parameters for CAIF-Links. */
73699 struct cfctrl_link_param {
73700@@ -101,8 +101,8 @@ struct cfctrl_request_info {
73701 struct cfctrl {
73702 struct cfsrvl serv;
73703 struct cfctrl_rsp res;
73704- atomic_t req_seq_no;
73705- atomic_t rsp_seq_no;
73706+ atomic_unchecked_t req_seq_no;
73707+ atomic_unchecked_t rsp_seq_no;
73708 struct list_head list;
73709 /* Protects from simultaneous access to first_req list */
73710 spinlock_t info_list_lock;
73711diff --git a/include/net/flow.h b/include/net/flow.h
73712index 628e11b..4c475df 100644
73713--- a/include/net/flow.h
73714+++ b/include/net/flow.h
73715@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
73716
73717 extern void flow_cache_flush(void);
73718 extern void flow_cache_flush_deferred(void);
73719-extern atomic_t flow_cache_genid;
73720+extern atomic_unchecked_t flow_cache_genid;
73721
73722 #endif
73723diff --git a/include/net/genetlink.h b/include/net/genetlink.h
73724index 93024a4..eeb6b6e 100644
73725--- a/include/net/genetlink.h
73726+++ b/include/net/genetlink.h
73727@@ -119,7 +119,7 @@ struct genl_ops {
73728 struct netlink_callback *cb);
73729 int (*done)(struct netlink_callback *cb);
73730 struct list_head ops_list;
73731-};
73732+} __do_const;
73733
73734 extern int genl_register_family(struct genl_family *family);
73735 extern int genl_register_family_with_ops(struct genl_family *family,
73736diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
73737index 734d9b5..48a9a4b 100644
73738--- a/include/net/gro_cells.h
73739+++ b/include/net/gro_cells.h
73740@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
73741 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
73742
73743 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
73744- atomic_long_inc(&dev->rx_dropped);
73745+ atomic_long_inc_unchecked(&dev->rx_dropped);
73746 kfree_skb(skb);
73747 return;
73748 }
73749diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
73750index de2c785..0588a6b 100644
73751--- a/include/net/inet_connection_sock.h
73752+++ b/include/net/inet_connection_sock.h
73753@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
73754 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
73755 int (*bind_conflict)(const struct sock *sk,
73756 const struct inet_bind_bucket *tb, bool relax);
73757-};
73758+} __do_const;
73759
73760 /** inet_connection_sock - INET connection oriented sock
73761 *
73762diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
73763index 53f464d..ba76aaa 100644
73764--- a/include/net/inetpeer.h
73765+++ b/include/net/inetpeer.h
73766@@ -47,8 +47,8 @@ struct inet_peer {
73767 */
73768 union {
73769 struct {
73770- atomic_t rid; /* Frag reception counter */
73771- atomic_t ip_id_count; /* IP ID for the next packet */
73772+ atomic_unchecked_t rid; /* Frag reception counter */
73773+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
73774 };
73775 struct rcu_head rcu;
73776 struct inet_peer *gc_next;
73777@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
73778 more++;
73779 inet_peer_refcheck(p);
73780 do {
73781- old = atomic_read(&p->ip_id_count);
73782+ old = atomic_read_unchecked(&p->ip_id_count);
73783 new = old + more;
73784 if (!new)
73785 new = 1;
73786- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
73787+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
73788 return new;
73789 }
73790
73791diff --git a/include/net/ip.h b/include/net/ip.h
73792index a68f838..74518ab 100644
73793--- a/include/net/ip.h
73794+++ b/include/net/ip.h
73795@@ -202,7 +202,7 @@ extern struct local_ports {
73796 } sysctl_local_ports;
73797 extern void inet_get_local_port_range(int *low, int *high);
73798
73799-extern unsigned long *sysctl_local_reserved_ports;
73800+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
73801 static inline int inet_is_reserved_local_port(int port)
73802 {
73803 return test_bit(port, sysctl_local_reserved_ports);
73804diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
73805index e49db91..76a81de 100644
73806--- a/include/net/ip_fib.h
73807+++ b/include/net/ip_fib.h
73808@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
73809
73810 #define FIB_RES_SADDR(net, res) \
73811 ((FIB_RES_NH(res).nh_saddr_genid == \
73812- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
73813+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
73814 FIB_RES_NH(res).nh_saddr : \
73815 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
73816 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
73817diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
73818index 4c062cc..3562c31 100644
73819--- a/include/net/ip_vs.h
73820+++ b/include/net/ip_vs.h
73821@@ -612,7 +612,7 @@ struct ip_vs_conn {
73822 struct ip_vs_conn *control; /* Master control connection */
73823 atomic_t n_control; /* Number of controlled ones */
73824 struct ip_vs_dest *dest; /* real server */
73825- atomic_t in_pkts; /* incoming packet counter */
73826+ atomic_unchecked_t in_pkts; /* incoming packet counter */
73827
73828 /* packet transmitter for different forwarding methods. If it
73829 mangles the packet, it must return NF_DROP or better NF_STOLEN,
73830@@ -761,7 +761,7 @@ struct ip_vs_dest {
73831 __be16 port; /* port number of the server */
73832 union nf_inet_addr addr; /* IP address of the server */
73833 volatile unsigned int flags; /* dest status flags */
73834- atomic_t conn_flags; /* flags to copy to conn */
73835+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
73836 atomic_t weight; /* server weight */
73837
73838 atomic_t refcnt; /* reference counter */
73839@@ -1013,11 +1013,11 @@ struct netns_ipvs {
73840 /* ip_vs_lblc */
73841 int sysctl_lblc_expiration;
73842 struct ctl_table_header *lblc_ctl_header;
73843- struct ctl_table *lblc_ctl_table;
73844+ ctl_table_no_const *lblc_ctl_table;
73845 /* ip_vs_lblcr */
73846 int sysctl_lblcr_expiration;
73847 struct ctl_table_header *lblcr_ctl_header;
73848- struct ctl_table *lblcr_ctl_table;
73849+ ctl_table_no_const *lblcr_ctl_table;
73850 /* ip_vs_est */
73851 struct list_head est_list; /* estimator list */
73852 spinlock_t est_lock;
73853diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
73854index 80ffde3..968b0f4 100644
73855--- a/include/net/irda/ircomm_tty.h
73856+++ b/include/net/irda/ircomm_tty.h
73857@@ -35,6 +35,7 @@
73858 #include <linux/termios.h>
73859 #include <linux/timer.h>
73860 #include <linux/tty.h> /* struct tty_struct */
73861+#include <asm/local.h>
73862
73863 #include <net/irda/irias_object.h>
73864 #include <net/irda/ircomm_core.h>
73865diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
73866index 714cc9a..ea05f3e 100644
73867--- a/include/net/iucv/af_iucv.h
73868+++ b/include/net/iucv/af_iucv.h
73869@@ -149,7 +149,7 @@ struct iucv_skb_cb {
73870 struct iucv_sock_list {
73871 struct hlist_head head;
73872 rwlock_t lock;
73873- atomic_t autobind_name;
73874+ atomic_unchecked_t autobind_name;
73875 };
73876
73877 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
73878diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
73879index df83f69..9b640b8 100644
73880--- a/include/net/llc_c_ac.h
73881+++ b/include/net/llc_c_ac.h
73882@@ -87,7 +87,7 @@
73883 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
73884 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
73885
73886-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73887+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73888
73889 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
73890 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
73891diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
73892index 6ca3113..f8026dd 100644
73893--- a/include/net/llc_c_ev.h
73894+++ b/include/net/llc_c_ev.h
73895@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
73896 return (struct llc_conn_state_ev *)skb->cb;
73897 }
73898
73899-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73900-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73901+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73902+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73903
73904 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
73905 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
73906diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
73907index 0e79cfb..f46db31 100644
73908--- a/include/net/llc_c_st.h
73909+++ b/include/net/llc_c_st.h
73910@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
73911 u8 next_state;
73912 llc_conn_ev_qfyr_t *ev_qualifiers;
73913 llc_conn_action_t *ev_actions;
73914-};
73915+} __do_const;
73916
73917 struct llc_conn_state {
73918 u8 current_state;
73919diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
73920index 37a3bbd..55a4241 100644
73921--- a/include/net/llc_s_ac.h
73922+++ b/include/net/llc_s_ac.h
73923@@ -23,7 +23,7 @@
73924 #define SAP_ACT_TEST_IND 9
73925
73926 /* All action functions must look like this */
73927-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73928+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73929
73930 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
73931 struct sk_buff *skb);
73932diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
73933index 567c681..cd73ac0 100644
73934--- a/include/net/llc_s_st.h
73935+++ b/include/net/llc_s_st.h
73936@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
73937 llc_sap_ev_t ev;
73938 u8 next_state;
73939 llc_sap_action_t *ev_actions;
73940-};
73941+} __do_const;
73942
73943 struct llc_sap_state {
73944 u8 curr_state;
73945diff --git a/include/net/mac80211.h b/include/net/mac80211.h
73946index 885898a..cdace34 100644
73947--- a/include/net/mac80211.h
73948+++ b/include/net/mac80211.h
73949@@ -4205,7 +4205,7 @@ struct rate_control_ops {
73950 void (*add_sta_debugfs)(void *priv, void *priv_sta,
73951 struct dentry *dir);
73952 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
73953-};
73954+} __do_const;
73955
73956 static inline int rate_supported(struct ieee80211_sta *sta,
73957 enum ieee80211_band band,
73958diff --git a/include/net/neighbour.h b/include/net/neighbour.h
73959index 7e748ad..5c6229b 100644
73960--- a/include/net/neighbour.h
73961+++ b/include/net/neighbour.h
73962@@ -123,7 +123,7 @@ struct neigh_ops {
73963 void (*error_report)(struct neighbour *, struct sk_buff *);
73964 int (*output)(struct neighbour *, struct sk_buff *);
73965 int (*connected_output)(struct neighbour *, struct sk_buff *);
73966-};
73967+} __do_const;
73968
73969 struct pneigh_entry {
73970 struct pneigh_entry *next;
73971diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
73972index b176978..ea169f4 100644
73973--- a/include/net/net_namespace.h
73974+++ b/include/net/net_namespace.h
73975@@ -117,7 +117,7 @@ struct net {
73976 #endif
73977 struct netns_ipvs *ipvs;
73978 struct sock *diag_nlsk;
73979- atomic_t rt_genid;
73980+ atomic_unchecked_t rt_genid;
73981 };
73982
73983 /*
73984@@ -274,7 +274,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73985 #define __net_init __init
73986 #define __net_exit __exit_refok
73987 #define __net_initdata __initdata
73988+#ifdef CONSTIFY_PLUGIN
73989 #define __net_initconst __initconst
73990+#else
73991+#define __net_initconst __initdata
73992+#endif
73993 #endif
73994
73995 struct pernet_operations {
73996@@ -284,7 +288,7 @@ struct pernet_operations {
73997 void (*exit_batch)(struct list_head *net_exit_list);
73998 int *id;
73999 size_t size;
74000-};
74001+} __do_const;
74002
74003 /*
74004 * Use these carefully. If you implement a network device and it
74005@@ -332,12 +336,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
74006
74007 static inline int rt_genid(struct net *net)
74008 {
74009- return atomic_read(&net->rt_genid);
74010+ return atomic_read_unchecked(&net->rt_genid);
74011 }
74012
74013 static inline void rt_genid_bump(struct net *net)
74014 {
74015- atomic_inc(&net->rt_genid);
74016+ atomic_inc_unchecked(&net->rt_genid);
74017 }
74018
74019 #endif /* __NET_NET_NAMESPACE_H */
74020diff --git a/include/net/netdma.h b/include/net/netdma.h
74021index 8ba8ce2..99b7fff 100644
74022--- a/include/net/netdma.h
74023+++ b/include/net/netdma.h
74024@@ -24,7 +24,7 @@
74025 #include <linux/dmaengine.h>
74026 #include <linux/skbuff.h>
74027
74028-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
74029+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
74030 struct sk_buff *skb, int offset, struct iovec *to,
74031 size_t len, struct dma_pinned_list *pinned_list);
74032
74033diff --git a/include/net/netlink.h b/include/net/netlink.h
74034index 9690b0f..87aded7 100644
74035--- a/include/net/netlink.h
74036+++ b/include/net/netlink.h
74037@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
74038 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
74039 {
74040 if (mark)
74041- skb_trim(skb, (unsigned char *) mark - skb->data);
74042+ skb_trim(skb, (const unsigned char *) mark - skb->data);
74043 }
74044
74045 /**
74046diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
74047index c9c0c53..53f24c3 100644
74048--- a/include/net/netns/conntrack.h
74049+++ b/include/net/netns/conntrack.h
74050@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
74051 struct nf_proto_net {
74052 #ifdef CONFIG_SYSCTL
74053 struct ctl_table_header *ctl_table_header;
74054- struct ctl_table *ctl_table;
74055+ ctl_table_no_const *ctl_table;
74056 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
74057 struct ctl_table_header *ctl_compat_header;
74058- struct ctl_table *ctl_compat_table;
74059+ ctl_table_no_const *ctl_compat_table;
74060 #endif
74061 #endif
74062 unsigned int users;
74063@@ -58,7 +58,7 @@ struct nf_ip_net {
74064 struct nf_icmp_net icmpv6;
74065 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
74066 struct ctl_table_header *ctl_table_header;
74067- struct ctl_table *ctl_table;
74068+ ctl_table_no_const *ctl_table;
74069 #endif
74070 };
74071
74072diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
74073index 2ba9de8..47bd6c7 100644
74074--- a/include/net/netns/ipv4.h
74075+++ b/include/net/netns/ipv4.h
74076@@ -67,7 +67,7 @@ struct netns_ipv4 {
74077 kgid_t sysctl_ping_group_range[2];
74078 long sysctl_tcp_mem[3];
74079
74080- atomic_t dev_addr_genid;
74081+ atomic_unchecked_t dev_addr_genid;
74082
74083 #ifdef CONFIG_IP_MROUTE
74084 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
74085diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
74086index 005e2c2..023d340 100644
74087--- a/include/net/netns/ipv6.h
74088+++ b/include/net/netns/ipv6.h
74089@@ -71,7 +71,7 @@ struct netns_ipv6 {
74090 struct fib_rules_ops *mr6_rules_ops;
74091 #endif
74092 #endif
74093- atomic_t dev_addr_genid;
74094+ atomic_unchecked_t dev_addr_genid;
74095 };
74096
74097 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
74098diff --git a/include/net/protocol.h b/include/net/protocol.h
74099index 047c047..b9dad15 100644
74100--- a/include/net/protocol.h
74101+++ b/include/net/protocol.h
74102@@ -44,7 +44,7 @@ struct net_protocol {
74103 void (*err_handler)(struct sk_buff *skb, u32 info);
74104 unsigned int no_policy:1,
74105 netns_ok:1;
74106-};
74107+} __do_const;
74108
74109 #if IS_ENABLED(CONFIG_IPV6)
74110 struct inet6_protocol {
74111@@ -57,7 +57,7 @@ struct inet6_protocol {
74112 u8 type, u8 code, int offset,
74113 __be32 info);
74114 unsigned int flags; /* INET6_PROTO_xxx */
74115-};
74116+} __do_const;
74117
74118 #define INET6_PROTO_NOPOLICY 0x1
74119 #define INET6_PROTO_FINAL 0x2
74120diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
74121index 7026648..584cc8c 100644
74122--- a/include/net/rtnetlink.h
74123+++ b/include/net/rtnetlink.h
74124@@ -81,7 +81,7 @@ struct rtnl_link_ops {
74125 const struct net_device *dev);
74126 unsigned int (*get_num_tx_queues)(void);
74127 unsigned int (*get_num_rx_queues)(void);
74128-};
74129+} __do_const;
74130
74131 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
74132 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
74133diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
74134index cd89510..d67810f 100644
74135--- a/include/net/sctp/sctp.h
74136+++ b/include/net/sctp/sctp.h
74137@@ -330,9 +330,9 @@ do { \
74138
74139 #else /* SCTP_DEBUG */
74140
74141-#define SCTP_DEBUG_PRINTK(whatever...)
74142-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
74143-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
74144+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
74145+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
74146+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
74147 #define SCTP_ENABLE_DEBUG
74148 #define SCTP_DISABLE_DEBUG
74149 #define SCTP_ASSERT(expr, str, func)
74150diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
74151index 2a82d13..62a31c2 100644
74152--- a/include/net/sctp/sm.h
74153+++ b/include/net/sctp/sm.h
74154@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
74155 typedef struct {
74156 sctp_state_fn_t *fn;
74157 const char *name;
74158-} sctp_sm_table_entry_t;
74159+} __do_const sctp_sm_table_entry_t;
74160
74161 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
74162 * currently in use.
74163@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
74164 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
74165
74166 /* Extern declarations for major data structures. */
74167-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
74168+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
74169
74170
74171 /* Get the size of a DATA chunk payload. */
74172diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
74173index 1bd4c41..9250b5b 100644
74174--- a/include/net/sctp/structs.h
74175+++ b/include/net/sctp/structs.h
74176@@ -516,7 +516,7 @@ struct sctp_pf {
74177 struct sctp_association *asoc);
74178 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
74179 struct sctp_af *af;
74180-};
74181+} __do_const;
74182
74183
74184 /* Structure to track chunk fragments that have been acked, but peer
74185diff --git a/include/net/sock.h b/include/net/sock.h
74186index 66772cf..25bc45b 100644
74187--- a/include/net/sock.h
74188+++ b/include/net/sock.h
74189@@ -325,7 +325,7 @@ struct sock {
74190 #ifdef CONFIG_RPS
74191 __u32 sk_rxhash;
74192 #endif
74193- atomic_t sk_drops;
74194+ atomic_unchecked_t sk_drops;
74195 int sk_rcvbuf;
74196
74197 struct sk_filter __rcu *sk_filter;
74198@@ -1797,7 +1797,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
74199 }
74200
74201 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
74202- char __user *from, char *to,
74203+ char __user *from, unsigned char *to,
74204 int copy, int offset)
74205 {
74206 if (skb->ip_summed == CHECKSUM_NONE) {
74207@@ -2056,7 +2056,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
74208 }
74209 }
74210
74211-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
74212+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
74213
74214 /**
74215 * sk_page_frag - return an appropriate page_frag
74216diff --git a/include/net/tcp.h b/include/net/tcp.h
74217index 5bba80f..8520a82 100644
74218--- a/include/net/tcp.h
74219+++ b/include/net/tcp.h
74220@@ -524,7 +524,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
74221 extern void tcp_xmit_retransmit_queue(struct sock *);
74222 extern void tcp_simple_retransmit(struct sock *);
74223 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
74224-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
74225+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
74226
74227 extern void tcp_send_probe0(struct sock *);
74228 extern void tcp_send_partial(struct sock *);
74229@@ -697,8 +697,8 @@ struct tcp_skb_cb {
74230 struct inet6_skb_parm h6;
74231 #endif
74232 } header; /* For incoming frames */
74233- __u32 seq; /* Starting sequence number */
74234- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
74235+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
74236+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
74237 __u32 when; /* used to compute rtt's */
74238 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
74239
74240@@ -712,7 +712,7 @@ struct tcp_skb_cb {
74241
74242 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
74243 /* 1 byte hole */
74244- __u32 ack_seq; /* Sequence number ACK'd */
74245+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
74246 };
74247
74248 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
74249diff --git a/include/net/xfrm.h b/include/net/xfrm.h
74250index 94ce082..62b278d 100644
74251--- a/include/net/xfrm.h
74252+++ b/include/net/xfrm.h
74253@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
74254 struct net_device *dev,
74255 const struct flowi *fl);
74256 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
74257-};
74258+} __do_const;
74259
74260 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
74261 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
74262@@ -341,7 +341,7 @@ struct xfrm_state_afinfo {
74263 struct sk_buff *skb);
74264 int (*transport_finish)(struct sk_buff *skb,
74265 int async);
74266-};
74267+} __do_const;
74268
74269 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
74270 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
74271@@ -424,7 +424,7 @@ struct xfrm_mode {
74272 struct module *owner;
74273 unsigned int encap;
74274 int flags;
74275-};
74276+} __do_const;
74277
74278 /* Flags for xfrm_mode. */
74279 enum {
74280@@ -521,7 +521,7 @@ struct xfrm_policy {
74281 struct timer_list timer;
74282
74283 struct flow_cache_object flo;
74284- atomic_t genid;
74285+ atomic_unchecked_t genid;
74286 u32 priority;
74287 u32 index;
74288 struct xfrm_mark mark;
74289diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
74290index 1a046b1..ee0bef0 100644
74291--- a/include/rdma/iw_cm.h
74292+++ b/include/rdma/iw_cm.h
74293@@ -122,7 +122,7 @@ struct iw_cm_verbs {
74294 int backlog);
74295
74296 int (*destroy_listen)(struct iw_cm_id *cm_id);
74297-};
74298+} __no_const;
74299
74300 /**
74301 * iw_create_cm_id - Create an IW CM identifier.
74302diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
74303index e1379b4..67eafbe 100644
74304--- a/include/scsi/libfc.h
74305+++ b/include/scsi/libfc.h
74306@@ -762,6 +762,7 @@ struct libfc_function_template {
74307 */
74308 void (*disc_stop_final) (struct fc_lport *);
74309 };
74310+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
74311
74312 /**
74313 * struct fc_disc - Discovery context
74314@@ -866,7 +867,7 @@ struct fc_lport {
74315 struct fc_vport *vport;
74316
74317 /* Operational Information */
74318- struct libfc_function_template tt;
74319+ libfc_function_template_no_const tt;
74320 u8 link_up;
74321 u8 qfull;
74322 enum fc_lport_state state;
74323diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
74324index cc64587..608f523 100644
74325--- a/include/scsi/scsi_device.h
74326+++ b/include/scsi/scsi_device.h
74327@@ -171,9 +171,9 @@ struct scsi_device {
74328 unsigned int max_device_blocked; /* what device_blocked counts down from */
74329 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
74330
74331- atomic_t iorequest_cnt;
74332- atomic_t iodone_cnt;
74333- atomic_t ioerr_cnt;
74334+ atomic_unchecked_t iorequest_cnt;
74335+ atomic_unchecked_t iodone_cnt;
74336+ atomic_unchecked_t ioerr_cnt;
74337
74338 struct device sdev_gendev,
74339 sdev_dev;
74340diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
74341index b797e8f..8e2c3aa 100644
74342--- a/include/scsi/scsi_transport_fc.h
74343+++ b/include/scsi/scsi_transport_fc.h
74344@@ -751,7 +751,8 @@ struct fc_function_template {
74345 unsigned long show_host_system_hostname:1;
74346
74347 unsigned long disable_target_scan:1;
74348-};
74349+} __do_const;
74350+typedef struct fc_function_template __no_const fc_function_template_no_const;
74351
74352
74353 /**
74354diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
74355index 9031a26..750d592 100644
74356--- a/include/sound/compress_driver.h
74357+++ b/include/sound/compress_driver.h
74358@@ -128,7 +128,7 @@ struct snd_compr_ops {
74359 struct snd_compr_caps *caps);
74360 int (*get_codec_caps) (struct snd_compr_stream *stream,
74361 struct snd_compr_codec_caps *codec);
74362-};
74363+} __no_const;
74364
74365 /**
74366 * struct snd_compr: Compressed device
74367diff --git a/include/sound/soc.h b/include/sound/soc.h
74368index 85c1522..f44bad1 100644
74369--- a/include/sound/soc.h
74370+++ b/include/sound/soc.h
74371@@ -781,7 +781,7 @@ struct snd_soc_codec_driver {
74372 /* probe ordering - for components with runtime dependencies */
74373 int probe_order;
74374 int remove_order;
74375-};
74376+} __do_const;
74377
74378 /* SoC platform interface */
74379 struct snd_soc_platform_driver {
74380@@ -827,7 +827,7 @@ struct snd_soc_platform_driver {
74381 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
74382 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
74383 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
74384-};
74385+} __do_const;
74386
74387 struct snd_soc_platform {
74388 const char *name;
74389diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
74390index 4ea4f98..a63629b 100644
74391--- a/include/target/target_core_base.h
74392+++ b/include/target/target_core_base.h
74393@@ -653,7 +653,7 @@ struct se_device {
74394 spinlock_t stats_lock;
74395 /* Active commands on this virtual SE device */
74396 atomic_t simple_cmds;
74397- atomic_t dev_ordered_id;
74398+ atomic_unchecked_t dev_ordered_id;
74399 atomic_t dev_ordered_sync;
74400 atomic_t dev_qf_count;
74401 int export_count;
74402diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
74403new file mode 100644
74404index 0000000..fb634b7
74405--- /dev/null
74406+++ b/include/trace/events/fs.h
74407@@ -0,0 +1,53 @@
74408+#undef TRACE_SYSTEM
74409+#define TRACE_SYSTEM fs
74410+
74411+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
74412+#define _TRACE_FS_H
74413+
74414+#include <linux/fs.h>
74415+#include <linux/tracepoint.h>
74416+
74417+TRACE_EVENT(do_sys_open,
74418+
74419+ TP_PROTO(const char *filename, int flags, int mode),
74420+
74421+ TP_ARGS(filename, flags, mode),
74422+
74423+ TP_STRUCT__entry(
74424+ __string( filename, filename )
74425+ __field( int, flags )
74426+ __field( int, mode )
74427+ ),
74428+
74429+ TP_fast_assign(
74430+ __assign_str(filename, filename);
74431+ __entry->flags = flags;
74432+ __entry->mode = mode;
74433+ ),
74434+
74435+ TP_printk("\"%s\" %x %o",
74436+ __get_str(filename), __entry->flags, __entry->mode)
74437+);
74438+
74439+TRACE_EVENT(open_exec,
74440+
74441+ TP_PROTO(const char *filename),
74442+
74443+ TP_ARGS(filename),
74444+
74445+ TP_STRUCT__entry(
74446+ __string( filename, filename )
74447+ ),
74448+
74449+ TP_fast_assign(
74450+ __assign_str(filename, filename);
74451+ ),
74452+
74453+ TP_printk("\"%s\"",
74454+ __get_str(filename))
74455+);
74456+
74457+#endif /* _TRACE_FS_H */
74458+
74459+/* This part must be outside protection */
74460+#include <trace/define_trace.h>
74461diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
74462index 1c09820..7f5ec79 100644
74463--- a/include/trace/events/irq.h
74464+++ b/include/trace/events/irq.h
74465@@ -36,7 +36,7 @@ struct softirq_action;
74466 */
74467 TRACE_EVENT(irq_handler_entry,
74468
74469- TP_PROTO(int irq, struct irqaction *action),
74470+ TP_PROTO(int irq, const struct irqaction *action),
74471
74472 TP_ARGS(irq, action),
74473
74474@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
74475 */
74476 TRACE_EVENT(irq_handler_exit,
74477
74478- TP_PROTO(int irq, struct irqaction *action, int ret),
74479+ TP_PROTO(int irq, const struct irqaction *action, int ret),
74480
74481 TP_ARGS(irq, action, ret),
74482
74483diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
74484index 7caf44c..23c6f27 100644
74485--- a/include/uapi/linux/a.out.h
74486+++ b/include/uapi/linux/a.out.h
74487@@ -39,6 +39,14 @@ enum machine_type {
74488 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
74489 };
74490
74491+/* Constants for the N_FLAGS field */
74492+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
74493+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
74494+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
74495+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
74496+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
74497+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
74498+
74499 #if !defined (N_MAGIC)
74500 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
74501 #endif
74502diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
74503index d876736..ccce5c0 100644
74504--- a/include/uapi/linux/byteorder/little_endian.h
74505+++ b/include/uapi/linux/byteorder/little_endian.h
74506@@ -42,51 +42,51 @@
74507
74508 static inline __le64 __cpu_to_le64p(const __u64 *p)
74509 {
74510- return (__force __le64)*p;
74511+ return (__force const __le64)*p;
74512 }
74513-static inline __u64 __le64_to_cpup(const __le64 *p)
74514+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
74515 {
74516- return (__force __u64)*p;
74517+ return (__force const __u64)*p;
74518 }
74519 static inline __le32 __cpu_to_le32p(const __u32 *p)
74520 {
74521- return (__force __le32)*p;
74522+ return (__force const __le32)*p;
74523 }
74524 static inline __u32 __le32_to_cpup(const __le32 *p)
74525 {
74526- return (__force __u32)*p;
74527+ return (__force const __u32)*p;
74528 }
74529 static inline __le16 __cpu_to_le16p(const __u16 *p)
74530 {
74531- return (__force __le16)*p;
74532+ return (__force const __le16)*p;
74533 }
74534 static inline __u16 __le16_to_cpup(const __le16 *p)
74535 {
74536- return (__force __u16)*p;
74537+ return (__force const __u16)*p;
74538 }
74539 static inline __be64 __cpu_to_be64p(const __u64 *p)
74540 {
74541- return (__force __be64)__swab64p(p);
74542+ return (__force const __be64)__swab64p(p);
74543 }
74544 static inline __u64 __be64_to_cpup(const __be64 *p)
74545 {
74546- return __swab64p((__u64 *)p);
74547+ return __swab64p((const __u64 *)p);
74548 }
74549 static inline __be32 __cpu_to_be32p(const __u32 *p)
74550 {
74551- return (__force __be32)__swab32p(p);
74552+ return (__force const __be32)__swab32p(p);
74553 }
74554-static inline __u32 __be32_to_cpup(const __be32 *p)
74555+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
74556 {
74557- return __swab32p((__u32 *)p);
74558+ return __swab32p((const __u32 *)p);
74559 }
74560 static inline __be16 __cpu_to_be16p(const __u16 *p)
74561 {
74562- return (__force __be16)__swab16p(p);
74563+ return (__force const __be16)__swab16p(p);
74564 }
74565 static inline __u16 __be16_to_cpup(const __be16 *p)
74566 {
74567- return __swab16p((__u16 *)p);
74568+ return __swab16p((const __u16 *)p);
74569 }
74570 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
74571 #define __le64_to_cpus(x) do { (void)(x); } while (0)
74572diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
74573index ef6103b..d4e65dd 100644
74574--- a/include/uapi/linux/elf.h
74575+++ b/include/uapi/linux/elf.h
74576@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
74577 #define PT_GNU_EH_FRAME 0x6474e550
74578
74579 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
74580+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
74581+
74582+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
74583+
74584+/* Constants for the e_flags field */
74585+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
74586+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
74587+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
74588+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
74589+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
74590+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
74591
74592 /*
74593 * Extended Numbering
74594@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
74595 #define DT_DEBUG 21
74596 #define DT_TEXTREL 22
74597 #define DT_JMPREL 23
74598+#define DT_FLAGS 30
74599+ #define DF_TEXTREL 0x00000004
74600 #define DT_ENCODING 32
74601 #define OLD_DT_LOOS 0x60000000
74602 #define DT_LOOS 0x6000000d
74603@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
74604 #define PF_W 0x2
74605 #define PF_X 0x1
74606
74607+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
74608+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
74609+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
74610+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
74611+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
74612+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
74613+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
74614+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
74615+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
74616+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
74617+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
74618+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
74619+
74620 typedef struct elf32_phdr{
74621 Elf32_Word p_type;
74622 Elf32_Off p_offset;
74623@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
74624 #define EI_OSABI 7
74625 #define EI_PAD 8
74626
74627+#define EI_PAX 14
74628+
74629 #define ELFMAG0 0x7f /* EI_MAG */
74630 #define ELFMAG1 'E'
74631 #define ELFMAG2 'L'
74632diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
74633index aa169c4..6a2771d 100644
74634--- a/include/uapi/linux/personality.h
74635+++ b/include/uapi/linux/personality.h
74636@@ -30,6 +30,7 @@ enum {
74637 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
74638 ADDR_NO_RANDOMIZE | \
74639 ADDR_COMPAT_LAYOUT | \
74640+ ADDR_LIMIT_3GB | \
74641 MMAP_PAGE_ZERO)
74642
74643 /*
74644diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
74645index 7530e74..e714828 100644
74646--- a/include/uapi/linux/screen_info.h
74647+++ b/include/uapi/linux/screen_info.h
74648@@ -43,7 +43,8 @@ struct screen_info {
74649 __u16 pages; /* 0x32 */
74650 __u16 vesa_attributes; /* 0x34 */
74651 __u32 capabilities; /* 0x36 */
74652- __u8 _reserved[6]; /* 0x3a */
74653+ __u16 vesapm_size; /* 0x3a */
74654+ __u8 _reserved[4]; /* 0x3c */
74655 } __attribute__((packed));
74656
74657 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
74658diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
74659index 0e011eb..82681b1 100644
74660--- a/include/uapi/linux/swab.h
74661+++ b/include/uapi/linux/swab.h
74662@@ -43,7 +43,7 @@
74663 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
74664 */
74665
74666-static inline __attribute_const__ __u16 __fswab16(__u16 val)
74667+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
74668 {
74669 #ifdef __HAVE_BUILTIN_BSWAP16__
74670 return __builtin_bswap16(val);
74671@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
74672 #endif
74673 }
74674
74675-static inline __attribute_const__ __u32 __fswab32(__u32 val)
74676+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
74677 {
74678 #ifdef __HAVE_BUILTIN_BSWAP32__
74679 return __builtin_bswap32(val);
74680@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
74681 #endif
74682 }
74683
74684-static inline __attribute_const__ __u64 __fswab64(__u64 val)
74685+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
74686 {
74687 #ifdef __HAVE_BUILTIN_BSWAP64__
74688 return __builtin_bswap64(val);
74689diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
74690index 6d67213..8dab561 100644
74691--- a/include/uapi/linux/sysctl.h
74692+++ b/include/uapi/linux/sysctl.h
74693@@ -155,7 +155,11 @@ enum
74694 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
74695 };
74696
74697-
74698+#ifdef CONFIG_PAX_SOFTMODE
74699+enum {
74700+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
74701+};
74702+#endif
74703
74704 /* CTL_VM names: */
74705 enum
74706diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
74707index e4629b9..6958086 100644
74708--- a/include/uapi/linux/xattr.h
74709+++ b/include/uapi/linux/xattr.h
74710@@ -63,5 +63,9 @@
74711 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
74712 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
74713
74714+/* User namespace */
74715+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
74716+#define XATTR_PAX_FLAGS_SUFFIX "flags"
74717+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
74718
74719 #endif /* _UAPI_LINUX_XATTR_H */
74720diff --git a/include/video/udlfb.h b/include/video/udlfb.h
74721index f9466fa..f4e2b81 100644
74722--- a/include/video/udlfb.h
74723+++ b/include/video/udlfb.h
74724@@ -53,10 +53,10 @@ struct dlfb_data {
74725 u32 pseudo_palette[256];
74726 int blank_mode; /*one of FB_BLANK_ */
74727 /* blit-only rendering path metrics, exposed through sysfs */
74728- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
74729- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
74730- atomic_t bytes_sent; /* to usb, after compression including overhead */
74731- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
74732+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
74733+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
74734+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
74735+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
74736 };
74737
74738 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
74739diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
74740index 1a91850..28573f8 100644
74741--- a/include/video/uvesafb.h
74742+++ b/include/video/uvesafb.h
74743@@ -122,6 +122,7 @@ struct uvesafb_par {
74744 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
74745 u8 pmi_setpal; /* PMI for palette changes */
74746 u16 *pmi_base; /* protected mode interface location */
74747+ u8 *pmi_code; /* protected mode code location */
74748 void *pmi_start;
74749 void *pmi_pal;
74750 u8 *vbe_state_orig; /*
74751diff --git a/init/Kconfig b/init/Kconfig
74752index 2d9b831..ae4c8ac 100644
74753--- a/init/Kconfig
74754+++ b/init/Kconfig
74755@@ -1029,6 +1029,7 @@ endif # CGROUPS
74756
74757 config CHECKPOINT_RESTORE
74758 bool "Checkpoint/restore support" if EXPERT
74759+ depends on !GRKERNSEC
74760 default n
74761 help
74762 Enables additional kernel features in a sake of checkpoint/restore.
74763@@ -1516,7 +1517,7 @@ config SLUB_DEBUG
74764
74765 config COMPAT_BRK
74766 bool "Disable heap randomization"
74767- default y
74768+ default n
74769 help
74770 Randomizing heap placement makes heap exploits harder, but it
74771 also breaks ancient binaries (including anything libc5 based).
74772@@ -1779,7 +1780,7 @@ config INIT_ALL_POSSIBLE
74773 config STOP_MACHINE
74774 bool
74775 default y
74776- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
74777+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
74778 help
74779 Need stop_machine() primitive.
74780
74781diff --git a/init/Makefile b/init/Makefile
74782index 7bc47ee..6da2dc7 100644
74783--- a/init/Makefile
74784+++ b/init/Makefile
74785@@ -2,6 +2,9 @@
74786 # Makefile for the linux kernel.
74787 #
74788
74789+ccflags-y := $(GCC_PLUGINS_CFLAGS)
74790+asflags-y := $(GCC_PLUGINS_AFLAGS)
74791+
74792 obj-y := main.o version.o mounts.o
74793 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
74794 obj-y += noinitramfs.o
74795diff --git a/init/do_mounts.c b/init/do_mounts.c
74796index a2b49f2..03a0e17c 100644
74797--- a/init/do_mounts.c
74798+++ b/init/do_mounts.c
74799@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
74800 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
74801 {
74802 struct super_block *s;
74803- int err = sys_mount(name, "/root", fs, flags, data);
74804+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
74805 if (err)
74806 return err;
74807
74808- sys_chdir("/root");
74809+ sys_chdir((const char __force_user *)"/root");
74810 s = current->fs->pwd.dentry->d_sb;
74811 ROOT_DEV = s->s_dev;
74812 printk(KERN_INFO
74813@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
74814 va_start(args, fmt);
74815 vsprintf(buf, fmt, args);
74816 va_end(args);
74817- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
74818+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
74819 if (fd >= 0) {
74820 sys_ioctl(fd, FDEJECT, 0);
74821 sys_close(fd);
74822 }
74823 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
74824- fd = sys_open("/dev/console", O_RDWR, 0);
74825+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
74826 if (fd >= 0) {
74827 sys_ioctl(fd, TCGETS, (long)&termios);
74828 termios.c_lflag &= ~ICANON;
74829 sys_ioctl(fd, TCSETSF, (long)&termios);
74830- sys_read(fd, &c, 1);
74831+ sys_read(fd, (char __user *)&c, 1);
74832 termios.c_lflag |= ICANON;
74833 sys_ioctl(fd, TCSETSF, (long)&termios);
74834 sys_close(fd);
74835@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
74836 mount_root();
74837 out:
74838 devtmpfs_mount("dev");
74839- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74840- sys_chroot(".");
74841+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74842+ sys_chroot((const char __force_user *)".");
74843 }
74844diff --git a/init/do_mounts.h b/init/do_mounts.h
74845index f5b978a..69dbfe8 100644
74846--- a/init/do_mounts.h
74847+++ b/init/do_mounts.h
74848@@ -15,15 +15,15 @@ extern int root_mountflags;
74849
74850 static inline int create_dev(char *name, dev_t dev)
74851 {
74852- sys_unlink(name);
74853- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
74854+ sys_unlink((char __force_user *)name);
74855+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
74856 }
74857
74858 #if BITS_PER_LONG == 32
74859 static inline u32 bstat(char *name)
74860 {
74861 struct stat64 stat;
74862- if (sys_stat64(name, &stat) != 0)
74863+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
74864 return 0;
74865 if (!S_ISBLK(stat.st_mode))
74866 return 0;
74867@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
74868 static inline u32 bstat(char *name)
74869 {
74870 struct stat stat;
74871- if (sys_newstat(name, &stat) != 0)
74872+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
74873 return 0;
74874 if (!S_ISBLK(stat.st_mode))
74875 return 0;
74876diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
74877index 3e0878e..8a9d7a0 100644
74878--- a/init/do_mounts_initrd.c
74879+++ b/init/do_mounts_initrd.c
74880@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
74881 {
74882 sys_unshare(CLONE_FS | CLONE_FILES);
74883 /* stdin/stdout/stderr for /linuxrc */
74884- sys_open("/dev/console", O_RDWR, 0);
74885+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
74886 sys_dup(0);
74887 sys_dup(0);
74888 /* move initrd over / and chdir/chroot in initrd root */
74889- sys_chdir("/root");
74890- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74891- sys_chroot(".");
74892+ sys_chdir((const char __force_user *)"/root");
74893+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74894+ sys_chroot((const char __force_user *)".");
74895 sys_setsid();
74896 return 0;
74897 }
74898@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
74899 create_dev("/dev/root.old", Root_RAM0);
74900 /* mount initrd on rootfs' /root */
74901 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
74902- sys_mkdir("/old", 0700);
74903- sys_chdir("/old");
74904+ sys_mkdir((const char __force_user *)"/old", 0700);
74905+ sys_chdir((const char __force_user *)"/old");
74906
74907 /* try loading default modules from initrd */
74908 load_default_modules();
74909@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
74910 current->flags &= ~PF_FREEZER_SKIP;
74911
74912 /* move initrd to rootfs' /old */
74913- sys_mount("..", ".", NULL, MS_MOVE, NULL);
74914+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
74915 /* switch root and cwd back to / of rootfs */
74916- sys_chroot("..");
74917+ sys_chroot((const char __force_user *)"..");
74918
74919 if (new_decode_dev(real_root_dev) == Root_RAM0) {
74920- sys_chdir("/old");
74921+ sys_chdir((const char __force_user *)"/old");
74922 return;
74923 }
74924
74925- sys_chdir("/");
74926+ sys_chdir((const char __force_user *)"/");
74927 ROOT_DEV = new_decode_dev(real_root_dev);
74928 mount_root();
74929
74930 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
74931- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
74932+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
74933 if (!error)
74934 printk("okay\n");
74935 else {
74936- int fd = sys_open("/dev/root.old", O_RDWR, 0);
74937+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
74938 if (error == -ENOENT)
74939 printk("/initrd does not exist. Ignored.\n");
74940 else
74941 printk("failed\n");
74942 printk(KERN_NOTICE "Unmounting old root\n");
74943- sys_umount("/old", MNT_DETACH);
74944+ sys_umount((char __force_user *)"/old", MNT_DETACH);
74945 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
74946 if (fd < 0) {
74947 error = fd;
74948@@ -127,11 +127,11 @@ int __init initrd_load(void)
74949 * mounted in the normal path.
74950 */
74951 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
74952- sys_unlink("/initrd.image");
74953+ sys_unlink((const char __force_user *)"/initrd.image");
74954 handle_initrd();
74955 return 1;
74956 }
74957 }
74958- sys_unlink("/initrd.image");
74959+ sys_unlink((const char __force_user *)"/initrd.image");
74960 return 0;
74961 }
74962diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
74963index 8cb6db5..d729f50 100644
74964--- a/init/do_mounts_md.c
74965+++ b/init/do_mounts_md.c
74966@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
74967 partitioned ? "_d" : "", minor,
74968 md_setup_args[ent].device_names);
74969
74970- fd = sys_open(name, 0, 0);
74971+ fd = sys_open((char __force_user *)name, 0, 0);
74972 if (fd < 0) {
74973 printk(KERN_ERR "md: open failed - cannot start "
74974 "array %s\n", name);
74975@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
74976 * array without it
74977 */
74978 sys_close(fd);
74979- fd = sys_open(name, 0, 0);
74980+ fd = sys_open((char __force_user *)name, 0, 0);
74981 sys_ioctl(fd, BLKRRPART, 0);
74982 }
74983 sys_close(fd);
74984@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
74985
74986 wait_for_device_probe();
74987
74988- fd = sys_open("/dev/md0", 0, 0);
74989+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
74990 if (fd >= 0) {
74991 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
74992 sys_close(fd);
74993diff --git a/init/init_task.c b/init/init_task.c
74994index ba0a7f36..2bcf1d5 100644
74995--- a/init/init_task.c
74996+++ b/init/init_task.c
74997@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
74998 * Initial thread structure. Alignment of this is handled by a special
74999 * linker map entry.
75000 */
75001+#ifdef CONFIG_X86
75002+union thread_union init_thread_union __init_task_data;
75003+#else
75004 union thread_union init_thread_union __init_task_data =
75005 { INIT_THREAD_INFO(init_task) };
75006+#endif
75007diff --git a/init/initramfs.c b/init/initramfs.c
75008index a67ef9d..2d17ed9 100644
75009--- a/init/initramfs.c
75010+++ b/init/initramfs.c
75011@@ -84,7 +84,7 @@ static void __init free_hash(void)
75012 }
75013 }
75014
75015-static long __init do_utime(char *filename, time_t mtime)
75016+static long __init do_utime(char __force_user *filename, time_t mtime)
75017 {
75018 struct timespec t[2];
75019
75020@@ -119,7 +119,7 @@ static void __init dir_utime(void)
75021 struct dir_entry *de, *tmp;
75022 list_for_each_entry_safe(de, tmp, &dir_list, list) {
75023 list_del(&de->list);
75024- do_utime(de->name, de->mtime);
75025+ do_utime((char __force_user *)de->name, de->mtime);
75026 kfree(de->name);
75027 kfree(de);
75028 }
75029@@ -281,7 +281,7 @@ static int __init maybe_link(void)
75030 if (nlink >= 2) {
75031 char *old = find_link(major, minor, ino, mode, collected);
75032 if (old)
75033- return (sys_link(old, collected) < 0) ? -1 : 1;
75034+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
75035 }
75036 return 0;
75037 }
75038@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
75039 {
75040 struct stat st;
75041
75042- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
75043+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
75044 if (S_ISDIR(st.st_mode))
75045- sys_rmdir(path);
75046+ sys_rmdir((char __force_user *)path);
75047 else
75048- sys_unlink(path);
75049+ sys_unlink((char __force_user *)path);
75050 }
75051 }
75052
75053@@ -315,7 +315,7 @@ static int __init do_name(void)
75054 int openflags = O_WRONLY|O_CREAT;
75055 if (ml != 1)
75056 openflags |= O_TRUNC;
75057- wfd = sys_open(collected, openflags, mode);
75058+ wfd = sys_open((char __force_user *)collected, openflags, mode);
75059
75060 if (wfd >= 0) {
75061 sys_fchown(wfd, uid, gid);
75062@@ -327,17 +327,17 @@ static int __init do_name(void)
75063 }
75064 }
75065 } else if (S_ISDIR(mode)) {
75066- sys_mkdir(collected, mode);
75067- sys_chown(collected, uid, gid);
75068- sys_chmod(collected, mode);
75069+ sys_mkdir((char __force_user *)collected, mode);
75070+ sys_chown((char __force_user *)collected, uid, gid);
75071+ sys_chmod((char __force_user *)collected, mode);
75072 dir_add(collected, mtime);
75073 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
75074 S_ISFIFO(mode) || S_ISSOCK(mode)) {
75075 if (maybe_link() == 0) {
75076- sys_mknod(collected, mode, rdev);
75077- sys_chown(collected, uid, gid);
75078- sys_chmod(collected, mode);
75079- do_utime(collected, mtime);
75080+ sys_mknod((char __force_user *)collected, mode, rdev);
75081+ sys_chown((char __force_user *)collected, uid, gid);
75082+ sys_chmod((char __force_user *)collected, mode);
75083+ do_utime((char __force_user *)collected, mtime);
75084 }
75085 }
75086 return 0;
75087@@ -346,15 +346,15 @@ static int __init do_name(void)
75088 static int __init do_copy(void)
75089 {
75090 if (count >= body_len) {
75091- sys_write(wfd, victim, body_len);
75092+ sys_write(wfd, (char __force_user *)victim, body_len);
75093 sys_close(wfd);
75094- do_utime(vcollected, mtime);
75095+ do_utime((char __force_user *)vcollected, mtime);
75096 kfree(vcollected);
75097 eat(body_len);
75098 state = SkipIt;
75099 return 0;
75100 } else {
75101- sys_write(wfd, victim, count);
75102+ sys_write(wfd, (char __force_user *)victim, count);
75103 body_len -= count;
75104 eat(count);
75105 return 1;
75106@@ -365,9 +365,9 @@ static int __init do_symlink(void)
75107 {
75108 collected[N_ALIGN(name_len) + body_len] = '\0';
75109 clean_path(collected, 0);
75110- sys_symlink(collected + N_ALIGN(name_len), collected);
75111- sys_lchown(collected, uid, gid);
75112- do_utime(collected, mtime);
75113+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
75114+ sys_lchown((char __force_user *)collected, uid, gid);
75115+ do_utime((char __force_user *)collected, mtime);
75116 state = SkipIt;
75117 next_state = Reset;
75118 return 0;
75119@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
75120 {
75121 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
75122 if (err)
75123- panic(err); /* Failed to decompress INTERNAL initramfs */
75124+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
75125 if (initrd_start) {
75126 #ifdef CONFIG_BLK_DEV_RAM
75127 int fd;
75128diff --git a/init/main.c b/init/main.c
75129index 9484f4b..4c01430 100644
75130--- a/init/main.c
75131+++ b/init/main.c
75132@@ -100,6 +100,8 @@ static inline void mark_rodata_ro(void) { }
75133 extern void tc_init(void);
75134 #endif
75135
75136+extern void grsecurity_init(void);
75137+
75138 /*
75139 * Debug helper: via this flag we know that we are in 'early bootup code'
75140 * where only the boot processor is running with IRQ disabled. This means
75141@@ -153,6 +155,64 @@ static int __init set_reset_devices(char *str)
75142
75143 __setup("reset_devices", set_reset_devices);
75144
75145+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75146+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
75147+static int __init setup_grsec_proc_gid(char *str)
75148+{
75149+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
75150+ return 1;
75151+}
75152+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
75153+#endif
75154+
75155+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
75156+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
75157+EXPORT_SYMBOL(pax_user_shadow_base);
75158+extern char pax_enter_kernel_user[];
75159+extern char pax_exit_kernel_user[];
75160+extern pgdval_t clone_pgd_mask;
75161+#endif
75162+
75163+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
75164+static int __init setup_pax_nouderef(char *str)
75165+{
75166+#ifdef CONFIG_X86_32
75167+ unsigned int cpu;
75168+ struct desc_struct *gdt;
75169+
75170+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
75171+ gdt = get_cpu_gdt_table(cpu);
75172+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
75173+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
75174+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
75175+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
75176+ }
75177+ loadsegment(ds, __KERNEL_DS);
75178+ loadsegment(es, __KERNEL_DS);
75179+ loadsegment(ss, __KERNEL_DS);
75180+#else
75181+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
75182+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
75183+ clone_pgd_mask = ~(pgdval_t)0UL;
75184+ pax_user_shadow_base = 0UL;
75185+#endif
75186+
75187+ return 0;
75188+}
75189+early_param("pax_nouderef", setup_pax_nouderef);
75190+#endif
75191+
75192+#ifdef CONFIG_PAX_SOFTMODE
75193+int pax_softmode;
75194+
75195+static int __init setup_pax_softmode(char *str)
75196+{
75197+ get_option(&str, &pax_softmode);
75198+ return 1;
75199+}
75200+__setup("pax_softmode=", setup_pax_softmode);
75201+#endif
75202+
75203 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
75204 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
75205 static const char *panic_later, *panic_param;
75206@@ -655,8 +715,6 @@ static void __init do_ctors(void)
75207 bool initcall_debug;
75208 core_param(initcall_debug, initcall_debug, bool, 0644);
75209
75210-static char msgbuf[64];
75211-
75212 static int __init_or_module do_one_initcall_debug(initcall_t fn)
75213 {
75214 ktime_t calltime, delta, rettime;
75215@@ -679,23 +737,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
75216 {
75217 int count = preempt_count();
75218 int ret;
75219+ const char *msg1 = "", *msg2 = "";
75220
75221 if (initcall_debug)
75222 ret = do_one_initcall_debug(fn);
75223 else
75224 ret = fn();
75225
75226- msgbuf[0] = 0;
75227-
75228 if (preempt_count() != count) {
75229- sprintf(msgbuf, "preemption imbalance ");
75230+ msg1 = " preemption imbalance";
75231 preempt_count() = count;
75232 }
75233 if (irqs_disabled()) {
75234- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
75235+ msg2 = " disabled interrupts";
75236 local_irq_enable();
75237 }
75238- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
75239+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
75240
75241 return ret;
75242 }
75243@@ -748,8 +805,14 @@ static void __init do_initcall_level(int level)
75244 level, level,
75245 &repair_env_string);
75246
75247- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
75248+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
75249 do_one_initcall(*fn);
75250+
75251+#ifdef LATENT_ENTROPY_PLUGIN
75252+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75253+#endif
75254+
75255+ }
75256 }
75257
75258 static void __init do_initcalls(void)
75259@@ -783,8 +846,14 @@ static void __init do_pre_smp_initcalls(void)
75260 {
75261 initcall_t *fn;
75262
75263- for (fn = __initcall_start; fn < __initcall0_start; fn++)
75264+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
75265 do_one_initcall(*fn);
75266+
75267+#ifdef LATENT_ENTROPY_PLUGIN
75268+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
75269+#endif
75270+
75271+ }
75272 }
75273
75274 /*
75275@@ -802,8 +871,8 @@ static int run_init_process(const char *init_filename)
75276 {
75277 argv_init[0] = init_filename;
75278 return do_execve(init_filename,
75279- (const char __user *const __user *)argv_init,
75280- (const char __user *const __user *)envp_init);
75281+ (const char __user *const __force_user *)argv_init,
75282+ (const char __user *const __force_user *)envp_init);
75283 }
75284
75285 static noinline void __init kernel_init_freeable(void);
75286@@ -880,7 +949,7 @@ static noinline void __init kernel_init_freeable(void)
75287 do_basic_setup();
75288
75289 /* Open the /dev/console on the rootfs, this should never fail */
75290- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
75291+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
75292 pr_err("Warning: unable to open an initial console.\n");
75293
75294 (void) sys_dup(0);
75295@@ -893,11 +962,13 @@ static noinline void __init kernel_init_freeable(void)
75296 if (!ramdisk_execute_command)
75297 ramdisk_execute_command = "/init";
75298
75299- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
75300+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
75301 ramdisk_execute_command = NULL;
75302 prepare_namespace();
75303 }
75304
75305+ grsecurity_init();
75306+
75307 /*
75308 * Ok, we have completed the initial bootup, and
75309 * we're essentially up and running. Get rid of the
75310diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
75311index 130dfec..cc88451 100644
75312--- a/ipc/ipc_sysctl.c
75313+++ b/ipc/ipc_sysctl.c
75314@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
75315 static int proc_ipc_dointvec(ctl_table *table, int write,
75316 void __user *buffer, size_t *lenp, loff_t *ppos)
75317 {
75318- struct ctl_table ipc_table;
75319+ ctl_table_no_const ipc_table;
75320
75321 memcpy(&ipc_table, table, sizeof(ipc_table));
75322 ipc_table.data = get_ipc(table);
75323@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
75324 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
75325 void __user *buffer, size_t *lenp, loff_t *ppos)
75326 {
75327- struct ctl_table ipc_table;
75328+ ctl_table_no_const ipc_table;
75329
75330 memcpy(&ipc_table, table, sizeof(ipc_table));
75331 ipc_table.data = get_ipc(table);
75332@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
75333 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
75334 void __user *buffer, size_t *lenp, loff_t *ppos)
75335 {
75336- struct ctl_table ipc_table;
75337+ ctl_table_no_const ipc_table;
75338 size_t lenp_bef = *lenp;
75339 int rc;
75340
75341@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
75342 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
75343 void __user *buffer, size_t *lenp, loff_t *ppos)
75344 {
75345- struct ctl_table ipc_table;
75346+ ctl_table_no_const ipc_table;
75347 memcpy(&ipc_table, table, sizeof(ipc_table));
75348 ipc_table.data = get_ipc(table);
75349
75350@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
75351 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
75352 void __user *buffer, size_t *lenp, loff_t *ppos)
75353 {
75354- struct ctl_table ipc_table;
75355+ ctl_table_no_const ipc_table;
75356 size_t lenp_bef = *lenp;
75357 int oldval;
75358 int rc;
75359diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
75360index 383d638..943fdbb 100644
75361--- a/ipc/mq_sysctl.c
75362+++ b/ipc/mq_sysctl.c
75363@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
75364 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
75365 void __user *buffer, size_t *lenp, loff_t *ppos)
75366 {
75367- struct ctl_table mq_table;
75368+ ctl_table_no_const mq_table;
75369 memcpy(&mq_table, table, sizeof(mq_table));
75370 mq_table.data = get_mq(table);
75371
75372diff --git a/ipc/mqueue.c b/ipc/mqueue.c
75373index e4e47f6..a85e0ad 100644
75374--- a/ipc/mqueue.c
75375+++ b/ipc/mqueue.c
75376@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
75377 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
75378 info->attr.mq_msgsize);
75379
75380+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
75381 spin_lock(&mq_lock);
75382 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
75383 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
75384diff --git a/ipc/msg.c b/ipc/msg.c
75385index d0c6d96..69a893c 100644
75386--- a/ipc/msg.c
75387+++ b/ipc/msg.c
75388@@ -296,18 +296,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
75389 return security_msg_queue_associate(msq, msgflg);
75390 }
75391
75392+static struct ipc_ops msg_ops = {
75393+ .getnew = newque,
75394+ .associate = msg_security,
75395+ .more_checks = NULL
75396+};
75397+
75398 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
75399 {
75400 struct ipc_namespace *ns;
75401- struct ipc_ops msg_ops;
75402 struct ipc_params msg_params;
75403
75404 ns = current->nsproxy->ipc_ns;
75405
75406- msg_ops.getnew = newque;
75407- msg_ops.associate = msg_security;
75408- msg_ops.more_checks = NULL;
75409-
75410 msg_params.key = key;
75411 msg_params.flg = msgflg;
75412
75413diff --git a/ipc/sem.c b/ipc/sem.c
75414index 70480a3..f4e8262 100644
75415--- a/ipc/sem.c
75416+++ b/ipc/sem.c
75417@@ -460,10 +460,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
75418 return 0;
75419 }
75420
75421+static struct ipc_ops sem_ops = {
75422+ .getnew = newary,
75423+ .associate = sem_security,
75424+ .more_checks = sem_more_checks
75425+};
75426+
75427 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
75428 {
75429 struct ipc_namespace *ns;
75430- struct ipc_ops sem_ops;
75431 struct ipc_params sem_params;
75432
75433 ns = current->nsproxy->ipc_ns;
75434@@ -471,10 +476,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
75435 if (nsems < 0 || nsems > ns->sc_semmsl)
75436 return -EINVAL;
75437
75438- sem_ops.getnew = newary;
75439- sem_ops.associate = sem_security;
75440- sem_ops.more_checks = sem_more_checks;
75441-
75442 sem_params.key = key;
75443 sem_params.flg = semflg;
75444 sem_params.u.nsems = nsems;
75445diff --git a/ipc/shm.c b/ipc/shm.c
75446index 7e199fa..180a1ca 100644
75447--- a/ipc/shm.c
75448+++ b/ipc/shm.c
75449@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
75450 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
75451 #endif
75452
75453+#ifdef CONFIG_GRKERNSEC
75454+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75455+ const time_t shm_createtime, const kuid_t cuid,
75456+ const int shmid);
75457+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75458+ const time_t shm_createtime);
75459+#endif
75460+
75461 void shm_init_ns(struct ipc_namespace *ns)
75462 {
75463 ns->shm_ctlmax = SHMMAX;
75464@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
75465 shp->shm_lprid = 0;
75466 shp->shm_atim = shp->shm_dtim = 0;
75467 shp->shm_ctim = get_seconds();
75468+#ifdef CONFIG_GRKERNSEC
75469+ {
75470+ struct timespec timeval;
75471+ do_posix_clock_monotonic_gettime(&timeval);
75472+
75473+ shp->shm_createtime = timeval.tv_sec;
75474+ }
75475+#endif
75476 shp->shm_segsz = size;
75477 shp->shm_nattch = 0;
75478 shp->shm_file = file;
75479@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
75480 return 0;
75481 }
75482
75483+static struct ipc_ops shm_ops = {
75484+ .getnew = newseg,
75485+ .associate = shm_security,
75486+ .more_checks = shm_more_checks
75487+};
75488+
75489 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
75490 {
75491 struct ipc_namespace *ns;
75492- struct ipc_ops shm_ops;
75493 struct ipc_params shm_params;
75494
75495 ns = current->nsproxy->ipc_ns;
75496
75497- shm_ops.getnew = newseg;
75498- shm_ops.associate = shm_security;
75499- shm_ops.more_checks = shm_more_checks;
75500-
75501 shm_params.key = key;
75502 shm_params.flg = shmflg;
75503 shm_params.u.size = size;
75504@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
75505 f_mode = FMODE_READ | FMODE_WRITE;
75506 }
75507 if (shmflg & SHM_EXEC) {
75508+
75509+#ifdef CONFIG_PAX_MPROTECT
75510+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
75511+ goto out;
75512+#endif
75513+
75514 prot |= PROT_EXEC;
75515 acc_mode |= S_IXUGO;
75516 }
75517@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
75518 if (err)
75519 goto out_unlock;
75520
75521+#ifdef CONFIG_GRKERNSEC
75522+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
75523+ shp->shm_perm.cuid, shmid) ||
75524+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
75525+ err = -EACCES;
75526+ goto out_unlock;
75527+ }
75528+#endif
75529+
75530 path = shp->shm_file->f_path;
75531 path_get(&path);
75532 shp->shm_nattch++;
75533+#ifdef CONFIG_GRKERNSEC
75534+ shp->shm_lapid = current->pid;
75535+#endif
75536 size = i_size_read(path.dentry->d_inode);
75537 shm_unlock(shp);
75538
75539diff --git a/kernel/acct.c b/kernel/acct.c
75540index 8d6e145..33e0b1e 100644
75541--- a/kernel/acct.c
75542+++ b/kernel/acct.c
75543@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
75544 */
75545 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
75546 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
75547- file->f_op->write(file, (char *)&ac,
75548+ file->f_op->write(file, (char __force_user *)&ac,
75549 sizeof(acct_t), &file->f_pos);
75550 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
75551 set_fs(fs);
75552diff --git a/kernel/audit.c b/kernel/audit.c
75553index 91e53d0..d9e3ec4 100644
75554--- a/kernel/audit.c
75555+++ b/kernel/audit.c
75556@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
75557 3) suppressed due to audit_rate_limit
75558 4) suppressed due to audit_backlog_limit
75559 */
75560-static atomic_t audit_lost = ATOMIC_INIT(0);
75561+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
75562
75563 /* The netlink socket. */
75564 static struct sock *audit_sock;
75565@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
75566 unsigned long now;
75567 int print;
75568
75569- atomic_inc(&audit_lost);
75570+ atomic_inc_unchecked(&audit_lost);
75571
75572 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
75573
75574@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
75575 printk(KERN_WARNING
75576 "audit: audit_lost=%d audit_rate_limit=%d "
75577 "audit_backlog_limit=%d\n",
75578- atomic_read(&audit_lost),
75579+ atomic_read_unchecked(&audit_lost),
75580 audit_rate_limit,
75581 audit_backlog_limit);
75582 audit_panic(message);
75583@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
75584 status_set.pid = audit_pid;
75585 status_set.rate_limit = audit_rate_limit;
75586 status_set.backlog_limit = audit_backlog_limit;
75587- status_set.lost = atomic_read(&audit_lost);
75588+ status_set.lost = atomic_read_unchecked(&audit_lost);
75589 status_set.backlog = skb_queue_len(&audit_skb_queue);
75590 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
75591 &status_set, sizeof(status_set));
75592diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
75593index 6bd4a90..0ee9eff 100644
75594--- a/kernel/auditfilter.c
75595+++ b/kernel/auditfilter.c
75596@@ -423,7 +423,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
75597 f->lsm_rule = NULL;
75598
75599 /* Support legacy tests for a valid loginuid */
75600- if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295)) {
75601+ if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295U)) {
75602 f->type = AUDIT_LOGINUID_SET;
75603 f->val = 0;
75604 }
75605diff --git a/kernel/auditsc.c b/kernel/auditsc.c
75606index 3c8a601..3a416f6 100644
75607--- a/kernel/auditsc.c
75608+++ b/kernel/auditsc.c
75609@@ -1956,7 +1956,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
75610 }
75611
75612 /* global counter which is incremented every time something logs in */
75613-static atomic_t session_id = ATOMIC_INIT(0);
75614+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
75615
75616 /**
75617 * audit_set_loginuid - set current task's audit_context loginuid
75618@@ -1980,7 +1980,7 @@ int audit_set_loginuid(kuid_t loginuid)
75619 return -EPERM;
75620 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
75621
75622- sessionid = atomic_inc_return(&session_id);
75623+ sessionid = atomic_inc_return_unchecked(&session_id);
75624 if (context && context->in_syscall) {
75625 struct audit_buffer *ab;
75626
75627diff --git a/kernel/capability.c b/kernel/capability.c
75628index f6c2ce5..982c0f9 100644
75629--- a/kernel/capability.c
75630+++ b/kernel/capability.c
75631@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
75632 * before modification is attempted and the application
75633 * fails.
75634 */
75635+ if (tocopy > ARRAY_SIZE(kdata))
75636+ return -EFAULT;
75637+
75638 if (copy_to_user(dataptr, kdata, tocopy
75639 * sizeof(struct __user_cap_data_struct))) {
75640 return -EFAULT;
75641@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
75642 int ret;
75643
75644 rcu_read_lock();
75645- ret = security_capable(__task_cred(t), ns, cap);
75646+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
75647+ gr_task_is_capable(t, __task_cred(t), cap);
75648 rcu_read_unlock();
75649
75650- return (ret == 0);
75651+ return ret;
75652 }
75653
75654 /**
75655@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
75656 int ret;
75657
75658 rcu_read_lock();
75659- ret = security_capable_noaudit(__task_cred(t), ns, cap);
75660+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
75661 rcu_read_unlock();
75662
75663- return (ret == 0);
75664+ return ret;
75665 }
75666
75667 /**
75668@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
75669 BUG();
75670 }
75671
75672- if (security_capable(current_cred(), ns, cap) == 0) {
75673+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
75674 current->flags |= PF_SUPERPRIV;
75675 return true;
75676 }
75677@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
75678 }
75679 EXPORT_SYMBOL(ns_capable);
75680
75681+bool ns_capable_nolog(struct user_namespace *ns, int cap)
75682+{
75683+ if (unlikely(!cap_valid(cap))) {
75684+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
75685+ BUG();
75686+ }
75687+
75688+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
75689+ current->flags |= PF_SUPERPRIV;
75690+ return true;
75691+ }
75692+ return false;
75693+}
75694+EXPORT_SYMBOL(ns_capable_nolog);
75695+
75696 /**
75697 * file_ns_capable - Determine if the file's opener had a capability in effect
75698 * @file: The file we want to check
75699@@ -432,6 +451,12 @@ bool capable(int cap)
75700 }
75701 EXPORT_SYMBOL(capable);
75702
75703+bool capable_nolog(int cap)
75704+{
75705+ return ns_capable_nolog(&init_user_ns, cap);
75706+}
75707+EXPORT_SYMBOL(capable_nolog);
75708+
75709 /**
75710 * nsown_capable - Check superior capability to one's own user_ns
75711 * @cap: The capability in question
75712@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
75713
75714 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
75715 }
75716+
75717+bool inode_capable_nolog(const struct inode *inode, int cap)
75718+{
75719+ struct user_namespace *ns = current_user_ns();
75720+
75721+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
75722+}
75723diff --git a/kernel/cgroup.c b/kernel/cgroup.c
75724index c6e77ef..af531a0 100644
75725--- a/kernel/cgroup.c
75726+++ b/kernel/cgroup.c
75727@@ -5391,7 +5391,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
75728 struct css_set *cg = link->cg;
75729 struct task_struct *task;
75730 int count = 0;
75731- seq_printf(seq, "css_set %p\n", cg);
75732+ seq_printf(seq, "css_set %pK\n", cg);
75733 list_for_each_entry(task, &cg->tasks, cg_list) {
75734 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
75735 seq_puts(seq, " ...\n");
75736diff --git a/kernel/compat.c b/kernel/compat.c
75737index 0a09e48..f44f3f0 100644
75738--- a/kernel/compat.c
75739+++ b/kernel/compat.c
75740@@ -13,6 +13,7 @@
75741
75742 #include <linux/linkage.h>
75743 #include <linux/compat.h>
75744+#include <linux/module.h>
75745 #include <linux/errno.h>
75746 #include <linux/time.h>
75747 #include <linux/signal.h>
75748@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
75749 mm_segment_t oldfs;
75750 long ret;
75751
75752- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
75753+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
75754 oldfs = get_fs();
75755 set_fs(KERNEL_DS);
75756 ret = hrtimer_nanosleep_restart(restart);
75757@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
75758 oldfs = get_fs();
75759 set_fs(KERNEL_DS);
75760 ret = hrtimer_nanosleep(&tu,
75761- rmtp ? (struct timespec __user *)&rmt : NULL,
75762+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
75763 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
75764 set_fs(oldfs);
75765
75766@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
75767 mm_segment_t old_fs = get_fs();
75768
75769 set_fs(KERNEL_DS);
75770- ret = sys_sigpending((old_sigset_t __user *) &s);
75771+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
75772 set_fs(old_fs);
75773 if (ret == 0)
75774 ret = put_user(s, set);
75775@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
75776 mm_segment_t old_fs = get_fs();
75777
75778 set_fs(KERNEL_DS);
75779- ret = sys_old_getrlimit(resource, &r);
75780+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
75781 set_fs(old_fs);
75782
75783 if (!ret) {
75784@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
75785 set_fs (KERNEL_DS);
75786 ret = sys_wait4(pid,
75787 (stat_addr ?
75788- (unsigned int __user *) &status : NULL),
75789- options, (struct rusage __user *) &r);
75790+ (unsigned int __force_user *) &status : NULL),
75791+ options, (struct rusage __force_user *) &r);
75792 set_fs (old_fs);
75793
75794 if (ret > 0) {
75795@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
75796 memset(&info, 0, sizeof(info));
75797
75798 set_fs(KERNEL_DS);
75799- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
75800- uru ? (struct rusage __user *)&ru : NULL);
75801+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
75802+ uru ? (struct rusage __force_user *)&ru : NULL);
75803 set_fs(old_fs);
75804
75805 if ((ret < 0) || (info.si_signo == 0))
75806@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
75807 oldfs = get_fs();
75808 set_fs(KERNEL_DS);
75809 err = sys_timer_settime(timer_id, flags,
75810- (struct itimerspec __user *) &newts,
75811- (struct itimerspec __user *) &oldts);
75812+ (struct itimerspec __force_user *) &newts,
75813+ (struct itimerspec __force_user *) &oldts);
75814 set_fs(oldfs);
75815 if (!err && old && put_compat_itimerspec(old, &oldts))
75816 return -EFAULT;
75817@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
75818 oldfs = get_fs();
75819 set_fs(KERNEL_DS);
75820 err = sys_timer_gettime(timer_id,
75821- (struct itimerspec __user *) &ts);
75822+ (struct itimerspec __force_user *) &ts);
75823 set_fs(oldfs);
75824 if (!err && put_compat_itimerspec(setting, &ts))
75825 return -EFAULT;
75826@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
75827 oldfs = get_fs();
75828 set_fs(KERNEL_DS);
75829 err = sys_clock_settime(which_clock,
75830- (struct timespec __user *) &ts);
75831+ (struct timespec __force_user *) &ts);
75832 set_fs(oldfs);
75833 return err;
75834 }
75835@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
75836 oldfs = get_fs();
75837 set_fs(KERNEL_DS);
75838 err = sys_clock_gettime(which_clock,
75839- (struct timespec __user *) &ts);
75840+ (struct timespec __force_user *) &ts);
75841 set_fs(oldfs);
75842 if (!err && put_compat_timespec(&ts, tp))
75843 return -EFAULT;
75844@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
75845
75846 oldfs = get_fs();
75847 set_fs(KERNEL_DS);
75848- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
75849+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
75850 set_fs(oldfs);
75851
75852 err = compat_put_timex(utp, &txc);
75853@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
75854 oldfs = get_fs();
75855 set_fs(KERNEL_DS);
75856 err = sys_clock_getres(which_clock,
75857- (struct timespec __user *) &ts);
75858+ (struct timespec __force_user *) &ts);
75859 set_fs(oldfs);
75860 if (!err && tp && put_compat_timespec(&ts, tp))
75861 return -EFAULT;
75862@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
75863 long err;
75864 mm_segment_t oldfs;
75865 struct timespec tu;
75866- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
75867+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
75868
75869- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
75870+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
75871 oldfs = get_fs();
75872 set_fs(KERNEL_DS);
75873 err = clock_nanosleep_restart(restart);
75874@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
75875 oldfs = get_fs();
75876 set_fs(KERNEL_DS);
75877 err = sys_clock_nanosleep(which_clock, flags,
75878- (struct timespec __user *) &in,
75879- (struct timespec __user *) &out);
75880+ (struct timespec __force_user *) &in,
75881+ (struct timespec __force_user *) &out);
75882 set_fs(oldfs);
75883
75884 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
75885diff --git a/kernel/configs.c b/kernel/configs.c
75886index c18b1f1..b9a0132 100644
75887--- a/kernel/configs.c
75888+++ b/kernel/configs.c
75889@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
75890 struct proc_dir_entry *entry;
75891
75892 /* create the current config file */
75893+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
75894+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
75895+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
75896+ &ikconfig_file_ops);
75897+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75898+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
75899+ &ikconfig_file_ops);
75900+#endif
75901+#else
75902 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
75903 &ikconfig_file_ops);
75904+#endif
75905+
75906 if (!entry)
75907 return -ENOMEM;
75908
75909diff --git a/kernel/cred.c b/kernel/cred.c
75910index e0573a4..3874e41 100644
75911--- a/kernel/cred.c
75912+++ b/kernel/cred.c
75913@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
75914 validate_creds(cred);
75915 alter_cred_subscribers(cred, -1);
75916 put_cred(cred);
75917+
75918+#ifdef CONFIG_GRKERNSEC_SETXID
75919+ cred = (struct cred *) tsk->delayed_cred;
75920+ if (cred != NULL) {
75921+ tsk->delayed_cred = NULL;
75922+ validate_creds(cred);
75923+ alter_cred_subscribers(cred, -1);
75924+ put_cred(cred);
75925+ }
75926+#endif
75927 }
75928
75929 /**
75930@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
75931 * Always returns 0 thus allowing this function to be tail-called at the end
75932 * of, say, sys_setgid().
75933 */
75934-int commit_creds(struct cred *new)
75935+static int __commit_creds(struct cred *new)
75936 {
75937 struct task_struct *task = current;
75938 const struct cred *old = task->real_cred;
75939@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
75940
75941 get_cred(new); /* we will require a ref for the subj creds too */
75942
75943+ gr_set_role_label(task, new->uid, new->gid);
75944+
75945 /* dumpability changes */
75946 if (!uid_eq(old->euid, new->euid) ||
75947 !gid_eq(old->egid, new->egid) ||
75948@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
75949 put_cred(old);
75950 return 0;
75951 }
75952+#ifdef CONFIG_GRKERNSEC_SETXID
75953+extern int set_user(struct cred *new);
75954+
75955+void gr_delayed_cred_worker(void)
75956+{
75957+ const struct cred *new = current->delayed_cred;
75958+ struct cred *ncred;
75959+
75960+ current->delayed_cred = NULL;
75961+
75962+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
75963+ // from doing get_cred on it when queueing this
75964+ put_cred(new);
75965+ return;
75966+ } else if (new == NULL)
75967+ return;
75968+
75969+ ncred = prepare_creds();
75970+ if (!ncred)
75971+ goto die;
75972+ // uids
75973+ ncred->uid = new->uid;
75974+ ncred->euid = new->euid;
75975+ ncred->suid = new->suid;
75976+ ncred->fsuid = new->fsuid;
75977+ // gids
75978+ ncred->gid = new->gid;
75979+ ncred->egid = new->egid;
75980+ ncred->sgid = new->sgid;
75981+ ncred->fsgid = new->fsgid;
75982+ // groups
75983+ if (set_groups(ncred, new->group_info) < 0) {
75984+ abort_creds(ncred);
75985+ goto die;
75986+ }
75987+ // caps
75988+ ncred->securebits = new->securebits;
75989+ ncred->cap_inheritable = new->cap_inheritable;
75990+ ncred->cap_permitted = new->cap_permitted;
75991+ ncred->cap_effective = new->cap_effective;
75992+ ncred->cap_bset = new->cap_bset;
75993+
75994+ if (set_user(ncred)) {
75995+ abort_creds(ncred);
75996+ goto die;
75997+ }
75998+
75999+ // from doing get_cred on it when queueing this
76000+ put_cred(new);
76001+
76002+ __commit_creds(ncred);
76003+ return;
76004+die:
76005+ // from doing get_cred on it when queueing this
76006+ put_cred(new);
76007+ do_group_exit(SIGKILL);
76008+}
76009+#endif
76010+
76011+int commit_creds(struct cred *new)
76012+{
76013+#ifdef CONFIG_GRKERNSEC_SETXID
76014+ int ret;
76015+ int schedule_it = 0;
76016+ struct task_struct *t;
76017+
76018+ /* we won't get called with tasklist_lock held for writing
76019+ and interrupts disabled as the cred struct in that case is
76020+ init_cred
76021+ */
76022+ if (grsec_enable_setxid && !current_is_single_threaded() &&
76023+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
76024+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
76025+ schedule_it = 1;
76026+ }
76027+ ret = __commit_creds(new);
76028+ if (schedule_it) {
76029+ rcu_read_lock();
76030+ read_lock(&tasklist_lock);
76031+ for (t = next_thread(current); t != current;
76032+ t = next_thread(t)) {
76033+ if (t->delayed_cred == NULL) {
76034+ t->delayed_cred = get_cred(new);
76035+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
76036+ set_tsk_need_resched(t);
76037+ }
76038+ }
76039+ read_unlock(&tasklist_lock);
76040+ rcu_read_unlock();
76041+ }
76042+ return ret;
76043+#else
76044+ return __commit_creds(new);
76045+#endif
76046+}
76047+
76048 EXPORT_SYMBOL(commit_creds);
76049
76050 /**
76051diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
76052index 0506d44..2c20034 100644
76053--- a/kernel/debug/debug_core.c
76054+++ b/kernel/debug/debug_core.c
76055@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
76056 */
76057 static atomic_t masters_in_kgdb;
76058 static atomic_t slaves_in_kgdb;
76059-static atomic_t kgdb_break_tasklet_var;
76060+static atomic_unchecked_t kgdb_break_tasklet_var;
76061 atomic_t kgdb_setting_breakpoint;
76062
76063 struct task_struct *kgdb_usethread;
76064@@ -133,7 +133,7 @@ int kgdb_single_step;
76065 static pid_t kgdb_sstep_pid;
76066
76067 /* to keep track of the CPU which is doing the single stepping*/
76068-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
76069+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
76070
76071 /*
76072 * If you are debugging a problem where roundup (the collection of
76073@@ -541,7 +541,7 @@ return_normal:
76074 * kernel will only try for the value of sstep_tries before
76075 * giving up and continuing on.
76076 */
76077- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
76078+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
76079 (kgdb_info[cpu].task &&
76080 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
76081 atomic_set(&kgdb_active, -1);
76082@@ -635,8 +635,8 @@ cpu_master_loop:
76083 }
76084
76085 kgdb_restore:
76086- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
76087- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
76088+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
76089+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
76090 if (kgdb_info[sstep_cpu].task)
76091 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
76092 else
76093@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
76094 static void kgdb_tasklet_bpt(unsigned long ing)
76095 {
76096 kgdb_breakpoint();
76097- atomic_set(&kgdb_break_tasklet_var, 0);
76098+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
76099 }
76100
76101 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
76102
76103 void kgdb_schedule_breakpoint(void)
76104 {
76105- if (atomic_read(&kgdb_break_tasklet_var) ||
76106+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
76107 atomic_read(&kgdb_active) != -1 ||
76108 atomic_read(&kgdb_setting_breakpoint))
76109 return;
76110- atomic_inc(&kgdb_break_tasklet_var);
76111+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
76112 tasklet_schedule(&kgdb_tasklet_breakpoint);
76113 }
76114 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
76115diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
76116index 00eb8f7..d7e3244 100644
76117--- a/kernel/debug/kdb/kdb_main.c
76118+++ b/kernel/debug/kdb/kdb_main.c
76119@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
76120 continue;
76121
76122 kdb_printf("%-20s%8u 0x%p ", mod->name,
76123- mod->core_size, (void *)mod);
76124+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
76125 #ifdef CONFIG_MODULE_UNLOAD
76126 kdb_printf("%4ld ", module_refcount(mod));
76127 #endif
76128@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
76129 kdb_printf(" (Loading)");
76130 else
76131 kdb_printf(" (Live)");
76132- kdb_printf(" 0x%p", mod->module_core);
76133+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
76134
76135 #ifdef CONFIG_MODULE_UNLOAD
76136 {
76137diff --git a/kernel/events/core.c b/kernel/events/core.c
76138index e76e495..cbfe63a 100644
76139--- a/kernel/events/core.c
76140+++ b/kernel/events/core.c
76141@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
76142 * 0 - disallow raw tracepoint access for unpriv
76143 * 1 - disallow cpu events for unpriv
76144 * 2 - disallow kernel profiling for unpriv
76145+ * 3 - disallow all unpriv perf event use
76146 */
76147-int sysctl_perf_event_paranoid __read_mostly = 1;
76148+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
76149+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
76150+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
76151+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
76152+#else
76153+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
76154+#endif
76155
76156 /* Minimum for 512 kiB + 1 user control page */
76157 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
76158@@ -184,7 +191,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
76159 return 0;
76160 }
76161
76162-static atomic64_t perf_event_id;
76163+static atomic64_unchecked_t perf_event_id;
76164
76165 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
76166 enum event_type_t event_type);
76167@@ -2747,7 +2754,7 @@ static void __perf_event_read(void *info)
76168
76169 static inline u64 perf_event_count(struct perf_event *event)
76170 {
76171- return local64_read(&event->count) + atomic64_read(&event->child_count);
76172+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
76173 }
76174
76175 static u64 perf_event_read(struct perf_event *event)
76176@@ -3093,9 +3100,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
76177 mutex_lock(&event->child_mutex);
76178 total += perf_event_read(event);
76179 *enabled += event->total_time_enabled +
76180- atomic64_read(&event->child_total_time_enabled);
76181+ atomic64_read_unchecked(&event->child_total_time_enabled);
76182 *running += event->total_time_running +
76183- atomic64_read(&event->child_total_time_running);
76184+ atomic64_read_unchecked(&event->child_total_time_running);
76185
76186 list_for_each_entry(child, &event->child_list, child_list) {
76187 total += perf_event_read(child);
76188@@ -3481,10 +3488,10 @@ void perf_event_update_userpage(struct perf_event *event)
76189 userpg->offset -= local64_read(&event->hw.prev_count);
76190
76191 userpg->time_enabled = enabled +
76192- atomic64_read(&event->child_total_time_enabled);
76193+ atomic64_read_unchecked(&event->child_total_time_enabled);
76194
76195 userpg->time_running = running +
76196- atomic64_read(&event->child_total_time_running);
76197+ atomic64_read_unchecked(&event->child_total_time_running);
76198
76199 arch_perf_update_userpage(userpg, now);
76200
76201@@ -4034,7 +4041,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
76202
76203 /* Data. */
76204 sp = perf_user_stack_pointer(regs);
76205- rem = __output_copy_user(handle, (void *) sp, dump_size);
76206+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
76207 dyn_size = dump_size - rem;
76208
76209 perf_output_skip(handle, rem);
76210@@ -4122,11 +4129,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
76211 values[n++] = perf_event_count(event);
76212 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
76213 values[n++] = enabled +
76214- atomic64_read(&event->child_total_time_enabled);
76215+ atomic64_read_unchecked(&event->child_total_time_enabled);
76216 }
76217 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
76218 values[n++] = running +
76219- atomic64_read(&event->child_total_time_running);
76220+ atomic64_read_unchecked(&event->child_total_time_running);
76221 }
76222 if (read_format & PERF_FORMAT_ID)
76223 values[n++] = primary_event_id(event);
76224@@ -4835,12 +4842,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
76225 * need to add enough zero bytes after the string to handle
76226 * the 64bit alignment we do later.
76227 */
76228- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
76229+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
76230 if (!buf) {
76231 name = strncpy(tmp, "//enomem", sizeof(tmp));
76232 goto got_name;
76233 }
76234- name = d_path(&file->f_path, buf, PATH_MAX);
76235+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
76236 if (IS_ERR(name)) {
76237 name = strncpy(tmp, "//toolong", sizeof(tmp));
76238 goto got_name;
76239@@ -6262,7 +6269,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
76240 event->parent = parent_event;
76241
76242 event->ns = get_pid_ns(task_active_pid_ns(current));
76243- event->id = atomic64_inc_return(&perf_event_id);
76244+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
76245
76246 event->state = PERF_EVENT_STATE_INACTIVE;
76247
76248@@ -6572,6 +6579,11 @@ SYSCALL_DEFINE5(perf_event_open,
76249 if (flags & ~PERF_FLAG_ALL)
76250 return -EINVAL;
76251
76252+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
76253+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
76254+ return -EACCES;
76255+#endif
76256+
76257 err = perf_copy_attr(attr_uptr, &attr);
76258 if (err)
76259 return err;
76260@@ -6904,10 +6916,10 @@ static void sync_child_event(struct perf_event *child_event,
76261 /*
76262 * Add back the child's count to the parent's count:
76263 */
76264- atomic64_add(child_val, &parent_event->child_count);
76265- atomic64_add(child_event->total_time_enabled,
76266+ atomic64_add_unchecked(child_val, &parent_event->child_count);
76267+ atomic64_add_unchecked(child_event->total_time_enabled,
76268 &parent_event->child_total_time_enabled);
76269- atomic64_add(child_event->total_time_running,
76270+ atomic64_add_unchecked(child_event->total_time_running,
76271 &parent_event->child_total_time_running);
76272
76273 /*
76274diff --git a/kernel/events/internal.h b/kernel/events/internal.h
76275index ca65997..cc8cee4 100644
76276--- a/kernel/events/internal.h
76277+++ b/kernel/events/internal.h
76278@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
76279 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
76280 }
76281
76282-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
76283+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
76284 static inline unsigned int \
76285 func_name(struct perf_output_handle *handle, \
76286- const void *buf, unsigned int len) \
76287+ const void user *buf, unsigned int len) \
76288 { \
76289 unsigned long size, written; \
76290 \
76291@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
76292 return n;
76293 }
76294
76295-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
76296+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
76297
76298 #define MEMCPY_SKIP(dst, src, n) (n)
76299
76300-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
76301+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
76302
76303 #ifndef arch_perf_out_copy_user
76304 #define arch_perf_out_copy_user __copy_from_user_inatomic
76305 #endif
76306
76307-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
76308+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
76309
76310 /* Callchain handling */
76311 extern struct perf_callchain_entry *
76312diff --git a/kernel/exit.c b/kernel/exit.c
76313index 7bb73f9..d7978ed 100644
76314--- a/kernel/exit.c
76315+++ b/kernel/exit.c
76316@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
76317 struct task_struct *leader;
76318 int zap_leader;
76319 repeat:
76320+#ifdef CONFIG_NET
76321+ gr_del_task_from_ip_table(p);
76322+#endif
76323+
76324 /* don't need to get the RCU readlock here - the process is dead and
76325 * can't be modifying its own credentials. But shut RCU-lockdep up */
76326 rcu_read_lock();
76327@@ -340,7 +344,7 @@ int allow_signal(int sig)
76328 * know it'll be handled, so that they don't get converted to
76329 * SIGKILL or just silently dropped.
76330 */
76331- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
76332+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
76333 recalc_sigpending();
76334 spin_unlock_irq(&current->sighand->siglock);
76335 return 0;
76336@@ -709,6 +713,8 @@ void do_exit(long code)
76337 struct task_struct *tsk = current;
76338 int group_dead;
76339
76340+ set_fs(USER_DS);
76341+
76342 profile_task_exit(tsk);
76343
76344 WARN_ON(blk_needs_flush_plug(tsk));
76345@@ -725,7 +731,6 @@ void do_exit(long code)
76346 * mm_release()->clear_child_tid() from writing to a user-controlled
76347 * kernel address.
76348 */
76349- set_fs(USER_DS);
76350
76351 ptrace_event(PTRACE_EVENT_EXIT, code);
76352
76353@@ -784,6 +789,9 @@ void do_exit(long code)
76354 tsk->exit_code = code;
76355 taskstats_exit(tsk, group_dead);
76356
76357+ gr_acl_handle_psacct(tsk, code);
76358+ gr_acl_handle_exit();
76359+
76360 exit_mm(tsk);
76361
76362 if (group_dead)
76363@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
76364 * Take down every thread in the group. This is called by fatal signals
76365 * as well as by sys_exit_group (below).
76366 */
76367-void
76368+__noreturn void
76369 do_group_exit(int exit_code)
76370 {
76371 struct signal_struct *sig = current->signal;
76372diff --git a/kernel/fork.c b/kernel/fork.c
76373index 987b28a..11ee8a5 100644
76374--- a/kernel/fork.c
76375+++ b/kernel/fork.c
76376@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
76377 *stackend = STACK_END_MAGIC; /* for overflow detection */
76378
76379 #ifdef CONFIG_CC_STACKPROTECTOR
76380- tsk->stack_canary = get_random_int();
76381+ tsk->stack_canary = pax_get_random_long();
76382 #endif
76383
76384 /*
76385@@ -345,13 +345,81 @@ free_tsk:
76386 }
76387
76388 #ifdef CONFIG_MMU
76389+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
76390+{
76391+ struct vm_area_struct *tmp;
76392+ unsigned long charge;
76393+ struct mempolicy *pol;
76394+ struct file *file;
76395+
76396+ charge = 0;
76397+ if (mpnt->vm_flags & VM_ACCOUNT) {
76398+ unsigned long len = vma_pages(mpnt);
76399+
76400+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
76401+ goto fail_nomem;
76402+ charge = len;
76403+ }
76404+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76405+ if (!tmp)
76406+ goto fail_nomem;
76407+ *tmp = *mpnt;
76408+ tmp->vm_mm = mm;
76409+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
76410+ pol = mpol_dup(vma_policy(mpnt));
76411+ if (IS_ERR(pol))
76412+ goto fail_nomem_policy;
76413+ vma_set_policy(tmp, pol);
76414+ if (anon_vma_fork(tmp, mpnt))
76415+ goto fail_nomem_anon_vma_fork;
76416+ tmp->vm_flags &= ~VM_LOCKED;
76417+ tmp->vm_next = tmp->vm_prev = NULL;
76418+ tmp->vm_mirror = NULL;
76419+ file = tmp->vm_file;
76420+ if (file) {
76421+ struct inode *inode = file_inode(file);
76422+ struct address_space *mapping = file->f_mapping;
76423+
76424+ get_file(file);
76425+ if (tmp->vm_flags & VM_DENYWRITE)
76426+ atomic_dec(&inode->i_writecount);
76427+ mutex_lock(&mapping->i_mmap_mutex);
76428+ if (tmp->vm_flags & VM_SHARED)
76429+ mapping->i_mmap_writable++;
76430+ flush_dcache_mmap_lock(mapping);
76431+ /* insert tmp into the share list, just after mpnt */
76432+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
76433+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
76434+ else
76435+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
76436+ flush_dcache_mmap_unlock(mapping);
76437+ mutex_unlock(&mapping->i_mmap_mutex);
76438+ }
76439+
76440+ /*
76441+ * Clear hugetlb-related page reserves for children. This only
76442+ * affects MAP_PRIVATE mappings. Faults generated by the child
76443+ * are not guaranteed to succeed, even if read-only
76444+ */
76445+ if (is_vm_hugetlb_page(tmp))
76446+ reset_vma_resv_huge_pages(tmp);
76447+
76448+ return tmp;
76449+
76450+fail_nomem_anon_vma_fork:
76451+ mpol_put(pol);
76452+fail_nomem_policy:
76453+ kmem_cache_free(vm_area_cachep, tmp);
76454+fail_nomem:
76455+ vm_unacct_memory(charge);
76456+ return NULL;
76457+}
76458+
76459 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
76460 {
76461 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
76462 struct rb_node **rb_link, *rb_parent;
76463 int retval;
76464- unsigned long charge;
76465- struct mempolicy *pol;
76466
76467 uprobe_start_dup_mmap();
76468 down_write(&oldmm->mmap_sem);
76469@@ -365,8 +433,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
76470 mm->locked_vm = 0;
76471 mm->mmap = NULL;
76472 mm->mmap_cache = NULL;
76473- mm->free_area_cache = oldmm->mmap_base;
76474- mm->cached_hole_size = ~0UL;
76475+ mm->free_area_cache = oldmm->free_area_cache;
76476+ mm->cached_hole_size = oldmm->cached_hole_size;
76477 mm->map_count = 0;
76478 cpumask_clear(mm_cpumask(mm));
76479 mm->mm_rb = RB_ROOT;
76480@@ -382,57 +450,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
76481
76482 prev = NULL;
76483 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
76484- struct file *file;
76485-
76486 if (mpnt->vm_flags & VM_DONTCOPY) {
76487 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
76488 -vma_pages(mpnt));
76489 continue;
76490 }
76491- charge = 0;
76492- if (mpnt->vm_flags & VM_ACCOUNT) {
76493- unsigned long len = vma_pages(mpnt);
76494-
76495- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
76496- goto fail_nomem;
76497- charge = len;
76498- }
76499- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
76500- if (!tmp)
76501- goto fail_nomem;
76502- *tmp = *mpnt;
76503- INIT_LIST_HEAD(&tmp->anon_vma_chain);
76504- pol = mpol_dup(vma_policy(mpnt));
76505- retval = PTR_ERR(pol);
76506- if (IS_ERR(pol))
76507- goto fail_nomem_policy;
76508- vma_set_policy(tmp, pol);
76509- tmp->vm_mm = mm;
76510- if (anon_vma_fork(tmp, mpnt))
76511- goto fail_nomem_anon_vma_fork;
76512- tmp->vm_flags &= ~VM_LOCKED;
76513- tmp->vm_next = tmp->vm_prev = NULL;
76514- file = tmp->vm_file;
76515- if (file) {
76516- struct inode *inode = file_inode(file);
76517- struct address_space *mapping = file->f_mapping;
76518-
76519- get_file(file);
76520- if (tmp->vm_flags & VM_DENYWRITE)
76521- atomic_dec(&inode->i_writecount);
76522- mutex_lock(&mapping->i_mmap_mutex);
76523- if (tmp->vm_flags & VM_SHARED)
76524- mapping->i_mmap_writable++;
76525- flush_dcache_mmap_lock(mapping);
76526- /* insert tmp into the share list, just after mpnt */
76527- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
76528- vma_nonlinear_insert(tmp,
76529- &mapping->i_mmap_nonlinear);
76530- else
76531- vma_interval_tree_insert_after(tmp, mpnt,
76532- &mapping->i_mmap);
76533- flush_dcache_mmap_unlock(mapping);
76534- mutex_unlock(&mapping->i_mmap_mutex);
76535+ tmp = dup_vma(mm, oldmm, mpnt);
76536+ if (!tmp) {
76537+ retval = -ENOMEM;
76538+ goto out;
76539 }
76540
76541 /*
76542@@ -464,6 +490,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
76543 if (retval)
76544 goto out;
76545 }
76546+
76547+#ifdef CONFIG_PAX_SEGMEXEC
76548+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
76549+ struct vm_area_struct *mpnt_m;
76550+
76551+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
76552+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
76553+
76554+ if (!mpnt->vm_mirror)
76555+ continue;
76556+
76557+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
76558+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
76559+ mpnt->vm_mirror = mpnt_m;
76560+ } else {
76561+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
76562+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
76563+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
76564+ mpnt->vm_mirror->vm_mirror = mpnt;
76565+ }
76566+ }
76567+ BUG_ON(mpnt_m);
76568+ }
76569+#endif
76570+
76571 /* a new mm has just been created */
76572 arch_dup_mmap(oldmm, mm);
76573 retval = 0;
76574@@ -473,14 +524,6 @@ out:
76575 up_write(&oldmm->mmap_sem);
76576 uprobe_end_dup_mmap();
76577 return retval;
76578-fail_nomem_anon_vma_fork:
76579- mpol_put(pol);
76580-fail_nomem_policy:
76581- kmem_cache_free(vm_area_cachep, tmp);
76582-fail_nomem:
76583- retval = -ENOMEM;
76584- vm_unacct_memory(charge);
76585- goto out;
76586 }
76587
76588 static inline int mm_alloc_pgd(struct mm_struct *mm)
76589@@ -695,8 +738,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
76590 return ERR_PTR(err);
76591
76592 mm = get_task_mm(task);
76593- if (mm && mm != current->mm &&
76594- !ptrace_may_access(task, mode)) {
76595+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
76596+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
76597 mmput(mm);
76598 mm = ERR_PTR(-EACCES);
76599 }
76600@@ -918,13 +961,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
76601 spin_unlock(&fs->lock);
76602 return -EAGAIN;
76603 }
76604- fs->users++;
76605+ atomic_inc(&fs->users);
76606 spin_unlock(&fs->lock);
76607 return 0;
76608 }
76609 tsk->fs = copy_fs_struct(fs);
76610 if (!tsk->fs)
76611 return -ENOMEM;
76612+ /* Carry through gr_chroot_dentry and is_chrooted instead
76613+ of recomputing it here. Already copied when the task struct
76614+ is duplicated. This allows pivot_root to not be treated as
76615+ a chroot
76616+ */
76617+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
76618+
76619 return 0;
76620 }
76621
76622@@ -1197,10 +1247,13 @@ static struct task_struct *copy_process(unsigned long clone_flags,
76623 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
76624 #endif
76625 retval = -EAGAIN;
76626+
76627+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
76628+
76629 if (atomic_read(&p->real_cred->user->processes) >=
76630 task_rlimit(p, RLIMIT_NPROC)) {
76631- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
76632- p->real_cred->user != INIT_USER)
76633+ if (p->real_cred->user != INIT_USER &&
76634+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
76635 goto bad_fork_free;
76636 }
76637 current->flags &= ~PF_NPROC_EXCEEDED;
76638@@ -1446,6 +1499,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
76639 goto bad_fork_free_pid;
76640 }
76641
76642+ /* synchronizes with gr_set_acls()
76643+ we need to call this past the point of no return for fork()
76644+ */
76645+ gr_copy_label(p);
76646+
76647 if (clone_flags & CLONE_THREAD) {
76648 current->signal->nr_threads++;
76649 atomic_inc(&current->signal->live);
76650@@ -1529,6 +1587,8 @@ bad_fork_cleanup_count:
76651 bad_fork_free:
76652 free_task(p);
76653 fork_out:
76654+ gr_log_forkfail(retval);
76655+
76656 return ERR_PTR(retval);
76657 }
76658
76659@@ -1613,6 +1673,8 @@ long do_fork(unsigned long clone_flags,
76660 if (clone_flags & CLONE_PARENT_SETTID)
76661 put_user(nr, parent_tidptr);
76662
76663+ gr_handle_brute_check();
76664+
76665 if (clone_flags & CLONE_VFORK) {
76666 p->vfork_done = &vfork;
76667 init_completion(&vfork);
76668@@ -1723,7 +1785,7 @@ void __init proc_caches_init(void)
76669 mm_cachep = kmem_cache_create("mm_struct",
76670 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
76671 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
76672- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
76673+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
76674 mmap_init();
76675 nsproxy_cache_init();
76676 }
76677@@ -1763,7 +1825,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
76678 return 0;
76679
76680 /* don't need lock here; in the worst case we'll do useless copy */
76681- if (fs->users == 1)
76682+ if (atomic_read(&fs->users) == 1)
76683 return 0;
76684
76685 *new_fsp = copy_fs_struct(fs);
76686@@ -1875,7 +1937,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
76687 fs = current->fs;
76688 spin_lock(&fs->lock);
76689 current->fs = new_fs;
76690- if (--fs->users)
76691+ gr_set_chroot_entries(current, &current->fs->root);
76692+ if (atomic_dec_return(&fs->users))
76693 new_fs = NULL;
76694 else
76695 new_fs = fs;
76696diff --git a/kernel/futex.c b/kernel/futex.c
76697index 49dacfb..5c6b450 100644
76698--- a/kernel/futex.c
76699+++ b/kernel/futex.c
76700@@ -54,6 +54,7 @@
76701 #include <linux/mount.h>
76702 #include <linux/pagemap.h>
76703 #include <linux/syscalls.h>
76704+#include <linux/ptrace.h>
76705 #include <linux/signal.h>
76706 #include <linux/export.h>
76707 #include <linux/magic.h>
76708@@ -242,6 +243,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
76709 struct page *page, *page_head;
76710 int err, ro = 0;
76711
76712+#ifdef CONFIG_PAX_SEGMEXEC
76713+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
76714+ return -EFAULT;
76715+#endif
76716+
76717 /*
76718 * The futex address must be "naturally" aligned.
76719 */
76720@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
76721 {
76722 u32 curval;
76723 int i;
76724+ mm_segment_t oldfs;
76725
76726 /*
76727 * This will fail and we want it. Some arch implementations do
76728@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
76729 * implementation, the non-functional ones will return
76730 * -ENOSYS.
76731 */
76732+ oldfs = get_fs();
76733+ set_fs(USER_DS);
76734 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
76735 futex_cmpxchg_enabled = 1;
76736+ set_fs(oldfs);
76737
76738 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
76739 plist_head_init(&futex_queues[i].chain);
76740diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
76741index f9f44fd..29885e4 100644
76742--- a/kernel/futex_compat.c
76743+++ b/kernel/futex_compat.c
76744@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
76745 return 0;
76746 }
76747
76748-static void __user *futex_uaddr(struct robust_list __user *entry,
76749+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
76750 compat_long_t futex_offset)
76751 {
76752 compat_uptr_t base = ptr_to_compat(entry);
76753diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
76754index 9b22d03..6295b62 100644
76755--- a/kernel/gcov/base.c
76756+++ b/kernel/gcov/base.c
76757@@ -102,11 +102,6 @@ void gcov_enable_events(void)
76758 }
76759
76760 #ifdef CONFIG_MODULES
76761-static inline int within(void *addr, void *start, unsigned long size)
76762-{
76763- return ((addr >= start) && (addr < start + size));
76764-}
76765-
76766 /* Update list and generate events when modules are unloaded. */
76767 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
76768 void *data)
76769@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
76770 prev = NULL;
76771 /* Remove entries located in module from linked list. */
76772 for (info = gcov_info_head; info; info = info->next) {
76773- if (within(info, mod->module_core, mod->core_size)) {
76774+ if (within_module_core_rw((unsigned long)info, mod)) {
76775 if (prev)
76776 prev->next = info->next;
76777 else
76778diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
76779index 2288fbd..0f3941f 100644
76780--- a/kernel/hrtimer.c
76781+++ b/kernel/hrtimer.c
76782@@ -1435,7 +1435,7 @@ void hrtimer_peek_ahead_timers(void)
76783 local_irq_restore(flags);
76784 }
76785
76786-static void run_hrtimer_softirq(struct softirq_action *h)
76787+static void run_hrtimer_softirq(void)
76788 {
76789 hrtimer_peek_ahead_timers();
76790 }
76791@@ -1770,7 +1770,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
76792 return NOTIFY_OK;
76793 }
76794
76795-static struct notifier_block __cpuinitdata hrtimers_nb = {
76796+static struct notifier_block hrtimers_nb = {
76797 .notifier_call = hrtimer_cpu_notify,
76798 };
76799
76800diff --git a/kernel/irq_work.c b/kernel/irq_work.c
76801index 55fcce6..0e4cf34 100644
76802--- a/kernel/irq_work.c
76803+++ b/kernel/irq_work.c
76804@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
76805 return NOTIFY_OK;
76806 }
76807
76808-static struct notifier_block cpu_notify;
76809+static struct notifier_block cpu_notify = {
76810+ .notifier_call = irq_work_cpu_notify,
76811+ .priority = 0,
76812+};
76813
76814 static __init int irq_work_init_cpu_notifier(void)
76815 {
76816- cpu_notify.notifier_call = irq_work_cpu_notify;
76817- cpu_notify.priority = 0;
76818 register_cpu_notifier(&cpu_notify);
76819 return 0;
76820 }
76821diff --git a/kernel/jump_label.c b/kernel/jump_label.c
76822index 60f48fa..7f3a770 100644
76823--- a/kernel/jump_label.c
76824+++ b/kernel/jump_label.c
76825@@ -13,6 +13,7 @@
76826 #include <linux/sort.h>
76827 #include <linux/err.h>
76828 #include <linux/static_key.h>
76829+#include <linux/mm.h>
76830
76831 #ifdef HAVE_JUMP_LABEL
76832
76833@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
76834
76835 size = (((unsigned long)stop - (unsigned long)start)
76836 / sizeof(struct jump_entry));
76837+ pax_open_kernel();
76838 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
76839+ pax_close_kernel();
76840 }
76841
76842 static void jump_label_update(struct static_key *key, int enable);
76843@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
76844 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
76845 struct jump_entry *iter;
76846
76847+ pax_open_kernel();
76848 for (iter = iter_start; iter < iter_stop; iter++) {
76849 if (within_module_init(iter->code, mod))
76850 iter->code = 0;
76851 }
76852+ pax_close_kernel();
76853 }
76854
76855 static int
76856diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
76857index 3127ad5..159d880 100644
76858--- a/kernel/kallsyms.c
76859+++ b/kernel/kallsyms.c
76860@@ -11,6 +11,9 @@
76861 * Changed the compression method from stem compression to "table lookup"
76862 * compression (see scripts/kallsyms.c for a more complete description)
76863 */
76864+#ifdef CONFIG_GRKERNSEC_HIDESYM
76865+#define __INCLUDED_BY_HIDESYM 1
76866+#endif
76867 #include <linux/kallsyms.h>
76868 #include <linux/module.h>
76869 #include <linux/init.h>
76870@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
76871
76872 static inline int is_kernel_inittext(unsigned long addr)
76873 {
76874+ if (system_state != SYSTEM_BOOTING)
76875+ return 0;
76876+
76877 if (addr >= (unsigned long)_sinittext
76878 && addr <= (unsigned long)_einittext)
76879 return 1;
76880 return 0;
76881 }
76882
76883+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76884+#ifdef CONFIG_MODULES
76885+static inline int is_module_text(unsigned long addr)
76886+{
76887+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
76888+ return 1;
76889+
76890+ addr = ktla_ktva(addr);
76891+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
76892+}
76893+#else
76894+static inline int is_module_text(unsigned long addr)
76895+{
76896+ return 0;
76897+}
76898+#endif
76899+#endif
76900+
76901 static inline int is_kernel_text(unsigned long addr)
76902 {
76903 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
76904@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
76905
76906 static inline int is_kernel(unsigned long addr)
76907 {
76908+
76909+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76910+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
76911+ return 1;
76912+
76913+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
76914+#else
76915 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
76916+#endif
76917+
76918 return 1;
76919 return in_gate_area_no_mm(addr);
76920 }
76921
76922 static int is_ksym_addr(unsigned long addr)
76923 {
76924+
76925+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76926+ if (is_module_text(addr))
76927+ return 0;
76928+#endif
76929+
76930 if (all_var)
76931 return is_kernel(addr);
76932
76933@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
76934
76935 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
76936 {
76937- iter->name[0] = '\0';
76938 iter->nameoff = get_symbol_offset(new_pos);
76939 iter->pos = new_pos;
76940 }
76941@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
76942 {
76943 struct kallsym_iter *iter = m->private;
76944
76945+#ifdef CONFIG_GRKERNSEC_HIDESYM
76946+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
76947+ return 0;
76948+#endif
76949+
76950 /* Some debugging symbols have no name. Ignore them. */
76951 if (!iter->name[0])
76952 return 0;
76953@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
76954 */
76955 type = iter->exported ? toupper(iter->type) :
76956 tolower(iter->type);
76957+
76958 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
76959 type, iter->name, iter->module_name);
76960 } else
76961@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
76962 struct kallsym_iter *iter;
76963 int ret;
76964
76965- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
76966+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
76967 if (!iter)
76968 return -ENOMEM;
76969 reset_iter(iter, 0);
76970diff --git a/kernel/kcmp.c b/kernel/kcmp.c
76971index e30ac0f..3528cac 100644
76972--- a/kernel/kcmp.c
76973+++ b/kernel/kcmp.c
76974@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
76975 struct task_struct *task1, *task2;
76976 int ret;
76977
76978+#ifdef CONFIG_GRKERNSEC
76979+ return -ENOSYS;
76980+#endif
76981+
76982 rcu_read_lock();
76983
76984 /*
76985diff --git a/kernel/kexec.c b/kernel/kexec.c
76986index 59f7b55..4022f65 100644
76987--- a/kernel/kexec.c
76988+++ b/kernel/kexec.c
76989@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
76990 unsigned long flags)
76991 {
76992 struct compat_kexec_segment in;
76993- struct kexec_segment out, __user *ksegments;
76994+ struct kexec_segment out;
76995+ struct kexec_segment __user *ksegments;
76996 unsigned long i, result;
76997
76998 /* Don't allow clients that don't understand the native
76999diff --git a/kernel/kmod.c b/kernel/kmod.c
77000index 8241906..d625f2c 100644
77001--- a/kernel/kmod.c
77002+++ b/kernel/kmod.c
77003@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
77004 kfree(info->argv);
77005 }
77006
77007-static int call_modprobe(char *module_name, int wait)
77008+static int call_modprobe(char *module_name, char *module_param, int wait)
77009 {
77010 struct subprocess_info *info;
77011 static char *envp[] = {
77012@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
77013 NULL
77014 };
77015
77016- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
77017+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
77018 if (!argv)
77019 goto out;
77020
77021@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
77022 argv[1] = "-q";
77023 argv[2] = "--";
77024 argv[3] = module_name; /* check free_modprobe_argv() */
77025- argv[4] = NULL;
77026+ argv[4] = module_param;
77027+ argv[5] = NULL;
77028
77029 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
77030 NULL, free_modprobe_argv, NULL);
77031@@ -129,9 +130,8 @@ out:
77032 * If module auto-loading support is disabled then this function
77033 * becomes a no-operation.
77034 */
77035-int __request_module(bool wait, const char *fmt, ...)
77036+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
77037 {
77038- va_list args;
77039 char module_name[MODULE_NAME_LEN];
77040 unsigned int max_modprobes;
77041 int ret;
77042@@ -147,9 +147,7 @@ int __request_module(bool wait, const char *fmt, ...)
77043 */
77044 WARN_ON_ONCE(wait && current_is_async());
77045
77046- va_start(args, fmt);
77047- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
77048- va_end(args);
77049+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
77050 if (ret >= MODULE_NAME_LEN)
77051 return -ENAMETOOLONG;
77052
77053@@ -157,6 +155,20 @@ int __request_module(bool wait, const char *fmt, ...)
77054 if (ret)
77055 return ret;
77056
77057+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77058+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
77059+ /* hack to workaround consolekit/udisks stupidity */
77060+ read_lock(&tasklist_lock);
77061+ if (!strcmp(current->comm, "mount") &&
77062+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
77063+ read_unlock(&tasklist_lock);
77064+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
77065+ return -EPERM;
77066+ }
77067+ read_unlock(&tasklist_lock);
77068+ }
77069+#endif
77070+
77071 /* If modprobe needs a service that is in a module, we get a recursive
77072 * loop. Limit the number of running kmod threads to max_threads/2 or
77073 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
77074@@ -185,11 +197,52 @@ int __request_module(bool wait, const char *fmt, ...)
77075
77076 trace_module_request(module_name, wait, _RET_IP_);
77077
77078- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
77079+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
77080
77081 atomic_dec(&kmod_concurrent);
77082 return ret;
77083 }
77084+
77085+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
77086+{
77087+ va_list args;
77088+ int ret;
77089+
77090+ va_start(args, fmt);
77091+ ret = ____request_module(wait, module_param, fmt, args);
77092+ va_end(args);
77093+
77094+ return ret;
77095+}
77096+
77097+int __request_module(bool wait, const char *fmt, ...)
77098+{
77099+ va_list args;
77100+ int ret;
77101+
77102+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77103+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
77104+ char module_param[MODULE_NAME_LEN];
77105+
77106+ memset(module_param, 0, sizeof(module_param));
77107+
77108+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
77109+
77110+ va_start(args, fmt);
77111+ ret = ____request_module(wait, module_param, fmt, args);
77112+ va_end(args);
77113+
77114+ return ret;
77115+ }
77116+#endif
77117+
77118+ va_start(args, fmt);
77119+ ret = ____request_module(wait, NULL, fmt, args);
77120+ va_end(args);
77121+
77122+ return ret;
77123+}
77124+
77125 EXPORT_SYMBOL(__request_module);
77126 #endif /* CONFIG_MODULES */
77127
77128@@ -300,7 +353,7 @@ static int wait_for_helper(void *data)
77129 *
77130 * Thus the __user pointer cast is valid here.
77131 */
77132- sys_wait4(pid, (int __user *)&ret, 0, NULL);
77133+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
77134
77135 /*
77136 * If ret is 0, either ____call_usermodehelper failed and the
77137@@ -651,7 +704,7 @@ EXPORT_SYMBOL(call_usermodehelper);
77138 static int proc_cap_handler(struct ctl_table *table, int write,
77139 void __user *buffer, size_t *lenp, loff_t *ppos)
77140 {
77141- struct ctl_table t;
77142+ ctl_table_no_const t;
77143 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
77144 kernel_cap_t new_cap;
77145 int err, i;
77146diff --git a/kernel/kprobes.c b/kernel/kprobes.c
77147index bddf3b2..07b90dd 100644
77148--- a/kernel/kprobes.c
77149+++ b/kernel/kprobes.c
77150@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
77151 * kernel image and loaded module images reside. This is required
77152 * so x86_64 can correctly handle the %rip-relative fixups.
77153 */
77154- kip->insns = module_alloc(PAGE_SIZE);
77155+ kip->insns = module_alloc_exec(PAGE_SIZE);
77156 if (!kip->insns) {
77157 kfree(kip);
77158 return NULL;
77159@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
77160 */
77161 if (!list_is_singular(&kip->list)) {
77162 list_del(&kip->list);
77163- module_free(NULL, kip->insns);
77164+ module_free_exec(NULL, kip->insns);
77165 kfree(kip);
77166 }
77167 return 1;
77168@@ -2083,7 +2083,7 @@ static int __init init_kprobes(void)
77169 {
77170 int i, err = 0;
77171 unsigned long offset = 0, size = 0;
77172- char *modname, namebuf[128];
77173+ char *modname, namebuf[KSYM_NAME_LEN];
77174 const char *symbol_name;
77175 void *addr;
77176 struct kprobe_blackpoint *kb;
77177@@ -2168,11 +2168,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
77178 kprobe_type = "k";
77179
77180 if (sym)
77181- seq_printf(pi, "%p %s %s+0x%x %s ",
77182+ seq_printf(pi, "%pK %s %s+0x%x %s ",
77183 p->addr, kprobe_type, sym, offset,
77184 (modname ? modname : " "));
77185 else
77186- seq_printf(pi, "%p %s %p ",
77187+ seq_printf(pi, "%pK %s %pK ",
77188 p->addr, kprobe_type, p->addr);
77189
77190 if (!pp)
77191@@ -2209,7 +2209,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
77192 const char *sym = NULL;
77193 unsigned int i = *(loff_t *) v;
77194 unsigned long offset = 0;
77195- char *modname, namebuf[128];
77196+ char *modname, namebuf[KSYM_NAME_LEN];
77197
77198 head = &kprobe_table[i];
77199 preempt_disable();
77200diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
77201index 6ada93c..dce7d5d 100644
77202--- a/kernel/ksysfs.c
77203+++ b/kernel/ksysfs.c
77204@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
77205 {
77206 if (count+1 > UEVENT_HELPER_PATH_LEN)
77207 return -ENOENT;
77208+ if (!capable(CAP_SYS_ADMIN))
77209+ return -EPERM;
77210 memcpy(uevent_helper, buf, count);
77211 uevent_helper[count] = '\0';
77212 if (count && uevent_helper[count-1] == '\n')
77213@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
77214 return count;
77215 }
77216
77217-static struct bin_attribute notes_attr = {
77218+static bin_attribute_no_const notes_attr __read_only = {
77219 .attr = {
77220 .name = "notes",
77221 .mode = S_IRUGO,
77222diff --git a/kernel/lockdep.c b/kernel/lockdep.c
77223index 1f3186b..bb7dbc6 100644
77224--- a/kernel/lockdep.c
77225+++ b/kernel/lockdep.c
77226@@ -596,6 +596,10 @@ static int static_obj(void *obj)
77227 end = (unsigned long) &_end,
77228 addr = (unsigned long) obj;
77229
77230+#ifdef CONFIG_PAX_KERNEXEC
77231+ start = ktla_ktva(start);
77232+#endif
77233+
77234 /*
77235 * static variable?
77236 */
77237@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
77238 if (!static_obj(lock->key)) {
77239 debug_locks_off();
77240 printk("INFO: trying to register non-static key.\n");
77241+ printk("lock:%pS key:%pS.\n", lock, lock->key);
77242 printk("the code is fine but needs lockdep annotation.\n");
77243 printk("turning off the locking correctness validator.\n");
77244 dump_stack();
77245@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
77246 if (!class)
77247 return 0;
77248 }
77249- atomic_inc((atomic_t *)&class->ops);
77250+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
77251 if (very_verbose(class)) {
77252 printk("\nacquire class [%p] %s", class->key, class->name);
77253 if (class->name_version > 1)
77254diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
77255index b2c71c5..7b88d63 100644
77256--- a/kernel/lockdep_proc.c
77257+++ b/kernel/lockdep_proc.c
77258@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
77259 return 0;
77260 }
77261
77262- seq_printf(m, "%p", class->key);
77263+ seq_printf(m, "%pK", class->key);
77264 #ifdef CONFIG_DEBUG_LOCKDEP
77265 seq_printf(m, " OPS:%8ld", class->ops);
77266 #endif
77267@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
77268
77269 list_for_each_entry(entry, &class->locks_after, entry) {
77270 if (entry->distance == 1) {
77271- seq_printf(m, " -> [%p] ", entry->class->key);
77272+ seq_printf(m, " -> [%pK] ", entry->class->key);
77273 print_name(m, entry->class);
77274 seq_puts(m, "\n");
77275 }
77276@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
77277 if (!class->key)
77278 continue;
77279
77280- seq_printf(m, "[%p] ", class->key);
77281+ seq_printf(m, "[%pK] ", class->key);
77282 print_name(m, class);
77283 seq_puts(m, "\n");
77284 }
77285@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
77286 if (!i)
77287 seq_line(m, '-', 40-namelen, namelen);
77288
77289- snprintf(ip, sizeof(ip), "[<%p>]",
77290+ snprintf(ip, sizeof(ip), "[<%pK>]",
77291 (void *)class->contention_point[i]);
77292 seq_printf(m, "%40s %14lu %29s %pS\n",
77293 name, stats->contention_point[i],
77294@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
77295 if (!i)
77296 seq_line(m, '-', 40-namelen, namelen);
77297
77298- snprintf(ip, sizeof(ip), "[<%p>]",
77299+ snprintf(ip, sizeof(ip), "[<%pK>]",
77300 (void *)class->contending_point[i]);
77301 seq_printf(m, "%40s %14lu %29s %pS\n",
77302 name, stats->contending_point[i],
77303diff --git a/kernel/module.c b/kernel/module.c
77304index fa53db8..6f17200 100644
77305--- a/kernel/module.c
77306+++ b/kernel/module.c
77307@@ -61,6 +61,7 @@
77308 #include <linux/pfn.h>
77309 #include <linux/bsearch.h>
77310 #include <linux/fips.h>
77311+#include <linux/grsecurity.h>
77312 #include <uapi/linux/module.h>
77313 #include "module-internal.h"
77314
77315@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
77316
77317 /* Bounds of module allocation, for speeding __module_address.
77318 * Protected by module_mutex. */
77319-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
77320+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
77321+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
77322
77323 int register_module_notifier(struct notifier_block * nb)
77324 {
77325@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
77326 return true;
77327
77328 list_for_each_entry_rcu(mod, &modules, list) {
77329- struct symsearch arr[] = {
77330+ struct symsearch modarr[] = {
77331 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
77332 NOT_GPL_ONLY, false },
77333 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
77334@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
77335 if (mod->state == MODULE_STATE_UNFORMED)
77336 continue;
77337
77338- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
77339+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
77340 return true;
77341 }
77342 return false;
77343@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
77344 static int percpu_modalloc(struct module *mod,
77345 unsigned long size, unsigned long align)
77346 {
77347- if (align > PAGE_SIZE) {
77348+ if (align-1 >= PAGE_SIZE) {
77349 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
77350 mod->name, align, PAGE_SIZE);
77351 align = PAGE_SIZE;
77352@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
77353 static ssize_t show_coresize(struct module_attribute *mattr,
77354 struct module_kobject *mk, char *buffer)
77355 {
77356- return sprintf(buffer, "%u\n", mk->mod->core_size);
77357+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
77358 }
77359
77360 static struct module_attribute modinfo_coresize =
77361@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
77362 static ssize_t show_initsize(struct module_attribute *mattr,
77363 struct module_kobject *mk, char *buffer)
77364 {
77365- return sprintf(buffer, "%u\n", mk->mod->init_size);
77366+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
77367 }
77368
77369 static struct module_attribute modinfo_initsize =
77370@@ -1313,7 +1315,7 @@ resolve_symbol_wait(struct module *mod,
77371 */
77372 #ifdef CONFIG_SYSFS
77373
77374-#ifdef CONFIG_KALLSYMS
77375+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
77376 static inline bool sect_empty(const Elf_Shdr *sect)
77377 {
77378 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
77379@@ -1453,7 +1455,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
77380 {
77381 unsigned int notes, loaded, i;
77382 struct module_notes_attrs *notes_attrs;
77383- struct bin_attribute *nattr;
77384+ bin_attribute_no_const *nattr;
77385
77386 /* failed to create section attributes, so can't create notes */
77387 if (!mod->sect_attrs)
77388@@ -1565,7 +1567,7 @@ static void del_usage_links(struct module *mod)
77389 static int module_add_modinfo_attrs(struct module *mod)
77390 {
77391 struct module_attribute *attr;
77392- struct module_attribute *temp_attr;
77393+ module_attribute_no_const *temp_attr;
77394 int error = 0;
77395 int i;
77396
77397@@ -1779,21 +1781,21 @@ static void set_section_ro_nx(void *base,
77398
77399 static void unset_module_core_ro_nx(struct module *mod)
77400 {
77401- set_page_attributes(mod->module_core + mod->core_text_size,
77402- mod->module_core + mod->core_size,
77403+ set_page_attributes(mod->module_core_rw,
77404+ mod->module_core_rw + mod->core_size_rw,
77405 set_memory_x);
77406- set_page_attributes(mod->module_core,
77407- mod->module_core + mod->core_ro_size,
77408+ set_page_attributes(mod->module_core_rx,
77409+ mod->module_core_rx + mod->core_size_rx,
77410 set_memory_rw);
77411 }
77412
77413 static void unset_module_init_ro_nx(struct module *mod)
77414 {
77415- set_page_attributes(mod->module_init + mod->init_text_size,
77416- mod->module_init + mod->init_size,
77417+ set_page_attributes(mod->module_init_rw,
77418+ mod->module_init_rw + mod->init_size_rw,
77419 set_memory_x);
77420- set_page_attributes(mod->module_init,
77421- mod->module_init + mod->init_ro_size,
77422+ set_page_attributes(mod->module_init_rx,
77423+ mod->module_init_rx + mod->init_size_rx,
77424 set_memory_rw);
77425 }
77426
77427@@ -1806,14 +1808,14 @@ void set_all_modules_text_rw(void)
77428 list_for_each_entry_rcu(mod, &modules, list) {
77429 if (mod->state == MODULE_STATE_UNFORMED)
77430 continue;
77431- if ((mod->module_core) && (mod->core_text_size)) {
77432- set_page_attributes(mod->module_core,
77433- mod->module_core + mod->core_text_size,
77434+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
77435+ set_page_attributes(mod->module_core_rx,
77436+ mod->module_core_rx + mod->core_size_rx,
77437 set_memory_rw);
77438 }
77439- if ((mod->module_init) && (mod->init_text_size)) {
77440- set_page_attributes(mod->module_init,
77441- mod->module_init + mod->init_text_size,
77442+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
77443+ set_page_attributes(mod->module_init_rx,
77444+ mod->module_init_rx + mod->init_size_rx,
77445 set_memory_rw);
77446 }
77447 }
77448@@ -1829,14 +1831,14 @@ void set_all_modules_text_ro(void)
77449 list_for_each_entry_rcu(mod, &modules, list) {
77450 if (mod->state == MODULE_STATE_UNFORMED)
77451 continue;
77452- if ((mod->module_core) && (mod->core_text_size)) {
77453- set_page_attributes(mod->module_core,
77454- mod->module_core + mod->core_text_size,
77455+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
77456+ set_page_attributes(mod->module_core_rx,
77457+ mod->module_core_rx + mod->core_size_rx,
77458 set_memory_ro);
77459 }
77460- if ((mod->module_init) && (mod->init_text_size)) {
77461- set_page_attributes(mod->module_init,
77462- mod->module_init + mod->init_text_size,
77463+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
77464+ set_page_attributes(mod->module_init_rx,
77465+ mod->module_init_rx + mod->init_size_rx,
77466 set_memory_ro);
77467 }
77468 }
77469@@ -1887,16 +1889,19 @@ static void free_module(struct module *mod)
77470
77471 /* This may be NULL, but that's OK */
77472 unset_module_init_ro_nx(mod);
77473- module_free(mod, mod->module_init);
77474+ module_free(mod, mod->module_init_rw);
77475+ module_free_exec(mod, mod->module_init_rx);
77476 kfree(mod->args);
77477 percpu_modfree(mod);
77478
77479 /* Free lock-classes: */
77480- lockdep_free_key_range(mod->module_core, mod->core_size);
77481+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
77482+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
77483
77484 /* Finally, free the core (containing the module structure) */
77485 unset_module_core_ro_nx(mod);
77486- module_free(mod, mod->module_core);
77487+ module_free_exec(mod, mod->module_core_rx);
77488+ module_free(mod, mod->module_core_rw);
77489
77490 #ifdef CONFIG_MPU
77491 update_protections(current->mm);
77492@@ -1966,9 +1971,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
77493 int ret = 0;
77494 const struct kernel_symbol *ksym;
77495
77496+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77497+ int is_fs_load = 0;
77498+ int register_filesystem_found = 0;
77499+ char *p;
77500+
77501+ p = strstr(mod->args, "grsec_modharden_fs");
77502+ if (p) {
77503+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
77504+ /* copy \0 as well */
77505+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
77506+ is_fs_load = 1;
77507+ }
77508+#endif
77509+
77510 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
77511 const char *name = info->strtab + sym[i].st_name;
77512
77513+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77514+ /* it's a real shame this will never get ripped and copied
77515+ upstream! ;(
77516+ */
77517+ if (is_fs_load && !strcmp(name, "register_filesystem"))
77518+ register_filesystem_found = 1;
77519+#endif
77520+
77521 switch (sym[i].st_shndx) {
77522 case SHN_COMMON:
77523 /* We compiled with -fno-common. These are not
77524@@ -1989,7 +2016,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
77525 ksym = resolve_symbol_wait(mod, info, name);
77526 /* Ok if resolved. */
77527 if (ksym && !IS_ERR(ksym)) {
77528+ pax_open_kernel();
77529 sym[i].st_value = ksym->value;
77530+ pax_close_kernel();
77531 break;
77532 }
77533
77534@@ -2008,11 +2037,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
77535 secbase = (unsigned long)mod_percpu(mod);
77536 else
77537 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
77538+ pax_open_kernel();
77539 sym[i].st_value += secbase;
77540+ pax_close_kernel();
77541 break;
77542 }
77543 }
77544
77545+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77546+ if (is_fs_load && !register_filesystem_found) {
77547+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
77548+ ret = -EPERM;
77549+ }
77550+#endif
77551+
77552 return ret;
77553 }
77554
77555@@ -2096,22 +2134,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
77556 || s->sh_entsize != ~0UL
77557 || strstarts(sname, ".init"))
77558 continue;
77559- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
77560+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
77561+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
77562+ else
77563+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
77564 pr_debug("\t%s\n", sname);
77565 }
77566- switch (m) {
77567- case 0: /* executable */
77568- mod->core_size = debug_align(mod->core_size);
77569- mod->core_text_size = mod->core_size;
77570- break;
77571- case 1: /* RO: text and ro-data */
77572- mod->core_size = debug_align(mod->core_size);
77573- mod->core_ro_size = mod->core_size;
77574- break;
77575- case 3: /* whole core */
77576- mod->core_size = debug_align(mod->core_size);
77577- break;
77578- }
77579 }
77580
77581 pr_debug("Init section allocation order:\n");
77582@@ -2125,23 +2153,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
77583 || s->sh_entsize != ~0UL
77584 || !strstarts(sname, ".init"))
77585 continue;
77586- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
77587- | INIT_OFFSET_MASK);
77588+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
77589+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
77590+ else
77591+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
77592+ s->sh_entsize |= INIT_OFFSET_MASK;
77593 pr_debug("\t%s\n", sname);
77594 }
77595- switch (m) {
77596- case 0: /* executable */
77597- mod->init_size = debug_align(mod->init_size);
77598- mod->init_text_size = mod->init_size;
77599- break;
77600- case 1: /* RO: text and ro-data */
77601- mod->init_size = debug_align(mod->init_size);
77602- mod->init_ro_size = mod->init_size;
77603- break;
77604- case 3: /* whole init */
77605- mod->init_size = debug_align(mod->init_size);
77606- break;
77607- }
77608 }
77609 }
77610
77611@@ -2314,7 +2332,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
77612
77613 /* Put symbol section at end of init part of module. */
77614 symsect->sh_flags |= SHF_ALLOC;
77615- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
77616+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
77617 info->index.sym) | INIT_OFFSET_MASK;
77618 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
77619
77620@@ -2331,13 +2349,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
77621 }
77622
77623 /* Append room for core symbols at end of core part. */
77624- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
77625- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
77626- mod->core_size += strtab_size;
77627+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
77628+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
77629+ mod->core_size_rx += strtab_size;
77630
77631 /* Put string table section at end of init part of module. */
77632 strsect->sh_flags |= SHF_ALLOC;
77633- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
77634+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
77635 info->index.str) | INIT_OFFSET_MASK;
77636 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
77637 }
77638@@ -2355,12 +2373,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
77639 /* Make sure we get permanent strtab: don't use info->strtab. */
77640 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
77641
77642+ pax_open_kernel();
77643+
77644 /* Set types up while we still have access to sections. */
77645 for (i = 0; i < mod->num_symtab; i++)
77646 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
77647
77648- mod->core_symtab = dst = mod->module_core + info->symoffs;
77649- mod->core_strtab = s = mod->module_core + info->stroffs;
77650+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
77651+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
77652 src = mod->symtab;
77653 for (ndst = i = 0; i < mod->num_symtab; i++) {
77654 if (i == 0 ||
77655@@ -2372,6 +2392,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
77656 }
77657 }
77658 mod->core_num_syms = ndst;
77659+
77660+ pax_close_kernel();
77661 }
77662 #else
77663 static inline void layout_symtab(struct module *mod, struct load_info *info)
77664@@ -2405,17 +2427,33 @@ void * __weak module_alloc(unsigned long size)
77665 return vmalloc_exec(size);
77666 }
77667
77668-static void *module_alloc_update_bounds(unsigned long size)
77669+static void *module_alloc_update_bounds_rw(unsigned long size)
77670 {
77671 void *ret = module_alloc(size);
77672
77673 if (ret) {
77674 mutex_lock(&module_mutex);
77675 /* Update module bounds. */
77676- if ((unsigned long)ret < module_addr_min)
77677- module_addr_min = (unsigned long)ret;
77678- if ((unsigned long)ret + size > module_addr_max)
77679- module_addr_max = (unsigned long)ret + size;
77680+ if ((unsigned long)ret < module_addr_min_rw)
77681+ module_addr_min_rw = (unsigned long)ret;
77682+ if ((unsigned long)ret + size > module_addr_max_rw)
77683+ module_addr_max_rw = (unsigned long)ret + size;
77684+ mutex_unlock(&module_mutex);
77685+ }
77686+ return ret;
77687+}
77688+
77689+static void *module_alloc_update_bounds_rx(unsigned long size)
77690+{
77691+ void *ret = module_alloc_exec(size);
77692+
77693+ if (ret) {
77694+ mutex_lock(&module_mutex);
77695+ /* Update module bounds. */
77696+ if ((unsigned long)ret < module_addr_min_rx)
77697+ module_addr_min_rx = (unsigned long)ret;
77698+ if ((unsigned long)ret + size > module_addr_max_rx)
77699+ module_addr_max_rx = (unsigned long)ret + size;
77700 mutex_unlock(&module_mutex);
77701 }
77702 return ret;
77703@@ -2691,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
77704 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
77705 {
77706 const char *modmagic = get_modinfo(info, "vermagic");
77707+ const char *license = get_modinfo(info, "license");
77708 int err;
77709
77710+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
77711+ if (!license || !license_is_gpl_compatible(license))
77712+ return -ENOEXEC;
77713+#endif
77714+
77715 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
77716 modmagic = NULL;
77717
77718@@ -2718,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
77719 }
77720
77721 /* Set up license info based on the info section */
77722- set_license(mod, get_modinfo(info, "license"));
77723+ set_license(mod, license);
77724
77725 return 0;
77726 }
77727@@ -2799,7 +2843,7 @@ static int move_module(struct module *mod, struct load_info *info)
77728 void *ptr;
77729
77730 /* Do the allocs. */
77731- ptr = module_alloc_update_bounds(mod->core_size);
77732+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
77733 /*
77734 * The pointer to this block is stored in the module structure
77735 * which is inside the block. Just mark it as not being a
77736@@ -2809,11 +2853,11 @@ static int move_module(struct module *mod, struct load_info *info)
77737 if (!ptr)
77738 return -ENOMEM;
77739
77740- memset(ptr, 0, mod->core_size);
77741- mod->module_core = ptr;
77742+ memset(ptr, 0, mod->core_size_rw);
77743+ mod->module_core_rw = ptr;
77744
77745- if (mod->init_size) {
77746- ptr = module_alloc_update_bounds(mod->init_size);
77747+ if (mod->init_size_rw) {
77748+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
77749 /*
77750 * The pointer to this block is stored in the module structure
77751 * which is inside the block. This block doesn't need to be
77752@@ -2822,13 +2866,45 @@ static int move_module(struct module *mod, struct load_info *info)
77753 */
77754 kmemleak_ignore(ptr);
77755 if (!ptr) {
77756- module_free(mod, mod->module_core);
77757+ module_free(mod, mod->module_core_rw);
77758 return -ENOMEM;
77759 }
77760- memset(ptr, 0, mod->init_size);
77761- mod->module_init = ptr;
77762+ memset(ptr, 0, mod->init_size_rw);
77763+ mod->module_init_rw = ptr;
77764 } else
77765- mod->module_init = NULL;
77766+ mod->module_init_rw = NULL;
77767+
77768+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
77769+ kmemleak_not_leak(ptr);
77770+ if (!ptr) {
77771+ if (mod->module_init_rw)
77772+ module_free(mod, mod->module_init_rw);
77773+ module_free(mod, mod->module_core_rw);
77774+ return -ENOMEM;
77775+ }
77776+
77777+ pax_open_kernel();
77778+ memset(ptr, 0, mod->core_size_rx);
77779+ pax_close_kernel();
77780+ mod->module_core_rx = ptr;
77781+
77782+ if (mod->init_size_rx) {
77783+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
77784+ kmemleak_ignore(ptr);
77785+ if (!ptr && mod->init_size_rx) {
77786+ module_free_exec(mod, mod->module_core_rx);
77787+ if (mod->module_init_rw)
77788+ module_free(mod, mod->module_init_rw);
77789+ module_free(mod, mod->module_core_rw);
77790+ return -ENOMEM;
77791+ }
77792+
77793+ pax_open_kernel();
77794+ memset(ptr, 0, mod->init_size_rx);
77795+ pax_close_kernel();
77796+ mod->module_init_rx = ptr;
77797+ } else
77798+ mod->module_init_rx = NULL;
77799
77800 /* Transfer each section which specifies SHF_ALLOC */
77801 pr_debug("final section addresses:\n");
77802@@ -2839,16 +2915,45 @@ static int move_module(struct module *mod, struct load_info *info)
77803 if (!(shdr->sh_flags & SHF_ALLOC))
77804 continue;
77805
77806- if (shdr->sh_entsize & INIT_OFFSET_MASK)
77807- dest = mod->module_init
77808- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77809- else
77810- dest = mod->module_core + shdr->sh_entsize;
77811+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
77812+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77813+ dest = mod->module_init_rw
77814+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77815+ else
77816+ dest = mod->module_init_rx
77817+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77818+ } else {
77819+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77820+ dest = mod->module_core_rw + shdr->sh_entsize;
77821+ else
77822+ dest = mod->module_core_rx + shdr->sh_entsize;
77823+ }
77824+
77825+ if (shdr->sh_type != SHT_NOBITS) {
77826+
77827+#ifdef CONFIG_PAX_KERNEXEC
77828+#ifdef CONFIG_X86_64
77829+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
77830+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
77831+#endif
77832+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
77833+ pax_open_kernel();
77834+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77835+ pax_close_kernel();
77836+ } else
77837+#endif
77838
77839- if (shdr->sh_type != SHT_NOBITS)
77840 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77841+ }
77842 /* Update sh_addr to point to copy in image. */
77843- shdr->sh_addr = (unsigned long)dest;
77844+
77845+#ifdef CONFIG_PAX_KERNEXEC
77846+ if (shdr->sh_flags & SHF_EXECINSTR)
77847+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
77848+ else
77849+#endif
77850+
77851+ shdr->sh_addr = (unsigned long)dest;
77852 pr_debug("\t0x%lx %s\n",
77853 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
77854 }
77855@@ -2905,12 +3010,12 @@ static void flush_module_icache(const struct module *mod)
77856 * Do it before processing of module parameters, so the module
77857 * can provide parameter accessor functions of its own.
77858 */
77859- if (mod->module_init)
77860- flush_icache_range((unsigned long)mod->module_init,
77861- (unsigned long)mod->module_init
77862- + mod->init_size);
77863- flush_icache_range((unsigned long)mod->module_core,
77864- (unsigned long)mod->module_core + mod->core_size);
77865+ if (mod->module_init_rx)
77866+ flush_icache_range((unsigned long)mod->module_init_rx,
77867+ (unsigned long)mod->module_init_rx
77868+ + mod->init_size_rx);
77869+ flush_icache_range((unsigned long)mod->module_core_rx,
77870+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
77871
77872 set_fs(old_fs);
77873 }
77874@@ -2977,8 +3082,10 @@ static int alloc_module_percpu(struct module *mod, struct load_info *info)
77875 static void module_deallocate(struct module *mod, struct load_info *info)
77876 {
77877 percpu_modfree(mod);
77878- module_free(mod, mod->module_init);
77879- module_free(mod, mod->module_core);
77880+ module_free_exec(mod, mod->module_init_rx);
77881+ module_free_exec(mod, mod->module_core_rx);
77882+ module_free(mod, mod->module_init_rw);
77883+ module_free(mod, mod->module_core_rw);
77884 }
77885
77886 int __weak module_finalize(const Elf_Ehdr *hdr,
77887@@ -2991,7 +3098,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
77888 static int post_relocation(struct module *mod, const struct load_info *info)
77889 {
77890 /* Sort exception table now relocations are done. */
77891+ pax_open_kernel();
77892 sort_extable(mod->extable, mod->extable + mod->num_exentries);
77893+ pax_close_kernel();
77894
77895 /* Copy relocated percpu area over. */
77896 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
77897@@ -3045,16 +3154,16 @@ static int do_init_module(struct module *mod)
77898 MODULE_STATE_COMING, mod);
77899
77900 /* Set RO and NX regions for core */
77901- set_section_ro_nx(mod->module_core,
77902- mod->core_text_size,
77903- mod->core_ro_size,
77904- mod->core_size);
77905+ set_section_ro_nx(mod->module_core_rx,
77906+ mod->core_size_rx,
77907+ mod->core_size_rx,
77908+ mod->core_size_rx);
77909
77910 /* Set RO and NX regions for init */
77911- set_section_ro_nx(mod->module_init,
77912- mod->init_text_size,
77913- mod->init_ro_size,
77914- mod->init_size);
77915+ set_section_ro_nx(mod->module_init_rx,
77916+ mod->init_size_rx,
77917+ mod->init_size_rx,
77918+ mod->init_size_rx);
77919
77920 do_mod_ctors(mod);
77921 /* Start the module */
77922@@ -3116,11 +3225,12 @@ static int do_init_module(struct module *mod)
77923 mod->strtab = mod->core_strtab;
77924 #endif
77925 unset_module_init_ro_nx(mod);
77926- module_free(mod, mod->module_init);
77927- mod->module_init = NULL;
77928- mod->init_size = 0;
77929- mod->init_ro_size = 0;
77930- mod->init_text_size = 0;
77931+ module_free(mod, mod->module_init_rw);
77932+ module_free_exec(mod, mod->module_init_rx);
77933+ mod->module_init_rw = NULL;
77934+ mod->module_init_rx = NULL;
77935+ mod->init_size_rw = 0;
77936+ mod->init_size_rx = 0;
77937 mutex_unlock(&module_mutex);
77938 wake_up_all(&module_wq);
77939
77940@@ -3252,9 +3362,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
77941 if (err)
77942 goto free_unload;
77943
77944+ /* Now copy in args */
77945+ mod->args = strndup_user(uargs, ~0UL >> 1);
77946+ if (IS_ERR(mod->args)) {
77947+ err = PTR_ERR(mod->args);
77948+ goto free_unload;
77949+ }
77950+
77951 /* Set up MODINFO_ATTR fields */
77952 setup_modinfo(mod, info);
77953
77954+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77955+ {
77956+ char *p, *p2;
77957+
77958+ if (strstr(mod->args, "grsec_modharden_netdev")) {
77959+ 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);
77960+ err = -EPERM;
77961+ goto free_modinfo;
77962+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
77963+ p += sizeof("grsec_modharden_normal") - 1;
77964+ p2 = strstr(p, "_");
77965+ if (p2) {
77966+ *p2 = '\0';
77967+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
77968+ *p2 = '_';
77969+ }
77970+ err = -EPERM;
77971+ goto free_modinfo;
77972+ }
77973+ }
77974+#endif
77975+
77976 /* Fix up syms, so that st_value is a pointer to location. */
77977 err = simplify_symbols(mod, info);
77978 if (err < 0)
77979@@ -3270,13 +3409,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
77980
77981 flush_module_icache(mod);
77982
77983- /* Now copy in args */
77984- mod->args = strndup_user(uargs, ~0UL >> 1);
77985- if (IS_ERR(mod->args)) {
77986- err = PTR_ERR(mod->args);
77987- goto free_arch_cleanup;
77988- }
77989-
77990 dynamic_debug_setup(info->debug, info->num_debug);
77991
77992 /* Finally it's fully formed, ready to start executing. */
77993@@ -3311,11 +3443,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
77994 ddebug_cleanup:
77995 dynamic_debug_remove(info->debug);
77996 synchronize_sched();
77997- kfree(mod->args);
77998- free_arch_cleanup:
77999 module_arch_cleanup(mod);
78000 free_modinfo:
78001 free_modinfo(mod);
78002+ kfree(mod->args);
78003 free_unload:
78004 module_unload_free(mod);
78005 unlink_mod:
78006@@ -3398,10 +3529,16 @@ static const char *get_ksymbol(struct module *mod,
78007 unsigned long nextval;
78008
78009 /* At worse, next value is at end of module */
78010- if (within_module_init(addr, mod))
78011- nextval = (unsigned long)mod->module_init+mod->init_text_size;
78012+ if (within_module_init_rx(addr, mod))
78013+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
78014+ else if (within_module_init_rw(addr, mod))
78015+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
78016+ else if (within_module_core_rx(addr, mod))
78017+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
78018+ else if (within_module_core_rw(addr, mod))
78019+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
78020 else
78021- nextval = (unsigned long)mod->module_core+mod->core_text_size;
78022+ return NULL;
78023
78024 /* Scan for closest preceding symbol, and next symbol. (ELF
78025 starts real symbols at 1). */
78026@@ -3654,7 +3791,7 @@ static int m_show(struct seq_file *m, void *p)
78027 return 0;
78028
78029 seq_printf(m, "%s %u",
78030- mod->name, mod->init_size + mod->core_size);
78031+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
78032 print_unload_info(m, mod);
78033
78034 /* Informative for users. */
78035@@ -3663,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
78036 mod->state == MODULE_STATE_COMING ? "Loading":
78037 "Live");
78038 /* Used by oprofile and other similar tools. */
78039- seq_printf(m, " 0x%pK", mod->module_core);
78040+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
78041
78042 /* Taints info */
78043 if (mod->taints)
78044@@ -3699,7 +3836,17 @@ static const struct file_operations proc_modules_operations = {
78045
78046 static int __init proc_modules_init(void)
78047 {
78048+#ifndef CONFIG_GRKERNSEC_HIDESYM
78049+#ifdef CONFIG_GRKERNSEC_PROC_USER
78050+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
78051+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78052+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
78053+#else
78054 proc_create("modules", 0, NULL, &proc_modules_operations);
78055+#endif
78056+#else
78057+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
78058+#endif
78059 return 0;
78060 }
78061 module_init(proc_modules_init);
78062@@ -3760,14 +3907,14 @@ struct module *__module_address(unsigned long addr)
78063 {
78064 struct module *mod;
78065
78066- if (addr < module_addr_min || addr > module_addr_max)
78067+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
78068+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
78069 return NULL;
78070
78071 list_for_each_entry_rcu(mod, &modules, list) {
78072 if (mod->state == MODULE_STATE_UNFORMED)
78073 continue;
78074- if (within_module_core(addr, mod)
78075- || within_module_init(addr, mod))
78076+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
78077 return mod;
78078 }
78079 return NULL;
78080@@ -3802,11 +3949,20 @@ bool is_module_text_address(unsigned long addr)
78081 */
78082 struct module *__module_text_address(unsigned long addr)
78083 {
78084- struct module *mod = __module_address(addr);
78085+ struct module *mod;
78086+
78087+#ifdef CONFIG_X86_32
78088+ addr = ktla_ktva(addr);
78089+#endif
78090+
78091+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
78092+ return NULL;
78093+
78094+ mod = __module_address(addr);
78095+
78096 if (mod) {
78097 /* Make sure it's within the text section. */
78098- if (!within(addr, mod->module_init, mod->init_text_size)
78099- && !within(addr, mod->module_core, mod->core_text_size))
78100+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
78101 mod = NULL;
78102 }
78103 return mod;
78104diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
78105index 7e3443f..b2a1e6b 100644
78106--- a/kernel/mutex-debug.c
78107+++ b/kernel/mutex-debug.c
78108@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
78109 }
78110
78111 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
78112- struct thread_info *ti)
78113+ struct task_struct *task)
78114 {
78115 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
78116
78117 /* Mark the current thread as blocked on the lock: */
78118- ti->task->blocked_on = waiter;
78119+ task->blocked_on = waiter;
78120 }
78121
78122 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
78123- struct thread_info *ti)
78124+ struct task_struct *task)
78125 {
78126 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
78127- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
78128- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
78129- ti->task->blocked_on = NULL;
78130+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
78131+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
78132+ task->blocked_on = NULL;
78133
78134 list_del_init(&waiter->list);
78135 waiter->task = NULL;
78136diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
78137index 0799fd3..d06ae3b 100644
78138--- a/kernel/mutex-debug.h
78139+++ b/kernel/mutex-debug.h
78140@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
78141 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
78142 extern void debug_mutex_add_waiter(struct mutex *lock,
78143 struct mutex_waiter *waiter,
78144- struct thread_info *ti);
78145+ struct task_struct *task);
78146 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
78147- struct thread_info *ti);
78148+ struct task_struct *task);
78149 extern void debug_mutex_unlock(struct mutex *lock);
78150 extern void debug_mutex_init(struct mutex *lock, const char *name,
78151 struct lock_class_key *key);
78152diff --git a/kernel/mutex.c b/kernel/mutex.c
78153index ad53a66..f1bf8bc 100644
78154--- a/kernel/mutex.c
78155+++ b/kernel/mutex.c
78156@@ -134,7 +134,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
78157 node->locked = 1;
78158 return;
78159 }
78160- ACCESS_ONCE(prev->next) = node;
78161+ ACCESS_ONCE_RW(prev->next) = node;
78162 smp_wmb();
78163 /* Wait until the lock holder passes the lock down */
78164 while (!ACCESS_ONCE(node->locked))
78165@@ -155,7 +155,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
78166 while (!(next = ACCESS_ONCE(node->next)))
78167 arch_mutex_cpu_relax();
78168 }
78169- ACCESS_ONCE(next->locked) = 1;
78170+ ACCESS_ONCE_RW(next->locked) = 1;
78171 smp_wmb();
78172 }
78173
78174@@ -341,7 +341,7 @@ slowpath:
78175 spin_lock_mutex(&lock->wait_lock, flags);
78176
78177 debug_mutex_lock_common(lock, &waiter);
78178- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
78179+ debug_mutex_add_waiter(lock, &waiter, task);
78180
78181 /* add waiting tasks to the end of the waitqueue (FIFO): */
78182 list_add_tail(&waiter.list, &lock->wait_list);
78183@@ -371,8 +371,7 @@ slowpath:
78184 * TASK_UNINTERRUPTIBLE case.)
78185 */
78186 if (unlikely(signal_pending_state(state, task))) {
78187- mutex_remove_waiter(lock, &waiter,
78188- task_thread_info(task));
78189+ mutex_remove_waiter(lock, &waiter, task);
78190 mutex_release(&lock->dep_map, 1, ip);
78191 spin_unlock_mutex(&lock->wait_lock, flags);
78192
78193@@ -391,7 +390,7 @@ slowpath:
78194 done:
78195 lock_acquired(&lock->dep_map, ip);
78196 /* got the lock - rejoice! */
78197- mutex_remove_waiter(lock, &waiter, current_thread_info());
78198+ mutex_remove_waiter(lock, &waiter, task);
78199 mutex_set_owner(lock);
78200
78201 /* set it to 0 if there are no waiters left: */
78202diff --git a/kernel/notifier.c b/kernel/notifier.c
78203index 2d5cc4c..d9ea600 100644
78204--- a/kernel/notifier.c
78205+++ b/kernel/notifier.c
78206@@ -5,6 +5,7 @@
78207 #include <linux/rcupdate.h>
78208 #include <linux/vmalloc.h>
78209 #include <linux/reboot.h>
78210+#include <linux/mm.h>
78211
78212 /*
78213 * Notifier list for kernel code which wants to be called
78214@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
78215 while ((*nl) != NULL) {
78216 if (n->priority > (*nl)->priority)
78217 break;
78218- nl = &((*nl)->next);
78219+ nl = (struct notifier_block **)&((*nl)->next);
78220 }
78221- n->next = *nl;
78222+ pax_open_kernel();
78223+ *(const void **)&n->next = *nl;
78224 rcu_assign_pointer(*nl, n);
78225+ pax_close_kernel();
78226 return 0;
78227 }
78228
78229@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
78230 return 0;
78231 if (n->priority > (*nl)->priority)
78232 break;
78233- nl = &((*nl)->next);
78234+ nl = (struct notifier_block **)&((*nl)->next);
78235 }
78236- n->next = *nl;
78237+ pax_open_kernel();
78238+ *(const void **)&n->next = *nl;
78239 rcu_assign_pointer(*nl, n);
78240+ pax_close_kernel();
78241 return 0;
78242 }
78243
78244@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
78245 {
78246 while ((*nl) != NULL) {
78247 if ((*nl) == n) {
78248+ pax_open_kernel();
78249 rcu_assign_pointer(*nl, n->next);
78250+ pax_close_kernel();
78251 return 0;
78252 }
78253- nl = &((*nl)->next);
78254+ nl = (struct notifier_block **)&((*nl)->next);
78255 }
78256 return -ENOENT;
78257 }
78258diff --git a/kernel/panic.c b/kernel/panic.c
78259index 167ec09..0dda5f9 100644
78260--- a/kernel/panic.c
78261+++ b/kernel/panic.c
78262@@ -400,7 +400,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
78263 unsigned taint, struct slowpath_args *args)
78264 {
78265 printk(KERN_WARNING "------------[ cut here ]------------\n");
78266- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
78267+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
78268
78269 if (args)
78270 vprintk(args->fmt, args->args);
78271@@ -453,7 +453,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
78272 */
78273 void __stack_chk_fail(void)
78274 {
78275- panic("stack-protector: Kernel stack is corrupted in: %p\n",
78276+ dump_stack();
78277+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
78278 __builtin_return_address(0));
78279 }
78280 EXPORT_SYMBOL(__stack_chk_fail);
78281diff --git a/kernel/pid.c b/kernel/pid.c
78282index 0db3e79..95b9dc2 100644
78283--- a/kernel/pid.c
78284+++ b/kernel/pid.c
78285@@ -33,6 +33,7 @@
78286 #include <linux/rculist.h>
78287 #include <linux/bootmem.h>
78288 #include <linux/hash.h>
78289+#include <linux/security.h>
78290 #include <linux/pid_namespace.h>
78291 #include <linux/init_task.h>
78292 #include <linux/syscalls.h>
78293@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
78294
78295 int pid_max = PID_MAX_DEFAULT;
78296
78297-#define RESERVED_PIDS 300
78298+#define RESERVED_PIDS 500
78299
78300 int pid_max_min = RESERVED_PIDS + 1;
78301 int pid_max_max = PID_MAX_LIMIT;
78302@@ -442,10 +443,18 @@ EXPORT_SYMBOL(pid_task);
78303 */
78304 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
78305 {
78306+ struct task_struct *task;
78307+
78308 rcu_lockdep_assert(rcu_read_lock_held(),
78309 "find_task_by_pid_ns() needs rcu_read_lock()"
78310 " protection");
78311- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
78312+
78313+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
78314+
78315+ if (gr_pid_is_chrooted(task))
78316+ return NULL;
78317+
78318+ return task;
78319 }
78320
78321 struct task_struct *find_task_by_vpid(pid_t vnr)
78322@@ -453,6 +462,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
78323 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
78324 }
78325
78326+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
78327+{
78328+ rcu_lockdep_assert(rcu_read_lock_held(),
78329+ "find_task_by_pid_ns() needs rcu_read_lock()"
78330+ " protection");
78331+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
78332+}
78333+
78334 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
78335 {
78336 struct pid *pid;
78337diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
78338index 6917e8e..9909aeb 100644
78339--- a/kernel/pid_namespace.c
78340+++ b/kernel/pid_namespace.c
78341@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
78342 void __user *buffer, size_t *lenp, loff_t *ppos)
78343 {
78344 struct pid_namespace *pid_ns = task_active_pid_ns(current);
78345- struct ctl_table tmp = *table;
78346+ ctl_table_no_const tmp = *table;
78347
78348 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
78349 return -EPERM;
78350diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
78351index 42670e9..8719c2f 100644
78352--- a/kernel/posix-cpu-timers.c
78353+++ b/kernel/posix-cpu-timers.c
78354@@ -1636,14 +1636,14 @@ struct k_clock clock_posix_cpu = {
78355
78356 static __init int init_posix_cpu_timers(void)
78357 {
78358- struct k_clock process = {
78359+ static struct k_clock process = {
78360 .clock_getres = process_cpu_clock_getres,
78361 .clock_get = process_cpu_clock_get,
78362 .timer_create = process_cpu_timer_create,
78363 .nsleep = process_cpu_nsleep,
78364 .nsleep_restart = process_cpu_nsleep_restart,
78365 };
78366- struct k_clock thread = {
78367+ static struct k_clock thread = {
78368 .clock_getres = thread_cpu_clock_getres,
78369 .clock_get = thread_cpu_clock_get,
78370 .timer_create = thread_cpu_timer_create,
78371diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
78372index 424c2d4..a9194f7 100644
78373--- a/kernel/posix-timers.c
78374+++ b/kernel/posix-timers.c
78375@@ -43,6 +43,7 @@
78376 #include <linux/hash.h>
78377 #include <linux/posix-clock.h>
78378 #include <linux/posix-timers.h>
78379+#include <linux/grsecurity.h>
78380 #include <linux/syscalls.h>
78381 #include <linux/wait.h>
78382 #include <linux/workqueue.h>
78383@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
78384 * which we beg off on and pass to do_sys_settimeofday().
78385 */
78386
78387-static struct k_clock posix_clocks[MAX_CLOCKS];
78388+static struct k_clock *posix_clocks[MAX_CLOCKS];
78389
78390 /*
78391 * These ones are defined below.
78392@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
78393 */
78394 static __init int init_posix_timers(void)
78395 {
78396- struct k_clock clock_realtime = {
78397+ static struct k_clock clock_realtime = {
78398 .clock_getres = hrtimer_get_res,
78399 .clock_get = posix_clock_realtime_get,
78400 .clock_set = posix_clock_realtime_set,
78401@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
78402 .timer_get = common_timer_get,
78403 .timer_del = common_timer_del,
78404 };
78405- struct k_clock clock_monotonic = {
78406+ static struct k_clock clock_monotonic = {
78407 .clock_getres = hrtimer_get_res,
78408 .clock_get = posix_ktime_get_ts,
78409 .nsleep = common_nsleep,
78410@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
78411 .timer_get = common_timer_get,
78412 .timer_del = common_timer_del,
78413 };
78414- struct k_clock clock_monotonic_raw = {
78415+ static struct k_clock clock_monotonic_raw = {
78416 .clock_getres = hrtimer_get_res,
78417 .clock_get = posix_get_monotonic_raw,
78418 };
78419- struct k_clock clock_realtime_coarse = {
78420+ static struct k_clock clock_realtime_coarse = {
78421 .clock_getres = posix_get_coarse_res,
78422 .clock_get = posix_get_realtime_coarse,
78423 };
78424- struct k_clock clock_monotonic_coarse = {
78425+ static struct k_clock clock_monotonic_coarse = {
78426 .clock_getres = posix_get_coarse_res,
78427 .clock_get = posix_get_monotonic_coarse,
78428 };
78429- struct k_clock clock_tai = {
78430+ static struct k_clock clock_tai = {
78431 .clock_getres = hrtimer_get_res,
78432 .clock_get = posix_get_tai,
78433 .nsleep = common_nsleep,
78434@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
78435 .timer_get = common_timer_get,
78436 .timer_del = common_timer_del,
78437 };
78438- struct k_clock clock_boottime = {
78439+ static struct k_clock clock_boottime = {
78440 .clock_getres = hrtimer_get_res,
78441 .clock_get = posix_get_boottime,
78442 .nsleep = common_nsleep,
78443@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
78444 return;
78445 }
78446
78447- posix_clocks[clock_id] = *new_clock;
78448+ posix_clocks[clock_id] = new_clock;
78449 }
78450 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
78451
78452@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
78453 return (id & CLOCKFD_MASK) == CLOCKFD ?
78454 &clock_posix_dynamic : &clock_posix_cpu;
78455
78456- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
78457+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
78458 return NULL;
78459- return &posix_clocks[id];
78460+ return posix_clocks[id];
78461 }
78462
78463 static int common_timer_create(struct k_itimer *new_timer)
78464@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
78465 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
78466 return -EFAULT;
78467
78468+ /* only the CLOCK_REALTIME clock can be set, all other clocks
78469+ have their clock_set fptr set to a nosettime dummy function
78470+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
78471+ call common_clock_set, which calls do_sys_settimeofday, which
78472+ we hook
78473+ */
78474+
78475 return kc->clock_set(which_clock, &new_tp);
78476 }
78477
78478diff --git a/kernel/power/process.c b/kernel/power/process.c
78479index 98088e0..aaf95c0 100644
78480--- a/kernel/power/process.c
78481+++ b/kernel/power/process.c
78482@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
78483 u64 elapsed_csecs64;
78484 unsigned int elapsed_csecs;
78485 bool wakeup = false;
78486+ bool timedout = false;
78487
78488 do_gettimeofday(&start);
78489
78490@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
78491
78492 while (true) {
78493 todo = 0;
78494+ if (time_after(jiffies, end_time))
78495+ timedout = true;
78496 read_lock(&tasklist_lock);
78497 do_each_thread(g, p) {
78498 if (p == current || !freeze_task(p))
78499 continue;
78500
78501- if (!freezer_should_skip(p))
78502+ if (!freezer_should_skip(p)) {
78503 todo++;
78504+ if (timedout) {
78505+ printk(KERN_ERR "Task refusing to freeze:\n");
78506+ sched_show_task(p);
78507+ }
78508+ }
78509 } while_each_thread(g, p);
78510 read_unlock(&tasklist_lock);
78511
78512@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
78513 todo += wq_busy;
78514 }
78515
78516- if (!todo || time_after(jiffies, end_time))
78517+ if (!todo || timedout)
78518 break;
78519
78520 if (pm_wakeup_pending()) {
78521diff --git a/kernel/printk.c b/kernel/printk.c
78522index d37d45c..ab918b3 100644
78523--- a/kernel/printk.c
78524+++ b/kernel/printk.c
78525@@ -390,6 +390,11 @@ static int check_syslog_permissions(int type, bool from_file)
78526 if (from_file && type != SYSLOG_ACTION_OPEN)
78527 return 0;
78528
78529+#ifdef CONFIG_GRKERNSEC_DMESG
78530+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
78531+ return -EPERM;
78532+#endif
78533+
78534 if (syslog_action_restricted(type)) {
78535 if (capable(CAP_SYSLOG))
78536 return 0;
78537diff --git a/kernel/profile.c b/kernel/profile.c
78538index 0bf4007..6234708 100644
78539--- a/kernel/profile.c
78540+++ b/kernel/profile.c
78541@@ -37,7 +37,7 @@ struct profile_hit {
78542 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
78543 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
78544
78545-static atomic_t *prof_buffer;
78546+static atomic_unchecked_t *prof_buffer;
78547 static unsigned long prof_len, prof_shift;
78548
78549 int prof_on __read_mostly;
78550@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
78551 hits[i].pc = 0;
78552 continue;
78553 }
78554- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
78555+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
78556 hits[i].hits = hits[i].pc = 0;
78557 }
78558 }
78559@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
78560 * Add the current hit(s) and flush the write-queue out
78561 * to the global buffer:
78562 */
78563- atomic_add(nr_hits, &prof_buffer[pc]);
78564+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
78565 for (i = 0; i < NR_PROFILE_HIT; ++i) {
78566- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
78567+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
78568 hits[i].pc = hits[i].hits = 0;
78569 }
78570 out:
78571@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
78572 {
78573 unsigned long pc;
78574 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
78575- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
78576+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
78577 }
78578 #endif /* !CONFIG_SMP */
78579
78580@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
78581 return -EFAULT;
78582 buf++; p++; count--; read++;
78583 }
78584- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
78585+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
78586 if (copy_to_user(buf, (void *)pnt, count))
78587 return -EFAULT;
78588 read += count;
78589@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
78590 }
78591 #endif
78592 profile_discard_flip_buffers();
78593- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
78594+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
78595 return count;
78596 }
78597
78598diff --git a/kernel/ptrace.c b/kernel/ptrace.c
78599index 335a7ae..3bbbceb 100644
78600--- a/kernel/ptrace.c
78601+++ b/kernel/ptrace.c
78602@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
78603 if (seize)
78604 flags |= PT_SEIZED;
78605 rcu_read_lock();
78606- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
78607+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
78608 flags |= PT_PTRACE_CAP;
78609 rcu_read_unlock();
78610 task->ptrace = flags;
78611@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
78612 break;
78613 return -EIO;
78614 }
78615- if (copy_to_user(dst, buf, retval))
78616+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
78617 return -EFAULT;
78618 copied += retval;
78619 src += retval;
78620@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
78621 bool seized = child->ptrace & PT_SEIZED;
78622 int ret = -EIO;
78623 siginfo_t siginfo, *si;
78624- void __user *datavp = (void __user *) data;
78625+ void __user *datavp = (__force void __user *) data;
78626 unsigned long __user *datalp = datavp;
78627 unsigned long flags;
78628
78629@@ -1011,14 +1011,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
78630 goto out;
78631 }
78632
78633+ if (gr_handle_ptrace(child, request)) {
78634+ ret = -EPERM;
78635+ goto out_put_task_struct;
78636+ }
78637+
78638 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
78639 ret = ptrace_attach(child, request, addr, data);
78640 /*
78641 * Some architectures need to do book-keeping after
78642 * a ptrace attach.
78643 */
78644- if (!ret)
78645+ if (!ret) {
78646 arch_ptrace_attach(child);
78647+ gr_audit_ptrace(child);
78648+ }
78649 goto out_put_task_struct;
78650 }
78651
78652@@ -1046,7 +1053,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
78653 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
78654 if (copied != sizeof(tmp))
78655 return -EIO;
78656- return put_user(tmp, (unsigned long __user *)data);
78657+ return put_user(tmp, (__force unsigned long __user *)data);
78658 }
78659
78660 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
78661@@ -1140,7 +1147,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
78662 }
78663
78664 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78665- compat_long_t addr, compat_long_t data)
78666+ compat_ulong_t addr, compat_ulong_t data)
78667 {
78668 struct task_struct *child;
78669 long ret;
78670@@ -1156,14 +1163,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
78671 goto out;
78672 }
78673
78674+ if (gr_handle_ptrace(child, request)) {
78675+ ret = -EPERM;
78676+ goto out_put_task_struct;
78677+ }
78678+
78679 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
78680 ret = ptrace_attach(child, request, addr, data);
78681 /*
78682 * Some architectures need to do book-keeping after
78683 * a ptrace attach.
78684 */
78685- if (!ret)
78686+ if (!ret) {
78687 arch_ptrace_attach(child);
78688+ gr_audit_ptrace(child);
78689+ }
78690 goto out_put_task_struct;
78691 }
78692
78693diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
78694index 48ab703..07561d4 100644
78695--- a/kernel/rcupdate.c
78696+++ b/kernel/rcupdate.c
78697@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
78698 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
78699 */
78700 if (till_stall_check < 3) {
78701- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
78702+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
78703 till_stall_check = 3;
78704 } else if (till_stall_check > 300) {
78705- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
78706+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
78707 till_stall_check = 300;
78708 }
78709 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
78710diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
78711index a0714a5..2ab5e34 100644
78712--- a/kernel/rcutiny.c
78713+++ b/kernel/rcutiny.c
78714@@ -46,7 +46,7 @@
78715 struct rcu_ctrlblk;
78716 static void invoke_rcu_callbacks(void);
78717 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
78718-static void rcu_process_callbacks(struct softirq_action *unused);
78719+static void rcu_process_callbacks(void);
78720 static void __call_rcu(struct rcu_head *head,
78721 void (*func)(struct rcu_head *rcu),
78722 struct rcu_ctrlblk *rcp);
78723@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
78724 rcu_is_callbacks_kthread()));
78725 }
78726
78727-static void rcu_process_callbacks(struct softirq_action *unused)
78728+static void rcu_process_callbacks(void)
78729 {
78730 __rcu_process_callbacks(&rcu_sched_ctrlblk);
78731 __rcu_process_callbacks(&rcu_bh_ctrlblk);
78732diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
78733index 8a23300..4255818 100644
78734--- a/kernel/rcutiny_plugin.h
78735+++ b/kernel/rcutiny_plugin.h
78736@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
78737 have_rcu_kthread_work = morework;
78738 local_irq_restore(flags);
78739 if (work)
78740- rcu_process_callbacks(NULL);
78741+ rcu_process_callbacks();
78742 schedule_timeout_interruptible(1); /* Leave CPU for others. */
78743 }
78744
78745diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
78746index e1f3a8c..42c94a2 100644
78747--- a/kernel/rcutorture.c
78748+++ b/kernel/rcutorture.c
78749@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
78750 { 0 };
78751 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
78752 { 0 };
78753-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
78754-static atomic_t n_rcu_torture_alloc;
78755-static atomic_t n_rcu_torture_alloc_fail;
78756-static atomic_t n_rcu_torture_free;
78757-static atomic_t n_rcu_torture_mberror;
78758-static atomic_t n_rcu_torture_error;
78759+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
78760+static atomic_unchecked_t n_rcu_torture_alloc;
78761+static atomic_unchecked_t n_rcu_torture_alloc_fail;
78762+static atomic_unchecked_t n_rcu_torture_free;
78763+static atomic_unchecked_t n_rcu_torture_mberror;
78764+static atomic_unchecked_t n_rcu_torture_error;
78765 static long n_rcu_torture_barrier_error;
78766 static long n_rcu_torture_boost_ktrerror;
78767 static long n_rcu_torture_boost_rterror;
78768@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
78769
78770 spin_lock_bh(&rcu_torture_lock);
78771 if (list_empty(&rcu_torture_freelist)) {
78772- atomic_inc(&n_rcu_torture_alloc_fail);
78773+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
78774 spin_unlock_bh(&rcu_torture_lock);
78775 return NULL;
78776 }
78777- atomic_inc(&n_rcu_torture_alloc);
78778+ atomic_inc_unchecked(&n_rcu_torture_alloc);
78779 p = rcu_torture_freelist.next;
78780 list_del_init(p);
78781 spin_unlock_bh(&rcu_torture_lock);
78782@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
78783 static void
78784 rcu_torture_free(struct rcu_torture *p)
78785 {
78786- atomic_inc(&n_rcu_torture_free);
78787+ atomic_inc_unchecked(&n_rcu_torture_free);
78788 spin_lock_bh(&rcu_torture_lock);
78789 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
78790 spin_unlock_bh(&rcu_torture_lock);
78791@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
78792 i = rp->rtort_pipe_count;
78793 if (i > RCU_TORTURE_PIPE_LEN)
78794 i = RCU_TORTURE_PIPE_LEN;
78795- atomic_inc(&rcu_torture_wcount[i]);
78796+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78797 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78798 rp->rtort_mbtest = 0;
78799 rcu_torture_free(rp);
78800@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
78801 i = rp->rtort_pipe_count;
78802 if (i > RCU_TORTURE_PIPE_LEN)
78803 i = RCU_TORTURE_PIPE_LEN;
78804- atomic_inc(&rcu_torture_wcount[i]);
78805+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78806 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78807 rp->rtort_mbtest = 0;
78808 list_del(&rp->rtort_free);
78809@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
78810 i = old_rp->rtort_pipe_count;
78811 if (i > RCU_TORTURE_PIPE_LEN)
78812 i = RCU_TORTURE_PIPE_LEN;
78813- atomic_inc(&rcu_torture_wcount[i]);
78814+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78815 old_rp->rtort_pipe_count++;
78816 cur_ops->deferred_free(old_rp);
78817 }
78818@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
78819 return;
78820 }
78821 if (p->rtort_mbtest == 0)
78822- atomic_inc(&n_rcu_torture_mberror);
78823+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78824 spin_lock(&rand_lock);
78825 cur_ops->read_delay(&rand);
78826 n_rcu_torture_timers++;
78827@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
78828 continue;
78829 }
78830 if (p->rtort_mbtest == 0)
78831- atomic_inc(&n_rcu_torture_mberror);
78832+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78833 cur_ops->read_delay(&rand);
78834 preempt_disable();
78835 pipe_count = p->rtort_pipe_count;
78836@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
78837 rcu_torture_current,
78838 rcu_torture_current_version,
78839 list_empty(&rcu_torture_freelist),
78840- atomic_read(&n_rcu_torture_alloc),
78841- atomic_read(&n_rcu_torture_alloc_fail),
78842- atomic_read(&n_rcu_torture_free));
78843+ atomic_read_unchecked(&n_rcu_torture_alloc),
78844+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
78845+ atomic_read_unchecked(&n_rcu_torture_free));
78846 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
78847- atomic_read(&n_rcu_torture_mberror),
78848+ atomic_read_unchecked(&n_rcu_torture_mberror),
78849 n_rcu_torture_boost_ktrerror,
78850 n_rcu_torture_boost_rterror);
78851 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
78852@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
78853 n_barrier_attempts,
78854 n_rcu_torture_barrier_error);
78855 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
78856- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
78857+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
78858 n_rcu_torture_barrier_error != 0 ||
78859 n_rcu_torture_boost_ktrerror != 0 ||
78860 n_rcu_torture_boost_rterror != 0 ||
78861 n_rcu_torture_boost_failure != 0 ||
78862 i > 1) {
78863 cnt += sprintf(&page[cnt], "!!! ");
78864- atomic_inc(&n_rcu_torture_error);
78865+ atomic_inc_unchecked(&n_rcu_torture_error);
78866 WARN_ON_ONCE(1);
78867 }
78868 cnt += sprintf(&page[cnt], "Reader Pipe: ");
78869@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
78870 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
78871 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78872 cnt += sprintf(&page[cnt], " %d",
78873- atomic_read(&rcu_torture_wcount[i]));
78874+ atomic_read_unchecked(&rcu_torture_wcount[i]));
78875 }
78876 cnt += sprintf(&page[cnt], "\n");
78877 if (cur_ops->stats)
78878@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
78879
78880 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
78881
78882- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78883+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78884 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
78885 else if (n_online_successes != n_online_attempts ||
78886 n_offline_successes != n_offline_attempts)
78887@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
78888
78889 rcu_torture_current = NULL;
78890 rcu_torture_current_version = 0;
78891- atomic_set(&n_rcu_torture_alloc, 0);
78892- atomic_set(&n_rcu_torture_alloc_fail, 0);
78893- atomic_set(&n_rcu_torture_free, 0);
78894- atomic_set(&n_rcu_torture_mberror, 0);
78895- atomic_set(&n_rcu_torture_error, 0);
78896+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
78897+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
78898+ atomic_set_unchecked(&n_rcu_torture_free, 0);
78899+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
78900+ atomic_set_unchecked(&n_rcu_torture_error, 0);
78901 n_rcu_torture_barrier_error = 0;
78902 n_rcu_torture_boost_ktrerror = 0;
78903 n_rcu_torture_boost_rterror = 0;
78904 n_rcu_torture_boost_failure = 0;
78905 n_rcu_torture_boosts = 0;
78906 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
78907- atomic_set(&rcu_torture_wcount[i], 0);
78908+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
78909 for_each_possible_cpu(cpu) {
78910 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78911 per_cpu(rcu_torture_count, cpu)[i] = 0;
78912diff --git a/kernel/rcutree.c b/kernel/rcutree.c
78913index 3538001..e379e0b 100644
78914--- a/kernel/rcutree.c
78915+++ b/kernel/rcutree.c
78916@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
78917 rcu_prepare_for_idle(smp_processor_id());
78918 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78919 smp_mb__before_atomic_inc(); /* See above. */
78920- atomic_inc(&rdtp->dynticks);
78921+ atomic_inc_unchecked(&rdtp->dynticks);
78922 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
78923- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78924+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78925
78926 /*
78927 * It is illegal to enter an extended quiescent state while
78928@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
78929 int user)
78930 {
78931 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
78932- atomic_inc(&rdtp->dynticks);
78933+ atomic_inc_unchecked(&rdtp->dynticks);
78934 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78935 smp_mb__after_atomic_inc(); /* See above. */
78936- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78937+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78938 rcu_cleanup_after_idle(smp_processor_id());
78939 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
78940 if (!user && !is_idle_task(current)) {
78941@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
78942 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
78943
78944 if (rdtp->dynticks_nmi_nesting == 0 &&
78945- (atomic_read(&rdtp->dynticks) & 0x1))
78946+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
78947 return;
78948 rdtp->dynticks_nmi_nesting++;
78949 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
78950- atomic_inc(&rdtp->dynticks);
78951+ atomic_inc_unchecked(&rdtp->dynticks);
78952 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78953 smp_mb__after_atomic_inc(); /* See above. */
78954- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78955+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78956 }
78957
78958 /**
78959@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
78960 return;
78961 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78962 smp_mb__before_atomic_inc(); /* See above. */
78963- atomic_inc(&rdtp->dynticks);
78964+ atomic_inc_unchecked(&rdtp->dynticks);
78965 smp_mb__after_atomic_inc(); /* Force delay to next write. */
78966- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78967+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78968 }
78969
78970 /**
78971@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
78972 int ret;
78973
78974 preempt_disable();
78975- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78976+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78977 preempt_enable();
78978 return ret;
78979 }
78980@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
78981 */
78982 static int dyntick_save_progress_counter(struct rcu_data *rdp)
78983 {
78984- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
78985+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78986 return (rdp->dynticks_snap & 0x1) == 0;
78987 }
78988
78989@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
78990 unsigned int curr;
78991 unsigned int snap;
78992
78993- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
78994+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78995 snap = (unsigned int)rdp->dynticks_snap;
78996
78997 /*
78998@@ -1440,9 +1440,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
78999 rdp = this_cpu_ptr(rsp->rda);
79000 rcu_preempt_check_blocked_tasks(rnp);
79001 rnp->qsmask = rnp->qsmaskinit;
79002- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
79003+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
79004 WARN_ON_ONCE(rnp->completed != rsp->completed);
79005- ACCESS_ONCE(rnp->completed) = rsp->completed;
79006+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
79007 if (rnp == rdp->mynode)
79008 rcu_start_gp_per_cpu(rsp, rnp, rdp);
79009 rcu_preempt_boost_start_gp(rnp);
79010@@ -1524,7 +1524,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
79011 */
79012 rcu_for_each_node_breadth_first(rsp, rnp) {
79013 raw_spin_lock_irq(&rnp->lock);
79014- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
79015+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
79016 rdp = this_cpu_ptr(rsp->rda);
79017 if (rnp == rdp->mynode)
79018 __rcu_process_gp_end(rsp, rnp, rdp);
79019@@ -1855,7 +1855,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
79020 rsp->qlen += rdp->qlen;
79021 rdp->n_cbs_orphaned += rdp->qlen;
79022 rdp->qlen_lazy = 0;
79023- ACCESS_ONCE(rdp->qlen) = 0;
79024+ ACCESS_ONCE_RW(rdp->qlen) = 0;
79025 }
79026
79027 /*
79028@@ -2101,7 +2101,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
79029 }
79030 smp_mb(); /* List handling before counting for rcu_barrier(). */
79031 rdp->qlen_lazy -= count_lazy;
79032- ACCESS_ONCE(rdp->qlen) -= count;
79033+ ACCESS_ONCE_RW(rdp->qlen) -= count;
79034 rdp->n_cbs_invoked += count;
79035
79036 /* Reinstate batch limit if we have worked down the excess. */
79037@@ -2295,7 +2295,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
79038 /*
79039 * Do RCU core processing for the current CPU.
79040 */
79041-static void rcu_process_callbacks(struct softirq_action *unused)
79042+static void rcu_process_callbacks(void)
79043 {
79044 struct rcu_state *rsp;
79045
79046@@ -2419,7 +2419,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
79047 local_irq_restore(flags);
79048 return;
79049 }
79050- ACCESS_ONCE(rdp->qlen)++;
79051+ ACCESS_ONCE_RW(rdp->qlen)++;
79052 if (lazy)
79053 rdp->qlen_lazy++;
79054 else
79055@@ -2628,11 +2628,11 @@ void synchronize_sched_expedited(void)
79056 * counter wrap on a 32-bit system. Quite a few more CPUs would of
79057 * course be required on a 64-bit system.
79058 */
79059- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
79060+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
79061 (ulong)atomic_long_read(&rsp->expedited_done) +
79062 ULONG_MAX / 8)) {
79063 synchronize_sched();
79064- atomic_long_inc(&rsp->expedited_wrap);
79065+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
79066 return;
79067 }
79068
79069@@ -2640,7 +2640,7 @@ void synchronize_sched_expedited(void)
79070 * Take a ticket. Note that atomic_inc_return() implies a
79071 * full memory barrier.
79072 */
79073- snap = atomic_long_inc_return(&rsp->expedited_start);
79074+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
79075 firstsnap = snap;
79076 get_online_cpus();
79077 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
79078@@ -2653,14 +2653,14 @@ void synchronize_sched_expedited(void)
79079 synchronize_sched_expedited_cpu_stop,
79080 NULL) == -EAGAIN) {
79081 put_online_cpus();
79082- atomic_long_inc(&rsp->expedited_tryfail);
79083+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
79084
79085 /* Check to see if someone else did our work for us. */
79086 s = atomic_long_read(&rsp->expedited_done);
79087 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
79088 /* ensure test happens before caller kfree */
79089 smp_mb__before_atomic_inc(); /* ^^^ */
79090- atomic_long_inc(&rsp->expedited_workdone1);
79091+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
79092 return;
79093 }
79094
79095@@ -2669,7 +2669,7 @@ void synchronize_sched_expedited(void)
79096 udelay(trycount * num_online_cpus());
79097 } else {
79098 wait_rcu_gp(call_rcu_sched);
79099- atomic_long_inc(&rsp->expedited_normal);
79100+ atomic_long_inc_unchecked(&rsp->expedited_normal);
79101 return;
79102 }
79103
79104@@ -2678,7 +2678,7 @@ void synchronize_sched_expedited(void)
79105 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
79106 /* ensure test happens before caller kfree */
79107 smp_mb__before_atomic_inc(); /* ^^^ */
79108- atomic_long_inc(&rsp->expedited_workdone2);
79109+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
79110 return;
79111 }
79112
79113@@ -2690,10 +2690,10 @@ void synchronize_sched_expedited(void)
79114 * period works for us.
79115 */
79116 get_online_cpus();
79117- snap = atomic_long_read(&rsp->expedited_start);
79118+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
79119 smp_mb(); /* ensure read is before try_stop_cpus(). */
79120 }
79121- atomic_long_inc(&rsp->expedited_stoppedcpus);
79122+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
79123
79124 /*
79125 * Everyone up to our most recent fetch is covered by our grace
79126@@ -2702,16 +2702,16 @@ void synchronize_sched_expedited(void)
79127 * than we did already did their update.
79128 */
79129 do {
79130- atomic_long_inc(&rsp->expedited_done_tries);
79131+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
79132 s = atomic_long_read(&rsp->expedited_done);
79133 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
79134 /* ensure test happens before caller kfree */
79135 smp_mb__before_atomic_inc(); /* ^^^ */
79136- atomic_long_inc(&rsp->expedited_done_lost);
79137+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
79138 break;
79139 }
79140 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
79141- atomic_long_inc(&rsp->expedited_done_exit);
79142+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
79143
79144 put_online_cpus();
79145 }
79146@@ -2893,7 +2893,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
79147 * ACCESS_ONCE() to prevent the compiler from speculating
79148 * the increment to precede the early-exit check.
79149 */
79150- ACCESS_ONCE(rsp->n_barrier_done)++;
79151+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
79152 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
79153 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
79154 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
79155@@ -2943,7 +2943,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
79156
79157 /* Increment ->n_barrier_done to prevent duplicate work. */
79158 smp_mb(); /* Keep increment after above mechanism. */
79159- ACCESS_ONCE(rsp->n_barrier_done)++;
79160+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
79161 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
79162 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
79163 smp_mb(); /* Keep increment before caller's subsequent code. */
79164@@ -2988,10 +2988,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
79165 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
79166 init_callback_list(rdp);
79167 rdp->qlen_lazy = 0;
79168- ACCESS_ONCE(rdp->qlen) = 0;
79169+ ACCESS_ONCE_RW(rdp->qlen) = 0;
79170 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
79171 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
79172- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
79173+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
79174 rdp->cpu = cpu;
79175 rdp->rsp = rsp;
79176 rcu_boot_init_nocb_percpu_data(rdp);
79177@@ -3024,8 +3024,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
79178 rdp->blimit = blimit;
79179 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
79180 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
79181- atomic_set(&rdp->dynticks->dynticks,
79182- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
79183+ atomic_set_unchecked(&rdp->dynticks->dynticks,
79184+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
79185 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
79186
79187 /* Add CPU to rcu_node bitmasks. */
79188@@ -3120,7 +3120,7 @@ static int __init rcu_spawn_gp_kthread(void)
79189 struct task_struct *t;
79190
79191 for_each_rcu_flavor(rsp) {
79192- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
79193+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
79194 BUG_ON(IS_ERR(t));
79195 rnp = rcu_get_root(rsp);
79196 raw_spin_lock_irqsave(&rnp->lock, flags);
79197diff --git a/kernel/rcutree.h b/kernel/rcutree.h
79198index 4df5034..5ee93f2 100644
79199--- a/kernel/rcutree.h
79200+++ b/kernel/rcutree.h
79201@@ -87,7 +87,7 @@ struct rcu_dynticks {
79202 long long dynticks_nesting; /* Track irq/process nesting level. */
79203 /* Process level is worth LLONG_MAX/2. */
79204 int dynticks_nmi_nesting; /* Track NMI nesting level. */
79205- atomic_t dynticks; /* Even value for idle, else odd. */
79206+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
79207 #ifdef CONFIG_RCU_FAST_NO_HZ
79208 bool all_lazy; /* Are all CPU's CBs lazy? */
79209 unsigned long nonlazy_posted;
79210@@ -414,17 +414,17 @@ struct rcu_state {
79211 /* _rcu_barrier(). */
79212 /* End of fields guarded by barrier_mutex. */
79213
79214- atomic_long_t expedited_start; /* Starting ticket. */
79215- atomic_long_t expedited_done; /* Done ticket. */
79216- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
79217- atomic_long_t expedited_tryfail; /* # acquisition failures. */
79218- atomic_long_t expedited_workdone1; /* # done by others #1. */
79219- atomic_long_t expedited_workdone2; /* # done by others #2. */
79220- atomic_long_t expedited_normal; /* # fallbacks to normal. */
79221- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
79222- atomic_long_t expedited_done_tries; /* # tries to update _done. */
79223- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
79224- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
79225+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
79226+ atomic_long_t expedited_done; /* Done ticket. */
79227+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
79228+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
79229+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
79230+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
79231+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
79232+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
79233+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
79234+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
79235+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
79236
79237 unsigned long jiffies_force_qs; /* Time at which to invoke */
79238 /* force_quiescent_state(). */
79239diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
79240index 3db5a37..b395fb35 100644
79241--- a/kernel/rcutree_plugin.h
79242+++ b/kernel/rcutree_plugin.h
79243@@ -903,7 +903,7 @@ void synchronize_rcu_expedited(void)
79244
79245 /* Clean up and exit. */
79246 smp_mb(); /* ensure expedited GP seen before counter increment. */
79247- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
79248+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
79249 unlock_mb_ret:
79250 mutex_unlock(&sync_rcu_preempt_exp_mutex);
79251 mb_ret:
79252@@ -1451,7 +1451,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
79253 free_cpumask_var(cm);
79254 }
79255
79256-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
79257+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
79258 .store = &rcu_cpu_kthread_task,
79259 .thread_should_run = rcu_cpu_kthread_should_run,
79260 .thread_fn = rcu_cpu_kthread,
79261@@ -1916,7 +1916,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
79262 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
79263 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
79264 cpu, ticks_value, ticks_title,
79265- atomic_read(&rdtp->dynticks) & 0xfff,
79266+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
79267 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
79268 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
79269 fast_no_hz);
79270@@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
79271
79272 /* Enqueue the callback on the nocb list and update counts. */
79273 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
79274- ACCESS_ONCE(*old_rhpp) = rhp;
79275+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
79276 atomic_long_add(rhcount, &rdp->nocb_q_count);
79277 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
79278
79279@@ -2219,12 +2219,12 @@ static int rcu_nocb_kthread(void *arg)
79280 * Extract queued callbacks, update counts, and wait
79281 * for a grace period to elapse.
79282 */
79283- ACCESS_ONCE(rdp->nocb_head) = NULL;
79284+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
79285 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
79286 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
79287 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
79288- ACCESS_ONCE(rdp->nocb_p_count) += c;
79289- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
79290+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
79291+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
79292 rcu_nocb_wait_gp(rdp);
79293
79294 /* Each pass through the following loop invokes a callback. */
79295@@ -2246,8 +2246,8 @@ static int rcu_nocb_kthread(void *arg)
79296 list = next;
79297 }
79298 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
79299- ACCESS_ONCE(rdp->nocb_p_count) -= c;
79300- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
79301+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
79302+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
79303 rdp->n_nocbs_invoked += c;
79304 }
79305 return 0;
79306@@ -2274,7 +2274,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
79307 t = kthread_run(rcu_nocb_kthread, rdp,
79308 "rcuo%c/%d", rsp->abbr, cpu);
79309 BUG_ON(IS_ERR(t));
79310- ACCESS_ONCE(rdp->nocb_kthread) = t;
79311+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
79312 }
79313 }
79314
79315diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
79316index cf6c174..a8f4b50 100644
79317--- a/kernel/rcutree_trace.c
79318+++ b/kernel/rcutree_trace.c
79319@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
79320 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
79321 rdp->passed_quiesce, rdp->qs_pending);
79322 seq_printf(m, " dt=%d/%llx/%d df=%lu",
79323- atomic_read(&rdp->dynticks->dynticks),
79324+ atomic_read_unchecked(&rdp->dynticks->dynticks),
79325 rdp->dynticks->dynticks_nesting,
79326 rdp->dynticks->dynticks_nmi_nesting,
79327 rdp->dynticks_fqs);
79328@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
79329 struct rcu_state *rsp = (struct rcu_state *)m->private;
79330
79331 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",
79332- atomic_long_read(&rsp->expedited_start),
79333+ atomic_long_read_unchecked(&rsp->expedited_start),
79334 atomic_long_read(&rsp->expedited_done),
79335- atomic_long_read(&rsp->expedited_wrap),
79336- atomic_long_read(&rsp->expedited_tryfail),
79337- atomic_long_read(&rsp->expedited_workdone1),
79338- atomic_long_read(&rsp->expedited_workdone2),
79339- atomic_long_read(&rsp->expedited_normal),
79340- atomic_long_read(&rsp->expedited_stoppedcpus),
79341- atomic_long_read(&rsp->expedited_done_tries),
79342- atomic_long_read(&rsp->expedited_done_lost),
79343- atomic_long_read(&rsp->expedited_done_exit));
79344+ atomic_long_read_unchecked(&rsp->expedited_wrap),
79345+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
79346+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
79347+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
79348+ atomic_long_read_unchecked(&rsp->expedited_normal),
79349+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
79350+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
79351+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
79352+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
79353 return 0;
79354 }
79355
79356diff --git a/kernel/resource.c b/kernel/resource.c
79357index d738698..5f8e60a 100644
79358--- a/kernel/resource.c
79359+++ b/kernel/resource.c
79360@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
79361
79362 static int __init ioresources_init(void)
79363 {
79364+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79365+#ifdef CONFIG_GRKERNSEC_PROC_USER
79366+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
79367+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
79368+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79369+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
79370+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
79371+#endif
79372+#else
79373 proc_create("ioports", 0, NULL, &proc_ioports_operations);
79374 proc_create("iomem", 0, NULL, &proc_iomem_operations);
79375+#endif
79376 return 0;
79377 }
79378 __initcall(ioresources_init);
79379diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
79380index 1d96dd0..994ff19 100644
79381--- a/kernel/rtmutex-tester.c
79382+++ b/kernel/rtmutex-tester.c
79383@@ -22,7 +22,7 @@
79384 #define MAX_RT_TEST_MUTEXES 8
79385
79386 static spinlock_t rttest_lock;
79387-static atomic_t rttest_event;
79388+static atomic_unchecked_t rttest_event;
79389
79390 struct test_thread_data {
79391 int opcode;
79392@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
79393
79394 case RTTEST_LOCKCONT:
79395 td->mutexes[td->opdata] = 1;
79396- td->event = atomic_add_return(1, &rttest_event);
79397+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79398 return 0;
79399
79400 case RTTEST_RESET:
79401@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
79402 return 0;
79403
79404 case RTTEST_RESETEVENT:
79405- atomic_set(&rttest_event, 0);
79406+ atomic_set_unchecked(&rttest_event, 0);
79407 return 0;
79408
79409 default:
79410@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
79411 return ret;
79412
79413 td->mutexes[id] = 1;
79414- td->event = atomic_add_return(1, &rttest_event);
79415+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79416 rt_mutex_lock(&mutexes[id]);
79417- td->event = atomic_add_return(1, &rttest_event);
79418+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79419 td->mutexes[id] = 4;
79420 return 0;
79421
79422@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
79423 return ret;
79424
79425 td->mutexes[id] = 1;
79426- td->event = atomic_add_return(1, &rttest_event);
79427+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79428 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
79429- td->event = atomic_add_return(1, &rttest_event);
79430+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79431 td->mutexes[id] = ret ? 0 : 4;
79432 return ret ? -EINTR : 0;
79433
79434@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
79435 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
79436 return ret;
79437
79438- td->event = atomic_add_return(1, &rttest_event);
79439+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79440 rt_mutex_unlock(&mutexes[id]);
79441- td->event = atomic_add_return(1, &rttest_event);
79442+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79443 td->mutexes[id] = 0;
79444 return 0;
79445
79446@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
79447 break;
79448
79449 td->mutexes[dat] = 2;
79450- td->event = atomic_add_return(1, &rttest_event);
79451+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79452 break;
79453
79454 default:
79455@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
79456 return;
79457
79458 td->mutexes[dat] = 3;
79459- td->event = atomic_add_return(1, &rttest_event);
79460+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79461 break;
79462
79463 case RTTEST_LOCKNOWAIT:
79464@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
79465 return;
79466
79467 td->mutexes[dat] = 1;
79468- td->event = atomic_add_return(1, &rttest_event);
79469+ td->event = atomic_add_return_unchecked(1, &rttest_event);
79470 return;
79471
79472 default:
79473diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
79474index 64de5f8..7735e12 100644
79475--- a/kernel/sched/auto_group.c
79476+++ b/kernel/sched/auto_group.c
79477@@ -11,7 +11,7 @@
79478
79479 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
79480 static struct autogroup autogroup_default;
79481-static atomic_t autogroup_seq_nr;
79482+static atomic_unchecked_t autogroup_seq_nr;
79483
79484 void __init autogroup_init(struct task_struct *init_task)
79485 {
79486@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
79487
79488 kref_init(&ag->kref);
79489 init_rwsem(&ag->lock);
79490- ag->id = atomic_inc_return(&autogroup_seq_nr);
79491+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
79492 ag->tg = tg;
79493 #ifdef CONFIG_RT_GROUP_SCHED
79494 /*
79495diff --git a/kernel/sched/core.c b/kernel/sched/core.c
79496index e8b3350..d83d44e 100644
79497--- a/kernel/sched/core.c
79498+++ b/kernel/sched/core.c
79499@@ -3440,7 +3440,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
79500 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
79501 * positive (at least 1, or number of jiffies left till timeout) if completed.
79502 */
79503-long __sched
79504+long __sched __intentional_overflow(-1)
79505 wait_for_completion_interruptible_timeout(struct completion *x,
79506 unsigned long timeout)
79507 {
79508@@ -3457,7 +3457,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
79509 *
79510 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
79511 */
79512-int __sched wait_for_completion_killable(struct completion *x)
79513+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
79514 {
79515 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
79516 if (t == -ERESTARTSYS)
79517@@ -3478,7 +3478,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
79518 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
79519 * positive (at least 1, or number of jiffies left till timeout) if completed.
79520 */
79521-long __sched
79522+long __sched __intentional_overflow(-1)
79523 wait_for_completion_killable_timeout(struct completion *x,
79524 unsigned long timeout)
79525 {
79526@@ -3704,6 +3704,8 @@ int can_nice(const struct task_struct *p, const int nice)
79527 /* convert nice value [19,-20] to rlimit style value [1,40] */
79528 int nice_rlim = 20 - nice;
79529
79530+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
79531+
79532 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
79533 capable(CAP_SYS_NICE));
79534 }
79535@@ -3737,7 +3739,8 @@ SYSCALL_DEFINE1(nice, int, increment)
79536 if (nice > 19)
79537 nice = 19;
79538
79539- if (increment < 0 && !can_nice(current, nice))
79540+ if (increment < 0 && (!can_nice(current, nice) ||
79541+ gr_handle_chroot_nice()))
79542 return -EPERM;
79543
79544 retval = security_task_setnice(current, nice);
79545@@ -3891,6 +3894,7 @@ recheck:
79546 unsigned long rlim_rtprio =
79547 task_rlimit(p, RLIMIT_RTPRIO);
79548
79549+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
79550 /* can't set/change the rt policy */
79551 if (policy != p->policy && !rlim_rtprio)
79552 return -EPERM;
79553@@ -4988,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
79554
79555 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
79556
79557-static struct ctl_table sd_ctl_dir[] = {
79558+static ctl_table_no_const sd_ctl_dir[] __read_only = {
79559 {
79560 .procname = "sched_domain",
79561 .mode = 0555,
79562@@ -5005,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
79563 {}
79564 };
79565
79566-static struct ctl_table *sd_alloc_ctl_entry(int n)
79567+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
79568 {
79569- struct ctl_table *entry =
79570+ ctl_table_no_const *entry =
79571 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
79572
79573 return entry;
79574 }
79575
79576-static void sd_free_ctl_entry(struct ctl_table **tablep)
79577+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
79578 {
79579- struct ctl_table *entry;
79580+ ctl_table_no_const *entry;
79581
79582 /*
79583 * In the intermediate directories, both the child directory and
79584@@ -5023,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
79585 * will always be set. In the lowest directory the names are
79586 * static strings and all have proc handlers.
79587 */
79588- for (entry = *tablep; entry->mode; entry++) {
79589- if (entry->child)
79590- sd_free_ctl_entry(&entry->child);
79591+ for (entry = tablep; entry->mode; entry++) {
79592+ if (entry->child) {
79593+ sd_free_ctl_entry(entry->child);
79594+ pax_open_kernel();
79595+ entry->child = NULL;
79596+ pax_close_kernel();
79597+ }
79598 if (entry->proc_handler == NULL)
79599 kfree(entry->procname);
79600 }
79601
79602- kfree(*tablep);
79603- *tablep = NULL;
79604+ kfree(tablep);
79605 }
79606
79607 static int min_load_idx = 0;
79608 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
79609
79610 static void
79611-set_table_entry(struct ctl_table *entry,
79612+set_table_entry(ctl_table_no_const *entry,
79613 const char *procname, void *data, int maxlen,
79614 umode_t mode, proc_handler *proc_handler,
79615 bool load_idx)
79616@@ -5058,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
79617 static struct ctl_table *
79618 sd_alloc_ctl_domain_table(struct sched_domain *sd)
79619 {
79620- struct ctl_table *table = sd_alloc_ctl_entry(13);
79621+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
79622
79623 if (table == NULL)
79624 return NULL;
79625@@ -5093,9 +5100,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
79626 return table;
79627 }
79628
79629-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
79630+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
79631 {
79632- struct ctl_table *entry, *table;
79633+ ctl_table_no_const *entry, *table;
79634 struct sched_domain *sd;
79635 int domain_num = 0, i;
79636 char buf[32];
79637@@ -5122,11 +5129,13 @@ static struct ctl_table_header *sd_sysctl_header;
79638 static void register_sched_domain_sysctl(void)
79639 {
79640 int i, cpu_num = num_possible_cpus();
79641- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
79642+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
79643 char buf[32];
79644
79645 WARN_ON(sd_ctl_dir[0].child);
79646+ pax_open_kernel();
79647 sd_ctl_dir[0].child = entry;
79648+ pax_close_kernel();
79649
79650 if (entry == NULL)
79651 return;
79652@@ -5149,8 +5158,12 @@ static void unregister_sched_domain_sysctl(void)
79653 if (sd_sysctl_header)
79654 unregister_sysctl_table(sd_sysctl_header);
79655 sd_sysctl_header = NULL;
79656- if (sd_ctl_dir[0].child)
79657- sd_free_ctl_entry(&sd_ctl_dir[0].child);
79658+ if (sd_ctl_dir[0].child) {
79659+ sd_free_ctl_entry(sd_ctl_dir[0].child);
79660+ pax_open_kernel();
79661+ sd_ctl_dir[0].child = NULL;
79662+ pax_close_kernel();
79663+ }
79664 }
79665 #else
79666 static void register_sched_domain_sysctl(void)
79667@@ -5249,7 +5262,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
79668 * happens before everything else. This has to be lower priority than
79669 * the notifier in the perf_event subsystem, though.
79670 */
79671-static struct notifier_block __cpuinitdata migration_notifier = {
79672+static struct notifier_block migration_notifier = {
79673 .notifier_call = migration_call,
79674 .priority = CPU_PRI_MIGRATION,
79675 };
79676diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
79677index c61a614..d7f3d7e 100644
79678--- a/kernel/sched/fair.c
79679+++ b/kernel/sched/fair.c
79680@@ -831,7 +831,7 @@ void task_numa_fault(int node, int pages, bool migrated)
79681
79682 static void reset_ptenuma_scan(struct task_struct *p)
79683 {
79684- ACCESS_ONCE(p->mm->numa_scan_seq)++;
79685+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
79686 p->mm->numa_scan_offset = 0;
79687 }
79688
79689@@ -5686,7 +5686,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
79690 * run_rebalance_domains is triggered when needed from the scheduler tick.
79691 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
79692 */
79693-static void run_rebalance_domains(struct softirq_action *h)
79694+static void run_rebalance_domains(void)
79695 {
79696 int this_cpu = smp_processor_id();
79697 struct rq *this_rq = cpu_rq(this_cpu);
79698diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
79699index ce39224d..0e09343 100644
79700--- a/kernel/sched/sched.h
79701+++ b/kernel/sched/sched.h
79702@@ -1009,7 +1009,7 @@ struct sched_class {
79703 #ifdef CONFIG_FAIR_GROUP_SCHED
79704 void (*task_move_group) (struct task_struct *p, int on_rq);
79705 #endif
79706-};
79707+} __do_const;
79708
79709 #define sched_class_highest (&stop_sched_class)
79710 #define for_each_class(class) \
79711diff --git a/kernel/signal.c b/kernel/signal.c
79712index 113411b..17190e2 100644
79713--- a/kernel/signal.c
79714+++ b/kernel/signal.c
79715@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
79716
79717 int print_fatal_signals __read_mostly;
79718
79719-static void __user *sig_handler(struct task_struct *t, int sig)
79720+static __sighandler_t sig_handler(struct task_struct *t, int sig)
79721 {
79722 return t->sighand->action[sig - 1].sa.sa_handler;
79723 }
79724
79725-static int sig_handler_ignored(void __user *handler, int sig)
79726+static int sig_handler_ignored(__sighandler_t handler, int sig)
79727 {
79728 /* Is it explicitly or implicitly ignored? */
79729 return handler == SIG_IGN ||
79730@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
79731
79732 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
79733 {
79734- void __user *handler;
79735+ __sighandler_t handler;
79736
79737 handler = sig_handler(t, sig);
79738
79739@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
79740 atomic_inc(&user->sigpending);
79741 rcu_read_unlock();
79742
79743+ if (!override_rlimit)
79744+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
79745+
79746 if (override_rlimit ||
79747 atomic_read(&user->sigpending) <=
79748 task_rlimit(t, RLIMIT_SIGPENDING)) {
79749@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
79750
79751 int unhandled_signal(struct task_struct *tsk, int sig)
79752 {
79753- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
79754+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
79755 if (is_global_init(tsk))
79756 return 1;
79757 if (handler != SIG_IGN && handler != SIG_DFL)
79758@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
79759 }
79760 }
79761
79762+ /* allow glibc communication via tgkill to other threads in our
79763+ thread group */
79764+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
79765+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
79766+ && gr_handle_signal(t, sig))
79767+ return -EPERM;
79768+
79769 return security_task_kill(t, info, sig, 0);
79770 }
79771
79772@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79773 return send_signal(sig, info, p, 1);
79774 }
79775
79776-static int
79777+int
79778 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79779 {
79780 return send_signal(sig, info, t, 0);
79781@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79782 unsigned long int flags;
79783 int ret, blocked, ignored;
79784 struct k_sigaction *action;
79785+ int is_unhandled = 0;
79786
79787 spin_lock_irqsave(&t->sighand->siglock, flags);
79788 action = &t->sighand->action[sig-1];
79789@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79790 }
79791 if (action->sa.sa_handler == SIG_DFL)
79792 t->signal->flags &= ~SIGNAL_UNKILLABLE;
79793+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
79794+ is_unhandled = 1;
79795 ret = specific_send_sig_info(sig, info, t);
79796 spin_unlock_irqrestore(&t->sighand->siglock, flags);
79797
79798+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
79799+ normal operation */
79800+ if (is_unhandled) {
79801+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
79802+ gr_handle_crash(t, sig);
79803+ }
79804+
79805 return ret;
79806 }
79807
79808@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79809 ret = check_kill_permission(sig, info, p);
79810 rcu_read_unlock();
79811
79812- if (!ret && sig)
79813+ if (!ret && sig) {
79814 ret = do_send_sig_info(sig, info, p, true);
79815+ if (!ret)
79816+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
79817+ }
79818
79819 return ret;
79820 }
79821@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
79822 int error = -ESRCH;
79823
79824 rcu_read_lock();
79825- p = find_task_by_vpid(pid);
79826+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79827+ /* allow glibc communication via tgkill to other threads in our
79828+ thread group */
79829+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
79830+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
79831+ p = find_task_by_vpid_unrestricted(pid);
79832+ else
79833+#endif
79834+ p = find_task_by_vpid(pid);
79835 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
79836 error = check_kill_permission(sig, info, p);
79837 /*
79838@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
79839 }
79840 seg = get_fs();
79841 set_fs(KERNEL_DS);
79842- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
79843- (stack_t __force __user *) &uoss,
79844+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
79845+ (stack_t __force_user *) &uoss,
79846 compat_user_stack_pointer());
79847 set_fs(seg);
79848 if (ret >= 0 && uoss_ptr) {
79849diff --git a/kernel/smp.c b/kernel/smp.c
79850index 4dba0f7..fe9f773 100644
79851--- a/kernel/smp.c
79852+++ b/kernel/smp.c
79853@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
79854 return NOTIFY_OK;
79855 }
79856
79857-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
79858+static struct notifier_block hotplug_cfd_notifier = {
79859 .notifier_call = hotplug_cfd,
79860 };
79861
79862diff --git a/kernel/smpboot.c b/kernel/smpboot.c
79863index 02fc5c9..e54c335 100644
79864--- a/kernel/smpboot.c
79865+++ b/kernel/smpboot.c
79866@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
79867 }
79868 smpboot_unpark_thread(plug_thread, cpu);
79869 }
79870- list_add(&plug_thread->list, &hotplug_threads);
79871+ pax_list_add(&plug_thread->list, &hotplug_threads);
79872 out:
79873 mutex_unlock(&smpboot_threads_lock);
79874 return ret;
79875@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
79876 {
79877 get_online_cpus();
79878 mutex_lock(&smpboot_threads_lock);
79879- list_del(&plug_thread->list);
79880+ pax_list_del(&plug_thread->list);
79881 smpboot_destroy_threads(plug_thread);
79882 mutex_unlock(&smpboot_threads_lock);
79883 put_online_cpus();
79884diff --git a/kernel/softirq.c b/kernel/softirq.c
79885index 3d6833f..da6d93d 100644
79886--- a/kernel/softirq.c
79887+++ b/kernel/softirq.c
79888@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
79889 EXPORT_SYMBOL(irq_stat);
79890 #endif
79891
79892-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
79893+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
79894
79895 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
79896
79897-char *softirq_to_name[NR_SOFTIRQS] = {
79898+const char * const softirq_to_name[NR_SOFTIRQS] = {
79899 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
79900 "TASKLET", "SCHED", "HRTIMER", "RCU"
79901 };
79902@@ -250,7 +250,7 @@ restart:
79903 kstat_incr_softirqs_this_cpu(vec_nr);
79904
79905 trace_softirq_entry(vec_nr);
79906- h->action(h);
79907+ h->action();
79908 trace_softirq_exit(vec_nr);
79909 if (unlikely(prev_count != preempt_count())) {
79910 printk(KERN_ERR "huh, entered softirq %u %s %p"
79911@@ -405,7 +405,7 @@ void __raise_softirq_irqoff(unsigned int nr)
79912 or_softirq_pending(1UL << nr);
79913 }
79914
79915-void open_softirq(int nr, void (*action)(struct softirq_action *))
79916+void __init open_softirq(int nr, void (*action)(void))
79917 {
79918 softirq_vec[nr].action = action;
79919 }
79920@@ -461,7 +461,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
79921
79922 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
79923
79924-static void tasklet_action(struct softirq_action *a)
79925+static void tasklet_action(void)
79926 {
79927 struct tasklet_struct *list;
79928
79929@@ -496,7 +496,7 @@ static void tasklet_action(struct softirq_action *a)
79930 }
79931 }
79932
79933-static void tasklet_hi_action(struct softirq_action *a)
79934+static void tasklet_hi_action(void)
79935 {
79936 struct tasklet_struct *list;
79937
79938@@ -730,7 +730,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
79939 return NOTIFY_OK;
79940 }
79941
79942-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
79943+static struct notifier_block remote_softirq_cpu_notifier = {
79944 .notifier_call = remote_softirq_cpu_notify,
79945 };
79946
79947@@ -847,11 +847,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
79948 return NOTIFY_OK;
79949 }
79950
79951-static struct notifier_block __cpuinitdata cpu_nfb = {
79952+static struct notifier_block cpu_nfb = {
79953 .notifier_call = cpu_callback
79954 };
79955
79956-static struct smp_hotplug_thread softirq_threads = {
79957+static struct smp_hotplug_thread softirq_threads __read_only = {
79958 .store = &ksoftirqd,
79959 .thread_should_run = ksoftirqd_should_run,
79960 .thread_fn = run_ksoftirqd,
79961diff --git a/kernel/srcu.c b/kernel/srcu.c
79962index 01d5ccb..cdcbee6 100644
79963--- a/kernel/srcu.c
79964+++ b/kernel/srcu.c
79965@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
79966
79967 idx = ACCESS_ONCE(sp->completed) & 0x1;
79968 preempt_disable();
79969- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79970+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79971 smp_mb(); /* B */ /* Avoid leaking the critical section. */
79972- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79973+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79974 preempt_enable();
79975 return idx;
79976 }
79977diff --git a/kernel/sys.c b/kernel/sys.c
79978index 2bbd9a7..0875671 100644
79979--- a/kernel/sys.c
79980+++ b/kernel/sys.c
79981@@ -163,6 +163,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
79982 error = -EACCES;
79983 goto out;
79984 }
79985+
79986+ if (gr_handle_chroot_setpriority(p, niceval)) {
79987+ error = -EACCES;
79988+ goto out;
79989+ }
79990+
79991 no_nice = security_task_setnice(p, niceval);
79992 if (no_nice) {
79993 error = no_nice;
79994@@ -626,6 +632,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
79995 goto error;
79996 }
79997
79998+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
79999+ goto error;
80000+
80001 if (rgid != (gid_t) -1 ||
80002 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
80003 new->sgid = new->egid;
80004@@ -661,6 +670,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
80005 old = current_cred();
80006
80007 retval = -EPERM;
80008+
80009+ if (gr_check_group_change(kgid, kgid, kgid))
80010+ goto error;
80011+
80012 if (nsown_capable(CAP_SETGID))
80013 new->gid = new->egid = new->sgid = new->fsgid = kgid;
80014 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
80015@@ -678,7 +691,7 @@ error:
80016 /*
80017 * change the user struct in a credentials set to match the new UID
80018 */
80019-static int set_user(struct cred *new)
80020+int set_user(struct cred *new)
80021 {
80022 struct user_struct *new_user;
80023
80024@@ -758,6 +771,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
80025 goto error;
80026 }
80027
80028+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
80029+ goto error;
80030+
80031 if (!uid_eq(new->uid, old->uid)) {
80032 retval = set_user(new);
80033 if (retval < 0)
80034@@ -808,6 +824,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
80035 old = current_cred();
80036
80037 retval = -EPERM;
80038+
80039+ if (gr_check_crash_uid(kuid))
80040+ goto error;
80041+ if (gr_check_user_change(kuid, kuid, kuid))
80042+ goto error;
80043+
80044 if (nsown_capable(CAP_SETUID)) {
80045 new->suid = new->uid = kuid;
80046 if (!uid_eq(kuid, old->uid)) {
80047@@ -877,6 +899,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
80048 goto error;
80049 }
80050
80051+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
80052+ goto error;
80053+
80054 if (ruid != (uid_t) -1) {
80055 new->uid = kruid;
80056 if (!uid_eq(kruid, old->uid)) {
80057@@ -959,6 +984,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
80058 goto error;
80059 }
80060
80061+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
80062+ goto error;
80063+
80064 if (rgid != (gid_t) -1)
80065 new->gid = krgid;
80066 if (egid != (gid_t) -1)
80067@@ -1020,12 +1048,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
80068 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
80069 nsown_capable(CAP_SETUID)) {
80070 if (!uid_eq(kuid, old->fsuid)) {
80071+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
80072+ goto error;
80073+
80074 new->fsuid = kuid;
80075 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
80076 goto change_okay;
80077 }
80078 }
80079
80080+error:
80081 abort_creds(new);
80082 return old_fsuid;
80083
80084@@ -1058,12 +1090,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
80085 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
80086 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
80087 nsown_capable(CAP_SETGID)) {
80088+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
80089+ goto error;
80090+
80091 if (!gid_eq(kgid, old->fsgid)) {
80092 new->fsgid = kgid;
80093 goto change_okay;
80094 }
80095 }
80096
80097+error:
80098 abort_creds(new);
80099 return old_fsgid;
80100
80101@@ -1432,19 +1468,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
80102 return -EFAULT;
80103
80104 down_read(&uts_sem);
80105- error = __copy_to_user(&name->sysname, &utsname()->sysname,
80106+ error = __copy_to_user(name->sysname, &utsname()->sysname,
80107 __OLD_UTS_LEN);
80108 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
80109- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
80110+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
80111 __OLD_UTS_LEN);
80112 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
80113- error |= __copy_to_user(&name->release, &utsname()->release,
80114+ error |= __copy_to_user(name->release, &utsname()->release,
80115 __OLD_UTS_LEN);
80116 error |= __put_user(0, name->release + __OLD_UTS_LEN);
80117- error |= __copy_to_user(&name->version, &utsname()->version,
80118+ error |= __copy_to_user(name->version, &utsname()->version,
80119 __OLD_UTS_LEN);
80120 error |= __put_user(0, name->version + __OLD_UTS_LEN);
80121- error |= __copy_to_user(&name->machine, &utsname()->machine,
80122+ error |= __copy_to_user(name->machine, &utsname()->machine,
80123 __OLD_UTS_LEN);
80124 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
80125 up_read(&uts_sem);
80126@@ -1646,6 +1682,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
80127 */
80128 new_rlim->rlim_cur = 1;
80129 }
80130+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
80131+ is changed to a lower value. Since tasks can be created by the same
80132+ user in between this limit change and an execve by this task, force
80133+ a recheck only for this task by setting PF_NPROC_EXCEEDED
80134+ */
80135+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
80136+ tsk->flags |= PF_NPROC_EXCEEDED;
80137 }
80138 if (!retval) {
80139 if (old_rlim)
80140diff --git a/kernel/sysctl.c b/kernel/sysctl.c
80141index 9edcf45..713c960 100644
80142--- a/kernel/sysctl.c
80143+++ b/kernel/sysctl.c
80144@@ -93,7 +93,6 @@
80145
80146
80147 #if defined(CONFIG_SYSCTL)
80148-
80149 /* External variables not in a header file. */
80150 extern int sysctl_overcommit_memory;
80151 extern int sysctl_overcommit_ratio;
80152@@ -119,18 +118,18 @@ extern int blk_iopoll_enabled;
80153
80154 /* Constants used for minimum and maximum */
80155 #ifdef CONFIG_LOCKUP_DETECTOR
80156-static int sixty = 60;
80157-static int neg_one = -1;
80158+static int sixty __read_only = 60;
80159 #endif
80160
80161-static int zero;
80162-static int __maybe_unused one = 1;
80163-static int __maybe_unused two = 2;
80164-static int __maybe_unused three = 3;
80165-static unsigned long one_ul = 1;
80166-static int one_hundred = 100;
80167+static int neg_one __read_only = -1;
80168+static int zero __read_only = 0;
80169+static int __maybe_unused one __read_only = 1;
80170+static int __maybe_unused two __read_only = 2;
80171+static int __maybe_unused three __read_only = 3;
80172+static unsigned long one_ul __read_only = 1;
80173+static int one_hundred __read_only = 100;
80174 #ifdef CONFIG_PRINTK
80175-static int ten_thousand = 10000;
80176+static int ten_thousand __read_only = 10000;
80177 #endif
80178
80179 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
80180@@ -177,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
80181 void __user *buffer, size_t *lenp, loff_t *ppos);
80182 #endif
80183
80184-#ifdef CONFIG_PRINTK
80185 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
80186 void __user *buffer, size_t *lenp, loff_t *ppos);
80187-#endif
80188
80189 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
80190 void __user *buffer, size_t *lenp, loff_t *ppos);
80191@@ -211,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
80192
80193 #endif
80194
80195+extern struct ctl_table grsecurity_table[];
80196+
80197 static struct ctl_table kern_table[];
80198 static struct ctl_table vm_table[];
80199 static struct ctl_table fs_table[];
80200@@ -225,6 +224,20 @@ extern struct ctl_table epoll_table[];
80201 int sysctl_legacy_va_layout;
80202 #endif
80203
80204+#ifdef CONFIG_PAX_SOFTMODE
80205+static ctl_table pax_table[] = {
80206+ {
80207+ .procname = "softmode",
80208+ .data = &pax_softmode,
80209+ .maxlen = sizeof(unsigned int),
80210+ .mode = 0600,
80211+ .proc_handler = &proc_dointvec,
80212+ },
80213+
80214+ { }
80215+};
80216+#endif
80217+
80218 /* The default sysctl tables: */
80219
80220 static struct ctl_table sysctl_base_table[] = {
80221@@ -273,6 +286,22 @@ static int max_extfrag_threshold = 1000;
80222 #endif
80223
80224 static struct ctl_table kern_table[] = {
80225+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
80226+ {
80227+ .procname = "grsecurity",
80228+ .mode = 0500,
80229+ .child = grsecurity_table,
80230+ },
80231+#endif
80232+
80233+#ifdef CONFIG_PAX_SOFTMODE
80234+ {
80235+ .procname = "pax",
80236+ .mode = 0500,
80237+ .child = pax_table,
80238+ },
80239+#endif
80240+
80241 {
80242 .procname = "sched_child_runs_first",
80243 .data = &sysctl_sched_child_runs_first,
80244@@ -607,7 +636,7 @@ static struct ctl_table kern_table[] = {
80245 .data = &modprobe_path,
80246 .maxlen = KMOD_PATH_LEN,
80247 .mode = 0644,
80248- .proc_handler = proc_dostring,
80249+ .proc_handler = proc_dostring_modpriv,
80250 },
80251 {
80252 .procname = "modules_disabled",
80253@@ -774,16 +803,20 @@ static struct ctl_table kern_table[] = {
80254 .extra1 = &zero,
80255 .extra2 = &one,
80256 },
80257+#endif
80258 {
80259 .procname = "kptr_restrict",
80260 .data = &kptr_restrict,
80261 .maxlen = sizeof(int),
80262 .mode = 0644,
80263 .proc_handler = proc_dointvec_minmax_sysadmin,
80264+#ifdef CONFIG_GRKERNSEC_HIDESYM
80265+ .extra1 = &two,
80266+#else
80267 .extra1 = &zero,
80268+#endif
80269 .extra2 = &two,
80270 },
80271-#endif
80272 {
80273 .procname = "ngroups_max",
80274 .data = &ngroups_max,
80275@@ -1025,10 +1058,17 @@ static struct ctl_table kern_table[] = {
80276 */
80277 {
80278 .procname = "perf_event_paranoid",
80279- .data = &sysctl_perf_event_paranoid,
80280- .maxlen = sizeof(sysctl_perf_event_paranoid),
80281+ .data = &sysctl_perf_event_legitimately_concerned,
80282+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
80283 .mode = 0644,
80284- .proc_handler = proc_dointvec,
80285+ /* go ahead, be a hero */
80286+ .proc_handler = proc_dointvec_minmax_sysadmin,
80287+ .extra1 = &neg_one,
80288+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80289+ .extra2 = &three,
80290+#else
80291+ .extra2 = &two,
80292+#endif
80293 },
80294 {
80295 .procname = "perf_event_mlock_kb",
80296@@ -1282,6 +1322,13 @@ static struct ctl_table vm_table[] = {
80297 .proc_handler = proc_dointvec_minmax,
80298 .extra1 = &zero,
80299 },
80300+ {
80301+ .procname = "heap_stack_gap",
80302+ .data = &sysctl_heap_stack_gap,
80303+ .maxlen = sizeof(sysctl_heap_stack_gap),
80304+ .mode = 0644,
80305+ .proc_handler = proc_doulongvec_minmax,
80306+ },
80307 #else
80308 {
80309 .procname = "nr_trim_pages",
80310@@ -1746,6 +1793,16 @@ int proc_dostring(struct ctl_table *table, int write,
80311 buffer, lenp, ppos);
80312 }
80313
80314+int proc_dostring_modpriv(struct ctl_table *table, int write,
80315+ void __user *buffer, size_t *lenp, loff_t *ppos)
80316+{
80317+ if (write && !capable(CAP_SYS_MODULE))
80318+ return -EPERM;
80319+
80320+ return _proc_do_string(table->data, table->maxlen, write,
80321+ buffer, lenp, ppos);
80322+}
80323+
80324 static size_t proc_skip_spaces(char **buf)
80325 {
80326 size_t ret;
80327@@ -1851,6 +1908,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
80328 len = strlen(tmp);
80329 if (len > *size)
80330 len = *size;
80331+ if (len > sizeof(tmp))
80332+ len = sizeof(tmp);
80333 if (copy_to_user(*buf, tmp, len))
80334 return -EFAULT;
80335 *size -= len;
80336@@ -2015,7 +2074,7 @@ int proc_dointvec(struct ctl_table *table, int write,
80337 static int proc_taint(struct ctl_table *table, int write,
80338 void __user *buffer, size_t *lenp, loff_t *ppos)
80339 {
80340- struct ctl_table t;
80341+ ctl_table_no_const t;
80342 unsigned long tmptaint = get_taint();
80343 int err;
80344
80345@@ -2043,7 +2102,6 @@ static int proc_taint(struct ctl_table *table, int write,
80346 return err;
80347 }
80348
80349-#ifdef CONFIG_PRINTK
80350 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
80351 void __user *buffer, size_t *lenp, loff_t *ppos)
80352 {
80353@@ -2052,7 +2110,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
80354
80355 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
80356 }
80357-#endif
80358
80359 struct do_proc_dointvec_minmax_conv_param {
80360 int *min;
80361@@ -2199,8 +2256,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
80362 *i = val;
80363 } else {
80364 val = convdiv * (*i) / convmul;
80365- if (!first)
80366+ if (!first) {
80367 err = proc_put_char(&buffer, &left, '\t');
80368+ if (err)
80369+ break;
80370+ }
80371 err = proc_put_long(&buffer, &left, val, false);
80372 if (err)
80373 break;
80374@@ -2592,6 +2652,12 @@ int proc_dostring(struct ctl_table *table, int write,
80375 return -ENOSYS;
80376 }
80377
80378+int proc_dostring_modpriv(struct ctl_table *table, int write,
80379+ void __user *buffer, size_t *lenp, loff_t *ppos)
80380+{
80381+ return -ENOSYS;
80382+}
80383+
80384 int proc_dointvec(struct ctl_table *table, int write,
80385 void __user *buffer, size_t *lenp, loff_t *ppos)
80386 {
80387@@ -2648,5 +2714,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
80388 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
80389 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
80390 EXPORT_SYMBOL(proc_dostring);
80391+EXPORT_SYMBOL(proc_dostring_modpriv);
80392 EXPORT_SYMBOL(proc_doulongvec_minmax);
80393 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
80394diff --git a/kernel/taskstats.c b/kernel/taskstats.c
80395index 145bb4d..b2aa969 100644
80396--- a/kernel/taskstats.c
80397+++ b/kernel/taskstats.c
80398@@ -28,9 +28,12 @@
80399 #include <linux/fs.h>
80400 #include <linux/file.h>
80401 #include <linux/pid_namespace.h>
80402+#include <linux/grsecurity.h>
80403 #include <net/genetlink.h>
80404 #include <linux/atomic.h>
80405
80406+extern int gr_is_taskstats_denied(int pid);
80407+
80408 /*
80409 * Maximum length of a cpumask that can be specified in
80410 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
80411@@ -570,6 +573,9 @@ err:
80412
80413 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
80414 {
80415+ if (gr_is_taskstats_denied(current->pid))
80416+ return -EACCES;
80417+
80418 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
80419 return cmd_attr_register_cpumask(info);
80420 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
80421diff --git a/kernel/time.c b/kernel/time.c
80422index d3617db..c98bbe9 100644
80423--- a/kernel/time.c
80424+++ b/kernel/time.c
80425@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
80426 return error;
80427
80428 if (tz) {
80429+ /* we log in do_settimeofday called below, so don't log twice
80430+ */
80431+ if (!tv)
80432+ gr_log_timechange();
80433+
80434 sys_tz = *tz;
80435 update_vsyscall_tz();
80436 if (firsttime) {
80437@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
80438 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
80439 * value to a scaled second value.
80440 */
80441-unsigned long
80442+unsigned long __intentional_overflow(-1)
80443 timespec_to_jiffies(const struct timespec *value)
80444 {
80445 unsigned long sec = value->tv_sec;
80446diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
80447index f11d83b..d016d91 100644
80448--- a/kernel/time/alarmtimer.c
80449+++ b/kernel/time/alarmtimer.c
80450@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
80451 struct platform_device *pdev;
80452 int error = 0;
80453 int i;
80454- struct k_clock alarm_clock = {
80455+ static struct k_clock alarm_clock = {
80456 .clock_getres = alarm_clock_getres,
80457 .clock_get = alarm_clock_get,
80458 .timer_create = alarm_timer_create,
80459diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
80460index baeeb5c..c22704a 100644
80461--- a/kernel/time/timekeeping.c
80462+++ b/kernel/time/timekeeping.c
80463@@ -15,6 +15,7 @@
80464 #include <linux/init.h>
80465 #include <linux/mm.h>
80466 #include <linux/sched.h>
80467+#include <linux/grsecurity.h>
80468 #include <linux/syscore_ops.h>
80469 #include <linux/clocksource.h>
80470 #include <linux/jiffies.h>
80471@@ -495,6 +496,8 @@ int do_settimeofday(const struct timespec *tv)
80472 if (!timespec_valid_strict(tv))
80473 return -EINVAL;
80474
80475+ gr_log_timechange();
80476+
80477 raw_spin_lock_irqsave(&timekeeper_lock, flags);
80478 write_seqcount_begin(&timekeeper_seq);
80479
80480diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
80481index 3bdf283..cc68d83 100644
80482--- a/kernel/time/timer_list.c
80483+++ b/kernel/time/timer_list.c
80484@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
80485
80486 static void print_name_offset(struct seq_file *m, void *sym)
80487 {
80488+#ifdef CONFIG_GRKERNSEC_HIDESYM
80489+ SEQ_printf(m, "<%p>", NULL);
80490+#else
80491 char symname[KSYM_NAME_LEN];
80492
80493 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
80494 SEQ_printf(m, "<%pK>", sym);
80495 else
80496 SEQ_printf(m, "%s", symname);
80497+#endif
80498 }
80499
80500 static void
80501@@ -119,7 +123,11 @@ next_one:
80502 static void
80503 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
80504 {
80505+#ifdef CONFIG_GRKERNSEC_HIDESYM
80506+ SEQ_printf(m, " .base: %p\n", NULL);
80507+#else
80508 SEQ_printf(m, " .base: %pK\n", base);
80509+#endif
80510 SEQ_printf(m, " .index: %d\n",
80511 base->index);
80512 SEQ_printf(m, " .resolution: %Lu nsecs\n",
80513@@ -355,7 +363,11 @@ static int __init init_timer_list_procfs(void)
80514 {
80515 struct proc_dir_entry *pe;
80516
80517+#ifdef CONFIG_GRKERNSEC_PROC_ADD
80518+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
80519+#else
80520 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
80521+#endif
80522 if (!pe)
80523 return -ENOMEM;
80524 return 0;
80525diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
80526index 0b537f2..40d6c20 100644
80527--- a/kernel/time/timer_stats.c
80528+++ b/kernel/time/timer_stats.c
80529@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
80530 static unsigned long nr_entries;
80531 static struct entry entries[MAX_ENTRIES];
80532
80533-static atomic_t overflow_count;
80534+static atomic_unchecked_t overflow_count;
80535
80536 /*
80537 * The entries are in a hash-table, for fast lookup:
80538@@ -140,7 +140,7 @@ static void reset_entries(void)
80539 nr_entries = 0;
80540 memset(entries, 0, sizeof(entries));
80541 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
80542- atomic_set(&overflow_count, 0);
80543+ atomic_set_unchecked(&overflow_count, 0);
80544 }
80545
80546 static struct entry *alloc_entry(void)
80547@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
80548 if (likely(entry))
80549 entry->count++;
80550 else
80551- atomic_inc(&overflow_count);
80552+ atomic_inc_unchecked(&overflow_count);
80553
80554 out_unlock:
80555 raw_spin_unlock_irqrestore(lock, flags);
80556@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
80557
80558 static void print_name_offset(struct seq_file *m, unsigned long addr)
80559 {
80560+#ifdef CONFIG_GRKERNSEC_HIDESYM
80561+ seq_printf(m, "<%p>", NULL);
80562+#else
80563 char symname[KSYM_NAME_LEN];
80564
80565 if (lookup_symbol_name(addr, symname) < 0)
80566- seq_printf(m, "<%p>", (void *)addr);
80567+ seq_printf(m, "<%pK>", (void *)addr);
80568 else
80569 seq_printf(m, "%s", symname);
80570+#endif
80571 }
80572
80573 static int tstats_show(struct seq_file *m, void *v)
80574@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
80575
80576 seq_puts(m, "Timer Stats Version: v0.2\n");
80577 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
80578- if (atomic_read(&overflow_count))
80579+ if (atomic_read_unchecked(&overflow_count))
80580 seq_printf(m, "Overflow: %d entries\n",
80581- atomic_read(&overflow_count));
80582+ atomic_read_unchecked(&overflow_count));
80583
80584 for (i = 0; i < nr_entries; i++) {
80585 entry = entries + i;
80586@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
80587 {
80588 struct proc_dir_entry *pe;
80589
80590+#ifdef CONFIG_GRKERNSEC_PROC_ADD
80591+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
80592+#else
80593 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
80594+#endif
80595 if (!pe)
80596 return -ENOMEM;
80597 return 0;
80598diff --git a/kernel/timer.c b/kernel/timer.c
80599index 15bc1b4..32da49c 100644
80600--- a/kernel/timer.c
80601+++ b/kernel/timer.c
80602@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
80603 /*
80604 * This function runs timers and the timer-tq in bottom half context.
80605 */
80606-static void run_timer_softirq(struct softirq_action *h)
80607+static void run_timer_softirq(void)
80608 {
80609 struct tvec_base *base = __this_cpu_read(tvec_bases);
80610
80611@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
80612 *
80613 * In all cases the return value is guaranteed to be non-negative.
80614 */
80615-signed long __sched schedule_timeout(signed long timeout)
80616+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
80617 {
80618 struct timer_list timer;
80619 unsigned long expire;
80620@@ -1635,7 +1635,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
80621 return NOTIFY_OK;
80622 }
80623
80624-static struct notifier_block __cpuinitdata timers_nb = {
80625+static struct notifier_block timers_nb = {
80626 .notifier_call = timer_cpu_notify,
80627 };
80628
80629diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
80630index b8b8560..75b1a09 100644
80631--- a/kernel/trace/blktrace.c
80632+++ b/kernel/trace/blktrace.c
80633@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
80634 struct blk_trace *bt = filp->private_data;
80635 char buf[16];
80636
80637- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
80638+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
80639
80640 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
80641 }
80642@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
80643 return 1;
80644
80645 bt = buf->chan->private_data;
80646- atomic_inc(&bt->dropped);
80647+ atomic_inc_unchecked(&bt->dropped);
80648 return 0;
80649 }
80650
80651@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
80652
80653 bt->dir = dir;
80654 bt->dev = dev;
80655- atomic_set(&bt->dropped, 0);
80656+ atomic_set_unchecked(&bt->dropped, 0);
80657
80658 ret = -EIO;
80659 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
80660diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
80661index 6c508ff..ee55a13 100644
80662--- a/kernel/trace/ftrace.c
80663+++ b/kernel/trace/ftrace.c
80664@@ -1915,12 +1915,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
80665 if (unlikely(ftrace_disabled))
80666 return 0;
80667
80668+ ret = ftrace_arch_code_modify_prepare();
80669+ FTRACE_WARN_ON(ret);
80670+ if (ret)
80671+ return 0;
80672+
80673 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
80674+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
80675 if (ret) {
80676 ftrace_bug(ret, ip);
80677- return 0;
80678 }
80679- return 1;
80680+ return ret ? 0 : 1;
80681 }
80682
80683 /*
80684@@ -3931,8 +3936,10 @@ static int ftrace_process_locs(struct module *mod,
80685 if (!count)
80686 return 0;
80687
80688+ pax_open_kernel();
80689 sort(start, count, sizeof(*start),
80690 ftrace_cmp_ips, ftrace_swap_ips);
80691+ pax_close_kernel();
80692
80693 start_pg = ftrace_allocate_pages(count);
80694 if (!start_pg)
80695@@ -4655,8 +4662,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
80696 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
80697
80698 static int ftrace_graph_active;
80699-static struct notifier_block ftrace_suspend_notifier;
80700-
80701 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
80702 {
80703 return 0;
80704@@ -4800,6 +4805,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
80705 return NOTIFY_DONE;
80706 }
80707
80708+static struct notifier_block ftrace_suspend_notifier = {
80709+ .notifier_call = ftrace_suspend_notifier_call
80710+};
80711+
80712 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
80713 trace_func_graph_ent_t entryfunc)
80714 {
80715@@ -4813,7 +4822,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
80716 goto out;
80717 }
80718
80719- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
80720 register_pm_notifier(&ftrace_suspend_notifier);
80721
80722 ftrace_graph_active++;
80723diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
80724index e444ff8..438b8f4 100644
80725--- a/kernel/trace/ring_buffer.c
80726+++ b/kernel/trace/ring_buffer.c
80727@@ -352,9 +352,9 @@ struct buffer_data_page {
80728 */
80729 struct buffer_page {
80730 struct list_head list; /* list of buffer pages */
80731- local_t write; /* index for next write */
80732+ local_unchecked_t write; /* index for next write */
80733 unsigned read; /* index for next read */
80734- local_t entries; /* entries on this page */
80735+ local_unchecked_t entries; /* entries on this page */
80736 unsigned long real_end; /* real end of data */
80737 struct buffer_data_page *page; /* Actual data page */
80738 };
80739@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
80740 unsigned long last_overrun;
80741 local_t entries_bytes;
80742 local_t entries;
80743- local_t overrun;
80744- local_t commit_overrun;
80745+ local_unchecked_t overrun;
80746+ local_unchecked_t commit_overrun;
80747 local_t dropped_events;
80748 local_t committing;
80749 local_t commits;
80750@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
80751 *
80752 * We add a counter to the write field to denote this.
80753 */
80754- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
80755- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
80756+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
80757+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
80758
80759 /*
80760 * Just make sure we have seen our old_write and synchronize
80761@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
80762 * cmpxchg to only update if an interrupt did not already
80763 * do it for us. If the cmpxchg fails, we don't care.
80764 */
80765- (void)local_cmpxchg(&next_page->write, old_write, val);
80766- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
80767+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
80768+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
80769
80770 /*
80771 * No need to worry about races with clearing out the commit.
80772@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
80773
80774 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
80775 {
80776- return local_read(&bpage->entries) & RB_WRITE_MASK;
80777+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
80778 }
80779
80780 static inline unsigned long rb_page_write(struct buffer_page *bpage)
80781 {
80782- return local_read(&bpage->write) & RB_WRITE_MASK;
80783+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
80784 }
80785
80786 static int
80787@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
80788 * bytes consumed in ring buffer from here.
80789 * Increment overrun to account for the lost events.
80790 */
80791- local_add(page_entries, &cpu_buffer->overrun);
80792+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
80793 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80794 }
80795
80796@@ -2063,7 +2063,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
80797 * it is our responsibility to update
80798 * the counters.
80799 */
80800- local_add(entries, &cpu_buffer->overrun);
80801+ local_add_unchecked(entries, &cpu_buffer->overrun);
80802 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80803
80804 /*
80805@@ -2213,7 +2213,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80806 if (tail == BUF_PAGE_SIZE)
80807 tail_page->real_end = 0;
80808
80809- local_sub(length, &tail_page->write);
80810+ local_sub_unchecked(length, &tail_page->write);
80811 return;
80812 }
80813
80814@@ -2248,7 +2248,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80815 rb_event_set_padding(event);
80816
80817 /* Set the write back to the previous setting */
80818- local_sub(length, &tail_page->write);
80819+ local_sub_unchecked(length, &tail_page->write);
80820 return;
80821 }
80822
80823@@ -2260,7 +2260,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80824
80825 /* Set write to end of buffer */
80826 length = (tail + length) - BUF_PAGE_SIZE;
80827- local_sub(length, &tail_page->write);
80828+ local_sub_unchecked(length, &tail_page->write);
80829 }
80830
80831 /*
80832@@ -2286,7 +2286,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80833 * about it.
80834 */
80835 if (unlikely(next_page == commit_page)) {
80836- local_inc(&cpu_buffer->commit_overrun);
80837+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80838 goto out_reset;
80839 }
80840
80841@@ -2342,7 +2342,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80842 cpu_buffer->tail_page) &&
80843 (cpu_buffer->commit_page ==
80844 cpu_buffer->reader_page))) {
80845- local_inc(&cpu_buffer->commit_overrun);
80846+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80847 goto out_reset;
80848 }
80849 }
80850@@ -2390,7 +2390,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80851 length += RB_LEN_TIME_EXTEND;
80852
80853 tail_page = cpu_buffer->tail_page;
80854- write = local_add_return(length, &tail_page->write);
80855+ write = local_add_return_unchecked(length, &tail_page->write);
80856
80857 /* set write to only the index of the write */
80858 write &= RB_WRITE_MASK;
80859@@ -2407,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80860 kmemcheck_annotate_bitfield(event, bitfield);
80861 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
80862
80863- local_inc(&tail_page->entries);
80864+ local_inc_unchecked(&tail_page->entries);
80865
80866 /*
80867 * If this is the first commit on the page, then update
80868@@ -2440,7 +2440,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80869
80870 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
80871 unsigned long write_mask =
80872- local_read(&bpage->write) & ~RB_WRITE_MASK;
80873+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
80874 unsigned long event_length = rb_event_length(event);
80875 /*
80876 * This is on the tail page. It is possible that
80877@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80878 */
80879 old_index += write_mask;
80880 new_index += write_mask;
80881- index = local_cmpxchg(&bpage->write, old_index, new_index);
80882+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
80883 if (index == old_index) {
80884 /* update counters */
80885 local_sub(event_length, &cpu_buffer->entries_bytes);
80886@@ -2842,7 +2842,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80887
80888 /* Do the likely case first */
80889 if (likely(bpage->page == (void *)addr)) {
80890- local_dec(&bpage->entries);
80891+ local_dec_unchecked(&bpage->entries);
80892 return;
80893 }
80894
80895@@ -2854,7 +2854,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80896 start = bpage;
80897 do {
80898 if (bpage->page == (void *)addr) {
80899- local_dec(&bpage->entries);
80900+ local_dec_unchecked(&bpage->entries);
80901 return;
80902 }
80903 rb_inc_page(cpu_buffer, &bpage);
80904@@ -3138,7 +3138,7 @@ static inline unsigned long
80905 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
80906 {
80907 return local_read(&cpu_buffer->entries) -
80908- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
80909+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
80910 }
80911
80912 /**
80913@@ -3227,7 +3227,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
80914 return 0;
80915
80916 cpu_buffer = buffer->buffers[cpu];
80917- ret = local_read(&cpu_buffer->overrun);
80918+ ret = local_read_unchecked(&cpu_buffer->overrun);
80919
80920 return ret;
80921 }
80922@@ -3250,7 +3250,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
80923 return 0;
80924
80925 cpu_buffer = buffer->buffers[cpu];
80926- ret = local_read(&cpu_buffer->commit_overrun);
80927+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
80928
80929 return ret;
80930 }
80931@@ -3335,7 +3335,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
80932 /* if you care about this being correct, lock the buffer */
80933 for_each_buffer_cpu(buffer, cpu) {
80934 cpu_buffer = buffer->buffers[cpu];
80935- overruns += local_read(&cpu_buffer->overrun);
80936+ overruns += local_read_unchecked(&cpu_buffer->overrun);
80937 }
80938
80939 return overruns;
80940@@ -3511,8 +3511,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80941 /*
80942 * Reset the reader page to size zero.
80943 */
80944- local_set(&cpu_buffer->reader_page->write, 0);
80945- local_set(&cpu_buffer->reader_page->entries, 0);
80946+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80947+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80948 local_set(&cpu_buffer->reader_page->page->commit, 0);
80949 cpu_buffer->reader_page->real_end = 0;
80950
80951@@ -3546,7 +3546,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80952 * want to compare with the last_overrun.
80953 */
80954 smp_mb();
80955- overwrite = local_read(&(cpu_buffer->overrun));
80956+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
80957
80958 /*
80959 * Here's the tricky part.
80960@@ -4116,8 +4116,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80961
80962 cpu_buffer->head_page
80963 = list_entry(cpu_buffer->pages, struct buffer_page, list);
80964- local_set(&cpu_buffer->head_page->write, 0);
80965- local_set(&cpu_buffer->head_page->entries, 0);
80966+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
80967+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
80968 local_set(&cpu_buffer->head_page->page->commit, 0);
80969
80970 cpu_buffer->head_page->read = 0;
80971@@ -4127,14 +4127,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80972
80973 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
80974 INIT_LIST_HEAD(&cpu_buffer->new_pages);
80975- local_set(&cpu_buffer->reader_page->write, 0);
80976- local_set(&cpu_buffer->reader_page->entries, 0);
80977+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80978+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80979 local_set(&cpu_buffer->reader_page->page->commit, 0);
80980 cpu_buffer->reader_page->read = 0;
80981
80982 local_set(&cpu_buffer->entries_bytes, 0);
80983- local_set(&cpu_buffer->overrun, 0);
80984- local_set(&cpu_buffer->commit_overrun, 0);
80985+ local_set_unchecked(&cpu_buffer->overrun, 0);
80986+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
80987 local_set(&cpu_buffer->dropped_events, 0);
80988 local_set(&cpu_buffer->entries, 0);
80989 local_set(&cpu_buffer->committing, 0);
80990@@ -4538,8 +4538,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
80991 rb_init_page(bpage);
80992 bpage = reader->page;
80993 reader->page = *data_page;
80994- local_set(&reader->write, 0);
80995- local_set(&reader->entries, 0);
80996+ local_set_unchecked(&reader->write, 0);
80997+ local_set_unchecked(&reader->entries, 0);
80998 reader->read = 0;
80999 *data_page = bpage;
81000
81001diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
81002index f7bc3ce..b8ef9b5 100644
81003--- a/kernel/trace/trace.c
81004+++ b/kernel/trace/trace.c
81005@@ -3303,7 +3303,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
81006 return 0;
81007 }
81008
81009-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
81010+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
81011 {
81012 /* do nothing if flag is already set */
81013 if (!!(trace_flags & mask) == !!enabled)
81014diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
81015index 51b4448..7be601f 100644
81016--- a/kernel/trace/trace.h
81017+++ b/kernel/trace/trace.h
81018@@ -1035,7 +1035,7 @@ extern const char *__stop___trace_bprintk_fmt[];
81019 void trace_printk_init_buffers(void);
81020 void trace_printk_start_comm(void);
81021 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
81022-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
81023+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
81024
81025 /*
81026 * Normal trace_printk() and friends allocates special buffers
81027diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
81028index 6953263..2004e16 100644
81029--- a/kernel/trace/trace_events.c
81030+++ b/kernel/trace/trace_events.c
81031@@ -1748,10 +1748,6 @@ static LIST_HEAD(ftrace_module_file_list);
81032 struct ftrace_module_file_ops {
81033 struct list_head list;
81034 struct module *mod;
81035- struct file_operations id;
81036- struct file_operations enable;
81037- struct file_operations format;
81038- struct file_operations filter;
81039 };
81040
81041 static struct ftrace_module_file_ops *
81042@@ -1792,17 +1788,12 @@ trace_create_file_ops(struct module *mod)
81043
81044 file_ops->mod = mod;
81045
81046- file_ops->id = ftrace_event_id_fops;
81047- file_ops->id.owner = mod;
81048-
81049- file_ops->enable = ftrace_enable_fops;
81050- file_ops->enable.owner = mod;
81051-
81052- file_ops->filter = ftrace_event_filter_fops;
81053- file_ops->filter.owner = mod;
81054-
81055- file_ops->format = ftrace_event_format_fops;
81056- file_ops->format.owner = mod;
81057+ pax_open_kernel();
81058+ mod->trace_id.owner = mod;
81059+ mod->trace_enable.owner = mod;
81060+ mod->trace_filter.owner = mod;
81061+ mod->trace_format.owner = mod;
81062+ pax_close_kernel();
81063
81064 list_add(&file_ops->list, &ftrace_module_file_list);
81065
81066@@ -1895,8 +1886,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
81067 struct ftrace_module_file_ops *file_ops)
81068 {
81069 return __trace_add_new_event(call, tr,
81070- &file_ops->id, &file_ops->enable,
81071- &file_ops->filter, &file_ops->format);
81072+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
81073+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
81074 }
81075
81076 #else
81077diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
81078index a5e8f48..a9690d2 100644
81079--- a/kernel/trace/trace_mmiotrace.c
81080+++ b/kernel/trace/trace_mmiotrace.c
81081@@ -24,7 +24,7 @@ struct header_iter {
81082 static struct trace_array *mmio_trace_array;
81083 static bool overrun_detected;
81084 static unsigned long prev_overruns;
81085-static atomic_t dropped_count;
81086+static atomic_unchecked_t dropped_count;
81087
81088 static void mmio_reset_data(struct trace_array *tr)
81089 {
81090@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
81091
81092 static unsigned long count_overruns(struct trace_iterator *iter)
81093 {
81094- unsigned long cnt = atomic_xchg(&dropped_count, 0);
81095+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
81096 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
81097
81098 if (over > prev_overruns)
81099@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
81100 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
81101 sizeof(*entry), 0, pc);
81102 if (!event) {
81103- atomic_inc(&dropped_count);
81104+ atomic_inc_unchecked(&dropped_count);
81105 return;
81106 }
81107 entry = ring_buffer_event_data(event);
81108@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
81109 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
81110 sizeof(*entry), 0, pc);
81111 if (!event) {
81112- atomic_inc(&dropped_count);
81113+ atomic_inc_unchecked(&dropped_count);
81114 return;
81115 }
81116 entry = ring_buffer_event_data(event);
81117diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
81118index bb922d9..2a54a257 100644
81119--- a/kernel/trace/trace_output.c
81120+++ b/kernel/trace/trace_output.c
81121@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
81122
81123 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
81124 if (!IS_ERR(p)) {
81125- p = mangle_path(s->buffer + s->len, p, "\n");
81126+ p = mangle_path(s->buffer + s->len, p, "\n\\");
81127 if (p) {
81128 s->len = p - s->buffer;
81129 return 1;
81130@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
81131 goto out;
81132 }
81133
81134+ pax_open_kernel();
81135 if (event->funcs->trace == NULL)
81136- event->funcs->trace = trace_nop_print;
81137+ *(void **)&event->funcs->trace = trace_nop_print;
81138 if (event->funcs->raw == NULL)
81139- event->funcs->raw = trace_nop_print;
81140+ *(void **)&event->funcs->raw = trace_nop_print;
81141 if (event->funcs->hex == NULL)
81142- event->funcs->hex = trace_nop_print;
81143+ *(void **)&event->funcs->hex = trace_nop_print;
81144 if (event->funcs->binary == NULL)
81145- event->funcs->binary = trace_nop_print;
81146+ *(void **)&event->funcs->binary = trace_nop_print;
81147+ pax_close_kernel();
81148
81149 key = event->type & (EVENT_HASHSIZE - 1);
81150
81151diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
81152index b20428c..4845a10 100644
81153--- a/kernel/trace/trace_stack.c
81154+++ b/kernel/trace/trace_stack.c
81155@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
81156 return;
81157
81158 /* we do not handle interrupt stacks yet */
81159- if (!object_is_on_stack(stack))
81160+ if (!object_starts_on_stack(stack))
81161 return;
81162
81163 local_irq_save(flags);
81164diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
81165index d8c30db..f2f6af5 100644
81166--- a/kernel/user_namespace.c
81167+++ b/kernel/user_namespace.c
81168@@ -79,6 +79,21 @@ int create_user_ns(struct cred *new)
81169 !kgid_has_mapping(parent_ns, group))
81170 return -EPERM;
81171
81172+#ifdef CONFIG_GRKERNSEC
81173+ /*
81174+ * This doesn't really inspire confidence:
81175+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
81176+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
81177+ * Increases kernel attack surface in areas developers
81178+ * previously cared little about ("low importance due
81179+ * to requiring "root" capability")
81180+ * To be removed when this code receives *proper* review
81181+ */
81182+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
81183+ !capable(CAP_SETGID))
81184+ return -EPERM;
81185+#endif
81186+
81187 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
81188 if (!ns)
81189 return -ENOMEM;
81190@@ -105,6 +120,7 @@ int create_user_ns(struct cred *new)
81191 int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
81192 {
81193 struct cred *cred;
81194+ int err;
81195
81196 if (!(unshare_flags & CLONE_NEWUSER))
81197 return 0;
81198@@ -113,8 +129,12 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
81199 if (!cred)
81200 return -ENOMEM;
81201
81202- *new_cred = cred;
81203- return create_user_ns(cred);
81204+ err = create_user_ns(cred);
81205+ if (err)
81206+ put_cred(cred);
81207+ else
81208+ *new_cred = cred;
81209+ return err;
81210 }
81211
81212 void free_user_ns(struct user_namespace *ns)
81213@@ -853,7 +873,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
81214 if (atomic_read(&current->mm->mm_users) > 1)
81215 return -EINVAL;
81216
81217- if (current->fs->users != 1)
81218+ if (atomic_read(&current->fs->users) != 1)
81219 return -EINVAL;
81220
81221 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
81222diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
81223index 4f69f9a..7c6f8f8 100644
81224--- a/kernel/utsname_sysctl.c
81225+++ b/kernel/utsname_sysctl.c
81226@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
81227 static int proc_do_uts_string(ctl_table *table, int write,
81228 void __user *buffer, size_t *lenp, loff_t *ppos)
81229 {
81230- struct ctl_table uts_table;
81231+ ctl_table_no_const uts_table;
81232 int r;
81233 memcpy(&uts_table, table, sizeof(uts_table));
81234 uts_table.data = get_uts(table, write);
81235diff --git a/kernel/watchdog.c b/kernel/watchdog.c
81236index 05039e3..17490c7 100644
81237--- a/kernel/watchdog.c
81238+++ b/kernel/watchdog.c
81239@@ -531,7 +531,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
81240 }
81241 #endif /* CONFIG_SYSCTL */
81242
81243-static struct smp_hotplug_thread watchdog_threads = {
81244+static struct smp_hotplug_thread watchdog_threads __read_only = {
81245 .store = &softlockup_watchdog,
81246 .thread_should_run = watchdog_should_run,
81247 .thread_fn = watchdog,
81248diff --git a/kernel/workqueue.c b/kernel/workqueue.c
81249index ee8e29a..410568e 100644
81250--- a/kernel/workqueue.c
81251+++ b/kernel/workqueue.c
81252@@ -4584,7 +4584,7 @@ static void rebind_workers(struct worker_pool *pool)
81253 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
81254 worker_flags |= WORKER_REBOUND;
81255 worker_flags &= ~WORKER_UNBOUND;
81256- ACCESS_ONCE(worker->flags) = worker_flags;
81257+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
81258 }
81259
81260 spin_unlock_irq(&pool->lock);
81261diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
81262index 74fdc5c..3310593 100644
81263--- a/lib/Kconfig.debug
81264+++ b/lib/Kconfig.debug
81265@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
81266
81267 config DEBUG_LOCK_ALLOC
81268 bool "Lock debugging: detect incorrect freeing of live locks"
81269- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
81270+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
81271 select DEBUG_SPINLOCK
81272 select DEBUG_MUTEXES
81273 select LOCKDEP
81274@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
81275
81276 config PROVE_LOCKING
81277 bool "Lock debugging: prove locking correctness"
81278- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
81279+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
81280 select LOCKDEP
81281 select DEBUG_SPINLOCK
81282 select DEBUG_MUTEXES
81283@@ -614,7 +614,7 @@ config LOCKDEP
81284
81285 config LOCK_STAT
81286 bool "Lock usage statistics"
81287- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
81288+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
81289 select LOCKDEP
81290 select DEBUG_SPINLOCK
81291 select DEBUG_MUTEXES
81292@@ -1282,6 +1282,7 @@ config LATENCYTOP
81293 depends on DEBUG_KERNEL
81294 depends on STACKTRACE_SUPPORT
81295 depends on PROC_FS
81296+ depends on !GRKERNSEC_HIDESYM
81297 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
81298 select KALLSYMS
81299 select KALLSYMS_ALL
81300@@ -1298,7 +1299,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
81301 config DEBUG_STRICT_USER_COPY_CHECKS
81302 bool "Strict user copy size checks"
81303 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
81304- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
81305+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
81306 help
81307 Enabling this option turns a certain set of sanity checks for user
81308 copy operations into compile time failures.
81309@@ -1328,7 +1329,7 @@ config INTERVAL_TREE_TEST
81310
81311 config PROVIDE_OHCI1394_DMA_INIT
81312 bool "Remote debugging over FireWire early on boot"
81313- depends on PCI && X86
81314+ depends on PCI && X86 && !GRKERNSEC
81315 help
81316 If you want to debug problems which hang or crash the kernel early
81317 on boot and the crashing machine has a FireWire port, you can use
81318@@ -1357,7 +1358,7 @@ config PROVIDE_OHCI1394_DMA_INIT
81319
81320 config FIREWIRE_OHCI_REMOTE_DMA
81321 bool "Remote debugging over FireWire with firewire-ohci"
81322- depends on FIREWIRE_OHCI
81323+ depends on FIREWIRE_OHCI && !GRKERNSEC
81324 help
81325 This option lets you use the FireWire bus for remote debugging
81326 with help of the firewire-ohci driver. It enables unfiltered
81327diff --git a/lib/Makefile b/lib/Makefile
81328index c55a037..fb46e3b 100644
81329--- a/lib/Makefile
81330+++ b/lib/Makefile
81331@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
81332
81333 obj-$(CONFIG_BTREE) += btree.o
81334 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
81335-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
81336+obj-y += list_debug.o
81337 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
81338
81339 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
81340diff --git a/lib/bitmap.c b/lib/bitmap.c
81341index 06f7e4f..f3cf2b0 100644
81342--- a/lib/bitmap.c
81343+++ b/lib/bitmap.c
81344@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
81345 {
81346 int c, old_c, totaldigits, ndigits, nchunks, nbits;
81347 u32 chunk;
81348- const char __user __force *ubuf = (const char __user __force *)buf;
81349+ const char __user *ubuf = (const char __force_user *)buf;
81350
81351 bitmap_zero(maskp, nmaskbits);
81352
81353@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
81354 {
81355 if (!access_ok(VERIFY_READ, ubuf, ulen))
81356 return -EFAULT;
81357- return __bitmap_parse((const char __force *)ubuf,
81358+ return __bitmap_parse((const char __force_kernel *)ubuf,
81359 ulen, 1, maskp, nmaskbits);
81360
81361 }
81362@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
81363 {
81364 unsigned a, b;
81365 int c, old_c, totaldigits;
81366- const char __user __force *ubuf = (const char __user __force *)buf;
81367+ const char __user *ubuf = (const char __force_user *)buf;
81368 int exp_digit, in_range;
81369
81370 totaldigits = c = 0;
81371@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
81372 {
81373 if (!access_ok(VERIFY_READ, ubuf, ulen))
81374 return -EFAULT;
81375- return __bitmap_parselist((const char __force *)ubuf,
81376+ return __bitmap_parselist((const char __force_kernel *)ubuf,
81377 ulen, 1, maskp, nmaskbits);
81378 }
81379 EXPORT_SYMBOL(bitmap_parselist_user);
81380diff --git a/lib/bug.c b/lib/bug.c
81381index 1686034..a9c00c8 100644
81382--- a/lib/bug.c
81383+++ b/lib/bug.c
81384@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
81385 return BUG_TRAP_TYPE_NONE;
81386
81387 bug = find_bug(bugaddr);
81388+ if (!bug)
81389+ return BUG_TRAP_TYPE_NONE;
81390
81391 file = NULL;
81392 line = 0;
81393diff --git a/lib/debugobjects.c b/lib/debugobjects.c
81394index 37061ed..da83f48 100644
81395--- a/lib/debugobjects.c
81396+++ b/lib/debugobjects.c
81397@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
81398 if (limit > 4)
81399 return;
81400
81401- is_on_stack = object_is_on_stack(addr);
81402+ is_on_stack = object_starts_on_stack(addr);
81403 if (is_on_stack == onstack)
81404 return;
81405
81406diff --git a/lib/devres.c b/lib/devres.c
81407index 8235331..5881053 100644
81408--- a/lib/devres.c
81409+++ b/lib/devres.c
81410@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
81411 void devm_iounmap(struct device *dev, void __iomem *addr)
81412 {
81413 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
81414- (void *)addr));
81415+ (void __force *)addr));
81416 iounmap(addr);
81417 }
81418 EXPORT_SYMBOL(devm_iounmap);
81419@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
81420 {
81421 ioport_unmap(addr);
81422 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
81423- devm_ioport_map_match, (void *)addr));
81424+ devm_ioport_map_match, (void __force *)addr));
81425 }
81426 EXPORT_SYMBOL(devm_ioport_unmap);
81427 #endif /* CONFIG_HAS_IOPORT */
81428diff --git a/lib/div64.c b/lib/div64.c
81429index a163b6c..9618fa5 100644
81430--- a/lib/div64.c
81431+++ b/lib/div64.c
81432@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
81433 EXPORT_SYMBOL(__div64_32);
81434
81435 #ifndef div_s64_rem
81436-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
81437+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
81438 {
81439 u64 quotient;
81440
81441@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
81442 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
81443 */
81444 #ifndef div64_u64
81445-u64 div64_u64(u64 dividend, u64 divisor)
81446+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
81447 {
81448 u32 high = divisor >> 32;
81449 u64 quot;
81450diff --git a/lib/dma-debug.c b/lib/dma-debug.c
81451index d87a17a..ac0d79a 100644
81452--- a/lib/dma-debug.c
81453+++ b/lib/dma-debug.c
81454@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
81455
81456 void dma_debug_add_bus(struct bus_type *bus)
81457 {
81458- struct notifier_block *nb;
81459+ notifier_block_no_const *nb;
81460
81461 if (global_disable)
81462 return;
81463@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
81464
81465 static void check_for_stack(struct device *dev, void *addr)
81466 {
81467- if (object_is_on_stack(addr))
81468+ if (object_starts_on_stack(addr))
81469 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
81470 "stack [addr=%p]\n", addr);
81471 }
81472diff --git a/lib/inflate.c b/lib/inflate.c
81473index 013a761..c28f3fc 100644
81474--- a/lib/inflate.c
81475+++ b/lib/inflate.c
81476@@ -269,7 +269,7 @@ static void free(void *where)
81477 malloc_ptr = free_mem_ptr;
81478 }
81479 #else
81480-#define malloc(a) kmalloc(a, GFP_KERNEL)
81481+#define malloc(a) kmalloc((a), GFP_KERNEL)
81482 #define free(a) kfree(a)
81483 #endif
81484
81485diff --git a/lib/ioremap.c b/lib/ioremap.c
81486index 0c9216c..863bd89 100644
81487--- a/lib/ioremap.c
81488+++ b/lib/ioremap.c
81489@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
81490 unsigned long next;
81491
81492 phys_addr -= addr;
81493- pmd = pmd_alloc(&init_mm, pud, addr);
81494+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
81495 if (!pmd)
81496 return -ENOMEM;
81497 do {
81498@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
81499 unsigned long next;
81500
81501 phys_addr -= addr;
81502- pud = pud_alloc(&init_mm, pgd, addr);
81503+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
81504 if (!pud)
81505 return -ENOMEM;
81506 do {
81507diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
81508index bd2bea9..6b3c95e 100644
81509--- a/lib/is_single_threaded.c
81510+++ b/lib/is_single_threaded.c
81511@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
81512 struct task_struct *p, *t;
81513 bool ret;
81514
81515+ if (!mm)
81516+ return true;
81517+
81518 if (atomic_read(&task->signal->live) != 1)
81519 return false;
81520
81521diff --git a/lib/kobject.c b/lib/kobject.c
81522index b7e29a6..2f3ca75 100644
81523--- a/lib/kobject.c
81524+++ b/lib/kobject.c
81525@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
81526 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
81527 if (!kset)
81528 return NULL;
81529- retval = kobject_set_name(&kset->kobj, name);
81530+ retval = kobject_set_name(&kset->kobj, "%s", name);
81531 if (retval) {
81532 kfree(kset);
81533 return NULL;
81534@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
81535
81536
81537 static DEFINE_SPINLOCK(kobj_ns_type_lock);
81538-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
81539+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
81540
81541-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
81542+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
81543 {
81544 enum kobj_ns_type type = ops->type;
81545 int error;
81546diff --git a/lib/list_debug.c b/lib/list_debug.c
81547index c24c2f7..06e070b 100644
81548--- a/lib/list_debug.c
81549+++ b/lib/list_debug.c
81550@@ -11,7 +11,9 @@
81551 #include <linux/bug.h>
81552 #include <linux/kernel.h>
81553 #include <linux/rculist.h>
81554+#include <linux/mm.h>
81555
81556+#ifdef CONFIG_DEBUG_LIST
81557 /*
81558 * Insert a new entry between two known consecutive entries.
81559 *
81560@@ -19,21 +21,32 @@
81561 * the prev/next entries already!
81562 */
81563
81564-void __list_add(struct list_head *new,
81565- struct list_head *prev,
81566- struct list_head *next)
81567+static bool __list_add_debug(struct list_head *new,
81568+ struct list_head *prev,
81569+ struct list_head *next)
81570 {
81571- WARN(next->prev != prev,
81572+ if (WARN(next->prev != prev,
81573 "list_add corruption. next->prev should be "
81574 "prev (%p), but was %p. (next=%p).\n",
81575- prev, next->prev, next);
81576- WARN(prev->next != next,
81577+ prev, next->prev, next) ||
81578+ WARN(prev->next != next,
81579 "list_add corruption. prev->next should be "
81580 "next (%p), but was %p. (prev=%p).\n",
81581- next, prev->next, prev);
81582- WARN(new == prev || new == next,
81583- "list_add double add: new=%p, prev=%p, next=%p.\n",
81584- new, prev, next);
81585+ next, prev->next, prev) ||
81586+ WARN(new == prev || new == next,
81587+ "list_add double add: new=%p, prev=%p, next=%p.\n",
81588+ new, prev, next))
81589+ return false;
81590+ return true;
81591+}
81592+
81593+void __list_add(struct list_head *new,
81594+ struct list_head *prev,
81595+ struct list_head *next)
81596+{
81597+ if (!__list_add_debug(new, prev, next))
81598+ return;
81599+
81600 next->prev = new;
81601 new->next = next;
81602 new->prev = prev;
81603@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
81604 }
81605 EXPORT_SYMBOL(__list_add);
81606
81607-void __list_del_entry(struct list_head *entry)
81608+static bool __list_del_entry_debug(struct list_head *entry)
81609 {
81610 struct list_head *prev, *next;
81611
81612@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
81613 WARN(next->prev != entry,
81614 "list_del corruption. next->prev should be %p, "
81615 "but was %p\n", entry, next->prev))
81616+ return false;
81617+ return true;
81618+}
81619+
81620+void __list_del_entry(struct list_head *entry)
81621+{
81622+ if (!__list_del_entry_debug(entry))
81623 return;
81624
81625- __list_del(prev, next);
81626+ __list_del(entry->prev, entry->next);
81627 }
81628 EXPORT_SYMBOL(__list_del_entry);
81629
81630@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
81631 void __list_add_rcu(struct list_head *new,
81632 struct list_head *prev, struct list_head *next)
81633 {
81634- WARN(next->prev != prev,
81635- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
81636- prev, next->prev, next);
81637- WARN(prev->next != next,
81638- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
81639- next, prev->next, prev);
81640+ if (!__list_add_debug(new, prev, next))
81641+ return;
81642+
81643 new->next = next;
81644 new->prev = prev;
81645 rcu_assign_pointer(list_next_rcu(prev), new);
81646 next->prev = new;
81647 }
81648 EXPORT_SYMBOL(__list_add_rcu);
81649+#endif
81650+
81651+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
81652+{
81653+#ifdef CONFIG_DEBUG_LIST
81654+ if (!__list_add_debug(new, prev, next))
81655+ return;
81656+#endif
81657+
81658+ pax_open_kernel();
81659+ next->prev = new;
81660+ new->next = next;
81661+ new->prev = prev;
81662+ prev->next = new;
81663+ pax_close_kernel();
81664+}
81665+EXPORT_SYMBOL(__pax_list_add);
81666+
81667+void pax_list_del(struct list_head *entry)
81668+{
81669+#ifdef CONFIG_DEBUG_LIST
81670+ if (!__list_del_entry_debug(entry))
81671+ return;
81672+#endif
81673+
81674+ pax_open_kernel();
81675+ __list_del(entry->prev, entry->next);
81676+ entry->next = LIST_POISON1;
81677+ entry->prev = LIST_POISON2;
81678+ pax_close_kernel();
81679+}
81680+EXPORT_SYMBOL(pax_list_del);
81681+
81682+void pax_list_del_init(struct list_head *entry)
81683+{
81684+ pax_open_kernel();
81685+ __list_del(entry->prev, entry->next);
81686+ INIT_LIST_HEAD(entry);
81687+ pax_close_kernel();
81688+}
81689+EXPORT_SYMBOL(pax_list_del_init);
81690+
81691+void __pax_list_add_rcu(struct list_head *new,
81692+ struct list_head *prev, struct list_head *next)
81693+{
81694+#ifdef CONFIG_DEBUG_LIST
81695+ if (!__list_add_debug(new, prev, next))
81696+ return;
81697+#endif
81698+
81699+ pax_open_kernel();
81700+ new->next = next;
81701+ new->prev = prev;
81702+ rcu_assign_pointer(list_next_rcu(prev), new);
81703+ next->prev = new;
81704+ pax_close_kernel();
81705+}
81706+EXPORT_SYMBOL(__pax_list_add_rcu);
81707+
81708+void pax_list_del_rcu(struct list_head *entry)
81709+{
81710+#ifdef CONFIG_DEBUG_LIST
81711+ if (!__list_del_entry_debug(entry))
81712+ return;
81713+#endif
81714+
81715+ pax_open_kernel();
81716+ __list_del(entry->prev, entry->next);
81717+ entry->next = LIST_POISON1;
81718+ entry->prev = LIST_POISON2;
81719+ pax_close_kernel();
81720+}
81721+EXPORT_SYMBOL(pax_list_del_rcu);
81722diff --git a/lib/radix-tree.c b/lib/radix-tree.c
81723index e796429..6e38f9f 100644
81724--- a/lib/radix-tree.c
81725+++ b/lib/radix-tree.c
81726@@ -92,7 +92,7 @@ struct radix_tree_preload {
81727 int nr;
81728 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
81729 };
81730-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
81731+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
81732
81733 static inline void *ptr_to_indirect(void *ptr)
81734 {
81735diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
81736index bb2b201..46abaf9 100644
81737--- a/lib/strncpy_from_user.c
81738+++ b/lib/strncpy_from_user.c
81739@@ -21,7 +21,7 @@
81740 */
81741 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
81742 {
81743- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81744+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81745 long res = 0;
81746
81747 /*
81748diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
81749index a28df52..3d55877 100644
81750--- a/lib/strnlen_user.c
81751+++ b/lib/strnlen_user.c
81752@@ -26,7 +26,7 @@
81753 */
81754 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
81755 {
81756- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81757+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
81758 long align, res = 0;
81759 unsigned long c;
81760
81761diff --git a/lib/swiotlb.c b/lib/swiotlb.c
81762index d23762e..e21eab2 100644
81763--- a/lib/swiotlb.c
81764+++ b/lib/swiotlb.c
81765@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
81766
81767 void
81768 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
81769- dma_addr_t dev_addr)
81770+ dma_addr_t dev_addr, struct dma_attrs *attrs)
81771 {
81772 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
81773
81774diff --git a/lib/usercopy.c b/lib/usercopy.c
81775index 4f5b1dd..7cab418 100644
81776--- a/lib/usercopy.c
81777+++ b/lib/usercopy.c
81778@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
81779 WARN(1, "Buffer overflow detected!\n");
81780 }
81781 EXPORT_SYMBOL(copy_from_user_overflow);
81782+
81783+void copy_to_user_overflow(void)
81784+{
81785+ WARN(1, "Buffer overflow detected!\n");
81786+}
81787+EXPORT_SYMBOL(copy_to_user_overflow);
81788diff --git a/lib/vsprintf.c b/lib/vsprintf.c
81789index e149c64..24aa71a 100644
81790--- a/lib/vsprintf.c
81791+++ b/lib/vsprintf.c
81792@@ -16,6 +16,9 @@
81793 * - scnprintf and vscnprintf
81794 */
81795
81796+#ifdef CONFIG_GRKERNSEC_HIDESYM
81797+#define __INCLUDED_BY_HIDESYM 1
81798+#endif
81799 #include <stdarg.h>
81800 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
81801 #include <linux/types.h>
81802@@ -981,7 +984,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
81803 return number(buf, end, *(const netdev_features_t *)addr, spec);
81804 }
81805
81806+#ifdef CONFIG_GRKERNSEC_HIDESYM
81807+int kptr_restrict __read_mostly = 2;
81808+#else
81809 int kptr_restrict __read_mostly;
81810+#endif
81811
81812 /*
81813 * Show a '%p' thing. A kernel extension is that the '%p' is followed
81814@@ -994,6 +1001,7 @@ int kptr_restrict __read_mostly;
81815 * - 'f' For simple symbolic function names without offset
81816 * - 'S' For symbolic direct pointers with offset
81817 * - 's' For symbolic direct pointers without offset
81818+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
81819 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
81820 * - 'B' For backtraced symbolic direct pointers with offset
81821 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
81822@@ -1052,12 +1060,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81823
81824 if (!ptr && *fmt != 'K') {
81825 /*
81826- * Print (null) with the same width as a pointer so it makes
81827+ * Print (nil) with the same width as a pointer so it makes
81828 * tabular output look nice.
81829 */
81830 if (spec.field_width == -1)
81831 spec.field_width = default_width;
81832- return string(buf, end, "(null)", spec);
81833+ return string(buf, end, "(nil)", spec);
81834 }
81835
81836 switch (*fmt) {
81837@@ -1067,6 +1075,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81838 /* Fallthrough */
81839 case 'S':
81840 case 's':
81841+#ifdef CONFIG_GRKERNSEC_HIDESYM
81842+ break;
81843+#else
81844+ return symbol_string(buf, end, ptr, spec, fmt);
81845+#endif
81846+ case 'A':
81847 case 'B':
81848 return symbol_string(buf, end, ptr, spec, fmt);
81849 case 'R':
81850@@ -1107,6 +1121,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81851 va_end(va);
81852 return buf;
81853 }
81854+ case 'P':
81855+ break;
81856 case 'K':
81857 /*
81858 * %pK cannot be used in IRQ context because its test
81859@@ -1136,6 +1152,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81860 return number(buf, end,
81861 (unsigned long long) *((phys_addr_t *)ptr), spec);
81862 }
81863+
81864+#ifdef CONFIG_GRKERNSEC_HIDESYM
81865+ /* 'P' = approved pointers to copy to userland,
81866+ as in the /proc/kallsyms case, as we make it display nothing
81867+ for non-root users, and the real contents for root users
81868+ Also ignore 'K' pointers, since we force their NULLing for non-root users
81869+ above
81870+ */
81871+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
81872+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
81873+ dump_stack();
81874+ ptr = NULL;
81875+ }
81876+#endif
81877+
81878 spec.flags |= SMALL;
81879 if (spec.field_width == -1) {
81880 spec.field_width = default_width;
81881@@ -1857,11 +1888,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81882 typeof(type) value; \
81883 if (sizeof(type) == 8) { \
81884 args = PTR_ALIGN(args, sizeof(u32)); \
81885- *(u32 *)&value = *(u32 *)args; \
81886- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
81887+ *(u32 *)&value = *(const u32 *)args; \
81888+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
81889 } else { \
81890 args = PTR_ALIGN(args, sizeof(type)); \
81891- value = *(typeof(type) *)args; \
81892+ value = *(const typeof(type) *)args; \
81893 } \
81894 args += sizeof(type); \
81895 value; \
81896@@ -1924,7 +1955,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81897 case FORMAT_TYPE_STR: {
81898 const char *str_arg = args;
81899 args += strlen(str_arg) + 1;
81900- str = string(str, end, (char *)str_arg, spec);
81901+ str = string(str, end, str_arg, spec);
81902 break;
81903 }
81904
81905diff --git a/localversion-grsec b/localversion-grsec
81906new file mode 100644
81907index 0000000..7cd6065
81908--- /dev/null
81909+++ b/localversion-grsec
81910@@ -0,0 +1 @@
81911+-grsec
81912diff --git a/mm/Kconfig b/mm/Kconfig
81913index e742d06..c56fdd8 100644
81914--- a/mm/Kconfig
81915+++ b/mm/Kconfig
81916@@ -317,10 +317,10 @@ config KSM
81917 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
81918
81919 config DEFAULT_MMAP_MIN_ADDR
81920- int "Low address space to protect from user allocation"
81921+ int "Low address space to protect from user allocation"
81922 depends on MMU
81923- default 4096
81924- help
81925+ default 65536
81926+ help
81927 This is the portion of low virtual memory which should be protected
81928 from userspace allocation. Keeping a user from writing to low pages
81929 can help reduce the impact of kernel NULL pointer bugs.
81930@@ -351,7 +351,7 @@ config MEMORY_FAILURE
81931
81932 config HWPOISON_INJECT
81933 tristate "HWPoison pages injector"
81934- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
81935+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
81936 select PROC_PAGE_MONITOR
81937
81938 config NOMMU_INITIAL_TRIM_EXCESS
81939diff --git a/mm/backing-dev.c b/mm/backing-dev.c
81940index 5025174..9fc1c5c 100644
81941--- a/mm/backing-dev.c
81942+++ b/mm/backing-dev.c
81943@@ -515,7 +515,6 @@ EXPORT_SYMBOL(bdi_destroy);
81944 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
81945 unsigned int cap)
81946 {
81947- char tmp[32];
81948 int err;
81949
81950 bdi->name = name;
81951@@ -524,8 +523,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
81952 if (err)
81953 return err;
81954
81955- sprintf(tmp, "%.28s%s", name, "-%d");
81956- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
81957+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return(&bdi_seq));
81958 if (err) {
81959 bdi_destroy(bdi);
81960 return err;
81961diff --git a/mm/filemap.c b/mm/filemap.c
81962index 7905fe7..e60faa8 100644
81963--- a/mm/filemap.c
81964+++ b/mm/filemap.c
81965@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
81966 struct address_space *mapping = file->f_mapping;
81967
81968 if (!mapping->a_ops->readpage)
81969- return -ENOEXEC;
81970+ return -ENODEV;
81971 file_accessed(file);
81972 vma->vm_ops = &generic_file_vm_ops;
81973 return 0;
81974@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
81975 *pos = i_size_read(inode);
81976
81977 if (limit != RLIM_INFINITY) {
81978+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
81979 if (*pos >= limit) {
81980 send_sig(SIGXFSZ, current, 0);
81981 return -EFBIG;
81982diff --git a/mm/fremap.c b/mm/fremap.c
81983index 87da359..3f41cb1 100644
81984--- a/mm/fremap.c
81985+++ b/mm/fremap.c
81986@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
81987 retry:
81988 vma = find_vma(mm, start);
81989
81990+#ifdef CONFIG_PAX_SEGMEXEC
81991+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
81992+ goto out;
81993+#endif
81994+
81995 /*
81996 * Make sure the vma is shared, that it supports prefaulting,
81997 * and that the remapped range is valid and fully within
81998diff --git a/mm/highmem.c b/mm/highmem.c
81999index b32b70c..e512eb0 100644
82000--- a/mm/highmem.c
82001+++ b/mm/highmem.c
82002@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
82003 * So no dangers, even with speculative execution.
82004 */
82005 page = pte_page(pkmap_page_table[i]);
82006+ pax_open_kernel();
82007 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
82008-
82009+ pax_close_kernel();
82010 set_page_address(page, NULL);
82011 need_flush = 1;
82012 }
82013@@ -198,9 +199,11 @@ start:
82014 }
82015 }
82016 vaddr = PKMAP_ADDR(last_pkmap_nr);
82017+
82018+ pax_open_kernel();
82019 set_pte_at(&init_mm, vaddr,
82020 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
82021-
82022+ pax_close_kernel();
82023 pkmap_count[last_pkmap_nr] = 1;
82024 set_page_address(page, (void *)vaddr);
82025
82026diff --git a/mm/hugetlb.c b/mm/hugetlb.c
82027index 5cf99bf..28634c8 100644
82028--- a/mm/hugetlb.c
82029+++ b/mm/hugetlb.c
82030@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
82031 struct hstate *h = &default_hstate;
82032 unsigned long tmp;
82033 int ret;
82034+ ctl_table_no_const hugetlb_table;
82035
82036 tmp = h->max_huge_pages;
82037
82038 if (write && h->order >= MAX_ORDER)
82039 return -EINVAL;
82040
82041- table->data = &tmp;
82042- table->maxlen = sizeof(unsigned long);
82043- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
82044+ hugetlb_table = *table;
82045+ hugetlb_table.data = &tmp;
82046+ hugetlb_table.maxlen = sizeof(unsigned long);
82047+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
82048 if (ret)
82049 goto out;
82050
82051@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
82052 struct hstate *h = &default_hstate;
82053 unsigned long tmp;
82054 int ret;
82055+ ctl_table_no_const hugetlb_table;
82056
82057 tmp = h->nr_overcommit_huge_pages;
82058
82059 if (write && h->order >= MAX_ORDER)
82060 return -EINVAL;
82061
82062- table->data = &tmp;
82063- table->maxlen = sizeof(unsigned long);
82064- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
82065+ hugetlb_table = *table;
82066+ hugetlb_table.data = &tmp;
82067+ hugetlb_table.maxlen = sizeof(unsigned long);
82068+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
82069 if (ret)
82070 goto out;
82071
82072@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
82073 return 1;
82074 }
82075
82076+#ifdef CONFIG_PAX_SEGMEXEC
82077+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
82078+{
82079+ struct mm_struct *mm = vma->vm_mm;
82080+ struct vm_area_struct *vma_m;
82081+ unsigned long address_m;
82082+ pte_t *ptep_m;
82083+
82084+ vma_m = pax_find_mirror_vma(vma);
82085+ if (!vma_m)
82086+ return;
82087+
82088+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
82089+ address_m = address + SEGMEXEC_TASK_SIZE;
82090+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
82091+ get_page(page_m);
82092+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
82093+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
82094+}
82095+#endif
82096+
82097 /*
82098 * Hugetlb_cow() should be called with page lock of the original hugepage held.
82099 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
82100@@ -2663,6 +2688,11 @@ retry_avoidcopy:
82101 make_huge_pte(vma, new_page, 1));
82102 page_remove_rmap(old_page);
82103 hugepage_add_new_anon_rmap(new_page, vma, address);
82104+
82105+#ifdef CONFIG_PAX_SEGMEXEC
82106+ pax_mirror_huge_pte(vma, address, new_page);
82107+#endif
82108+
82109 /* Make the old page be freed below */
82110 new_page = old_page;
82111 }
82112@@ -2821,6 +2851,10 @@ retry:
82113 && (vma->vm_flags & VM_SHARED)));
82114 set_huge_pte_at(mm, address, ptep, new_pte);
82115
82116+#ifdef CONFIG_PAX_SEGMEXEC
82117+ pax_mirror_huge_pte(vma, address, page);
82118+#endif
82119+
82120 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
82121 /* Optimization, do the COW without a second fault */
82122 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
82123@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82124 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
82125 struct hstate *h = hstate_vma(vma);
82126
82127+#ifdef CONFIG_PAX_SEGMEXEC
82128+ struct vm_area_struct *vma_m;
82129+#endif
82130+
82131 address &= huge_page_mask(h);
82132
82133 ptep = huge_pte_offset(mm, address);
82134@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82135 VM_FAULT_SET_HINDEX(hstate_index(h));
82136 }
82137
82138+#ifdef CONFIG_PAX_SEGMEXEC
82139+ vma_m = pax_find_mirror_vma(vma);
82140+ if (vma_m) {
82141+ unsigned long address_m;
82142+
82143+ if (vma->vm_start > vma_m->vm_start) {
82144+ address_m = address;
82145+ address -= SEGMEXEC_TASK_SIZE;
82146+ vma = vma_m;
82147+ h = hstate_vma(vma);
82148+ } else
82149+ address_m = address + SEGMEXEC_TASK_SIZE;
82150+
82151+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
82152+ return VM_FAULT_OOM;
82153+ address_m &= HPAGE_MASK;
82154+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
82155+ }
82156+#endif
82157+
82158 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
82159 if (!ptep)
82160 return VM_FAULT_OOM;
82161diff --git a/mm/internal.h b/mm/internal.h
82162index 8562de0..7fdfe92 100644
82163--- a/mm/internal.h
82164+++ b/mm/internal.h
82165@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
82166 * in mm/page_alloc.c
82167 */
82168 extern void __free_pages_bootmem(struct page *page, unsigned int order);
82169+extern void free_compound_page(struct page *page);
82170 extern void prep_compound_page(struct page *page, unsigned long order);
82171 #ifdef CONFIG_MEMORY_FAILURE
82172 extern bool is_free_buddy_page(struct page *page);
82173diff --git a/mm/kmemleak.c b/mm/kmemleak.c
82174index c8d7f31..2dbeffd 100644
82175--- a/mm/kmemleak.c
82176+++ b/mm/kmemleak.c
82177@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
82178
82179 for (i = 0; i < object->trace_len; i++) {
82180 void *ptr = (void *)object->trace[i];
82181- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
82182+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
82183 }
82184 }
82185
82186@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
82187 return -ENOMEM;
82188 }
82189
82190- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
82191+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
82192 &kmemleak_fops);
82193 if (!dentry)
82194 pr_warning("Failed to create the debugfs kmemleak file\n");
82195diff --git a/mm/maccess.c b/mm/maccess.c
82196index d53adf9..03a24bf 100644
82197--- a/mm/maccess.c
82198+++ b/mm/maccess.c
82199@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
82200 set_fs(KERNEL_DS);
82201 pagefault_disable();
82202 ret = __copy_from_user_inatomic(dst,
82203- (__force const void __user *)src, size);
82204+ (const void __force_user *)src, size);
82205 pagefault_enable();
82206 set_fs(old_fs);
82207
82208@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
82209
82210 set_fs(KERNEL_DS);
82211 pagefault_disable();
82212- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
82213+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
82214 pagefault_enable();
82215 set_fs(old_fs);
82216
82217diff --git a/mm/madvise.c b/mm/madvise.c
82218index 7055883..aafb1ed 100644
82219--- a/mm/madvise.c
82220+++ b/mm/madvise.c
82221@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
82222 pgoff_t pgoff;
82223 unsigned long new_flags = vma->vm_flags;
82224
82225+#ifdef CONFIG_PAX_SEGMEXEC
82226+ struct vm_area_struct *vma_m;
82227+#endif
82228+
82229 switch (behavior) {
82230 case MADV_NORMAL:
82231 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
82232@@ -126,6 +130,13 @@ success:
82233 /*
82234 * vm_flags is protected by the mmap_sem held in write mode.
82235 */
82236+
82237+#ifdef CONFIG_PAX_SEGMEXEC
82238+ vma_m = pax_find_mirror_vma(vma);
82239+ if (vma_m)
82240+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
82241+#endif
82242+
82243 vma->vm_flags = new_flags;
82244
82245 out:
82246@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
82247 struct vm_area_struct ** prev,
82248 unsigned long start, unsigned long end)
82249 {
82250+
82251+#ifdef CONFIG_PAX_SEGMEXEC
82252+ struct vm_area_struct *vma_m;
82253+#endif
82254+
82255 *prev = vma;
82256 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
82257 return -EINVAL;
82258@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
82259 zap_page_range(vma, start, end - start, &details);
82260 } else
82261 zap_page_range(vma, start, end - start, NULL);
82262+
82263+#ifdef CONFIG_PAX_SEGMEXEC
82264+ vma_m = pax_find_mirror_vma(vma);
82265+ if (vma_m) {
82266+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
82267+ struct zap_details details = {
82268+ .nonlinear_vma = vma_m,
82269+ .last_index = ULONG_MAX,
82270+ };
82271+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
82272+ } else
82273+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
82274+ }
82275+#endif
82276+
82277 return 0;
82278 }
82279
82280@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
82281 if (end < start)
82282 return error;
82283
82284+#ifdef CONFIG_PAX_SEGMEXEC
82285+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
82286+ if (end > SEGMEXEC_TASK_SIZE)
82287+ return error;
82288+ } else
82289+#endif
82290+
82291+ if (end > TASK_SIZE)
82292+ return error;
82293+
82294 error = 0;
82295 if (end == start)
82296 return error;
82297diff --git a/mm/memory-failure.c b/mm/memory-failure.c
82298index ceb0c7f..b2b8e94 100644
82299--- a/mm/memory-failure.c
82300+++ b/mm/memory-failure.c
82301@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
82302
82303 int sysctl_memory_failure_recovery __read_mostly = 1;
82304
82305-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
82306+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
82307
82308 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
82309
82310@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
82311 pfn, t->comm, t->pid);
82312 si.si_signo = SIGBUS;
82313 si.si_errno = 0;
82314- si.si_addr = (void *)addr;
82315+ si.si_addr = (void __user *)addr;
82316 #ifdef __ARCH_SI_TRAPNO
82317 si.si_trapno = trapno;
82318 #endif
82319@@ -760,7 +760,7 @@ static struct page_state {
82320 unsigned long res;
82321 char *msg;
82322 int (*action)(struct page *p, unsigned long pfn);
82323-} error_states[] = {
82324+} __do_const error_states[] = {
82325 { reserved, reserved, "reserved kernel", me_kernel },
82326 /*
82327 * free pages are specially detected outside this table:
82328@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
82329 nr_pages = 1 << compound_order(hpage);
82330 else /* normal page or thp */
82331 nr_pages = 1;
82332- atomic_long_add(nr_pages, &num_poisoned_pages);
82333+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
82334
82335 /*
82336 * We need/can do nothing about count=0 pages.
82337@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
82338 if (!PageHWPoison(hpage)
82339 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
82340 || (p != hpage && TestSetPageHWPoison(hpage))) {
82341- atomic_long_sub(nr_pages, &num_poisoned_pages);
82342+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
82343 return 0;
82344 }
82345 set_page_hwpoison_huge_page(hpage);
82346@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
82347 }
82348 if (hwpoison_filter(p)) {
82349 if (TestClearPageHWPoison(p))
82350- atomic_long_sub(nr_pages, &num_poisoned_pages);
82351+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
82352 unlock_page(hpage);
82353 put_page(hpage);
82354 return 0;
82355@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
82356 return 0;
82357 }
82358 if (TestClearPageHWPoison(p))
82359- atomic_long_sub(nr_pages, &num_poisoned_pages);
82360+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
82361 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
82362 return 0;
82363 }
82364@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
82365 */
82366 if (TestClearPageHWPoison(page)) {
82367 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
82368- atomic_long_sub(nr_pages, &num_poisoned_pages);
82369+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
82370 freeit = 1;
82371 if (PageHuge(page))
82372 clear_page_hwpoison_huge_page(page);
82373@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
82374 } else {
82375 set_page_hwpoison_huge_page(hpage);
82376 dequeue_hwpoisoned_huge_page(hpage);
82377- atomic_long_add(1 << compound_trans_order(hpage),
82378+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
82379 &num_poisoned_pages);
82380 }
82381 /* keep elevated page count for bad page */
82382@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
82383 if (PageHuge(page)) {
82384 set_page_hwpoison_huge_page(hpage);
82385 dequeue_hwpoisoned_huge_page(hpage);
82386- atomic_long_add(1 << compound_trans_order(hpage),
82387+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
82388 &num_poisoned_pages);
82389 } else {
82390 SetPageHWPoison(page);
82391- atomic_long_inc(&num_poisoned_pages);
82392+ atomic_long_inc_unchecked(&num_poisoned_pages);
82393 }
82394 }
82395 /* keep elevated page count for bad page */
82396@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
82397 put_page(page);
82398 pr_info("soft_offline: %#lx: invalidated\n", pfn);
82399 SetPageHWPoison(page);
82400- atomic_long_inc(&num_poisoned_pages);
82401+ atomic_long_inc_unchecked(&num_poisoned_pages);
82402 return 0;
82403 }
82404
82405@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
82406 ret = -EIO;
82407 } else {
82408 SetPageHWPoison(page);
82409- atomic_long_inc(&num_poisoned_pages);
82410+ atomic_long_inc_unchecked(&num_poisoned_pages);
82411 }
82412 } else {
82413 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
82414diff --git a/mm/memory.c b/mm/memory.c
82415index 5e50800..c47ba9a 100644
82416--- a/mm/memory.c
82417+++ b/mm/memory.c
82418@@ -429,6 +429,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
82419 free_pte_range(tlb, pmd, addr);
82420 } while (pmd++, addr = next, addr != end);
82421
82422+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
82423 start &= PUD_MASK;
82424 if (start < floor)
82425 return;
82426@@ -443,6 +444,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
82427 pmd = pmd_offset(pud, start);
82428 pud_clear(pud);
82429 pmd_free_tlb(tlb, pmd, start);
82430+#endif
82431+
82432 }
82433
82434 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
82435@@ -462,6 +465,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
82436 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
82437 } while (pud++, addr = next, addr != end);
82438
82439+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
82440 start &= PGDIR_MASK;
82441 if (start < floor)
82442 return;
82443@@ -476,6 +480,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
82444 pud = pud_offset(pgd, start);
82445 pgd_clear(pgd);
82446 pud_free_tlb(tlb, pud, start);
82447+#endif
82448+
82449 }
82450
82451 /*
82452@@ -1638,12 +1644,6 @@ no_page_table:
82453 return page;
82454 }
82455
82456-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
82457-{
82458- return stack_guard_page_start(vma, addr) ||
82459- stack_guard_page_end(vma, addr+PAGE_SIZE);
82460-}
82461-
82462 /**
82463 * __get_user_pages() - pin user pages in memory
82464 * @tsk: task_struct of target task
82465@@ -1730,10 +1730,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
82466
82467 i = 0;
82468
82469- do {
82470+ while (nr_pages) {
82471 struct vm_area_struct *vma;
82472
82473- vma = find_extend_vma(mm, start);
82474+ vma = find_vma(mm, start);
82475 if (!vma && in_gate_area(mm, start)) {
82476 unsigned long pg = start & PAGE_MASK;
82477 pgd_t *pgd;
82478@@ -1782,7 +1782,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
82479 goto next_page;
82480 }
82481
82482- if (!vma ||
82483+ if (!vma || start < vma->vm_start ||
82484 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
82485 !(vm_flags & vma->vm_flags))
82486 return i ? : -EFAULT;
82487@@ -1811,11 +1811,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
82488 int ret;
82489 unsigned int fault_flags = 0;
82490
82491- /* For mlock, just skip the stack guard page. */
82492- if (foll_flags & FOLL_MLOCK) {
82493- if (stack_guard_page(vma, start))
82494- goto next_page;
82495- }
82496 if (foll_flags & FOLL_WRITE)
82497 fault_flags |= FAULT_FLAG_WRITE;
82498 if (nonblocking)
82499@@ -1895,7 +1890,7 @@ next_page:
82500 start += page_increm * PAGE_SIZE;
82501 nr_pages -= page_increm;
82502 } while (nr_pages && start < vma->vm_end);
82503- } while (nr_pages);
82504+ }
82505 return i;
82506 }
82507 EXPORT_SYMBOL(__get_user_pages);
82508@@ -2102,6 +2097,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
82509 page_add_file_rmap(page);
82510 set_pte_at(mm, addr, pte, mk_pte(page, prot));
82511
82512+#ifdef CONFIG_PAX_SEGMEXEC
82513+ pax_mirror_file_pte(vma, addr, page, ptl);
82514+#endif
82515+
82516 retval = 0;
82517 pte_unmap_unlock(pte, ptl);
82518 return retval;
82519@@ -2146,9 +2145,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
82520 if (!page_count(page))
82521 return -EINVAL;
82522 if (!(vma->vm_flags & VM_MIXEDMAP)) {
82523+
82524+#ifdef CONFIG_PAX_SEGMEXEC
82525+ struct vm_area_struct *vma_m;
82526+#endif
82527+
82528 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
82529 BUG_ON(vma->vm_flags & VM_PFNMAP);
82530 vma->vm_flags |= VM_MIXEDMAP;
82531+
82532+#ifdef CONFIG_PAX_SEGMEXEC
82533+ vma_m = pax_find_mirror_vma(vma);
82534+ if (vma_m)
82535+ vma_m->vm_flags |= VM_MIXEDMAP;
82536+#endif
82537+
82538 }
82539 return insert_page(vma, addr, page, vma->vm_page_prot);
82540 }
82541@@ -2231,6 +2242,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
82542 unsigned long pfn)
82543 {
82544 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
82545+ BUG_ON(vma->vm_mirror);
82546
82547 if (addr < vma->vm_start || addr >= vma->vm_end)
82548 return -EFAULT;
82549@@ -2478,7 +2490,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
82550
82551 BUG_ON(pud_huge(*pud));
82552
82553- pmd = pmd_alloc(mm, pud, addr);
82554+ pmd = (mm == &init_mm) ?
82555+ pmd_alloc_kernel(mm, pud, addr) :
82556+ pmd_alloc(mm, pud, addr);
82557 if (!pmd)
82558 return -ENOMEM;
82559 do {
82560@@ -2498,7 +2512,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
82561 unsigned long next;
82562 int err;
82563
82564- pud = pud_alloc(mm, pgd, addr);
82565+ pud = (mm == &init_mm) ?
82566+ pud_alloc_kernel(mm, pgd, addr) :
82567+ pud_alloc(mm, pgd, addr);
82568 if (!pud)
82569 return -ENOMEM;
82570 do {
82571@@ -2586,6 +2602,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
82572 copy_user_highpage(dst, src, va, vma);
82573 }
82574
82575+#ifdef CONFIG_PAX_SEGMEXEC
82576+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
82577+{
82578+ struct mm_struct *mm = vma->vm_mm;
82579+ spinlock_t *ptl;
82580+ pte_t *pte, entry;
82581+
82582+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
82583+ entry = *pte;
82584+ if (!pte_present(entry)) {
82585+ if (!pte_none(entry)) {
82586+ BUG_ON(pte_file(entry));
82587+ free_swap_and_cache(pte_to_swp_entry(entry));
82588+ pte_clear_not_present_full(mm, address, pte, 0);
82589+ }
82590+ } else {
82591+ struct page *page;
82592+
82593+ flush_cache_page(vma, address, pte_pfn(entry));
82594+ entry = ptep_clear_flush(vma, address, pte);
82595+ BUG_ON(pte_dirty(entry));
82596+ page = vm_normal_page(vma, address, entry);
82597+ if (page) {
82598+ update_hiwater_rss(mm);
82599+ if (PageAnon(page))
82600+ dec_mm_counter_fast(mm, MM_ANONPAGES);
82601+ else
82602+ dec_mm_counter_fast(mm, MM_FILEPAGES);
82603+ page_remove_rmap(page);
82604+ page_cache_release(page);
82605+ }
82606+ }
82607+ pte_unmap_unlock(pte, ptl);
82608+}
82609+
82610+/* PaX: if vma is mirrored, synchronize the mirror's PTE
82611+ *
82612+ * the ptl of the lower mapped page is held on entry and is not released on exit
82613+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
82614+ */
82615+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
82616+{
82617+ struct mm_struct *mm = vma->vm_mm;
82618+ unsigned long address_m;
82619+ spinlock_t *ptl_m;
82620+ struct vm_area_struct *vma_m;
82621+ pmd_t *pmd_m;
82622+ pte_t *pte_m, entry_m;
82623+
82624+ BUG_ON(!page_m || !PageAnon(page_m));
82625+
82626+ vma_m = pax_find_mirror_vma(vma);
82627+ if (!vma_m)
82628+ return;
82629+
82630+ BUG_ON(!PageLocked(page_m));
82631+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
82632+ address_m = address + SEGMEXEC_TASK_SIZE;
82633+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
82634+ pte_m = pte_offset_map(pmd_m, address_m);
82635+ ptl_m = pte_lockptr(mm, pmd_m);
82636+ if (ptl != ptl_m) {
82637+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
82638+ if (!pte_none(*pte_m))
82639+ goto out;
82640+ }
82641+
82642+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
82643+ page_cache_get(page_m);
82644+ page_add_anon_rmap(page_m, vma_m, address_m);
82645+ inc_mm_counter_fast(mm, MM_ANONPAGES);
82646+ set_pte_at(mm, address_m, pte_m, entry_m);
82647+ update_mmu_cache(vma_m, address_m, pte_m);
82648+out:
82649+ if (ptl != ptl_m)
82650+ spin_unlock(ptl_m);
82651+ pte_unmap(pte_m);
82652+ unlock_page(page_m);
82653+}
82654+
82655+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
82656+{
82657+ struct mm_struct *mm = vma->vm_mm;
82658+ unsigned long address_m;
82659+ spinlock_t *ptl_m;
82660+ struct vm_area_struct *vma_m;
82661+ pmd_t *pmd_m;
82662+ pte_t *pte_m, entry_m;
82663+
82664+ BUG_ON(!page_m || PageAnon(page_m));
82665+
82666+ vma_m = pax_find_mirror_vma(vma);
82667+ if (!vma_m)
82668+ return;
82669+
82670+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
82671+ address_m = address + SEGMEXEC_TASK_SIZE;
82672+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
82673+ pte_m = pte_offset_map(pmd_m, address_m);
82674+ ptl_m = pte_lockptr(mm, pmd_m);
82675+ if (ptl != ptl_m) {
82676+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
82677+ if (!pte_none(*pte_m))
82678+ goto out;
82679+ }
82680+
82681+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
82682+ page_cache_get(page_m);
82683+ page_add_file_rmap(page_m);
82684+ inc_mm_counter_fast(mm, MM_FILEPAGES);
82685+ set_pte_at(mm, address_m, pte_m, entry_m);
82686+ update_mmu_cache(vma_m, address_m, pte_m);
82687+out:
82688+ if (ptl != ptl_m)
82689+ spin_unlock(ptl_m);
82690+ pte_unmap(pte_m);
82691+}
82692+
82693+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
82694+{
82695+ struct mm_struct *mm = vma->vm_mm;
82696+ unsigned long address_m;
82697+ spinlock_t *ptl_m;
82698+ struct vm_area_struct *vma_m;
82699+ pmd_t *pmd_m;
82700+ pte_t *pte_m, entry_m;
82701+
82702+ vma_m = pax_find_mirror_vma(vma);
82703+ if (!vma_m)
82704+ return;
82705+
82706+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
82707+ address_m = address + SEGMEXEC_TASK_SIZE;
82708+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
82709+ pte_m = pte_offset_map(pmd_m, address_m);
82710+ ptl_m = pte_lockptr(mm, pmd_m);
82711+ if (ptl != ptl_m) {
82712+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
82713+ if (!pte_none(*pte_m))
82714+ goto out;
82715+ }
82716+
82717+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
82718+ set_pte_at(mm, address_m, pte_m, entry_m);
82719+out:
82720+ if (ptl != ptl_m)
82721+ spin_unlock(ptl_m);
82722+ pte_unmap(pte_m);
82723+}
82724+
82725+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
82726+{
82727+ struct page *page_m;
82728+ pte_t entry;
82729+
82730+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
82731+ goto out;
82732+
82733+ entry = *pte;
82734+ page_m = vm_normal_page(vma, address, entry);
82735+ if (!page_m)
82736+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
82737+ else if (PageAnon(page_m)) {
82738+ if (pax_find_mirror_vma(vma)) {
82739+ pte_unmap_unlock(pte, ptl);
82740+ lock_page(page_m);
82741+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
82742+ if (pte_same(entry, *pte))
82743+ pax_mirror_anon_pte(vma, address, page_m, ptl);
82744+ else
82745+ unlock_page(page_m);
82746+ }
82747+ } else
82748+ pax_mirror_file_pte(vma, address, page_m, ptl);
82749+
82750+out:
82751+ pte_unmap_unlock(pte, ptl);
82752+}
82753+#endif
82754+
82755 /*
82756 * This routine handles present pages, when users try to write
82757 * to a shared page. It is done by copying the page to a new address
82758@@ -2802,6 +2998,12 @@ gotten:
82759 */
82760 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82761 if (likely(pte_same(*page_table, orig_pte))) {
82762+
82763+#ifdef CONFIG_PAX_SEGMEXEC
82764+ if (pax_find_mirror_vma(vma))
82765+ BUG_ON(!trylock_page(new_page));
82766+#endif
82767+
82768 if (old_page) {
82769 if (!PageAnon(old_page)) {
82770 dec_mm_counter_fast(mm, MM_FILEPAGES);
82771@@ -2853,6 +3055,10 @@ gotten:
82772 page_remove_rmap(old_page);
82773 }
82774
82775+#ifdef CONFIG_PAX_SEGMEXEC
82776+ pax_mirror_anon_pte(vma, address, new_page, ptl);
82777+#endif
82778+
82779 /* Free the old page.. */
82780 new_page = old_page;
82781 ret |= VM_FAULT_WRITE;
82782@@ -3128,6 +3334,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82783 swap_free(entry);
82784 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
82785 try_to_free_swap(page);
82786+
82787+#ifdef CONFIG_PAX_SEGMEXEC
82788+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
82789+#endif
82790+
82791 unlock_page(page);
82792 if (page != swapcache) {
82793 /*
82794@@ -3151,6 +3362,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82795
82796 /* No need to invalidate - it was non-present before */
82797 update_mmu_cache(vma, address, page_table);
82798+
82799+#ifdef CONFIG_PAX_SEGMEXEC
82800+ pax_mirror_anon_pte(vma, address, page, ptl);
82801+#endif
82802+
82803 unlock:
82804 pte_unmap_unlock(page_table, ptl);
82805 out:
82806@@ -3170,40 +3386,6 @@ out_release:
82807 }
82808
82809 /*
82810- * This is like a special single-page "expand_{down|up}wards()",
82811- * except we must first make sure that 'address{-|+}PAGE_SIZE'
82812- * doesn't hit another vma.
82813- */
82814-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
82815-{
82816- address &= PAGE_MASK;
82817- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
82818- struct vm_area_struct *prev = vma->vm_prev;
82819-
82820- /*
82821- * Is there a mapping abutting this one below?
82822- *
82823- * That's only ok if it's the same stack mapping
82824- * that has gotten split..
82825- */
82826- if (prev && prev->vm_end == address)
82827- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
82828-
82829- expand_downwards(vma, address - PAGE_SIZE);
82830- }
82831- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
82832- struct vm_area_struct *next = vma->vm_next;
82833-
82834- /* As VM_GROWSDOWN but s/below/above/ */
82835- if (next && next->vm_start == address + PAGE_SIZE)
82836- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
82837-
82838- expand_upwards(vma, address + PAGE_SIZE);
82839- }
82840- return 0;
82841-}
82842-
82843-/*
82844 * We enter with non-exclusive mmap_sem (to exclude vma changes,
82845 * but allow concurrent faults), and pte mapped but not yet locked.
82846 * We return with mmap_sem still held, but pte unmapped and unlocked.
82847@@ -3212,27 +3394,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82848 unsigned long address, pte_t *page_table, pmd_t *pmd,
82849 unsigned int flags)
82850 {
82851- struct page *page;
82852+ struct page *page = NULL;
82853 spinlock_t *ptl;
82854 pte_t entry;
82855
82856- pte_unmap(page_table);
82857-
82858- /* Check if we need to add a guard page to the stack */
82859- if (check_stack_guard_page(vma, address) < 0)
82860- return VM_FAULT_SIGBUS;
82861-
82862- /* Use the zero-page for reads */
82863 if (!(flags & FAULT_FLAG_WRITE)) {
82864 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
82865 vma->vm_page_prot));
82866- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82867+ ptl = pte_lockptr(mm, pmd);
82868+ spin_lock(ptl);
82869 if (!pte_none(*page_table))
82870 goto unlock;
82871 goto setpte;
82872 }
82873
82874 /* Allocate our own private page. */
82875+ pte_unmap(page_table);
82876+
82877 if (unlikely(anon_vma_prepare(vma)))
82878 goto oom;
82879 page = alloc_zeroed_user_highpage_movable(vma, address);
82880@@ -3256,6 +3434,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82881 if (!pte_none(*page_table))
82882 goto release;
82883
82884+#ifdef CONFIG_PAX_SEGMEXEC
82885+ if (pax_find_mirror_vma(vma))
82886+ BUG_ON(!trylock_page(page));
82887+#endif
82888+
82889 inc_mm_counter_fast(mm, MM_ANONPAGES);
82890 page_add_new_anon_rmap(page, vma, address);
82891 setpte:
82892@@ -3263,6 +3446,12 @@ setpte:
82893
82894 /* No need to invalidate - it was non-present before */
82895 update_mmu_cache(vma, address, page_table);
82896+
82897+#ifdef CONFIG_PAX_SEGMEXEC
82898+ if (page)
82899+ pax_mirror_anon_pte(vma, address, page, ptl);
82900+#endif
82901+
82902 unlock:
82903 pte_unmap_unlock(page_table, ptl);
82904 return 0;
82905@@ -3406,6 +3595,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82906 */
82907 /* Only go through if we didn't race with anybody else... */
82908 if (likely(pte_same(*page_table, orig_pte))) {
82909+
82910+#ifdef CONFIG_PAX_SEGMEXEC
82911+ if (anon && pax_find_mirror_vma(vma))
82912+ BUG_ON(!trylock_page(page));
82913+#endif
82914+
82915 flush_icache_page(vma, page);
82916 entry = mk_pte(page, vma->vm_page_prot);
82917 if (flags & FAULT_FLAG_WRITE)
82918@@ -3425,6 +3620,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82919
82920 /* no need to invalidate: a not-present page won't be cached */
82921 update_mmu_cache(vma, address, page_table);
82922+
82923+#ifdef CONFIG_PAX_SEGMEXEC
82924+ if (anon)
82925+ pax_mirror_anon_pte(vma, address, page, ptl);
82926+ else
82927+ pax_mirror_file_pte(vma, address, page, ptl);
82928+#endif
82929+
82930 } else {
82931 if (cow_page)
82932 mem_cgroup_uncharge_page(cow_page);
82933@@ -3746,6 +3949,12 @@ int handle_pte_fault(struct mm_struct *mm,
82934 if (flags & FAULT_FLAG_WRITE)
82935 flush_tlb_fix_spurious_fault(vma, address);
82936 }
82937+
82938+#ifdef CONFIG_PAX_SEGMEXEC
82939+ pax_mirror_pte(vma, address, pte, pmd, ptl);
82940+ return 0;
82941+#endif
82942+
82943 unlock:
82944 pte_unmap_unlock(pte, ptl);
82945 return 0;
82946@@ -3762,6 +3971,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82947 pmd_t *pmd;
82948 pte_t *pte;
82949
82950+#ifdef CONFIG_PAX_SEGMEXEC
82951+ struct vm_area_struct *vma_m;
82952+#endif
82953+
82954 __set_current_state(TASK_RUNNING);
82955
82956 count_vm_event(PGFAULT);
82957@@ -3773,6 +3986,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82958 if (unlikely(is_vm_hugetlb_page(vma)))
82959 return hugetlb_fault(mm, vma, address, flags);
82960
82961+#ifdef CONFIG_PAX_SEGMEXEC
82962+ vma_m = pax_find_mirror_vma(vma);
82963+ if (vma_m) {
82964+ unsigned long address_m;
82965+ pgd_t *pgd_m;
82966+ pud_t *pud_m;
82967+ pmd_t *pmd_m;
82968+
82969+ if (vma->vm_start > vma_m->vm_start) {
82970+ address_m = address;
82971+ address -= SEGMEXEC_TASK_SIZE;
82972+ vma = vma_m;
82973+ } else
82974+ address_m = address + SEGMEXEC_TASK_SIZE;
82975+
82976+ pgd_m = pgd_offset(mm, address_m);
82977+ pud_m = pud_alloc(mm, pgd_m, address_m);
82978+ if (!pud_m)
82979+ return VM_FAULT_OOM;
82980+ pmd_m = pmd_alloc(mm, pud_m, address_m);
82981+ if (!pmd_m)
82982+ return VM_FAULT_OOM;
82983+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
82984+ return VM_FAULT_OOM;
82985+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
82986+ }
82987+#endif
82988+
82989 retry:
82990 pgd = pgd_offset(mm, address);
82991 pud = pud_alloc(mm, pgd, address);
82992@@ -3871,6 +4112,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82993 spin_unlock(&mm->page_table_lock);
82994 return 0;
82995 }
82996+
82997+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82998+{
82999+ pud_t *new = pud_alloc_one(mm, address);
83000+ if (!new)
83001+ return -ENOMEM;
83002+
83003+ smp_wmb(); /* See comment in __pte_alloc */
83004+
83005+ spin_lock(&mm->page_table_lock);
83006+ if (pgd_present(*pgd)) /* Another has populated it */
83007+ pud_free(mm, new);
83008+ else
83009+ pgd_populate_kernel(mm, pgd, new);
83010+ spin_unlock(&mm->page_table_lock);
83011+ return 0;
83012+}
83013 #endif /* __PAGETABLE_PUD_FOLDED */
83014
83015 #ifndef __PAGETABLE_PMD_FOLDED
83016@@ -3901,6 +4159,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83017 spin_unlock(&mm->page_table_lock);
83018 return 0;
83019 }
83020+
83021+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83022+{
83023+ pmd_t *new = pmd_alloc_one(mm, address);
83024+ if (!new)
83025+ return -ENOMEM;
83026+
83027+ smp_wmb(); /* See comment in __pte_alloc */
83028+
83029+ spin_lock(&mm->page_table_lock);
83030+#ifndef __ARCH_HAS_4LEVEL_HACK
83031+ if (pud_present(*pud)) /* Another has populated it */
83032+ pmd_free(mm, new);
83033+ else
83034+ pud_populate_kernel(mm, pud, new);
83035+#else
83036+ if (pgd_present(*pud)) /* Another has populated it */
83037+ pmd_free(mm, new);
83038+ else
83039+ pgd_populate_kernel(mm, pud, new);
83040+#endif /* __ARCH_HAS_4LEVEL_HACK */
83041+ spin_unlock(&mm->page_table_lock);
83042+ return 0;
83043+}
83044 #endif /* __PAGETABLE_PMD_FOLDED */
83045
83046 #if !defined(__HAVE_ARCH_GATE_AREA)
83047@@ -3914,7 +4196,7 @@ static int __init gate_vma_init(void)
83048 gate_vma.vm_start = FIXADDR_USER_START;
83049 gate_vma.vm_end = FIXADDR_USER_END;
83050 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
83051- gate_vma.vm_page_prot = __P101;
83052+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
83053
83054 return 0;
83055 }
83056@@ -4048,8 +4330,8 @@ out:
83057 return ret;
83058 }
83059
83060-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83061- void *buf, int len, int write)
83062+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83063+ void *buf, size_t len, int write)
83064 {
83065 resource_size_t phys_addr;
83066 unsigned long prot = 0;
83067@@ -4074,8 +4356,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83068 * Access another process' address space as given in mm. If non-NULL, use the
83069 * given task for page fault accounting.
83070 */
83071-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83072- unsigned long addr, void *buf, int len, int write)
83073+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83074+ unsigned long addr, void *buf, size_t len, int write)
83075 {
83076 struct vm_area_struct *vma;
83077 void *old_buf = buf;
83078@@ -4083,7 +4365,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83079 down_read(&mm->mmap_sem);
83080 /* ignore errors, just check how much was successfully transferred */
83081 while (len) {
83082- int bytes, ret, offset;
83083+ ssize_t bytes, ret, offset;
83084 void *maddr;
83085 struct page *page = NULL;
83086
83087@@ -4142,8 +4424,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83088 *
83089 * The caller must hold a reference on @mm.
83090 */
83091-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83092- void *buf, int len, int write)
83093+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83094+ void *buf, size_t len, int write)
83095 {
83096 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83097 }
83098@@ -4153,11 +4435,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83099 * Source/target buffer must be kernel space,
83100 * Do not walk the page table directly, use get_user_pages
83101 */
83102-int access_process_vm(struct task_struct *tsk, unsigned long addr,
83103- void *buf, int len, int write)
83104+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
83105+ void *buf, size_t len, int write)
83106 {
83107 struct mm_struct *mm;
83108- int ret;
83109+ ssize_t ret;
83110
83111 mm = get_task_mm(tsk);
83112 if (!mm)
83113diff --git a/mm/mempolicy.c b/mm/mempolicy.c
83114index 4baf12e..5497066 100644
83115--- a/mm/mempolicy.c
83116+++ b/mm/mempolicy.c
83117@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
83118 unsigned long vmstart;
83119 unsigned long vmend;
83120
83121+#ifdef CONFIG_PAX_SEGMEXEC
83122+ struct vm_area_struct *vma_m;
83123+#endif
83124+
83125 vma = find_vma(mm, start);
83126 if (!vma || vma->vm_start > start)
83127 return -EFAULT;
83128@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
83129 err = vma_replace_policy(vma, new_pol);
83130 if (err)
83131 goto out;
83132+
83133+#ifdef CONFIG_PAX_SEGMEXEC
83134+ vma_m = pax_find_mirror_vma(vma);
83135+ if (vma_m) {
83136+ err = vma_replace_policy(vma_m, new_pol);
83137+ if (err)
83138+ goto out;
83139+ }
83140+#endif
83141+
83142 }
83143
83144 out:
83145@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
83146
83147 if (end < start)
83148 return -EINVAL;
83149+
83150+#ifdef CONFIG_PAX_SEGMEXEC
83151+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83152+ if (end > SEGMEXEC_TASK_SIZE)
83153+ return -EINVAL;
83154+ } else
83155+#endif
83156+
83157+ if (end > TASK_SIZE)
83158+ return -EINVAL;
83159+
83160 if (end == start)
83161 return 0;
83162
83163@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
83164 */
83165 tcred = __task_cred(task);
83166 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
83167- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
83168- !capable(CAP_SYS_NICE)) {
83169+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
83170 rcu_read_unlock();
83171 err = -EPERM;
83172 goto out_put;
83173@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
83174 goto out;
83175 }
83176
83177+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
83178+ if (mm != current->mm &&
83179+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
83180+ mmput(mm);
83181+ err = -EPERM;
83182+ goto out;
83183+ }
83184+#endif
83185+
83186 err = do_migrate_pages(mm, old, new,
83187 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
83188
83189diff --git a/mm/migrate.c b/mm/migrate.c
83190index 6f0c244..6d1ae32 100644
83191--- a/mm/migrate.c
83192+++ b/mm/migrate.c
83193@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
83194 */
83195 tcred = __task_cred(task);
83196 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
83197- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
83198- !capable(CAP_SYS_NICE)) {
83199+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
83200 rcu_read_unlock();
83201 err = -EPERM;
83202 goto out;
83203diff --git a/mm/mlock.c b/mm/mlock.c
83204index 79b7cf7..9944291 100644
83205--- a/mm/mlock.c
83206+++ b/mm/mlock.c
83207@@ -13,6 +13,7 @@
83208 #include <linux/pagemap.h>
83209 #include <linux/mempolicy.h>
83210 #include <linux/syscalls.h>
83211+#include <linux/security.h>
83212 #include <linux/sched.h>
83213 #include <linux/export.h>
83214 #include <linux/rmap.h>
83215@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
83216 {
83217 unsigned long nstart, end, tmp;
83218 struct vm_area_struct * vma, * prev;
83219- int error;
83220+ int error = 0;
83221
83222 VM_BUG_ON(start & ~PAGE_MASK);
83223 VM_BUG_ON(len != PAGE_ALIGN(len));
83224@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
83225 return -EINVAL;
83226 if (end == start)
83227 return 0;
83228+ if (end > TASK_SIZE)
83229+ return -EINVAL;
83230+
83231 vma = find_vma(current->mm, start);
83232 if (!vma || vma->vm_start > start)
83233 return -ENOMEM;
83234@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
83235 for (nstart = start ; ; ) {
83236 vm_flags_t newflags;
83237
83238+#ifdef CONFIG_PAX_SEGMEXEC
83239+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
83240+ break;
83241+#endif
83242+
83243 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
83244
83245 newflags = vma->vm_flags & ~VM_LOCKED;
83246@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
83247 lock_limit >>= PAGE_SHIFT;
83248
83249 /* check against resource limits */
83250+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
83251 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
83252 error = do_mlock(start, len, 1);
83253 up_write(&current->mm->mmap_sem);
83254@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
83255 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
83256 vm_flags_t newflags;
83257
83258+#ifdef CONFIG_PAX_SEGMEXEC
83259+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
83260+ break;
83261+#endif
83262+
83263 newflags = vma->vm_flags & ~VM_LOCKED;
83264 if (flags & MCL_CURRENT)
83265 newflags |= VM_LOCKED;
83266@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
83267 lock_limit >>= PAGE_SHIFT;
83268
83269 ret = -ENOMEM;
83270+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
83271 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
83272 capable(CAP_IPC_LOCK))
83273 ret = do_mlockall(flags);
83274diff --git a/mm/mmap.c b/mm/mmap.c
83275index 7dbe397..e84c411 100644
83276--- a/mm/mmap.c
83277+++ b/mm/mmap.c
83278@@ -36,6 +36,7 @@
83279 #include <linux/sched/sysctl.h>
83280 #include <linux/notifier.h>
83281 #include <linux/memory.h>
83282+#include <linux/random.h>
83283
83284 #include <asm/uaccess.h>
83285 #include <asm/cacheflush.h>
83286@@ -52,6 +53,16 @@
83287 #define arch_rebalance_pgtables(addr, len) (addr)
83288 #endif
83289
83290+static inline void verify_mm_writelocked(struct mm_struct *mm)
83291+{
83292+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
83293+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83294+ up_read(&mm->mmap_sem);
83295+ BUG();
83296+ }
83297+#endif
83298+}
83299+
83300 static void unmap_region(struct mm_struct *mm,
83301 struct vm_area_struct *vma, struct vm_area_struct *prev,
83302 unsigned long start, unsigned long end);
83303@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
83304 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
83305 *
83306 */
83307-pgprot_t protection_map[16] = {
83308+pgprot_t protection_map[16] __read_only = {
83309 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
83310 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
83311 };
83312
83313-pgprot_t vm_get_page_prot(unsigned long vm_flags)
83314+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83315 {
83316- return __pgprot(pgprot_val(protection_map[vm_flags &
83317+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
83318 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
83319 pgprot_val(arch_vm_get_page_prot(vm_flags)));
83320+
83321+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83322+ if (!(__supported_pte_mask & _PAGE_NX) &&
83323+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
83324+ (vm_flags & (VM_READ | VM_WRITE)))
83325+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
83326+#endif
83327+
83328+ return prot;
83329 }
83330 EXPORT_SYMBOL(vm_get_page_prot);
83331
83332@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
83333 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
83334 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
83335 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
83336+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
83337 /*
83338 * Make sure vm_committed_as in one cacheline and not cacheline shared with
83339 * other variables. It can be updated by several CPUs frequently.
83340@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
83341 struct vm_area_struct *next = vma->vm_next;
83342
83343 might_sleep();
83344+ BUG_ON(vma->vm_mirror);
83345 if (vma->vm_ops && vma->vm_ops->close)
83346 vma->vm_ops->close(vma);
83347 if (vma->vm_file)
83348@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
83349 * not page aligned -Ram Gupta
83350 */
83351 rlim = rlimit(RLIMIT_DATA);
83352+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
83353 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
83354 (mm->end_data - mm->start_data) > rlim)
83355 goto out;
83356@@ -933,6 +956,12 @@ static int
83357 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
83358 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
83359 {
83360+
83361+#ifdef CONFIG_PAX_SEGMEXEC
83362+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
83363+ return 0;
83364+#endif
83365+
83366 if (is_mergeable_vma(vma, file, vm_flags) &&
83367 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
83368 if (vma->vm_pgoff == vm_pgoff)
83369@@ -952,6 +981,12 @@ static int
83370 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
83371 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
83372 {
83373+
83374+#ifdef CONFIG_PAX_SEGMEXEC
83375+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
83376+ return 0;
83377+#endif
83378+
83379 if (is_mergeable_vma(vma, file, vm_flags) &&
83380 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
83381 pgoff_t vm_pglen;
83382@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
83383 struct vm_area_struct *vma_merge(struct mm_struct *mm,
83384 struct vm_area_struct *prev, unsigned long addr,
83385 unsigned long end, unsigned long vm_flags,
83386- struct anon_vma *anon_vma, struct file *file,
83387+ struct anon_vma *anon_vma, struct file *file,
83388 pgoff_t pgoff, struct mempolicy *policy)
83389 {
83390 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
83391 struct vm_area_struct *area, *next;
83392 int err;
83393
83394+#ifdef CONFIG_PAX_SEGMEXEC
83395+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
83396+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
83397+
83398+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
83399+#endif
83400+
83401 /*
83402 * We later require that vma->vm_flags == vm_flags,
83403 * so this tests vma->vm_flags & VM_SPECIAL, too.
83404@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
83405 if (next && next->vm_end == end) /* cases 6, 7, 8 */
83406 next = next->vm_next;
83407
83408+#ifdef CONFIG_PAX_SEGMEXEC
83409+ if (prev)
83410+ prev_m = pax_find_mirror_vma(prev);
83411+ if (area)
83412+ area_m = pax_find_mirror_vma(area);
83413+ if (next)
83414+ next_m = pax_find_mirror_vma(next);
83415+#endif
83416+
83417 /*
83418 * Can it merge with the predecessor?
83419 */
83420@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
83421 /* cases 1, 6 */
83422 err = vma_adjust(prev, prev->vm_start,
83423 next->vm_end, prev->vm_pgoff, NULL);
83424- } else /* cases 2, 5, 7 */
83425+
83426+#ifdef CONFIG_PAX_SEGMEXEC
83427+ if (!err && prev_m)
83428+ err = vma_adjust(prev_m, prev_m->vm_start,
83429+ next_m->vm_end, prev_m->vm_pgoff, NULL);
83430+#endif
83431+
83432+ } else { /* cases 2, 5, 7 */
83433 err = vma_adjust(prev, prev->vm_start,
83434 end, prev->vm_pgoff, NULL);
83435+
83436+#ifdef CONFIG_PAX_SEGMEXEC
83437+ if (!err && prev_m)
83438+ err = vma_adjust(prev_m, prev_m->vm_start,
83439+ end_m, prev_m->vm_pgoff, NULL);
83440+#endif
83441+
83442+ }
83443 if (err)
83444 return NULL;
83445 khugepaged_enter_vma_merge(prev);
83446@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
83447 mpol_equal(policy, vma_policy(next)) &&
83448 can_vma_merge_before(next, vm_flags,
83449 anon_vma, file, pgoff+pglen)) {
83450- if (prev && addr < prev->vm_end) /* case 4 */
83451+ if (prev && addr < prev->vm_end) { /* case 4 */
83452 err = vma_adjust(prev, prev->vm_start,
83453 addr, prev->vm_pgoff, NULL);
83454- else /* cases 3, 8 */
83455+
83456+#ifdef CONFIG_PAX_SEGMEXEC
83457+ if (!err && prev_m)
83458+ err = vma_adjust(prev_m, prev_m->vm_start,
83459+ addr_m, prev_m->vm_pgoff, NULL);
83460+#endif
83461+
83462+ } else { /* cases 3, 8 */
83463 err = vma_adjust(area, addr, next->vm_end,
83464 next->vm_pgoff - pglen, NULL);
83465+
83466+#ifdef CONFIG_PAX_SEGMEXEC
83467+ if (!err && area_m)
83468+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
83469+ next_m->vm_pgoff - pglen, NULL);
83470+#endif
83471+
83472+ }
83473 if (err)
83474 return NULL;
83475 khugepaged_enter_vma_merge(area);
83476@@ -1165,8 +1246,10 @@ none:
83477 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
83478 struct file *file, long pages)
83479 {
83480- const unsigned long stack_flags
83481- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
83482+
83483+#ifdef CONFIG_PAX_RANDMMAP
83484+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83485+#endif
83486
83487 mm->total_vm += pages;
83488
83489@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
83490 mm->shared_vm += pages;
83491 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
83492 mm->exec_vm += pages;
83493- } else if (flags & stack_flags)
83494+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
83495 mm->stack_vm += pages;
83496 }
83497 #endif /* CONFIG_PROC_FS */
83498@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83499 * (the exception is when the underlying filesystem is noexec
83500 * mounted, in which case we dont add PROT_EXEC.)
83501 */
83502- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83503+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83504 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
83505 prot |= PROT_EXEC;
83506
83507@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83508 /* Obtain the address to map to. we verify (or select) it and ensure
83509 * that it represents a valid section of the address space.
83510 */
83511- addr = get_unmapped_area(file, addr, len, pgoff, flags);
83512+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
83513 if (addr & ~PAGE_MASK)
83514 return addr;
83515
83516@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83517 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
83518 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
83519
83520+#ifdef CONFIG_PAX_MPROTECT
83521+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83522+
83523+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
83524+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
83525+ mm->binfmt->handle_mmap)
83526+ mm->binfmt->handle_mmap(file);
83527+#endif
83528+
83529+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83530+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
83531+ gr_log_rwxmmap(file);
83532+
83533+#ifdef CONFIG_PAX_EMUPLT
83534+ vm_flags &= ~VM_EXEC;
83535+#else
83536+ return -EPERM;
83537+#endif
83538+
83539+ }
83540+
83541+ if (!(vm_flags & VM_EXEC))
83542+ vm_flags &= ~VM_MAYEXEC;
83543+#else
83544+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83545+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83546+#endif
83547+ else
83548+ vm_flags &= ~VM_MAYWRITE;
83549+ }
83550+#endif
83551+
83552+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83553+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
83554+ vm_flags &= ~VM_PAGEEXEC;
83555+#endif
83556+
83557 if (flags & MAP_LOCKED)
83558 if (!can_do_mlock())
83559 return -EPERM;
83560@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83561 locked += mm->locked_vm;
83562 lock_limit = rlimit(RLIMIT_MEMLOCK);
83563 lock_limit >>= PAGE_SHIFT;
83564+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
83565 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
83566 return -EAGAIN;
83567 }
83568@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83569 vm_flags |= VM_NORESERVE;
83570 }
83571
83572+ if (!gr_acl_handle_mmap(file, prot))
83573+ return -EACCES;
83574+
83575 addr = mmap_region(file, addr, len, vm_flags, pgoff);
83576 if (!IS_ERR_VALUE(addr) &&
83577 ((vm_flags & VM_LOCKED) ||
83578@@ -1432,7 +1556,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
83579 vm_flags_t vm_flags = vma->vm_flags;
83580
83581 /* If it was private or non-writable, the write bit is already clear */
83582- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
83583+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
83584 return 0;
83585
83586 /* The backer wishes to know when pages are first written to? */
83587@@ -1480,7 +1604,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
83588 unsigned long charged = 0;
83589 struct inode *inode = file ? file_inode(file) : NULL;
83590
83591+#ifdef CONFIG_PAX_SEGMEXEC
83592+ struct vm_area_struct *vma_m = NULL;
83593+#endif
83594+
83595+ /*
83596+ * mm->mmap_sem is required to protect against another thread
83597+ * changing the mappings in case we sleep.
83598+ */
83599+ verify_mm_writelocked(mm);
83600+
83601 /* Check against address space limit. */
83602+
83603+#ifdef CONFIG_PAX_RANDMMAP
83604+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83605+#endif
83606+
83607 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
83608 unsigned long nr_pages;
83609
83610@@ -1499,11 +1638,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
83611
83612 /* Clear old maps */
83613 error = -ENOMEM;
83614-munmap_back:
83615 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83616 if (do_munmap(mm, addr, len))
83617 return -ENOMEM;
83618- goto munmap_back;
83619+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83620 }
83621
83622 /*
83623@@ -1534,6 +1672,16 @@ munmap_back:
83624 goto unacct_error;
83625 }
83626
83627+#ifdef CONFIG_PAX_SEGMEXEC
83628+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
83629+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83630+ if (!vma_m) {
83631+ error = -ENOMEM;
83632+ goto free_vma;
83633+ }
83634+ }
83635+#endif
83636+
83637 vma->vm_mm = mm;
83638 vma->vm_start = addr;
83639 vma->vm_end = addr + len;
83640@@ -1558,6 +1706,13 @@ munmap_back:
83641 if (error)
83642 goto unmap_and_free_vma;
83643
83644+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83645+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
83646+ vma->vm_flags |= VM_PAGEEXEC;
83647+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83648+ }
83649+#endif
83650+
83651 /* Can addr have changed??
83652 *
83653 * Answer: Yes, several device drivers can do it in their
83654@@ -1596,6 +1751,11 @@ munmap_back:
83655 vma_link(mm, vma, prev, rb_link, rb_parent);
83656 file = vma->vm_file;
83657
83658+#ifdef CONFIG_PAX_SEGMEXEC
83659+ if (vma_m)
83660+ BUG_ON(pax_mirror_vma(vma_m, vma));
83661+#endif
83662+
83663 /* Once vma denies write, undo our temporary denial count */
83664 if (correct_wcount)
83665 atomic_inc(&inode->i_writecount);
83666@@ -1603,6 +1763,7 @@ out:
83667 perf_event_mmap(vma);
83668
83669 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
83670+ track_exec_limit(mm, addr, addr + len, vm_flags);
83671 if (vm_flags & VM_LOCKED) {
83672 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
83673 vma == get_gate_vma(current->mm)))
83674@@ -1626,6 +1787,12 @@ unmap_and_free_vma:
83675 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
83676 charged = 0;
83677 free_vma:
83678+
83679+#ifdef CONFIG_PAX_SEGMEXEC
83680+ if (vma_m)
83681+ kmem_cache_free(vm_area_cachep, vma_m);
83682+#endif
83683+
83684 kmem_cache_free(vm_area_cachep, vma);
83685 unacct_error:
83686 if (charged)
83687@@ -1633,7 +1800,63 @@ unacct_error:
83688 return error;
83689 }
83690
83691-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
83692+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
83693+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
83694+{
83695+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
83696+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
83697+
83698+ return 0;
83699+}
83700+#endif
83701+
83702+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
83703+{
83704+ if (!vma) {
83705+#ifdef CONFIG_STACK_GROWSUP
83706+ if (addr > sysctl_heap_stack_gap)
83707+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
83708+ else
83709+ vma = find_vma(current->mm, 0);
83710+ if (vma && (vma->vm_flags & VM_GROWSUP))
83711+ return false;
83712+#endif
83713+ return true;
83714+ }
83715+
83716+ if (addr + len > vma->vm_start)
83717+ return false;
83718+
83719+ if (vma->vm_flags & VM_GROWSDOWN)
83720+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
83721+#ifdef CONFIG_STACK_GROWSUP
83722+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
83723+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
83724+#endif
83725+ else if (offset)
83726+ return offset <= vma->vm_start - addr - len;
83727+
83728+ return true;
83729+}
83730+
83731+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
83732+{
83733+ if (vma->vm_start < len)
83734+ return -ENOMEM;
83735+
83736+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
83737+ if (offset <= vma->vm_start - len)
83738+ return vma->vm_start - len - offset;
83739+ else
83740+ return -ENOMEM;
83741+ }
83742+
83743+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
83744+ return vma->vm_start - len - sysctl_heap_stack_gap;
83745+ return -ENOMEM;
83746+}
83747+
83748+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
83749 {
83750 /*
83751 * We implement the search by looking for an rbtree node that
83752@@ -1681,11 +1904,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
83753 }
83754 }
83755
83756- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
83757+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
83758 check_current:
83759 /* Check if current node has a suitable gap */
83760 if (gap_start > high_limit)
83761 return -ENOMEM;
83762+
83763+ if (gap_end - gap_start > info->threadstack_offset)
83764+ gap_start += info->threadstack_offset;
83765+ else
83766+ gap_start = gap_end;
83767+
83768+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
83769+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83770+ gap_start += sysctl_heap_stack_gap;
83771+ else
83772+ gap_start = gap_end;
83773+ }
83774+ if (vma->vm_flags & VM_GROWSDOWN) {
83775+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83776+ gap_end -= sysctl_heap_stack_gap;
83777+ else
83778+ gap_end = gap_start;
83779+ }
83780 if (gap_end >= low_limit && gap_end - gap_start >= length)
83781 goto found;
83782
83783@@ -1735,7 +1976,7 @@ found:
83784 return gap_start;
83785 }
83786
83787-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
83788+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
83789 {
83790 struct mm_struct *mm = current->mm;
83791 struct vm_area_struct *vma;
83792@@ -1789,6 +2030,24 @@ check_current:
83793 gap_end = vma->vm_start;
83794 if (gap_end < low_limit)
83795 return -ENOMEM;
83796+
83797+ if (gap_end - gap_start > info->threadstack_offset)
83798+ gap_end -= info->threadstack_offset;
83799+ else
83800+ gap_end = gap_start;
83801+
83802+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
83803+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83804+ gap_start += sysctl_heap_stack_gap;
83805+ else
83806+ gap_start = gap_end;
83807+ }
83808+ if (vma->vm_flags & VM_GROWSDOWN) {
83809+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83810+ gap_end -= sysctl_heap_stack_gap;
83811+ else
83812+ gap_end = gap_start;
83813+ }
83814 if (gap_start <= high_limit && gap_end - gap_start >= length)
83815 goto found;
83816
83817@@ -1852,6 +2111,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83818 struct mm_struct *mm = current->mm;
83819 struct vm_area_struct *vma;
83820 struct vm_unmapped_area_info info;
83821+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83822
83823 if (len > TASK_SIZE)
83824 return -ENOMEM;
83825@@ -1859,29 +2119,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83826 if (flags & MAP_FIXED)
83827 return addr;
83828
83829+#ifdef CONFIG_PAX_RANDMMAP
83830+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83831+#endif
83832+
83833 if (addr) {
83834 addr = PAGE_ALIGN(addr);
83835 vma = find_vma(mm, addr);
83836- if (TASK_SIZE - len >= addr &&
83837- (!vma || addr + len <= vma->vm_start))
83838+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83839 return addr;
83840 }
83841
83842 info.flags = 0;
83843 info.length = len;
83844 info.low_limit = TASK_UNMAPPED_BASE;
83845+
83846+#ifdef CONFIG_PAX_RANDMMAP
83847+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83848+ info.low_limit += mm->delta_mmap;
83849+#endif
83850+
83851 info.high_limit = TASK_SIZE;
83852 info.align_mask = 0;
83853+ info.threadstack_offset = offset;
83854 return vm_unmapped_area(&info);
83855 }
83856 #endif
83857
83858 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
83859 {
83860+
83861+#ifdef CONFIG_PAX_SEGMEXEC
83862+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83863+ return;
83864+#endif
83865+
83866 /*
83867 * Is this a new hole at the lowest possible address?
83868 */
83869- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
83870+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
83871 mm->free_area_cache = addr;
83872 }
83873
83874@@ -1899,6 +2175,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83875 struct mm_struct *mm = current->mm;
83876 unsigned long addr = addr0;
83877 struct vm_unmapped_area_info info;
83878+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83879
83880 /* requested length too big for entire address space */
83881 if (len > TASK_SIZE)
83882@@ -1907,12 +2184,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83883 if (flags & MAP_FIXED)
83884 return addr;
83885
83886+#ifdef CONFIG_PAX_RANDMMAP
83887+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83888+#endif
83889+
83890 /* requesting a specific address */
83891 if (addr) {
83892 addr = PAGE_ALIGN(addr);
83893 vma = find_vma(mm, addr);
83894- if (TASK_SIZE - len >= addr &&
83895- (!vma || addr + len <= vma->vm_start))
83896+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83897 return addr;
83898 }
83899
83900@@ -1921,6 +2201,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83901 info.low_limit = PAGE_SIZE;
83902 info.high_limit = mm->mmap_base;
83903 info.align_mask = 0;
83904+ info.threadstack_offset = offset;
83905 addr = vm_unmapped_area(&info);
83906
83907 /*
83908@@ -1933,6 +2214,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83909 VM_BUG_ON(addr != -ENOMEM);
83910 info.flags = 0;
83911 info.low_limit = TASK_UNMAPPED_BASE;
83912+
83913+#ifdef CONFIG_PAX_RANDMMAP
83914+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83915+ info.low_limit += mm->delta_mmap;
83916+#endif
83917+
83918 info.high_limit = TASK_SIZE;
83919 addr = vm_unmapped_area(&info);
83920 }
83921@@ -1943,6 +2230,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83922
83923 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83924 {
83925+
83926+#ifdef CONFIG_PAX_SEGMEXEC
83927+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83928+ return;
83929+#endif
83930+
83931 /*
83932 * Is this a new hole at the highest possible address?
83933 */
83934@@ -1950,8 +2243,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83935 mm->free_area_cache = addr;
83936
83937 /* dont allow allocations above current base */
83938- if (mm->free_area_cache > mm->mmap_base)
83939+ if (mm->free_area_cache > mm->mmap_base) {
83940 mm->free_area_cache = mm->mmap_base;
83941+ mm->cached_hole_size = ~0UL;
83942+ }
83943 }
83944
83945 unsigned long
83946@@ -2047,6 +2342,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
83947 return vma;
83948 }
83949
83950+#ifdef CONFIG_PAX_SEGMEXEC
83951+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
83952+{
83953+ struct vm_area_struct *vma_m;
83954+
83955+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
83956+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
83957+ BUG_ON(vma->vm_mirror);
83958+ return NULL;
83959+ }
83960+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
83961+ vma_m = vma->vm_mirror;
83962+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
83963+ BUG_ON(vma->vm_file != vma_m->vm_file);
83964+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
83965+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
83966+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
83967+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
83968+ return vma_m;
83969+}
83970+#endif
83971+
83972 /*
83973 * Verify that the stack growth is acceptable and
83974 * update accounting. This is shared with both the
83975@@ -2063,6 +2380,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83976 return -ENOMEM;
83977
83978 /* Stack limit test */
83979+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
83980 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
83981 return -ENOMEM;
83982
83983@@ -2073,6 +2391,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83984 locked = mm->locked_vm + grow;
83985 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
83986 limit >>= PAGE_SHIFT;
83987+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
83988 if (locked > limit && !capable(CAP_IPC_LOCK))
83989 return -ENOMEM;
83990 }
83991@@ -2102,37 +2421,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83992 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
83993 * vma is the last one with address > vma->vm_end. Have to extend vma.
83994 */
83995+#ifndef CONFIG_IA64
83996+static
83997+#endif
83998 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83999 {
84000 int error;
84001+ bool locknext;
84002
84003 if (!(vma->vm_flags & VM_GROWSUP))
84004 return -EFAULT;
84005
84006+ /* Also guard against wrapping around to address 0. */
84007+ if (address < PAGE_ALIGN(address+1))
84008+ address = PAGE_ALIGN(address+1);
84009+ else
84010+ return -ENOMEM;
84011+
84012 /*
84013 * We must make sure the anon_vma is allocated
84014 * so that the anon_vma locking is not a noop.
84015 */
84016 if (unlikely(anon_vma_prepare(vma)))
84017 return -ENOMEM;
84018+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
84019+ if (locknext && anon_vma_prepare(vma->vm_next))
84020+ return -ENOMEM;
84021 vma_lock_anon_vma(vma);
84022+ if (locknext)
84023+ vma_lock_anon_vma(vma->vm_next);
84024
84025 /*
84026 * vma->vm_start/vm_end cannot change under us because the caller
84027 * is required to hold the mmap_sem in read mode. We need the
84028- * anon_vma lock to serialize against concurrent expand_stacks.
84029- * Also guard against wrapping around to address 0.
84030+ * anon_vma locks to serialize against concurrent expand_stacks
84031+ * and expand_upwards.
84032 */
84033- if (address < PAGE_ALIGN(address+4))
84034- address = PAGE_ALIGN(address+4);
84035- else {
84036- vma_unlock_anon_vma(vma);
84037- return -ENOMEM;
84038- }
84039 error = 0;
84040
84041 /* Somebody else might have raced and expanded it already */
84042- if (address > vma->vm_end) {
84043+ 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)
84044+ error = -ENOMEM;
84045+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
84046 unsigned long size, grow;
84047
84048 size = address - vma->vm_start;
84049@@ -2167,6 +2497,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
84050 }
84051 }
84052 }
84053+ if (locknext)
84054+ vma_unlock_anon_vma(vma->vm_next);
84055 vma_unlock_anon_vma(vma);
84056 khugepaged_enter_vma_merge(vma);
84057 validate_mm(vma->vm_mm);
84058@@ -2181,6 +2513,8 @@ int expand_downwards(struct vm_area_struct *vma,
84059 unsigned long address)
84060 {
84061 int error;
84062+ bool lockprev = false;
84063+ struct vm_area_struct *prev;
84064
84065 /*
84066 * We must make sure the anon_vma is allocated
84067@@ -2194,6 +2528,15 @@ int expand_downwards(struct vm_area_struct *vma,
84068 if (error)
84069 return error;
84070
84071+ prev = vma->vm_prev;
84072+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
84073+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
84074+#endif
84075+ if (lockprev && anon_vma_prepare(prev))
84076+ return -ENOMEM;
84077+ if (lockprev)
84078+ vma_lock_anon_vma(prev);
84079+
84080 vma_lock_anon_vma(vma);
84081
84082 /*
84083@@ -2203,9 +2546,17 @@ int expand_downwards(struct vm_area_struct *vma,
84084 */
84085
84086 /* Somebody else might have raced and expanded it already */
84087- if (address < vma->vm_start) {
84088+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
84089+ error = -ENOMEM;
84090+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
84091 unsigned long size, grow;
84092
84093+#ifdef CONFIG_PAX_SEGMEXEC
84094+ struct vm_area_struct *vma_m;
84095+
84096+ vma_m = pax_find_mirror_vma(vma);
84097+#endif
84098+
84099 size = vma->vm_end - address;
84100 grow = (vma->vm_start - address) >> PAGE_SHIFT;
84101
84102@@ -2230,13 +2581,27 @@ int expand_downwards(struct vm_area_struct *vma,
84103 vma->vm_pgoff -= grow;
84104 anon_vma_interval_tree_post_update_vma(vma);
84105 vma_gap_update(vma);
84106+
84107+#ifdef CONFIG_PAX_SEGMEXEC
84108+ if (vma_m) {
84109+ anon_vma_interval_tree_pre_update_vma(vma_m);
84110+ vma_m->vm_start -= grow << PAGE_SHIFT;
84111+ vma_m->vm_pgoff -= grow;
84112+ anon_vma_interval_tree_post_update_vma(vma_m);
84113+ vma_gap_update(vma_m);
84114+ }
84115+#endif
84116+
84117 spin_unlock(&vma->vm_mm->page_table_lock);
84118
84119+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
84120 perf_event_mmap(vma);
84121 }
84122 }
84123 }
84124 vma_unlock_anon_vma(vma);
84125+ if (lockprev)
84126+ vma_unlock_anon_vma(prev);
84127 khugepaged_enter_vma_merge(vma);
84128 validate_mm(vma->vm_mm);
84129 return error;
84130@@ -2334,6 +2699,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
84131 do {
84132 long nrpages = vma_pages(vma);
84133
84134+#ifdef CONFIG_PAX_SEGMEXEC
84135+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
84136+ vma = remove_vma(vma);
84137+ continue;
84138+ }
84139+#endif
84140+
84141 if (vma->vm_flags & VM_ACCOUNT)
84142 nr_accounted += nrpages;
84143 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
84144@@ -2379,6 +2751,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
84145 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
84146 vma->vm_prev = NULL;
84147 do {
84148+
84149+#ifdef CONFIG_PAX_SEGMEXEC
84150+ if (vma->vm_mirror) {
84151+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
84152+ vma->vm_mirror->vm_mirror = NULL;
84153+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
84154+ vma->vm_mirror = NULL;
84155+ }
84156+#endif
84157+
84158 vma_rb_erase(vma, &mm->mm_rb);
84159 mm->map_count--;
84160 tail_vma = vma;
84161@@ -2410,14 +2792,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
84162 struct vm_area_struct *new;
84163 int err = -ENOMEM;
84164
84165+#ifdef CONFIG_PAX_SEGMEXEC
84166+ struct vm_area_struct *vma_m, *new_m = NULL;
84167+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
84168+#endif
84169+
84170 if (is_vm_hugetlb_page(vma) && (addr &
84171 ~(huge_page_mask(hstate_vma(vma)))))
84172 return -EINVAL;
84173
84174+#ifdef CONFIG_PAX_SEGMEXEC
84175+ vma_m = pax_find_mirror_vma(vma);
84176+#endif
84177+
84178 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84179 if (!new)
84180 goto out_err;
84181
84182+#ifdef CONFIG_PAX_SEGMEXEC
84183+ if (vma_m) {
84184+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84185+ if (!new_m) {
84186+ kmem_cache_free(vm_area_cachep, new);
84187+ goto out_err;
84188+ }
84189+ }
84190+#endif
84191+
84192 /* most fields are the same, copy all, and then fixup */
84193 *new = *vma;
84194
84195@@ -2430,6 +2831,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
84196 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
84197 }
84198
84199+#ifdef CONFIG_PAX_SEGMEXEC
84200+ if (vma_m) {
84201+ *new_m = *vma_m;
84202+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
84203+ new_m->vm_mirror = new;
84204+ new->vm_mirror = new_m;
84205+
84206+ if (new_below)
84207+ new_m->vm_end = addr_m;
84208+ else {
84209+ new_m->vm_start = addr_m;
84210+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
84211+ }
84212+ }
84213+#endif
84214+
84215 pol = mpol_dup(vma_policy(vma));
84216 if (IS_ERR(pol)) {
84217 err = PTR_ERR(pol);
84218@@ -2452,6 +2869,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
84219 else
84220 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
84221
84222+#ifdef CONFIG_PAX_SEGMEXEC
84223+ if (!err && vma_m) {
84224+ if (anon_vma_clone(new_m, vma_m))
84225+ goto out_free_mpol;
84226+
84227+ mpol_get(pol);
84228+ vma_set_policy(new_m, pol);
84229+
84230+ if (new_m->vm_file)
84231+ get_file(new_m->vm_file);
84232+
84233+ if (new_m->vm_ops && new_m->vm_ops->open)
84234+ new_m->vm_ops->open(new_m);
84235+
84236+ if (new_below)
84237+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
84238+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
84239+ else
84240+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
84241+
84242+ if (err) {
84243+ if (new_m->vm_ops && new_m->vm_ops->close)
84244+ new_m->vm_ops->close(new_m);
84245+ if (new_m->vm_file)
84246+ fput(new_m->vm_file);
84247+ mpol_put(pol);
84248+ }
84249+ }
84250+#endif
84251+
84252 /* Success. */
84253 if (!err)
84254 return 0;
84255@@ -2461,10 +2908,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
84256 new->vm_ops->close(new);
84257 if (new->vm_file)
84258 fput(new->vm_file);
84259- unlink_anon_vmas(new);
84260 out_free_mpol:
84261 mpol_put(pol);
84262 out_free_vma:
84263+
84264+#ifdef CONFIG_PAX_SEGMEXEC
84265+ if (new_m) {
84266+ unlink_anon_vmas(new_m);
84267+ kmem_cache_free(vm_area_cachep, new_m);
84268+ }
84269+#endif
84270+
84271+ unlink_anon_vmas(new);
84272 kmem_cache_free(vm_area_cachep, new);
84273 out_err:
84274 return err;
84275@@ -2477,6 +2932,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
84276 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
84277 unsigned long addr, int new_below)
84278 {
84279+
84280+#ifdef CONFIG_PAX_SEGMEXEC
84281+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
84282+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
84283+ if (mm->map_count >= sysctl_max_map_count-1)
84284+ return -ENOMEM;
84285+ } else
84286+#endif
84287+
84288 if (mm->map_count >= sysctl_max_map_count)
84289 return -ENOMEM;
84290
84291@@ -2488,11 +2952,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
84292 * work. This now handles partial unmappings.
84293 * Jeremy Fitzhardinge <jeremy@goop.org>
84294 */
84295+#ifdef CONFIG_PAX_SEGMEXEC
84296 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
84297 {
84298+ int ret = __do_munmap(mm, start, len);
84299+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
84300+ return ret;
84301+
84302+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
84303+}
84304+
84305+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
84306+#else
84307+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
84308+#endif
84309+{
84310 unsigned long end;
84311 struct vm_area_struct *vma, *prev, *last;
84312
84313+ /*
84314+ * mm->mmap_sem is required to protect against another thread
84315+ * changing the mappings in case we sleep.
84316+ */
84317+ verify_mm_writelocked(mm);
84318+
84319 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
84320 return -EINVAL;
84321
84322@@ -2567,6 +3050,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
84323 /* Fix up all other VM information */
84324 remove_vma_list(mm, vma);
84325
84326+ track_exec_limit(mm, start, end, 0UL);
84327+
84328 return 0;
84329 }
84330
84331@@ -2575,6 +3060,13 @@ int vm_munmap(unsigned long start, size_t len)
84332 int ret;
84333 struct mm_struct *mm = current->mm;
84334
84335+
84336+#ifdef CONFIG_PAX_SEGMEXEC
84337+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
84338+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
84339+ return -EINVAL;
84340+#endif
84341+
84342 down_write(&mm->mmap_sem);
84343 ret = do_munmap(mm, start, len);
84344 up_write(&mm->mmap_sem);
84345@@ -2588,16 +3080,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
84346 return vm_munmap(addr, len);
84347 }
84348
84349-static inline void verify_mm_writelocked(struct mm_struct *mm)
84350-{
84351-#ifdef CONFIG_DEBUG_VM
84352- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
84353- WARN_ON(1);
84354- up_read(&mm->mmap_sem);
84355- }
84356-#endif
84357-}
84358-
84359 /*
84360 * this is really a simplified "do_mmap". it only handles
84361 * anonymous maps. eventually we may be able to do some
84362@@ -2611,6 +3093,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
84363 struct rb_node ** rb_link, * rb_parent;
84364 pgoff_t pgoff = addr >> PAGE_SHIFT;
84365 int error;
84366+ unsigned long charged;
84367
84368 len = PAGE_ALIGN(len);
84369 if (!len)
84370@@ -2618,16 +3101,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
84371
84372 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
84373
84374+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
84375+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
84376+ flags &= ~VM_EXEC;
84377+
84378+#ifdef CONFIG_PAX_MPROTECT
84379+ if (mm->pax_flags & MF_PAX_MPROTECT)
84380+ flags &= ~VM_MAYEXEC;
84381+#endif
84382+
84383+ }
84384+#endif
84385+
84386 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
84387 if (error & ~PAGE_MASK)
84388 return error;
84389
84390+ charged = len >> PAGE_SHIFT;
84391+
84392 /*
84393 * mlock MCL_FUTURE?
84394 */
84395 if (mm->def_flags & VM_LOCKED) {
84396 unsigned long locked, lock_limit;
84397- locked = len >> PAGE_SHIFT;
84398+ locked = charged;
84399 locked += mm->locked_vm;
84400 lock_limit = rlimit(RLIMIT_MEMLOCK);
84401 lock_limit >>= PAGE_SHIFT;
84402@@ -2644,21 +3141,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
84403 /*
84404 * Clear old maps. this also does some error checking for us
84405 */
84406- munmap_back:
84407 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
84408 if (do_munmap(mm, addr, len))
84409 return -ENOMEM;
84410- goto munmap_back;
84411+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
84412 }
84413
84414 /* Check against address space limits *after* clearing old maps... */
84415- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
84416+ if (!may_expand_vm(mm, charged))
84417 return -ENOMEM;
84418
84419 if (mm->map_count > sysctl_max_map_count)
84420 return -ENOMEM;
84421
84422- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
84423+ if (security_vm_enough_memory_mm(mm, charged))
84424 return -ENOMEM;
84425
84426 /* Can we just expand an old private anonymous mapping? */
84427@@ -2672,7 +3168,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
84428 */
84429 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
84430 if (!vma) {
84431- vm_unacct_memory(len >> PAGE_SHIFT);
84432+ vm_unacct_memory(charged);
84433 return -ENOMEM;
84434 }
84435
84436@@ -2686,9 +3182,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
84437 vma_link(mm, vma, prev, rb_link, rb_parent);
84438 out:
84439 perf_event_mmap(vma);
84440- mm->total_vm += len >> PAGE_SHIFT;
84441+ mm->total_vm += charged;
84442 if (flags & VM_LOCKED)
84443- mm->locked_vm += (len >> PAGE_SHIFT);
84444+ mm->locked_vm += charged;
84445+ track_exec_limit(mm, addr, addr + len, flags);
84446 return addr;
84447 }
84448
84449@@ -2750,6 +3247,7 @@ void exit_mmap(struct mm_struct *mm)
84450 while (vma) {
84451 if (vma->vm_flags & VM_ACCOUNT)
84452 nr_accounted += vma_pages(vma);
84453+ vma->vm_mirror = NULL;
84454 vma = remove_vma(vma);
84455 }
84456 vm_unacct_memory(nr_accounted);
84457@@ -2766,6 +3264,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
84458 struct vm_area_struct *prev;
84459 struct rb_node **rb_link, *rb_parent;
84460
84461+#ifdef CONFIG_PAX_SEGMEXEC
84462+ struct vm_area_struct *vma_m = NULL;
84463+#endif
84464+
84465+ if (security_mmap_addr(vma->vm_start))
84466+ return -EPERM;
84467+
84468 /*
84469 * The vm_pgoff of a purely anonymous vma should be irrelevant
84470 * until its first write fault, when page's anon_vma and index
84471@@ -2789,7 +3294,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
84472 security_vm_enough_memory_mm(mm, vma_pages(vma)))
84473 return -ENOMEM;
84474
84475+#ifdef CONFIG_PAX_SEGMEXEC
84476+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
84477+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
84478+ if (!vma_m)
84479+ return -ENOMEM;
84480+ }
84481+#endif
84482+
84483 vma_link(mm, vma, prev, rb_link, rb_parent);
84484+
84485+#ifdef CONFIG_PAX_SEGMEXEC
84486+ if (vma_m)
84487+ BUG_ON(pax_mirror_vma(vma_m, vma));
84488+#endif
84489+
84490 return 0;
84491 }
84492
84493@@ -2809,6 +3328,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
84494 struct mempolicy *pol;
84495 bool faulted_in_anon_vma = true;
84496
84497+ BUG_ON(vma->vm_mirror);
84498+
84499 /*
84500 * If anonymous vma has not yet been faulted, update new pgoff
84501 * to match new location, to increase its chance of merging.
84502@@ -2875,6 +3396,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
84503 return NULL;
84504 }
84505
84506+#ifdef CONFIG_PAX_SEGMEXEC
84507+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
84508+{
84509+ struct vm_area_struct *prev_m;
84510+ struct rb_node **rb_link_m, *rb_parent_m;
84511+ struct mempolicy *pol_m;
84512+
84513+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
84514+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
84515+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
84516+ *vma_m = *vma;
84517+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
84518+ if (anon_vma_clone(vma_m, vma))
84519+ return -ENOMEM;
84520+ pol_m = vma_policy(vma_m);
84521+ mpol_get(pol_m);
84522+ vma_set_policy(vma_m, pol_m);
84523+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
84524+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
84525+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
84526+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
84527+ if (vma_m->vm_file)
84528+ get_file(vma_m->vm_file);
84529+ if (vma_m->vm_ops && vma_m->vm_ops->open)
84530+ vma_m->vm_ops->open(vma_m);
84531+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
84532+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
84533+ vma_m->vm_mirror = vma;
84534+ vma->vm_mirror = vma_m;
84535+ return 0;
84536+}
84537+#endif
84538+
84539 /*
84540 * Return true if the calling process may expand its vm space by the passed
84541 * number of pages
84542@@ -2886,6 +3440,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
84543
84544 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
84545
84546+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
84547 if (cur + npages > lim)
84548 return 0;
84549 return 1;
84550@@ -2956,6 +3511,22 @@ int install_special_mapping(struct mm_struct *mm,
84551 vma->vm_start = addr;
84552 vma->vm_end = addr + len;
84553
84554+#ifdef CONFIG_PAX_MPROTECT
84555+ if (mm->pax_flags & MF_PAX_MPROTECT) {
84556+#ifndef CONFIG_PAX_MPROTECT_COMPAT
84557+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
84558+ return -EPERM;
84559+ if (!(vm_flags & VM_EXEC))
84560+ vm_flags &= ~VM_MAYEXEC;
84561+#else
84562+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
84563+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
84564+#endif
84565+ else
84566+ vm_flags &= ~VM_MAYWRITE;
84567+ }
84568+#endif
84569+
84570 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
84571 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
84572
84573diff --git a/mm/mprotect.c b/mm/mprotect.c
84574index 94722a4..e661e29 100644
84575--- a/mm/mprotect.c
84576+++ b/mm/mprotect.c
84577@@ -23,10 +23,18 @@
84578 #include <linux/mmu_notifier.h>
84579 #include <linux/migrate.h>
84580 #include <linux/perf_event.h>
84581+#include <linux/sched/sysctl.h>
84582+
84583+#ifdef CONFIG_PAX_MPROTECT
84584+#include <linux/elf.h>
84585+#include <linux/binfmts.h>
84586+#endif
84587+
84588 #include <asm/uaccess.h>
84589 #include <asm/pgtable.h>
84590 #include <asm/cacheflush.h>
84591 #include <asm/tlbflush.h>
84592+#include <asm/mmu_context.h>
84593
84594 #ifndef pgprot_modify
84595 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
84596@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
84597 return pages;
84598 }
84599
84600+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84601+/* called while holding the mmap semaphor for writing except stack expansion */
84602+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
84603+{
84604+ unsigned long oldlimit, newlimit = 0UL;
84605+
84606+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
84607+ return;
84608+
84609+ spin_lock(&mm->page_table_lock);
84610+ oldlimit = mm->context.user_cs_limit;
84611+ if ((prot & VM_EXEC) && oldlimit < end)
84612+ /* USER_CS limit moved up */
84613+ newlimit = end;
84614+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
84615+ /* USER_CS limit moved down */
84616+ newlimit = start;
84617+
84618+ if (newlimit) {
84619+ mm->context.user_cs_limit = newlimit;
84620+
84621+#ifdef CONFIG_SMP
84622+ wmb();
84623+ cpus_clear(mm->context.cpu_user_cs_mask);
84624+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
84625+#endif
84626+
84627+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
84628+ }
84629+ spin_unlock(&mm->page_table_lock);
84630+ if (newlimit == end) {
84631+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
84632+
84633+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
84634+ if (is_vm_hugetlb_page(vma))
84635+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
84636+ else
84637+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
84638+ }
84639+}
84640+#endif
84641+
84642 int
84643 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
84644 unsigned long start, unsigned long end, unsigned long newflags)
84645@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
84646 int error;
84647 int dirty_accountable = 0;
84648
84649+#ifdef CONFIG_PAX_SEGMEXEC
84650+ struct vm_area_struct *vma_m = NULL;
84651+ unsigned long start_m, end_m;
84652+
84653+ start_m = start + SEGMEXEC_TASK_SIZE;
84654+ end_m = end + SEGMEXEC_TASK_SIZE;
84655+#endif
84656+
84657 if (newflags == oldflags) {
84658 *pprev = vma;
84659 return 0;
84660 }
84661
84662+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
84663+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
84664+
84665+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
84666+ return -ENOMEM;
84667+
84668+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
84669+ return -ENOMEM;
84670+ }
84671+
84672 /*
84673 * If we make a private mapping writable we increase our commit;
84674 * but (without finer accounting) cannot reduce our commit if we
84675@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
84676 }
84677 }
84678
84679+#ifdef CONFIG_PAX_SEGMEXEC
84680+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
84681+ if (start != vma->vm_start) {
84682+ error = split_vma(mm, vma, start, 1);
84683+ if (error)
84684+ goto fail;
84685+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
84686+ *pprev = (*pprev)->vm_next;
84687+ }
84688+
84689+ if (end != vma->vm_end) {
84690+ error = split_vma(mm, vma, end, 0);
84691+ if (error)
84692+ goto fail;
84693+ }
84694+
84695+ if (pax_find_mirror_vma(vma)) {
84696+ error = __do_munmap(mm, start_m, end_m - start_m);
84697+ if (error)
84698+ goto fail;
84699+ } else {
84700+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
84701+ if (!vma_m) {
84702+ error = -ENOMEM;
84703+ goto fail;
84704+ }
84705+ vma->vm_flags = newflags;
84706+ error = pax_mirror_vma(vma_m, vma);
84707+ if (error) {
84708+ vma->vm_flags = oldflags;
84709+ goto fail;
84710+ }
84711+ }
84712+ }
84713+#endif
84714+
84715 /*
84716 * First try to merge with previous and/or next vma.
84717 */
84718@@ -296,9 +400,21 @@ success:
84719 * vm_flags and vm_page_prot are protected by the mmap_sem
84720 * held in write mode.
84721 */
84722+
84723+#ifdef CONFIG_PAX_SEGMEXEC
84724+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
84725+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
84726+#endif
84727+
84728 vma->vm_flags = newflags;
84729+
84730+#ifdef CONFIG_PAX_MPROTECT
84731+ if (mm->binfmt && mm->binfmt->handle_mprotect)
84732+ mm->binfmt->handle_mprotect(vma, newflags);
84733+#endif
84734+
84735 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
84736- vm_get_page_prot(newflags));
84737+ vm_get_page_prot(vma->vm_flags));
84738
84739 if (vma_wants_writenotify(vma)) {
84740 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
84741@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84742 end = start + len;
84743 if (end <= start)
84744 return -ENOMEM;
84745+
84746+#ifdef CONFIG_PAX_SEGMEXEC
84747+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
84748+ if (end > SEGMEXEC_TASK_SIZE)
84749+ return -EINVAL;
84750+ } else
84751+#endif
84752+
84753+ if (end > TASK_SIZE)
84754+ return -EINVAL;
84755+
84756 if (!arch_validate_prot(prot))
84757 return -EINVAL;
84758
84759@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84760 /*
84761 * Does the application expect PROT_READ to imply PROT_EXEC:
84762 */
84763- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
84764+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
84765 prot |= PROT_EXEC;
84766
84767 vm_flags = calc_vm_prot_bits(prot);
84768@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84769 if (start > vma->vm_start)
84770 prev = vma;
84771
84772+#ifdef CONFIG_PAX_MPROTECT
84773+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
84774+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
84775+#endif
84776+
84777 for (nstart = start ; ; ) {
84778 unsigned long newflags;
84779
84780@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84781
84782 /* newflags >> 4 shift VM_MAY% in place of VM_% */
84783 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
84784+ if (prot & (PROT_WRITE | PROT_EXEC))
84785+ gr_log_rwxmprotect(vma);
84786+
84787+ error = -EACCES;
84788+ goto out;
84789+ }
84790+
84791+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
84792 error = -EACCES;
84793 goto out;
84794 }
84795@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84796 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
84797 if (error)
84798 goto out;
84799+
84800+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
84801+
84802 nstart = tmp;
84803
84804 if (nstart < prev->vm_end)
84805diff --git a/mm/mremap.c b/mm/mremap.c
84806index 463a257..c0c7a92 100644
84807--- a/mm/mremap.c
84808+++ b/mm/mremap.c
84809@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
84810 continue;
84811 pte = ptep_get_and_clear(mm, old_addr, old_pte);
84812 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
84813+
84814+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84815+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
84816+ pte = pte_exprotect(pte);
84817+#endif
84818+
84819 set_pte_at(mm, new_addr, new_pte, pte);
84820 }
84821
84822@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
84823 if (is_vm_hugetlb_page(vma))
84824 goto Einval;
84825
84826+#ifdef CONFIG_PAX_SEGMEXEC
84827+ if (pax_find_mirror_vma(vma))
84828+ goto Einval;
84829+#endif
84830+
84831 /* We can't remap across vm area boundaries */
84832 if (old_len > vma->vm_end - addr)
84833 goto Efault;
84834@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
84835 unsigned long ret = -EINVAL;
84836 unsigned long charged = 0;
84837 unsigned long map_flags;
84838+ unsigned long pax_task_size = TASK_SIZE;
84839
84840 if (new_addr & ~PAGE_MASK)
84841 goto out;
84842
84843- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
84844+#ifdef CONFIG_PAX_SEGMEXEC
84845+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84846+ pax_task_size = SEGMEXEC_TASK_SIZE;
84847+#endif
84848+
84849+ pax_task_size -= PAGE_SIZE;
84850+
84851+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
84852 goto out;
84853
84854 /* Check if the location we're moving into overlaps the
84855 * old location at all, and fail if it does.
84856 */
84857- if ((new_addr <= addr) && (new_addr+new_len) > addr)
84858- goto out;
84859-
84860- if ((addr <= new_addr) && (addr+old_len) > new_addr)
84861+ if (addr + old_len > new_addr && new_addr + new_len > addr)
84862 goto out;
84863
84864 ret = do_munmap(mm, new_addr, new_len);
84865@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84866 unsigned long ret = -EINVAL;
84867 unsigned long charged = 0;
84868 bool locked = false;
84869+ unsigned long pax_task_size = TASK_SIZE;
84870
84871 down_write(&current->mm->mmap_sem);
84872
84873@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84874 if (!new_len)
84875 goto out;
84876
84877+#ifdef CONFIG_PAX_SEGMEXEC
84878+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84879+ pax_task_size = SEGMEXEC_TASK_SIZE;
84880+#endif
84881+
84882+ pax_task_size -= PAGE_SIZE;
84883+
84884+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
84885+ old_len > pax_task_size || addr > pax_task_size-old_len)
84886+ goto out;
84887+
84888 if (flags & MREMAP_FIXED) {
84889 if (flags & MREMAP_MAYMOVE)
84890 ret = mremap_to(addr, old_len, new_addr, new_len,
84891@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84892 new_addr = addr;
84893 }
84894 ret = addr;
84895+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
84896 goto out;
84897 }
84898 }
84899@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84900 goto out;
84901 }
84902
84903+ map_flags = vma->vm_flags;
84904 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
84905+ if (!(ret & ~PAGE_MASK)) {
84906+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
84907+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
84908+ }
84909 }
84910 out:
84911 if (ret & ~PAGE_MASK)
84912diff --git a/mm/nommu.c b/mm/nommu.c
84913index 298884d..5f74980 100644
84914--- a/mm/nommu.c
84915+++ b/mm/nommu.c
84916@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
84917 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
84918 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
84919 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
84920-int heap_stack_gap = 0;
84921
84922 atomic_long_t mmap_pages_allocated;
84923
84924@@ -842,15 +841,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
84925 EXPORT_SYMBOL(find_vma);
84926
84927 /*
84928- * find a VMA
84929- * - we don't extend stack VMAs under NOMMU conditions
84930- */
84931-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
84932-{
84933- return find_vma(mm, addr);
84934-}
84935-
84936-/*
84937 * expand a stack to a given address
84938 * - not supported under NOMMU conditions
84939 */
84940@@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
84941
84942 /* most fields are the same, copy all, and then fixup */
84943 *new = *vma;
84944+ INIT_LIST_HEAD(&new->anon_vma_chain);
84945 *region = *vma->vm_region;
84946 new->vm_region = region;
84947
84948@@ -1995,8 +1986,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
84949 }
84950 EXPORT_SYMBOL(generic_file_remap_pages);
84951
84952-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84953- unsigned long addr, void *buf, int len, int write)
84954+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84955+ unsigned long addr, void *buf, size_t len, int write)
84956 {
84957 struct vm_area_struct *vma;
84958
84959@@ -2037,8 +2028,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84960 *
84961 * The caller must hold a reference on @mm.
84962 */
84963-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84964- void *buf, int len, int write)
84965+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84966+ void *buf, size_t len, int write)
84967 {
84968 return __access_remote_vm(NULL, mm, addr, buf, len, write);
84969 }
84970@@ -2047,7 +2038,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84971 * Access another process' address space.
84972 * - source/target buffer must be kernel space
84973 */
84974-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
84975+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
84976 {
84977 struct mm_struct *mm;
84978
84979diff --git a/mm/page-writeback.c b/mm/page-writeback.c
84980index 4514ad7..92eaa1c 100644
84981--- a/mm/page-writeback.c
84982+++ b/mm/page-writeback.c
84983@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
84984 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
84985 * - the bdi dirty thresh drops quickly due to change of JBOD workload
84986 */
84987-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
84988+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
84989 unsigned long thresh,
84990 unsigned long bg_thresh,
84991 unsigned long dirty,
84992@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
84993 }
84994 }
84995
84996-static struct notifier_block __cpuinitdata ratelimit_nb = {
84997+static struct notifier_block ratelimit_nb = {
84998 .notifier_call = ratelimit_handler,
84999 .next = NULL,
85000 };
85001diff --git a/mm/page_alloc.c b/mm/page_alloc.c
85002index 2ee0fd3..6e2edfb 100644
85003--- a/mm/page_alloc.c
85004+++ b/mm/page_alloc.c
85005@@ -60,6 +60,7 @@
85006 #include <linux/page-debug-flags.h>
85007 #include <linux/hugetlb.h>
85008 #include <linux/sched/rt.h>
85009+#include <linux/random.h>
85010
85011 #include <asm/tlbflush.h>
85012 #include <asm/div64.h>
85013@@ -345,7 +346,7 @@ out:
85014 * This usage means that zero-order pages may not be compound.
85015 */
85016
85017-static void free_compound_page(struct page *page)
85018+void free_compound_page(struct page *page)
85019 {
85020 __free_pages_ok(page, compound_order(page));
85021 }
85022@@ -702,6 +703,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
85023 int i;
85024 int bad = 0;
85025
85026+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85027+ unsigned long index = 1UL << order;
85028+#endif
85029+
85030 trace_mm_page_free(page, order);
85031 kmemcheck_free_shadow(page, order);
85032
85033@@ -717,6 +722,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
85034 debug_check_no_obj_freed(page_address(page),
85035 PAGE_SIZE << order);
85036 }
85037+
85038+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85039+ for (; index; --index)
85040+ sanitize_highpage(page + index - 1);
85041+#endif
85042+
85043 arch_free_page(page, order);
85044 kernel_map_pages(page, 1 << order, 0);
85045
85046@@ -739,6 +750,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
85047 local_irq_restore(flags);
85048 }
85049
85050+#ifdef CONFIG_PAX_LATENT_ENTROPY
85051+bool __meminitdata extra_latent_entropy;
85052+
85053+static int __init setup_pax_extra_latent_entropy(char *str)
85054+{
85055+ extra_latent_entropy = true;
85056+ return 0;
85057+}
85058+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
85059+
85060+volatile u64 latent_entropy;
85061+#endif
85062+
85063 /*
85064 * Read access to zone->managed_pages is safe because it's unsigned long,
85065 * but we still need to serialize writers. Currently all callers of
85066@@ -761,6 +785,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
85067 set_page_count(p, 0);
85068 }
85069
85070+#ifdef CONFIG_PAX_LATENT_ENTROPY
85071+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
85072+ u64 hash = 0;
85073+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
85074+ const u64 *data = lowmem_page_address(page);
85075+
85076+ for (index = 0; index < end; index++)
85077+ hash ^= hash + data[index];
85078+ latent_entropy ^= hash;
85079+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
85080+ }
85081+#endif
85082+
85083 page_zone(page)->managed_pages += 1 << order;
85084 set_page_refcounted(page);
85085 __free_pages(page, order);
85086@@ -870,8 +907,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
85087 arch_alloc_page(page, order);
85088 kernel_map_pages(page, 1 << order, 1);
85089
85090+#ifndef CONFIG_PAX_MEMORY_SANITIZE
85091 if (gfp_flags & __GFP_ZERO)
85092 prep_zero_page(page, order, gfp_flags);
85093+#endif
85094
85095 if (order && (gfp_flags & __GFP_COMP))
85096 prep_compound_page(page, order);
85097diff --git a/mm/page_io.c b/mm/page_io.c
85098index a8a3ef4..7260a60 100644
85099--- a/mm/page_io.c
85100+++ b/mm/page_io.c
85101@@ -214,7 +214,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
85102 struct file *swap_file = sis->swap_file;
85103 struct address_space *mapping = swap_file->f_mapping;
85104 struct iovec iov = {
85105- .iov_base = kmap(page),
85106+ .iov_base = (void __force_user *)kmap(page),
85107 .iov_len = PAGE_SIZE,
85108 };
85109
85110diff --git a/mm/percpu.c b/mm/percpu.c
85111index 8c8e08f..73a5cda 100644
85112--- a/mm/percpu.c
85113+++ b/mm/percpu.c
85114@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
85115 static unsigned int pcpu_high_unit_cpu __read_mostly;
85116
85117 /* the address of the first chunk which starts with the kernel static area */
85118-void *pcpu_base_addr __read_mostly;
85119+void *pcpu_base_addr __read_only;
85120 EXPORT_SYMBOL_GPL(pcpu_base_addr);
85121
85122 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
85123diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
85124index fd26d04..0cea1b0 100644
85125--- a/mm/process_vm_access.c
85126+++ b/mm/process_vm_access.c
85127@@ -13,6 +13,7 @@
85128 #include <linux/uio.h>
85129 #include <linux/sched.h>
85130 #include <linux/highmem.h>
85131+#include <linux/security.h>
85132 #include <linux/ptrace.h>
85133 #include <linux/slab.h>
85134 #include <linux/syscalls.h>
85135@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
85136 size_t iov_l_curr_offset = 0;
85137 ssize_t iov_len;
85138
85139+ return -ENOSYS; // PaX: until properly audited
85140+
85141 /*
85142 * Work out how many pages of struct pages we're going to need
85143 * when eventually calling get_user_pages
85144 */
85145 for (i = 0; i < riovcnt; i++) {
85146 iov_len = rvec[i].iov_len;
85147- if (iov_len > 0) {
85148- nr_pages_iov = ((unsigned long)rvec[i].iov_base
85149- + iov_len)
85150- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
85151- / PAGE_SIZE + 1;
85152- nr_pages = max(nr_pages, nr_pages_iov);
85153- }
85154+ if (iov_len <= 0)
85155+ continue;
85156+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
85157+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
85158+ nr_pages = max(nr_pages, nr_pages_iov);
85159 }
85160
85161 if (nr_pages == 0)
85162@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
85163 goto free_proc_pages;
85164 }
85165
85166+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
85167+ rc = -EPERM;
85168+ goto put_task_struct;
85169+ }
85170+
85171 mm = mm_access(task, PTRACE_MODE_ATTACH);
85172 if (!mm || IS_ERR(mm)) {
85173 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
85174diff --git a/mm/rmap.c b/mm/rmap.c
85175index 6280da8..b5c090e 100644
85176--- a/mm/rmap.c
85177+++ b/mm/rmap.c
85178@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
85179 struct anon_vma *anon_vma = vma->anon_vma;
85180 struct anon_vma_chain *avc;
85181
85182+#ifdef CONFIG_PAX_SEGMEXEC
85183+ struct anon_vma_chain *avc_m = NULL;
85184+#endif
85185+
85186 might_sleep();
85187 if (unlikely(!anon_vma)) {
85188 struct mm_struct *mm = vma->vm_mm;
85189@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
85190 if (!avc)
85191 goto out_enomem;
85192
85193+#ifdef CONFIG_PAX_SEGMEXEC
85194+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
85195+ if (!avc_m)
85196+ goto out_enomem_free_avc;
85197+#endif
85198+
85199 anon_vma = find_mergeable_anon_vma(vma);
85200 allocated = NULL;
85201 if (!anon_vma) {
85202@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
85203 /* page_table_lock to protect against threads */
85204 spin_lock(&mm->page_table_lock);
85205 if (likely(!vma->anon_vma)) {
85206+
85207+#ifdef CONFIG_PAX_SEGMEXEC
85208+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
85209+
85210+ if (vma_m) {
85211+ BUG_ON(vma_m->anon_vma);
85212+ vma_m->anon_vma = anon_vma;
85213+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
85214+ avc_m = NULL;
85215+ }
85216+#endif
85217+
85218 vma->anon_vma = anon_vma;
85219 anon_vma_chain_link(vma, avc, anon_vma);
85220 allocated = NULL;
85221@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
85222
85223 if (unlikely(allocated))
85224 put_anon_vma(allocated);
85225+
85226+#ifdef CONFIG_PAX_SEGMEXEC
85227+ if (unlikely(avc_m))
85228+ anon_vma_chain_free(avc_m);
85229+#endif
85230+
85231 if (unlikely(avc))
85232 anon_vma_chain_free(avc);
85233 }
85234 return 0;
85235
85236 out_enomem_free_avc:
85237+
85238+#ifdef CONFIG_PAX_SEGMEXEC
85239+ if (avc_m)
85240+ anon_vma_chain_free(avc_m);
85241+#endif
85242+
85243 anon_vma_chain_free(avc);
85244 out_enomem:
85245 return -ENOMEM;
85246@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
85247 * Attach the anon_vmas from src to dst.
85248 * Returns 0 on success, -ENOMEM on failure.
85249 */
85250-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
85251+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
85252 {
85253 struct anon_vma_chain *avc, *pavc;
85254 struct anon_vma *root = NULL;
85255@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
85256 * the corresponding VMA in the parent process is attached to.
85257 * Returns 0 on success, non-zero on failure.
85258 */
85259-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
85260+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
85261 {
85262 struct anon_vma_chain *avc;
85263 struct anon_vma *anon_vma;
85264@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
85265 void __init anon_vma_init(void)
85266 {
85267 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
85268- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
85269- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
85270+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
85271+ anon_vma_ctor);
85272+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
85273+ SLAB_PANIC|SLAB_NO_SANITIZE);
85274 }
85275
85276 /*
85277diff --git a/mm/shmem.c b/mm/shmem.c
85278index 5e6a842..b41916e 100644
85279--- a/mm/shmem.c
85280+++ b/mm/shmem.c
85281@@ -33,7 +33,7 @@
85282 #include <linux/swap.h>
85283 #include <linux/aio.h>
85284
85285-static struct vfsmount *shm_mnt;
85286+struct vfsmount *shm_mnt;
85287
85288 #ifdef CONFIG_SHMEM
85289 /*
85290@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
85291 #define BOGO_DIRENT_SIZE 20
85292
85293 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
85294-#define SHORT_SYMLINK_LEN 128
85295+#define SHORT_SYMLINK_LEN 64
85296
85297 /*
85298 * shmem_fallocate and shmem_writepage communicate via inode->i_private
85299@@ -2203,6 +2203,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
85300 static int shmem_xattr_validate(const char *name)
85301 {
85302 struct { const char *prefix; size_t len; } arr[] = {
85303+
85304+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
85305+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
85306+#endif
85307+
85308 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
85309 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
85310 };
85311@@ -2258,6 +2263,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
85312 if (err)
85313 return err;
85314
85315+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
85316+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
85317+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
85318+ return -EOPNOTSUPP;
85319+ if (size > 8)
85320+ return -EINVAL;
85321+ }
85322+#endif
85323+
85324 return simple_xattr_set(&info->xattrs, name, value, size, flags);
85325 }
85326
85327@@ -2570,8 +2584,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
85328 int err = -ENOMEM;
85329
85330 /* Round up to L1_CACHE_BYTES to resist false sharing */
85331- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
85332- L1_CACHE_BYTES), GFP_KERNEL);
85333+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
85334 if (!sbinfo)
85335 return -ENOMEM;
85336
85337diff --git a/mm/slab.c b/mm/slab.c
85338index bd88411..2d46fd6 100644
85339--- a/mm/slab.c
85340+++ b/mm/slab.c
85341@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
85342 if ((x)->max_freeable < i) \
85343 (x)->max_freeable = i; \
85344 } while (0)
85345-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
85346-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
85347-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
85348-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
85349+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
85350+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
85351+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
85352+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
85353+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
85354+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
85355 #else
85356 #define STATS_INC_ACTIVE(x) do { } while (0)
85357 #define STATS_DEC_ACTIVE(x) do { } while (0)
85358@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
85359 #define STATS_INC_ALLOCMISS(x) do { } while (0)
85360 #define STATS_INC_FREEHIT(x) do { } while (0)
85361 #define STATS_INC_FREEMISS(x) do { } while (0)
85362+#define STATS_INC_SANITIZED(x) do { } while (0)
85363+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
85364 #endif
85365
85366 #if DEBUG
85367@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
85368 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
85369 */
85370 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
85371- const struct slab *slab, void *obj)
85372+ const struct slab *slab, const void *obj)
85373 {
85374 u32 offset = (obj - slab->s_mem);
85375 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
85376@@ -1384,7 +1388,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
85377 return notifier_from_errno(err);
85378 }
85379
85380-static struct notifier_block __cpuinitdata cpucache_notifier = {
85381+static struct notifier_block cpucache_notifier = {
85382 &cpuup_callback, NULL, 0
85383 };
85384
85385@@ -1565,12 +1569,12 @@ void __init kmem_cache_init(void)
85386 */
85387
85388 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
85389- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
85390+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
85391
85392 if (INDEX_AC != INDEX_NODE)
85393 kmalloc_caches[INDEX_NODE] =
85394 create_kmalloc_cache("kmalloc-node",
85395- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
85396+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
85397
85398 slab_early_init = 0;
85399
85400@@ -3583,6 +3587,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
85401 struct array_cache *ac = cpu_cache_get(cachep);
85402
85403 check_irq_off();
85404+
85405+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85406+ if (pax_sanitize_slab) {
85407+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
85408+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
85409+
85410+ if (cachep->ctor)
85411+ cachep->ctor(objp);
85412+
85413+ STATS_INC_SANITIZED(cachep);
85414+ } else
85415+ STATS_INC_NOT_SANITIZED(cachep);
85416+ }
85417+#endif
85418+
85419 kmemleak_free_recursive(objp, cachep->flags);
85420 objp = cache_free_debugcheck(cachep, objp, caller);
85421
85422@@ -3800,6 +3819,7 @@ void kfree(const void *objp)
85423
85424 if (unlikely(ZERO_OR_NULL_PTR(objp)))
85425 return;
85426+ VM_BUG_ON(!virt_addr_valid(objp));
85427 local_irq_save(flags);
85428 kfree_debugcheck(objp);
85429 c = virt_to_cache(objp);
85430@@ -4241,14 +4261,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
85431 }
85432 /* cpu stats */
85433 {
85434- unsigned long allochit = atomic_read(&cachep->allochit);
85435- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
85436- unsigned long freehit = atomic_read(&cachep->freehit);
85437- unsigned long freemiss = atomic_read(&cachep->freemiss);
85438+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
85439+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
85440+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
85441+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
85442
85443 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
85444 allochit, allocmiss, freehit, freemiss);
85445 }
85446+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85447+ {
85448+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
85449+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
85450+
85451+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
85452+ }
85453+#endif
85454 #endif
85455 }
85456
85457@@ -4476,13 +4504,71 @@ static const struct file_operations proc_slabstats_operations = {
85458 static int __init slab_proc_init(void)
85459 {
85460 #ifdef CONFIG_DEBUG_SLAB_LEAK
85461- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
85462+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
85463 #endif
85464 return 0;
85465 }
85466 module_init(slab_proc_init);
85467 #endif
85468
85469+bool is_usercopy_object(const void *ptr)
85470+{
85471+ struct page *page;
85472+ struct kmem_cache *cachep;
85473+
85474+ if (ZERO_OR_NULL_PTR(ptr))
85475+ return false;
85476+
85477+ if (!slab_is_available())
85478+ return false;
85479+
85480+ if (!virt_addr_valid(ptr))
85481+ return false;
85482+
85483+ page = virt_to_head_page(ptr);
85484+
85485+ if (!PageSlab(page))
85486+ return false;
85487+
85488+ cachep = page->slab_cache;
85489+ return cachep->flags & SLAB_USERCOPY;
85490+}
85491+
85492+#ifdef CONFIG_PAX_USERCOPY
85493+const char *check_heap_object(const void *ptr, unsigned long n)
85494+{
85495+ struct page *page;
85496+ struct kmem_cache *cachep;
85497+ struct slab *slabp;
85498+ unsigned int objnr;
85499+ unsigned long offset;
85500+
85501+ if (ZERO_OR_NULL_PTR(ptr))
85502+ return "<null>";
85503+
85504+ if (!virt_addr_valid(ptr))
85505+ return NULL;
85506+
85507+ page = virt_to_head_page(ptr);
85508+
85509+ if (!PageSlab(page))
85510+ return NULL;
85511+
85512+ cachep = page->slab_cache;
85513+ if (!(cachep->flags & SLAB_USERCOPY))
85514+ return cachep->name;
85515+
85516+ slabp = page->slab_page;
85517+ objnr = obj_to_index(cachep, slabp, ptr);
85518+ BUG_ON(objnr >= cachep->num);
85519+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
85520+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
85521+ return NULL;
85522+
85523+ return cachep->name;
85524+}
85525+#endif
85526+
85527 /**
85528 * ksize - get the actual amount of memory allocated for a given object
85529 * @objp: Pointer to the object
85530diff --git a/mm/slab.h b/mm/slab.h
85531index f96b49e..db1d204 100644
85532--- a/mm/slab.h
85533+++ b/mm/slab.h
85534@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
85535 /* The slab cache that manages slab cache information */
85536 extern struct kmem_cache *kmem_cache;
85537
85538+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85539+#ifdef CONFIG_X86_64
85540+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
85541+#else
85542+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
85543+#endif
85544+extern bool pax_sanitize_slab;
85545+#endif
85546+
85547 unsigned long calculate_alignment(unsigned long flags,
85548 unsigned long align, unsigned long size);
85549
85550@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85551
85552 /* Legal flag mask for kmem_cache_create(), for various configurations */
85553 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
85554- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
85555+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
85556+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
85557
85558 #if defined(CONFIG_DEBUG_SLAB)
85559 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
85560@@ -229,6 +239,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
85561 return s;
85562
85563 page = virt_to_head_page(x);
85564+
85565+ BUG_ON(!PageSlab(page));
85566+
85567 cachep = page->slab_cache;
85568 if (slab_equal_or_root(cachep, s))
85569 return cachep;
85570diff --git a/mm/slab_common.c b/mm/slab_common.c
85571index 2d41450..4efe6ee 100644
85572--- a/mm/slab_common.c
85573+++ b/mm/slab_common.c
85574@@ -22,11 +22,22 @@
85575
85576 #include "slab.h"
85577
85578-enum slab_state slab_state;
85579+enum slab_state slab_state __read_only;
85580 LIST_HEAD(slab_caches);
85581 DEFINE_MUTEX(slab_mutex);
85582 struct kmem_cache *kmem_cache;
85583
85584+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85585+bool pax_sanitize_slab __read_only = true;
85586+static int __init pax_sanitize_slab_setup(char *str)
85587+{
85588+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
85589+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
85590+ return 1;
85591+}
85592+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
85593+#endif
85594+
85595 #ifdef CONFIG_DEBUG_VM
85596 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
85597 size_t size)
85598@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
85599
85600 err = __kmem_cache_create(s, flags);
85601 if (!err) {
85602- s->refcount = 1;
85603+ atomic_set(&s->refcount, 1);
85604 list_add(&s->list, &slab_caches);
85605 memcg_cache_list_add(memcg, s);
85606 } else {
85607@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
85608
85609 get_online_cpus();
85610 mutex_lock(&slab_mutex);
85611- s->refcount--;
85612- if (!s->refcount) {
85613+ if (atomic_dec_and_test(&s->refcount)) {
85614 list_del(&s->list);
85615
85616 if (!__kmem_cache_shutdown(s)) {
85617@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
85618 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
85619 name, size, err);
85620
85621- s->refcount = -1; /* Exempt from merging for now */
85622+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
85623 }
85624
85625 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
85626@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
85627
85628 create_boot_cache(s, name, size, flags);
85629 list_add(&s->list, &slab_caches);
85630- s->refcount = 1;
85631+ atomic_set(&s->refcount, 1);
85632 return s;
85633 }
85634
85635@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85636 EXPORT_SYMBOL(kmalloc_dma_caches);
85637 #endif
85638
85639+#ifdef CONFIG_PAX_USERCOPY_SLABS
85640+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85641+EXPORT_SYMBOL(kmalloc_usercopy_caches);
85642+#endif
85643+
85644 /*
85645 * Conversion table for small slabs sizes / 8 to the index in the
85646 * kmalloc array. This is necessary for slabs < 192 since we have non power
85647@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
85648 return kmalloc_dma_caches[index];
85649
85650 #endif
85651+
85652+#ifdef CONFIG_PAX_USERCOPY_SLABS
85653+ if (unlikely((flags & GFP_USERCOPY)))
85654+ return kmalloc_usercopy_caches[index];
85655+
85656+#endif
85657+
85658 return kmalloc_caches[index];
85659 }
85660
85661@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
85662 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
85663 if (!kmalloc_caches[i]) {
85664 kmalloc_caches[i] = create_kmalloc_cache(NULL,
85665- 1 << i, flags);
85666+ 1 << i, SLAB_USERCOPY | flags);
85667 }
85668
85669 /*
85670@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
85671 * earlier power of two caches
85672 */
85673 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
85674- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
85675+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
85676
85677 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
85678- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
85679+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
85680 }
85681
85682 /* Kmalloc array is now usable */
85683@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
85684 }
85685 }
85686 #endif
85687+
85688+#ifdef CONFIG_PAX_USERCOPY_SLABS
85689+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
85690+ struct kmem_cache *s = kmalloc_caches[i];
85691+
85692+ if (s) {
85693+ int size = kmalloc_size(i);
85694+ char *n = kasprintf(GFP_NOWAIT,
85695+ "usercopy-kmalloc-%d", size);
85696+
85697+ BUG_ON(!n);
85698+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
85699+ size, SLAB_USERCOPY | flags);
85700+ }
85701+ }
85702+#endif
85703+
85704 }
85705 #endif /* !CONFIG_SLOB */
85706
85707@@ -516,6 +555,9 @@ void print_slabinfo_header(struct seq_file *m)
85708 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
85709 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
85710 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
85711+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85712+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
85713+#endif
85714 #endif
85715 seq_putc(m, '\n');
85716 }
85717diff --git a/mm/slob.c b/mm/slob.c
85718index eeed4a0..bb0e9ab 100644
85719--- a/mm/slob.c
85720+++ b/mm/slob.c
85721@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
85722 /*
85723 * Return the size of a slob block.
85724 */
85725-static slobidx_t slob_units(slob_t *s)
85726+static slobidx_t slob_units(const slob_t *s)
85727 {
85728 if (s->units > 0)
85729 return s->units;
85730@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
85731 /*
85732 * Return the next free slob block pointer after this one.
85733 */
85734-static slob_t *slob_next(slob_t *s)
85735+static slob_t *slob_next(const slob_t *s)
85736 {
85737 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
85738 slobidx_t next;
85739@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
85740 /*
85741 * Returns true if s is the last free block in its page.
85742 */
85743-static int slob_last(slob_t *s)
85744+static int slob_last(const slob_t *s)
85745 {
85746 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
85747 }
85748
85749-static void *slob_new_pages(gfp_t gfp, int order, int node)
85750+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
85751 {
85752- void *page;
85753+ struct page *page;
85754
85755 #ifdef CONFIG_NUMA
85756 if (node != NUMA_NO_NODE)
85757@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
85758 if (!page)
85759 return NULL;
85760
85761- return page_address(page);
85762+ __SetPageSlab(page);
85763+ return page;
85764 }
85765
85766-static void slob_free_pages(void *b, int order)
85767+static void slob_free_pages(struct page *sp, int order)
85768 {
85769 if (current->reclaim_state)
85770 current->reclaim_state->reclaimed_slab += 1 << order;
85771- free_pages((unsigned long)b, order);
85772+ __ClearPageSlab(sp);
85773+ page_mapcount_reset(sp);
85774+ sp->private = 0;
85775+ __free_pages(sp, order);
85776 }
85777
85778 /*
85779@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
85780
85781 /* Not enough space: must allocate a new page */
85782 if (!b) {
85783- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
85784- if (!b)
85785+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
85786+ if (!sp)
85787 return NULL;
85788- sp = virt_to_page(b);
85789- __SetPageSlab(sp);
85790+ b = page_address(sp);
85791
85792 spin_lock_irqsave(&slob_lock, flags);
85793 sp->units = SLOB_UNITS(PAGE_SIZE);
85794 sp->freelist = b;
85795+ sp->private = 0;
85796 INIT_LIST_HEAD(&sp->list);
85797 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
85798 set_slob_page_free(sp, slob_list);
85799@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
85800 if (slob_page_free(sp))
85801 clear_slob_page_free(sp);
85802 spin_unlock_irqrestore(&slob_lock, flags);
85803- __ClearPageSlab(sp);
85804- page_mapcount_reset(sp);
85805- slob_free_pages(b, 0);
85806+ slob_free_pages(sp, 0);
85807 return;
85808 }
85809
85810+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85811+ if (pax_sanitize_slab)
85812+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
85813+#endif
85814+
85815 if (!slob_page_free(sp)) {
85816 /* This slob page is about to become partially free. Easy! */
85817 sp->units = units;
85818@@ -424,11 +431,10 @@ out:
85819 */
85820
85821 static __always_inline void *
85822-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
85823+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
85824 {
85825- unsigned int *m;
85826- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85827- void *ret;
85828+ slob_t *m;
85829+ void *ret = NULL;
85830
85831 gfp &= gfp_allowed_mask;
85832
85833@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
85834
85835 if (!m)
85836 return NULL;
85837- *m = size;
85838+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
85839+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
85840+ m[0].units = size;
85841+ m[1].units = align;
85842 ret = (void *)m + align;
85843
85844 trace_kmalloc_node(caller, ret,
85845 size, size + align, gfp, node);
85846 } else {
85847 unsigned int order = get_order(size);
85848+ struct page *page;
85849
85850 if (likely(order))
85851 gfp |= __GFP_COMP;
85852- ret = slob_new_pages(gfp, order, node);
85853+ page = slob_new_pages(gfp, order, node);
85854+ if (page) {
85855+ ret = page_address(page);
85856+ page->private = size;
85857+ }
85858
85859 trace_kmalloc_node(caller, ret,
85860 size, PAGE_SIZE << order, gfp, node);
85861 }
85862
85863- kmemleak_alloc(ret, size, 1, gfp);
85864+ return ret;
85865+}
85866+
85867+static __always_inline void *
85868+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
85869+{
85870+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85871+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
85872+
85873+ if (!ZERO_OR_NULL_PTR(ret))
85874+ kmemleak_alloc(ret, size, 1, gfp);
85875 return ret;
85876 }
85877
85878@@ -493,34 +517,112 @@ void kfree(const void *block)
85879 return;
85880 kmemleak_free(block);
85881
85882+ VM_BUG_ON(!virt_addr_valid(block));
85883 sp = virt_to_page(block);
85884- if (PageSlab(sp)) {
85885+ VM_BUG_ON(!PageSlab(sp));
85886+ if (!sp->private) {
85887 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85888- unsigned int *m = (unsigned int *)(block - align);
85889- slob_free(m, *m + align);
85890- } else
85891+ slob_t *m = (slob_t *)(block - align);
85892+ slob_free(m, m[0].units + align);
85893+ } else {
85894+ __ClearPageSlab(sp);
85895+ page_mapcount_reset(sp);
85896+ sp->private = 0;
85897 __free_pages(sp, compound_order(sp));
85898+ }
85899 }
85900 EXPORT_SYMBOL(kfree);
85901
85902+bool is_usercopy_object(const void *ptr)
85903+{
85904+ if (!slab_is_available())
85905+ return false;
85906+
85907+ // PAX: TODO
85908+
85909+ return false;
85910+}
85911+
85912+#ifdef CONFIG_PAX_USERCOPY
85913+const char *check_heap_object(const void *ptr, unsigned long n)
85914+{
85915+ struct page *page;
85916+ const slob_t *free;
85917+ const void *base;
85918+ unsigned long flags;
85919+
85920+ if (ZERO_OR_NULL_PTR(ptr))
85921+ return "<null>";
85922+
85923+ if (!virt_addr_valid(ptr))
85924+ return NULL;
85925+
85926+ page = virt_to_head_page(ptr);
85927+ if (!PageSlab(page))
85928+ return NULL;
85929+
85930+ if (page->private) {
85931+ base = page;
85932+ if (base <= ptr && n <= page->private - (ptr - base))
85933+ return NULL;
85934+ return "<slob>";
85935+ }
85936+
85937+ /* some tricky double walking to find the chunk */
85938+ spin_lock_irqsave(&slob_lock, flags);
85939+ base = (void *)((unsigned long)ptr & PAGE_MASK);
85940+ free = page->freelist;
85941+
85942+ while (!slob_last(free) && (void *)free <= ptr) {
85943+ base = free + slob_units(free);
85944+ free = slob_next(free);
85945+ }
85946+
85947+ while (base < (void *)free) {
85948+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
85949+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
85950+ int offset;
85951+
85952+ if (ptr < base + align)
85953+ break;
85954+
85955+ offset = ptr - base - align;
85956+ if (offset >= m) {
85957+ base += size;
85958+ continue;
85959+ }
85960+
85961+ if (n > m - offset)
85962+ break;
85963+
85964+ spin_unlock_irqrestore(&slob_lock, flags);
85965+ return NULL;
85966+ }
85967+
85968+ spin_unlock_irqrestore(&slob_lock, flags);
85969+ return "<slob>";
85970+}
85971+#endif
85972+
85973 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
85974 size_t ksize(const void *block)
85975 {
85976 struct page *sp;
85977 int align;
85978- unsigned int *m;
85979+ slob_t *m;
85980
85981 BUG_ON(!block);
85982 if (unlikely(block == ZERO_SIZE_PTR))
85983 return 0;
85984
85985 sp = virt_to_page(block);
85986- if (unlikely(!PageSlab(sp)))
85987- return PAGE_SIZE << compound_order(sp);
85988+ VM_BUG_ON(!PageSlab(sp));
85989+ if (sp->private)
85990+ return sp->private;
85991
85992 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85993- m = (unsigned int *)(block - align);
85994- return SLOB_UNITS(*m) * SLOB_UNIT;
85995+ m = (slob_t *)(block - align);
85996+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
85997 }
85998 EXPORT_SYMBOL(ksize);
85999
86000@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
86001
86002 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
86003 {
86004- void *b;
86005+ void *b = NULL;
86006
86007 flags &= gfp_allowed_mask;
86008
86009 lockdep_trace_alloc(flags);
86010
86011+#ifdef CONFIG_PAX_USERCOPY_SLABS
86012+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
86013+#else
86014 if (c->size < PAGE_SIZE) {
86015 b = slob_alloc(c->size, flags, c->align, node);
86016 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
86017 SLOB_UNITS(c->size) * SLOB_UNIT,
86018 flags, node);
86019 } else {
86020- b = slob_new_pages(flags, get_order(c->size), node);
86021+ struct page *sp;
86022+
86023+ sp = slob_new_pages(flags, get_order(c->size), node);
86024+ if (sp) {
86025+ b = page_address(sp);
86026+ sp->private = c->size;
86027+ }
86028 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
86029 PAGE_SIZE << get_order(c->size),
86030 flags, node);
86031 }
86032+#endif
86033
86034 if (c->ctor)
86035 c->ctor(b);
86036@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
86037
86038 static void __kmem_cache_free(void *b, int size)
86039 {
86040- if (size < PAGE_SIZE)
86041+ struct page *sp;
86042+
86043+ sp = virt_to_page(b);
86044+ BUG_ON(!PageSlab(sp));
86045+ if (!sp->private)
86046 slob_free(b, size);
86047 else
86048- slob_free_pages(b, get_order(size));
86049+ slob_free_pages(sp, get_order(size));
86050 }
86051
86052 static void kmem_rcu_free(struct rcu_head *head)
86053@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
86054
86055 void kmem_cache_free(struct kmem_cache *c, void *b)
86056 {
86057+ int size = c->size;
86058+
86059+#ifdef CONFIG_PAX_USERCOPY_SLABS
86060+ if (size + c->align < PAGE_SIZE) {
86061+ size += c->align;
86062+ b -= c->align;
86063+ }
86064+#endif
86065+
86066 kmemleak_free_recursive(b, c->flags);
86067 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
86068 struct slob_rcu *slob_rcu;
86069- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
86070- slob_rcu->size = c->size;
86071+ slob_rcu = b + (size - sizeof(struct slob_rcu));
86072+ slob_rcu->size = size;
86073 call_rcu(&slob_rcu->head, kmem_rcu_free);
86074 } else {
86075- __kmem_cache_free(b, c->size);
86076+ __kmem_cache_free(b, size);
86077 }
86078
86079+#ifdef CONFIG_PAX_USERCOPY_SLABS
86080+ trace_kfree(_RET_IP_, b);
86081+#else
86082 trace_kmem_cache_free(_RET_IP_, b);
86083+#endif
86084+
86085 }
86086 EXPORT_SYMBOL(kmem_cache_free);
86087
86088diff --git a/mm/slub.c b/mm/slub.c
86089index 57707f0..7857bd3 100644
86090--- a/mm/slub.c
86091+++ b/mm/slub.c
86092@@ -198,7 +198,7 @@ struct track {
86093
86094 enum track_item { TRACK_ALLOC, TRACK_FREE };
86095
86096-#ifdef CONFIG_SYSFS
86097+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
86098 static int sysfs_slab_add(struct kmem_cache *);
86099 static int sysfs_slab_alias(struct kmem_cache *, const char *);
86100 static void sysfs_slab_remove(struct kmem_cache *);
86101@@ -519,7 +519,7 @@ static void print_track(const char *s, struct track *t)
86102 if (!t->addr)
86103 return;
86104
86105- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
86106+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
86107 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
86108 #ifdef CONFIG_STACKTRACE
86109 {
86110@@ -2594,6 +2594,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
86111
86112 slab_free_hook(s, x);
86113
86114+#ifdef CONFIG_PAX_MEMORY_SANITIZE
86115+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
86116+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
86117+ if (s->ctor)
86118+ s->ctor(x);
86119+ }
86120+#endif
86121+
86122 redo:
86123 /*
86124 * Determine the currently cpus per cpu slab.
86125@@ -2661,7 +2669,7 @@ static int slub_min_objects;
86126 * Merge control. If this is set then no merging of slab caches will occur.
86127 * (Could be removed. This was introduced to pacify the merge skeptics.)
86128 */
86129-static int slub_nomerge;
86130+static int slub_nomerge = 1;
86131
86132 /*
86133 * Calculate the order of allocation given an slab object size.
86134@@ -2938,6 +2946,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
86135 s->inuse = size;
86136
86137 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
86138+#ifdef CONFIG_PAX_MEMORY_SANITIZE
86139+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
86140+#endif
86141 s->ctor)) {
86142 /*
86143 * Relocate free pointer after the object if it is not
86144@@ -3283,6 +3294,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
86145 EXPORT_SYMBOL(__kmalloc_node);
86146 #endif
86147
86148+bool is_usercopy_object(const void *ptr)
86149+{
86150+ struct page *page;
86151+ struct kmem_cache *s;
86152+
86153+ if (ZERO_OR_NULL_PTR(ptr))
86154+ return false;
86155+
86156+ if (!slab_is_available())
86157+ return false;
86158+
86159+ if (!virt_addr_valid(ptr))
86160+ return false;
86161+
86162+ page = virt_to_head_page(ptr);
86163+
86164+ if (!PageSlab(page))
86165+ return false;
86166+
86167+ s = page->slab_cache;
86168+ return s->flags & SLAB_USERCOPY;
86169+}
86170+
86171+#ifdef CONFIG_PAX_USERCOPY
86172+const char *check_heap_object(const void *ptr, unsigned long n)
86173+{
86174+ struct page *page;
86175+ struct kmem_cache *s;
86176+ unsigned long offset;
86177+
86178+ if (ZERO_OR_NULL_PTR(ptr))
86179+ return "<null>";
86180+
86181+ if (!virt_addr_valid(ptr))
86182+ return NULL;
86183+
86184+ page = virt_to_head_page(ptr);
86185+
86186+ if (!PageSlab(page))
86187+ return NULL;
86188+
86189+ s = page->slab_cache;
86190+ if (!(s->flags & SLAB_USERCOPY))
86191+ return s->name;
86192+
86193+ offset = (ptr - page_address(page)) % s->size;
86194+ if (offset <= s->object_size && n <= s->object_size - offset)
86195+ return NULL;
86196+
86197+ return s->name;
86198+}
86199+#endif
86200+
86201 size_t ksize(const void *object)
86202 {
86203 struct page *page;
86204@@ -3347,6 +3411,7 @@ void kfree(const void *x)
86205 if (unlikely(ZERO_OR_NULL_PTR(x)))
86206 return;
86207
86208+ VM_BUG_ON(!virt_addr_valid(x));
86209 page = virt_to_head_page(x);
86210 if (unlikely(!PageSlab(page))) {
86211 BUG_ON(!PageCompound(page));
86212@@ -3652,7 +3717,7 @@ static int slab_unmergeable(struct kmem_cache *s)
86213 /*
86214 * We may have set a slab to be unmergeable during bootstrap.
86215 */
86216- if (s->refcount < 0)
86217+ if (atomic_read(&s->refcount) < 0)
86218 return 1;
86219
86220 return 0;
86221@@ -3710,7 +3775,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
86222
86223 s = find_mergeable(memcg, size, align, flags, name, ctor);
86224 if (s) {
86225- s->refcount++;
86226+ atomic_inc(&s->refcount);
86227 /*
86228 * Adjust the object sizes so that we clear
86229 * the complete object on kzalloc.
86230@@ -3719,7 +3784,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
86231 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
86232
86233 if (sysfs_slab_alias(s, name)) {
86234- s->refcount--;
86235+ atomic_dec(&s->refcount);
86236 s = NULL;
86237 }
86238 }
86239@@ -3781,7 +3846,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
86240 return NOTIFY_OK;
86241 }
86242
86243-static struct notifier_block __cpuinitdata slab_notifier = {
86244+static struct notifier_block slab_notifier = {
86245 .notifier_call = slab_cpuup_callback
86246 };
86247
86248@@ -3839,7 +3904,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
86249 }
86250 #endif
86251
86252-#ifdef CONFIG_SYSFS
86253+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
86254 static int count_inuse(struct page *page)
86255 {
86256 return page->inuse;
86257@@ -4226,12 +4291,12 @@ static void resiliency_test(void)
86258 validate_slab_cache(kmalloc_caches[9]);
86259 }
86260 #else
86261-#ifdef CONFIG_SYSFS
86262+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
86263 static void resiliency_test(void) {};
86264 #endif
86265 #endif
86266
86267-#ifdef CONFIG_SYSFS
86268+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
86269 enum slab_stat_type {
86270 SL_ALL, /* All slabs */
86271 SL_PARTIAL, /* Only partially allocated slabs */
86272@@ -4475,7 +4540,7 @@ SLAB_ATTR_RO(ctor);
86273
86274 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
86275 {
86276- return sprintf(buf, "%d\n", s->refcount - 1);
86277+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
86278 }
86279 SLAB_ATTR_RO(aliases);
86280
86281@@ -4563,6 +4628,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
86282 SLAB_ATTR_RO(cache_dma);
86283 #endif
86284
86285+#ifdef CONFIG_PAX_USERCOPY_SLABS
86286+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
86287+{
86288+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
86289+}
86290+SLAB_ATTR_RO(usercopy);
86291+#endif
86292+
86293 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
86294 {
86295 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
86296@@ -4897,6 +4970,9 @@ static struct attribute *slab_attrs[] = {
86297 #ifdef CONFIG_ZONE_DMA
86298 &cache_dma_attr.attr,
86299 #endif
86300+#ifdef CONFIG_PAX_USERCOPY_SLABS
86301+ &usercopy_attr.attr,
86302+#endif
86303 #ifdef CONFIG_NUMA
86304 &remote_node_defrag_ratio_attr.attr,
86305 #endif
86306@@ -5128,6 +5204,7 @@ static char *create_unique_id(struct kmem_cache *s)
86307 return name;
86308 }
86309
86310+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
86311 static int sysfs_slab_add(struct kmem_cache *s)
86312 {
86313 int err;
86314@@ -5151,7 +5228,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
86315 }
86316
86317 s->kobj.kset = slab_kset;
86318- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
86319+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
86320 if (err) {
86321 kobject_put(&s->kobj);
86322 return err;
86323@@ -5185,6 +5262,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
86324 kobject_del(&s->kobj);
86325 kobject_put(&s->kobj);
86326 }
86327+#endif
86328
86329 /*
86330 * Need to buffer aliases during bootup until sysfs becomes
86331@@ -5198,6 +5276,7 @@ struct saved_alias {
86332
86333 static struct saved_alias *alias_list;
86334
86335+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
86336 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
86337 {
86338 struct saved_alias *al;
86339@@ -5220,6 +5299,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
86340 alias_list = al;
86341 return 0;
86342 }
86343+#endif
86344
86345 static int __init slab_sysfs_init(void)
86346 {
86347diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
86348index 27eeab3..7c3f7f2 100644
86349--- a/mm/sparse-vmemmap.c
86350+++ b/mm/sparse-vmemmap.c
86351@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
86352 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
86353 if (!p)
86354 return NULL;
86355- pud_populate(&init_mm, pud, p);
86356+ pud_populate_kernel(&init_mm, pud, p);
86357 }
86358 return pud;
86359 }
86360@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
86361 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
86362 if (!p)
86363 return NULL;
86364- pgd_populate(&init_mm, pgd, p);
86365+ pgd_populate_kernel(&init_mm, pgd, p);
86366 }
86367 return pgd;
86368 }
86369diff --git a/mm/sparse.c b/mm/sparse.c
86370index 1c91f0d3..485470a 100644
86371--- a/mm/sparse.c
86372+++ b/mm/sparse.c
86373@@ -761,7 +761,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
86374
86375 for (i = 0; i < PAGES_PER_SECTION; i++) {
86376 if (PageHWPoison(&memmap[i])) {
86377- atomic_long_sub(1, &num_poisoned_pages);
86378+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
86379 ClearPageHWPoison(&memmap[i]);
86380 }
86381 }
86382diff --git a/mm/swap.c b/mm/swap.c
86383index dfd7d71..ccdf688 100644
86384--- a/mm/swap.c
86385+++ b/mm/swap.c
86386@@ -31,6 +31,7 @@
86387 #include <linux/memcontrol.h>
86388 #include <linux/gfp.h>
86389 #include <linux/uio.h>
86390+#include <linux/hugetlb.h>
86391
86392 #include "internal.h"
86393
86394@@ -73,6 +74,8 @@ static void __put_compound_page(struct page *page)
86395
86396 __page_cache_release(page);
86397 dtor = get_compound_page_dtor(page);
86398+ if (!PageHuge(page))
86399+ BUG_ON(dtor != free_compound_page);
86400 (*dtor)(page);
86401 }
86402
86403diff --git a/mm/swapfile.c b/mm/swapfile.c
86404index 746af55b..7ac94ae 100644
86405--- a/mm/swapfile.c
86406+++ b/mm/swapfile.c
86407@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
86408
86409 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
86410 /* Activity counter to indicate that a swapon or swapoff has occurred */
86411-static atomic_t proc_poll_event = ATOMIC_INIT(0);
86412+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
86413
86414 static inline unsigned char swap_count(unsigned char ent)
86415 {
86416@@ -1684,7 +1684,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
86417 }
86418 filp_close(swap_file, NULL);
86419 err = 0;
86420- atomic_inc(&proc_poll_event);
86421+ atomic_inc_unchecked(&proc_poll_event);
86422 wake_up_interruptible(&proc_poll_wait);
86423
86424 out_dput:
86425@@ -1701,8 +1701,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
86426
86427 poll_wait(file, &proc_poll_wait, wait);
86428
86429- if (seq->poll_event != atomic_read(&proc_poll_event)) {
86430- seq->poll_event = atomic_read(&proc_poll_event);
86431+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
86432+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
86433 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
86434 }
86435
86436@@ -1800,7 +1800,7 @@ static int swaps_open(struct inode *inode, struct file *file)
86437 return ret;
86438
86439 seq = file->private_data;
86440- seq->poll_event = atomic_read(&proc_poll_event);
86441+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
86442 return 0;
86443 }
86444
86445@@ -2143,7 +2143,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
86446 (frontswap_map) ? "FS" : "");
86447
86448 mutex_unlock(&swapon_mutex);
86449- atomic_inc(&proc_poll_event);
86450+ atomic_inc_unchecked(&proc_poll_event);
86451 wake_up_interruptible(&proc_poll_wait);
86452
86453 if (S_ISREG(inode->i_mode))
86454diff --git a/mm/util.c b/mm/util.c
86455index ab1424d..7c5bd5a 100644
86456--- a/mm/util.c
86457+++ b/mm/util.c
86458@@ -294,6 +294,12 @@ done:
86459 void arch_pick_mmap_layout(struct mm_struct *mm)
86460 {
86461 mm->mmap_base = TASK_UNMAPPED_BASE;
86462+
86463+#ifdef CONFIG_PAX_RANDMMAP
86464+ if (mm->pax_flags & MF_PAX_RANDMMAP)
86465+ mm->mmap_base += mm->delta_mmap;
86466+#endif
86467+
86468 mm->get_unmapped_area = arch_get_unmapped_area;
86469 mm->unmap_area = arch_unmap_area;
86470 }
86471diff --git a/mm/vmalloc.c b/mm/vmalloc.c
86472index d365724..6cae7c2 100644
86473--- a/mm/vmalloc.c
86474+++ b/mm/vmalloc.c
86475@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
86476
86477 pte = pte_offset_kernel(pmd, addr);
86478 do {
86479- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
86480- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
86481+
86482+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86483+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
86484+ BUG_ON(!pte_exec(*pte));
86485+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
86486+ continue;
86487+ }
86488+#endif
86489+
86490+ {
86491+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
86492+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
86493+ }
86494 } while (pte++, addr += PAGE_SIZE, addr != end);
86495 }
86496
86497@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
86498 pte = pte_alloc_kernel(pmd, addr);
86499 if (!pte)
86500 return -ENOMEM;
86501+
86502+ pax_open_kernel();
86503 do {
86504 struct page *page = pages[*nr];
86505
86506- if (WARN_ON(!pte_none(*pte)))
86507+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86508+ if (pgprot_val(prot) & _PAGE_NX)
86509+#endif
86510+
86511+ if (!pte_none(*pte)) {
86512+ pax_close_kernel();
86513+ WARN_ON(1);
86514 return -EBUSY;
86515- if (WARN_ON(!page))
86516+ }
86517+ if (!page) {
86518+ pax_close_kernel();
86519+ WARN_ON(1);
86520 return -ENOMEM;
86521+ }
86522 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
86523 (*nr)++;
86524 } while (pte++, addr += PAGE_SIZE, addr != end);
86525+ pax_close_kernel();
86526 return 0;
86527 }
86528
86529@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
86530 pmd_t *pmd;
86531 unsigned long next;
86532
86533- pmd = pmd_alloc(&init_mm, pud, addr);
86534+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
86535 if (!pmd)
86536 return -ENOMEM;
86537 do {
86538@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
86539 pud_t *pud;
86540 unsigned long next;
86541
86542- pud = pud_alloc(&init_mm, pgd, addr);
86543+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
86544 if (!pud)
86545 return -ENOMEM;
86546 do {
86547@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
86548 if (addr >= MODULES_VADDR && addr < MODULES_END)
86549 return 1;
86550 #endif
86551+
86552+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86553+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
86554+ return 1;
86555+#endif
86556+
86557 return is_vmalloc_addr(x);
86558 }
86559
86560@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
86561
86562 if (!pgd_none(*pgd)) {
86563 pud_t *pud = pud_offset(pgd, addr);
86564+#ifdef CONFIG_X86
86565+ if (!pud_large(*pud))
86566+#endif
86567 if (!pud_none(*pud)) {
86568 pmd_t *pmd = pmd_offset(pud, addr);
86569+#ifdef CONFIG_X86
86570+ if (!pmd_large(*pmd))
86571+#endif
86572 if (!pmd_none(*pmd)) {
86573 pte_t *ptep, pte;
86574
86575@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
86576 * Allocate a region of KVA of the specified size and alignment, within the
86577 * vstart and vend.
86578 */
86579-static struct vmap_area *alloc_vmap_area(unsigned long size,
86580+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
86581 unsigned long align,
86582 unsigned long vstart, unsigned long vend,
86583 int node, gfp_t gfp_mask)
86584@@ -1337,6 +1373,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
86585 struct vm_struct *area;
86586
86587 BUG_ON(in_interrupt());
86588+
86589+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86590+ if (flags & VM_KERNEXEC) {
86591+ if (start != VMALLOC_START || end != VMALLOC_END)
86592+ return NULL;
86593+ start = (unsigned long)MODULES_EXEC_VADDR;
86594+ end = (unsigned long)MODULES_EXEC_END;
86595+ }
86596+#endif
86597+
86598 if (flags & VM_IOREMAP) {
86599 int bit = fls(size);
86600
86601@@ -1581,6 +1627,11 @@ void *vmap(struct page **pages, unsigned int count,
86602 if (count > totalram_pages)
86603 return NULL;
86604
86605+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86606+ if (!(pgprot_val(prot) & _PAGE_NX))
86607+ flags |= VM_KERNEXEC;
86608+#endif
86609+
86610 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
86611 __builtin_return_address(0));
86612 if (!area)
86613@@ -1682,6 +1733,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
86614 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
86615 goto fail;
86616
86617+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86618+ if (!(pgprot_val(prot) & _PAGE_NX))
86619+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
86620+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
86621+ else
86622+#endif
86623+
86624 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
86625 start, end, node, gfp_mask, caller);
86626 if (!area)
86627@@ -1858,10 +1916,9 @@ EXPORT_SYMBOL(vzalloc_node);
86628 * For tight control over page level allocator and protection flags
86629 * use __vmalloc() instead.
86630 */
86631-
86632 void *vmalloc_exec(unsigned long size)
86633 {
86634- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
86635+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
86636 NUMA_NO_NODE, __builtin_return_address(0));
86637 }
86638
86639@@ -2168,6 +2225,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
86640 unsigned long uaddr = vma->vm_start;
86641 unsigned long usize = vma->vm_end - vma->vm_start;
86642
86643+ BUG_ON(vma->vm_mirror);
86644+
86645 if ((PAGE_SIZE-1) & (unsigned long)addr)
86646 return -EINVAL;
86647
86648@@ -2629,7 +2688,11 @@ static int s_show(struct seq_file *m, void *p)
86649 v->addr, v->addr + v->size, v->size);
86650
86651 if (v->caller)
86652+#ifdef CONFIG_GRKERNSEC_HIDESYM
86653+ seq_printf(m, " %pK", v->caller);
86654+#else
86655 seq_printf(m, " %pS", v->caller);
86656+#endif
86657
86658 if (v->nr_pages)
86659 seq_printf(m, " pages=%d", v->nr_pages);
86660diff --git a/mm/vmstat.c b/mm/vmstat.c
86661index f42745e..62f8346 100644
86662--- a/mm/vmstat.c
86663+++ b/mm/vmstat.c
86664@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
86665 *
86666 * vm_stat contains the global counters
86667 */
86668-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
86669+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
86670 EXPORT_SYMBOL(vm_stat);
86671
86672 #ifdef CONFIG_SMP
86673@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
86674 v = p->vm_stat_diff[i];
86675 p->vm_stat_diff[i] = 0;
86676 local_irq_restore(flags);
86677- atomic_long_add(v, &zone->vm_stat[i]);
86678+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
86679 global_diff[i] += v;
86680 #ifdef CONFIG_NUMA
86681 /* 3 seconds idle till flush */
86682@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
86683
86684 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
86685 if (global_diff[i])
86686- atomic_long_add(global_diff[i], &vm_stat[i]);
86687+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
86688 }
86689
86690 /*
86691@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
86692 if (pset->vm_stat_diff[i]) {
86693 int v = pset->vm_stat_diff[i];
86694 pset->vm_stat_diff[i] = 0;
86695- atomic_long_add(v, &zone->vm_stat[i]);
86696- atomic_long_add(v, &vm_stat[i]);
86697+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
86698+ atomic_long_add_unchecked(v, &vm_stat[i]);
86699 }
86700 }
86701 #endif
86702@@ -1226,7 +1226,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
86703 return NOTIFY_OK;
86704 }
86705
86706-static struct notifier_block __cpuinitdata vmstat_notifier =
86707+static struct notifier_block vmstat_notifier =
86708 { &vmstat_cpuup_callback, NULL, 0 };
86709 #endif
86710
86711@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
86712 start_cpu_timer(cpu);
86713 #endif
86714 #ifdef CONFIG_PROC_FS
86715- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
86716- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
86717- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
86718- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
86719+ {
86720+ mode_t gr_mode = S_IRUGO;
86721+#ifdef CONFIG_GRKERNSEC_PROC_ADD
86722+ gr_mode = S_IRUSR;
86723+#endif
86724+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
86725+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
86726+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
86727+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
86728+#else
86729+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
86730+#endif
86731+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
86732+ }
86733 #endif
86734 return 0;
86735 }
86736diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
86737index 9424f37..6aabf19 100644
86738--- a/net/8021q/vlan.c
86739+++ b/net/8021q/vlan.c
86740@@ -469,7 +469,7 @@ out:
86741 return NOTIFY_DONE;
86742 }
86743
86744-static struct notifier_block vlan_notifier_block __read_mostly = {
86745+static struct notifier_block vlan_notifier_block = {
86746 .notifier_call = vlan_device_event,
86747 };
86748
86749@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
86750 err = -EPERM;
86751 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
86752 break;
86753- if ((args.u.name_type >= 0) &&
86754- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
86755+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
86756 struct vlan_net *vn;
86757
86758 vn = net_generic(net, vlan_net_id);
86759diff --git a/net/9p/mod.c b/net/9p/mod.c
86760index 6ab36ae..6f1841b 100644
86761--- a/net/9p/mod.c
86762+++ b/net/9p/mod.c
86763@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
86764 void v9fs_register_trans(struct p9_trans_module *m)
86765 {
86766 spin_lock(&v9fs_trans_lock);
86767- list_add_tail(&m->list, &v9fs_trans_list);
86768+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
86769 spin_unlock(&v9fs_trans_lock);
86770 }
86771 EXPORT_SYMBOL(v9fs_register_trans);
86772@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
86773 void v9fs_unregister_trans(struct p9_trans_module *m)
86774 {
86775 spin_lock(&v9fs_trans_lock);
86776- list_del_init(&m->list);
86777+ pax_list_del_init((struct list_head *)&m->list);
86778 spin_unlock(&v9fs_trans_lock);
86779 }
86780 EXPORT_SYMBOL(v9fs_unregister_trans);
86781diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
86782index 02efb25..41541a9 100644
86783--- a/net/9p/trans_fd.c
86784+++ b/net/9p/trans_fd.c
86785@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
86786 oldfs = get_fs();
86787 set_fs(get_ds());
86788 /* The cast to a user pointer is valid due to the set_fs() */
86789- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
86790+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
86791 set_fs(oldfs);
86792
86793 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
86794diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
86795index 876fbe8..8bbea9f 100644
86796--- a/net/atm/atm_misc.c
86797+++ b/net/atm/atm_misc.c
86798@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
86799 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
86800 return 1;
86801 atm_return(vcc, truesize);
86802- atomic_inc(&vcc->stats->rx_drop);
86803+ atomic_inc_unchecked(&vcc->stats->rx_drop);
86804 return 0;
86805 }
86806 EXPORT_SYMBOL(atm_charge);
86807@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
86808 }
86809 }
86810 atm_return(vcc, guess);
86811- atomic_inc(&vcc->stats->rx_drop);
86812+ atomic_inc_unchecked(&vcc->stats->rx_drop);
86813 return NULL;
86814 }
86815 EXPORT_SYMBOL(atm_alloc_charge);
86816@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
86817
86818 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
86819 {
86820-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
86821+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
86822 __SONET_ITEMS
86823 #undef __HANDLE_ITEM
86824 }
86825@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
86826
86827 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
86828 {
86829-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
86830+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
86831 __SONET_ITEMS
86832 #undef __HANDLE_ITEM
86833 }
86834diff --git a/net/atm/lec.h b/net/atm/lec.h
86835index 4149db1..f2ab682 100644
86836--- a/net/atm/lec.h
86837+++ b/net/atm/lec.h
86838@@ -48,7 +48,7 @@ struct lane2_ops {
86839 const u8 *tlvs, u32 sizeoftlvs);
86840 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
86841 const u8 *tlvs, u32 sizeoftlvs);
86842-};
86843+} __no_const;
86844
86845 /*
86846 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
86847diff --git a/net/atm/proc.c b/net/atm/proc.c
86848index bbb6461..cf04016 100644
86849--- a/net/atm/proc.c
86850+++ b/net/atm/proc.c
86851@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
86852 const struct k_atm_aal_stats *stats)
86853 {
86854 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
86855- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
86856- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
86857- atomic_read(&stats->rx_drop));
86858+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
86859+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
86860+ atomic_read_unchecked(&stats->rx_drop));
86861 }
86862
86863 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
86864diff --git a/net/atm/resources.c b/net/atm/resources.c
86865index 0447d5d..3cf4728 100644
86866--- a/net/atm/resources.c
86867+++ b/net/atm/resources.c
86868@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
86869 static void copy_aal_stats(struct k_atm_aal_stats *from,
86870 struct atm_aal_stats *to)
86871 {
86872-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
86873+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
86874 __AAL_STAT_ITEMS
86875 #undef __HANDLE_ITEM
86876 }
86877@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
86878 static void subtract_aal_stats(struct k_atm_aal_stats *from,
86879 struct atm_aal_stats *to)
86880 {
86881-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
86882+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
86883 __AAL_STAT_ITEMS
86884 #undef __HANDLE_ITEM
86885 }
86886diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
86887index d5744b7..506bae3 100644
86888--- a/net/ax25/sysctl_net_ax25.c
86889+++ b/net/ax25/sysctl_net_ax25.c
86890@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
86891 {
86892 char path[sizeof("net/ax25/") + IFNAMSIZ];
86893 int k;
86894- struct ctl_table *table;
86895+ ctl_table_no_const *table;
86896
86897 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
86898 if (!table)
86899diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
86900index f680ee1..97e3542 100644
86901--- a/net/batman-adv/bat_iv_ogm.c
86902+++ b/net/batman-adv/bat_iv_ogm.c
86903@@ -79,7 +79,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
86904
86905 /* randomize initial seqno to avoid collision */
86906 get_random_bytes(&random_seqno, sizeof(random_seqno));
86907- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
86908+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
86909
86910 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
86911 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
86912@@ -627,9 +627,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
86913 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
86914
86915 /* change sequence number to network order */
86916- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
86917+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
86918 batadv_ogm_packet->seqno = htonl(seqno);
86919- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
86920+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
86921
86922 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
86923 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
86924@@ -1037,7 +1037,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
86925 return;
86926
86927 /* could be changed by schedule_own_packet() */
86928- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
86929+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
86930
86931 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
86932 has_directlink_flag = 1;
86933diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
86934index 522243a..b48c0ef 100644
86935--- a/net/batman-adv/hard-interface.c
86936+++ b/net/batman-adv/hard-interface.c
86937@@ -401,7 +401,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
86938 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
86939 dev_add_pack(&hard_iface->batman_adv_ptype);
86940
86941- atomic_set(&hard_iface->frag_seqno, 1);
86942+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
86943 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
86944 hard_iface->net_dev->name);
86945
86946@@ -550,7 +550,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
86947 /* This can't be called via a bat_priv callback because
86948 * we have no bat_priv yet.
86949 */
86950- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
86951+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
86952 hard_iface->bat_iv.ogm_buff = NULL;
86953
86954 return hard_iface;
86955diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
86956index 819dfb0..9a672d1 100644
86957--- a/net/batman-adv/soft-interface.c
86958+++ b/net/batman-adv/soft-interface.c
86959@@ -253,7 +253,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
86960 primary_if->net_dev->dev_addr, ETH_ALEN);
86961
86962 /* set broadcast sequence number */
86963- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
86964+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
86965 bcast_packet->seqno = htonl(seqno);
86966
86967 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
86968@@ -472,7 +472,7 @@ static int batadv_softif_init_late(struct net_device *dev)
86969 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
86970
86971 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
86972- atomic_set(&bat_priv->bcast_seqno, 1);
86973+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
86974 atomic_set(&bat_priv->tt.vn, 0);
86975 atomic_set(&bat_priv->tt.local_changes, 0);
86976 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
86977diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
86978index aba8364..50fcbb8 100644
86979--- a/net/batman-adv/types.h
86980+++ b/net/batman-adv/types.h
86981@@ -51,7 +51,7 @@
86982 struct batadv_hard_iface_bat_iv {
86983 unsigned char *ogm_buff;
86984 int ogm_buff_len;
86985- atomic_t ogm_seqno;
86986+ atomic_unchecked_t ogm_seqno;
86987 };
86988
86989 /**
86990@@ -75,7 +75,7 @@ struct batadv_hard_iface {
86991 int16_t if_num;
86992 char if_status;
86993 struct net_device *net_dev;
86994- atomic_t frag_seqno;
86995+ atomic_unchecked_t frag_seqno;
86996 struct kobject *hardif_obj;
86997 atomic_t refcount;
86998 struct packet_type batman_adv_ptype;
86999@@ -558,7 +558,7 @@ struct batadv_priv {
87000 #ifdef CONFIG_BATMAN_ADV_DEBUG
87001 atomic_t log_level;
87002 #endif
87003- atomic_t bcast_seqno;
87004+ atomic_unchecked_t bcast_seqno;
87005 atomic_t bcast_queue_left;
87006 atomic_t batman_queue_left;
87007 char num_ifaces;
87008diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
87009index 0bb3b59..ffcbf2f 100644
87010--- a/net/batman-adv/unicast.c
87011+++ b/net/batman-adv/unicast.c
87012@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
87013 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
87014 frag2->flags = large_tail;
87015
87016- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
87017+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
87018 frag1->seqno = htons(seqno - 1);
87019 frag2->seqno = htons(seqno);
87020
87021diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
87022index ace5e55..a65a1c0 100644
87023--- a/net/bluetooth/hci_core.c
87024+++ b/net/bluetooth/hci_core.c
87025@@ -2211,16 +2211,16 @@ int hci_register_dev(struct hci_dev *hdev)
87026 list_add(&hdev->list, &hci_dev_list);
87027 write_unlock(&hci_dev_list_lock);
87028
87029- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
87030- WQ_MEM_RECLAIM, 1);
87031+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
87032+ WQ_MEM_RECLAIM, 1, hdev->name);
87033 if (!hdev->workqueue) {
87034 error = -ENOMEM;
87035 goto err;
87036 }
87037
87038- hdev->req_workqueue = alloc_workqueue(hdev->name,
87039+ hdev->req_workqueue = alloc_workqueue("%s",
87040 WQ_HIGHPRI | WQ_UNBOUND |
87041- WQ_MEM_RECLAIM, 1);
87042+ WQ_MEM_RECLAIM, 1, hdev->name);
87043 if (!hdev->req_workqueue) {
87044 destroy_workqueue(hdev->workqueue);
87045 error = -ENOMEM;
87046diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
87047index 9bd7d95..6c4884f 100644
87048--- a/net/bluetooth/hci_sock.c
87049+++ b/net/bluetooth/hci_sock.c
87050@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
87051 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
87052 }
87053
87054- len = min_t(unsigned int, len, sizeof(uf));
87055+ len = min((size_t)len, sizeof(uf));
87056 if (copy_from_user(&uf, optval, len)) {
87057 err = -EFAULT;
87058 break;
87059diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
87060index 68843a2..30e9342 100644
87061--- a/net/bluetooth/l2cap_core.c
87062+++ b/net/bluetooth/l2cap_core.c
87063@@ -3507,8 +3507,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
87064 break;
87065
87066 case L2CAP_CONF_RFC:
87067- if (olen == sizeof(rfc))
87068- memcpy(&rfc, (void *)val, olen);
87069+ if (olen != sizeof(rfc))
87070+ break;
87071+
87072+ memcpy(&rfc, (void *)val, olen);
87073
87074 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
87075 rfc.mode != chan->mode)
87076diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
87077index 36fed40..be2eeb2 100644
87078--- a/net/bluetooth/l2cap_sock.c
87079+++ b/net/bluetooth/l2cap_sock.c
87080@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
87081 struct sock *sk = sock->sk;
87082 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
87083 struct l2cap_options opts;
87084- int len, err = 0;
87085+ int err = 0;
87086+ size_t len = optlen;
87087 u32 opt;
87088
87089 BT_DBG("sk %p", sk);
87090@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
87091 opts.max_tx = chan->max_tx;
87092 opts.txwin_size = chan->tx_win;
87093
87094- len = min_t(unsigned int, sizeof(opts), optlen);
87095+ len = min(sizeof(opts), len);
87096 if (copy_from_user((char *) &opts, optval, len)) {
87097 err = -EFAULT;
87098 break;
87099@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
87100 struct bt_security sec;
87101 struct bt_power pwr;
87102 struct l2cap_conn *conn;
87103- int len, err = 0;
87104+ int err = 0;
87105+ size_t len = optlen;
87106 u32 opt;
87107
87108 BT_DBG("sk %p", sk);
87109@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
87110
87111 sec.level = BT_SECURITY_LOW;
87112
87113- len = min_t(unsigned int, sizeof(sec), optlen);
87114+ len = min(sizeof(sec), len);
87115 if (copy_from_user((char *) &sec, optval, len)) {
87116 err = -EFAULT;
87117 break;
87118@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
87119
87120 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
87121
87122- len = min_t(unsigned int, sizeof(pwr), optlen);
87123+ len = min(sizeof(pwr), len);
87124 if (copy_from_user((char *) &pwr, optval, len)) {
87125 err = -EFAULT;
87126 break;
87127diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
87128index 30b3721..c1bd0a0 100644
87129--- a/net/bluetooth/rfcomm/sock.c
87130+++ b/net/bluetooth/rfcomm/sock.c
87131@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
87132 struct sock *sk = sock->sk;
87133 struct bt_security sec;
87134 int err = 0;
87135- size_t len;
87136+ size_t len = optlen;
87137 u32 opt;
87138
87139 BT_DBG("sk %p", sk);
87140@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
87141
87142 sec.level = BT_SECURITY_LOW;
87143
87144- len = min_t(unsigned int, sizeof(sec), optlen);
87145+ len = min(sizeof(sec), len);
87146 if (copy_from_user((char *) &sec, optval, len)) {
87147 err = -EFAULT;
87148 break;
87149diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
87150index b6e44ad..5b0d514 100644
87151--- a/net/bluetooth/rfcomm/tty.c
87152+++ b/net/bluetooth/rfcomm/tty.c
87153@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
87154 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
87155
87156 spin_lock_irqsave(&dev->port.lock, flags);
87157- if (dev->port.count > 0) {
87158+ if (atomic_read(&dev->port.count) > 0) {
87159 spin_unlock_irqrestore(&dev->port.lock, flags);
87160 return;
87161 }
87162@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
87163 return -ENODEV;
87164
87165 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
87166- dev->channel, dev->port.count);
87167+ dev->channel, atomic_read(&dev->port.count));
87168
87169 spin_lock_irqsave(&dev->port.lock, flags);
87170- if (++dev->port.count > 1) {
87171+ if (atomic_inc_return(&dev->port.count) > 1) {
87172 spin_unlock_irqrestore(&dev->port.lock, flags);
87173 return 0;
87174 }
87175@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
87176 return;
87177
87178 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
87179- dev->port.count);
87180+ atomic_read(&dev->port.count));
87181
87182 spin_lock_irqsave(&dev->port.lock, flags);
87183- if (!--dev->port.count) {
87184+ if (!atomic_dec_return(&dev->port.count)) {
87185 spin_unlock_irqrestore(&dev->port.lock, flags);
87186 if (dev->tty_dev->parent)
87187 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
87188diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
87189index 3d110c4..4e1b2eb 100644
87190--- a/net/bridge/netfilter/ebtables.c
87191+++ b/net/bridge/netfilter/ebtables.c
87192@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87193 tmp.valid_hooks = t->table->valid_hooks;
87194 }
87195 mutex_unlock(&ebt_mutex);
87196- if (copy_to_user(user, &tmp, *len) != 0){
87197+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
87198 BUGPRINT("c2u Didn't work\n");
87199 ret = -EFAULT;
87200 break;
87201@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
87202 goto out;
87203 tmp.valid_hooks = t->valid_hooks;
87204
87205- if (copy_to_user(user, &tmp, *len) != 0) {
87206+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
87207 ret = -EFAULT;
87208 break;
87209 }
87210@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
87211 tmp.entries_size = t->table->entries_size;
87212 tmp.valid_hooks = t->table->valid_hooks;
87213
87214- if (copy_to_user(user, &tmp, *len) != 0) {
87215+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
87216 ret = -EFAULT;
87217 break;
87218 }
87219diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
87220index 2bd4b58..0dc30a1 100644
87221--- a/net/caif/cfctrl.c
87222+++ b/net/caif/cfctrl.c
87223@@ -10,6 +10,7 @@
87224 #include <linux/spinlock.h>
87225 #include <linux/slab.h>
87226 #include <linux/pkt_sched.h>
87227+#include <linux/sched.h>
87228 #include <net/caif/caif_layer.h>
87229 #include <net/caif/cfpkt.h>
87230 #include <net/caif/cfctrl.h>
87231@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
87232 memset(&dev_info, 0, sizeof(dev_info));
87233 dev_info.id = 0xff;
87234 cfsrvl_init(&this->serv, 0, &dev_info, false);
87235- atomic_set(&this->req_seq_no, 1);
87236- atomic_set(&this->rsp_seq_no, 1);
87237+ atomic_set_unchecked(&this->req_seq_no, 1);
87238+ atomic_set_unchecked(&this->rsp_seq_no, 1);
87239 this->serv.layer.receive = cfctrl_recv;
87240 sprintf(this->serv.layer.name, "ctrl");
87241 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
87242@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
87243 struct cfctrl_request_info *req)
87244 {
87245 spin_lock_bh(&ctrl->info_list_lock);
87246- atomic_inc(&ctrl->req_seq_no);
87247- req->sequence_no = atomic_read(&ctrl->req_seq_no);
87248+ atomic_inc_unchecked(&ctrl->req_seq_no);
87249+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
87250 list_add_tail(&req->list, &ctrl->list);
87251 spin_unlock_bh(&ctrl->info_list_lock);
87252 }
87253@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
87254 if (p != first)
87255 pr_warn("Requests are not received in order\n");
87256
87257- atomic_set(&ctrl->rsp_seq_no,
87258+ atomic_set_unchecked(&ctrl->rsp_seq_no,
87259 p->sequence_no);
87260 list_del(&p->list);
87261 goto out;
87262diff --git a/net/can/af_can.c b/net/can/af_can.c
87263index c4e5085..aa9efdf 100644
87264--- a/net/can/af_can.c
87265+++ b/net/can/af_can.c
87266@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
87267 };
87268
87269 /* notifier block for netdevice event */
87270-static struct notifier_block can_netdev_notifier __read_mostly = {
87271+static struct notifier_block can_netdev_notifier = {
87272 .notifier_call = can_notifier,
87273 };
87274
87275diff --git a/net/can/gw.c b/net/can/gw.c
87276index 3ee690e..00d581b 100644
87277--- a/net/can/gw.c
87278+++ b/net/can/gw.c
87279@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
87280 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
87281
87282 static HLIST_HEAD(cgw_list);
87283-static struct notifier_block notifier;
87284
87285 static struct kmem_cache *cgw_cache __read_mostly;
87286
87287@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
87288 return err;
87289 }
87290
87291+static struct notifier_block notifier = {
87292+ .notifier_call = cgw_notifier
87293+};
87294+
87295 static __init int cgw_module_init(void)
87296 {
87297 /* sanitize given module parameter */
87298@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
87299 return -ENOMEM;
87300
87301 /* set notifier */
87302- notifier.notifier_call = cgw_notifier;
87303 register_netdevice_notifier(&notifier);
87304
87305 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
87306diff --git a/net/compat.c b/net/compat.c
87307index f0a1ba6..0541331 100644
87308--- a/net/compat.c
87309+++ b/net/compat.c
87310@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
87311 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
87312 __get_user(kmsg->msg_flags, &umsg->msg_flags))
87313 return -EFAULT;
87314- kmsg->msg_name = compat_ptr(tmp1);
87315- kmsg->msg_iov = compat_ptr(tmp2);
87316- kmsg->msg_control = compat_ptr(tmp3);
87317+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
87318+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
87319+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
87320 return 0;
87321 }
87322
87323@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
87324
87325 if (kern_msg->msg_namelen) {
87326 if (mode == VERIFY_READ) {
87327- int err = move_addr_to_kernel(kern_msg->msg_name,
87328+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
87329 kern_msg->msg_namelen,
87330 kern_address);
87331 if (err < 0)
87332@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
87333 kern_msg->msg_name = NULL;
87334
87335 tot_len = iov_from_user_compat_to_kern(kern_iov,
87336- (struct compat_iovec __user *)kern_msg->msg_iov,
87337+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
87338 kern_msg->msg_iovlen);
87339 if (tot_len >= 0)
87340 kern_msg->msg_iov = kern_iov;
87341@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
87342
87343 #define CMSG_COMPAT_FIRSTHDR(msg) \
87344 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
87345- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
87346+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
87347 (struct compat_cmsghdr __user *)NULL)
87348
87349 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
87350 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
87351 (ucmlen) <= (unsigned long) \
87352 ((mhdr)->msg_controllen - \
87353- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
87354+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
87355
87356 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
87357 struct compat_cmsghdr __user *cmsg, int cmsg_len)
87358 {
87359 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
87360- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
87361+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
87362 msg->msg_controllen)
87363 return NULL;
87364 return (struct compat_cmsghdr __user *)ptr;
87365@@ -219,7 +219,7 @@ Efault:
87366
87367 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
87368 {
87369- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
87370+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
87371 struct compat_cmsghdr cmhdr;
87372 struct compat_timeval ctv;
87373 struct compat_timespec cts[3];
87374@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
87375
87376 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
87377 {
87378- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
87379+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
87380 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
87381 int fdnum = scm->fp->count;
87382 struct file **fp = scm->fp->fp;
87383@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
87384 return -EFAULT;
87385 old_fs = get_fs();
87386 set_fs(KERNEL_DS);
87387- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
87388+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
87389 set_fs(old_fs);
87390
87391 return err;
87392@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
87393 len = sizeof(ktime);
87394 old_fs = get_fs();
87395 set_fs(KERNEL_DS);
87396- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
87397+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
87398 set_fs(old_fs);
87399
87400 if (!err) {
87401@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
87402 case MCAST_JOIN_GROUP:
87403 case MCAST_LEAVE_GROUP:
87404 {
87405- struct compat_group_req __user *gr32 = (void *)optval;
87406+ struct compat_group_req __user *gr32 = (void __user *)optval;
87407 struct group_req __user *kgr =
87408 compat_alloc_user_space(sizeof(struct group_req));
87409 u32 interface;
87410@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
87411 case MCAST_BLOCK_SOURCE:
87412 case MCAST_UNBLOCK_SOURCE:
87413 {
87414- struct compat_group_source_req __user *gsr32 = (void *)optval;
87415+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
87416 struct group_source_req __user *kgsr = compat_alloc_user_space(
87417 sizeof(struct group_source_req));
87418 u32 interface;
87419@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
87420 }
87421 case MCAST_MSFILTER:
87422 {
87423- struct compat_group_filter __user *gf32 = (void *)optval;
87424+ struct compat_group_filter __user *gf32 = (void __user *)optval;
87425 struct group_filter __user *kgf;
87426 u32 interface, fmode, numsrc;
87427
87428@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
87429 char __user *optval, int __user *optlen,
87430 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
87431 {
87432- struct compat_group_filter __user *gf32 = (void *)optval;
87433+ struct compat_group_filter __user *gf32 = (void __user *)optval;
87434 struct group_filter __user *kgf;
87435 int __user *koptlen;
87436 u32 interface, fmode, numsrc;
87437@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
87438
87439 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
87440 return -EINVAL;
87441- if (copy_from_user(a, args, nas[call]))
87442+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
87443 return -EFAULT;
87444 a0 = a[0];
87445 a1 = a[1];
87446diff --git a/net/core/datagram.c b/net/core/datagram.c
87447index b71423d..0360434 100644
87448--- a/net/core/datagram.c
87449+++ b/net/core/datagram.c
87450@@ -295,7 +295,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
87451 }
87452
87453 kfree_skb(skb);
87454- atomic_inc(&sk->sk_drops);
87455+ atomic_inc_unchecked(&sk->sk_drops);
87456 sk_mem_reclaim_partial(sk);
87457
87458 return err;
87459diff --git a/net/core/dev.c b/net/core/dev.c
87460index 7ddbb31..3902452 100644
87461--- a/net/core/dev.c
87462+++ b/net/core/dev.c
87463@@ -1649,7 +1649,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
87464 {
87465 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
87466 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
87467- atomic_long_inc(&dev->rx_dropped);
87468+ atomic_long_inc_unchecked(&dev->rx_dropped);
87469 kfree_skb(skb);
87470 return NET_RX_DROP;
87471 }
87472@@ -1658,7 +1658,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
87473 skb_orphan(skb);
87474
87475 if (unlikely(!is_skb_forwardable(dev, skb))) {
87476- atomic_long_inc(&dev->rx_dropped);
87477+ atomic_long_inc_unchecked(&dev->rx_dropped);
87478 kfree_skb(skb);
87479 return NET_RX_DROP;
87480 }
87481@@ -2404,7 +2404,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
87482
87483 struct dev_gso_cb {
87484 void (*destructor)(struct sk_buff *skb);
87485-};
87486+} __no_const;
87487
87488 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
87489
87490@@ -3139,7 +3139,7 @@ enqueue:
87491
87492 local_irq_restore(flags);
87493
87494- atomic_long_inc(&skb->dev->rx_dropped);
87495+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
87496 kfree_skb(skb);
87497 return NET_RX_DROP;
87498 }
87499@@ -3211,7 +3211,7 @@ int netif_rx_ni(struct sk_buff *skb)
87500 }
87501 EXPORT_SYMBOL(netif_rx_ni);
87502
87503-static void net_tx_action(struct softirq_action *h)
87504+static void net_tx_action(void)
87505 {
87506 struct softnet_data *sd = &__get_cpu_var(softnet_data);
87507
87508@@ -3545,7 +3545,7 @@ ncls:
87509 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
87510 } else {
87511 drop:
87512- atomic_long_inc(&skb->dev->rx_dropped);
87513+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
87514 kfree_skb(skb);
87515 /* Jamal, now you will not able to escape explaining
87516 * me how you were going to use this. :-)
87517@@ -4153,7 +4153,7 @@ void netif_napi_del(struct napi_struct *napi)
87518 }
87519 EXPORT_SYMBOL(netif_napi_del);
87520
87521-static void net_rx_action(struct softirq_action *h)
87522+static void net_rx_action(void)
87523 {
87524 struct softnet_data *sd = &__get_cpu_var(softnet_data);
87525 unsigned long time_limit = jiffies + 2;
87526@@ -5590,7 +5590,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
87527 } else {
87528 netdev_stats_to_stats64(storage, &dev->stats);
87529 }
87530- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
87531+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
87532 return storage;
87533 }
87534 EXPORT_SYMBOL(dev_get_stats);
87535diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
87536index 5b7d0e1..cb960fc 100644
87537--- a/net/core/dev_ioctl.c
87538+++ b/net/core/dev_ioctl.c
87539@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
87540 if (no_module && capable(CAP_NET_ADMIN))
87541 no_module = request_module("netdev-%s", name);
87542 if (no_module && capable(CAP_SYS_MODULE)) {
87543+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87544+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
87545+#else
87546 if (!request_module("%s", name))
87547 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
87548 name);
87549+#endif
87550 }
87551 }
87552 EXPORT_SYMBOL(dev_load);
87553diff --git a/net/core/ethtool.c b/net/core/ethtool.c
87554index ce91766..3b71cdb 100644
87555--- a/net/core/ethtool.c
87556+++ b/net/core/ethtool.c
87557@@ -1319,10 +1319,19 @@ static int ethtool_get_dump_data(struct net_device *dev,
87558 if (ret)
87559 return ret;
87560
87561- len = (tmp.len > dump.len) ? dump.len : tmp.len;
87562+ len = min(tmp.len, dump.len);
87563 if (!len)
87564 return -EFAULT;
87565
87566+ /* Don't ever let the driver think there's more space available
87567+ * than it requested with .get_dump_flag().
87568+ */
87569+ dump.len = len;
87570+
87571+ /* Always allocate enough space to hold the whole thing so that the
87572+ * driver does not need to check the length and bother with partial
87573+ * dumping.
87574+ */
87575 data = vzalloc(tmp.len);
87576 if (!data)
87577 return -ENOMEM;
87578@@ -1330,6 +1339,16 @@ static int ethtool_get_dump_data(struct net_device *dev,
87579 if (ret)
87580 goto out;
87581
87582+ /* There are two sane possibilities:
87583+ * 1. The driver's .get_dump_data() does not touch dump.len.
87584+ * 2. Or it may set dump.len to how much it really writes, which
87585+ * should be tmp.len (or len if it can do a partial dump).
87586+ * In any case respond to userspace with the actual length of data
87587+ * it's receiving.
87588+ */
87589+ WARN_ON(dump.len != len && dump.len != tmp.len);
87590+ dump.len = len;
87591+
87592 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
87593 ret = -EFAULT;
87594 goto out;
87595diff --git a/net/core/flow.c b/net/core/flow.c
87596index 7102f16..146b4bd 100644
87597--- a/net/core/flow.c
87598+++ b/net/core/flow.c
87599@@ -61,7 +61,7 @@ struct flow_cache {
87600 struct timer_list rnd_timer;
87601 };
87602
87603-atomic_t flow_cache_genid = ATOMIC_INIT(0);
87604+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
87605 EXPORT_SYMBOL(flow_cache_genid);
87606 static struct flow_cache flow_cache_global;
87607 static struct kmem_cache *flow_cachep __read_mostly;
87608@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
87609
87610 static int flow_entry_valid(struct flow_cache_entry *fle)
87611 {
87612- if (atomic_read(&flow_cache_genid) != fle->genid)
87613+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
87614 return 0;
87615 if (fle->object && !fle->object->ops->check(fle->object))
87616 return 0;
87617@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
87618 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
87619 fcp->hash_count++;
87620 }
87621- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
87622+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
87623 flo = fle->object;
87624 if (!flo)
87625 goto ret_object;
87626@@ -279,7 +279,7 @@ nocache:
87627 }
87628 flo = resolver(net, key, family, dir, flo, ctx);
87629 if (fle) {
87630- fle->genid = atomic_read(&flow_cache_genid);
87631+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
87632 if (!IS_ERR(flo))
87633 fle->object = flo;
87634 else
87635diff --git a/net/core/iovec.c b/net/core/iovec.c
87636index de178e4..1dabd8b 100644
87637--- a/net/core/iovec.c
87638+++ b/net/core/iovec.c
87639@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
87640 if (m->msg_namelen) {
87641 if (mode == VERIFY_READ) {
87642 void __user *namep;
87643- namep = (void __user __force *) m->msg_name;
87644+ namep = (void __force_user *) m->msg_name;
87645 err = move_addr_to_kernel(namep, m->msg_namelen,
87646 address);
87647 if (err < 0)
87648@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
87649 }
87650
87651 size = m->msg_iovlen * sizeof(struct iovec);
87652- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
87653+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
87654 return -EFAULT;
87655
87656 m->msg_iov = iov;
87657diff --git a/net/core/neighbour.c b/net/core/neighbour.c
87658index ce90b02..8752627 100644
87659--- a/net/core/neighbour.c
87660+++ b/net/core/neighbour.c
87661@@ -2771,7 +2771,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
87662 size_t *lenp, loff_t *ppos)
87663 {
87664 int size, ret;
87665- ctl_table tmp = *ctl;
87666+ ctl_table_no_const tmp = *ctl;
87667
87668 tmp.extra1 = &zero;
87669 tmp.extra2 = &unres_qlen_max;
87670diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
87671index 569d355..79cf2d0 100644
87672--- a/net/core/net-procfs.c
87673+++ b/net/core/net-procfs.c
87674@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
87675 else
87676 seq_printf(seq, "%04x", ntohs(pt->type));
87677
87678+#ifdef CONFIG_GRKERNSEC_HIDESYM
87679+ seq_printf(seq, " %-8s %pf\n",
87680+ pt->dev ? pt->dev->name : "", NULL);
87681+#else
87682 seq_printf(seq, " %-8s %pf\n",
87683 pt->dev ? pt->dev->name : "", pt->func);
87684+#endif
87685 }
87686
87687 return 0;
87688diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
87689index 981fed3..536af34 100644
87690--- a/net/core/net-sysfs.c
87691+++ b/net/core/net-sysfs.c
87692@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
87693 }
87694 EXPORT_SYMBOL(netdev_class_remove_file);
87695
87696-int netdev_kobject_init(void)
87697+int __init netdev_kobject_init(void)
87698 {
87699 kobj_ns_type_register(&net_ns_type_operations);
87700 return class_register(&net_class);
87701diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
87702index f9765203..9feaef8 100644
87703--- a/net/core/net_namespace.c
87704+++ b/net/core/net_namespace.c
87705@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
87706 int error;
87707 LIST_HEAD(net_exit_list);
87708
87709- list_add_tail(&ops->list, list);
87710+ pax_list_add_tail((struct list_head *)&ops->list, list);
87711 if (ops->init || (ops->id && ops->size)) {
87712 for_each_net(net) {
87713 error = ops_init(ops, net);
87714@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
87715
87716 out_undo:
87717 /* If I have an error cleanup all namespaces I initialized */
87718- list_del(&ops->list);
87719+ pax_list_del((struct list_head *)&ops->list);
87720 ops_exit_list(ops, &net_exit_list);
87721 ops_free_list(ops, &net_exit_list);
87722 return error;
87723@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
87724 struct net *net;
87725 LIST_HEAD(net_exit_list);
87726
87727- list_del(&ops->list);
87728+ pax_list_del((struct list_head *)&ops->list);
87729 for_each_net(net)
87730 list_add_tail(&net->exit_list, &net_exit_list);
87731 ops_exit_list(ops, &net_exit_list);
87732@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
87733 mutex_lock(&net_mutex);
87734 error = register_pernet_operations(&pernet_list, ops);
87735 if (!error && (first_device == &pernet_list))
87736- first_device = &ops->list;
87737+ first_device = (struct list_head *)&ops->list;
87738 mutex_unlock(&net_mutex);
87739 return error;
87740 }
87741diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
87742index a08bd2b..4e8f43c 100644
87743--- a/net/core/rtnetlink.c
87744+++ b/net/core/rtnetlink.c
87745@@ -58,7 +58,7 @@ struct rtnl_link {
87746 rtnl_doit_func doit;
87747 rtnl_dumpit_func dumpit;
87748 rtnl_calcit_func calcit;
87749-};
87750+} __no_const;
87751
87752 static DEFINE_MUTEX(rtnl_mutex);
87753
87754@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
87755 if (rtnl_link_ops_get(ops->kind))
87756 return -EEXIST;
87757
87758- if (!ops->dellink)
87759- ops->dellink = unregister_netdevice_queue;
87760+ if (!ops->dellink) {
87761+ pax_open_kernel();
87762+ *(void **)&ops->dellink = unregister_netdevice_queue;
87763+ pax_close_kernel();
87764+ }
87765
87766- list_add_tail(&ops->list, &link_ops);
87767+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
87768 return 0;
87769 }
87770 EXPORT_SYMBOL_GPL(__rtnl_link_register);
87771@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
87772 for_each_net(net) {
87773 __rtnl_kill_links(net, ops);
87774 }
87775- list_del(&ops->list);
87776+ pax_list_del((struct list_head *)&ops->list);
87777 }
87778 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
87779
87780diff --git a/net/core/scm.c b/net/core/scm.c
87781index 03795d0..eaf7368 100644
87782--- a/net/core/scm.c
87783+++ b/net/core/scm.c
87784@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
87785 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
87786 {
87787 struct cmsghdr __user *cm
87788- = (__force struct cmsghdr __user *)msg->msg_control;
87789+ = (struct cmsghdr __force_user *)msg->msg_control;
87790 struct cmsghdr cmhdr;
87791 int cmlen = CMSG_LEN(len);
87792 int err;
87793@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
87794 err = -EFAULT;
87795 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
87796 goto out;
87797- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
87798+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
87799 goto out;
87800 cmlen = CMSG_SPACE(len);
87801 if (msg->msg_controllen < cmlen)
87802@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
87803 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
87804 {
87805 struct cmsghdr __user *cm
87806- = (__force struct cmsghdr __user*)msg->msg_control;
87807+ = (struct cmsghdr __force_user *)msg->msg_control;
87808
87809 int fdmax = 0;
87810 int fdnum = scm->fp->count;
87811@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
87812 if (fdnum < fdmax)
87813 fdmax = fdnum;
87814
87815- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
87816+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
87817 i++, cmfptr++)
87818 {
87819 struct socket *sock;
87820diff --git a/net/core/skbuff.c b/net/core/skbuff.c
87821index 1c1738c..4cab7f0 100644
87822--- a/net/core/skbuff.c
87823+++ b/net/core/skbuff.c
87824@@ -3087,13 +3087,15 @@ void __init skb_init(void)
87825 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
87826 sizeof(struct sk_buff),
87827 0,
87828- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
87829+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
87830+ SLAB_NO_SANITIZE,
87831 NULL);
87832 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
87833 (2*sizeof(struct sk_buff)) +
87834 sizeof(atomic_t),
87835 0,
87836- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
87837+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
87838+ SLAB_NO_SANITIZE,
87839 NULL);
87840 }
87841
87842diff --git a/net/core/sock.c b/net/core/sock.c
87843index d6d024c..6ea7ab4 100644
87844--- a/net/core/sock.c
87845+++ b/net/core/sock.c
87846@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87847 struct sk_buff_head *list = &sk->sk_receive_queue;
87848
87849 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
87850- atomic_inc(&sk->sk_drops);
87851+ atomic_inc_unchecked(&sk->sk_drops);
87852 trace_sock_rcvqueue_full(sk, skb);
87853 return -ENOMEM;
87854 }
87855@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87856 return err;
87857
87858 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
87859- atomic_inc(&sk->sk_drops);
87860+ atomic_inc_unchecked(&sk->sk_drops);
87861 return -ENOBUFS;
87862 }
87863
87864@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
87865 skb_dst_force(skb);
87866
87867 spin_lock_irqsave(&list->lock, flags);
87868- skb->dropcount = atomic_read(&sk->sk_drops);
87869+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
87870 __skb_queue_tail(list, skb);
87871 spin_unlock_irqrestore(&list->lock, flags);
87872
87873@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
87874 skb->dev = NULL;
87875
87876 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
87877- atomic_inc(&sk->sk_drops);
87878+ atomic_inc_unchecked(&sk->sk_drops);
87879 goto discard_and_relse;
87880 }
87881 if (nested)
87882@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
87883 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
87884 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
87885 bh_unlock_sock(sk);
87886- atomic_inc(&sk->sk_drops);
87887+ atomic_inc_unchecked(&sk->sk_drops);
87888 goto discard_and_relse;
87889 }
87890
87891@@ -933,12 +933,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
87892 struct timeval tm;
87893 } v;
87894
87895- int lv = sizeof(int);
87896- int len;
87897+ unsigned int lv = sizeof(int);
87898+ unsigned int len;
87899
87900 if (get_user(len, optlen))
87901 return -EFAULT;
87902- if (len < 0)
87903+ if (len > INT_MAX)
87904 return -EINVAL;
87905
87906 memset(&v, 0, sizeof(v));
87907@@ -1090,11 +1090,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
87908
87909 case SO_PEERNAME:
87910 {
87911- char address[128];
87912+ char address[_K_SS_MAXSIZE];
87913
87914 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
87915 return -ENOTCONN;
87916- if (lv < len)
87917+ if (lv < len || sizeof address < len)
87918 return -EINVAL;
87919 if (copy_to_user(optval, address, len))
87920 return -EFAULT;
87921@@ -1161,7 +1161,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
87922
87923 if (len > lv)
87924 len = lv;
87925- if (copy_to_user(optval, &v, len))
87926+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
87927 return -EFAULT;
87928 lenout:
87929 if (put_user(len, optlen))
87930@@ -2277,7 +2277,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
87931 */
87932 smp_wmb();
87933 atomic_set(&sk->sk_refcnt, 1);
87934- atomic_set(&sk->sk_drops, 0);
87935+ atomic_set_unchecked(&sk->sk_drops, 0);
87936 }
87937 EXPORT_SYMBOL(sock_init_data);
87938
87939diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
87940index a0e9cf6..ef7f9ed 100644
87941--- a/net/core/sock_diag.c
87942+++ b/net/core/sock_diag.c
87943@@ -9,26 +9,33 @@
87944 #include <linux/inet_diag.h>
87945 #include <linux/sock_diag.h>
87946
87947-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
87948+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
87949 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
87950 static DEFINE_MUTEX(sock_diag_table_mutex);
87951
87952 int sock_diag_check_cookie(void *sk, __u32 *cookie)
87953 {
87954+#ifndef CONFIG_GRKERNSEC_HIDESYM
87955 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
87956 cookie[1] != INET_DIAG_NOCOOKIE) &&
87957 ((u32)(unsigned long)sk != cookie[0] ||
87958 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
87959 return -ESTALE;
87960 else
87961+#endif
87962 return 0;
87963 }
87964 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
87965
87966 void sock_diag_save_cookie(void *sk, __u32 *cookie)
87967 {
87968+#ifdef CONFIG_GRKERNSEC_HIDESYM
87969+ cookie[0] = 0;
87970+ cookie[1] = 0;
87971+#else
87972 cookie[0] = (u32)(unsigned long)sk;
87973 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
87974+#endif
87975 }
87976 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
87977
87978@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
87979 mutex_lock(&sock_diag_table_mutex);
87980 if (sock_diag_handlers[hndl->family])
87981 err = -EBUSY;
87982- else
87983+ else {
87984+ pax_open_kernel();
87985 sock_diag_handlers[hndl->family] = hndl;
87986+ pax_close_kernel();
87987+ }
87988 mutex_unlock(&sock_diag_table_mutex);
87989
87990 return err;
87991@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
87992
87993 mutex_lock(&sock_diag_table_mutex);
87994 BUG_ON(sock_diag_handlers[family] != hnld);
87995+ pax_open_kernel();
87996 sock_diag_handlers[family] = NULL;
87997+ pax_close_kernel();
87998 mutex_unlock(&sock_diag_table_mutex);
87999 }
88000 EXPORT_SYMBOL_GPL(sock_diag_unregister);
88001diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
88002index cfdb46a..cef55e1 100644
88003--- a/net/core/sysctl_net_core.c
88004+++ b/net/core/sysctl_net_core.c
88005@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
88006 {
88007 unsigned int orig_size, size;
88008 int ret, i;
88009- ctl_table tmp = {
88010+ ctl_table_no_const tmp = {
88011 .data = &size,
88012 .maxlen = sizeof(size),
88013 .mode = table->mode
88014@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
88015
88016 static __net_init int sysctl_core_net_init(struct net *net)
88017 {
88018- struct ctl_table *tbl;
88019+ ctl_table_no_const *tbl = NULL;
88020
88021 net->core.sysctl_somaxconn = SOMAXCONN;
88022
88023- tbl = netns_core_table;
88024 if (!net_eq(net, &init_net)) {
88025- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
88026+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
88027 if (tbl == NULL)
88028 goto err_dup;
88029
88030@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
88031 if (net->user_ns != &init_user_ns) {
88032 tbl[0].procname = NULL;
88033 }
88034- }
88035-
88036- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
88037+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
88038+ } else
88039+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
88040 if (net->core.sysctl_hdr == NULL)
88041 goto err_reg;
88042
88043 return 0;
88044
88045 err_reg:
88046- if (tbl != netns_core_table)
88047- kfree(tbl);
88048+ kfree(tbl);
88049 err_dup:
88050 return -ENOMEM;
88051 }
88052@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
88053 kfree(tbl);
88054 }
88055
88056-static __net_initdata struct pernet_operations sysctl_core_ops = {
88057+static __net_initconst struct pernet_operations sysctl_core_ops = {
88058 .init = sysctl_core_net_init,
88059 .exit = sysctl_core_net_exit,
88060 };
88061diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
88062index c21f200..bc4565b 100644
88063--- a/net/decnet/af_decnet.c
88064+++ b/net/decnet/af_decnet.c
88065@@ -465,6 +465,7 @@ static struct proto dn_proto = {
88066 .sysctl_rmem = sysctl_decnet_rmem,
88067 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
88068 .obj_size = sizeof(struct dn_sock),
88069+ .slab_flags = SLAB_USERCOPY,
88070 };
88071
88072 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
88073diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
88074index a55eecc..dd8428c 100644
88075--- a/net/decnet/sysctl_net_decnet.c
88076+++ b/net/decnet/sysctl_net_decnet.c
88077@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
88078
88079 if (len > *lenp) len = *lenp;
88080
88081- if (copy_to_user(buffer, addr, len))
88082+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
88083 return -EFAULT;
88084
88085 *lenp = len;
88086@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
88087
88088 if (len > *lenp) len = *lenp;
88089
88090- if (copy_to_user(buffer, devname, len))
88091+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
88092 return -EFAULT;
88093
88094 *lenp = len;
88095diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
88096index d01be2a..8976537 100644
88097--- a/net/ipv4/af_inet.c
88098+++ b/net/ipv4/af_inet.c
88099@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
88100
88101 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
88102
88103- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
88104- if (!sysctl_local_reserved_ports)
88105- goto out;
88106-
88107 rc = proto_register(&tcp_prot, 1);
88108 if (rc)
88109- goto out_free_reserved_ports;
88110+ goto out;
88111
88112 rc = proto_register(&udp_prot, 1);
88113 if (rc)
88114@@ -1818,8 +1814,6 @@ out_unregister_udp_proto:
88115 proto_unregister(&udp_prot);
88116 out_unregister_tcp_proto:
88117 proto_unregister(&tcp_prot);
88118-out_free_reserved_ports:
88119- kfree(sysctl_local_reserved_ports);
88120 goto out;
88121 }
88122
88123diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
88124index 2e7f194..0fa4d6d 100644
88125--- a/net/ipv4/ah4.c
88126+++ b/net/ipv4/ah4.c
88127@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
88128 return;
88129
88130 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
88131- atomic_inc(&flow_cache_genid);
88132+ atomic_inc_unchecked(&flow_cache_genid);
88133 rt_genid_bump(net);
88134
88135 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
88136diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
88137index dfc39d4..0d4fa52 100644
88138--- a/net/ipv4/devinet.c
88139+++ b/net/ipv4/devinet.c
88140@@ -771,7 +771,7 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
88141 ci = nla_data(tb[IFA_CACHEINFO]);
88142 if (!ci->ifa_valid || ci->ifa_prefered > ci->ifa_valid) {
88143 err = -EINVAL;
88144- goto errout;
88145+ goto errout_free;
88146 }
88147 *pvalid_lft = ci->ifa_valid;
88148 *pprefered_lft = ci->ifa_prefered;
88149@@ -779,6 +779,8 @@ static struct in_ifaddr *rtm_to_ifaddr(struct net *net, struct nlmsghdr *nlh,
88150
88151 return ifa;
88152
88153+errout_free:
88154+ inet_free_ifa(ifa);
88155 errout:
88156 return ERR_PTR(err);
88157 }
88158@@ -1529,7 +1531,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
88159 idx = 0;
88160 head = &net->dev_index_head[h];
88161 rcu_read_lock();
88162- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
88163+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
88164 net->dev_base_seq;
88165 hlist_for_each_entry_rcu(dev, head, index_hlist) {
88166 if (idx < s_idx)
88167@@ -1840,7 +1842,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
88168 idx = 0;
88169 head = &net->dev_index_head[h];
88170 rcu_read_lock();
88171- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
88172+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
88173 net->dev_base_seq;
88174 hlist_for_each_entry_rcu(dev, head, index_hlist) {
88175 if (idx < s_idx)
88176@@ -2065,7 +2067,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
88177 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
88178 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
88179
88180-static struct devinet_sysctl_table {
88181+static const struct devinet_sysctl_table {
88182 struct ctl_table_header *sysctl_header;
88183 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
88184 } devinet_sysctl = {
88185@@ -2183,7 +2185,7 @@ static __net_init int devinet_init_net(struct net *net)
88186 int err;
88187 struct ipv4_devconf *all, *dflt;
88188 #ifdef CONFIG_SYSCTL
88189- struct ctl_table *tbl = ctl_forward_entry;
88190+ ctl_table_no_const *tbl = NULL;
88191 struct ctl_table_header *forw_hdr;
88192 #endif
88193
88194@@ -2201,7 +2203,7 @@ static __net_init int devinet_init_net(struct net *net)
88195 goto err_alloc_dflt;
88196
88197 #ifdef CONFIG_SYSCTL
88198- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
88199+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
88200 if (tbl == NULL)
88201 goto err_alloc_ctl;
88202
88203@@ -2221,7 +2223,10 @@ static __net_init int devinet_init_net(struct net *net)
88204 goto err_reg_dflt;
88205
88206 err = -ENOMEM;
88207- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
88208+ if (!net_eq(net, &init_net))
88209+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
88210+ else
88211+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
88212 if (forw_hdr == NULL)
88213 goto err_reg_ctl;
88214 net->ipv4.forw_hdr = forw_hdr;
88215@@ -2237,8 +2242,7 @@ err_reg_ctl:
88216 err_reg_dflt:
88217 __devinet_sysctl_unregister(all);
88218 err_reg_all:
88219- if (tbl != ctl_forward_entry)
88220- kfree(tbl);
88221+ kfree(tbl);
88222 err_alloc_ctl:
88223 #endif
88224 if (dflt != &ipv4_devconf_dflt)
88225diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
88226index 4cfe34d..a6ba66e 100644
88227--- a/net/ipv4/esp4.c
88228+++ b/net/ipv4/esp4.c
88229@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
88230 return;
88231
88232 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
88233- atomic_inc(&flow_cache_genid);
88234+ atomic_inc_unchecked(&flow_cache_genid);
88235 rt_genid_bump(net);
88236
88237 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
88238diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
88239index c7629a2..b62d139 100644
88240--- a/net/ipv4/fib_frontend.c
88241+++ b/net/ipv4/fib_frontend.c
88242@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
88243 #ifdef CONFIG_IP_ROUTE_MULTIPATH
88244 fib_sync_up(dev);
88245 #endif
88246- atomic_inc(&net->ipv4.dev_addr_genid);
88247+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
88248 rt_cache_flush(dev_net(dev));
88249 break;
88250 case NETDEV_DOWN:
88251 fib_del_ifaddr(ifa, NULL);
88252- atomic_inc(&net->ipv4.dev_addr_genid);
88253+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
88254 if (ifa->ifa_dev->ifa_list == NULL) {
88255 /* Last address was deleted from this interface.
88256 * Disable IP.
88257@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
88258 #ifdef CONFIG_IP_ROUTE_MULTIPATH
88259 fib_sync_up(dev);
88260 #endif
88261- atomic_inc(&net->ipv4.dev_addr_genid);
88262+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
88263 rt_cache_flush(net);
88264 break;
88265 case NETDEV_DOWN:
88266diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
88267index 8f6cb7a..34507f9 100644
88268--- a/net/ipv4/fib_semantics.c
88269+++ b/net/ipv4/fib_semantics.c
88270@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
88271 nh->nh_saddr = inet_select_addr(nh->nh_dev,
88272 nh->nh_gw,
88273 nh->nh_parent->fib_scope);
88274- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
88275+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
88276
88277 return nh->nh_saddr;
88278 }
88279diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
88280index 6acb541..9ea617d 100644
88281--- a/net/ipv4/inet_connection_sock.c
88282+++ b/net/ipv4/inet_connection_sock.c
88283@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
88284 .range = { 32768, 61000 },
88285 };
88286
88287-unsigned long *sysctl_local_reserved_ports;
88288+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
88289 EXPORT_SYMBOL(sysctl_local_reserved_ports);
88290
88291 void inet_get_local_port_range(int *low, int *high)
88292diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
88293index 6af375a..c493c74 100644
88294--- a/net/ipv4/inet_hashtables.c
88295+++ b/net/ipv4/inet_hashtables.c
88296@@ -18,12 +18,15 @@
88297 #include <linux/sched.h>
88298 #include <linux/slab.h>
88299 #include <linux/wait.h>
88300+#include <linux/security.h>
88301
88302 #include <net/inet_connection_sock.h>
88303 #include <net/inet_hashtables.h>
88304 #include <net/secure_seq.h>
88305 #include <net/ip.h>
88306
88307+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
88308+
88309 /*
88310 * Allocate and initialize a new local port bind bucket.
88311 * The bindhash mutex for snum's hash chain must be held here.
88312@@ -554,6 +557,8 @@ ok:
88313 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
88314 spin_unlock(&head->lock);
88315
88316+ gr_update_task_in_ip_table(current, inet_sk(sk));
88317+
88318 if (tw) {
88319 inet_twsk_deschedule(tw, death_row);
88320 while (twrefcnt) {
88321diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
88322index 000e3d2..5472da3 100644
88323--- a/net/ipv4/inetpeer.c
88324+++ b/net/ipv4/inetpeer.c
88325@@ -503,8 +503,8 @@ relookup:
88326 if (p) {
88327 p->daddr = *daddr;
88328 atomic_set(&p->refcnt, 1);
88329- atomic_set(&p->rid, 0);
88330- atomic_set(&p->ip_id_count,
88331+ atomic_set_unchecked(&p->rid, 0);
88332+ atomic_set_unchecked(&p->ip_id_count,
88333 (daddr->family == AF_INET) ?
88334 secure_ip_id(daddr->addr.a4) :
88335 secure_ipv6_id(daddr->addr.a6));
88336diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
88337index b66910a..cfe416e 100644
88338--- a/net/ipv4/ip_fragment.c
88339+++ b/net/ipv4/ip_fragment.c
88340@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
88341 return 0;
88342
88343 start = qp->rid;
88344- end = atomic_inc_return(&peer->rid);
88345+ end = atomic_inc_return_unchecked(&peer->rid);
88346 qp->rid = end;
88347
88348 rc = qp->q.fragments && (end - start) > max;
88349@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
88350
88351 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
88352 {
88353- struct ctl_table *table;
88354+ ctl_table_no_const *table = NULL;
88355 struct ctl_table_header *hdr;
88356
88357- table = ip4_frags_ns_ctl_table;
88358 if (!net_eq(net, &init_net)) {
88359- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
88360+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
88361 if (table == NULL)
88362 goto err_alloc;
88363
88364@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
88365 /* Don't export sysctls to unprivileged users */
88366 if (net->user_ns != &init_user_ns)
88367 table[0].procname = NULL;
88368- }
88369+ hdr = register_net_sysctl(net, "net/ipv4", table);
88370+ } else
88371+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
88372
88373- hdr = register_net_sysctl(net, "net/ipv4", table);
88374 if (hdr == NULL)
88375 goto err_reg;
88376
88377@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
88378 return 0;
88379
88380 err_reg:
88381- if (!net_eq(net, &init_net))
88382- kfree(table);
88383+ kfree(table);
88384 err_alloc:
88385 return -ENOMEM;
88386 }
88387diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
88388index 855004f..68e7458 100644
88389--- a/net/ipv4/ip_gre.c
88390+++ b/net/ipv4/ip_gre.c
88391@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
88392 module_param(log_ecn_error, bool, 0644);
88393 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
88394
88395-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
88396+static struct rtnl_link_ops ipgre_link_ops;
88397 static int ipgre_tunnel_init(struct net_device *dev);
88398
88399 static int ipgre_net_id __read_mostly;
88400@@ -919,7 +919,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
88401 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
88402 };
88403
88404-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
88405+static struct rtnl_link_ops ipgre_link_ops = {
88406 .kind = "gre",
88407 .maxtype = IFLA_GRE_MAX,
88408 .policy = ipgre_policy,
88409@@ -933,7 +933,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
88410 .fill_info = ipgre_fill_info,
88411 };
88412
88413-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
88414+static struct rtnl_link_ops ipgre_tap_ops = {
88415 .kind = "gretap",
88416 .maxtype = IFLA_GRE_MAX,
88417 .policy = ipgre_policy,
88418diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
88419index d9c4f11..02b82dbc 100644
88420--- a/net/ipv4/ip_sockglue.c
88421+++ b/net/ipv4/ip_sockglue.c
88422@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
88423 len = min_t(unsigned int, len, opt->optlen);
88424 if (put_user(len, optlen))
88425 return -EFAULT;
88426- if (copy_to_user(optval, opt->__data, len))
88427+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
88428+ copy_to_user(optval, opt->__data, len))
88429 return -EFAULT;
88430 return 0;
88431 }
88432@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
88433 if (sk->sk_type != SOCK_STREAM)
88434 return -ENOPROTOOPT;
88435
88436- msg.msg_control = optval;
88437+ msg.msg_control = (void __force_kernel *)optval;
88438 msg.msg_controllen = len;
88439 msg.msg_flags = flags;
88440
88441diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
88442index 17cc0ff..63856c4 100644
88443--- a/net/ipv4/ip_vti.c
88444+++ b/net/ipv4/ip_vti.c
88445@@ -47,7 +47,7 @@
88446 #define HASH_SIZE 16
88447 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
88448
88449-static struct rtnl_link_ops vti_link_ops __read_mostly;
88450+static struct rtnl_link_ops vti_link_ops;
88451
88452 static int vti_net_id __read_mostly;
88453 struct vti_net {
88454@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
88455 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
88456 };
88457
88458-static struct rtnl_link_ops vti_link_ops __read_mostly = {
88459+static struct rtnl_link_ops vti_link_ops = {
88460 .kind = "vti",
88461 .maxtype = IFLA_VTI_MAX,
88462 .policy = vti_policy,
88463diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
88464index 59cb8c7..a72160c 100644
88465--- a/net/ipv4/ipcomp.c
88466+++ b/net/ipv4/ipcomp.c
88467@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
88468 return;
88469
88470 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
88471- atomic_inc(&flow_cache_genid);
88472+ atomic_inc_unchecked(&flow_cache_genid);
88473 rt_genid_bump(net);
88474
88475 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
88476diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
88477index efa1138..20dbba0 100644
88478--- a/net/ipv4/ipconfig.c
88479+++ b/net/ipv4/ipconfig.c
88480@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
88481
88482 mm_segment_t oldfs = get_fs();
88483 set_fs(get_ds());
88484- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
88485+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
88486 set_fs(oldfs);
88487 return res;
88488 }
88489@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
88490
88491 mm_segment_t oldfs = get_fs();
88492 set_fs(get_ds());
88493- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
88494+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
88495 set_fs(oldfs);
88496 return res;
88497 }
88498@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
88499
88500 mm_segment_t oldfs = get_fs();
88501 set_fs(get_ds());
88502- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
88503+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
88504 set_fs(oldfs);
88505 return res;
88506 }
88507diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
88508index 7cfc456..e726868 100644
88509--- a/net/ipv4/ipip.c
88510+++ b/net/ipv4/ipip.c
88511@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
88512 static int ipip_net_id __read_mostly;
88513
88514 static int ipip_tunnel_init(struct net_device *dev);
88515-static struct rtnl_link_ops ipip_link_ops __read_mostly;
88516+static struct rtnl_link_ops ipip_link_ops;
88517
88518 static int ipip_err(struct sk_buff *skb, u32 info)
88519 {
88520@@ -406,7 +406,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
88521 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
88522 };
88523
88524-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
88525+static struct rtnl_link_ops ipip_link_ops = {
88526 .kind = "ipip",
88527 .maxtype = IFLA_IPTUN_MAX,
88528 .policy = ipip_policy,
88529diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
88530index 85a4f21..1beb1f5 100644
88531--- a/net/ipv4/netfilter/arp_tables.c
88532+++ b/net/ipv4/netfilter/arp_tables.c
88533@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
88534 #endif
88535
88536 static int get_info(struct net *net, void __user *user,
88537- const int *len, int compat)
88538+ int len, int compat)
88539 {
88540 char name[XT_TABLE_MAXNAMELEN];
88541 struct xt_table *t;
88542 int ret;
88543
88544- if (*len != sizeof(struct arpt_getinfo)) {
88545- duprintf("length %u != %Zu\n", *len,
88546+ if (len != sizeof(struct arpt_getinfo)) {
88547+ duprintf("length %u != %Zu\n", len,
88548 sizeof(struct arpt_getinfo));
88549 return -EINVAL;
88550 }
88551@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
88552 info.size = private->size;
88553 strcpy(info.name, name);
88554
88555- if (copy_to_user(user, &info, *len) != 0)
88556+ if (copy_to_user(user, &info, len) != 0)
88557 ret = -EFAULT;
88558 else
88559 ret = 0;
88560@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
88561
88562 switch (cmd) {
88563 case ARPT_SO_GET_INFO:
88564- ret = get_info(sock_net(sk), user, len, 1);
88565+ ret = get_info(sock_net(sk), user, *len, 1);
88566 break;
88567 case ARPT_SO_GET_ENTRIES:
88568 ret = compat_get_entries(sock_net(sk), user, len);
88569@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
88570
88571 switch (cmd) {
88572 case ARPT_SO_GET_INFO:
88573- ret = get_info(sock_net(sk), user, len, 0);
88574+ ret = get_info(sock_net(sk), user, *len, 0);
88575 break;
88576
88577 case ARPT_SO_GET_ENTRIES:
88578diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
88579index d23118d..6ad7277 100644
88580--- a/net/ipv4/netfilter/ip_tables.c
88581+++ b/net/ipv4/netfilter/ip_tables.c
88582@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
88583 #endif
88584
88585 static int get_info(struct net *net, void __user *user,
88586- const int *len, int compat)
88587+ int len, int compat)
88588 {
88589 char name[XT_TABLE_MAXNAMELEN];
88590 struct xt_table *t;
88591 int ret;
88592
88593- if (*len != sizeof(struct ipt_getinfo)) {
88594- duprintf("length %u != %zu\n", *len,
88595+ if (len != sizeof(struct ipt_getinfo)) {
88596+ duprintf("length %u != %zu\n", len,
88597 sizeof(struct ipt_getinfo));
88598 return -EINVAL;
88599 }
88600@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
88601 info.size = private->size;
88602 strcpy(info.name, name);
88603
88604- if (copy_to_user(user, &info, *len) != 0)
88605+ if (copy_to_user(user, &info, len) != 0)
88606 ret = -EFAULT;
88607 else
88608 ret = 0;
88609@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88610
88611 switch (cmd) {
88612 case IPT_SO_GET_INFO:
88613- ret = get_info(sock_net(sk), user, len, 1);
88614+ ret = get_info(sock_net(sk), user, *len, 1);
88615 break;
88616 case IPT_SO_GET_ENTRIES:
88617 ret = compat_get_entries(sock_net(sk), user, len);
88618@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88619
88620 switch (cmd) {
88621 case IPT_SO_GET_INFO:
88622- ret = get_info(sock_net(sk), user, len, 0);
88623+ ret = get_info(sock_net(sk), user, *len, 0);
88624 break;
88625
88626 case IPT_SO_GET_ENTRIES:
88627diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
88628index 7d93d62..cbbf2a3 100644
88629--- a/net/ipv4/ping.c
88630+++ b/net/ipv4/ping.c
88631@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
88632 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
88633 0, sock_i_ino(sp),
88634 atomic_read(&sp->sk_refcnt), sp,
88635- atomic_read(&sp->sk_drops), len);
88636+ atomic_read_unchecked(&sp->sk_drops), len);
88637 }
88638
88639 static int ping_seq_show(struct seq_file *seq, void *v)
88640diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
88641index dd44e0a..06dcca4 100644
88642--- a/net/ipv4/raw.c
88643+++ b/net/ipv4/raw.c
88644@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
88645 int raw_rcv(struct sock *sk, struct sk_buff *skb)
88646 {
88647 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
88648- atomic_inc(&sk->sk_drops);
88649+ atomic_inc_unchecked(&sk->sk_drops);
88650 kfree_skb(skb);
88651 return NET_RX_DROP;
88652 }
88653@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
88654
88655 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
88656 {
88657+ struct icmp_filter filter;
88658+
88659 if (optlen > sizeof(struct icmp_filter))
88660 optlen = sizeof(struct icmp_filter);
88661- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
88662+ if (copy_from_user(&filter, optval, optlen))
88663 return -EFAULT;
88664+ raw_sk(sk)->filter = filter;
88665 return 0;
88666 }
88667
88668 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
88669 {
88670 int len, ret = -EFAULT;
88671+ struct icmp_filter filter;
88672
88673 if (get_user(len, optlen))
88674 goto out;
88675@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
88676 if (len > sizeof(struct icmp_filter))
88677 len = sizeof(struct icmp_filter);
88678 ret = -EFAULT;
88679- if (put_user(len, optlen) ||
88680- copy_to_user(optval, &raw_sk(sk)->filter, len))
88681+ filter = raw_sk(sk)->filter;
88682+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
88683 goto out;
88684 ret = 0;
88685 out: return ret;
88686@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88687 0, 0L, 0,
88688 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88689 0, sock_i_ino(sp),
88690- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88691+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88692 }
88693
88694 static int raw_seq_show(struct seq_file *seq, void *v)
88695diff --git a/net/ipv4/route.c b/net/ipv4/route.c
88696index d35bbf0..faa3ab8 100644
88697--- a/net/ipv4/route.c
88698+++ b/net/ipv4/route.c
88699@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
88700 .maxlen = sizeof(int),
88701 .mode = 0200,
88702 .proc_handler = ipv4_sysctl_rtcache_flush,
88703+ .extra1 = &init_net,
88704 },
88705 { },
88706 };
88707
88708 static __net_init int sysctl_route_net_init(struct net *net)
88709 {
88710- struct ctl_table *tbl;
88711+ ctl_table_no_const *tbl = NULL;
88712
88713- tbl = ipv4_route_flush_table;
88714 if (!net_eq(net, &init_net)) {
88715- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
88716+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
88717 if (tbl == NULL)
88718 goto err_dup;
88719
88720 /* Don't export sysctls to unprivileged users */
88721 if (net->user_ns != &init_user_ns)
88722 tbl[0].procname = NULL;
88723- }
88724- tbl[0].extra1 = net;
88725+ tbl[0].extra1 = net;
88726+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
88727+ } else
88728+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
88729
88730- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
88731 if (net->ipv4.route_hdr == NULL)
88732 goto err_reg;
88733 return 0;
88734
88735 err_reg:
88736- if (tbl != ipv4_route_flush_table)
88737- kfree(tbl);
88738+ kfree(tbl);
88739 err_dup:
88740 return -ENOMEM;
88741 }
88742@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
88743
88744 static __net_init int rt_genid_init(struct net *net)
88745 {
88746- atomic_set(&net->rt_genid, 0);
88747+ atomic_set_unchecked(&net->rt_genid, 0);
88748 get_random_bytes(&net->ipv4.dev_addr_genid,
88749 sizeof(net->ipv4.dev_addr_genid));
88750 return 0;
88751diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
88752index fa2f63f..6554815 100644
88753--- a/net/ipv4/sysctl_net_ipv4.c
88754+++ b/net/ipv4/sysctl_net_ipv4.c
88755@@ -55,7 +55,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
88756 {
88757 int ret;
88758 int range[2];
88759- ctl_table tmp = {
88760+ ctl_table_no_const tmp = {
88761 .data = &range,
88762 .maxlen = sizeof(range),
88763 .mode = table->mode,
88764@@ -108,7 +108,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
88765 int ret;
88766 gid_t urange[2];
88767 kgid_t low, high;
88768- ctl_table tmp = {
88769+ ctl_table_no_const tmp = {
88770 .data = &urange,
88771 .maxlen = sizeof(urange),
88772 .mode = table->mode,
88773@@ -139,7 +139,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
88774 void __user *buffer, size_t *lenp, loff_t *ppos)
88775 {
88776 char val[TCP_CA_NAME_MAX];
88777- ctl_table tbl = {
88778+ ctl_table_no_const tbl = {
88779 .data = val,
88780 .maxlen = TCP_CA_NAME_MAX,
88781 };
88782@@ -158,7 +158,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
88783 void __user *buffer, size_t *lenp,
88784 loff_t *ppos)
88785 {
88786- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
88787+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
88788 int ret;
88789
88790 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
88791@@ -175,7 +175,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
88792 void __user *buffer, size_t *lenp,
88793 loff_t *ppos)
88794 {
88795- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
88796+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
88797 int ret;
88798
88799 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
88800@@ -201,15 +201,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
88801 struct mem_cgroup *memcg;
88802 #endif
88803
88804- ctl_table tmp = {
88805+ ctl_table_no_const tmp = {
88806 .data = &vec,
88807 .maxlen = sizeof(vec),
88808 .mode = ctl->mode,
88809 };
88810
88811 if (!write) {
88812- ctl->data = &net->ipv4.sysctl_tcp_mem;
88813- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
88814+ ctl_table_no_const tcp_mem = *ctl;
88815+
88816+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
88817+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
88818 }
88819
88820 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
88821@@ -236,7 +238,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
88822 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
88823 size_t *lenp, loff_t *ppos)
88824 {
88825- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
88826+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
88827 struct tcp_fastopen_context *ctxt;
88828 int ret;
88829 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
88830@@ -477,7 +479,7 @@ static struct ctl_table ipv4_table[] = {
88831 },
88832 {
88833 .procname = "ip_local_reserved_ports",
88834- .data = NULL, /* initialized in sysctl_ipv4_init */
88835+ .data = sysctl_local_reserved_ports,
88836 .maxlen = 65536,
88837 .mode = 0644,
88838 .proc_handler = proc_do_large_bitmap,
88839@@ -842,11 +844,10 @@ static struct ctl_table ipv4_net_table[] = {
88840
88841 static __net_init int ipv4_sysctl_init_net(struct net *net)
88842 {
88843- struct ctl_table *table;
88844+ ctl_table_no_const *table = NULL;
88845
88846- table = ipv4_net_table;
88847 if (!net_eq(net, &init_net)) {
88848- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
88849+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
88850 if (table == NULL)
88851 goto err_alloc;
88852
88853@@ -881,15 +882,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
88854
88855 tcp_init_mem(net);
88856
88857- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
88858+ if (!net_eq(net, &init_net))
88859+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
88860+ else
88861+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
88862 if (net->ipv4.ipv4_hdr == NULL)
88863 goto err_reg;
88864
88865 return 0;
88866
88867 err_reg:
88868- if (!net_eq(net, &init_net))
88869- kfree(table);
88870+ kfree(table);
88871 err_alloc:
88872 return -ENOMEM;
88873 }
88874@@ -911,16 +914,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
88875 static __init int sysctl_ipv4_init(void)
88876 {
88877 struct ctl_table_header *hdr;
88878- struct ctl_table *i;
88879-
88880- for (i = ipv4_table; i->procname; i++) {
88881- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
88882- i->data = sysctl_local_reserved_ports;
88883- break;
88884- }
88885- }
88886- if (!i->procname)
88887- return -EINVAL;
88888
88889 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
88890 if (hdr == NULL)
88891diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
88892index 9c62257..651cc27 100644
88893--- a/net/ipv4/tcp_input.c
88894+++ b/net/ipv4/tcp_input.c
88895@@ -4436,7 +4436,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
88896 * simplifies code)
88897 */
88898 static void
88899-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
88900+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
88901 struct sk_buff *head, struct sk_buff *tail,
88902 u32 start, u32 end)
88903 {
88904@@ -5522,6 +5522,7 @@ discard:
88905 tcp_paws_reject(&tp->rx_opt, 0))
88906 goto discard_and_undo;
88907
88908+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
88909 if (th->syn) {
88910 /* We see SYN without ACK. It is attempt of
88911 * simultaneous connect with crossed SYNs.
88912@@ -5572,6 +5573,7 @@ discard:
88913 goto discard;
88914 #endif
88915 }
88916+#endif
88917 /* "fifth, if neither of the SYN or RST bits is set then
88918 * drop the segment and return."
88919 */
88920@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
88921 goto discard;
88922
88923 if (th->syn) {
88924- if (th->fin)
88925+ if (th->fin || th->urg || th->psh)
88926 goto discard;
88927 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
88928 return 1;
88929diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
88930index 7999fc5..c812f42 100644
88931--- a/net/ipv4/tcp_ipv4.c
88932+++ b/net/ipv4/tcp_ipv4.c
88933@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
88934 EXPORT_SYMBOL(sysctl_tcp_low_latency);
88935
88936
88937+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88938+extern int grsec_enable_blackhole;
88939+#endif
88940+
88941 #ifdef CONFIG_TCP_MD5SIG
88942 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
88943 __be32 daddr, __be32 saddr, const struct tcphdr *th);
88944@@ -1855,6 +1859,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
88945 return 0;
88946
88947 reset:
88948+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88949+ if (!grsec_enable_blackhole)
88950+#endif
88951 tcp_v4_send_reset(rsk, skb);
88952 discard:
88953 kfree_skb(skb);
88954@@ -2000,12 +2007,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
88955 TCP_SKB_CB(skb)->sacked = 0;
88956
88957 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88958- if (!sk)
88959+ if (!sk) {
88960+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88961+ ret = 1;
88962+#endif
88963 goto no_tcp_socket;
88964-
88965+ }
88966 process:
88967- if (sk->sk_state == TCP_TIME_WAIT)
88968+ if (sk->sk_state == TCP_TIME_WAIT) {
88969+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88970+ ret = 2;
88971+#endif
88972 goto do_time_wait;
88973+ }
88974
88975 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
88976 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88977@@ -2058,6 +2072,10 @@ csum_error:
88978 bad_packet:
88979 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88980 } else {
88981+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88982+ if (!grsec_enable_blackhole || (ret == 1 &&
88983+ (skb->dev->flags & IFF_LOOPBACK)))
88984+#endif
88985 tcp_v4_send_reset(NULL, skb);
88986 }
88987
88988diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
88989index 0f01788..d52a859 100644
88990--- a/net/ipv4/tcp_minisocks.c
88991+++ b/net/ipv4/tcp_minisocks.c
88992@@ -27,6 +27,10 @@
88993 #include <net/inet_common.h>
88994 #include <net/xfrm.h>
88995
88996+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88997+extern int grsec_enable_blackhole;
88998+#endif
88999+
89000 int sysctl_tcp_syncookies __read_mostly = 1;
89001 EXPORT_SYMBOL(sysctl_tcp_syncookies);
89002
89003@@ -717,7 +721,10 @@ embryonic_reset:
89004 * avoid becoming vulnerable to outside attack aiming at
89005 * resetting legit local connections.
89006 */
89007- req->rsk_ops->send_reset(sk, skb);
89008+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89009+ if (!grsec_enable_blackhole)
89010+#endif
89011+ req->rsk_ops->send_reset(sk, skb);
89012 } else if (fastopen) { /* received a valid RST pkt */
89013 reqsk_fastopen_remove(sk, req, true);
89014 tcp_reset(sk);
89015diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
89016index d4943f6..e7a74a5 100644
89017--- a/net/ipv4/tcp_probe.c
89018+++ b/net/ipv4/tcp_probe.c
89019@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
89020 if (cnt + width >= len)
89021 break;
89022
89023- if (copy_to_user(buf + cnt, tbuf, width))
89024+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
89025 return -EFAULT;
89026 cnt += width;
89027 }
89028diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
89029index 4b85e6f..22f9ac9 100644
89030--- a/net/ipv4/tcp_timer.c
89031+++ b/net/ipv4/tcp_timer.c
89032@@ -22,6 +22,10 @@
89033 #include <linux/gfp.h>
89034 #include <net/tcp.h>
89035
89036+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89037+extern int grsec_lastack_retries;
89038+#endif
89039+
89040 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
89041 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
89042 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
89043@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
89044 }
89045 }
89046
89047+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89048+ if ((sk->sk_state == TCP_LAST_ACK) &&
89049+ (grsec_lastack_retries > 0) &&
89050+ (grsec_lastack_retries < retry_until))
89051+ retry_until = grsec_lastack_retries;
89052+#endif
89053+
89054 if (retransmits_timed_out(sk, retry_until,
89055 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
89056 /* Has it gone just too far? */
89057diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
89058index 93b731d..5a2dd92 100644
89059--- a/net/ipv4/udp.c
89060+++ b/net/ipv4/udp.c
89061@@ -87,6 +87,7 @@
89062 #include <linux/types.h>
89063 #include <linux/fcntl.h>
89064 #include <linux/module.h>
89065+#include <linux/security.h>
89066 #include <linux/socket.h>
89067 #include <linux/sockios.h>
89068 #include <linux/igmp.h>
89069@@ -111,6 +112,10 @@
89070 #include <trace/events/skb.h>
89071 #include "udp_impl.h"
89072
89073+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89074+extern int grsec_enable_blackhole;
89075+#endif
89076+
89077 struct udp_table udp_table __read_mostly;
89078 EXPORT_SYMBOL(udp_table);
89079
89080@@ -594,6 +599,9 @@ found:
89081 return s;
89082 }
89083
89084+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
89085+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
89086+
89087 /*
89088 * This routine is called by the ICMP module when it gets some
89089 * sort of error condition. If err < 0 then the socket should
89090@@ -890,9 +898,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
89091 dport = usin->sin_port;
89092 if (dport == 0)
89093 return -EINVAL;
89094+
89095+ err = gr_search_udp_sendmsg(sk, usin);
89096+ if (err)
89097+ return err;
89098 } else {
89099 if (sk->sk_state != TCP_ESTABLISHED)
89100 return -EDESTADDRREQ;
89101+
89102+ err = gr_search_udp_sendmsg(sk, NULL);
89103+ if (err)
89104+ return err;
89105+
89106 daddr = inet->inet_daddr;
89107 dport = inet->inet_dport;
89108 /* Open fast path for connected socket.
89109@@ -1136,7 +1153,7 @@ static unsigned int first_packet_length(struct sock *sk)
89110 IS_UDPLITE(sk));
89111 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
89112 IS_UDPLITE(sk));
89113- atomic_inc(&sk->sk_drops);
89114+ atomic_inc_unchecked(&sk->sk_drops);
89115 __skb_unlink(skb, rcvq);
89116 __skb_queue_tail(&list_kill, skb);
89117 }
89118@@ -1222,6 +1239,10 @@ try_again:
89119 if (!skb)
89120 goto out;
89121
89122+ err = gr_search_udp_recvmsg(sk, skb);
89123+ if (err)
89124+ goto out_free;
89125+
89126 ulen = skb->len - sizeof(struct udphdr);
89127 copied = len;
89128 if (copied > ulen)
89129@@ -1255,7 +1276,7 @@ try_again:
89130 if (unlikely(err)) {
89131 trace_kfree_skb(skb, udp_recvmsg);
89132 if (!peeked) {
89133- atomic_inc(&sk->sk_drops);
89134+ atomic_inc_unchecked(&sk->sk_drops);
89135 UDP_INC_STATS_USER(sock_net(sk),
89136 UDP_MIB_INERRORS, is_udplite);
89137 }
89138@@ -1542,7 +1563,7 @@ csum_error:
89139 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
89140 drop:
89141 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
89142- atomic_inc(&sk->sk_drops);
89143+ atomic_inc_unchecked(&sk->sk_drops);
89144 kfree_skb(skb);
89145 return -1;
89146 }
89147@@ -1561,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
89148 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
89149
89150 if (!skb1) {
89151- atomic_inc(&sk->sk_drops);
89152+ atomic_inc_unchecked(&sk->sk_drops);
89153 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
89154 IS_UDPLITE(sk));
89155 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
89156@@ -1730,6 +1751,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
89157 goto csum_error;
89158
89159 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
89160+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89161+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
89162+#endif
89163 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
89164
89165 /*
89166@@ -2160,7 +2184,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
89167 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
89168 0, sock_i_ino(sp),
89169 atomic_read(&sp->sk_refcnt), sp,
89170- atomic_read(&sp->sk_drops), len);
89171+ atomic_read_unchecked(&sp->sk_drops), len);
89172 }
89173
89174 int udp4_seq_show(struct seq_file *seq, void *v)
89175diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
89176index 9a459be..086b866 100644
89177--- a/net/ipv4/xfrm4_policy.c
89178+++ b/net/ipv4/xfrm4_policy.c
89179@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
89180
89181 static int __net_init xfrm4_net_init(struct net *net)
89182 {
89183- struct ctl_table *table;
89184+ ctl_table_no_const *table = NULL;
89185 struct ctl_table_header *hdr;
89186
89187- table = xfrm4_policy_table;
89188 if (!net_eq(net, &init_net)) {
89189- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
89190+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
89191 if (!table)
89192 goto err_alloc;
89193
89194 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
89195- }
89196-
89197- hdr = register_net_sysctl(net, "net/ipv4", table);
89198+ hdr = register_net_sysctl(net, "net/ipv4", table);
89199+ } else
89200+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
89201 if (!hdr)
89202 goto err_reg;
89203
89204@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
89205 return 0;
89206
89207 err_reg:
89208- if (!net_eq(net, &init_net))
89209- kfree(table);
89210+ kfree(table);
89211 err_alloc:
89212 return -ENOMEM;
89213 }
89214diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
89215index fb8c94c..fb18024 100644
89216--- a/net/ipv6/addrconf.c
89217+++ b/net/ipv6/addrconf.c
89218@@ -621,7 +621,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
89219 idx = 0;
89220 head = &net->dev_index_head[h];
89221 rcu_read_lock();
89222- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
89223+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
89224 net->dev_base_seq;
89225 hlist_for_each_entry_rcu(dev, head, index_hlist) {
89226 if (idx < s_idx)
89227@@ -2380,7 +2380,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
89228 p.iph.ihl = 5;
89229 p.iph.protocol = IPPROTO_IPV6;
89230 p.iph.ttl = 64;
89231- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
89232+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
89233
89234 if (ops->ndo_do_ioctl) {
89235 mm_segment_t oldfs = get_fs();
89236@@ -4002,7 +4002,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
89237 s_ip_idx = ip_idx = cb->args[2];
89238
89239 rcu_read_lock();
89240- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
89241+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
89242 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
89243 idx = 0;
89244 head = &net->dev_index_head[h];
89245@@ -4587,7 +4587,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
89246 dst_free(&ifp->rt->dst);
89247 break;
89248 }
89249- atomic_inc(&net->ipv6.dev_addr_genid);
89250+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
89251 }
89252
89253 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
89254@@ -4607,7 +4607,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
89255 int *valp = ctl->data;
89256 int val = *valp;
89257 loff_t pos = *ppos;
89258- ctl_table lctl;
89259+ ctl_table_no_const lctl;
89260 int ret;
89261
89262 /*
89263@@ -4689,7 +4689,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
89264 int *valp = ctl->data;
89265 int val = *valp;
89266 loff_t pos = *ppos;
89267- ctl_table lctl;
89268+ ctl_table_no_const lctl;
89269 int ret;
89270
89271 /*
89272diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
89273index b4ff0a4..db9b764 100644
89274--- a/net/ipv6/icmp.c
89275+++ b/net/ipv6/icmp.c
89276@@ -980,7 +980,7 @@ ctl_table ipv6_icmp_table_template[] = {
89277
89278 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
89279 {
89280- struct ctl_table *table;
89281+ ctl_table_no_const *table;
89282
89283 table = kmemdup(ipv6_icmp_table_template,
89284 sizeof(ipv6_icmp_table_template),
89285diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
89286index ecd6073..58162ae 100644
89287--- a/net/ipv6/ip6_gre.c
89288+++ b/net/ipv6/ip6_gre.c
89289@@ -74,7 +74,7 @@ struct ip6gre_net {
89290 struct net_device *fb_tunnel_dev;
89291 };
89292
89293-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
89294+static struct rtnl_link_ops ip6gre_link_ops;
89295 static int ip6gre_tunnel_init(struct net_device *dev);
89296 static void ip6gre_tunnel_setup(struct net_device *dev);
89297 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
89298@@ -1283,7 +1283,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
89299 }
89300
89301
89302-static struct inet6_protocol ip6gre_protocol __read_mostly = {
89303+static struct inet6_protocol ip6gre_protocol = {
89304 .handler = ip6gre_rcv,
89305 .err_handler = ip6gre_err,
89306 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
89307@@ -1617,7 +1617,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
89308 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
89309 };
89310
89311-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
89312+static struct rtnl_link_ops ip6gre_link_ops = {
89313 .kind = "ip6gre",
89314 .maxtype = IFLA_GRE_MAX,
89315 .policy = ip6gre_policy,
89316@@ -1630,7 +1630,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
89317 .fill_info = ip6gre_fill_info,
89318 };
89319
89320-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
89321+static struct rtnl_link_ops ip6gre_tap_ops = {
89322 .kind = "ip6gretap",
89323 .maxtype = IFLA_GRE_MAX,
89324 .policy = ip6gre_policy,
89325diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
89326index 1e55866..b398dab 100644
89327--- a/net/ipv6/ip6_tunnel.c
89328+++ b/net/ipv6/ip6_tunnel.c
89329@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
89330
89331 static int ip6_tnl_dev_init(struct net_device *dev);
89332 static void ip6_tnl_dev_setup(struct net_device *dev);
89333-static struct rtnl_link_ops ip6_link_ops __read_mostly;
89334+static struct rtnl_link_ops ip6_link_ops;
89335
89336 static int ip6_tnl_net_id __read_mostly;
89337 struct ip6_tnl_net {
89338@@ -1672,7 +1672,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
89339 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
89340 };
89341
89342-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
89343+static struct rtnl_link_ops ip6_link_ops = {
89344 .kind = "ip6tnl",
89345 .maxtype = IFLA_IPTUN_MAX,
89346 .policy = ip6_tnl_policy,
89347diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
89348index d1e2e8e..51c19ae 100644
89349--- a/net/ipv6/ipv6_sockglue.c
89350+++ b/net/ipv6/ipv6_sockglue.c
89351@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
89352 if (sk->sk_type != SOCK_STREAM)
89353 return -ENOPROTOOPT;
89354
89355- msg.msg_control = optval;
89356+ msg.msg_control = (void __force_kernel *)optval;
89357 msg.msg_controllen = len;
89358 msg.msg_flags = flags;
89359
89360diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
89361index 44400c2..8e11f52 100644
89362--- a/net/ipv6/netfilter/ip6_tables.c
89363+++ b/net/ipv6/netfilter/ip6_tables.c
89364@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
89365 #endif
89366
89367 static int get_info(struct net *net, void __user *user,
89368- const int *len, int compat)
89369+ int len, int compat)
89370 {
89371 char name[XT_TABLE_MAXNAMELEN];
89372 struct xt_table *t;
89373 int ret;
89374
89375- if (*len != sizeof(struct ip6t_getinfo)) {
89376- duprintf("length %u != %zu\n", *len,
89377+ if (len != sizeof(struct ip6t_getinfo)) {
89378+ duprintf("length %u != %zu\n", len,
89379 sizeof(struct ip6t_getinfo));
89380 return -EINVAL;
89381 }
89382@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
89383 info.size = private->size;
89384 strcpy(info.name, name);
89385
89386- if (copy_to_user(user, &info, *len) != 0)
89387+ if (copy_to_user(user, &info, len) != 0)
89388 ret = -EFAULT;
89389 else
89390 ret = 0;
89391@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
89392
89393 switch (cmd) {
89394 case IP6T_SO_GET_INFO:
89395- ret = get_info(sock_net(sk), user, len, 1);
89396+ ret = get_info(sock_net(sk), user, *len, 1);
89397 break;
89398 case IP6T_SO_GET_ENTRIES:
89399 ret = compat_get_entries(sock_net(sk), user, len);
89400@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
89401
89402 switch (cmd) {
89403 case IP6T_SO_GET_INFO:
89404- ret = get_info(sock_net(sk), user, len, 0);
89405+ ret = get_info(sock_net(sk), user, *len, 0);
89406 break;
89407
89408 case IP6T_SO_GET_ENTRIES:
89409diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
89410index dffdc1a..ccc6678 100644
89411--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
89412+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
89413@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
89414
89415 static int nf_ct_frag6_sysctl_register(struct net *net)
89416 {
89417- struct ctl_table *table;
89418+ ctl_table_no_const *table = NULL;
89419 struct ctl_table_header *hdr;
89420
89421- table = nf_ct_frag6_sysctl_table;
89422 if (!net_eq(net, &init_net)) {
89423- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
89424+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
89425 GFP_KERNEL);
89426 if (table == NULL)
89427 goto err_alloc;
89428@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
89429 table[0].data = &net->nf_frag.frags.timeout;
89430 table[1].data = &net->nf_frag.frags.low_thresh;
89431 table[2].data = &net->nf_frag.frags.high_thresh;
89432- }
89433-
89434- hdr = register_net_sysctl(net, "net/netfilter", table);
89435+ hdr = register_net_sysctl(net, "net/netfilter", table);
89436+ } else
89437+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
89438 if (hdr == NULL)
89439 goto err_reg;
89440
89441@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
89442 return 0;
89443
89444 err_reg:
89445- if (!net_eq(net, &init_net))
89446- kfree(table);
89447+ kfree(table);
89448 err_alloc:
89449 return -ENOMEM;
89450 }
89451diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
89452index eedff8c..6e13a47 100644
89453--- a/net/ipv6/raw.c
89454+++ b/net/ipv6/raw.c
89455@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
89456 {
89457 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
89458 skb_checksum_complete(skb)) {
89459- atomic_inc(&sk->sk_drops);
89460+ atomic_inc_unchecked(&sk->sk_drops);
89461 kfree_skb(skb);
89462 return NET_RX_DROP;
89463 }
89464@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
89465 struct raw6_sock *rp = raw6_sk(sk);
89466
89467 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
89468- atomic_inc(&sk->sk_drops);
89469+ atomic_inc_unchecked(&sk->sk_drops);
89470 kfree_skb(skb);
89471 return NET_RX_DROP;
89472 }
89473@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
89474
89475 if (inet->hdrincl) {
89476 if (skb_checksum_complete(skb)) {
89477- atomic_inc(&sk->sk_drops);
89478+ atomic_inc_unchecked(&sk->sk_drops);
89479 kfree_skb(skb);
89480 return NET_RX_DROP;
89481 }
89482@@ -602,7 +602,7 @@ out:
89483 return err;
89484 }
89485
89486-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
89487+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
89488 struct flowi6 *fl6, struct dst_entry **dstp,
89489 unsigned int flags)
89490 {
89491@@ -914,12 +914,15 @@ do_confirm:
89492 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
89493 char __user *optval, int optlen)
89494 {
89495+ struct icmp6_filter filter;
89496+
89497 switch (optname) {
89498 case ICMPV6_FILTER:
89499 if (optlen > sizeof(struct icmp6_filter))
89500 optlen = sizeof(struct icmp6_filter);
89501- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
89502+ if (copy_from_user(&filter, optval, optlen))
89503 return -EFAULT;
89504+ raw6_sk(sk)->filter = filter;
89505 return 0;
89506 default:
89507 return -ENOPROTOOPT;
89508@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
89509 char __user *optval, int __user *optlen)
89510 {
89511 int len;
89512+ struct icmp6_filter filter;
89513
89514 switch (optname) {
89515 case ICMPV6_FILTER:
89516@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
89517 len = sizeof(struct icmp6_filter);
89518 if (put_user(len, optlen))
89519 return -EFAULT;
89520- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
89521+ filter = raw6_sk(sk)->filter;
89522+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
89523 return -EFAULT;
89524 return 0;
89525 default:
89526@@ -1251,7 +1256,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
89527 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
89528 0,
89529 sock_i_ino(sp),
89530- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
89531+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
89532 }
89533
89534 static int raw6_seq_show(struct seq_file *seq, void *v)
89535diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
89536index 790d9f4..68ae078 100644
89537--- a/net/ipv6/reassembly.c
89538+++ b/net/ipv6/reassembly.c
89539@@ -621,12 +621,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
89540
89541 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
89542 {
89543- struct ctl_table *table;
89544+ ctl_table_no_const *table = NULL;
89545 struct ctl_table_header *hdr;
89546
89547- table = ip6_frags_ns_ctl_table;
89548 if (!net_eq(net, &init_net)) {
89549- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
89550+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
89551 if (table == NULL)
89552 goto err_alloc;
89553
89554@@ -637,9 +636,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
89555 /* Don't export sysctls to unprivileged users */
89556 if (net->user_ns != &init_user_ns)
89557 table[0].procname = NULL;
89558- }
89559+ hdr = register_net_sysctl(net, "net/ipv6", table);
89560+ } else
89561+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
89562
89563- hdr = register_net_sysctl(net, "net/ipv6", table);
89564 if (hdr == NULL)
89565 goto err_reg;
89566
89567@@ -647,8 +647,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
89568 return 0;
89569
89570 err_reg:
89571- if (!net_eq(net, &init_net))
89572- kfree(table);
89573+ kfree(table);
89574 err_alloc:
89575 return -ENOMEM;
89576 }
89577diff --git a/net/ipv6/route.c b/net/ipv6/route.c
89578index bacce6c..9d1741a 100644
89579--- a/net/ipv6/route.c
89580+++ b/net/ipv6/route.c
89581@@ -2903,7 +2903,7 @@ ctl_table ipv6_route_table_template[] = {
89582
89583 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
89584 {
89585- struct ctl_table *table;
89586+ ctl_table_no_const *table;
89587
89588 table = kmemdup(ipv6_route_table_template,
89589 sizeof(ipv6_route_table_template),
89590diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
89591index 60df36d..f3ab7c8 100644
89592--- a/net/ipv6/sit.c
89593+++ b/net/ipv6/sit.c
89594@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
89595 static void ipip6_dev_free(struct net_device *dev);
89596 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
89597 __be32 *v4dst);
89598-static struct rtnl_link_ops sit_link_ops __read_mostly;
89599+static struct rtnl_link_ops sit_link_ops;
89600
89601 static int sit_net_id __read_mostly;
89602 struct sit_net {
89603@@ -1453,7 +1453,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
89604 #endif
89605 };
89606
89607-static struct rtnl_link_ops sit_link_ops __read_mostly = {
89608+static struct rtnl_link_ops sit_link_ops = {
89609 .kind = "sit",
89610 .maxtype = IFLA_IPTUN_MAX,
89611 .policy = ipip6_policy,
89612diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
89613index e85c48b..b8268d3 100644
89614--- a/net/ipv6/sysctl_net_ipv6.c
89615+++ b/net/ipv6/sysctl_net_ipv6.c
89616@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
89617
89618 static int __net_init ipv6_sysctl_net_init(struct net *net)
89619 {
89620- struct ctl_table *ipv6_table;
89621+ ctl_table_no_const *ipv6_table;
89622 struct ctl_table *ipv6_route_table;
89623 struct ctl_table *ipv6_icmp_table;
89624 int err;
89625diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
89626index 0a17ed9..2526cc3 100644
89627--- a/net/ipv6/tcp_ipv6.c
89628+++ b/net/ipv6/tcp_ipv6.c
89629@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
89630 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
89631 }
89632
89633+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89634+extern int grsec_enable_blackhole;
89635+#endif
89636+
89637 static void tcp_v6_hash(struct sock *sk)
89638 {
89639 if (sk->sk_state != TCP_CLOSE) {
89640@@ -1398,6 +1402,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
89641 return 0;
89642
89643 reset:
89644+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89645+ if (!grsec_enable_blackhole)
89646+#endif
89647 tcp_v6_send_reset(sk, skb);
89648 discard:
89649 if (opt_skb)
89650@@ -1480,12 +1487,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
89651 TCP_SKB_CB(skb)->sacked = 0;
89652
89653 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
89654- if (!sk)
89655+ if (!sk) {
89656+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89657+ ret = 1;
89658+#endif
89659 goto no_tcp_socket;
89660+ }
89661
89662 process:
89663- if (sk->sk_state == TCP_TIME_WAIT)
89664+ if (sk->sk_state == TCP_TIME_WAIT) {
89665+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89666+ ret = 2;
89667+#endif
89668 goto do_time_wait;
89669+ }
89670
89671 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
89672 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
89673@@ -1536,6 +1551,10 @@ csum_error:
89674 bad_packet:
89675 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
89676 } else {
89677+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89678+ if (!grsec_enable_blackhole || (ret == 1 &&
89679+ (skb->dev->flags & IFF_LOOPBACK)))
89680+#endif
89681 tcp_v6_send_reset(NULL, skb);
89682 }
89683
89684diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
89685index e7b28f9..d09c290 100644
89686--- a/net/ipv6/udp.c
89687+++ b/net/ipv6/udp.c
89688@@ -52,6 +52,10 @@
89689 #include <trace/events/skb.h>
89690 #include "udp_impl.h"
89691
89692+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89693+extern int grsec_enable_blackhole;
89694+#endif
89695+
89696 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
89697 {
89698 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
89699@@ -419,7 +423,7 @@ try_again:
89700 if (unlikely(err)) {
89701 trace_kfree_skb(skb, udpv6_recvmsg);
89702 if (!peeked) {
89703- atomic_inc(&sk->sk_drops);
89704+ atomic_inc_unchecked(&sk->sk_drops);
89705 if (is_udp4)
89706 UDP_INC_STATS_USER(sock_net(sk),
89707 UDP_MIB_INERRORS,
89708@@ -665,7 +669,7 @@ csum_error:
89709 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
89710 drop:
89711 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
89712- atomic_inc(&sk->sk_drops);
89713+ atomic_inc_unchecked(&sk->sk_drops);
89714 kfree_skb(skb);
89715 return -1;
89716 }
89717@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
89718 if (likely(skb1 == NULL))
89719 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
89720 if (!skb1) {
89721- atomic_inc(&sk->sk_drops);
89722+ atomic_inc_unchecked(&sk->sk_drops);
89723 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
89724 IS_UDPLITE(sk));
89725 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
89726@@ -860,6 +864,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
89727 goto csum_error;
89728
89729 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
89730+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
89731+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
89732+#endif
89733 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
89734
89735 kfree_skb(skb);
89736@@ -1392,7 +1399,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
89737 0,
89738 sock_i_ino(sp),
89739 atomic_read(&sp->sk_refcnt), sp,
89740- atomic_read(&sp->sk_drops));
89741+ atomic_read_unchecked(&sp->sk_drops));
89742 }
89743
89744 int udp6_seq_show(struct seq_file *seq, void *v)
89745diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
89746index 23ed03d..465a71d 100644
89747--- a/net/ipv6/xfrm6_policy.c
89748+++ b/net/ipv6/xfrm6_policy.c
89749@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
89750
89751 static int __net_init xfrm6_net_init(struct net *net)
89752 {
89753- struct ctl_table *table;
89754+ ctl_table_no_const *table = NULL;
89755 struct ctl_table_header *hdr;
89756
89757- table = xfrm6_policy_table;
89758 if (!net_eq(net, &init_net)) {
89759- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
89760+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
89761 if (!table)
89762 goto err_alloc;
89763
89764 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
89765- }
89766+ hdr = register_net_sysctl(net, "net/ipv6", table);
89767+ } else
89768+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
89769
89770- hdr = register_net_sysctl(net, "net/ipv6", table);
89771 if (!hdr)
89772 goto err_reg;
89773
89774@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
89775 return 0;
89776
89777 err_reg:
89778- if (!net_eq(net, &init_net))
89779- kfree(table);
89780+ kfree(table);
89781 err_alloc:
89782 return -ENOMEM;
89783 }
89784diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
89785index 41ac7938..75e3bb1 100644
89786--- a/net/irda/ircomm/ircomm_tty.c
89787+++ b/net/irda/ircomm/ircomm_tty.c
89788@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
89789 add_wait_queue(&port->open_wait, &wait);
89790
89791 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
89792- __FILE__, __LINE__, tty->driver->name, port->count);
89793+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
89794
89795 spin_lock_irqsave(&port->lock, flags);
89796 if (!tty_hung_up_p(filp))
89797- port->count--;
89798+ atomic_dec(&port->count);
89799 port->blocked_open++;
89800 spin_unlock_irqrestore(&port->lock, flags);
89801
89802@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
89803 }
89804
89805 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
89806- __FILE__, __LINE__, tty->driver->name, port->count);
89807+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
89808
89809 schedule();
89810 }
89811@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
89812
89813 spin_lock_irqsave(&port->lock, flags);
89814 if (!tty_hung_up_p(filp))
89815- port->count++;
89816+ atomic_inc(&port->count);
89817 port->blocked_open--;
89818 spin_unlock_irqrestore(&port->lock, flags);
89819
89820 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
89821- __FILE__, __LINE__, tty->driver->name, port->count);
89822+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
89823
89824 if (!retval)
89825 port->flags |= ASYNC_NORMAL_ACTIVE;
89826@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
89827
89828 /* ++ is not atomic, so this should be protected - Jean II */
89829 spin_lock_irqsave(&self->port.lock, flags);
89830- self->port.count++;
89831+ atomic_inc(&self->port.count);
89832 spin_unlock_irqrestore(&self->port.lock, flags);
89833 tty_port_tty_set(&self->port, tty);
89834
89835 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
89836- self->line, self->port.count);
89837+ self->line, atomic_read(&self->port.count));
89838
89839 /* Not really used by us, but lets do it anyway */
89840 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
89841@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
89842 tty_kref_put(port->tty);
89843 }
89844 port->tty = NULL;
89845- port->count = 0;
89846+ atomic_set(&port->count, 0);
89847 spin_unlock_irqrestore(&port->lock, flags);
89848
89849 wake_up_interruptible(&port->open_wait);
89850@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
89851 seq_putc(m, '\n');
89852
89853 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
89854- seq_printf(m, "Open count: %d\n", self->port.count);
89855+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
89856 seq_printf(m, "Max data size: %d\n", self->max_data_size);
89857 seq_printf(m, "Max header size: %d\n", self->max_header_size);
89858
89859diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
89860index ae69165..c8b82d8 100644
89861--- a/net/iucv/af_iucv.c
89862+++ b/net/iucv/af_iucv.c
89863@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
89864
89865 write_lock_bh(&iucv_sk_list.lock);
89866
89867- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
89868+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
89869 while (__iucv_get_sock_by_name(name)) {
89870 sprintf(name, "%08x",
89871- atomic_inc_return(&iucv_sk_list.autobind_name));
89872+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
89873 }
89874
89875 write_unlock_bh(&iucv_sk_list.lock);
89876diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
89877index 4fe76ff..426a904 100644
89878--- a/net/iucv/iucv.c
89879+++ b/net/iucv/iucv.c
89880@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
89881 return NOTIFY_OK;
89882 }
89883
89884-static struct notifier_block __refdata iucv_cpu_notifier = {
89885+static struct notifier_block iucv_cpu_notifier = {
89886 .notifier_call = iucv_cpu_notify,
89887 };
89888
89889diff --git a/net/key/af_key.c b/net/key/af_key.c
89890index 9da8620..97070ad 100644
89891--- a/net/key/af_key.c
89892+++ b/net/key/af_key.c
89893@@ -3047,10 +3047,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
89894 static u32 get_acqseq(void)
89895 {
89896 u32 res;
89897- static atomic_t acqseq;
89898+ static atomic_unchecked_t acqseq;
89899
89900 do {
89901- res = atomic_inc_return(&acqseq);
89902+ res = atomic_inc_return_unchecked(&acqseq);
89903 } while (!res);
89904 return res;
89905 }
89906diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
89907index 4fdb306e..920086a 100644
89908--- a/net/mac80211/cfg.c
89909+++ b/net/mac80211/cfg.c
89910@@ -804,7 +804,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
89911 ret = ieee80211_vif_use_channel(sdata, chandef,
89912 IEEE80211_CHANCTX_EXCLUSIVE);
89913 }
89914- } else if (local->open_count == local->monitors) {
89915+ } else if (local_read(&local->open_count) == local->monitors) {
89916 local->_oper_chandef = *chandef;
89917 ieee80211_hw_config(local, 0);
89918 }
89919@@ -2920,7 +2920,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
89920 else
89921 local->probe_req_reg--;
89922
89923- if (!local->open_count)
89924+ if (!local_read(&local->open_count))
89925 break;
89926
89927 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
89928@@ -3383,8 +3383,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
89929 if (chanctx_conf) {
89930 *chandef = chanctx_conf->def;
89931 ret = 0;
89932- } else if (local->open_count > 0 &&
89933- local->open_count == local->monitors &&
89934+ } else if (local_read(&local->open_count) > 0 &&
89935+ local_read(&local->open_count) == local->monitors &&
89936 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
89937 if (local->use_chanctx)
89938 *chandef = local->monitor_chandef;
89939diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
89940index 9ca8e32..48e4a9b 100644
89941--- a/net/mac80211/ieee80211_i.h
89942+++ b/net/mac80211/ieee80211_i.h
89943@@ -28,6 +28,7 @@
89944 #include <net/ieee80211_radiotap.h>
89945 #include <net/cfg80211.h>
89946 #include <net/mac80211.h>
89947+#include <asm/local.h>
89948 #include "key.h"
89949 #include "sta_info.h"
89950 #include "debug.h"
89951@@ -891,7 +892,7 @@ struct ieee80211_local {
89952 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
89953 spinlock_t queue_stop_reason_lock;
89954
89955- int open_count;
89956+ local_t open_count;
89957 int monitors, cooked_mntrs;
89958 /* number of interfaces with corresponding FIF_ flags */
89959 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
89960diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
89961index 514e90f..56f22bf 100644
89962--- a/net/mac80211/iface.c
89963+++ b/net/mac80211/iface.c
89964@@ -502,7 +502,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89965 break;
89966 }
89967
89968- if (local->open_count == 0) {
89969+ if (local_read(&local->open_count) == 0) {
89970 res = drv_start(local);
89971 if (res)
89972 goto err_del_bss;
89973@@ -545,7 +545,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89974 break;
89975 }
89976
89977- if (local->monitors == 0 && local->open_count == 0) {
89978+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
89979 res = ieee80211_add_virtual_monitor(local);
89980 if (res)
89981 goto err_stop;
89982@@ -653,7 +653,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89983 atomic_inc(&local->iff_promiscs);
89984
89985 if (coming_up)
89986- local->open_count++;
89987+ local_inc(&local->open_count);
89988
89989 if (hw_reconf_flags)
89990 ieee80211_hw_config(local, hw_reconf_flags);
89991@@ -691,7 +691,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89992 err_del_interface:
89993 drv_remove_interface(local, sdata);
89994 err_stop:
89995- if (!local->open_count)
89996+ if (!local_read(&local->open_count))
89997 drv_stop(local);
89998 err_del_bss:
89999 sdata->bss = NULL;
90000@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
90001 }
90002
90003 if (going_down)
90004- local->open_count--;
90005+ local_dec(&local->open_count);
90006
90007 switch (sdata->vif.type) {
90008 case NL80211_IFTYPE_AP_VLAN:
90009@@ -895,7 +895,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
90010 }
90011 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
90012
90013- if (local->open_count == 0)
90014+ if (local_read(&local->open_count) == 0)
90015 ieee80211_clear_tx_pending(local);
90016
90017 /*
90018@@ -931,7 +931,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
90019
90020 ieee80211_recalc_ps(local, -1);
90021
90022- if (local->open_count == 0) {
90023+ if (local_read(&local->open_count) == 0) {
90024 ieee80211_stop_device(local);
90025
90026 /* no reconfiguring after stop! */
90027@@ -942,7 +942,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
90028 ieee80211_configure_filter(local);
90029 ieee80211_hw_config(local, hw_reconf_flags);
90030
90031- if (local->monitors == local->open_count)
90032+ if (local->monitors == local_read(&local->open_count))
90033 ieee80211_add_virtual_monitor(local);
90034 }
90035
90036diff --git a/net/mac80211/main.c b/net/mac80211/main.c
90037index 8a7bfc4..4407cd0 100644
90038--- a/net/mac80211/main.c
90039+++ b/net/mac80211/main.c
90040@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
90041 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
90042 IEEE80211_CONF_CHANGE_POWER);
90043
90044- if (changed && local->open_count) {
90045+ if (changed && local_read(&local->open_count)) {
90046 ret = drv_config(local, changed);
90047 /*
90048 * Goal:
90049diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
90050index 7fc5d0d..07ea536 100644
90051--- a/net/mac80211/pm.c
90052+++ b/net/mac80211/pm.c
90053@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
90054 struct ieee80211_sub_if_data *sdata;
90055 struct sta_info *sta;
90056
90057- if (!local->open_count)
90058+ if (!local_read(&local->open_count))
90059 goto suspend;
90060
90061 ieee80211_scan_cancel(local);
90062@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
90063 cancel_work_sync(&local->dynamic_ps_enable_work);
90064 del_timer_sync(&local->dynamic_ps_timer);
90065
90066- local->wowlan = wowlan && local->open_count;
90067+ local->wowlan = wowlan && local_read(&local->open_count);
90068 if (local->wowlan) {
90069 int err = drv_suspend(local, wowlan);
90070 if (err < 0) {
90071@@ -113,7 +113,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
90072 WARN_ON(!list_empty(&local->chanctx_list));
90073
90074 /* stop hardware - this must stop RX */
90075- if (local->open_count)
90076+ if (local_read(&local->open_count))
90077 ieee80211_stop_device(local);
90078
90079 suspend:
90080diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
90081index a02bef3..f2f38dd 100644
90082--- a/net/mac80211/rate.c
90083+++ b/net/mac80211/rate.c
90084@@ -712,7 +712,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
90085
90086 ASSERT_RTNL();
90087
90088- if (local->open_count)
90089+ if (local_read(&local->open_count))
90090 return -EBUSY;
90091
90092 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
90093diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
90094index c97a065..ff61928 100644
90095--- a/net/mac80211/rc80211_pid_debugfs.c
90096+++ b/net/mac80211/rc80211_pid_debugfs.c
90097@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
90098
90099 spin_unlock_irqrestore(&events->lock, status);
90100
90101- if (copy_to_user(buf, pb, p))
90102+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
90103 return -EFAULT;
90104
90105 return p;
90106diff --git a/net/mac80211/util.c b/net/mac80211/util.c
90107index 72e6292..e6319eb 100644
90108--- a/net/mac80211/util.c
90109+++ b/net/mac80211/util.c
90110@@ -1472,7 +1472,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
90111 }
90112 #endif
90113 /* everything else happens only if HW was up & running */
90114- if (!local->open_count)
90115+ if (!local_read(&local->open_count))
90116 goto wake_up;
90117
90118 /*
90119@@ -1696,7 +1696,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
90120 local->in_reconfig = false;
90121 barrier();
90122
90123- if (local->monitors == local->open_count && local->monitors > 0)
90124+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
90125 ieee80211_add_virtual_monitor(local);
90126
90127 /*
90128diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
90129index 56d22ca..87c778f 100644
90130--- a/net/netfilter/Kconfig
90131+++ b/net/netfilter/Kconfig
90132@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
90133
90134 To compile it as a module, choose M here. If unsure, say N.
90135
90136+config NETFILTER_XT_MATCH_GRADM
90137+ tristate '"gradm" match support'
90138+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
90139+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
90140+ ---help---
90141+ The gradm match allows to match on grsecurity RBAC being enabled.
90142+ It is useful when iptables rules are applied early on bootup to
90143+ prevent connections to the machine (except from a trusted host)
90144+ while the RBAC system is disabled.
90145+
90146 config NETFILTER_XT_MATCH_HASHLIMIT
90147 tristate '"hashlimit" match support'
90148 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
90149diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
90150index a1abf87..dbcb7ee 100644
90151--- a/net/netfilter/Makefile
90152+++ b/net/netfilter/Makefile
90153@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
90154 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
90155 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
90156 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
90157+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
90158 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
90159 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
90160 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
90161diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
90162index f771390..145b765 100644
90163--- a/net/netfilter/ipset/ip_set_core.c
90164+++ b/net/netfilter/ipset/ip_set_core.c
90165@@ -1820,7 +1820,7 @@ done:
90166 return ret;
90167 }
90168
90169-static struct nf_sockopt_ops so_set __read_mostly = {
90170+static struct nf_sockopt_ops so_set = {
90171 .pf = PF_INET,
90172 .get_optmin = SO_IP_SET,
90173 .get_optmax = SO_IP_SET + 1,
90174diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
90175index a083bda..da661c3 100644
90176--- a/net/netfilter/ipvs/ip_vs_conn.c
90177+++ b/net/netfilter/ipvs/ip_vs_conn.c
90178@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
90179 /* Increase the refcnt counter of the dest */
90180 ip_vs_dest_hold(dest);
90181
90182- conn_flags = atomic_read(&dest->conn_flags);
90183+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
90184 if (cp->protocol != IPPROTO_UDP)
90185 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
90186 flags = cp->flags;
90187@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
90188
90189 cp->control = NULL;
90190 atomic_set(&cp->n_control, 0);
90191- atomic_set(&cp->in_pkts, 0);
90192+ atomic_set_unchecked(&cp->in_pkts, 0);
90193
90194 cp->packet_xmit = NULL;
90195 cp->app = NULL;
90196@@ -1190,7 +1190,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
90197
90198 /* Don't drop the entry if its number of incoming packets is not
90199 located in [0, 8] */
90200- i = atomic_read(&cp->in_pkts);
90201+ i = atomic_read_unchecked(&cp->in_pkts);
90202 if (i > 8 || i < 0) return 0;
90203
90204 if (!todrop_rate[i]) return 0;
90205diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
90206index 23b8eb5..48a8959 100644
90207--- a/net/netfilter/ipvs/ip_vs_core.c
90208+++ b/net/netfilter/ipvs/ip_vs_core.c
90209@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
90210 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
90211 /* do not touch skb anymore */
90212
90213- atomic_inc(&cp->in_pkts);
90214+ atomic_inc_unchecked(&cp->in_pkts);
90215 ip_vs_conn_put(cp);
90216 return ret;
90217 }
90218@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
90219 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
90220 pkts = sysctl_sync_threshold(ipvs);
90221 else
90222- pkts = atomic_add_return(1, &cp->in_pkts);
90223+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
90224
90225 if (ipvs->sync_state & IP_VS_STATE_MASTER)
90226 ip_vs_sync_conn(net, cp, pkts);
90227diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
90228index 9e6c2a0..28552e2 100644
90229--- a/net/netfilter/ipvs/ip_vs_ctl.c
90230+++ b/net/netfilter/ipvs/ip_vs_ctl.c
90231@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
90232 */
90233 ip_vs_rs_hash(ipvs, dest);
90234 }
90235- atomic_set(&dest->conn_flags, conn_flags);
90236+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
90237
90238 /* bind the service */
90239 if (!dest->svc) {
90240@@ -1657,7 +1657,7 @@ proc_do_sync_ports(ctl_table *table, int write,
90241 * align with netns init in ip_vs_control_net_init()
90242 */
90243
90244-static struct ctl_table vs_vars[] = {
90245+static ctl_table_no_const vs_vars[] __read_only = {
90246 {
90247 .procname = "amemthresh",
90248 .maxlen = sizeof(int),
90249@@ -2060,7 +2060,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
90250 " %-7s %-6d %-10d %-10d\n",
90251 &dest->addr.in6,
90252 ntohs(dest->port),
90253- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
90254+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
90255 atomic_read(&dest->weight),
90256 atomic_read(&dest->activeconns),
90257 atomic_read(&dest->inactconns));
90258@@ -2071,7 +2071,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
90259 "%-7s %-6d %-10d %-10d\n",
90260 ntohl(dest->addr.ip),
90261 ntohs(dest->port),
90262- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
90263+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
90264 atomic_read(&dest->weight),
90265 atomic_read(&dest->activeconns),
90266 atomic_read(&dest->inactconns));
90267@@ -2549,7 +2549,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
90268
90269 entry.addr = dest->addr.ip;
90270 entry.port = dest->port;
90271- entry.conn_flags = atomic_read(&dest->conn_flags);
90272+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
90273 entry.weight = atomic_read(&dest->weight);
90274 entry.u_threshold = dest->u_threshold;
90275 entry.l_threshold = dest->l_threshold;
90276@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
90277 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
90278 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
90279 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
90280- (atomic_read(&dest->conn_flags) &
90281+ (atomic_read_unchecked(&dest->conn_flags) &
90282 IP_VS_CONN_F_FWD_MASK)) ||
90283 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
90284 atomic_read(&dest->weight)) ||
90285@@ -3682,7 +3682,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
90286 {
90287 int idx;
90288 struct netns_ipvs *ipvs = net_ipvs(net);
90289- struct ctl_table *tbl;
90290+ ctl_table_no_const *tbl;
90291
90292 atomic_set(&ipvs->dropentry, 0);
90293 spin_lock_init(&ipvs->dropentry_lock);
90294diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
90295index 5ea26bd..c9bc65f 100644
90296--- a/net/netfilter/ipvs/ip_vs_lblc.c
90297+++ b/net/netfilter/ipvs/ip_vs_lblc.c
90298@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
90299 * IPVS LBLC sysctl table
90300 */
90301 #ifdef CONFIG_SYSCTL
90302-static ctl_table vs_vars_table[] = {
90303+static ctl_table_no_const vs_vars_table[] __read_only = {
90304 {
90305 .procname = "lblc_expiration",
90306 .data = NULL,
90307diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
90308index 50123c2..067c773 100644
90309--- a/net/netfilter/ipvs/ip_vs_lblcr.c
90310+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
90311@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
90312 * IPVS LBLCR sysctl table
90313 */
90314
90315-static ctl_table vs_vars_table[] = {
90316+static ctl_table_no_const vs_vars_table[] __read_only = {
90317 {
90318 .procname = "lblcr_expiration",
90319 .data = NULL,
90320diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
90321index f6046d9..4f10cfd 100644
90322--- a/net/netfilter/ipvs/ip_vs_sync.c
90323+++ b/net/netfilter/ipvs/ip_vs_sync.c
90324@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
90325 cp = cp->control;
90326 if (cp) {
90327 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
90328- pkts = atomic_add_return(1, &cp->in_pkts);
90329+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
90330 else
90331 pkts = sysctl_sync_threshold(ipvs);
90332 ip_vs_sync_conn(net, cp->control, pkts);
90333@@ -758,7 +758,7 @@ control:
90334 if (!cp)
90335 return;
90336 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
90337- pkts = atomic_add_return(1, &cp->in_pkts);
90338+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
90339 else
90340 pkts = sysctl_sync_threshold(ipvs);
90341 goto sloop;
90342@@ -882,7 +882,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
90343
90344 if (opt)
90345 memcpy(&cp->in_seq, opt, sizeof(*opt));
90346- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
90347+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
90348 cp->state = state;
90349 cp->old_state = cp->state;
90350 /*
90351diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
90352index b75ff64..0c51bbe 100644
90353--- a/net/netfilter/ipvs/ip_vs_xmit.c
90354+++ b/net/netfilter/ipvs/ip_vs_xmit.c
90355@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
90356 else
90357 rc = NF_ACCEPT;
90358 /* do not touch skb anymore */
90359- atomic_inc(&cp->in_pkts);
90360+ atomic_inc_unchecked(&cp->in_pkts);
90361 goto out;
90362 }
90363
90364@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
90365 else
90366 rc = NF_ACCEPT;
90367 /* do not touch skb anymore */
90368- atomic_inc(&cp->in_pkts);
90369+ atomic_inc_unchecked(&cp->in_pkts);
90370 goto out;
90371 }
90372
90373diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
90374index 2d3030a..7ba1c0a 100644
90375--- a/net/netfilter/nf_conntrack_acct.c
90376+++ b/net/netfilter/nf_conntrack_acct.c
90377@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
90378 #ifdef CONFIG_SYSCTL
90379 static int nf_conntrack_acct_init_sysctl(struct net *net)
90380 {
90381- struct ctl_table *table;
90382+ ctl_table_no_const *table;
90383
90384 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
90385 GFP_KERNEL);
90386diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
90387index 0283bae..5febcb0 100644
90388--- a/net/netfilter/nf_conntrack_core.c
90389+++ b/net/netfilter/nf_conntrack_core.c
90390@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
90391 #define DYING_NULLS_VAL ((1<<30)+1)
90392 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
90393
90394+#ifdef CONFIG_GRKERNSEC_HIDESYM
90395+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
90396+#endif
90397+
90398 int nf_conntrack_init_net(struct net *net)
90399 {
90400 int ret;
90401@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
90402 goto err_stat;
90403 }
90404
90405+#ifdef CONFIG_GRKERNSEC_HIDESYM
90406+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
90407+#else
90408 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
90409+#endif
90410 if (!net->ct.slabname) {
90411 ret = -ENOMEM;
90412 goto err_slabname;
90413diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
90414index 1df1761..ce8b88a 100644
90415--- a/net/netfilter/nf_conntrack_ecache.c
90416+++ b/net/netfilter/nf_conntrack_ecache.c
90417@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
90418 #ifdef CONFIG_SYSCTL
90419 static int nf_conntrack_event_init_sysctl(struct net *net)
90420 {
90421- struct ctl_table *table;
90422+ ctl_table_no_const *table;
90423
90424 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
90425 GFP_KERNEL);
90426diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
90427index 974a2a4..52cc6ff 100644
90428--- a/net/netfilter/nf_conntrack_helper.c
90429+++ b/net/netfilter/nf_conntrack_helper.c
90430@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
90431
90432 static int nf_conntrack_helper_init_sysctl(struct net *net)
90433 {
90434- struct ctl_table *table;
90435+ ctl_table_no_const *table;
90436
90437 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
90438 GFP_KERNEL);
90439diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
90440index 0ab9636..cea3c6a 100644
90441--- a/net/netfilter/nf_conntrack_proto.c
90442+++ b/net/netfilter/nf_conntrack_proto.c
90443@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
90444
90445 static void
90446 nf_ct_unregister_sysctl(struct ctl_table_header **header,
90447- struct ctl_table **table,
90448+ ctl_table_no_const **table,
90449 unsigned int users)
90450 {
90451 if (users > 0)
90452diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
90453index a99b6c3..3841268 100644
90454--- a/net/netfilter/nf_conntrack_proto_dccp.c
90455+++ b/net/netfilter/nf_conntrack_proto_dccp.c
90456@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
90457 out_invalid:
90458 if (LOG_INVALID(net, IPPROTO_DCCP))
90459 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
90460- NULL, msg);
90461+ NULL, "%s", msg);
90462 return false;
90463 }
90464
90465@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
90466
90467 out_invalid:
90468 if (LOG_INVALID(net, IPPROTO_DCCP))
90469- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
90470+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
90471 return -NF_ACCEPT;
90472 }
90473
90474diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
90475index bd700b4..4a3dc61 100644
90476--- a/net/netfilter/nf_conntrack_standalone.c
90477+++ b/net/netfilter/nf_conntrack_standalone.c
90478@@ -471,7 +471,7 @@ static ctl_table nf_ct_netfilter_table[] = {
90479
90480 static int nf_conntrack_standalone_init_sysctl(struct net *net)
90481 {
90482- struct ctl_table *table;
90483+ ctl_table_no_const *table;
90484
90485 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
90486 GFP_KERNEL);
90487diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
90488index 902fb0a..87f7fdb 100644
90489--- a/net/netfilter/nf_conntrack_timestamp.c
90490+++ b/net/netfilter/nf_conntrack_timestamp.c
90491@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
90492 #ifdef CONFIG_SYSCTL
90493 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
90494 {
90495- struct ctl_table *table;
90496+ ctl_table_no_const *table;
90497
90498 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
90499 GFP_KERNEL);
90500diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
90501index 3b18dd1..f79e0ca 100644
90502--- a/net/netfilter/nf_log.c
90503+++ b/net/netfilter/nf_log.c
90504@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
90505
90506 #ifdef CONFIG_SYSCTL
90507 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
90508-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
90509+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
90510
90511 static int nf_log_proc_dostring(ctl_table *table, int write,
90512 void __user *buffer, size_t *lenp, loff_t *ppos)
90513@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
90514 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
90515 mutex_unlock(&nf_log_mutex);
90516 } else {
90517+ ctl_table_no_const nf_log_table = *table;
90518+
90519 mutex_lock(&nf_log_mutex);
90520 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
90521 lockdep_is_held(&nf_log_mutex));
90522 if (!logger)
90523- table->data = "NONE";
90524+ nf_log_table.data = "NONE";
90525 else
90526- table->data = logger->name;
90527- r = proc_dostring(table, write, buffer, lenp, ppos);
90528+ nf_log_table.data = logger->name;
90529+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
90530 mutex_unlock(&nf_log_mutex);
90531 }
90532
90533diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
90534index f042ae5..30ea486 100644
90535--- a/net/netfilter/nf_sockopt.c
90536+++ b/net/netfilter/nf_sockopt.c
90537@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
90538 }
90539 }
90540
90541- list_add(&reg->list, &nf_sockopts);
90542+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
90543 out:
90544 mutex_unlock(&nf_sockopt_mutex);
90545 return ret;
90546@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
90547 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
90548 {
90549 mutex_lock(&nf_sockopt_mutex);
90550- list_del(&reg->list);
90551+ pax_list_del((struct list_head *)&reg->list);
90552 mutex_unlock(&nf_sockopt_mutex);
90553 }
90554 EXPORT_SYMBOL(nf_unregister_sockopt);
90555diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
90556index 962e979..d4ae2e9 100644
90557--- a/net/netfilter/nfnetlink_log.c
90558+++ b/net/netfilter/nfnetlink_log.c
90559@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
90560 struct nfnl_log_net {
90561 spinlock_t instances_lock;
90562 struct hlist_head instance_table[INSTANCE_BUCKETS];
90563- atomic_t global_seq;
90564+ atomic_unchecked_t global_seq;
90565 };
90566
90567 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
90568@@ -559,7 +559,7 @@ __build_packet_message(struct nfnl_log_net *log,
90569 /* global sequence number */
90570 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
90571 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
90572- htonl(atomic_inc_return(&log->global_seq))))
90573+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
90574 goto nla_put_failure;
90575
90576 if (data_len) {
90577diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
90578new file mode 100644
90579index 0000000..c566332
90580--- /dev/null
90581+++ b/net/netfilter/xt_gradm.c
90582@@ -0,0 +1,51 @@
90583+/*
90584+ * gradm match for netfilter
90585