]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.10.1-201307141923.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.10.1-201307141923.patch
CommitLineData
d34bf12f
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..3dd8184 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,18 @@ 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_softmode= 0/1 to disable/enable PaX softmode on boot already.
256+
257+ pax_extra_latent_entropy
258+ Enable a very simple form of latent entropy extraction
259+ from the first 4GB of memory as the bootmem allocator
260+ passes the memory pages to the buddy allocator.
261+
262 pcbit= [HW,ISDN]
263
264 pcd. [PARIDE]
265diff --git a/Makefile b/Makefile
266index b75cc30..6abd111 100644
267--- a/Makefile
268+++ b/Makefile
269@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
270
271 HOSTCC = gcc
272 HOSTCXX = g++
273-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
274-HOSTCXXFLAGS = -O2
275+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
276+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
277+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
278
279 # Decide whether to build built-in, modular, or both.
280 # Normally, just do built-in.
281@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
282 # Rules shared between *config targets and build targets
283
284 # Basic helpers built in scripts/
285-PHONY += scripts_basic
286-scripts_basic:
287+PHONY += scripts_basic gcc-plugins
288+scripts_basic: gcc-plugins
289 $(Q)$(MAKE) $(build)=scripts/basic
290 $(Q)rm -f .tmp_quiet_recordmcount
291
292@@ -576,6 +577,65 @@ else
293 KBUILD_CFLAGS += -O2
294 endif
295
296+ifndef DISABLE_PAX_PLUGINS
297+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
298+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
299+else
300+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
301+endif
302+ifneq ($(PLUGINCC),)
303+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
304+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
305+endif
306+ifdef CONFIG_PAX_MEMORY_STACKLEAK
307+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
308+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
309+endif
310+ifdef CONFIG_KALLOCSTAT_PLUGIN
311+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
312+endif
313+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
314+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
315+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
316+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
317+endif
318+ifdef CONFIG_CHECKER_PLUGIN
319+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
320+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
321+endif
322+endif
323+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
324+ifdef CONFIG_PAX_SIZE_OVERFLOW
325+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
326+endif
327+ifdef CONFIG_PAX_LATENT_ENTROPY
328+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
329+endif
330+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
331+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
332+endif
333+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
334+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
335+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
336+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
337+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
338+ifeq ($(KBUILD_EXTMOD),)
339+gcc-plugins:
340+ $(Q)$(MAKE) $(build)=tools/gcc
341+else
342+gcc-plugins: ;
343+endif
344+else
345+gcc-plugins:
346+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
347+ $(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.))
348+else
349+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
350+endif
351+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
352+endif
353+endif
354+
355 include $(srctree)/arch/$(SRCARCH)/Makefile
356
357 ifdef CONFIG_READABLE_ASM
358@@ -733,7 +793,7 @@ export mod_sign_cmd
359
360
361 ifeq ($(KBUILD_EXTMOD),)
362-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
363+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
364
365 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
366 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
367@@ -782,6 +842,8 @@ endif
368
369 # The actual objects are generated when descending,
370 # make sure no implicit rule kicks in
371+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
372+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
373 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
374
375 # Handle descending into subdirectories listed in $(vmlinux-dirs)
376@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
377 # Error messages still appears in the original language
378
379 PHONY += $(vmlinux-dirs)
380-$(vmlinux-dirs): prepare scripts
381+$(vmlinux-dirs): gcc-plugins prepare scripts
382 $(Q)$(MAKE) $(build)=$@
383
384 # Store (new) KERNELRELASE string in include/config/kernel.release
385@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
386 $(Q)$(MAKE) $(build)=.
387
388 # All the preparing..
389+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
390 prepare: prepare0
391
392 # Generate some files
393@@ -942,6 +1005,8 @@ all: modules
394 # using awk while concatenating to the final file.
395
396 PHONY += modules
397+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
398+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
399 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
400 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
401 @$(kecho) ' Building modules, stage 2.';
402@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
403
404 # Target to prepare building external modules
405 PHONY += modules_prepare
406-modules_prepare: prepare scripts
407+modules_prepare: gcc-plugins prepare scripts
408
409 # Target to install modules
410 PHONY += modules_install
411@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
412 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
413 signing_key.priv signing_key.x509 x509.genkey \
414 extra_certificates signing_key.x509.keyid \
415- signing_key.x509.signer
416+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
417
418 # clean - Delete most, but leave enough to build external modules
419 #
420@@ -1063,6 +1128,7 @@ distclean: mrproper
421 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
422 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
423 -o -name '.*.rej' \
424+ -o -name '.*.rej' -o -name '*.so' \
425 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
426 -type f -print | xargs rm -f
427
428@@ -1223,6 +1289,8 @@ PHONY += $(module-dirs) modules
429 $(module-dirs): crmodverdir $(objtree)/Module.symvers
430 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
431
432+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
433+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
434 modules: $(module-dirs)
435 @$(kecho) ' Building modules, stage 2.';
436 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
437@@ -1359,17 +1427,21 @@ else
438 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
439 endif
440
441-%.s: %.c prepare scripts FORCE
442+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
443+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
444+%.s: %.c gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 %.i: %.c prepare scripts FORCE
447 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
448-%.o: %.c prepare scripts FORCE
449+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451+%.o: %.c gcc-plugins prepare scripts FORCE
452 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
453 %.lst: %.c prepare scripts FORCE
454 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
455-%.s: %.S prepare scripts FORCE
456+%.s: %.S gcc-plugins prepare scripts FORCE
457 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
458-%.o: %.S prepare scripts FORCE
459+%.o: %.S gcc-plugins prepare scripts FORCE
460 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
461 %.symtypes: %.c prepare scripts FORCE
462 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
463@@ -1379,11 +1451,15 @@ endif
464 $(cmd_crmodverdir)
465 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
466 $(build)=$(build-dir)
467-%/: prepare scripts FORCE
468+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
469+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
470+%/: gcc-plugins prepare scripts FORCE
471 $(cmd_crmodverdir)
472 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
473 $(build)=$(build-dir)
474-%.ko: prepare scripts FORCE
475+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
476+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
477+%.ko: gcc-plugins prepare scripts FORCE
478 $(cmd_crmodverdir)
479 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
480 $(build)=$(build-dir) $(@:.ko=.o)
481diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
482index c2cbe4f..f7264b4 100644
483--- a/arch/alpha/include/asm/atomic.h
484+++ b/arch/alpha/include/asm/atomic.h
485@@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
486 #define atomic_dec(v) atomic_sub(1,(v))
487 #define atomic64_dec(v) atomic64_sub(1,(v))
488
489+#define atomic64_read_unchecked(v) atomic64_read(v)
490+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
491+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
492+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
493+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
494+#define atomic64_inc_unchecked(v) atomic64_inc(v)
495+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
496+#define atomic64_dec_unchecked(v) atomic64_dec(v)
497+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
498+
499 #define smp_mb__before_atomic_dec() smp_mb()
500 #define smp_mb__after_atomic_dec() smp_mb()
501 #define smp_mb__before_atomic_inc() smp_mb()
502diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
503index ad368a9..fbe0f25 100644
504--- a/arch/alpha/include/asm/cache.h
505+++ b/arch/alpha/include/asm/cache.h
506@@ -4,19 +4,19 @@
507 #ifndef __ARCH_ALPHA_CACHE_H
508 #define __ARCH_ALPHA_CACHE_H
509
510+#include <linux/const.h>
511
512 /* Bytes per L1 (data) cache line. */
513 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
514-# define L1_CACHE_BYTES 64
515 # define L1_CACHE_SHIFT 6
516 #else
517 /* Both EV4 and EV5 are write-through, read-allocate,
518 direct-mapped, physical.
519 */
520-# define L1_CACHE_BYTES 32
521 # define L1_CACHE_SHIFT 5
522 #endif
523
524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
525 #define SMP_CACHE_BYTES L1_CACHE_BYTES
526
527 #endif
528diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
529index 968d999..d36b2df 100644
530--- a/arch/alpha/include/asm/elf.h
531+++ b/arch/alpha/include/asm/elf.h
532@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
533
534 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
535
536+#ifdef CONFIG_PAX_ASLR
537+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
538+
539+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
540+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
541+#endif
542+
543 /* $0 is set by ld.so to a pointer to a function which might be
544 registered using atexit. This provides a mean for the dynamic
545 linker to call DT_FINI functions for shared libraries that have
546diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
547index bc2a0da..8ad11ee 100644
548--- a/arch/alpha/include/asm/pgalloc.h
549+++ b/arch/alpha/include/asm/pgalloc.h
550@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
551 pgd_set(pgd, pmd);
552 }
553
554+static inline void
555+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
556+{
557+ pgd_populate(mm, pgd, pmd);
558+}
559+
560 extern pgd_t *pgd_alloc(struct mm_struct *mm);
561
562 static inline void
563diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
564index 81a4342..348b927 100644
565--- a/arch/alpha/include/asm/pgtable.h
566+++ b/arch/alpha/include/asm/pgtable.h
567@@ -102,6 +102,17 @@ struct vm_area_struct;
568 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
569 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
570 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
571+
572+#ifdef CONFIG_PAX_PAGEEXEC
573+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
574+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
575+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
576+#else
577+# define PAGE_SHARED_NOEXEC PAGE_SHARED
578+# define PAGE_COPY_NOEXEC PAGE_COPY
579+# define PAGE_READONLY_NOEXEC PAGE_READONLY
580+#endif
581+
582 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
583
584 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
585diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
586index 2fd00b7..cfd5069 100644
587--- a/arch/alpha/kernel/module.c
588+++ b/arch/alpha/kernel/module.c
589@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
590
591 /* The small sections were sorted to the end of the segment.
592 The following should definitely cover them. */
593- gp = (u64)me->module_core + me->core_size - 0x8000;
594+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
595 got = sechdrs[me->arch.gotsecindex].sh_addr;
596
597 for (i = 0; i < n; i++) {
598diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
599index b9e37ad..44c24e7 100644
600--- a/arch/alpha/kernel/osf_sys.c
601+++ b/arch/alpha/kernel/osf_sys.c
602@@ -1297,10 +1297,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
603 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
604
605 static unsigned long
606-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
607- unsigned long limit)
608+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
609+ unsigned long limit, unsigned long flags)
610 {
611 struct vm_unmapped_area_info info;
612+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
613
614 info.flags = 0;
615 info.length = len;
616@@ -1308,6 +1309,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
617 info.high_limit = limit;
618 info.align_mask = 0;
619 info.align_offset = 0;
620+ info.threadstack_offset = offset;
621 return vm_unmapped_area(&info);
622 }
623
624@@ -1340,20 +1342,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
625 merely specific addresses, but regions of memory -- perhaps
626 this feature should be incorporated into all ports? */
627
628+#ifdef CONFIG_PAX_RANDMMAP
629+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
630+#endif
631+
632 if (addr) {
633- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
634+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
635 if (addr != (unsigned long) -ENOMEM)
636 return addr;
637 }
638
639 /* Next, try allocating at TASK_UNMAPPED_BASE. */
640- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
641- len, limit);
642+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
643+
644 if (addr != (unsigned long) -ENOMEM)
645 return addr;
646
647 /* Finally, try allocating in low memory. */
648- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
649+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
650
651 return addr;
652 }
653diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
654index 0c4132d..88f0d53 100644
655--- a/arch/alpha/mm/fault.c
656+++ b/arch/alpha/mm/fault.c
657@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
658 __reload_thread(pcb);
659 }
660
661+#ifdef CONFIG_PAX_PAGEEXEC
662+/*
663+ * PaX: decide what to do with offenders (regs->pc = fault address)
664+ *
665+ * returns 1 when task should be killed
666+ * 2 when patched PLT trampoline was detected
667+ * 3 when unpatched PLT trampoline was detected
668+ */
669+static int pax_handle_fetch_fault(struct pt_regs *regs)
670+{
671+
672+#ifdef CONFIG_PAX_EMUPLT
673+ int err;
674+
675+ do { /* PaX: patched PLT emulation #1 */
676+ unsigned int ldah, ldq, jmp;
677+
678+ err = get_user(ldah, (unsigned int *)regs->pc);
679+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
680+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
681+
682+ if (err)
683+ break;
684+
685+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
686+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
687+ jmp == 0x6BFB0000U)
688+ {
689+ unsigned long r27, addr;
690+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
691+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
692+
693+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
694+ err = get_user(r27, (unsigned long *)addr);
695+ if (err)
696+ break;
697+
698+ regs->r27 = r27;
699+ regs->pc = r27;
700+ return 2;
701+ }
702+ } while (0);
703+
704+ do { /* PaX: patched PLT emulation #2 */
705+ unsigned int ldah, lda, br;
706+
707+ err = get_user(ldah, (unsigned int *)regs->pc);
708+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
709+ err |= get_user(br, (unsigned int *)(regs->pc+8));
710+
711+ if (err)
712+ break;
713+
714+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
715+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
716+ (br & 0xFFE00000U) == 0xC3E00000U)
717+ {
718+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
719+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
720+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
721+
722+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
723+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
724+ return 2;
725+ }
726+ } while (0);
727+
728+ do { /* PaX: unpatched PLT emulation */
729+ unsigned int br;
730+
731+ err = get_user(br, (unsigned int *)regs->pc);
732+
733+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
734+ unsigned int br2, ldq, nop, jmp;
735+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
736+
737+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
738+ err = get_user(br2, (unsigned int *)addr);
739+ err |= get_user(ldq, (unsigned int *)(addr+4));
740+ err |= get_user(nop, (unsigned int *)(addr+8));
741+ err |= get_user(jmp, (unsigned int *)(addr+12));
742+ err |= get_user(resolver, (unsigned long *)(addr+16));
743+
744+ if (err)
745+ break;
746+
747+ if (br2 == 0xC3600000U &&
748+ ldq == 0xA77B000CU &&
749+ nop == 0x47FF041FU &&
750+ jmp == 0x6B7B0000U)
751+ {
752+ regs->r28 = regs->pc+4;
753+ regs->r27 = addr+16;
754+ regs->pc = resolver;
755+ return 3;
756+ }
757+ }
758+ } while (0);
759+#endif
760+
761+ return 1;
762+}
763+
764+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
765+{
766+ unsigned long i;
767+
768+ printk(KERN_ERR "PAX: bytes at PC: ");
769+ for (i = 0; i < 5; i++) {
770+ unsigned int c;
771+ if (get_user(c, (unsigned int *)pc+i))
772+ printk(KERN_CONT "???????? ");
773+ else
774+ printk(KERN_CONT "%08x ", c);
775+ }
776+ printk("\n");
777+}
778+#endif
779
780 /*
781 * This routine handles page faults. It determines the address,
782@@ -133,8 +251,29 @@ retry:
783 good_area:
784 si_code = SEGV_ACCERR;
785 if (cause < 0) {
786- if (!(vma->vm_flags & VM_EXEC))
787+ if (!(vma->vm_flags & VM_EXEC)) {
788+
789+#ifdef CONFIG_PAX_PAGEEXEC
790+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
791+ goto bad_area;
792+
793+ up_read(&mm->mmap_sem);
794+ switch (pax_handle_fetch_fault(regs)) {
795+
796+#ifdef CONFIG_PAX_EMUPLT
797+ case 2:
798+ case 3:
799+ return;
800+#endif
801+
802+ }
803+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
804+ do_group_exit(SIGKILL);
805+#else
806 goto bad_area;
807+#endif
808+
809+ }
810 } else if (!cause) {
811 /* Allow reads even for write-only mappings */
812 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
813diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
814index 136f263..f471277 100644
815--- a/arch/arm/Kconfig
816+++ b/arch/arm/Kconfig
817@@ -1766,7 +1766,7 @@ config ALIGNMENT_TRAP
818
819 config UACCESS_WITH_MEMCPY
820 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
821- depends on MMU
822+ depends on MMU && !PAX_MEMORY_UDEREF
823 default y if CPU_FEROCEON
824 help
825 Implement faster copy_to_user and clear_user methods for CPU
826diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
827index da1c77d..2ee6056 100644
828--- a/arch/arm/include/asm/atomic.h
829+++ b/arch/arm/include/asm/atomic.h
830@@ -17,17 +17,35 @@
831 #include <asm/barrier.h>
832 #include <asm/cmpxchg.h>
833
834+#ifdef CONFIG_GENERIC_ATOMIC64
835+#include <asm-generic/atomic64.h>
836+#endif
837+
838 #define ATOMIC_INIT(i) { (i) }
839
840 #ifdef __KERNEL__
841
842+#define _ASM_EXTABLE(from, to) \
843+" .pushsection __ex_table,\"a\"\n"\
844+" .align 3\n" \
845+" .long " #from ", " #to"\n" \
846+" .popsection"
847+
848 /*
849 * On ARM, ordinary assignment (str instruction) doesn't clear the local
850 * strex/ldrex monitor on some implementations. The reason we can use it for
851 * atomic_set() is the clrex or dummy strex done on every exception return.
852 */
853 #define atomic_read(v) (*(volatile int *)&(v)->counter)
854+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
855+{
856+ return v->counter;
857+}
858 #define atomic_set(v,i) (((v)->counter) = (i))
859+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
860+{
861+ v->counter = i;
862+}
863
864 #if __LINUX_ARM_ARCH__ >= 6
865
866@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
867 int result;
868
869 __asm__ __volatile__("@ atomic_add\n"
870+"1: ldrex %1, [%3]\n"
871+" adds %0, %1, %4\n"
872+
873+#ifdef CONFIG_PAX_REFCOUNT
874+" bvc 3f\n"
875+"2: bkpt 0xf103\n"
876+"3:\n"
877+#endif
878+
879+" strex %1, %0, [%3]\n"
880+" teq %1, #0\n"
881+" bne 1b"
882+
883+#ifdef CONFIG_PAX_REFCOUNT
884+"\n4:\n"
885+ _ASM_EXTABLE(2b, 4b)
886+#endif
887+
888+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
889+ : "r" (&v->counter), "Ir" (i)
890+ : "cc");
891+}
892+
893+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
894+{
895+ unsigned long tmp;
896+ int result;
897+
898+ __asm__ __volatile__("@ atomic_add_unchecked\n"
899 "1: ldrex %0, [%3]\n"
900 " add %0, %0, %4\n"
901 " strex %1, %0, [%3]\n"
902@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
903 smp_mb();
904
905 __asm__ __volatile__("@ atomic_add_return\n"
906+"1: ldrex %1, [%3]\n"
907+" adds %0, %1, %4\n"
908+
909+#ifdef CONFIG_PAX_REFCOUNT
910+" bvc 3f\n"
911+" mov %0, %1\n"
912+"2: bkpt 0xf103\n"
913+"3:\n"
914+#endif
915+
916+" strex %1, %0, [%3]\n"
917+" teq %1, #0\n"
918+" bne 1b"
919+
920+#ifdef CONFIG_PAX_REFCOUNT
921+"\n4:\n"
922+ _ASM_EXTABLE(2b, 4b)
923+#endif
924+
925+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
926+ : "r" (&v->counter), "Ir" (i)
927+ : "cc");
928+
929+ smp_mb();
930+
931+ return result;
932+}
933+
934+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
935+{
936+ unsigned long tmp;
937+ int result;
938+
939+ smp_mb();
940+
941+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
942 "1: ldrex %0, [%3]\n"
943 " add %0, %0, %4\n"
944 " strex %1, %0, [%3]\n"
945@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
946 int result;
947
948 __asm__ __volatile__("@ atomic_sub\n"
949+"1: ldrex %1, [%3]\n"
950+" subs %0, %1, %4\n"
951+
952+#ifdef CONFIG_PAX_REFCOUNT
953+" bvc 3f\n"
954+"2: bkpt 0xf103\n"
955+"3:\n"
956+#endif
957+
958+" strex %1, %0, [%3]\n"
959+" teq %1, #0\n"
960+" bne 1b"
961+
962+#ifdef CONFIG_PAX_REFCOUNT
963+"\n4:\n"
964+ _ASM_EXTABLE(2b, 4b)
965+#endif
966+
967+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
968+ : "r" (&v->counter), "Ir" (i)
969+ : "cc");
970+}
971+
972+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
973+{
974+ unsigned long tmp;
975+ int result;
976+
977+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
978 "1: ldrex %0, [%3]\n"
979 " sub %0, %0, %4\n"
980 " strex %1, %0, [%3]\n"
981@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
982 smp_mb();
983
984 __asm__ __volatile__("@ atomic_sub_return\n"
985-"1: ldrex %0, [%3]\n"
986-" sub %0, %0, %4\n"
987+"1: ldrex %1, [%3]\n"
988+" subs %0, %1, %4\n"
989+
990+#ifdef CONFIG_PAX_REFCOUNT
991+" bvc 3f\n"
992+" mov %0, %1\n"
993+"2: bkpt 0xf103\n"
994+"3:\n"
995+#endif
996+
997 " strex %1, %0, [%3]\n"
998 " teq %1, #0\n"
999 " bne 1b"
1000+
1001+#ifdef CONFIG_PAX_REFCOUNT
1002+"\n4:\n"
1003+ _ASM_EXTABLE(2b, 4b)
1004+#endif
1005+
1006 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1007 : "r" (&v->counter), "Ir" (i)
1008 : "cc");
1009@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1010 return oldval;
1011 }
1012
1013+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1014+{
1015+ unsigned long oldval, res;
1016+
1017+ smp_mb();
1018+
1019+ do {
1020+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1021+ "ldrex %1, [%3]\n"
1022+ "mov %0, #0\n"
1023+ "teq %1, %4\n"
1024+ "strexeq %0, %5, [%3]\n"
1025+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1026+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1027+ : "cc");
1028+ } while (res);
1029+
1030+ smp_mb();
1031+
1032+ return oldval;
1033+}
1034+
1035 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1036 {
1037 unsigned long tmp, tmp2;
1038@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1039
1040 return val;
1041 }
1042+
1043+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1044+{
1045+ return atomic_add_return(i, v);
1046+}
1047+
1048 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1049+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1050+{
1051+ (void) atomic_add_return(i, v);
1052+}
1053
1054 static inline int atomic_sub_return(int i, atomic_t *v)
1055 {
1056@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1057 return val;
1058 }
1059 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1060+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1061+{
1062+ (void) atomic_sub_return(i, v);
1063+}
1064
1065 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1066 {
1067@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1068 return ret;
1069 }
1070
1071+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1072+{
1073+ return atomic_cmpxchg(v, old, new);
1074+}
1075+
1076 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1077 {
1078 unsigned long flags;
1079@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1080 #endif /* __LINUX_ARM_ARCH__ */
1081
1082 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1083+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1084+{
1085+ return xchg(&v->counter, new);
1086+}
1087
1088 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1089 {
1090@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1091 }
1092
1093 #define atomic_inc(v) atomic_add(1, v)
1094+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1095+{
1096+ atomic_add_unchecked(1, v);
1097+}
1098 #define atomic_dec(v) atomic_sub(1, v)
1099+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1100+{
1101+ atomic_sub_unchecked(1, v);
1102+}
1103
1104 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1105+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1106+{
1107+ return atomic_add_return_unchecked(1, v) == 0;
1108+}
1109 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1110 #define atomic_inc_return(v) (atomic_add_return(1, v))
1111+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1112+{
1113+ return atomic_add_return_unchecked(1, v);
1114+}
1115 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1116 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1117
1118@@ -241,6 +428,14 @@ typedef struct {
1119 u64 __aligned(8) counter;
1120 } atomic64_t;
1121
1122+#ifdef CONFIG_PAX_REFCOUNT
1123+typedef struct {
1124+ u64 __aligned(8) counter;
1125+} atomic64_unchecked_t;
1126+#else
1127+typedef atomic64_t atomic64_unchecked_t;
1128+#endif
1129+
1130 #define ATOMIC64_INIT(i) { (i) }
1131
1132 #ifdef CONFIG_ARM_LPAE
1133@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1134 return result;
1135 }
1136
1137+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1138+{
1139+ u64 result;
1140+
1141+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1142+" ldrd %0, %H0, [%1]"
1143+ : "=&r" (result)
1144+ : "r" (&v->counter), "Qo" (v->counter)
1145+ );
1146+
1147+ return result;
1148+}
1149+
1150 static inline void atomic64_set(atomic64_t *v, u64 i)
1151 {
1152 __asm__ __volatile__("@ atomic64_set\n"
1153@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1154 : "r" (&v->counter), "r" (i)
1155 );
1156 }
1157+
1158+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1159+{
1160+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1161+" strd %2, %H2, [%1]"
1162+ : "=Qo" (v->counter)
1163+ : "r" (&v->counter), "r" (i)
1164+ );
1165+}
1166 #else
1167 static inline u64 atomic64_read(const atomic64_t *v)
1168 {
1169@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1170 return result;
1171 }
1172
1173+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1174+{
1175+ u64 result;
1176+
1177+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1178+" ldrexd %0, %H0, [%1]"
1179+ : "=&r" (result)
1180+ : "r" (&v->counter), "Qo" (v->counter)
1181+ );
1182+
1183+ return result;
1184+}
1185+
1186 static inline void atomic64_set(atomic64_t *v, u64 i)
1187 {
1188 u64 tmp;
1189@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1190 : "r" (&v->counter), "r" (i)
1191 : "cc");
1192 }
1193+
1194+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1195+{
1196+ u64 tmp;
1197+
1198+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1199+"1: ldrexd %0, %H0, [%2]\n"
1200+" strexd %0, %3, %H3, [%2]\n"
1201+" teq %0, #0\n"
1202+" bne 1b"
1203+ : "=&r" (tmp), "=Qo" (v->counter)
1204+ : "r" (&v->counter), "r" (i)
1205+ : "cc");
1206+}
1207+
1208 #endif
1209
1210 static inline void atomic64_add(u64 i, atomic64_t *v)
1211@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1212 __asm__ __volatile__("@ atomic64_add\n"
1213 "1: ldrexd %0, %H0, [%3]\n"
1214 " adds %0, %0, %4\n"
1215+" adcs %H0, %H0, %H4\n"
1216+
1217+#ifdef CONFIG_PAX_REFCOUNT
1218+" bvc 3f\n"
1219+"2: bkpt 0xf103\n"
1220+"3:\n"
1221+#endif
1222+
1223+" strexd %1, %0, %H0, [%3]\n"
1224+" teq %1, #0\n"
1225+" bne 1b"
1226+
1227+#ifdef CONFIG_PAX_REFCOUNT
1228+"\n4:\n"
1229+ _ASM_EXTABLE(2b, 4b)
1230+#endif
1231+
1232+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1233+ : "r" (&v->counter), "r" (i)
1234+ : "cc");
1235+}
1236+
1237+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1238+{
1239+ u64 result;
1240+ unsigned long tmp;
1241+
1242+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1243+"1: ldrexd %0, %H0, [%3]\n"
1244+" adds %0, %0, %4\n"
1245 " adc %H0, %H0, %H4\n"
1246 " strexd %1, %0, %H0, [%3]\n"
1247 " teq %1, #0\n"
1248@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1249
1250 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1251 {
1252- u64 result;
1253- unsigned long tmp;
1254+ u64 result, tmp;
1255
1256 smp_mb();
1257
1258 __asm__ __volatile__("@ atomic64_add_return\n"
1259+"1: ldrexd %1, %H1, [%3]\n"
1260+" adds %0, %1, %4\n"
1261+" adcs %H0, %H1, %H4\n"
1262+
1263+#ifdef CONFIG_PAX_REFCOUNT
1264+" bvc 3f\n"
1265+" mov %0, %1\n"
1266+" mov %H0, %H1\n"
1267+"2: bkpt 0xf103\n"
1268+"3:\n"
1269+#endif
1270+
1271+" strexd %1, %0, %H0, [%3]\n"
1272+" teq %1, #0\n"
1273+" bne 1b"
1274+
1275+#ifdef CONFIG_PAX_REFCOUNT
1276+"\n4:\n"
1277+ _ASM_EXTABLE(2b, 4b)
1278+#endif
1279+
1280+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1281+ : "r" (&v->counter), "r" (i)
1282+ : "cc");
1283+
1284+ smp_mb();
1285+
1286+ return result;
1287+}
1288+
1289+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1290+{
1291+ u64 result;
1292+ unsigned long tmp;
1293+
1294+ smp_mb();
1295+
1296+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1297 "1: ldrexd %0, %H0, [%3]\n"
1298 " adds %0, %0, %4\n"
1299 " adc %H0, %H0, %H4\n"
1300@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1301 __asm__ __volatile__("@ atomic64_sub\n"
1302 "1: ldrexd %0, %H0, [%3]\n"
1303 " subs %0, %0, %4\n"
1304+" sbcs %H0, %H0, %H4\n"
1305+
1306+#ifdef CONFIG_PAX_REFCOUNT
1307+" bvc 3f\n"
1308+"2: bkpt 0xf103\n"
1309+"3:\n"
1310+#endif
1311+
1312+" strexd %1, %0, %H0, [%3]\n"
1313+" teq %1, #0\n"
1314+" bne 1b"
1315+
1316+#ifdef CONFIG_PAX_REFCOUNT
1317+"\n4:\n"
1318+ _ASM_EXTABLE(2b, 4b)
1319+#endif
1320+
1321+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1322+ : "r" (&v->counter), "r" (i)
1323+ : "cc");
1324+}
1325+
1326+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1327+{
1328+ u64 result;
1329+ unsigned long tmp;
1330+
1331+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1332+"1: ldrexd %0, %H0, [%3]\n"
1333+" subs %0, %0, %4\n"
1334 " sbc %H0, %H0, %H4\n"
1335 " strexd %1, %0, %H0, [%3]\n"
1336 " teq %1, #0\n"
1337@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1338
1339 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1340 {
1341- u64 result;
1342- unsigned long tmp;
1343+ u64 result, tmp;
1344
1345 smp_mb();
1346
1347 __asm__ __volatile__("@ atomic64_sub_return\n"
1348-"1: ldrexd %0, %H0, [%3]\n"
1349-" subs %0, %0, %4\n"
1350-" sbc %H0, %H0, %H4\n"
1351+"1: ldrexd %1, %H1, [%3]\n"
1352+" subs %0, %1, %4\n"
1353+" sbcs %H0, %H1, %H4\n"
1354+
1355+#ifdef CONFIG_PAX_REFCOUNT
1356+" bvc 3f\n"
1357+" mov %0, %1\n"
1358+" mov %H0, %H1\n"
1359+"2: bkpt 0xf103\n"
1360+"3:\n"
1361+#endif
1362+
1363 " strexd %1, %0, %H0, [%3]\n"
1364 " teq %1, #0\n"
1365 " bne 1b"
1366+
1367+#ifdef CONFIG_PAX_REFCOUNT
1368+"\n4:\n"
1369+ _ASM_EXTABLE(2b, 4b)
1370+#endif
1371+
1372 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1373 : "r" (&v->counter), "r" (i)
1374 : "cc");
1375@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1376 return oldval;
1377 }
1378
1379+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1380+{
1381+ u64 oldval;
1382+ unsigned long res;
1383+
1384+ smp_mb();
1385+
1386+ do {
1387+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1388+ "ldrexd %1, %H1, [%3]\n"
1389+ "mov %0, #0\n"
1390+ "teq %1, %4\n"
1391+ "teqeq %H1, %H4\n"
1392+ "strexdeq %0, %5, %H5, [%3]"
1393+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1394+ : "r" (&ptr->counter), "r" (old), "r" (new)
1395+ : "cc");
1396+ } while (res);
1397+
1398+ smp_mb();
1399+
1400+ return oldval;
1401+}
1402+
1403 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1404 {
1405 u64 result;
1406@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1407
1408 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1409 {
1410- u64 result;
1411- unsigned long tmp;
1412+ u64 result, tmp;
1413
1414 smp_mb();
1415
1416 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1417-"1: ldrexd %0, %H0, [%3]\n"
1418-" subs %0, %0, #1\n"
1419-" sbc %H0, %H0, #0\n"
1420+"1: ldrexd %1, %H1, [%3]\n"
1421+" subs %0, %1, #1\n"
1422+" sbcs %H0, %H1, #0\n"
1423+
1424+#ifdef CONFIG_PAX_REFCOUNT
1425+" bvc 3f\n"
1426+" mov %0, %1\n"
1427+" mov %H0, %H1\n"
1428+"2: bkpt 0xf103\n"
1429+"3:\n"
1430+#endif
1431+
1432 " teq %H0, #0\n"
1433-" bmi 2f\n"
1434+" bmi 4f\n"
1435 " strexd %1, %0, %H0, [%3]\n"
1436 " teq %1, #0\n"
1437 " bne 1b\n"
1438-"2:"
1439+"4:\n"
1440+
1441+#ifdef CONFIG_PAX_REFCOUNT
1442+ _ASM_EXTABLE(2b, 4b)
1443+#endif
1444+
1445 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1446 : "r" (&v->counter)
1447 : "cc");
1448@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1449 " teq %0, %5\n"
1450 " teqeq %H0, %H5\n"
1451 " moveq %1, #0\n"
1452-" beq 2f\n"
1453+" beq 4f\n"
1454 " adds %0, %0, %6\n"
1455-" adc %H0, %H0, %H6\n"
1456+" adcs %H0, %H0, %H6\n"
1457+
1458+#ifdef CONFIG_PAX_REFCOUNT
1459+" bvc 3f\n"
1460+"2: bkpt 0xf103\n"
1461+"3:\n"
1462+#endif
1463+
1464 " strexd %2, %0, %H0, [%4]\n"
1465 " teq %2, #0\n"
1466 " bne 1b\n"
1467-"2:"
1468+"4:\n"
1469+
1470+#ifdef CONFIG_PAX_REFCOUNT
1471+ _ASM_EXTABLE(2b, 4b)
1472+#endif
1473+
1474 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1475 : "r" (&v->counter), "r" (u), "r" (a)
1476 : "cc");
1477@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1478
1479 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1480 #define atomic64_inc(v) atomic64_add(1LL, (v))
1481+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1482 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1483+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1484 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1485 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1486 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1487+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1488 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1489 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1490 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1491diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1492index 75fe66b..ba3dee4 100644
1493--- a/arch/arm/include/asm/cache.h
1494+++ b/arch/arm/include/asm/cache.h
1495@@ -4,8 +4,10 @@
1496 #ifndef __ASMARM_CACHE_H
1497 #define __ASMARM_CACHE_H
1498
1499+#include <linux/const.h>
1500+
1501 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1502-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1503+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1504
1505 /*
1506 * Memory returned by kmalloc() may be used for DMA, so we must make
1507@@ -24,5 +26,6 @@
1508 #endif
1509
1510 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1511+#define __read_only __attribute__ ((__section__(".data..read_only")))
1512
1513 #endif
1514diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1515index 17d0ae8..014e350 100644
1516--- a/arch/arm/include/asm/cacheflush.h
1517+++ b/arch/arm/include/asm/cacheflush.h
1518@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1519 void (*dma_unmap_area)(const void *, size_t, int);
1520
1521 void (*dma_flush_range)(const void *, const void *);
1522-};
1523+} __no_const;
1524
1525 /*
1526 * Select the calling method
1527diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1528index 6dcc164..b14d917 100644
1529--- a/arch/arm/include/asm/checksum.h
1530+++ b/arch/arm/include/asm/checksum.h
1531@@ -37,7 +37,19 @@ __wsum
1532 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1533
1534 __wsum
1535-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1536+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1537+
1538+static inline __wsum
1539+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1540+{
1541+ __wsum ret;
1542+ pax_open_userland();
1543+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1544+ pax_close_userland();
1545+ return ret;
1546+}
1547+
1548+
1549
1550 /*
1551 * Fold a partial checksum without adding pseudo headers
1552diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1553index 4f009c1..466c59b 100644
1554--- a/arch/arm/include/asm/cmpxchg.h
1555+++ b/arch/arm/include/asm/cmpxchg.h
1556@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1557
1558 #define xchg(ptr,x) \
1559 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1560+#define xchg_unchecked(ptr,x) \
1561+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1562
1563 #include <asm-generic/cmpxchg-local.h>
1564
1565diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1566index 6ddbe44..b5e38b1 100644
1567--- a/arch/arm/include/asm/domain.h
1568+++ b/arch/arm/include/asm/domain.h
1569@@ -48,18 +48,37 @@
1570 * Domain types
1571 */
1572 #define DOMAIN_NOACCESS 0
1573-#define DOMAIN_CLIENT 1
1574 #ifdef CONFIG_CPU_USE_DOMAINS
1575+#define DOMAIN_USERCLIENT 1
1576+#define DOMAIN_KERNELCLIENT 1
1577 #define DOMAIN_MANAGER 3
1578+#define DOMAIN_VECTORS DOMAIN_USER
1579 #else
1580+
1581+#ifdef CONFIG_PAX_KERNEXEC
1582 #define DOMAIN_MANAGER 1
1583+#define DOMAIN_KERNEXEC 3
1584+#else
1585+#define DOMAIN_MANAGER 1
1586+#endif
1587+
1588+#ifdef CONFIG_PAX_MEMORY_UDEREF
1589+#define DOMAIN_USERCLIENT 0
1590+#define DOMAIN_UDEREF 1
1591+#define DOMAIN_VECTORS DOMAIN_KERNEL
1592+#else
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_VECTORS DOMAIN_USER
1595+#endif
1596+#define DOMAIN_KERNELCLIENT 1
1597+
1598 #endif
1599
1600 #define domain_val(dom,type) ((type) << (2*(dom)))
1601
1602 #ifndef __ASSEMBLY__
1603
1604-#ifdef CONFIG_CPU_USE_DOMAINS
1605+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1606 static inline void set_domain(unsigned val)
1607 {
1608 asm volatile(
1609@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1610 isb();
1611 }
1612
1613-#define modify_domain(dom,type) \
1614- do { \
1615- struct thread_info *thread = current_thread_info(); \
1616- unsigned int domain = thread->cpu_domain; \
1617- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1618- thread->cpu_domain = domain | domain_val(dom, type); \
1619- set_domain(thread->cpu_domain); \
1620- } while (0)
1621-
1622+extern void modify_domain(unsigned int dom, unsigned int type);
1623 #else
1624 static inline void set_domain(unsigned val) { }
1625 static inline void modify_domain(unsigned dom, unsigned type) { }
1626diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1627index 38050b1..9d90e8b 100644
1628--- a/arch/arm/include/asm/elf.h
1629+++ b/arch/arm/include/asm/elf.h
1630@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1631 the loader. We need to make sure that it is out of the way of the program
1632 that it will "exec", and that there is sufficient room for the brk. */
1633
1634-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1635+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1636+
1637+#ifdef CONFIG_PAX_ASLR
1638+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1639+
1640+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1641+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1642+#endif
1643
1644 /* When the program starts, a1 contains a pointer to a function to be
1645 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1646@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1647 extern void elf_set_personality(const struct elf32_hdr *);
1648 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1649
1650-struct mm_struct;
1651-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1652-#define arch_randomize_brk arch_randomize_brk
1653-
1654 #endif
1655diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1656index de53547..52b9a28 100644
1657--- a/arch/arm/include/asm/fncpy.h
1658+++ b/arch/arm/include/asm/fncpy.h
1659@@ -81,7 +81,9 @@
1660 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1661 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1662 \
1663+ pax_open_kernel(); \
1664 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1665+ pax_close_kernel(); \
1666 flush_icache_range((unsigned long)(dest_buf), \
1667 (unsigned long)(dest_buf) + (size)); \
1668 \
1669diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1670index e42cf59..7b94b8f 100644
1671--- a/arch/arm/include/asm/futex.h
1672+++ b/arch/arm/include/asm/futex.h
1673@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1674 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1675 return -EFAULT;
1676
1677+ pax_open_userland();
1678+
1679 smp_mb();
1680 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1681 "1: ldrex %1, [%4]\n"
1682@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1683 : "cc", "memory");
1684 smp_mb();
1685
1686+ pax_close_userland();
1687+
1688 *uval = val;
1689 return ret;
1690 }
1691@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1692 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1693 return -EFAULT;
1694
1695+ pax_open_userland();
1696+
1697 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1698 "1: " TUSER(ldr) " %1, [%4]\n"
1699 " teq %1, %2\n"
1700@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1701 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1702 : "cc", "memory");
1703
1704+ pax_close_userland();
1705+
1706 *uval = val;
1707 return ret;
1708 }
1709@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1710 return -EFAULT;
1711
1712 pagefault_disable(); /* implies preempt_disable() */
1713+ pax_open_userland();
1714
1715 switch (op) {
1716 case FUTEX_OP_SET:
1717@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1718 ret = -ENOSYS;
1719 }
1720
1721+ pax_close_userland();
1722 pagefault_enable(); /* subsumes preempt_enable() */
1723
1724 if (!ret) {
1725diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1726index 83eb2f7..ed77159 100644
1727--- a/arch/arm/include/asm/kmap_types.h
1728+++ b/arch/arm/include/asm/kmap_types.h
1729@@ -4,6 +4,6 @@
1730 /*
1731 * This is the "bare minimum". AIO seems to require this.
1732 */
1733-#define KM_TYPE_NR 16
1734+#define KM_TYPE_NR 17
1735
1736 #endif
1737diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1738index 9e614a1..3302cca 100644
1739--- a/arch/arm/include/asm/mach/dma.h
1740+++ b/arch/arm/include/asm/mach/dma.h
1741@@ -22,7 +22,7 @@ struct dma_ops {
1742 int (*residue)(unsigned int, dma_t *); /* optional */
1743 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1744 const char *type;
1745-};
1746+} __do_const;
1747
1748 struct dma_struct {
1749 void *addr; /* single DMA address */
1750diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1751index 2fe141f..192dc01 100644
1752--- a/arch/arm/include/asm/mach/map.h
1753+++ b/arch/arm/include/asm/mach/map.h
1754@@ -27,13 +27,16 @@ struct map_desc {
1755 #define MT_MINICLEAN 6
1756 #define MT_LOW_VECTORS 7
1757 #define MT_HIGH_VECTORS 8
1758-#define MT_MEMORY 9
1759+#define MT_MEMORY_RWX 9
1760 #define MT_ROM 10
1761-#define MT_MEMORY_NONCACHED 11
1762+#define MT_MEMORY_NONCACHED_RX 11
1763 #define MT_MEMORY_DTCM 12
1764 #define MT_MEMORY_ITCM 13
1765 #define MT_MEMORY_SO 14
1766 #define MT_MEMORY_DMA_READY 15
1767+#define MT_MEMORY_RW 16
1768+#define MT_MEMORY_RX 17
1769+#define MT_MEMORY_NONCACHED_RW 18
1770
1771 #ifdef CONFIG_MMU
1772 extern void iotable_init(struct map_desc *, int);
1773diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1774index 12f71a1..04e063c 100644
1775--- a/arch/arm/include/asm/outercache.h
1776+++ b/arch/arm/include/asm/outercache.h
1777@@ -35,7 +35,7 @@ struct outer_cache_fns {
1778 #endif
1779 void (*set_debug)(unsigned long);
1780 void (*resume)(void);
1781-};
1782+} __no_const;
1783
1784 #ifdef CONFIG_OUTER_CACHE
1785
1786diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1787index 812a494..71fc0b6 100644
1788--- a/arch/arm/include/asm/page.h
1789+++ b/arch/arm/include/asm/page.h
1790@@ -114,7 +114,7 @@ struct cpu_user_fns {
1791 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1792 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1793 unsigned long vaddr, struct vm_area_struct *vma);
1794-};
1795+} __no_const;
1796
1797 #ifdef MULTI_USER
1798 extern struct cpu_user_fns cpu_user;
1799diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1800index 943504f..c37a730 100644
1801--- a/arch/arm/include/asm/pgalloc.h
1802+++ b/arch/arm/include/asm/pgalloc.h
1803@@ -17,6 +17,7 @@
1804 #include <asm/processor.h>
1805 #include <asm/cacheflush.h>
1806 #include <asm/tlbflush.h>
1807+#include <asm/system_info.h>
1808
1809 #define check_pgt_cache() do { } while (0)
1810
1811@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1812 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1813 }
1814
1815+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1816+{
1817+ pud_populate(mm, pud, pmd);
1818+}
1819+
1820 #else /* !CONFIG_ARM_LPAE */
1821
1822 /*
1823@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1824 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1825 #define pmd_free(mm, pmd) do { } while (0)
1826 #define pud_populate(mm,pmd,pte) BUG()
1827+#define pud_populate_kernel(mm,pmd,pte) BUG()
1828
1829 #endif /* CONFIG_ARM_LPAE */
1830
1831@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1832 __free_page(pte);
1833 }
1834
1835+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1836+{
1837+#ifdef CONFIG_ARM_LPAE
1838+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1839+#else
1840+ if (addr & SECTION_SIZE)
1841+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1842+ else
1843+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1844+#endif
1845+ flush_pmd_entry(pmdp);
1846+}
1847+
1848 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1849 pmdval_t prot)
1850 {
1851@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1852 static inline void
1853 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1854 {
1855- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1856+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1857 }
1858 #define pmd_pgtable(pmd) pmd_page(pmd)
1859
1860diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1861index 5cfba15..f415e1a 100644
1862--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1863+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1864@@ -20,12 +20,15 @@
1865 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1866 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1867 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1868+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1869 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1870 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1871 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1872+
1873 /*
1874 * - section
1875 */
1876+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1877 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1878 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1879 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1880@@ -37,6 +40,7 @@
1881 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1882 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1883 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1884+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1885
1886 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1887 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1888@@ -66,6 +70,7 @@
1889 * - extended small page/tiny page
1890 */
1891 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1892+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1893 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1894 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1895 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1896diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1897index f97ee02..07f1be5 100644
1898--- a/arch/arm/include/asm/pgtable-2level.h
1899+++ b/arch/arm/include/asm/pgtable-2level.h
1900@@ -125,6 +125,7 @@
1901 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1902 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1903 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1904+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1905
1906 /*
1907 * These are the memory types, defined to be compatible with
1908diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1909index 18f5cef..25b8f43 100644
1910--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1911+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1912@@ -41,6 +41,7 @@
1913 */
1914 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1915 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1916+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1917 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1918 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1919 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1920@@ -71,6 +72,7 @@
1921 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1922 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1923 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1924+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1925 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1926
1927 /*
1928diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1929index 86b8fe3..e25f975 100644
1930--- a/arch/arm/include/asm/pgtable-3level.h
1931+++ b/arch/arm/include/asm/pgtable-3level.h
1932@@ -74,6 +74,7 @@
1933 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1934 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1935 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1936+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1937 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1938 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1939 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1940@@ -82,6 +83,7 @@
1941 /*
1942 * To be used in assembly code with the upper page attributes.
1943 */
1944+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1945 #define L_PTE_XN_HIGH (1 << (54 - 32))
1946 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1947
1948diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1949index 9bcd262..fba731c 100644
1950--- a/arch/arm/include/asm/pgtable.h
1951+++ b/arch/arm/include/asm/pgtable.h
1952@@ -30,6 +30,9 @@
1953 #include <asm/pgtable-2level.h>
1954 #endif
1955
1956+#define ktla_ktva(addr) (addr)
1957+#define ktva_ktla(addr) (addr)
1958+
1959 /*
1960 * Just any arbitrary offset to the start of the vmalloc VM area: the
1961 * current 8MB value just means that there will be a 8MB "hole" after the
1962@@ -45,6 +48,9 @@
1963 #define LIBRARY_TEXT_START 0x0c000000
1964
1965 #ifndef __ASSEMBLY__
1966+extern pteval_t __supported_pte_mask;
1967+extern pmdval_t __supported_pmd_mask;
1968+
1969 extern void __pte_error(const char *file, int line, pte_t);
1970 extern void __pmd_error(const char *file, int line, pmd_t);
1971 extern void __pgd_error(const char *file, int line, pgd_t);
1972@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1973 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1974 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1975
1976+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1977+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1978+
1979+#ifdef CONFIG_PAX_KERNEXEC
1980+#include <asm/domain.h>
1981+#include <linux/thread_info.h>
1982+#include <linux/preempt.h>
1983+#endif
1984+
1985+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1986+static inline int test_domain(int domain, int domaintype)
1987+{
1988+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1989+}
1990+#endif
1991+
1992+#ifdef CONFIG_PAX_KERNEXEC
1993+static inline unsigned long pax_open_kernel(void) {
1994+#ifdef CONFIG_ARM_LPAE
1995+ /* TODO */
1996+#else
1997+ preempt_disable();
1998+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1999+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2000+#endif
2001+ return 0;
2002+}
2003+
2004+static inline unsigned long pax_close_kernel(void) {
2005+#ifdef CONFIG_ARM_LPAE
2006+ /* TODO */
2007+#else
2008+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2009+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2010+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2011+ preempt_enable_no_resched();
2012+#endif
2013+ return 0;
2014+}
2015+#else
2016+static inline unsigned long pax_open_kernel(void) { return 0; }
2017+static inline unsigned long pax_close_kernel(void) { return 0; }
2018+#endif
2019+
2020 /*
2021 * This is the lowest virtual address we can permit any user space
2022 * mapping to be mapped at. This is particularly important for
2023@@ -72,8 +122,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2024 /*
2025 * The pgprot_* and protection_map entries will be fixed up in runtime
2026 * to include the cachable and bufferable bits based on memory policy,
2027- * as well as any architecture dependent bits like global/ASID and SMP
2028- * shared mapping bits.
2029+ * as well as any architecture dependent bits like global/ASID, PXN,
2030+ * and SMP shared mapping bits.
2031 */
2032 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2033
2034@@ -257,7 +307,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2035 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2036 {
2037 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2038- L_PTE_NONE | L_PTE_VALID;
2039+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2040 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2041 return pte;
2042 }
2043diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2044index f3628fb..a0672dd 100644
2045--- a/arch/arm/include/asm/proc-fns.h
2046+++ b/arch/arm/include/asm/proc-fns.h
2047@@ -75,7 +75,7 @@ extern struct processor {
2048 unsigned int suspend_size;
2049 void (*do_suspend)(void *);
2050 void (*do_resume)(void *);
2051-} processor;
2052+} __do_const processor;
2053
2054 #ifndef MULTI_CPU
2055 extern void cpu_proc_init(void);
2056diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2057index 06e7d50..8a8e251 100644
2058--- a/arch/arm/include/asm/processor.h
2059+++ b/arch/arm/include/asm/processor.h
2060@@ -65,9 +65,8 @@ struct thread_struct {
2061 regs->ARM_cpsr |= PSR_ENDSTATE; \
2062 regs->ARM_pc = pc & ~1; /* pc */ \
2063 regs->ARM_sp = sp; /* sp */ \
2064- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2065- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2066- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2067+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2068+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2069 nommu_start_thread(regs); \
2070 })
2071
2072diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2073index ce0dbe7..c085b6f 100644
2074--- a/arch/arm/include/asm/psci.h
2075+++ b/arch/arm/include/asm/psci.h
2076@@ -29,7 +29,7 @@ struct psci_operations {
2077 int (*cpu_off)(struct psci_power_state state);
2078 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2079 int (*migrate)(unsigned long cpuid);
2080-};
2081+} __no_const;
2082
2083 extern struct psci_operations psci_ops;
2084
2085diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2086index d3a22be..3a69ad5 100644
2087--- a/arch/arm/include/asm/smp.h
2088+++ b/arch/arm/include/asm/smp.h
2089@@ -107,7 +107,7 @@ struct smp_operations {
2090 int (*cpu_disable)(unsigned int cpu);
2091 #endif
2092 #endif
2093-};
2094+} __no_const;
2095
2096 /*
2097 * set platform specific SMP operations
2098diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2099index 1995d1a..76693a2 100644
2100--- a/arch/arm/include/asm/thread_info.h
2101+++ b/arch/arm/include/asm/thread_info.h
2102@@ -77,9 +77,9 @@ struct thread_info {
2103 .flags = 0, \
2104 .preempt_count = INIT_PREEMPT_COUNT, \
2105 .addr_limit = KERNEL_DS, \
2106- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2107- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2108- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2109+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2110+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2111+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2112 .restart_block = { \
2113 .fn = do_no_restart_syscall, \
2114 }, \
2115@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2116 #define TIF_SYSCALL_AUDIT 9
2117 #define TIF_SYSCALL_TRACEPOINT 10
2118 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2119-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2120+/* within 8 bits of TIF_SYSCALL_TRACE
2121+ * to meet flexible second operand requirements
2122+ */
2123+#define TIF_GRSEC_SETXID 12
2124+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2125 #define TIF_USING_IWMMXT 17
2126 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2127 #define TIF_RESTORE_SIGMASK 20
2128@@ -166,10 +170,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2129 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2130 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2131 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2132+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2133
2134 /* Checks for any syscall work in entry-common.S */
2135 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2136- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2137+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2138
2139 /*
2140 * Change these and you break ASM code in entry-common.S
2141diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2142index 7e1f760..d42d7f8 100644
2143--- a/arch/arm/include/asm/uaccess.h
2144+++ b/arch/arm/include/asm/uaccess.h
2145@@ -18,6 +18,7 @@
2146 #include <asm/domain.h>
2147 #include <asm/unified.h>
2148 #include <asm/compiler.h>
2149+#include <asm/pgtable.h>
2150
2151 #define VERIFY_READ 0
2152 #define VERIFY_WRITE 1
2153@@ -63,11 +64,35 @@ extern int __put_user_bad(void);
2154 static inline void set_fs(mm_segment_t fs)
2155 {
2156 current_thread_info()->addr_limit = fs;
2157- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2158+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2159 }
2160
2161 #define segment_eq(a,b) ((a) == (b))
2162
2163+static inline void pax_open_userland(void)
2164+{
2165+
2166+#ifdef CONFIG_PAX_MEMORY_UDEREF
2167+ if (segment_eq(get_fs(), USER_DS)) {
2168+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2169+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2170+ }
2171+#endif
2172+
2173+}
2174+
2175+static inline void pax_close_userland(void)
2176+{
2177+
2178+#ifdef CONFIG_PAX_MEMORY_UDEREF
2179+ if (segment_eq(get_fs(), USER_DS)) {
2180+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2181+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2182+ }
2183+#endif
2184+
2185+}
2186+
2187 #define __addr_ok(addr) ({ \
2188 unsigned long flag; \
2189 __asm__("cmp %2, %0; movlo %0, #0" \
2190@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2191
2192 #define get_user(x,p) \
2193 ({ \
2194+ int __e; \
2195 might_fault(); \
2196- __get_user_check(x,p); \
2197+ pax_open_userland(); \
2198+ __e = __get_user_check(x,p); \
2199+ pax_close_userland(); \
2200+ __e; \
2201 })
2202
2203 extern int __put_user_1(void *, unsigned int);
2204@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2205
2206 #define put_user(x,p) \
2207 ({ \
2208+ int __e; \
2209 might_fault(); \
2210- __put_user_check(x,p); \
2211+ pax_open_userland(); \
2212+ __e = __put_user_check(x,p); \
2213+ pax_close_userland(); \
2214+ __e; \
2215 })
2216
2217 #else /* CONFIG_MMU */
2218@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2219 #define __get_user(x,ptr) \
2220 ({ \
2221 long __gu_err = 0; \
2222+ pax_open_userland(); \
2223 __get_user_err((x),(ptr),__gu_err); \
2224+ pax_close_userland(); \
2225 __gu_err; \
2226 })
2227
2228 #define __get_user_error(x,ptr,err) \
2229 ({ \
2230+ pax_open_userland(); \
2231 __get_user_err((x),(ptr),err); \
2232+ pax_close_userland(); \
2233 (void) 0; \
2234 })
2235
2236@@ -312,13 +349,17 @@ do { \
2237 #define __put_user(x,ptr) \
2238 ({ \
2239 long __pu_err = 0; \
2240+ pax_open_userland(); \
2241 __put_user_err((x),(ptr),__pu_err); \
2242+ pax_close_userland(); \
2243 __pu_err; \
2244 })
2245
2246 #define __put_user_error(x,ptr,err) \
2247 ({ \
2248+ pax_open_userland(); \
2249 __put_user_err((x),(ptr),err); \
2250+ pax_close_userland(); \
2251 (void) 0; \
2252 })
2253
2254@@ -418,11 +459,44 @@ do { \
2255
2256
2257 #ifdef CONFIG_MMU
2258-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2259-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2260+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2261+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2262+
2263+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2264+{
2265+ unsigned long ret;
2266+
2267+ check_object_size(to, n, false);
2268+ pax_open_userland();
2269+ ret = ___copy_from_user(to, from, n);
2270+ pax_close_userland();
2271+ return ret;
2272+}
2273+
2274+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2275+{
2276+ unsigned long ret;
2277+
2278+ check_object_size(from, n, true);
2279+ pax_open_userland();
2280+ ret = ___copy_to_user(to, from, n);
2281+ pax_close_userland();
2282+ return ret;
2283+}
2284+
2285 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2286-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2287+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2288 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2289+
2290+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2291+{
2292+ unsigned long ret;
2293+ pax_open_userland();
2294+ ret = ___clear_user(addr, n);
2295+ pax_close_userland();
2296+ return ret;
2297+}
2298+
2299 #else
2300 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2301 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2302@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2303
2304 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2305 {
2306+ if ((long)n < 0)
2307+ return n;
2308+
2309 if (access_ok(VERIFY_READ, from, n))
2310 n = __copy_from_user(to, from, n);
2311 else /* security hole - plug it */
2312@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2313
2314 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2315 {
2316+ if ((long)n < 0)
2317+ return n;
2318+
2319 if (access_ok(VERIFY_WRITE, to, n))
2320 n = __copy_to_user(to, from, n);
2321 return n;
2322diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2323index 96ee092..37f1844 100644
2324--- a/arch/arm/include/uapi/asm/ptrace.h
2325+++ b/arch/arm/include/uapi/asm/ptrace.h
2326@@ -73,7 +73,7 @@
2327 * ARMv7 groups of PSR bits
2328 */
2329 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2330-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2331+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2332 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2333 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2334
2335diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2336index 60d3b73..e5a0f22 100644
2337--- a/arch/arm/kernel/armksyms.c
2338+++ b/arch/arm/kernel/armksyms.c
2339@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2340
2341 /* networking */
2342 EXPORT_SYMBOL(csum_partial);
2343-EXPORT_SYMBOL(csum_partial_copy_from_user);
2344+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2345 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2346 EXPORT_SYMBOL(__csum_ipv6_magic);
2347
2348@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2349 #ifdef CONFIG_MMU
2350 EXPORT_SYMBOL(copy_page);
2351
2352-EXPORT_SYMBOL(__copy_from_user);
2353-EXPORT_SYMBOL(__copy_to_user);
2354-EXPORT_SYMBOL(__clear_user);
2355+EXPORT_SYMBOL(___copy_from_user);
2356+EXPORT_SYMBOL(___copy_to_user);
2357+EXPORT_SYMBOL(___clear_user);
2358
2359 EXPORT_SYMBOL(__get_user_1);
2360 EXPORT_SYMBOL(__get_user_2);
2361diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2362index 582b405..50351b7 100644
2363--- a/arch/arm/kernel/entry-armv.S
2364+++ b/arch/arm/kernel/entry-armv.S
2365@@ -47,6 +47,87 @@
2366 9997:
2367 .endm
2368
2369+ .macro pax_enter_kernel
2370+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2371+ @ make aligned space for saved DACR
2372+ sub sp, sp, #8
2373+ @ save regs
2374+ stmdb sp!, {r1, r2}
2375+ @ read DACR from cpu_domain into r1
2376+ mov r2, sp
2377+ @ assume 8K pages, since we have to split the immediate in two
2378+ bic r2, r2, #(0x1fc0)
2379+ bic r2, r2, #(0x3f)
2380+ ldr r1, [r2, #TI_CPU_DOMAIN]
2381+ @ store old DACR on stack
2382+ str r1, [sp, #8]
2383+#ifdef CONFIG_PAX_KERNEXEC
2384+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2385+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2386+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2387+#endif
2388+#ifdef CONFIG_PAX_MEMORY_UDEREF
2389+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2390+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2391+#endif
2392+ @ write r1 to current_thread_info()->cpu_domain
2393+ str r1, [r2, #TI_CPU_DOMAIN]
2394+ @ write r1 to DACR
2395+ mcr p15, 0, r1, c3, c0, 0
2396+ @ instruction sync
2397+ instr_sync
2398+ @ restore regs
2399+ ldmia sp!, {r1, r2}
2400+#endif
2401+ .endm
2402+
2403+ .macro pax_open_userland
2404+#ifdef CONFIG_PAX_MEMORY_UDEREF
2405+ @ save regs
2406+ stmdb sp!, {r0, r1}
2407+ @ read DACR from cpu_domain into r1
2408+ mov r0, sp
2409+ @ assume 8K pages, since we have to split the immediate in two
2410+ bic r0, r0, #(0x1fc0)
2411+ bic r0, r0, #(0x3f)
2412+ ldr r1, [r0, #TI_CPU_DOMAIN]
2413+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2414+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2415+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2416+ @ write r1 to current_thread_info()->cpu_domain
2417+ str r1, [r0, #TI_CPU_DOMAIN]
2418+ @ write r1 to DACR
2419+ mcr p15, 0, r1, c3, c0, 0
2420+ @ instruction sync
2421+ instr_sync
2422+ @ restore regs
2423+ ldmia sp!, {r0, r1}
2424+#endif
2425+ .endm
2426+
2427+ .macro pax_close_userland
2428+#ifdef CONFIG_PAX_MEMORY_UDEREF
2429+ @ save regs
2430+ stmdb sp!, {r0, r1}
2431+ @ read DACR from cpu_domain into r1
2432+ mov r0, sp
2433+ @ assume 8K pages, since we have to split the immediate in two
2434+ bic r0, r0, #(0x1fc0)
2435+ bic r0, r0, #(0x3f)
2436+ ldr r1, [r0, #TI_CPU_DOMAIN]
2437+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2438+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2439+ @ write r1 to current_thread_info()->cpu_domain
2440+ str r1, [r0, #TI_CPU_DOMAIN]
2441+ @ write r1 to DACR
2442+ mcr p15, 0, r1, c3, c0, 0
2443+ @ instruction sync
2444+ instr_sync
2445+ @ restore regs
2446+ ldmia sp!, {r0, r1}
2447+#endif
2448+ .endm
2449+
2450 .macro pabt_helper
2451 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2452 #ifdef MULTI_PABORT
2453@@ -89,11 +170,15 @@
2454 * Invalid mode handlers
2455 */
2456 .macro inv_entry, reason
2457+
2458+ pax_enter_kernel
2459+
2460 sub sp, sp, #S_FRAME_SIZE
2461 ARM( stmib sp, {r1 - lr} )
2462 THUMB( stmia sp, {r0 - r12} )
2463 THUMB( str sp, [sp, #S_SP] )
2464 THUMB( str lr, [sp, #S_LR] )
2465+
2466 mov r1, #\reason
2467 .endm
2468
2469@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2470 .macro svc_entry, stack_hole=0
2471 UNWIND(.fnstart )
2472 UNWIND(.save {r0 - pc} )
2473+
2474+ pax_enter_kernel
2475+
2476 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2477+
2478 #ifdef CONFIG_THUMB2_KERNEL
2479 SPFIX( str r0, [sp] ) @ temporarily saved
2480 SPFIX( mov r0, sp )
2481@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2482 ldmia r0, {r3 - r5}
2483 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2484 mov r6, #-1 @ "" "" "" ""
2485+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2486+ @ offset sp by 8 as done in pax_enter_kernel
2487+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2488+#else
2489 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2490+#endif
2491 SPFIX( addeq r2, r2, #4 )
2492 str r3, [sp, #-4]! @ save the "real" r0 copied
2493 @ from the exception stack
2494@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2495 .macro usr_entry
2496 UNWIND(.fnstart )
2497 UNWIND(.cantunwind ) @ don't unwind the user space
2498+
2499+ pax_enter_kernel_user
2500+
2501 sub sp, sp, #S_FRAME_SIZE
2502 ARM( stmib sp, {r1 - r12} )
2503 THUMB( stmia sp, {r0 - r12} )
2504@@ -414,7 +511,9 @@ __und_usr:
2505 tst r3, #PSR_T_BIT @ Thumb mode?
2506 bne __und_usr_thumb
2507 sub r4, r2, #4 @ ARM instr at LR - 4
2508+ pax_open_userland
2509 1: ldrt r0, [r4]
2510+ pax_close_userland
2511 #ifdef CONFIG_CPU_ENDIAN_BE8
2512 rev r0, r0 @ little endian instruction
2513 #endif
2514@@ -449,10 +548,14 @@ __und_usr_thumb:
2515 */
2516 .arch armv6t2
2517 #endif
2518+ pax_open_userland
2519 2: ldrht r5, [r4]
2520+ pax_close_userland
2521 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2522 blo __und_usr_fault_16 @ 16bit undefined instruction
2523+ pax_open_userland
2524 3: ldrht r0, [r2]
2525+ pax_close_userland
2526 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2527 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2528 orr r0, r0, r5, lsl #16
2529@@ -690,7 +793,7 @@ ENTRY(__switch_to)
2530 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2531 THUMB( str sp, [ip], #4 )
2532 THUMB( str lr, [ip], #4 )
2533-#ifdef CONFIG_CPU_USE_DOMAINS
2534+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2535 ldr r6, [r2, #TI_CPU_DOMAIN]
2536 #endif
2537 set_tls r3, r4, r5
2538@@ -699,7 +802,7 @@ ENTRY(__switch_to)
2539 ldr r8, =__stack_chk_guard
2540 ldr r7, [r7, #TSK_STACK_CANARY]
2541 #endif
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2545 #endif
2546 mov r5, r0
2547diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2548index bc5bc0a..d0998ca 100644
2549--- a/arch/arm/kernel/entry-common.S
2550+++ b/arch/arm/kernel/entry-common.S
2551@@ -10,18 +10,46 @@
2552
2553 #include <asm/unistd.h>
2554 #include <asm/ftrace.h>
2555+#include <asm/domain.h>
2556 #include <asm/unwind.h>
2557
2558+#include "entry-header.S"
2559+
2560 #ifdef CONFIG_NEED_RET_TO_USER
2561 #include <mach/entry-macro.S>
2562 #else
2563 .macro arch_ret_to_user, tmp1, tmp2
2564+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2565+ @ save regs
2566+ stmdb sp!, {r1, r2}
2567+ @ read DACR from cpu_domain into r1
2568+ mov r2, sp
2569+ @ assume 8K pages, since we have to split the immediate in two
2570+ bic r2, r2, #(0x1fc0)
2571+ bic r2, r2, #(0x3f)
2572+ ldr r1, [r2, #TI_CPU_DOMAIN]
2573+#ifdef CONFIG_PAX_KERNEXEC
2574+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2575+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2576+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2577+#endif
2578+#ifdef CONFIG_PAX_MEMORY_UDEREF
2579+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2580+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2581+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2582+#endif
2583+ @ write r1 to current_thread_info()->cpu_domain
2584+ str r1, [r2, #TI_CPU_DOMAIN]
2585+ @ write r1 to DACR
2586+ mcr p15, 0, r1, c3, c0, 0
2587+ @ instruction sync
2588+ instr_sync
2589+ @ restore regs
2590+ ldmia sp!, {r1, r2}
2591+#endif
2592 .endm
2593 #endif
2594
2595-#include "entry-header.S"
2596-
2597-
2598 .align 5
2599 /*
2600 * This is the fast syscall return path. We do as little as
2601@@ -350,6 +378,7 @@ ENDPROC(ftrace_stub)
2602
2603 .align 5
2604 ENTRY(vector_swi)
2605+
2606 sub sp, sp, #S_FRAME_SIZE
2607 stmia sp, {r0 - r12} @ Calling r0 - r12
2608 ARM( add r8, sp, #S_PC )
2609@@ -399,6 +428,12 @@ ENTRY(vector_swi)
2610 ldr scno, [lr, #-4] @ get SWI instruction
2611 #endif
2612
2613+ /*
2614+ * do this here to avoid a performance hit of wrapping the code above
2615+ * that directly dereferences userland to parse the SWI instruction
2616+ */
2617+ pax_enter_kernel_user
2618+
2619 #ifdef CONFIG_ALIGNMENT_TRAP
2620 ldr ip, __cr_alignment
2621 ldr ip, [ip]
2622diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2623index 160f337..db67ee4 100644
2624--- a/arch/arm/kernel/entry-header.S
2625+++ b/arch/arm/kernel/entry-header.S
2626@@ -73,6 +73,60 @@
2627 msr cpsr_c, \rtemp @ switch back to the SVC mode
2628 .endm
2629
2630+ .macro pax_enter_kernel_user
2631+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2632+ @ save regs
2633+ stmdb sp!, {r0, r1}
2634+ @ read DACR from cpu_domain into r1
2635+ mov r0, sp
2636+ @ assume 8K pages, since we have to split the immediate in two
2637+ bic r0, r0, #(0x1fc0)
2638+ bic r0, r0, #(0x3f)
2639+ ldr r1, [r0, #TI_CPU_DOMAIN]
2640+#ifdef CONFIG_PAX_MEMORY_UDEREF
2641+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2642+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2643+#endif
2644+#ifdef CONFIG_PAX_KERNEXEC
2645+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2646+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2647+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2648+#endif
2649+ @ write r1 to current_thread_info()->cpu_domain
2650+ str r1, [r0, #TI_CPU_DOMAIN]
2651+ @ write r1 to DACR
2652+ mcr p15, 0, r1, c3, c0, 0
2653+ @ instruction sync
2654+ instr_sync
2655+ @ restore regs
2656+ ldmia sp!, {r0, r1}
2657+#endif
2658+ .endm
2659+
2660+ .macro pax_exit_kernel
2661+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2662+ @ save regs
2663+ stmdb sp!, {r0, r1}
2664+ @ read old DACR from stack into r1
2665+ ldr r1, [sp, #(8 + S_SP)]
2666+ sub r1, r1, #8
2667+ ldr r1, [r1]
2668+
2669+ @ write r1 to current_thread_info()->cpu_domain
2670+ mov r0, sp
2671+ @ assume 8K pages, since we have to split the immediate in two
2672+ bic r0, r0, #(0x1fc0)
2673+ bic r0, r0, #(0x3f)
2674+ str r1, [r0, #TI_CPU_DOMAIN]
2675+ @ write r1 to DACR
2676+ mcr p15, 0, r1, c3, c0, 0
2677+ @ instruction sync
2678+ instr_sync
2679+ @ restore regs
2680+ ldmia sp!, {r0, r1}
2681+#endif
2682+ .endm
2683+
2684 #ifndef CONFIG_THUMB2_KERNEL
2685 .macro svc_exit, rpsr, irq = 0
2686 .if \irq != 0
2687@@ -92,6 +146,9 @@
2688 blne trace_hardirqs_off
2689 #endif
2690 .endif
2691+
2692+ pax_exit_kernel
2693+
2694 msr spsr_cxsf, \rpsr
2695 #if defined(CONFIG_CPU_V6)
2696 ldr r0, [sp]
2697@@ -155,6 +212,9 @@
2698 blne trace_hardirqs_off
2699 #endif
2700 .endif
2701+
2702+ pax_exit_kernel
2703+
2704 ldr lr, [sp, #S_SP] @ top of the stack
2705 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2706 clrex @ clear the exclusive monitor
2707diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2708index 2adda11..7fbe958 100644
2709--- a/arch/arm/kernel/fiq.c
2710+++ b/arch/arm/kernel/fiq.c
2711@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2712 #if defined(CONFIG_CPU_USE_DOMAINS)
2713 memcpy((void *)0xffff001c, start, length);
2714 #else
2715+ pax_open_kernel();
2716 memcpy(vectors_page + 0x1c, start, length);
2717+ pax_close_kernel();
2718 #endif
2719 flush_icache_range(0xffff001c, 0xffff001c + length);
2720 if (!vectors_high())
2721diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2722index 8bac553..caee108 100644
2723--- a/arch/arm/kernel/head.S
2724+++ b/arch/arm/kernel/head.S
2725@@ -52,7 +52,9 @@
2726 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2727
2728 .macro pgtbl, rd, phys
2729- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2730+ mov \rd, #TEXT_OFFSET
2731+ sub \rd, #PG_DIR_SIZE
2732+ add \rd, \rd, \phys
2733 .endm
2734
2735 /*
2736@@ -434,7 +436,7 @@ __enable_mmu:
2737 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2738 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2739 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2740- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2741+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2742 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2743 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2744 #endif
2745diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2746index 1fd749e..47adb08 100644
2747--- a/arch/arm/kernel/hw_breakpoint.c
2748+++ b/arch/arm/kernel/hw_breakpoint.c
2749@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2750 return NOTIFY_OK;
2751 }
2752
2753-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2754+static struct notifier_block dbg_reset_nb = {
2755 .notifier_call = dbg_reset_notify,
2756 };
2757
2758diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2759index 1e9be5d..03edbc2 100644
2760--- a/arch/arm/kernel/module.c
2761+++ b/arch/arm/kernel/module.c
2762@@ -37,12 +37,37 @@
2763 #endif
2764
2765 #ifdef CONFIG_MMU
2766-void *module_alloc(unsigned long size)
2767+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2768 {
2769+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2770+ return NULL;
2771 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2772- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2773+ GFP_KERNEL, prot, -1,
2774 __builtin_return_address(0));
2775 }
2776+
2777+void *module_alloc(unsigned long size)
2778+{
2779+
2780+#ifdef CONFIG_PAX_KERNEXEC
2781+ return __module_alloc(size, PAGE_KERNEL);
2782+#else
2783+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2784+#endif
2785+
2786+}
2787+
2788+#ifdef CONFIG_PAX_KERNEXEC
2789+void module_free_exec(struct module *mod, void *module_region)
2790+{
2791+ module_free(mod, module_region);
2792+}
2793+
2794+void *module_alloc_exec(unsigned long size)
2795+{
2796+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2797+}
2798+#endif
2799 #endif
2800
2801 int
2802diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2803index 07314af..c46655c 100644
2804--- a/arch/arm/kernel/patch.c
2805+++ b/arch/arm/kernel/patch.c
2806@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2807 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2808 int size;
2809
2810+ pax_open_kernel();
2811 if (thumb2 && __opcode_is_thumb16(insn)) {
2812 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2813 size = sizeof(u16);
2814@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2815 *(u32 *)addr = insn;
2816 size = sizeof(u32);
2817 }
2818+ pax_close_kernel();
2819
2820 flush_icache_range((uintptr_t)(addr),
2821 (uintptr_t)(addr) + size);
2822diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2823index 1f2740e..b36e225 100644
2824--- a/arch/arm/kernel/perf_event_cpu.c
2825+++ b/arch/arm/kernel/perf_event_cpu.c
2826@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2827 return NOTIFY_OK;
2828 }
2829
2830-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2831+static struct notifier_block cpu_pmu_hotplug_notifier = {
2832 .notifier_call = cpu_pmu_notify,
2833 };
2834
2835diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2836index 6e8931c..82ec6a5 100644
2837--- a/arch/arm/kernel/process.c
2838+++ b/arch/arm/kernel/process.c
2839@@ -28,7 +28,6 @@
2840 #include <linux/tick.h>
2841 #include <linux/utsname.h>
2842 #include <linux/uaccess.h>
2843-#include <linux/random.h>
2844 #include <linux/hw_breakpoint.h>
2845 #include <linux/cpuidle.h>
2846 #include <linux/leds.h>
2847@@ -223,6 +222,7 @@ void machine_power_off(void)
2848
2849 if (pm_power_off)
2850 pm_power_off();
2851+ BUG();
2852 }
2853
2854 /*
2855@@ -236,7 +236,7 @@ void machine_power_off(void)
2856 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2857 * to use. Implementing such co-ordination would be essentially impossible.
2858 */
2859-void machine_restart(char *cmd)
2860+__noreturn void machine_restart(char *cmd)
2861 {
2862 smp_send_stop();
2863
2864@@ -258,8 +258,8 @@ void __show_regs(struct pt_regs *regs)
2865
2866 show_regs_print_info(KERN_DEFAULT);
2867
2868- print_symbol("PC is at %s\n", instruction_pointer(regs));
2869- print_symbol("LR is at %s\n", regs->ARM_lr);
2870+ printk("PC is at %pA\n", instruction_pointer(regs));
2871+ printk("LR is at %pA\n", regs->ARM_lr);
2872 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2873 "sp : %08lx ip : %08lx fp : %08lx\n",
2874 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2875@@ -426,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2876 return 0;
2877 }
2878
2879-unsigned long arch_randomize_brk(struct mm_struct *mm)
2880-{
2881- unsigned long range_end = mm->brk + 0x02000000;
2882- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2883-}
2884-
2885 #ifdef CONFIG_MMU
2886 /*
2887 * The vectors page is always readable from user space for the
2888@@ -441,12 +435,12 @@ unsigned long arch_randomize_brk(struct mm_struct *mm)
2889 static struct vm_area_struct gate_vma = {
2890 .vm_start = 0xffff0000,
2891 .vm_end = 0xffff0000 + PAGE_SIZE,
2892- .vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC,
2893+ .vm_flags = VM_NONE,
2894 };
2895
2896 static int __init gate_vma_init(void)
2897 {
2898- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2899+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2900 return 0;
2901 }
2902 arch_initcall(gate_vma_init);
2903diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2904index 3653164..d83e55d 100644
2905--- a/arch/arm/kernel/psci.c
2906+++ b/arch/arm/kernel/psci.c
2907@@ -24,7 +24,7 @@
2908 #include <asm/opcodes-virt.h>
2909 #include <asm/psci.h>
2910
2911-struct psci_operations psci_ops;
2912+struct psci_operations psci_ops __read_only;
2913
2914 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2915
2916diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2917index 03deeff..741ce88 100644
2918--- a/arch/arm/kernel/ptrace.c
2919+++ b/arch/arm/kernel/ptrace.c
2920@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2921 return current_thread_info()->syscall;
2922 }
2923
2924+#ifdef CONFIG_GRKERNSEC_SETXID
2925+extern void gr_delayed_cred_worker(void);
2926+#endif
2927+
2928 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2929 {
2930 current_thread_info()->syscall = scno;
2931
2932+#ifdef CONFIG_GRKERNSEC_SETXID
2933+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2934+ gr_delayed_cred_worker();
2935+#endif
2936+
2937 /* Do the secure computing check first; failures should be fast. */
2938 if (secure_computing(scno) == -1)
2939 return -1;
2940diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2941index b4b1d39..efdc9be 100644
2942--- a/arch/arm/kernel/setup.c
2943+++ b/arch/arm/kernel/setup.c
2944@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2945 unsigned int elf_hwcap __read_mostly;
2946 EXPORT_SYMBOL(elf_hwcap);
2947
2948+pteval_t __supported_pte_mask __read_only;
2949+pmdval_t __supported_pmd_mask __read_only;
2950
2951 #ifdef MULTI_CPU
2952-struct processor processor __read_mostly;
2953+struct processor processor;
2954 #endif
2955 #ifdef MULTI_TLB
2956-struct cpu_tlb_fns cpu_tlb __read_mostly;
2957+struct cpu_tlb_fns cpu_tlb __read_only;
2958 #endif
2959 #ifdef MULTI_USER
2960-struct cpu_user_fns cpu_user __read_mostly;
2961+struct cpu_user_fns cpu_user __read_only;
2962 #endif
2963 #ifdef MULTI_CACHE
2964-struct cpu_cache_fns cpu_cache __read_mostly;
2965+struct cpu_cache_fns cpu_cache __read_only;
2966 #endif
2967 #ifdef CONFIG_OUTER_CACHE
2968-struct outer_cache_fns outer_cache __read_mostly;
2969+struct outer_cache_fns outer_cache __read_only;
2970 EXPORT_SYMBOL(outer_cache);
2971 #endif
2972
2973@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2974 asm("mrc p15, 0, %0, c0, c1, 4"
2975 : "=r" (mmfr0));
2976 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2977- (mmfr0 & 0x000000f0) >= 0x00000030)
2978+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2979 cpu_arch = CPU_ARCH_ARMv7;
2980- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2981+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2982+ __supported_pte_mask |= L_PTE_PXN;
2983+ __supported_pmd_mask |= PMD_PXNTABLE;
2984+ }
2985+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2986 (mmfr0 & 0x000000f0) == 0x00000020)
2987 cpu_arch = CPU_ARCH_ARMv6;
2988 else
2989@@ -479,7 +485,7 @@ static void __init setup_processor(void)
2990 __cpu_architecture = __get_cpu_architecture();
2991
2992 #ifdef MULTI_CPU
2993- processor = *list->proc;
2994+ memcpy((void *)&processor, list->proc, sizeof processor);
2995 #endif
2996 #ifdef MULTI_TLB
2997 cpu_tlb = *list->tlb;
2998diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
2999index 296786b..a8d4dd5 100644
3000--- a/arch/arm/kernel/signal.c
3001+++ b/arch/arm/kernel/signal.c
3002@@ -396,22 +396,14 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3003 __put_user(sigreturn_codes[idx+1], rc+1))
3004 return 1;
3005
3006- if (cpsr & MODE32_BIT) {
3007- /*
3008- * 32-bit code can use the new high-page
3009- * signal return code support.
3010- */
3011- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
3012- } else {
3013- /*
3014- * Ensure that the instruction cache sees
3015- * the return code written onto the stack.
3016- */
3017- flush_icache_range((unsigned long)rc,
3018- (unsigned long)(rc + 2));
3019+ /*
3020+ * Ensure that the instruction cache sees
3021+ * the return code written onto the stack.
3022+ */
3023+ flush_icache_range((unsigned long)rc,
3024+ (unsigned long)(rc + 2));
3025
3026- retcode = ((unsigned long)rc) + thumb;
3027- }
3028+ retcode = ((unsigned long)rc) + thumb;
3029 }
3030
3031 regs->ARM_r0 = map_sig(ksig->sig);
3032diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3033index 5919eb4..b5d6dfe 100644
3034--- a/arch/arm/kernel/smp.c
3035+++ b/arch/arm/kernel/smp.c
3036@@ -70,7 +70,7 @@ enum ipi_msg_type {
3037
3038 static DECLARE_COMPLETION(cpu_running);
3039
3040-static struct smp_operations smp_ops;
3041+static struct smp_operations smp_ops __read_only;
3042
3043 void __init smp_set_ops(struct smp_operations *ops)
3044 {
3045diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3046index 18b32e8..b0c8dca 100644
3047--- a/arch/arm/kernel/traps.c
3048+++ b/arch/arm/kernel/traps.c
3049@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3050 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3051 {
3052 #ifdef CONFIG_KALLSYMS
3053- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3054+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3055 #else
3056 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3057 #endif
3058@@ -259,6 +259,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3059 static int die_owner = -1;
3060 static unsigned int die_nest_count;
3061
3062+extern void gr_handle_kernel_exploit(void);
3063+
3064 static unsigned long oops_begin(void)
3065 {
3066 int cpu;
3067@@ -301,6 +303,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3068 panic("Fatal exception in interrupt");
3069 if (panic_on_oops)
3070 panic("Fatal exception");
3071+
3072+ gr_handle_kernel_exploit();
3073+
3074 if (signr)
3075 do_exit(signr);
3076 }
3077@@ -594,7 +599,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3078 * The user helper at 0xffff0fe0 must be used instead.
3079 * (see entry-armv.S for details)
3080 */
3081+ pax_open_kernel();
3082 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3083+ pax_close_kernel();
3084 }
3085 return 0;
3086
3087@@ -834,13 +841,10 @@ void __init early_trap_init(void *vectors_base)
3088 */
3089 kuser_get_tls_init(vectors);
3090
3091- /*
3092- * Copy signal return handlers into the vector page, and
3093- * set sigreturn to be a pointer to these.
3094- */
3095- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3096- sigreturn_codes, sizeof(sigreturn_codes));
3097-
3098 flush_icache_range(vectors, vectors + PAGE_SIZE);
3099- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3100+
3101+#ifndef CONFIG_PAX_MEMORY_UDEREF
3102+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3103+#endif
3104+
3105 }
3106diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3107index a871b8e..123b00a 100644
3108--- a/arch/arm/kernel/vmlinux.lds.S
3109+++ b/arch/arm/kernel/vmlinux.lds.S
3110@@ -8,7 +8,11 @@
3111 #include <asm/thread_info.h>
3112 #include <asm/memory.h>
3113 #include <asm/page.h>
3114-
3115+
3116+#ifdef CONFIG_PAX_KERNEXEC
3117+#include <asm/pgtable.h>
3118+#endif
3119+
3120 #define PROC_INFO \
3121 . = ALIGN(4); \
3122 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3123@@ -94,6 +98,11 @@ SECTIONS
3124 _text = .;
3125 HEAD_TEXT
3126 }
3127+
3128+#ifdef CONFIG_PAX_KERNEXEC
3129+ . = ALIGN(1<<SECTION_SHIFT);
3130+#endif
3131+
3132 .text : { /* Real text segment */
3133 _stext = .; /* Text and read-only data */
3134 __exception_text_start = .;
3135@@ -116,6 +125,8 @@ SECTIONS
3136 ARM_CPU_KEEP(PROC_INFO)
3137 }
3138
3139+ _etext = .; /* End of text section */
3140+
3141 RO_DATA(PAGE_SIZE)
3142
3143 . = ALIGN(4);
3144@@ -146,7 +157,9 @@ SECTIONS
3145
3146 NOTES
3147
3148- _etext = .; /* End of text and rodata section */
3149+#ifdef CONFIG_PAX_KERNEXEC
3150+ . = ALIGN(1<<SECTION_SHIFT);
3151+#endif
3152
3153 #ifndef CONFIG_XIP_KERNEL
3154 . = ALIGN(PAGE_SIZE);
3155@@ -207,6 +220,11 @@ SECTIONS
3156 . = PAGE_OFFSET + TEXT_OFFSET;
3157 #else
3158 __init_end = .;
3159+
3160+#ifdef CONFIG_PAX_KERNEXEC
3161+ . = ALIGN(1<<SECTION_SHIFT);
3162+#endif
3163+
3164 . = ALIGN(THREAD_SIZE);
3165 __data_loc = .;
3166 #endif
3167diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3168index 14a0d98..7771a7d 100644
3169--- a/arch/arm/lib/clear_user.S
3170+++ b/arch/arm/lib/clear_user.S
3171@@ -12,14 +12,14 @@
3172
3173 .text
3174
3175-/* Prototype: int __clear_user(void *addr, size_t sz)
3176+/* Prototype: int ___clear_user(void *addr, size_t sz)
3177 * Purpose : clear some user memory
3178 * Params : addr - user memory address to clear
3179 * : sz - number of bytes to clear
3180 * Returns : number of bytes NOT cleared
3181 */
3182 ENTRY(__clear_user_std)
3183-WEAK(__clear_user)
3184+WEAK(___clear_user)
3185 stmfd sp!, {r1, lr}
3186 mov r2, #0
3187 cmp r1, #4
3188@@ -44,7 +44,7 @@ WEAK(__clear_user)
3189 USER( strnebt r2, [r0])
3190 mov r0, #0
3191 ldmfd sp!, {r1, pc}
3192-ENDPROC(__clear_user)
3193+ENDPROC(___clear_user)
3194 ENDPROC(__clear_user_std)
3195
3196 .pushsection .fixup,"ax"
3197diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3198index 66a477a..bee61d3 100644
3199--- a/arch/arm/lib/copy_from_user.S
3200+++ b/arch/arm/lib/copy_from_user.S
3201@@ -16,7 +16,7 @@
3202 /*
3203 * Prototype:
3204 *
3205- * size_t __copy_from_user(void *to, const void *from, size_t n)
3206+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3207 *
3208 * Purpose:
3209 *
3210@@ -84,11 +84,11 @@
3211
3212 .text
3213
3214-ENTRY(__copy_from_user)
3215+ENTRY(___copy_from_user)
3216
3217 #include "copy_template.S"
3218
3219-ENDPROC(__copy_from_user)
3220+ENDPROC(___copy_from_user)
3221
3222 .pushsection .fixup,"ax"
3223 .align 0
3224diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3225index 6ee2f67..d1cce76 100644
3226--- a/arch/arm/lib/copy_page.S
3227+++ b/arch/arm/lib/copy_page.S
3228@@ -10,6 +10,7 @@
3229 * ASM optimised string functions
3230 */
3231 #include <linux/linkage.h>
3232+#include <linux/const.h>
3233 #include <asm/assembler.h>
3234 #include <asm/asm-offsets.h>
3235 #include <asm/cache.h>
3236diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3237index d066df6..df28194 100644
3238--- a/arch/arm/lib/copy_to_user.S
3239+++ b/arch/arm/lib/copy_to_user.S
3240@@ -16,7 +16,7 @@
3241 /*
3242 * Prototype:
3243 *
3244- * size_t __copy_to_user(void *to, const void *from, size_t n)
3245+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3246 *
3247 * Purpose:
3248 *
3249@@ -88,11 +88,11 @@
3250 .text
3251
3252 ENTRY(__copy_to_user_std)
3253-WEAK(__copy_to_user)
3254+WEAK(___copy_to_user)
3255
3256 #include "copy_template.S"
3257
3258-ENDPROC(__copy_to_user)
3259+ENDPROC(___copy_to_user)
3260 ENDPROC(__copy_to_user_std)
3261
3262 .pushsection .fixup,"ax"
3263diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3264index 7d08b43..f7ca7ea 100644
3265--- a/arch/arm/lib/csumpartialcopyuser.S
3266+++ b/arch/arm/lib/csumpartialcopyuser.S
3267@@ -57,8 +57,8 @@
3268 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3269 */
3270
3271-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3272-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3273+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3274+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3275
3276 #include "csumpartialcopygeneric.S"
3277
3278diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3279index 64dbfa5..84a3fd9 100644
3280--- a/arch/arm/lib/delay.c
3281+++ b/arch/arm/lib/delay.c
3282@@ -28,7 +28,7 @@
3283 /*
3284 * Default to the loop-based delay implementation.
3285 */
3286-struct arm_delay_ops arm_delay_ops = {
3287+struct arm_delay_ops arm_delay_ops __read_only = {
3288 .delay = __loop_delay,
3289 .const_udelay = __loop_const_udelay,
3290 .udelay = __loop_udelay,
3291diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3292index 025f742..8432b08 100644
3293--- a/arch/arm/lib/uaccess_with_memcpy.c
3294+++ b/arch/arm/lib/uaccess_with_memcpy.c
3295@@ -104,7 +104,7 @@ out:
3296 }
3297
3298 unsigned long
3299-__copy_to_user(void __user *to, const void *from, unsigned long n)
3300+___copy_to_user(void __user *to, const void *from, unsigned long n)
3301 {
3302 /*
3303 * This test is stubbed out of the main function above to keep
3304diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3305index f389228..592ef66 100644
3306--- a/arch/arm/mach-kirkwood/common.c
3307+++ b/arch/arm/mach-kirkwood/common.c
3308@@ -149,7 +149,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3309 clk_gate_ops.disable(hw);
3310 }
3311
3312-static struct clk_ops clk_gate_fn_ops;
3313+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3314+{
3315+ return clk_gate_ops.is_enabled(hw);
3316+}
3317+
3318+static struct clk_ops clk_gate_fn_ops = {
3319+ .enable = clk_gate_fn_enable,
3320+ .disable = clk_gate_fn_disable,
3321+ .is_enabled = clk_gate_fn_is_enabled,
3322+};
3323
3324 static struct clk __init *clk_register_gate_fn(struct device *dev,
3325 const char *name,
3326@@ -183,14 +192,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3327 gate_fn->fn_en = fn_en;
3328 gate_fn->fn_dis = fn_dis;
3329
3330- /* ops is the gate ops, but with our enable/disable functions */
3331- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3332- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3333- clk_gate_fn_ops = clk_gate_ops;
3334- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3335- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3336- }
3337-
3338 clk = clk_register(dev, &gate_fn->gate.hw);
3339
3340 if (IS_ERR(clk))
3341diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3342index f6eeb87..cc90868 100644
3343--- a/arch/arm/mach-omap2/board-n8x0.c
3344+++ b/arch/arm/mach-omap2/board-n8x0.c
3345@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3346 }
3347 #endif
3348
3349-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3350+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3351 .late_init = n8x0_menelaus_late_init,
3352 };
3353
3354diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3355index 6c4da12..d9ca72d 100644
3356--- a/arch/arm/mach-omap2/gpmc.c
3357+++ b/arch/arm/mach-omap2/gpmc.c
3358@@ -147,7 +147,6 @@ struct omap3_gpmc_regs {
3359 };
3360
3361 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3362-static struct irq_chip gpmc_irq_chip;
3363 static unsigned gpmc_irq_start;
3364
3365 static struct resource gpmc_mem_root;
3366@@ -711,6 +710,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3367
3368 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3369
3370+static struct irq_chip gpmc_irq_chip = {
3371+ .name = "gpmc",
3372+ .irq_startup = gpmc_irq_noop_ret,
3373+ .irq_enable = gpmc_irq_enable,
3374+ .irq_disable = gpmc_irq_disable,
3375+ .irq_shutdown = gpmc_irq_noop,
3376+ .irq_ack = gpmc_irq_noop,
3377+ .irq_mask = gpmc_irq_noop,
3378+ .irq_unmask = gpmc_irq_noop,
3379+
3380+};
3381+
3382 static int gpmc_setup_irq(void)
3383 {
3384 int i;
3385@@ -725,15 +736,6 @@ static int gpmc_setup_irq(void)
3386 return gpmc_irq_start;
3387 }
3388
3389- gpmc_irq_chip.name = "gpmc";
3390- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3391- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3392- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3393- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3394- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3395- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3396- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3397-
3398 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3399 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3400
3401diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3402index f8bb3b9..831e7b8 100644
3403--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3404+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3405@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3406 return NOTIFY_OK;
3407 }
3408
3409-static struct notifier_block __refdata irq_hotplug_notifier = {
3410+static struct notifier_block irq_hotplug_notifier = {
3411 .notifier_call = irq_cpu_hotplug_notify,
3412 };
3413
3414diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3415index e6d2307..d057195 100644
3416--- a/arch/arm/mach-omap2/omap_device.c
3417+++ b/arch/arm/mach-omap2/omap_device.c
3418@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3419 struct platform_device __init *omap_device_build(const char *pdev_name,
3420 int pdev_id,
3421 struct omap_hwmod *oh,
3422- void *pdata, int pdata_len)
3423+ const void *pdata, int pdata_len)
3424 {
3425 struct omap_hwmod *ohs[] = { oh };
3426
3427@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3428 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3429 int pdev_id,
3430 struct omap_hwmod **ohs,
3431- int oh_cnt, void *pdata,
3432+ int oh_cnt, const void *pdata,
3433 int pdata_len)
3434 {
3435 int ret = -ENOMEM;
3436diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3437index 044c31d..2ee0861 100644
3438--- a/arch/arm/mach-omap2/omap_device.h
3439+++ b/arch/arm/mach-omap2/omap_device.h
3440@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3441 /* Core code interface */
3442
3443 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3444- struct omap_hwmod *oh, void *pdata,
3445+ struct omap_hwmod *oh, const void *pdata,
3446 int pdata_len);
3447
3448 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3449 struct omap_hwmod **oh, int oh_cnt,
3450- void *pdata, int pdata_len);
3451+ const void *pdata, int pdata_len);
3452
3453 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3454 struct omap_hwmod **ohs, int oh_cnt);
3455diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3456index 7341eff..fd75e34 100644
3457--- a/arch/arm/mach-omap2/omap_hwmod.c
3458+++ b/arch/arm/mach-omap2/omap_hwmod.c
3459@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3460 int (*init_clkdm)(struct omap_hwmod *oh);
3461 void (*update_context_lost)(struct omap_hwmod *oh);
3462 int (*get_context_lost)(struct omap_hwmod *oh);
3463-};
3464+} __no_const;
3465
3466 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3467-static struct omap_hwmod_soc_ops soc_ops;
3468+static struct omap_hwmod_soc_ops soc_ops __read_only;
3469
3470 /* omap_hwmod_list contains all registered struct omap_hwmods */
3471 static LIST_HEAD(omap_hwmod_list);
3472diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3473index d15c7bb..b2d1f0c 100644
3474--- a/arch/arm/mach-omap2/wd_timer.c
3475+++ b/arch/arm/mach-omap2/wd_timer.c
3476@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3477 struct omap_hwmod *oh;
3478 char *oh_name = "wd_timer2";
3479 char *dev_name = "omap_wdt";
3480- struct omap_wd_timer_platform_data pdata;
3481+ static struct omap_wd_timer_platform_data pdata = {
3482+ .read_reset_sources = prm_read_reset_sources
3483+ };
3484
3485 if (!cpu_class_is_omap2() || of_have_populated_dt())
3486 return 0;
3487@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3488 return -EINVAL;
3489 }
3490
3491- pdata.read_reset_sources = prm_read_reset_sources;
3492-
3493 pdev = omap_device_build(dev_name, id, oh, &pdata,
3494 sizeof(struct omap_wd_timer_platform_data));
3495 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3496diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3497index 0cdba8d..297993e 100644
3498--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3499+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3500@@ -181,7 +181,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3501 bool entered_lp2 = false;
3502
3503 if (tegra_pending_sgi())
3504- ACCESS_ONCE(abort_flag) = true;
3505+ ACCESS_ONCE_RW(abort_flag) = true;
3506
3507 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3508
3509diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3510index cad3ca86..1d79e0f 100644
3511--- a/arch/arm/mach-ux500/setup.h
3512+++ b/arch/arm/mach-ux500/setup.h
3513@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3514 .type = MT_DEVICE, \
3515 }
3516
3517-#define __MEM_DEV_DESC(x, sz) { \
3518- .virtual = IO_ADDRESS(x), \
3519- .pfn = __phys_to_pfn(x), \
3520- .length = sz, \
3521- .type = MT_MEMORY, \
3522-}
3523-
3524 extern struct smp_operations ux500_smp_ops;
3525 extern void ux500_cpu_die(unsigned int cpu);
3526
3527diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3528index 35955b5..b475042 100644
3529--- a/arch/arm/mm/Kconfig
3530+++ b/arch/arm/mm/Kconfig
3531@@ -432,7 +432,7 @@ config CPU_32v5
3532
3533 config CPU_32v6
3534 bool
3535- select CPU_USE_DOMAINS if CPU_V6 && MMU
3536+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3537 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3538
3539 config CPU_32v6K
3540@@ -581,6 +581,7 @@ config CPU_CP15_MPU
3541
3542 config CPU_USE_DOMAINS
3543 bool
3544+ depends on !ARM_LPAE && !PAX_KERNEXEC
3545 help
3546 This option enables or disables the use of domain switching
3547 via the set_fs() function.
3548diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3549index 6f4585b..7b6f52b 100644
3550--- a/arch/arm/mm/alignment.c
3551+++ b/arch/arm/mm/alignment.c
3552@@ -211,10 +211,12 @@ union offset_union {
3553 #define __get16_unaligned_check(ins,val,addr) \
3554 do { \
3555 unsigned int err = 0, v, a = addr; \
3556+ pax_open_userland(); \
3557 __get8_unaligned_check(ins,v,a,err); \
3558 val = v << ((BE) ? 8 : 0); \
3559 __get8_unaligned_check(ins,v,a,err); \
3560 val |= v << ((BE) ? 0 : 8); \
3561+ pax_close_userland(); \
3562 if (err) \
3563 goto fault; \
3564 } while (0)
3565@@ -228,6 +230,7 @@ union offset_union {
3566 #define __get32_unaligned_check(ins,val,addr) \
3567 do { \
3568 unsigned int err = 0, v, a = addr; \
3569+ pax_open_userland(); \
3570 __get8_unaligned_check(ins,v,a,err); \
3571 val = v << ((BE) ? 24 : 0); \
3572 __get8_unaligned_check(ins,v,a,err); \
3573@@ -236,6 +239,7 @@ union offset_union {
3574 val |= v << ((BE) ? 8 : 16); \
3575 __get8_unaligned_check(ins,v,a,err); \
3576 val |= v << ((BE) ? 0 : 24); \
3577+ pax_close_userland(); \
3578 if (err) \
3579 goto fault; \
3580 } while (0)
3581@@ -249,6 +253,7 @@ union offset_union {
3582 #define __put16_unaligned_check(ins,val,addr) \
3583 do { \
3584 unsigned int err = 0, v = val, a = addr; \
3585+ pax_open_userland(); \
3586 __asm__( FIRST_BYTE_16 \
3587 ARM( "1: "ins" %1, [%2], #1\n" ) \
3588 THUMB( "1: "ins" %1, [%2]\n" ) \
3589@@ -268,6 +273,7 @@ union offset_union {
3590 " .popsection\n" \
3591 : "=r" (err), "=&r" (v), "=&r" (a) \
3592 : "0" (err), "1" (v), "2" (a)); \
3593+ pax_close_userland(); \
3594 if (err) \
3595 goto fault; \
3596 } while (0)
3597@@ -281,6 +287,7 @@ union offset_union {
3598 #define __put32_unaligned_check(ins,val,addr) \
3599 do { \
3600 unsigned int err = 0, v = val, a = addr; \
3601+ pax_open_userland(); \
3602 __asm__( FIRST_BYTE_32 \
3603 ARM( "1: "ins" %1, [%2], #1\n" ) \
3604 THUMB( "1: "ins" %1, [%2]\n" ) \
3605@@ -310,6 +317,7 @@ union offset_union {
3606 " .popsection\n" \
3607 : "=r" (err), "=&r" (v), "=&r" (a) \
3608 : "0" (err), "1" (v), "2" (a)); \
3609+ pax_close_userland(); \
3610 if (err) \
3611 goto fault; \
3612 } while (0)
3613diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3614index 5dbf13f..1a60561 100644
3615--- a/arch/arm/mm/fault.c
3616+++ b/arch/arm/mm/fault.c
3617@@ -25,6 +25,7 @@
3618 #include <asm/system_misc.h>
3619 #include <asm/system_info.h>
3620 #include <asm/tlbflush.h>
3621+#include <asm/sections.h>
3622
3623 #include "fault.h"
3624
3625@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3626 if (fixup_exception(regs))
3627 return;
3628
3629+#ifdef CONFIG_PAX_KERNEXEC
3630+ if ((fsr & FSR_WRITE) &&
3631+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3632+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3633+ {
3634+ if (current->signal->curr_ip)
3635+ 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),
3636+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3637+ else
3638+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3639+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3640+ }
3641+#endif
3642+
3643 /*
3644 * No handler, we'll have to terminate things with extreme prejudice.
3645 */
3646@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3647 }
3648 #endif
3649
3650+#ifdef CONFIG_PAX_PAGEEXEC
3651+ if (fsr & FSR_LNX_PF) {
3652+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3653+ do_group_exit(SIGKILL);
3654+ }
3655+#endif
3656+
3657 tsk->thread.address = addr;
3658 tsk->thread.error_code = fsr;
3659 tsk->thread.trap_no = 14;
3660@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3661 }
3662 #endif /* CONFIG_MMU */
3663
3664+#ifdef CONFIG_PAX_PAGEEXEC
3665+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3666+{
3667+ long i;
3668+
3669+ printk(KERN_ERR "PAX: bytes at PC: ");
3670+ for (i = 0; i < 20; i++) {
3671+ unsigned char c;
3672+ if (get_user(c, (__force unsigned char __user *)pc+i))
3673+ printk(KERN_CONT "?? ");
3674+ else
3675+ printk(KERN_CONT "%02x ", c);
3676+ }
3677+ printk("\n");
3678+
3679+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3680+ for (i = -1; i < 20; i++) {
3681+ unsigned long c;
3682+ if (get_user(c, (__force unsigned long __user *)sp+i))
3683+ printk(KERN_CONT "???????? ");
3684+ else
3685+ printk(KERN_CONT "%08lx ", c);
3686+ }
3687+ printk("\n");
3688+}
3689+#endif
3690+
3691 /*
3692 * First Level Translation Fault Handler
3693 *
3694@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3695 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3696 struct siginfo info;
3697
3698+#ifdef CONFIG_PAX_MEMORY_UDEREF
3699+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3700+ if (current->signal->curr_ip)
3701+ 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),
3702+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3703+ else
3704+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3705+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3706+ goto die;
3707+ }
3708+#endif
3709+
3710 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3711 return;
3712
3713+die:
3714 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3715 inf->name, fsr, addr);
3716
3717@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3718 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3719 struct siginfo info;
3720
3721+ if (user_mode(regs)) {
3722+ if (addr == 0xffff0fe0UL) {
3723+ /*
3724+ * PaX: __kuser_get_tls emulation
3725+ */
3726+ regs->ARM_r0 = current_thread_info()->tp_value;
3727+ regs->ARM_pc = regs->ARM_lr;
3728+ return;
3729+ }
3730+ }
3731+
3732+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3733+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3734+ if (current->signal->curr_ip)
3735+ 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),
3736+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3737+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3738+ else
3739+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3740+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3741+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3742+ goto die;
3743+ }
3744+#endif
3745+
3746+#ifdef CONFIG_PAX_REFCOUNT
3747+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3748+ unsigned int bkpt;
3749+
3750+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3751+ current->thread.error_code = ifsr;
3752+ current->thread.trap_no = 0;
3753+ pax_report_refcount_overflow(regs);
3754+ fixup_exception(regs);
3755+ return;
3756+ }
3757+ }
3758+#endif
3759+
3760 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3761 return;
3762
3763+die:
3764 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3765 inf->name, ifsr, addr);
3766
3767diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3768index cf08bdf..772656c 100644
3769--- a/arch/arm/mm/fault.h
3770+++ b/arch/arm/mm/fault.h
3771@@ -3,6 +3,7 @@
3772
3773 /*
3774 * Fault status register encodings. We steal bit 31 for our own purposes.
3775+ * Set when the FSR value is from an instruction fault.
3776 */
3777 #define FSR_LNX_PF (1 << 31)
3778 #define FSR_WRITE (1 << 11)
3779@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3780 }
3781 #endif
3782
3783+/* valid for LPAE and !LPAE */
3784+static inline int is_xn_fault(unsigned int fsr)
3785+{
3786+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3787+}
3788+
3789+static inline int is_domain_fault(unsigned int fsr)
3790+{
3791+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3792+}
3793+
3794 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3795 unsigned long search_exception_table(unsigned long addr);
3796
3797diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3798index 9a5cdc0..a1182cf 100644
3799--- a/arch/arm/mm/init.c
3800+++ b/arch/arm/mm/init.c
3801@@ -30,6 +30,8 @@
3802 #include <asm/setup.h>
3803 #include <asm/tlb.h>
3804 #include <asm/fixmap.h>
3805+#include <asm/system_info.h>
3806+#include <asm/cp15.h>
3807
3808 #include <asm/mach/arch.h>
3809 #include <asm/mach/map.h>
3810@@ -726,7 +728,46 @@ void free_initmem(void)
3811 {
3812 #ifdef CONFIG_HAVE_TCM
3813 extern char __tcm_start, __tcm_end;
3814+#endif
3815
3816+#ifdef CONFIG_PAX_KERNEXEC
3817+ unsigned long addr;
3818+ pgd_t *pgd;
3819+ pud_t *pud;
3820+ pmd_t *pmd;
3821+ int cpu_arch = cpu_architecture();
3822+ unsigned int cr = get_cr();
3823+
3824+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3825+ /* make pages tables, etc before .text NX */
3826+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3827+ pgd = pgd_offset_k(addr);
3828+ pud = pud_offset(pgd, addr);
3829+ pmd = pmd_offset(pud, addr);
3830+ __section_update(pmd, addr, PMD_SECT_XN);
3831+ }
3832+ /* make init NX */
3833+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3834+ pgd = pgd_offset_k(addr);
3835+ pud = pud_offset(pgd, addr);
3836+ pmd = pmd_offset(pud, addr);
3837+ __section_update(pmd, addr, PMD_SECT_XN);
3838+ }
3839+ /* make kernel code/rodata RX */
3840+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3841+ pgd = pgd_offset_k(addr);
3842+ pud = pud_offset(pgd, addr);
3843+ pmd = pmd_offset(pud, addr);
3844+#ifdef CONFIG_ARM_LPAE
3845+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3846+#else
3847+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3848+#endif
3849+ }
3850+ }
3851+#endif
3852+
3853+#ifdef CONFIG_HAVE_TCM
3854 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3855 free_reserved_area(&__tcm_start, &__tcm_end, 0, "TCM link");
3856 #endif
3857diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3858index 04d9006..c547d85 100644
3859--- a/arch/arm/mm/ioremap.c
3860+++ b/arch/arm/mm/ioremap.c
3861@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3862 unsigned int mtype;
3863
3864 if (cached)
3865- mtype = MT_MEMORY;
3866+ mtype = MT_MEMORY_RX;
3867 else
3868- mtype = MT_MEMORY_NONCACHED;
3869+ mtype = MT_MEMORY_NONCACHED_RX;
3870
3871 return __arm_ioremap_caller(phys_addr, size, mtype,
3872 __builtin_return_address(0));
3873diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3874index 10062ce..8695745 100644
3875--- a/arch/arm/mm/mmap.c
3876+++ b/arch/arm/mm/mmap.c
3877@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3878 struct vm_area_struct *vma;
3879 int do_align = 0;
3880 int aliasing = cache_is_vipt_aliasing();
3881+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3882 struct vm_unmapped_area_info info;
3883
3884 /*
3885@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3886 if (len > TASK_SIZE)
3887 return -ENOMEM;
3888
3889+#ifdef CONFIG_PAX_RANDMMAP
3890+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3891+#endif
3892+
3893 if (addr) {
3894 if (do_align)
3895 addr = COLOUR_ALIGN(addr, pgoff);
3896@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3897 addr = PAGE_ALIGN(addr);
3898
3899 vma = find_vma(mm, addr);
3900- if (TASK_SIZE - len >= addr &&
3901- (!vma || addr + len <= vma->vm_start))
3902+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3903 return addr;
3904 }
3905
3906@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3907 info.high_limit = TASK_SIZE;
3908 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3909 info.align_offset = pgoff << PAGE_SHIFT;
3910+ info.threadstack_offset = offset;
3911 return vm_unmapped_area(&info);
3912 }
3913
3914@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3915 unsigned long addr = addr0;
3916 int do_align = 0;
3917 int aliasing = cache_is_vipt_aliasing();
3918+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3919 struct vm_unmapped_area_info info;
3920
3921 /*
3922@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3923 return addr;
3924 }
3925
3926+#ifdef CONFIG_PAX_RANDMMAP
3927+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3928+#endif
3929+
3930 /* requesting a specific address */
3931 if (addr) {
3932 if (do_align)
3933@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3934 else
3935 addr = PAGE_ALIGN(addr);
3936 vma = find_vma(mm, addr);
3937- if (TASK_SIZE - len >= addr &&
3938- (!vma || addr + len <= vma->vm_start))
3939+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3940 return addr;
3941 }
3942
3943@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3944 info.high_limit = mm->mmap_base;
3945 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3946 info.align_offset = pgoff << PAGE_SHIFT;
3947+ info.threadstack_offset = offset;
3948 addr = vm_unmapped_area(&info);
3949
3950 /*
3951@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3952 {
3953 unsigned long random_factor = 0UL;
3954
3955+#ifdef CONFIG_PAX_RANDMMAP
3956+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3957+#endif
3958+
3959 /* 8 bits of randomness in 20 address space bits */
3960 if ((current->flags & PF_RANDOMIZE) &&
3961 !(current->personality & ADDR_NO_RANDOMIZE))
3962@@ -180,10 +194,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3963
3964 if (mmap_is_legacy()) {
3965 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3966+
3967+#ifdef CONFIG_PAX_RANDMMAP
3968+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3969+ mm->mmap_base += mm->delta_mmap;
3970+#endif
3971+
3972 mm->get_unmapped_area = arch_get_unmapped_area;
3973 mm->unmap_area = arch_unmap_area;
3974 } else {
3975 mm->mmap_base = mmap_base(random_factor);
3976+
3977+#ifdef CONFIG_PAX_RANDMMAP
3978+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3979+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3980+#endif
3981+
3982 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3983 mm->unmap_area = arch_unmap_area_topdown;
3984 }
3985diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3986index 4d409e6..f375351 100644
3987--- a/arch/arm/mm/mmu.c
3988+++ b/arch/arm/mm/mmu.c
3989@@ -36,6 +36,22 @@
3990 #include "mm.h"
3991 #include "tcm.h"
3992
3993+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3994+void modify_domain(unsigned int dom, unsigned int type)
3995+{
3996+ struct thread_info *thread = current_thread_info();
3997+ unsigned int domain = thread->cpu_domain;
3998+ /*
3999+ * DOMAIN_MANAGER might be defined to some other value,
4000+ * use the arch-defined constant
4001+ */
4002+ domain &= ~domain_val(dom, 3);
4003+ thread->cpu_domain = domain | domain_val(dom, type);
4004+ set_domain(thread->cpu_domain);
4005+}
4006+EXPORT_SYMBOL(modify_domain);
4007+#endif
4008+
4009 /*
4010 * empty_zero_page is a special page that is used for
4011 * zero-initialized data and COW.
4012@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4013
4014 #endif /* ifdef CONFIG_CPU_CP15 / else */
4015
4016-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4017+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4018 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4019
4020-static struct mem_type mem_types[] = {
4021+#ifdef CONFIG_PAX_KERNEXEC
4022+#define L_PTE_KERNEXEC L_PTE_RDONLY
4023+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4024+#else
4025+#define L_PTE_KERNEXEC L_PTE_DIRTY
4026+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4027+#endif
4028+
4029+static struct mem_type mem_types[] __read_only = {
4030 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4031 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4032 L_PTE_SHARED,
4033@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4034 [MT_UNCACHED] = {
4035 .prot_pte = PROT_PTE_DEVICE,
4036 .prot_l1 = PMD_TYPE_TABLE,
4037- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4038+ .prot_sect = PROT_SECT_DEVICE,
4039 .domain = DOMAIN_IO,
4040 },
4041 [MT_CACHECLEAN] = {
4042- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4043+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4044 .domain = DOMAIN_KERNEL,
4045 },
4046 #ifndef CONFIG_ARM_LPAE
4047 [MT_MINICLEAN] = {
4048- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4049+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4050 .domain = DOMAIN_KERNEL,
4051 },
4052 #endif
4053@@ -277,36 +301,65 @@ static struct mem_type mem_types[] = {
4054 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4055 L_PTE_RDONLY,
4056 .prot_l1 = PMD_TYPE_TABLE,
4057- .domain = DOMAIN_USER,
4058+ .domain = DOMAIN_VECTORS,
4059 },
4060 [MT_HIGH_VECTORS] = {
4061- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4062- L_PTE_USER | L_PTE_RDONLY,
4063+ /* we always want the vector page to be noaccess for userland on archs with
4064+ XN where we can enforce some reasonable measure of security
4065+ therefore, when kernexec is disabled, instead of L_PTE_USER | L_PTE_RDONLY
4066+ which turns into supervisor rwx, userland rx, we instead omit that entirely,
4067+ leaving it as supervisor rwx only
4068+ */
4069+#ifdef CONFIG_PAX_KERNEXEC
4070+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_RDONLY,
4071+#elif __LINUX_ARM_ARCH__ >= 6
4072+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4073+#else
4074+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_USER | L_PTE_RDONLY,
4075+#endif
4076 .prot_l1 = PMD_TYPE_TABLE,
4077- .domain = DOMAIN_USER,
4078+ .domain = DOMAIN_VECTORS,
4079 },
4080- [MT_MEMORY] = {
4081+ [MT_MEMORY_RWX] = {
4082 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4083 .prot_l1 = PMD_TYPE_TABLE,
4084 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4085 .domain = DOMAIN_KERNEL,
4086 },
4087+ [MT_MEMORY_RW] = {
4088+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4089+ .prot_l1 = PMD_TYPE_TABLE,
4090+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4091+ .domain = DOMAIN_KERNEL,
4092+ },
4093+ [MT_MEMORY_RX] = {
4094+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4095+ .prot_l1 = PMD_TYPE_TABLE,
4096+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4097+ .domain = DOMAIN_KERNEL,
4098+ },
4099 [MT_ROM] = {
4100- .prot_sect = PMD_TYPE_SECT,
4101+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4102 .domain = DOMAIN_KERNEL,
4103 },
4104- [MT_MEMORY_NONCACHED] = {
4105+ [MT_MEMORY_NONCACHED_RW] = {
4106 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4107 L_PTE_MT_BUFFERABLE,
4108 .prot_l1 = PMD_TYPE_TABLE,
4109 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4110 .domain = DOMAIN_KERNEL,
4111 },
4112+ [MT_MEMORY_NONCACHED_RX] = {
4113+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4114+ L_PTE_MT_BUFFERABLE,
4115+ .prot_l1 = PMD_TYPE_TABLE,
4116+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4117+ .domain = DOMAIN_KERNEL,
4118+ },
4119 [MT_MEMORY_DTCM] = {
4120- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4121- L_PTE_XN,
4122+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4123 .prot_l1 = PMD_TYPE_TABLE,
4124- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4125+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4126 .domain = DOMAIN_KERNEL,
4127 },
4128 [MT_MEMORY_ITCM] = {
4129@@ -316,10 +369,10 @@ static struct mem_type mem_types[] = {
4130 },
4131 [MT_MEMORY_SO] = {
4132 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4133- L_PTE_MT_UNCACHED | L_PTE_XN,
4134+ L_PTE_MT_UNCACHED,
4135 .prot_l1 = PMD_TYPE_TABLE,
4136 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4137- PMD_SECT_UNCACHED | PMD_SECT_XN,
4138+ PMD_SECT_UNCACHED,
4139 .domain = DOMAIN_KERNEL,
4140 },
4141 [MT_MEMORY_DMA_READY] = {
4142@@ -405,9 +458,35 @@ static void __init build_mem_type_table(void)
4143 * to prevent speculative instruction fetches.
4144 */
4145 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4146+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4147 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4148+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4149 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4150+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4151 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4152+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4153+
4154+ /* Mark other regions on ARMv6+ as execute-never */
4155+
4156+#ifdef CONFIG_PAX_KERNEXEC
4157+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4158+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4159+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4160+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4161+#ifndef CONFIG_ARM_LPAE
4162+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4163+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4164+#endif
4165+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4166+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4167+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4168+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4169+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4170+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4171+#endif
4172+
4173+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4174+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4175 }
4176 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4177 /*
4178@@ -468,6 +547,9 @@ static void __init build_mem_type_table(void)
4179 * from SVC mode and no access from userspace.
4180 */
4181 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4182+#ifdef CONFIG_PAX_KERNEXEC
4183+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4184+#endif
4185 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4186 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4187 #endif
4188@@ -485,11 +567,17 @@ static void __init build_mem_type_table(void)
4189 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4190 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4191 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4192- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4193- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4194+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4195+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4196+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4197+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4198+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4199+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4200 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4201- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4202- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4203+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4204+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4205+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4206+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4207 }
4208 }
4209
4210@@ -500,15 +588,20 @@ static void __init build_mem_type_table(void)
4211 if (cpu_arch >= CPU_ARCH_ARMv6) {
4212 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4213 /* Non-cacheable Normal is XCB = 001 */
4214- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4215+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4216+ PMD_SECT_BUFFERED;
4217+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4218 PMD_SECT_BUFFERED;
4219 } else {
4220 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4221- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4222+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4223+ PMD_SECT_TEX(1);
4224+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4225 PMD_SECT_TEX(1);
4226 }
4227 } else {
4228- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4229+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4230+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4231 }
4232
4233 #ifdef CONFIG_ARM_LPAE
4234@@ -524,6 +617,8 @@ static void __init build_mem_type_table(void)
4235 vecs_pgprot |= PTE_EXT_AF;
4236 #endif
4237
4238+ user_pgprot |= __supported_pte_mask;
4239+
4240 for (i = 0; i < 16; i++) {
4241 pteval_t v = pgprot_val(protection_map[i]);
4242 protection_map[i] = __pgprot(v | user_pgprot);
4243@@ -541,10 +636,15 @@ static void __init build_mem_type_table(void)
4244
4245 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4246 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4247- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4248- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4249+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4250+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4251+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4252+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4253+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4254+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4255 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4256- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4257+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4258+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4259 mem_types[MT_ROM].prot_sect |= cp->pmd;
4260
4261 switch (cp->pmd) {
4262@@ -1166,18 +1266,15 @@ void __init arm_mm_memblock_reserve(void)
4263 * called function. This means you can't use any function or debugging
4264 * method which may touch any device, otherwise the kernel _will_ crash.
4265 */
4266+
4267+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4268+
4269 static void __init devicemaps_init(struct machine_desc *mdesc)
4270 {
4271 struct map_desc map;
4272 unsigned long addr;
4273- void *vectors;
4274
4275- /*
4276- * Allocate the vector page early.
4277- */
4278- vectors = early_alloc(PAGE_SIZE);
4279-
4280- early_trap_init(vectors);
4281+ early_trap_init(&vectors);
4282
4283 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4284 pmd_clear(pmd_off_k(addr));
4285@@ -1217,7 +1314,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4286 * location (0xffff0000). If we aren't using high-vectors, also
4287 * create a mapping at the low-vectors virtual address.
4288 */
4289- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4290+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4291 map.virtual = 0xffff0000;
4292 map.length = PAGE_SIZE;
4293 map.type = MT_HIGH_VECTORS;
4294@@ -1275,8 +1372,39 @@ static void __init map_lowmem(void)
4295 map.pfn = __phys_to_pfn(start);
4296 map.virtual = __phys_to_virt(start);
4297 map.length = end - start;
4298- map.type = MT_MEMORY;
4299
4300+#ifdef CONFIG_PAX_KERNEXEC
4301+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4302+ struct map_desc kernel;
4303+ struct map_desc initmap;
4304+
4305+ /* when freeing initmem we will make this RW */
4306+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4307+ initmap.virtual = (unsigned long)__init_begin;
4308+ initmap.length = _sdata - __init_begin;
4309+ initmap.type = MT_MEMORY_RWX;
4310+ create_mapping(&initmap);
4311+
4312+ /* when freeing initmem we will make this RX */
4313+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4314+ kernel.virtual = (unsigned long)_stext;
4315+ kernel.length = __init_begin - _stext;
4316+ kernel.type = MT_MEMORY_RWX;
4317+ create_mapping(&kernel);
4318+
4319+ if (map.virtual < (unsigned long)_stext) {
4320+ map.length = (unsigned long)_stext - map.virtual;
4321+ map.type = MT_MEMORY_RWX;
4322+ create_mapping(&map);
4323+ }
4324+
4325+ map.pfn = __phys_to_pfn(__pa(_sdata));
4326+ map.virtual = (unsigned long)_sdata;
4327+ map.length = end - __pa(_sdata);
4328+ }
4329+#endif
4330+
4331+ map.type = MT_MEMORY_RW;
4332 create_mapping(&map);
4333 }
4334 }
4335diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4336index 9704097..3e36dde 100644
4337--- a/arch/arm/mm/proc-v7-2level.S
4338+++ b/arch/arm/mm/proc-v7-2level.S
4339@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4340 tst r1, #L_PTE_XN
4341 orrne r3, r3, #PTE_EXT_XN
4342
4343+ tst r1, #L_PTE_PXN
4344+ orrne r3, r3, #PTE_EXT_PXN
4345+
4346 tst r1, #L_PTE_YOUNG
4347 tstne r1, #L_PTE_VALID
4348 #ifndef CONFIG_CPU_USE_DOMAINS
4349diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4350index a5bc92d..0bb4730 100644
4351--- a/arch/arm/plat-omap/sram.c
4352+++ b/arch/arm/plat-omap/sram.c
4353@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4354 * Looks like we need to preserve some bootloader code at the
4355 * beginning of SRAM for jumping to flash for reboot to work...
4356 */
4357+ pax_open_kernel();
4358 memset_io(omap_sram_base + omap_sram_skip, 0,
4359 omap_sram_size - omap_sram_skip);
4360+ pax_close_kernel();
4361 }
4362diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4363index ce6d763..cfea917 100644
4364--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4365+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4366@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4367 int (*started)(unsigned ch);
4368 int (*flush)(unsigned ch);
4369 int (*stop)(unsigned ch);
4370-};
4371+} __no_const;
4372
4373 extern void *samsung_dmadev_get_ops(void);
4374 extern void *s3c_dma_get_ops(void);
4375diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4376index f4726dc..39ed646 100644
4377--- a/arch/arm64/kernel/debug-monitors.c
4378+++ b/arch/arm64/kernel/debug-monitors.c
4379@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4380 return NOTIFY_OK;
4381 }
4382
4383-static struct notifier_block __cpuinitdata os_lock_nb = {
4384+static struct notifier_block os_lock_nb = {
4385 .notifier_call = os_lock_notify,
4386 };
4387
4388diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4389index 5ab825c..96aaec8 100644
4390--- a/arch/arm64/kernel/hw_breakpoint.c
4391+++ b/arch/arm64/kernel/hw_breakpoint.c
4392@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4393 return NOTIFY_OK;
4394 }
4395
4396-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4397+static struct notifier_block hw_breakpoint_reset_nb = {
4398 .notifier_call = hw_breakpoint_reset_notify,
4399 };
4400
4401diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4402index c3a58a1..78fbf54 100644
4403--- a/arch/avr32/include/asm/cache.h
4404+++ b/arch/avr32/include/asm/cache.h
4405@@ -1,8 +1,10 @@
4406 #ifndef __ASM_AVR32_CACHE_H
4407 #define __ASM_AVR32_CACHE_H
4408
4409+#include <linux/const.h>
4410+
4411 #define L1_CACHE_SHIFT 5
4412-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4413+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4414
4415 /*
4416 * Memory returned by kmalloc() may be used for DMA, so we must make
4417diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4418index d232888..87c8df1 100644
4419--- a/arch/avr32/include/asm/elf.h
4420+++ b/arch/avr32/include/asm/elf.h
4421@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4422 the loader. We need to make sure that it is out of the way of the program
4423 that it will "exec", and that there is sufficient room for the brk. */
4424
4425-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4426+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4427
4428+#ifdef CONFIG_PAX_ASLR
4429+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4430+
4431+#define PAX_DELTA_MMAP_LEN 15
4432+#define PAX_DELTA_STACK_LEN 15
4433+#endif
4434
4435 /* This yields a mask that user programs can use to figure out what
4436 instruction set this CPU supports. This could be done in user space,
4437diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4438index 479330b..53717a8 100644
4439--- a/arch/avr32/include/asm/kmap_types.h
4440+++ b/arch/avr32/include/asm/kmap_types.h
4441@@ -2,9 +2,9 @@
4442 #define __ASM_AVR32_KMAP_TYPES_H
4443
4444 #ifdef CONFIG_DEBUG_HIGHMEM
4445-# define KM_TYPE_NR 29
4446+# define KM_TYPE_NR 30
4447 #else
4448-# define KM_TYPE_NR 14
4449+# define KM_TYPE_NR 15
4450 #endif
4451
4452 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4453diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4454index b2f2d2d..d1c85cb 100644
4455--- a/arch/avr32/mm/fault.c
4456+++ b/arch/avr32/mm/fault.c
4457@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4458
4459 int exception_trace = 1;
4460
4461+#ifdef CONFIG_PAX_PAGEEXEC
4462+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4463+{
4464+ unsigned long i;
4465+
4466+ printk(KERN_ERR "PAX: bytes at PC: ");
4467+ for (i = 0; i < 20; i++) {
4468+ unsigned char c;
4469+ if (get_user(c, (unsigned char *)pc+i))
4470+ printk(KERN_CONT "???????? ");
4471+ else
4472+ printk(KERN_CONT "%02x ", c);
4473+ }
4474+ printk("\n");
4475+}
4476+#endif
4477+
4478 /*
4479 * This routine handles page faults. It determines the address and the
4480 * problem, and then passes it off to one of the appropriate routines.
4481@@ -174,6 +191,16 @@ bad_area:
4482 up_read(&mm->mmap_sem);
4483
4484 if (user_mode(regs)) {
4485+
4486+#ifdef CONFIG_PAX_PAGEEXEC
4487+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4488+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4489+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4490+ do_group_exit(SIGKILL);
4491+ }
4492+ }
4493+#endif
4494+
4495 if (exception_trace && printk_ratelimit())
4496 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4497 "sp %08lx ecr %lu\n",
4498diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4499index 568885a..f8008df 100644
4500--- a/arch/blackfin/include/asm/cache.h
4501+++ b/arch/blackfin/include/asm/cache.h
4502@@ -7,6 +7,7 @@
4503 #ifndef __ARCH_BLACKFIN_CACHE_H
4504 #define __ARCH_BLACKFIN_CACHE_H
4505
4506+#include <linux/const.h>
4507 #include <linux/linkage.h> /* for asmlinkage */
4508
4509 /*
4510@@ -14,7 +15,7 @@
4511 * Blackfin loads 32 bytes for cache
4512 */
4513 #define L1_CACHE_SHIFT 5
4514-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4515+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4516 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4517
4518 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4519diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4520index aea2718..3639a60 100644
4521--- a/arch/cris/include/arch-v10/arch/cache.h
4522+++ b/arch/cris/include/arch-v10/arch/cache.h
4523@@ -1,8 +1,9 @@
4524 #ifndef _ASM_ARCH_CACHE_H
4525 #define _ASM_ARCH_CACHE_H
4526
4527+#include <linux/const.h>
4528 /* Etrax 100LX have 32-byte cache-lines. */
4529-#define L1_CACHE_BYTES 32
4530 #define L1_CACHE_SHIFT 5
4531+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4532
4533 #endif /* _ASM_ARCH_CACHE_H */
4534diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4535index 7caf25d..ee65ac5 100644
4536--- a/arch/cris/include/arch-v32/arch/cache.h
4537+++ b/arch/cris/include/arch-v32/arch/cache.h
4538@@ -1,11 +1,12 @@
4539 #ifndef _ASM_CRIS_ARCH_CACHE_H
4540 #define _ASM_CRIS_ARCH_CACHE_H
4541
4542+#include <linux/const.h>
4543 #include <arch/hwregs/dma.h>
4544
4545 /* A cache-line is 32 bytes. */
4546-#define L1_CACHE_BYTES 32
4547 #define L1_CACHE_SHIFT 5
4548+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4549
4550 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4551
4552diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4553index b86329d..6709906 100644
4554--- a/arch/frv/include/asm/atomic.h
4555+++ b/arch/frv/include/asm/atomic.h
4556@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4557 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4558 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4559
4560+#define atomic64_read_unchecked(v) atomic64_read(v)
4561+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4562+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4563+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4564+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4565+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4566+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4567+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4568+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4569+
4570 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4571 {
4572 int c, old;
4573diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4574index 2797163..c2a401d 100644
4575--- a/arch/frv/include/asm/cache.h
4576+++ b/arch/frv/include/asm/cache.h
4577@@ -12,10 +12,11 @@
4578 #ifndef __ASM_CACHE_H
4579 #define __ASM_CACHE_H
4580
4581+#include <linux/const.h>
4582
4583 /* bytes per L1 cache line */
4584 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4585-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4586+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4587
4588 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4589 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4590diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4591index 43901f2..0d8b865 100644
4592--- a/arch/frv/include/asm/kmap_types.h
4593+++ b/arch/frv/include/asm/kmap_types.h
4594@@ -2,6 +2,6 @@
4595 #ifndef _ASM_KMAP_TYPES_H
4596 #define _ASM_KMAP_TYPES_H
4597
4598-#define KM_TYPE_NR 17
4599+#define KM_TYPE_NR 18
4600
4601 #endif
4602diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4603index 836f147..4cf23f5 100644
4604--- a/arch/frv/mm/elf-fdpic.c
4605+++ b/arch/frv/mm/elf-fdpic.c
4606@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4607 {
4608 struct vm_area_struct *vma;
4609 struct vm_unmapped_area_info info;
4610+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4611
4612 if (len > TASK_SIZE)
4613 return -ENOMEM;
4614@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4615 if (addr) {
4616 addr = PAGE_ALIGN(addr);
4617 vma = find_vma(current->mm, addr);
4618- if (TASK_SIZE - len >= addr &&
4619- (!vma || addr + len <= vma->vm_start))
4620+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4621 goto success;
4622 }
4623
4624@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4625 info.high_limit = (current->mm->start_stack - 0x00200000);
4626 info.align_mask = 0;
4627 info.align_offset = 0;
4628+ info.threadstack_offset = offset;
4629 addr = vm_unmapped_area(&info);
4630 if (!(addr & ~PAGE_MASK))
4631 goto success;
4632diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4633index f4ca594..adc72fd6 100644
4634--- a/arch/hexagon/include/asm/cache.h
4635+++ b/arch/hexagon/include/asm/cache.h
4636@@ -21,9 +21,11 @@
4637 #ifndef __ASM_CACHE_H
4638 #define __ASM_CACHE_H
4639
4640+#include <linux/const.h>
4641+
4642 /* Bytes per L1 cache line */
4643-#define L1_CACHE_SHIFT (5)
4644-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4645+#define L1_CACHE_SHIFT 5
4646+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4647
4648 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4649 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4650diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4651index 6e6fe18..a6ae668 100644
4652--- a/arch/ia64/include/asm/atomic.h
4653+++ b/arch/ia64/include/asm/atomic.h
4654@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4655 #define atomic64_inc(v) atomic64_add(1, (v))
4656 #define atomic64_dec(v) atomic64_sub(1, (v))
4657
4658+#define atomic64_read_unchecked(v) atomic64_read(v)
4659+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4660+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4661+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4662+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4663+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4664+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4665+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4666+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4667+
4668 /* Atomic operations are already serializing */
4669 #define smp_mb__before_atomic_dec() barrier()
4670 #define smp_mb__after_atomic_dec() barrier()
4671diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4672index 988254a..e1ee885 100644
4673--- a/arch/ia64/include/asm/cache.h
4674+++ b/arch/ia64/include/asm/cache.h
4675@@ -1,6 +1,7 @@
4676 #ifndef _ASM_IA64_CACHE_H
4677 #define _ASM_IA64_CACHE_H
4678
4679+#include <linux/const.h>
4680
4681 /*
4682 * Copyright (C) 1998-2000 Hewlett-Packard Co
4683@@ -9,7 +10,7 @@
4684
4685 /* Bytes per L1 (data) cache line. */
4686 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4687-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4688+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4689
4690 #ifdef CONFIG_SMP
4691 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4692diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4693index 5a83c5c..4d7f553 100644
4694--- a/arch/ia64/include/asm/elf.h
4695+++ b/arch/ia64/include/asm/elf.h
4696@@ -42,6 +42,13 @@
4697 */
4698 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4699
4700+#ifdef CONFIG_PAX_ASLR
4701+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4702+
4703+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4704+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4705+#endif
4706+
4707 #define PT_IA_64_UNWIND 0x70000001
4708
4709 /* IA-64 relocations: */
4710diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4711index 96a8d92..617a1cf 100644
4712--- a/arch/ia64/include/asm/pgalloc.h
4713+++ b/arch/ia64/include/asm/pgalloc.h
4714@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4715 pgd_val(*pgd_entry) = __pa(pud);
4716 }
4717
4718+static inline void
4719+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4720+{
4721+ pgd_populate(mm, pgd_entry, pud);
4722+}
4723+
4724 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4725 {
4726 return quicklist_alloc(0, GFP_KERNEL, NULL);
4727@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4728 pud_val(*pud_entry) = __pa(pmd);
4729 }
4730
4731+static inline void
4732+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4733+{
4734+ pud_populate(mm, pud_entry, pmd);
4735+}
4736+
4737 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4738 {
4739 return quicklist_alloc(0, GFP_KERNEL, NULL);
4740diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4741index 815810c..d60bd4c 100644
4742--- a/arch/ia64/include/asm/pgtable.h
4743+++ b/arch/ia64/include/asm/pgtable.h
4744@@ -12,7 +12,7 @@
4745 * David Mosberger-Tang <davidm@hpl.hp.com>
4746 */
4747
4748-
4749+#include <linux/const.h>
4750 #include <asm/mman.h>
4751 #include <asm/page.h>
4752 #include <asm/processor.h>
4753@@ -142,6 +142,17 @@
4754 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4755 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4756 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4757+
4758+#ifdef CONFIG_PAX_PAGEEXEC
4759+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4760+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4761+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4762+#else
4763+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4764+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4765+# define PAGE_COPY_NOEXEC PAGE_COPY
4766+#endif
4767+
4768 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4769 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4770 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4771diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4772index 54ff557..70c88b7 100644
4773--- a/arch/ia64/include/asm/spinlock.h
4774+++ b/arch/ia64/include/asm/spinlock.h
4775@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4776 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4777
4778 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4779- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4780+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4781 }
4782
4783 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4784diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4785index 449c8c0..18965fb 100644
4786--- a/arch/ia64/include/asm/uaccess.h
4787+++ b/arch/ia64/include/asm/uaccess.h
4788@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4789 static inline unsigned long
4790 __copy_to_user (void __user *to, const void *from, unsigned long count)
4791 {
4792+ if (count > INT_MAX)
4793+ return count;
4794+
4795+ if (!__builtin_constant_p(count))
4796+ check_object_size(from, count, true);
4797+
4798 return __copy_user(to, (__force void __user *) from, count);
4799 }
4800
4801 static inline unsigned long
4802 __copy_from_user (void *to, const void __user *from, unsigned long count)
4803 {
4804+ if (count > INT_MAX)
4805+ return count;
4806+
4807+ if (!__builtin_constant_p(count))
4808+ check_object_size(to, count, false);
4809+
4810 return __copy_user((__force void __user *) to, from, count);
4811 }
4812
4813@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4814 ({ \
4815 void __user *__cu_to = (to); \
4816 const void *__cu_from = (from); \
4817- long __cu_len = (n); \
4818+ unsigned long __cu_len = (n); \
4819 \
4820- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4821+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4822+ if (!__builtin_constant_p(n)) \
4823+ check_object_size(__cu_from, __cu_len, true); \
4824 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4825+ } \
4826 __cu_len; \
4827 })
4828
4829@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4830 ({ \
4831 void *__cu_to = (to); \
4832 const void __user *__cu_from = (from); \
4833- long __cu_len = (n); \
4834+ unsigned long __cu_len = (n); \
4835 \
4836 __chk_user_ptr(__cu_from); \
4837- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4838+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4839+ if (!__builtin_constant_p(n)) \
4840+ check_object_size(__cu_to, __cu_len, false); \
4841 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4842+ } \
4843 __cu_len; \
4844 })
4845
4846diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4847index 2d67317..07d8bfa 100644
4848--- a/arch/ia64/kernel/err_inject.c
4849+++ b/arch/ia64/kernel/err_inject.c
4850@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4851 return NOTIFY_OK;
4852 }
4853
4854-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4855+static struct notifier_block err_inject_cpu_notifier =
4856 {
4857 .notifier_call = err_inject_cpu_callback,
4858 };
4859diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4860index d7396db..b33e873 100644
4861--- a/arch/ia64/kernel/mca.c
4862+++ b/arch/ia64/kernel/mca.c
4863@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4864 return NOTIFY_OK;
4865 }
4866
4867-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4868+static struct notifier_block mca_cpu_notifier = {
4869 .notifier_call = mca_cpu_callback
4870 };
4871
4872diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4873index 24603be..948052d 100644
4874--- a/arch/ia64/kernel/module.c
4875+++ b/arch/ia64/kernel/module.c
4876@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4877 void
4878 module_free (struct module *mod, void *module_region)
4879 {
4880- if (mod && mod->arch.init_unw_table &&
4881- module_region == mod->module_init) {
4882+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4883 unw_remove_unwind_table(mod->arch.init_unw_table);
4884 mod->arch.init_unw_table = NULL;
4885 }
4886@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4887 }
4888
4889 static inline int
4890+in_init_rx (const struct module *mod, uint64_t addr)
4891+{
4892+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4893+}
4894+
4895+static inline int
4896+in_init_rw (const struct module *mod, uint64_t addr)
4897+{
4898+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4899+}
4900+
4901+static inline int
4902 in_init (const struct module *mod, uint64_t addr)
4903 {
4904- return addr - (uint64_t) mod->module_init < mod->init_size;
4905+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4906+}
4907+
4908+static inline int
4909+in_core_rx (const struct module *mod, uint64_t addr)
4910+{
4911+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4912+}
4913+
4914+static inline int
4915+in_core_rw (const struct module *mod, uint64_t addr)
4916+{
4917+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4918 }
4919
4920 static inline int
4921 in_core (const struct module *mod, uint64_t addr)
4922 {
4923- return addr - (uint64_t) mod->module_core < mod->core_size;
4924+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4925 }
4926
4927 static inline int
4928@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4929 break;
4930
4931 case RV_BDREL:
4932- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4933+ if (in_init_rx(mod, val))
4934+ val -= (uint64_t) mod->module_init_rx;
4935+ else if (in_init_rw(mod, val))
4936+ val -= (uint64_t) mod->module_init_rw;
4937+ else if (in_core_rx(mod, val))
4938+ val -= (uint64_t) mod->module_core_rx;
4939+ else if (in_core_rw(mod, val))
4940+ val -= (uint64_t) mod->module_core_rw;
4941 break;
4942
4943 case RV_LTV:
4944@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4945 * addresses have been selected...
4946 */
4947 uint64_t gp;
4948- if (mod->core_size > MAX_LTOFF)
4949+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4950 /*
4951 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4952 * at the end of the module.
4953 */
4954- gp = mod->core_size - MAX_LTOFF / 2;
4955+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4956 else
4957- gp = mod->core_size / 2;
4958- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4959+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4960+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4961 mod->arch.gp = gp;
4962 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4963 }
4964diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4965index 2b3c2d7..a318d84 100644
4966--- a/arch/ia64/kernel/palinfo.c
4967+++ b/arch/ia64/kernel/palinfo.c
4968@@ -980,7 +980,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4969 return NOTIFY_OK;
4970 }
4971
4972-static struct notifier_block __refdata palinfo_cpu_notifier =
4973+static struct notifier_block palinfo_cpu_notifier =
4974 {
4975 .notifier_call = palinfo_cpu_callback,
4976 .priority = 0,
4977diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4978index 4bc580a..7767f24 100644
4979--- a/arch/ia64/kernel/salinfo.c
4980+++ b/arch/ia64/kernel/salinfo.c
4981@@ -609,7 +609,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4982 return NOTIFY_OK;
4983 }
4984
4985-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4986+static struct notifier_block salinfo_cpu_notifier =
4987 {
4988 .notifier_call = salinfo_cpu_callback,
4989 .priority = 0,
4990diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4991index 41e33f8..65180b2 100644
4992--- a/arch/ia64/kernel/sys_ia64.c
4993+++ b/arch/ia64/kernel/sys_ia64.c
4994@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4995 unsigned long align_mask = 0;
4996 struct mm_struct *mm = current->mm;
4997 struct vm_unmapped_area_info info;
4998+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4999
5000 if (len > RGN_MAP_LIMIT)
5001 return -ENOMEM;
5002@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5003 if (REGION_NUMBER(addr) == RGN_HPAGE)
5004 addr = 0;
5005 #endif
5006+
5007+#ifdef CONFIG_PAX_RANDMMAP
5008+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5009+ addr = mm->free_area_cache;
5010+ else
5011+#endif
5012+
5013 if (!addr)
5014 addr = TASK_UNMAPPED_BASE;
5015
5016@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5017 info.high_limit = TASK_SIZE;
5018 info.align_mask = align_mask;
5019 info.align_offset = 0;
5020+ info.threadstack_offset = offset;
5021 return vm_unmapped_area(&info);
5022 }
5023
5024diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
5025index dc00b2c..cce53c2 100644
5026--- a/arch/ia64/kernel/topology.c
5027+++ b/arch/ia64/kernel/topology.c
5028@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
5029 return NOTIFY_OK;
5030 }
5031
5032-static struct notifier_block __cpuinitdata cache_cpu_notifier =
5033+static struct notifier_block cache_cpu_notifier =
5034 {
5035 .notifier_call = cache_cpu_callback
5036 };
5037diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5038index 0ccb28f..8992469 100644
5039--- a/arch/ia64/kernel/vmlinux.lds.S
5040+++ b/arch/ia64/kernel/vmlinux.lds.S
5041@@ -198,7 +198,7 @@ SECTIONS {
5042 /* Per-cpu data: */
5043 . = ALIGN(PERCPU_PAGE_SIZE);
5044 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5045- __phys_per_cpu_start = __per_cpu_load;
5046+ __phys_per_cpu_start = per_cpu_load;
5047 /*
5048 * ensure percpu data fits
5049 * into percpu page size
5050diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5051index 6cf0341..d352594 100644
5052--- a/arch/ia64/mm/fault.c
5053+++ b/arch/ia64/mm/fault.c
5054@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5055 return pte_present(pte);
5056 }
5057
5058+#ifdef CONFIG_PAX_PAGEEXEC
5059+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5060+{
5061+ unsigned long i;
5062+
5063+ printk(KERN_ERR "PAX: bytes at PC: ");
5064+ for (i = 0; i < 8; i++) {
5065+ unsigned int c;
5066+ if (get_user(c, (unsigned int *)pc+i))
5067+ printk(KERN_CONT "???????? ");
5068+ else
5069+ printk(KERN_CONT "%08x ", c);
5070+ }
5071+ printk("\n");
5072+}
5073+#endif
5074+
5075 # define VM_READ_BIT 0
5076 # define VM_WRITE_BIT 1
5077 # define VM_EXEC_BIT 2
5078@@ -149,8 +166,21 @@ retry:
5079 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5080 goto bad_area;
5081
5082- if ((vma->vm_flags & mask) != mask)
5083+ if ((vma->vm_flags & mask) != mask) {
5084+
5085+#ifdef CONFIG_PAX_PAGEEXEC
5086+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5087+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5088+ goto bad_area;
5089+
5090+ up_read(&mm->mmap_sem);
5091+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5092+ do_group_exit(SIGKILL);
5093+ }
5094+#endif
5095+
5096 goto bad_area;
5097+ }
5098
5099 /*
5100 * If for any reason at all we couldn't handle the fault, make
5101diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5102index 76069c1..c2aa816 100644
5103--- a/arch/ia64/mm/hugetlbpage.c
5104+++ b/arch/ia64/mm/hugetlbpage.c
5105@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5106 unsigned long pgoff, unsigned long flags)
5107 {
5108 struct vm_unmapped_area_info info;
5109+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5110
5111 if (len > RGN_MAP_LIMIT)
5112 return -ENOMEM;
5113@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5114 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5115 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5116 info.align_offset = 0;
5117+ info.threadstack_offset = offset;
5118 return vm_unmapped_area(&info);
5119 }
5120
5121diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5122index d1fe4b4..2628f37 100644
5123--- a/arch/ia64/mm/init.c
5124+++ b/arch/ia64/mm/init.c
5125@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5126 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5127 vma->vm_end = vma->vm_start + PAGE_SIZE;
5128 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5129+
5130+#ifdef CONFIG_PAX_PAGEEXEC
5131+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5132+ vma->vm_flags &= ~VM_EXEC;
5133+
5134+#ifdef CONFIG_PAX_MPROTECT
5135+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5136+ vma->vm_flags &= ~VM_MAYEXEC;
5137+#endif
5138+
5139+ }
5140+#endif
5141+
5142 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5143 down_write(&current->mm->mmap_sem);
5144 if (insert_vm_struct(current->mm, vma)) {
5145diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5146index 40b3ee9..8c2c112 100644
5147--- a/arch/m32r/include/asm/cache.h
5148+++ b/arch/m32r/include/asm/cache.h
5149@@ -1,8 +1,10 @@
5150 #ifndef _ASM_M32R_CACHE_H
5151 #define _ASM_M32R_CACHE_H
5152
5153+#include <linux/const.h>
5154+
5155 /* L1 cache line size */
5156 #define L1_CACHE_SHIFT 4
5157-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5158+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5159
5160 #endif /* _ASM_M32R_CACHE_H */
5161diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5162index 82abd15..d95ae5d 100644
5163--- a/arch/m32r/lib/usercopy.c
5164+++ b/arch/m32r/lib/usercopy.c
5165@@ -14,6 +14,9 @@
5166 unsigned long
5167 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5168 {
5169+ if ((long)n < 0)
5170+ return n;
5171+
5172 prefetch(from);
5173 if (access_ok(VERIFY_WRITE, to, n))
5174 __copy_user(to,from,n);
5175@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5176 unsigned long
5177 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5178 {
5179+ if ((long)n < 0)
5180+ return n;
5181+
5182 prefetchw(to);
5183 if (access_ok(VERIFY_READ, from, n))
5184 __copy_user_zeroing(to,from,n);
5185diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5186index 0395c51..5f26031 100644
5187--- a/arch/m68k/include/asm/cache.h
5188+++ b/arch/m68k/include/asm/cache.h
5189@@ -4,9 +4,11 @@
5190 #ifndef __ARCH_M68K_CACHE_H
5191 #define __ARCH_M68K_CACHE_H
5192
5193+#include <linux/const.h>
5194+
5195 /* bytes per L1 cache line */
5196 #define L1_CACHE_SHIFT 4
5197-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5198+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5199
5200 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5201
5202diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5203index 3c52fa6..11b2ad8 100644
5204--- a/arch/metag/mm/hugetlbpage.c
5205+++ b/arch/metag/mm/hugetlbpage.c
5206@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5207 info.high_limit = TASK_SIZE;
5208 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5209 info.align_offset = 0;
5210+ info.threadstack_offset = 0;
5211 return vm_unmapped_area(&info);
5212 }
5213
5214diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5215index 4efe96a..60e8699 100644
5216--- a/arch/microblaze/include/asm/cache.h
5217+++ b/arch/microblaze/include/asm/cache.h
5218@@ -13,11 +13,12 @@
5219 #ifndef _ASM_MICROBLAZE_CACHE_H
5220 #define _ASM_MICROBLAZE_CACHE_H
5221
5222+#include <linux/const.h>
5223 #include <asm/registers.h>
5224
5225 #define L1_CACHE_SHIFT 5
5226 /* word-granular cache in microblaze */
5227-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5228+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5229
5230 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5231
5232diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5233index 08b6079..eb272cf 100644
5234--- a/arch/mips/include/asm/atomic.h
5235+++ b/arch/mips/include/asm/atomic.h
5236@@ -21,6 +21,10 @@
5237 #include <asm/cmpxchg.h>
5238 #include <asm/war.h>
5239
5240+#ifdef CONFIG_GENERIC_ATOMIC64
5241+#include <asm-generic/atomic64.h>
5242+#endif
5243+
5244 #define ATOMIC_INIT(i) { (i) }
5245
5246 /*
5247@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5248 */
5249 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5250
5251+#define atomic64_read_unchecked(v) atomic64_read(v)
5252+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5253+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5254+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5255+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5256+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5257+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5258+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5259+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5260+
5261 #endif /* CONFIG_64BIT */
5262
5263 /*
5264diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5265index b4db69f..8f3b093 100644
5266--- a/arch/mips/include/asm/cache.h
5267+++ b/arch/mips/include/asm/cache.h
5268@@ -9,10 +9,11 @@
5269 #ifndef _ASM_CACHE_H
5270 #define _ASM_CACHE_H
5271
5272+#include <linux/const.h>
5273 #include <kmalloc.h>
5274
5275 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5276-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5277+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5278
5279 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5280 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5281diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5282index cf3ae24..238d22f 100644
5283--- a/arch/mips/include/asm/elf.h
5284+++ b/arch/mips/include/asm/elf.h
5285@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5286 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5287 #endif
5288
5289+#ifdef CONFIG_PAX_ASLR
5290+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5291+
5292+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5293+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5294+#endif
5295+
5296 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5297 struct linux_binprm;
5298 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5299 int uses_interp);
5300
5301-struct mm_struct;
5302-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5303-#define arch_randomize_brk arch_randomize_brk
5304-
5305 #endif /* _ASM_ELF_H */
5306diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5307index c1f6afa..38cc6e9 100644
5308--- a/arch/mips/include/asm/exec.h
5309+++ b/arch/mips/include/asm/exec.h
5310@@ -12,6 +12,6 @@
5311 #ifndef _ASM_EXEC_H
5312 #define _ASM_EXEC_H
5313
5314-extern unsigned long arch_align_stack(unsigned long sp);
5315+#define arch_align_stack(x) ((x) & ~0xfUL)
5316
5317 #endif /* _ASM_EXEC_H */
5318diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5319index f59552f..3abe9b9 100644
5320--- a/arch/mips/include/asm/page.h
5321+++ b/arch/mips/include/asm/page.h
5322@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5323 #ifdef CONFIG_CPU_MIPS32
5324 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5325 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5326- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5327+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5328 #else
5329 typedef struct { unsigned long long pte; } pte_t;
5330 #define pte_val(x) ((x).pte)
5331diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5332index 881d18b..cea38bc 100644
5333--- a/arch/mips/include/asm/pgalloc.h
5334+++ b/arch/mips/include/asm/pgalloc.h
5335@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5336 {
5337 set_pud(pud, __pud((unsigned long)pmd));
5338 }
5339+
5340+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5341+{
5342+ pud_populate(mm, pud, pmd);
5343+}
5344 #endif
5345
5346 /*
5347diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5348index 895320e..bf63e10 100644
5349--- a/arch/mips/include/asm/thread_info.h
5350+++ b/arch/mips/include/asm/thread_info.h
5351@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
5352 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5353 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5354 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5355+/* li takes a 32bit immediate */
5356+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5357 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5358
5359 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5360@@ -130,15 +132,18 @@ static inline struct thread_info *current_thread_info(void)
5361 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5362 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5363 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5364+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5365+
5366+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5367
5368 /* work to do in syscall_trace_leave() */
5369-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5370+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5371
5372 /* work to do on interrupt/exception return */
5373 #define _TIF_WORK_MASK \
5374 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5375 /* work to do on any return to u-space */
5376-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5377+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5378
5379 #endif /* __KERNEL__ */
5380
5381diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5382index 1188e00..41cf144 100644
5383--- a/arch/mips/kernel/binfmt_elfn32.c
5384+++ b/arch/mips/kernel/binfmt_elfn32.c
5385@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5386 #undef ELF_ET_DYN_BASE
5387 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5388
5389+#ifdef CONFIG_PAX_ASLR
5390+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5391+
5392+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5393+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5394+#endif
5395+
5396 #include <asm/processor.h>
5397 #include <linux/module.h>
5398 #include <linux/elfcore.h>
5399diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5400index 202e581..689ca79 100644
5401--- a/arch/mips/kernel/binfmt_elfo32.c
5402+++ b/arch/mips/kernel/binfmt_elfo32.c
5403@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5404 #undef ELF_ET_DYN_BASE
5405 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5406
5407+#ifdef CONFIG_PAX_ASLR
5408+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5409+
5410+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5411+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5412+#endif
5413+
5414 #include <asm/processor.h>
5415
5416 /*
5417diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5418index c6a041d..b3e7318 100644
5419--- a/arch/mips/kernel/process.c
5420+++ b/arch/mips/kernel/process.c
5421@@ -563,15 +563,3 @@ unsigned long get_wchan(struct task_struct *task)
5422 out:
5423 return pc;
5424 }
5425-
5426-/*
5427- * Don't forget that the stack pointer must be aligned on a 8 bytes
5428- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5429- */
5430-unsigned long arch_align_stack(unsigned long sp)
5431-{
5432- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5433- sp -= get_random_int() & ~PAGE_MASK;
5434-
5435- return sp & ALMASK;
5436-}
5437diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5438index 9c6299c..2fb4c22 100644
5439--- a/arch/mips/kernel/ptrace.c
5440+++ b/arch/mips/kernel/ptrace.c
5441@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5442 return arch;
5443 }
5444
5445+#ifdef CONFIG_GRKERNSEC_SETXID
5446+extern void gr_delayed_cred_worker(void);
5447+#endif
5448+
5449 /*
5450 * Notification of system call entry/exit
5451 * - triggered by current->work.syscall_trace
5452@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5453 /* do the secure computing check first */
5454 secure_computing_strict(regs->regs[2]);
5455
5456+#ifdef CONFIG_GRKERNSEC_SETXID
5457+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5458+ gr_delayed_cred_worker();
5459+#endif
5460+
5461 if (!(current->ptrace & PT_PTRACED))
5462 goto out;
5463
5464diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5465index 9b36424..e7f4154 100644
5466--- a/arch/mips/kernel/scall32-o32.S
5467+++ b/arch/mips/kernel/scall32-o32.S
5468@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5469
5470 stack_done:
5471 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5472- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5473+ li t1, _TIF_SYSCALL_WORK
5474 and t0, t1
5475 bnez t0, syscall_trace_entry # -> yes
5476
5477diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5478index 97a5909..59622f8 100644
5479--- a/arch/mips/kernel/scall64-64.S
5480+++ b/arch/mips/kernel/scall64-64.S
5481@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5482
5483 sd a3, PT_R26(sp) # save a3 for syscall restarting
5484
5485- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5486+ li t1, _TIF_SYSCALL_WORK
5487 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5488 and t0, t1, t0
5489 bnez t0, syscall_trace_entry
5490diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5491index edcb659..fb2ab09 100644
5492--- a/arch/mips/kernel/scall64-n32.S
5493+++ b/arch/mips/kernel/scall64-n32.S
5494@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5495
5496 sd a3, PT_R26(sp) # save a3 for syscall restarting
5497
5498- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5499+ li t1, _TIF_SYSCALL_WORK
5500 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5501 and t0, t1, t0
5502 bnez t0, n32_syscall_trace_entry
5503diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5504index 74f485d..47d2c38 100644
5505--- a/arch/mips/kernel/scall64-o32.S
5506+++ b/arch/mips/kernel/scall64-o32.S
5507@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5508 PTR 4b, bad_stack
5509 .previous
5510
5511- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5512+ li t1, _TIF_SYSCALL_WORK
5513 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5514 and t0, t1, t0
5515 bnez t0, trace_a_syscall
5516diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5517index 0fead53..a2c0fb5 100644
5518--- a/arch/mips/mm/fault.c
5519+++ b/arch/mips/mm/fault.c
5520@@ -27,6 +27,23 @@
5521 #include <asm/highmem.h> /* For VMALLOC_END */
5522 #include <linux/kdebug.h>
5523
5524+#ifdef CONFIG_PAX_PAGEEXEC
5525+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5526+{
5527+ unsigned long i;
5528+
5529+ printk(KERN_ERR "PAX: bytes at PC: ");
5530+ for (i = 0; i < 5; i++) {
5531+ unsigned int c;
5532+ if (get_user(c, (unsigned int *)pc+i))
5533+ printk(KERN_CONT "???????? ");
5534+ else
5535+ printk(KERN_CONT "%08x ", c);
5536+ }
5537+ printk("\n");
5538+}
5539+#endif
5540+
5541 /*
5542 * This routine handles page faults. It determines the address,
5543 * and the problem, and then passes it off to one of the appropriate
5544diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5545index 7e5fe27..9656513 100644
5546--- a/arch/mips/mm/mmap.c
5547+++ b/arch/mips/mm/mmap.c
5548@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5549 struct vm_area_struct *vma;
5550 unsigned long addr = addr0;
5551 int do_color_align;
5552+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5553 struct vm_unmapped_area_info info;
5554
5555 if (unlikely(len > TASK_SIZE))
5556@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5557 do_color_align = 1;
5558
5559 /* requesting a specific address */
5560+
5561+#ifdef CONFIG_PAX_RANDMMAP
5562+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5563+#endif
5564+
5565 if (addr) {
5566 if (do_color_align)
5567 addr = COLOUR_ALIGN(addr, pgoff);
5568@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5569 addr = PAGE_ALIGN(addr);
5570
5571 vma = find_vma(mm, addr);
5572- if (TASK_SIZE - len >= addr &&
5573- (!vma || addr + len <= vma->vm_start))
5574+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5575 return addr;
5576 }
5577
5578 info.length = len;
5579 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
5580 info.align_offset = pgoff << PAGE_SHIFT;
5581+ info.threadstack_offset = offset;
5582
5583 if (dir == DOWN) {
5584 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
5585@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5586 {
5587 unsigned long random_factor = 0UL;
5588
5589+#ifdef CONFIG_PAX_RANDMMAP
5590+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5591+#endif
5592+
5593 if (current->flags & PF_RANDOMIZE) {
5594 random_factor = get_random_int();
5595 random_factor = random_factor << PAGE_SHIFT;
5596@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5597
5598 if (mmap_is_legacy()) {
5599 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5600+
5601+#ifdef CONFIG_PAX_RANDMMAP
5602+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5603+ mm->mmap_base += mm->delta_mmap;
5604+#endif
5605+
5606 mm->get_unmapped_area = arch_get_unmapped_area;
5607 mm->unmap_area = arch_unmap_area;
5608 } else {
5609 mm->mmap_base = mmap_base(random_factor);
5610+
5611+#ifdef CONFIG_PAX_RANDMMAP
5612+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5613+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5614+#endif
5615+
5616 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5617 mm->unmap_area = arch_unmap_area_topdown;
5618 }
5619 }
5620
5621-static inline unsigned long brk_rnd(void)
5622-{
5623- unsigned long rnd = get_random_int();
5624-
5625- rnd = rnd << PAGE_SHIFT;
5626- /* 8MB for 32bit, 256MB for 64bit */
5627- if (TASK_IS_32BIT_ADDR)
5628- rnd = rnd & 0x7ffffful;
5629- else
5630- rnd = rnd & 0xffffffful;
5631-
5632- return rnd;
5633-}
5634-
5635-unsigned long arch_randomize_brk(struct mm_struct *mm)
5636-{
5637- unsigned long base = mm->brk;
5638- unsigned long ret;
5639-
5640- ret = PAGE_ALIGN(base + brk_rnd());
5641-
5642- if (ret < mm->brk)
5643- return mm->brk;
5644-
5645- return ret;
5646-}
5647-
5648 int __virt_addr_valid(const volatile void *kaddr)
5649 {
5650 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5651diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5652index 967d144..db12197 100644
5653--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5654+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5655@@ -11,12 +11,14 @@
5656 #ifndef _ASM_PROC_CACHE_H
5657 #define _ASM_PROC_CACHE_H
5658
5659+#include <linux/const.h>
5660+
5661 /* L1 cache */
5662
5663 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5664 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5665-#define L1_CACHE_BYTES 16 /* bytes per entry */
5666 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5667+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5668 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5669
5670 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5671diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5672index bcb5df2..84fabd2 100644
5673--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5674+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5675@@ -16,13 +16,15 @@
5676 #ifndef _ASM_PROC_CACHE_H
5677 #define _ASM_PROC_CACHE_H
5678
5679+#include <linux/const.h>
5680+
5681 /*
5682 * L1 cache
5683 */
5684 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5685 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5686-#define L1_CACHE_BYTES 32 /* bytes per entry */
5687 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5688+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5689 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5690
5691 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5692diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5693index 4ce7a01..449202a 100644
5694--- a/arch/openrisc/include/asm/cache.h
5695+++ b/arch/openrisc/include/asm/cache.h
5696@@ -19,11 +19,13 @@
5697 #ifndef __ASM_OPENRISC_CACHE_H
5698 #define __ASM_OPENRISC_CACHE_H
5699
5700+#include <linux/const.h>
5701+
5702 /* FIXME: How can we replace these with values from the CPU...
5703 * they shouldn't be hard-coded!
5704 */
5705
5706-#define L1_CACHE_BYTES 16
5707 #define L1_CACHE_SHIFT 4
5708+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5709
5710 #endif /* __ASM_OPENRISC_CACHE_H */
5711diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5712index 472886c..00e7df9 100644
5713--- a/arch/parisc/include/asm/atomic.h
5714+++ b/arch/parisc/include/asm/atomic.h
5715@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
5716 return dec;
5717 }
5718
5719+#define atomic64_read_unchecked(v) atomic64_read(v)
5720+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5721+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5722+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5723+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5724+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5725+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5726+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5727+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5728+
5729 #endif /* !CONFIG_64BIT */
5730
5731
5732diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5733index 47f11c7..3420df2 100644
5734--- a/arch/parisc/include/asm/cache.h
5735+++ b/arch/parisc/include/asm/cache.h
5736@@ -5,6 +5,7 @@
5737 #ifndef __ARCH_PARISC_CACHE_H
5738 #define __ARCH_PARISC_CACHE_H
5739
5740+#include <linux/const.h>
5741
5742 /*
5743 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5744@@ -15,13 +16,13 @@
5745 * just ruin performance.
5746 */
5747 #ifdef CONFIG_PA20
5748-#define L1_CACHE_BYTES 64
5749 #define L1_CACHE_SHIFT 6
5750 #else
5751-#define L1_CACHE_BYTES 32
5752 #define L1_CACHE_SHIFT 5
5753 #endif
5754
5755+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5756+
5757 #ifndef __ASSEMBLY__
5758
5759 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5760diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5761index ad2b503..bdf1651 100644
5762--- a/arch/parisc/include/asm/elf.h
5763+++ b/arch/parisc/include/asm/elf.h
5764@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5765
5766 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5767
5768+#ifdef CONFIG_PAX_ASLR
5769+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5770+
5771+#define PAX_DELTA_MMAP_LEN 16
5772+#define PAX_DELTA_STACK_LEN 16
5773+#endif
5774+
5775 /* This yields a mask that user programs can use to figure out what
5776 instruction set this CPU supports. This could be done in user space,
5777 but it's not easy, and we've already done it here. */
5778diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5779index fc987a1..6e068ef 100644
5780--- a/arch/parisc/include/asm/pgalloc.h
5781+++ b/arch/parisc/include/asm/pgalloc.h
5782@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5783 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5784 }
5785
5786+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5787+{
5788+ pgd_populate(mm, pgd, pmd);
5789+}
5790+
5791 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5792 {
5793 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5794@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5795 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5796 #define pmd_free(mm, x) do { } while (0)
5797 #define pgd_populate(mm, pmd, pte) BUG()
5798+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5799
5800 #endif
5801
5802diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5803index 1e40d7f..a3eb445 100644
5804--- a/arch/parisc/include/asm/pgtable.h
5805+++ b/arch/parisc/include/asm/pgtable.h
5806@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5807 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5808 #define PAGE_COPY PAGE_EXECREAD
5809 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5810+
5811+#ifdef CONFIG_PAX_PAGEEXEC
5812+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5813+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5814+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5815+#else
5816+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5817+# define PAGE_COPY_NOEXEC PAGE_COPY
5818+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5819+#endif
5820+
5821 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5822 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5823 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5824diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5825index e0a8235..ce2f1e1 100644
5826--- a/arch/parisc/include/asm/uaccess.h
5827+++ b/arch/parisc/include/asm/uaccess.h
5828@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5829 const void __user *from,
5830 unsigned long n)
5831 {
5832- int sz = __compiletime_object_size(to);
5833+ size_t sz = __compiletime_object_size(to);
5834 int ret = -EFAULT;
5835
5836- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5837+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5838 ret = __copy_from_user(to, from, n);
5839 else
5840 copy_from_user_overflow();
5841diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5842index 2a625fb..9908930 100644
5843--- a/arch/parisc/kernel/module.c
5844+++ b/arch/parisc/kernel/module.c
5845@@ -98,16 +98,38 @@
5846
5847 /* three functions to determine where in the module core
5848 * or init pieces the location is */
5849+static inline int in_init_rx(struct module *me, void *loc)
5850+{
5851+ return (loc >= me->module_init_rx &&
5852+ loc < (me->module_init_rx + me->init_size_rx));
5853+}
5854+
5855+static inline int in_init_rw(struct module *me, void *loc)
5856+{
5857+ return (loc >= me->module_init_rw &&
5858+ loc < (me->module_init_rw + me->init_size_rw));
5859+}
5860+
5861 static inline int in_init(struct module *me, void *loc)
5862 {
5863- return (loc >= me->module_init &&
5864- loc <= (me->module_init + me->init_size));
5865+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5866+}
5867+
5868+static inline int in_core_rx(struct module *me, void *loc)
5869+{
5870+ return (loc >= me->module_core_rx &&
5871+ loc < (me->module_core_rx + me->core_size_rx));
5872+}
5873+
5874+static inline int in_core_rw(struct module *me, void *loc)
5875+{
5876+ return (loc >= me->module_core_rw &&
5877+ loc < (me->module_core_rw + me->core_size_rw));
5878 }
5879
5880 static inline int in_core(struct module *me, void *loc)
5881 {
5882- return (loc >= me->module_core &&
5883- loc <= (me->module_core + me->core_size));
5884+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5885 }
5886
5887 static inline int in_local(struct module *me, void *loc)
5888@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5889 }
5890
5891 /* align things a bit */
5892- me->core_size = ALIGN(me->core_size, 16);
5893- me->arch.got_offset = me->core_size;
5894- me->core_size += gots * sizeof(struct got_entry);
5895+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5896+ me->arch.got_offset = me->core_size_rw;
5897+ me->core_size_rw += gots * sizeof(struct got_entry);
5898
5899- me->core_size = ALIGN(me->core_size, 16);
5900- me->arch.fdesc_offset = me->core_size;
5901- me->core_size += fdescs * sizeof(Elf_Fdesc);
5902+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5903+ me->arch.fdesc_offset = me->core_size_rw;
5904+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5905
5906 me->arch.got_max = gots;
5907 me->arch.fdesc_max = fdescs;
5908@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5909
5910 BUG_ON(value == 0);
5911
5912- got = me->module_core + me->arch.got_offset;
5913+ got = me->module_core_rw + me->arch.got_offset;
5914 for (i = 0; got[i].addr; i++)
5915 if (got[i].addr == value)
5916 goto out;
5917@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5918 #ifdef CONFIG_64BIT
5919 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5920 {
5921- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5922+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5923
5924 if (!value) {
5925 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5926@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5927
5928 /* Create new one */
5929 fdesc->addr = value;
5930- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5931+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5932 return (Elf_Addr)fdesc;
5933 }
5934 #endif /* CONFIG_64BIT */
5935@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5936
5937 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5938 end = table + sechdrs[me->arch.unwind_section].sh_size;
5939- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5940+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5941
5942 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5943 me->arch.unwind_section, table, end, gp);
5944diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5945index 5dfd248..64914ac 100644
5946--- a/arch/parisc/kernel/sys_parisc.c
5947+++ b/arch/parisc/kernel/sys_parisc.c
5948@@ -33,9 +33,11 @@
5949 #include <linux/utsname.h>
5950 #include <linux/personality.h>
5951
5952-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5953+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5954+ unsigned long flags)
5955 {
5956 struct vm_unmapped_area_info info;
5957+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5958
5959 info.flags = 0;
5960 info.length = len;
5961@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5962 info.high_limit = TASK_SIZE;
5963 info.align_mask = 0;
5964 info.align_offset = 0;
5965+ info.threadstack_offset = offset;
5966 return vm_unmapped_area(&info);
5967 }
5968
5969@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
5970 return (unsigned long) mapping >> 8;
5971 }
5972
5973-static unsigned long get_shared_area(struct address_space *mapping,
5974- unsigned long addr, unsigned long len, unsigned long pgoff)
5975+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5976+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5977 {
5978 struct vm_unmapped_area_info info;
5979+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5980
5981 info.flags = 0;
5982 info.length = len;
5983@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5984 info.high_limit = TASK_SIZE;
5985 info.align_mask = PAGE_MASK & (SHMLBA - 1);
5986 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
5987+ info.threadstack_offset = offset;
5988 return vm_unmapped_area(&info);
5989 }
5990
5991@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5992 return -EINVAL;
5993 return addr;
5994 }
5995- if (!addr)
5996+ if (!addr) {
5997 addr = TASK_UNMAPPED_BASE;
5998
5999+#ifdef CONFIG_PAX_RANDMMAP
6000+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
6001+ addr += current->mm->delta_mmap;
6002+#endif
6003+
6004+ }
6005+
6006 if (filp) {
6007- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
6008+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
6009 } else if(flags & MAP_SHARED) {
6010- addr = get_shared_area(NULL, addr, len, pgoff);
6011+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
6012 } else {
6013- addr = get_unshared_area(addr, len);
6014+ addr = get_unshared_area(filp, addr, len, flags);
6015 }
6016 return addr;
6017 }
6018diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
6019index 04e47c6..7a8faf6 100644
6020--- a/arch/parisc/kernel/traps.c
6021+++ b/arch/parisc/kernel/traps.c
6022@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
6023
6024 down_read(&current->mm->mmap_sem);
6025 vma = find_vma(current->mm,regs->iaoq[0]);
6026- if (vma && (regs->iaoq[0] >= vma->vm_start)
6027- && (vma->vm_flags & VM_EXEC)) {
6028-
6029+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
6030 fault_address = regs->iaoq[0];
6031 fault_space = regs->iasq[0];
6032
6033diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
6034index f247a34..dc0f219 100644
6035--- a/arch/parisc/mm/fault.c
6036+++ b/arch/parisc/mm/fault.c
6037@@ -15,6 +15,7 @@
6038 #include <linux/sched.h>
6039 #include <linux/interrupt.h>
6040 #include <linux/module.h>
6041+#include <linux/unistd.h>
6042
6043 #include <asm/uaccess.h>
6044 #include <asm/traps.h>
6045@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
6046 static unsigned long
6047 parisc_acctyp(unsigned long code, unsigned int inst)
6048 {
6049- if (code == 6 || code == 16)
6050+ if (code == 6 || code == 7 || code == 16)
6051 return VM_EXEC;
6052
6053 switch (inst & 0xf0000000) {
6054@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
6055 }
6056 #endif
6057
6058+#ifdef CONFIG_PAX_PAGEEXEC
6059+/*
6060+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
6061+ *
6062+ * returns 1 when task should be killed
6063+ * 2 when rt_sigreturn trampoline was detected
6064+ * 3 when unpatched PLT trampoline was detected
6065+ */
6066+static int pax_handle_fetch_fault(struct pt_regs *regs)
6067+{
6068+
6069+#ifdef CONFIG_PAX_EMUPLT
6070+ int err;
6071+
6072+ do { /* PaX: unpatched PLT emulation */
6073+ unsigned int bl, depwi;
6074+
6075+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
6076+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
6077+
6078+ if (err)
6079+ break;
6080+
6081+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
6082+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
6083+
6084+ err = get_user(ldw, (unsigned int *)addr);
6085+ err |= get_user(bv, (unsigned int *)(addr+4));
6086+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6087+
6088+ if (err)
6089+ break;
6090+
6091+ if (ldw == 0x0E801096U &&
6092+ bv == 0xEAC0C000U &&
6093+ ldw2 == 0x0E881095U)
6094+ {
6095+ unsigned int resolver, map;
6096+
6097+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6098+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6099+ if (err)
6100+ break;
6101+
6102+ regs->gr[20] = instruction_pointer(regs)+8;
6103+ regs->gr[21] = map;
6104+ regs->gr[22] = resolver;
6105+ regs->iaoq[0] = resolver | 3UL;
6106+ regs->iaoq[1] = regs->iaoq[0] + 4;
6107+ return 3;
6108+ }
6109+ }
6110+ } while (0);
6111+#endif
6112+
6113+#ifdef CONFIG_PAX_EMUTRAMP
6114+
6115+#ifndef CONFIG_PAX_EMUSIGRT
6116+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6117+ return 1;
6118+#endif
6119+
6120+ do { /* PaX: rt_sigreturn emulation */
6121+ unsigned int ldi1, ldi2, bel, nop;
6122+
6123+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6124+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6125+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6126+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6127+
6128+ if (err)
6129+ break;
6130+
6131+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6132+ ldi2 == 0x3414015AU &&
6133+ bel == 0xE4008200U &&
6134+ nop == 0x08000240U)
6135+ {
6136+ regs->gr[25] = (ldi1 & 2) >> 1;
6137+ regs->gr[20] = __NR_rt_sigreturn;
6138+ regs->gr[31] = regs->iaoq[1] + 16;
6139+ regs->sr[0] = regs->iasq[1];
6140+ regs->iaoq[0] = 0x100UL;
6141+ regs->iaoq[1] = regs->iaoq[0] + 4;
6142+ regs->iasq[0] = regs->sr[2];
6143+ regs->iasq[1] = regs->sr[2];
6144+ return 2;
6145+ }
6146+ } while (0);
6147+#endif
6148+
6149+ return 1;
6150+}
6151+
6152+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6153+{
6154+ unsigned long i;
6155+
6156+ printk(KERN_ERR "PAX: bytes at PC: ");
6157+ for (i = 0; i < 5; i++) {
6158+ unsigned int c;
6159+ if (get_user(c, (unsigned int *)pc+i))
6160+ printk(KERN_CONT "???????? ");
6161+ else
6162+ printk(KERN_CONT "%08x ", c);
6163+ }
6164+ printk("\n");
6165+}
6166+#endif
6167+
6168 int fixup_exception(struct pt_regs *regs)
6169 {
6170 const struct exception_table_entry *fix;
6171@@ -194,8 +305,33 @@ good_area:
6172
6173 acc_type = parisc_acctyp(code,regs->iir);
6174
6175- if ((vma->vm_flags & acc_type) != acc_type)
6176+ if ((vma->vm_flags & acc_type) != acc_type) {
6177+
6178+#ifdef CONFIG_PAX_PAGEEXEC
6179+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6180+ (address & ~3UL) == instruction_pointer(regs))
6181+ {
6182+ up_read(&mm->mmap_sem);
6183+ switch (pax_handle_fetch_fault(regs)) {
6184+
6185+#ifdef CONFIG_PAX_EMUPLT
6186+ case 3:
6187+ return;
6188+#endif
6189+
6190+#ifdef CONFIG_PAX_EMUTRAMP
6191+ case 2:
6192+ return;
6193+#endif
6194+
6195+ }
6196+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6197+ do_group_exit(SIGKILL);
6198+ }
6199+#endif
6200+
6201 goto bad_area;
6202+ }
6203
6204 /*
6205 * If for any reason at all we couldn't handle the fault, make
6206diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6207index e3b1d41..8e81edf 100644
6208--- a/arch/powerpc/include/asm/atomic.h
6209+++ b/arch/powerpc/include/asm/atomic.h
6210@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6211 return t1;
6212 }
6213
6214+#define atomic64_read_unchecked(v) atomic64_read(v)
6215+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6216+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6217+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6218+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6219+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6220+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6221+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6222+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6223+
6224 #endif /* __powerpc64__ */
6225
6226 #endif /* __KERNEL__ */
6227diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6228index 9e495c9..b6878e5 100644
6229--- a/arch/powerpc/include/asm/cache.h
6230+++ b/arch/powerpc/include/asm/cache.h
6231@@ -3,6 +3,7 @@
6232
6233 #ifdef __KERNEL__
6234
6235+#include <linux/const.h>
6236
6237 /* bytes per L1 cache line */
6238 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6239@@ -22,7 +23,7 @@
6240 #define L1_CACHE_SHIFT 7
6241 #endif
6242
6243-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6244+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6245
6246 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6247
6248diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6249index cc0655a..13eac2e 100644
6250--- a/arch/powerpc/include/asm/elf.h
6251+++ b/arch/powerpc/include/asm/elf.h
6252@@ -28,8 +28,19 @@
6253 the loader. We need to make sure that it is out of the way of the program
6254 that it will "exec", and that there is sufficient room for the brk. */
6255
6256-extern unsigned long randomize_et_dyn(unsigned long base);
6257-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6258+#define ELF_ET_DYN_BASE (0x20000000)
6259+
6260+#ifdef CONFIG_PAX_ASLR
6261+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6262+
6263+#ifdef __powerpc64__
6264+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6265+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6266+#else
6267+#define PAX_DELTA_MMAP_LEN 15
6268+#define PAX_DELTA_STACK_LEN 15
6269+#endif
6270+#endif
6271
6272 /*
6273 * Our registers are always unsigned longs, whether we're a 32 bit
6274@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6275 (0x7ff >> (PAGE_SHIFT - 12)) : \
6276 (0x3ffff >> (PAGE_SHIFT - 12)))
6277
6278-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6279-#define arch_randomize_brk arch_randomize_brk
6280-
6281-
6282 #ifdef CONFIG_SPU_BASE
6283 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6284 #define NT_SPU 1
6285diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6286index 8196e9c..d83a9f3 100644
6287--- a/arch/powerpc/include/asm/exec.h
6288+++ b/arch/powerpc/include/asm/exec.h
6289@@ -4,6 +4,6 @@
6290 #ifndef _ASM_POWERPC_EXEC_H
6291 #define _ASM_POWERPC_EXEC_H
6292
6293-extern unsigned long arch_align_stack(unsigned long sp);
6294+#define arch_align_stack(x) ((x) & ~0xfUL)
6295
6296 #endif /* _ASM_POWERPC_EXEC_H */
6297diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6298index 5acabbd..7ea14fa 100644
6299--- a/arch/powerpc/include/asm/kmap_types.h
6300+++ b/arch/powerpc/include/asm/kmap_types.h
6301@@ -10,7 +10,7 @@
6302 * 2 of the License, or (at your option) any later version.
6303 */
6304
6305-#define KM_TYPE_NR 16
6306+#define KM_TYPE_NR 17
6307
6308 #endif /* __KERNEL__ */
6309 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6310diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6311index 8565c25..2865190 100644
6312--- a/arch/powerpc/include/asm/mman.h
6313+++ b/arch/powerpc/include/asm/mman.h
6314@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6315 }
6316 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6317
6318-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6319+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6320 {
6321 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6322 }
6323diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6324index 988c812..63c7d70 100644
6325--- a/arch/powerpc/include/asm/page.h
6326+++ b/arch/powerpc/include/asm/page.h
6327@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6328 * and needs to be executable. This means the whole heap ends
6329 * up being executable.
6330 */
6331-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6332- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6333+#define VM_DATA_DEFAULT_FLAGS32 \
6334+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6335+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6336
6337 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6338 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6339@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6340 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6341 #endif
6342
6343+#define ktla_ktva(addr) (addr)
6344+#define ktva_ktla(addr) (addr)
6345+
6346 #ifndef CONFIG_PPC_BOOK3S_64
6347 /*
6348 * Use the top bit of the higher-level page table entries to indicate whether
6349diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6350index 88693ce..ac6f9ab 100644
6351--- a/arch/powerpc/include/asm/page_64.h
6352+++ b/arch/powerpc/include/asm/page_64.h
6353@@ -153,15 +153,18 @@ do { \
6354 * stack by default, so in the absence of a PT_GNU_STACK program header
6355 * we turn execute permission off.
6356 */
6357-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6358- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6359+#define VM_STACK_DEFAULT_FLAGS32 \
6360+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6361+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6362
6363 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6364 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6365
6366+#ifndef CONFIG_PAX_PAGEEXEC
6367 #define VM_STACK_DEFAULT_FLAGS \
6368 (is_32bit_task() ? \
6369 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6370+#endif
6371
6372 #include <asm-generic/getorder.h>
6373
6374diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6375index b66ae72..4a378cd 100644
6376--- a/arch/powerpc/include/asm/pgalloc-64.h
6377+++ b/arch/powerpc/include/asm/pgalloc-64.h
6378@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6379 #ifndef CONFIG_PPC_64K_PAGES
6380
6381 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6382+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6383
6384 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6385 {
6386@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6387 pud_set(pud, (unsigned long)pmd);
6388 }
6389
6390+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6391+{
6392+ pud_populate(mm, pud, pmd);
6393+}
6394+
6395 #define pmd_populate(mm, pmd, pte_page) \
6396 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6397 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6398@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
6399 #endif
6400
6401 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6402+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6403
6404 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6405 pte_t *pte)
6406diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6407index 7aeb955..19f748e 100644
6408--- a/arch/powerpc/include/asm/pgtable.h
6409+++ b/arch/powerpc/include/asm/pgtable.h
6410@@ -2,6 +2,7 @@
6411 #define _ASM_POWERPC_PGTABLE_H
6412 #ifdef __KERNEL__
6413
6414+#include <linux/const.h>
6415 #ifndef __ASSEMBLY__
6416 #include <asm/processor.h> /* For TASK_SIZE */
6417 #include <asm/mmu.h>
6418diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6419index 4aad413..85d86bf 100644
6420--- a/arch/powerpc/include/asm/pte-hash32.h
6421+++ b/arch/powerpc/include/asm/pte-hash32.h
6422@@ -21,6 +21,7 @@
6423 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6424 #define _PAGE_USER 0x004 /* usermode access allowed */
6425 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6426+#define _PAGE_EXEC _PAGE_GUARDED
6427 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6428 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6429 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6430diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6431index 4a9e408..724aa59 100644
6432--- a/arch/powerpc/include/asm/reg.h
6433+++ b/arch/powerpc/include/asm/reg.h
6434@@ -234,6 +234,7 @@
6435 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6436 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6437 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6438+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6439 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6440 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6441 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6442diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6443index ffbaabe..eabe843 100644
6444--- a/arch/powerpc/include/asm/smp.h
6445+++ b/arch/powerpc/include/asm/smp.h
6446@@ -50,7 +50,7 @@ struct smp_ops_t {
6447 int (*cpu_disable)(void);
6448 void (*cpu_die)(unsigned int nr);
6449 int (*cpu_bootable)(unsigned int nr);
6450-};
6451+} __no_const;
6452
6453 extern void smp_send_debugger_break(void);
6454 extern void start_secondary_resume(void);
6455diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6456index ba7b197..d292e26 100644
6457--- a/arch/powerpc/include/asm/thread_info.h
6458+++ b/arch/powerpc/include/asm/thread_info.h
6459@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
6460 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
6461 TIF_NEED_RESCHED */
6462 #define TIF_32BIT 4 /* 32 bit binary */
6463-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
6464 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6465 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6466 #define TIF_SINGLESTEP 8 /* singlestepping active */
6467@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
6468 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6469 for stack store? */
6470 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6471+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
6472+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6473+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
6474
6475 /* as above, but as bit values */
6476 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6477@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
6478 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6479 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6480 #define _TIF_NOHZ (1<<TIF_NOHZ)
6481+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6482 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6483 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6484- _TIF_NOHZ)
6485+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
6486
6487 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6488 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6489diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6490index 4db4959..aba5c41 100644
6491--- a/arch/powerpc/include/asm/uaccess.h
6492+++ b/arch/powerpc/include/asm/uaccess.h
6493@@ -318,52 +318,6 @@ do { \
6494 extern unsigned long __copy_tofrom_user(void __user *to,
6495 const void __user *from, unsigned long size);
6496
6497-#ifndef __powerpc64__
6498-
6499-static inline unsigned long copy_from_user(void *to,
6500- const void __user *from, unsigned long n)
6501-{
6502- unsigned long over;
6503-
6504- if (access_ok(VERIFY_READ, from, n))
6505- return __copy_tofrom_user((__force void __user *)to, from, n);
6506- if ((unsigned long)from < TASK_SIZE) {
6507- over = (unsigned long)from + n - TASK_SIZE;
6508- return __copy_tofrom_user((__force void __user *)to, from,
6509- n - over) + over;
6510- }
6511- return n;
6512-}
6513-
6514-static inline unsigned long copy_to_user(void __user *to,
6515- const void *from, unsigned long n)
6516-{
6517- unsigned long over;
6518-
6519- if (access_ok(VERIFY_WRITE, to, n))
6520- return __copy_tofrom_user(to, (__force void __user *)from, n);
6521- if ((unsigned long)to < TASK_SIZE) {
6522- over = (unsigned long)to + n - TASK_SIZE;
6523- return __copy_tofrom_user(to, (__force void __user *)from,
6524- n - over) + over;
6525- }
6526- return n;
6527-}
6528-
6529-#else /* __powerpc64__ */
6530-
6531-#define __copy_in_user(to, from, size) \
6532- __copy_tofrom_user((to), (from), (size))
6533-
6534-extern unsigned long copy_from_user(void *to, const void __user *from,
6535- unsigned long n);
6536-extern unsigned long copy_to_user(void __user *to, const void *from,
6537- unsigned long n);
6538-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6539- unsigned long n);
6540-
6541-#endif /* __powerpc64__ */
6542-
6543 static inline unsigned long __copy_from_user_inatomic(void *to,
6544 const void __user *from, unsigned long n)
6545 {
6546@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6547 if (ret == 0)
6548 return 0;
6549 }
6550+
6551+ if (!__builtin_constant_p(n))
6552+ check_object_size(to, n, false);
6553+
6554 return __copy_tofrom_user((__force void __user *)to, from, n);
6555 }
6556
6557@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6558 if (ret == 0)
6559 return 0;
6560 }
6561+
6562+ if (!__builtin_constant_p(n))
6563+ check_object_size(from, n, true);
6564+
6565 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6566 }
6567
6568@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6569 return __copy_to_user_inatomic(to, from, size);
6570 }
6571
6572+#ifndef __powerpc64__
6573+
6574+static inline unsigned long __must_check copy_from_user(void *to,
6575+ const void __user *from, unsigned long n)
6576+{
6577+ unsigned long over;
6578+
6579+ if ((long)n < 0)
6580+ return n;
6581+
6582+ if (access_ok(VERIFY_READ, from, n)) {
6583+ if (!__builtin_constant_p(n))
6584+ check_object_size(to, n, false);
6585+ return __copy_tofrom_user((__force void __user *)to, from, n);
6586+ }
6587+ if ((unsigned long)from < TASK_SIZE) {
6588+ over = (unsigned long)from + n - TASK_SIZE;
6589+ if (!__builtin_constant_p(n - over))
6590+ check_object_size(to, n - over, false);
6591+ return __copy_tofrom_user((__force void __user *)to, from,
6592+ n - over) + over;
6593+ }
6594+ return n;
6595+}
6596+
6597+static inline unsigned long __must_check copy_to_user(void __user *to,
6598+ const void *from, unsigned long n)
6599+{
6600+ unsigned long over;
6601+
6602+ if ((long)n < 0)
6603+ return n;
6604+
6605+ if (access_ok(VERIFY_WRITE, to, n)) {
6606+ if (!__builtin_constant_p(n))
6607+ check_object_size(from, n, true);
6608+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6609+ }
6610+ if ((unsigned long)to < TASK_SIZE) {
6611+ over = (unsigned long)to + n - TASK_SIZE;
6612+ if (!__builtin_constant_p(n))
6613+ check_object_size(from, n - over, true);
6614+ return __copy_tofrom_user(to, (__force void __user *)from,
6615+ n - over) + over;
6616+ }
6617+ return n;
6618+}
6619+
6620+#else /* __powerpc64__ */
6621+
6622+#define __copy_in_user(to, from, size) \
6623+ __copy_tofrom_user((to), (from), (size))
6624+
6625+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6626+{
6627+ if ((long)n < 0 || n > INT_MAX)
6628+ return n;
6629+
6630+ if (!__builtin_constant_p(n))
6631+ check_object_size(to, n, false);
6632+
6633+ if (likely(access_ok(VERIFY_READ, from, n)))
6634+ n = __copy_from_user(to, from, n);
6635+ else
6636+ memset(to, 0, n);
6637+ return n;
6638+}
6639+
6640+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6641+{
6642+ if ((long)n < 0 || n > INT_MAX)
6643+ return n;
6644+
6645+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6646+ if (!__builtin_constant_p(n))
6647+ check_object_size(from, n, true);
6648+ n = __copy_to_user(to, from, n);
6649+ }
6650+ return n;
6651+}
6652+
6653+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6654+ unsigned long n);
6655+
6656+#endif /* __powerpc64__ */
6657+
6658 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6659
6660 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6661diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6662index 645170a..6cf0271 100644
6663--- a/arch/powerpc/kernel/exceptions-64e.S
6664+++ b/arch/powerpc/kernel/exceptions-64e.S
6665@@ -757,6 +757,7 @@ storage_fault_common:
6666 std r14,_DAR(r1)
6667 std r15,_DSISR(r1)
6668 addi r3,r1,STACK_FRAME_OVERHEAD
6669+ bl .save_nvgprs
6670 mr r4,r14
6671 mr r5,r15
6672 ld r14,PACA_EXGEN+EX_R14(r13)
6673@@ -765,8 +766,7 @@ storage_fault_common:
6674 cmpdi r3,0
6675 bne- 1f
6676 b .ret_from_except_lite
6677-1: bl .save_nvgprs
6678- mr r5,r3
6679+1: mr r5,r3
6680 addi r3,r1,STACK_FRAME_OVERHEAD
6681 ld r4,_DAR(r1)
6682 bl .bad_page_fault
6683diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6684index 40e4a17..5a84b37 100644
6685--- a/arch/powerpc/kernel/exceptions-64s.S
6686+++ b/arch/powerpc/kernel/exceptions-64s.S
6687@@ -1362,10 +1362,10 @@ handle_page_fault:
6688 11: ld r4,_DAR(r1)
6689 ld r5,_DSISR(r1)
6690 addi r3,r1,STACK_FRAME_OVERHEAD
6691+ bl .save_nvgprs
6692 bl .do_page_fault
6693 cmpdi r3,0
6694 beq+ 12f
6695- bl .save_nvgprs
6696 mr r5,r3
6697 addi r3,r1,STACK_FRAME_OVERHEAD
6698 lwz r4,_DAR(r1)
6699diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6700index 2e3200c..72095ce 100644
6701--- a/arch/powerpc/kernel/module_32.c
6702+++ b/arch/powerpc/kernel/module_32.c
6703@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6704 me->arch.core_plt_section = i;
6705 }
6706 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6707- printk("Module doesn't contain .plt or .init.plt sections.\n");
6708+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6709 return -ENOEXEC;
6710 }
6711
6712@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6713
6714 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6715 /* Init, or core PLT? */
6716- if (location >= mod->module_core
6717- && location < mod->module_core + mod->core_size)
6718+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6719+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6720 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6721- else
6722+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6723+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6724 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6725+ else {
6726+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6727+ return ~0UL;
6728+ }
6729
6730 /* Find this entry, or if that fails, the next avail. entry */
6731 while (entry->jump[0]) {
6732diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6733index 076d124..6cb2cbf 100644
6734--- a/arch/powerpc/kernel/process.c
6735+++ b/arch/powerpc/kernel/process.c
6736@@ -874,8 +874,8 @@ void show_regs(struct pt_regs * regs)
6737 * Lookup NIP late so we have the best change of getting the
6738 * above info out without failing
6739 */
6740- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6741- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6742+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6743+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6744 #endif
6745 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
6746 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
6747@@ -1335,10 +1335,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6748 newsp = stack[0];
6749 ip = stack[STACK_FRAME_LR_SAVE];
6750 if (!firstframe || ip != lr) {
6751- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6752+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6753 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6754 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6755- printk(" (%pS)",
6756+ printk(" (%pA)",
6757 (void *)current->ret_stack[curr_frame].ret);
6758 curr_frame--;
6759 }
6760@@ -1358,7 +1358,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6761 struct pt_regs *regs = (struct pt_regs *)
6762 (sp + STACK_FRAME_OVERHEAD);
6763 lr = regs->link;
6764- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6765+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6766 regs->trap, (void *)regs->nip, (void *)lr);
6767 firstframe = 1;
6768 }
6769@@ -1394,58 +1394,3 @@ void notrace __ppc64_runlatch_off(void)
6770 mtspr(SPRN_CTRLT, ctrl);
6771 }
6772 #endif /* CONFIG_PPC64 */
6773-
6774-unsigned long arch_align_stack(unsigned long sp)
6775-{
6776- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6777- sp -= get_random_int() & ~PAGE_MASK;
6778- return sp & ~0xf;
6779-}
6780-
6781-static inline unsigned long brk_rnd(void)
6782-{
6783- unsigned long rnd = 0;
6784-
6785- /* 8MB for 32bit, 1GB for 64bit */
6786- if (is_32bit_task())
6787- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6788- else
6789- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6790-
6791- return rnd << PAGE_SHIFT;
6792-}
6793-
6794-unsigned long arch_randomize_brk(struct mm_struct *mm)
6795-{
6796- unsigned long base = mm->brk;
6797- unsigned long ret;
6798-
6799-#ifdef CONFIG_PPC_STD_MMU_64
6800- /*
6801- * If we are using 1TB segments and we are allowed to randomise
6802- * the heap, we can put it above 1TB so it is backed by a 1TB
6803- * segment. Otherwise the heap will be in the bottom 1TB
6804- * which always uses 256MB segments and this may result in a
6805- * performance penalty.
6806- */
6807- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6808- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6809-#endif
6810-
6811- ret = PAGE_ALIGN(base + brk_rnd());
6812-
6813- if (ret < mm->brk)
6814- return mm->brk;
6815-
6816- return ret;
6817-}
6818-
6819-unsigned long randomize_et_dyn(unsigned long base)
6820-{
6821- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6822-
6823- if (ret < base)
6824- return base;
6825-
6826- return ret;
6827-}
6828diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6829index 98c2fc1..b73a4ca 100644
6830--- a/arch/powerpc/kernel/ptrace.c
6831+++ b/arch/powerpc/kernel/ptrace.c
6832@@ -1781,6 +1781,10 @@ long arch_ptrace(struct task_struct *child, long request,
6833 return ret;
6834 }
6835
6836+#ifdef CONFIG_GRKERNSEC_SETXID
6837+extern void gr_delayed_cred_worker(void);
6838+#endif
6839+
6840 /*
6841 * We must return the syscall number to actually look up in the table.
6842 * This can be -1L to skip running any syscall at all.
6843@@ -1793,6 +1797,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6844
6845 secure_computing_strict(regs->gpr[0]);
6846
6847+#ifdef CONFIG_GRKERNSEC_SETXID
6848+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6849+ gr_delayed_cred_worker();
6850+#endif
6851+
6852 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6853 tracehook_report_syscall_entry(regs))
6854 /*
6855@@ -1827,6 +1836,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6856 {
6857 int step;
6858
6859+#ifdef CONFIG_GRKERNSEC_SETXID
6860+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6861+ gr_delayed_cred_worker();
6862+#endif
6863+
6864 audit_syscall_exit(regs);
6865
6866 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6867diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6868index 201385c..0f01828 100644
6869--- a/arch/powerpc/kernel/signal_32.c
6870+++ b/arch/powerpc/kernel/signal_32.c
6871@@ -976,7 +976,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6872 /* Save user registers on the stack */
6873 frame = &rt_sf->uc.uc_mcontext;
6874 addr = frame;
6875- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6876+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6877 sigret = 0;
6878 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6879 } else {
6880diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6881index 3459473..2d40783 100644
6882--- a/arch/powerpc/kernel/signal_64.c
6883+++ b/arch/powerpc/kernel/signal_64.c
6884@@ -749,7 +749,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6885 #endif
6886
6887 /* Set up to return from userspace. */
6888- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6889+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6890 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6891 } else {
6892 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6893diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6894index e68a845..8b140e6 100644
6895--- a/arch/powerpc/kernel/sysfs.c
6896+++ b/arch/powerpc/kernel/sysfs.c
6897@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6898 return NOTIFY_OK;
6899 }
6900
6901-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6902+static struct notifier_block sysfs_cpu_nb = {
6903 .notifier_call = sysfs_cpu_notify,
6904 };
6905
6906diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6907index c0e5caf..68e8305 100644
6908--- a/arch/powerpc/kernel/traps.c
6909+++ b/arch/powerpc/kernel/traps.c
6910@@ -143,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6911 return flags;
6912 }
6913
6914+extern void gr_handle_kernel_exploit(void);
6915+
6916 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6917 int signr)
6918 {
6919@@ -192,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6920 panic("Fatal exception in interrupt");
6921 if (panic_on_oops)
6922 panic("Fatal exception");
6923+
6924+ gr_handle_kernel_exploit();
6925+
6926 do_exit(signr);
6927 }
6928
6929diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6930index d4f463a..8fb7431 100644
6931--- a/arch/powerpc/kernel/vdso.c
6932+++ b/arch/powerpc/kernel/vdso.c
6933@@ -34,6 +34,7 @@
6934 #include <asm/firmware.h>
6935 #include <asm/vdso.h>
6936 #include <asm/vdso_datapage.h>
6937+#include <asm/mman.h>
6938
6939 #include "setup.h"
6940
6941@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6942 vdso_base = VDSO32_MBASE;
6943 #endif
6944
6945- current->mm->context.vdso_base = 0;
6946+ current->mm->context.vdso_base = ~0UL;
6947
6948 /* vDSO has a problem and was disabled, just don't "enable" it for the
6949 * process
6950@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6951 vdso_base = get_unmapped_area(NULL, vdso_base,
6952 (vdso_pages << PAGE_SHIFT) +
6953 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6954- 0, 0);
6955+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6956 if (IS_ERR_VALUE(vdso_base)) {
6957 rc = vdso_base;
6958 goto fail_mmapsem;
6959diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6960index 5eea6f3..5d10396 100644
6961--- a/arch/powerpc/lib/usercopy_64.c
6962+++ b/arch/powerpc/lib/usercopy_64.c
6963@@ -9,22 +9,6 @@
6964 #include <linux/module.h>
6965 #include <asm/uaccess.h>
6966
6967-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6968-{
6969- if (likely(access_ok(VERIFY_READ, from, n)))
6970- n = __copy_from_user(to, from, n);
6971- else
6972- memset(to, 0, n);
6973- return n;
6974-}
6975-
6976-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6977-{
6978- if (likely(access_ok(VERIFY_WRITE, to, n)))
6979- n = __copy_to_user(to, from, n);
6980- return n;
6981-}
6982-
6983 unsigned long copy_in_user(void __user *to, const void __user *from,
6984 unsigned long n)
6985 {
6986@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6987 return n;
6988 }
6989
6990-EXPORT_SYMBOL(copy_from_user);
6991-EXPORT_SYMBOL(copy_to_user);
6992 EXPORT_SYMBOL(copy_in_user);
6993
6994diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6995index 8726779..a33c512 100644
6996--- a/arch/powerpc/mm/fault.c
6997+++ b/arch/powerpc/mm/fault.c
6998@@ -33,6 +33,10 @@
6999 #include <linux/magic.h>
7000 #include <linux/ratelimit.h>
7001 #include <linux/context_tracking.h>
7002+#include <linux/slab.h>
7003+#include <linux/pagemap.h>
7004+#include <linux/compiler.h>
7005+#include <linux/unistd.h>
7006
7007 #include <asm/firmware.h>
7008 #include <asm/page.h>
7009@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
7010 }
7011 #endif
7012
7013+#ifdef CONFIG_PAX_PAGEEXEC
7014+/*
7015+ * PaX: decide what to do with offenders (regs->nip = fault address)
7016+ *
7017+ * returns 1 when task should be killed
7018+ */
7019+static int pax_handle_fetch_fault(struct pt_regs *regs)
7020+{
7021+ return 1;
7022+}
7023+
7024+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7025+{
7026+ unsigned long i;
7027+
7028+ printk(KERN_ERR "PAX: bytes at PC: ");
7029+ for (i = 0; i < 5; i++) {
7030+ unsigned int c;
7031+ if (get_user(c, (unsigned int __user *)pc+i))
7032+ printk(KERN_CONT "???????? ");
7033+ else
7034+ printk(KERN_CONT "%08x ", c);
7035+ }
7036+ printk("\n");
7037+}
7038+#endif
7039+
7040 /*
7041 * Check whether the instruction at regs->nip is a store using
7042 * an update addressing form which will update r1.
7043@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
7044 * indicate errors in DSISR but can validly be set in SRR1.
7045 */
7046 if (trap == 0x400)
7047- error_code &= 0x48200000;
7048+ error_code &= 0x58200000;
7049 else
7050 is_write = error_code & DSISR_ISSTORE;
7051 #else
7052@@ -371,7 +402,7 @@ good_area:
7053 * "undefined". Of those that can be set, this is the only
7054 * one which seems bad.
7055 */
7056- if (error_code & 0x10000000)
7057+ if (error_code & DSISR_GUARDED)
7058 /* Guarded storage error. */
7059 goto bad_area;
7060 #endif /* CONFIG_8xx */
7061@@ -386,7 +417,7 @@ good_area:
7062 * processors use the same I/D cache coherency mechanism
7063 * as embedded.
7064 */
7065- if (error_code & DSISR_PROTFAULT)
7066+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
7067 goto bad_area;
7068 #endif /* CONFIG_PPC_STD_MMU */
7069
7070@@ -471,6 +502,23 @@ bad_area:
7071 bad_area_nosemaphore:
7072 /* User mode accesses cause a SIGSEGV */
7073 if (user_mode(regs)) {
7074+
7075+#ifdef CONFIG_PAX_PAGEEXEC
7076+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
7077+#ifdef CONFIG_PPC_STD_MMU
7078+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
7079+#else
7080+ if (is_exec && regs->nip == address) {
7081+#endif
7082+ switch (pax_handle_fetch_fault(regs)) {
7083+ }
7084+
7085+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7086+ do_group_exit(SIGKILL);
7087+ }
7088+ }
7089+#endif
7090+
7091 _exception(SIGSEGV, regs, code, address);
7092 goto bail;
7093 }
7094diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7095index 67a42ed..cd463e0 100644
7096--- a/arch/powerpc/mm/mmap_64.c
7097+++ b/arch/powerpc/mm/mmap_64.c
7098@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7099 {
7100 unsigned long rnd = 0;
7101
7102+#ifdef CONFIG_PAX_RANDMMAP
7103+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7104+#endif
7105+
7106 if (current->flags & PF_RANDOMIZE) {
7107 /* 8MB for 32bit, 1GB for 64bit */
7108 if (is_32bit_task())
7109@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7110 */
7111 if (mmap_is_legacy()) {
7112 mm->mmap_base = TASK_UNMAPPED_BASE;
7113+
7114+#ifdef CONFIG_PAX_RANDMMAP
7115+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7116+ mm->mmap_base += mm->delta_mmap;
7117+#endif
7118+
7119 mm->get_unmapped_area = arch_get_unmapped_area;
7120 mm->unmap_area = arch_unmap_area;
7121 } else {
7122 mm->mmap_base = mmap_base();
7123+
7124+#ifdef CONFIG_PAX_RANDMMAP
7125+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7126+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7127+#endif
7128+
7129 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7130 mm->unmap_area = arch_unmap_area_topdown;
7131 }
7132diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7133index e779642..e5bb889 100644
7134--- a/arch/powerpc/mm/mmu_context_nohash.c
7135+++ b/arch/powerpc/mm/mmu_context_nohash.c
7136@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7137 return NOTIFY_OK;
7138 }
7139
7140-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7141+static struct notifier_block mmu_context_cpu_nb = {
7142 .notifier_call = mmu_context_cpu_notify,
7143 };
7144
7145diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7146index 88c0425..717feb8 100644
7147--- a/arch/powerpc/mm/numa.c
7148+++ b/arch/powerpc/mm/numa.c
7149@@ -919,7 +919,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7150 return ret;
7151 }
7152
7153-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7154+static struct notifier_block ppc64_numa_nb = {
7155 .notifier_call = cpu_numa_callback,
7156 .priority = 1 /* Must run before sched domains notifier. */
7157 };
7158diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7159index 3e99c14..f00953c 100644
7160--- a/arch/powerpc/mm/slice.c
7161+++ b/arch/powerpc/mm/slice.c
7162@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7163 if ((mm->task_size - len) < addr)
7164 return 0;
7165 vma = find_vma(mm, addr);
7166- return (!vma || (addr + len) <= vma->vm_start);
7167+ return check_heap_stack_gap(vma, addr, len, 0);
7168 }
7169
7170 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7171@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
7172 info.align_offset = 0;
7173
7174 addr = TASK_UNMAPPED_BASE;
7175+
7176+#ifdef CONFIG_PAX_RANDMMAP
7177+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7178+ addr += mm->delta_mmap;
7179+#endif
7180+
7181 while (addr < TASK_SIZE) {
7182 info.low_limit = addr;
7183 if (!slice_scan_available(addr, available, 1, &addr))
7184@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7185 if (fixed && addr > (mm->task_size - len))
7186 return -EINVAL;
7187
7188+#ifdef CONFIG_PAX_RANDMMAP
7189+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7190+ addr = 0;
7191+#endif
7192+
7193 /* If hint, make sure it matches our alignment restrictions */
7194 if (!fixed && addr) {
7195 addr = _ALIGN_UP(addr, 1ul << pshift);
7196diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7197index 9098692..3d54cd1 100644
7198--- a/arch/powerpc/platforms/cell/spufs/file.c
7199+++ b/arch/powerpc/platforms/cell/spufs/file.c
7200@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7201 return VM_FAULT_NOPAGE;
7202 }
7203
7204-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7205+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7206 unsigned long address,
7207- void *buf, int len, int write)
7208+ void *buf, size_t len, int write)
7209 {
7210 struct spu_context *ctx = vma->vm_file->private_data;
7211 unsigned long offset = address - vma->vm_start;
7212diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7213index bdb738a..49c9f95 100644
7214--- a/arch/powerpc/platforms/powermac/smp.c
7215+++ b/arch/powerpc/platforms/powermac/smp.c
7216@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7217 return NOTIFY_OK;
7218 }
7219
7220-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7221+static struct notifier_block smp_core99_cpu_nb = {
7222 .notifier_call = smp_core99_cpu_notify,
7223 };
7224 #endif /* CONFIG_HOTPLUG_CPU */
7225diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7226index c797832..ce575c8 100644
7227--- a/arch/s390/include/asm/atomic.h
7228+++ b/arch/s390/include/asm/atomic.h
7229@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7230 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7231 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7232
7233+#define atomic64_read_unchecked(v) atomic64_read(v)
7234+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7235+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7236+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7237+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7238+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7239+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7240+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7241+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7242+
7243 #define smp_mb__before_atomic_dec() smp_mb()
7244 #define smp_mb__after_atomic_dec() smp_mb()
7245 #define smp_mb__before_atomic_inc() smp_mb()
7246diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7247index 4d7ccac..d03d0ad 100644
7248--- a/arch/s390/include/asm/cache.h
7249+++ b/arch/s390/include/asm/cache.h
7250@@ -9,8 +9,10 @@
7251 #ifndef __ARCH_S390_CACHE_H
7252 #define __ARCH_S390_CACHE_H
7253
7254-#define L1_CACHE_BYTES 256
7255+#include <linux/const.h>
7256+
7257 #define L1_CACHE_SHIFT 8
7258+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7259 #define NET_SKB_PAD 32
7260
7261 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7262diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7263index 78f4f87..598ce39 100644
7264--- a/arch/s390/include/asm/elf.h
7265+++ b/arch/s390/include/asm/elf.h
7266@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
7267 the loader. We need to make sure that it is out of the way of the program
7268 that it will "exec", and that there is sufficient room for the brk. */
7269
7270-extern unsigned long randomize_et_dyn(unsigned long base);
7271-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7272+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7273+
7274+#ifdef CONFIG_PAX_ASLR
7275+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7276+
7277+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7278+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7279+#endif
7280
7281 /* This yields a mask that user programs can use to figure out what
7282 instruction set this CPU supports. */
7283@@ -222,9 +228,6 @@ struct linux_binprm;
7284 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7285 int arch_setup_additional_pages(struct linux_binprm *, int);
7286
7287-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7288-#define arch_randomize_brk arch_randomize_brk
7289-
7290 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7291
7292 #endif
7293diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7294index c4a93d6..4d2a9b4 100644
7295--- a/arch/s390/include/asm/exec.h
7296+++ b/arch/s390/include/asm/exec.h
7297@@ -7,6 +7,6 @@
7298 #ifndef __ASM_EXEC_H
7299 #define __ASM_EXEC_H
7300
7301-extern unsigned long arch_align_stack(unsigned long sp);
7302+#define arch_align_stack(x) ((x) & ~0xfUL)
7303
7304 #endif /* __ASM_EXEC_H */
7305diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7306index 9c33ed4..e40cbef 100644
7307--- a/arch/s390/include/asm/uaccess.h
7308+++ b/arch/s390/include/asm/uaccess.h
7309@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7310 copy_to_user(void __user *to, const void *from, unsigned long n)
7311 {
7312 might_fault();
7313+
7314+ if ((long)n < 0)
7315+ return n;
7316+
7317 return __copy_to_user(to, from, n);
7318 }
7319
7320@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7321 static inline unsigned long __must_check
7322 __copy_from_user(void *to, const void __user *from, unsigned long n)
7323 {
7324+ if ((long)n < 0)
7325+ return n;
7326+
7327 if (__builtin_constant_p(n) && (n <= 256))
7328 return uaccess.copy_from_user_small(n, from, to);
7329 else
7330@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7331 static inline unsigned long __must_check
7332 copy_from_user(void *to, const void __user *from, unsigned long n)
7333 {
7334- unsigned int sz = __compiletime_object_size(to);
7335+ size_t sz = __compiletime_object_size(to);
7336
7337 might_fault();
7338- if (unlikely(sz != -1 && sz < n)) {
7339+
7340+ if ((long)n < 0)
7341+ return n;
7342+
7343+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7344 copy_from_user_overflow();
7345 return n;
7346 }
7347diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7348index 7845e15..59c4353 100644
7349--- a/arch/s390/kernel/module.c
7350+++ b/arch/s390/kernel/module.c
7351@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7352
7353 /* Increase core size by size of got & plt and set start
7354 offsets for got and plt. */
7355- me->core_size = ALIGN(me->core_size, 4);
7356- me->arch.got_offset = me->core_size;
7357- me->core_size += me->arch.got_size;
7358- me->arch.plt_offset = me->core_size;
7359- me->core_size += me->arch.plt_size;
7360+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7361+ me->arch.got_offset = me->core_size_rw;
7362+ me->core_size_rw += me->arch.got_size;
7363+ me->arch.plt_offset = me->core_size_rx;
7364+ me->core_size_rx += me->arch.plt_size;
7365 return 0;
7366 }
7367
7368@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7369 if (info->got_initialized == 0) {
7370 Elf_Addr *gotent;
7371
7372- gotent = me->module_core + me->arch.got_offset +
7373+ gotent = me->module_core_rw + me->arch.got_offset +
7374 info->got_offset;
7375 *gotent = val;
7376 info->got_initialized = 1;
7377@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7378 rc = apply_rela_bits(loc, val, 0, 64, 0);
7379 else if (r_type == R_390_GOTENT ||
7380 r_type == R_390_GOTPLTENT) {
7381- val += (Elf_Addr) me->module_core - loc;
7382+ val += (Elf_Addr) me->module_core_rw - loc;
7383 rc = apply_rela_bits(loc, val, 1, 32, 1);
7384 }
7385 break;
7386@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7387 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7388 if (info->plt_initialized == 0) {
7389 unsigned int *ip;
7390- ip = me->module_core + me->arch.plt_offset +
7391+ ip = me->module_core_rx + me->arch.plt_offset +
7392 info->plt_offset;
7393 #ifndef CONFIG_64BIT
7394 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7395@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7396 val - loc + 0xffffUL < 0x1ffffeUL) ||
7397 (r_type == R_390_PLT32DBL &&
7398 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7399- val = (Elf_Addr) me->module_core +
7400+ val = (Elf_Addr) me->module_core_rx +
7401 me->arch.plt_offset +
7402 info->plt_offset;
7403 val += rela->r_addend - loc;
7404@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7405 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7406 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7407 val = val + rela->r_addend -
7408- ((Elf_Addr) me->module_core + me->arch.got_offset);
7409+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7410 if (r_type == R_390_GOTOFF16)
7411 rc = apply_rela_bits(loc, val, 0, 16, 0);
7412 else if (r_type == R_390_GOTOFF32)
7413@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7414 break;
7415 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7416 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7417- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7418+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7419 rela->r_addend - loc;
7420 if (r_type == R_390_GOTPC)
7421 rc = apply_rela_bits(loc, val, 1, 32, 0);
7422diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7423index 2bc3edd..ab9d598 100644
7424--- a/arch/s390/kernel/process.c
7425+++ b/arch/s390/kernel/process.c
7426@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
7427 }
7428 return 0;
7429 }
7430-
7431-unsigned long arch_align_stack(unsigned long sp)
7432-{
7433- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7434- sp -= get_random_int() & ~PAGE_MASK;
7435- return sp & ~0xf;
7436-}
7437-
7438-static inline unsigned long brk_rnd(void)
7439-{
7440- /* 8MB for 32bit, 1GB for 64bit */
7441- if (is_32bit_task())
7442- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7443- else
7444- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7445-}
7446-
7447-unsigned long arch_randomize_brk(struct mm_struct *mm)
7448-{
7449- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7450-
7451- if (ret < mm->brk)
7452- return mm->brk;
7453- return ret;
7454-}
7455-
7456-unsigned long randomize_et_dyn(unsigned long base)
7457-{
7458- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7459-
7460- if (!(current->flags & PF_RANDOMIZE))
7461- return base;
7462- if (ret < base)
7463- return base;
7464- return ret;
7465-}
7466diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7467index 06bafec..2bca531 100644
7468--- a/arch/s390/mm/mmap.c
7469+++ b/arch/s390/mm/mmap.c
7470@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7471 */
7472 if (mmap_is_legacy()) {
7473 mm->mmap_base = TASK_UNMAPPED_BASE;
7474+
7475+#ifdef CONFIG_PAX_RANDMMAP
7476+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7477+ mm->mmap_base += mm->delta_mmap;
7478+#endif
7479+
7480 mm->get_unmapped_area = arch_get_unmapped_area;
7481 mm->unmap_area = arch_unmap_area;
7482 } else {
7483 mm->mmap_base = mmap_base();
7484+
7485+#ifdef CONFIG_PAX_RANDMMAP
7486+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7487+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7488+#endif
7489+
7490 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7491 mm->unmap_area = arch_unmap_area_topdown;
7492 }
7493@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7494 */
7495 if (mmap_is_legacy()) {
7496 mm->mmap_base = TASK_UNMAPPED_BASE;
7497+
7498+#ifdef CONFIG_PAX_RANDMMAP
7499+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7500+ mm->mmap_base += mm->delta_mmap;
7501+#endif
7502+
7503 mm->get_unmapped_area = s390_get_unmapped_area;
7504 mm->unmap_area = arch_unmap_area;
7505 } else {
7506 mm->mmap_base = mmap_base();
7507+
7508+#ifdef CONFIG_PAX_RANDMMAP
7509+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7510+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7511+#endif
7512+
7513 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7514 mm->unmap_area = arch_unmap_area_topdown;
7515 }
7516diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7517index ae3d59f..f65f075 100644
7518--- a/arch/score/include/asm/cache.h
7519+++ b/arch/score/include/asm/cache.h
7520@@ -1,7 +1,9 @@
7521 #ifndef _ASM_SCORE_CACHE_H
7522 #define _ASM_SCORE_CACHE_H
7523
7524+#include <linux/const.h>
7525+
7526 #define L1_CACHE_SHIFT 4
7527-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7528+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7529
7530 #endif /* _ASM_SCORE_CACHE_H */
7531diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7532index f9f3cd5..58ff438 100644
7533--- a/arch/score/include/asm/exec.h
7534+++ b/arch/score/include/asm/exec.h
7535@@ -1,6 +1,6 @@
7536 #ifndef _ASM_SCORE_EXEC_H
7537 #define _ASM_SCORE_EXEC_H
7538
7539-extern unsigned long arch_align_stack(unsigned long sp);
7540+#define arch_align_stack(x) (x)
7541
7542 #endif /* _ASM_SCORE_EXEC_H */
7543diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7544index f4c6d02..e9355c3 100644
7545--- a/arch/score/kernel/process.c
7546+++ b/arch/score/kernel/process.c
7547@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
7548
7549 return task_pt_regs(task)->cp0_epc;
7550 }
7551-
7552-unsigned long arch_align_stack(unsigned long sp)
7553-{
7554- return sp;
7555-}
7556diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7557index ef9e555..331bd29 100644
7558--- a/arch/sh/include/asm/cache.h
7559+++ b/arch/sh/include/asm/cache.h
7560@@ -9,10 +9,11 @@
7561 #define __ASM_SH_CACHE_H
7562 #ifdef __KERNEL__
7563
7564+#include <linux/const.h>
7565 #include <linux/init.h>
7566 #include <cpu/cache.h>
7567
7568-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7569+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7570
7571 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7572
7573diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7574index 03f2b55..b0270327 100644
7575--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7576+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7577@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7578 return NOTIFY_OK;
7579 }
7580
7581-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7582+static struct notifier_block shx3_cpu_notifier = {
7583 .notifier_call = shx3_cpu_callback,
7584 };
7585
7586diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7587index 6777177..cb5e44f 100644
7588--- a/arch/sh/mm/mmap.c
7589+++ b/arch/sh/mm/mmap.c
7590@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7591 struct mm_struct *mm = current->mm;
7592 struct vm_area_struct *vma;
7593 int do_colour_align;
7594+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7595 struct vm_unmapped_area_info info;
7596
7597 if (flags & MAP_FIXED) {
7598@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7599 if (filp || (flags & MAP_SHARED))
7600 do_colour_align = 1;
7601
7602+#ifdef CONFIG_PAX_RANDMMAP
7603+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7604+#endif
7605+
7606 if (addr) {
7607 if (do_colour_align)
7608 addr = COLOUR_ALIGN(addr, pgoff);
7609@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7610 addr = PAGE_ALIGN(addr);
7611
7612 vma = find_vma(mm, addr);
7613- if (TASK_SIZE - len >= addr &&
7614- (!vma || addr + len <= vma->vm_start))
7615+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7616 return addr;
7617 }
7618
7619 info.flags = 0;
7620 info.length = len;
7621- info.low_limit = TASK_UNMAPPED_BASE;
7622+ info.low_limit = mm->mmap_base;
7623 info.high_limit = TASK_SIZE;
7624 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7625 info.align_offset = pgoff << PAGE_SHIFT;
7626@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7627 struct mm_struct *mm = current->mm;
7628 unsigned long addr = addr0;
7629 int do_colour_align;
7630+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7631 struct vm_unmapped_area_info info;
7632
7633 if (flags & MAP_FIXED) {
7634@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7635 if (filp || (flags & MAP_SHARED))
7636 do_colour_align = 1;
7637
7638+#ifdef CONFIG_PAX_RANDMMAP
7639+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7640+#endif
7641+
7642 /* requesting a specific address */
7643 if (addr) {
7644 if (do_colour_align)
7645@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7646 addr = PAGE_ALIGN(addr);
7647
7648 vma = find_vma(mm, addr);
7649- if (TASK_SIZE - len >= addr &&
7650- (!vma || addr + len <= vma->vm_start))
7651+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7652 return addr;
7653 }
7654
7655@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7656 VM_BUG_ON(addr != -ENOMEM);
7657 info.flags = 0;
7658 info.low_limit = TASK_UNMAPPED_BASE;
7659+
7660+#ifdef CONFIG_PAX_RANDMMAP
7661+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7662+ info.low_limit += mm->delta_mmap;
7663+#endif
7664+
7665 info.high_limit = TASK_SIZE;
7666 addr = vm_unmapped_area(&info);
7667 }
7668diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7669index be56a24..443328f 100644
7670--- a/arch/sparc/include/asm/atomic_64.h
7671+++ b/arch/sparc/include/asm/atomic_64.h
7672@@ -14,18 +14,40 @@
7673 #define ATOMIC64_INIT(i) { (i) }
7674
7675 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7676+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7677+{
7678+ return v->counter;
7679+}
7680 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7681+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7682+{
7683+ return v->counter;
7684+}
7685
7686 #define atomic_set(v, i) (((v)->counter) = i)
7687+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7688+{
7689+ v->counter = i;
7690+}
7691 #define atomic64_set(v, i) (((v)->counter) = i)
7692+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7693+{
7694+ v->counter = i;
7695+}
7696
7697 extern void atomic_add(int, atomic_t *);
7698+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7699 extern void atomic64_add(long, atomic64_t *);
7700+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7701 extern void atomic_sub(int, atomic_t *);
7702+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7703 extern void atomic64_sub(long, atomic64_t *);
7704+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7705
7706 extern int atomic_add_ret(int, atomic_t *);
7707+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7708 extern long atomic64_add_ret(long, atomic64_t *);
7709+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7710 extern int atomic_sub_ret(int, atomic_t *);
7711 extern long atomic64_sub_ret(long, atomic64_t *);
7712
7713@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7714 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7715
7716 #define atomic_inc_return(v) atomic_add_ret(1, v)
7717+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7718+{
7719+ return atomic_add_ret_unchecked(1, v);
7720+}
7721 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7722+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7723+{
7724+ return atomic64_add_ret_unchecked(1, v);
7725+}
7726
7727 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7728 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7729
7730 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7731+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7732+{
7733+ return atomic_add_ret_unchecked(i, v);
7734+}
7735 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7736+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7737+{
7738+ return atomic64_add_ret_unchecked(i, v);
7739+}
7740
7741 /*
7742 * atomic_inc_and_test - increment and test
7743@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7744 * other cases.
7745 */
7746 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7747+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7748+{
7749+ return atomic_inc_return_unchecked(v) == 0;
7750+}
7751 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7752
7753 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7754@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7755 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7756
7757 #define atomic_inc(v) atomic_add(1, v)
7758+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7759+{
7760+ atomic_add_unchecked(1, v);
7761+}
7762 #define atomic64_inc(v) atomic64_add(1, v)
7763+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7764+{
7765+ atomic64_add_unchecked(1, v);
7766+}
7767
7768 #define atomic_dec(v) atomic_sub(1, v)
7769+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7770+{
7771+ atomic_sub_unchecked(1, v);
7772+}
7773 #define atomic64_dec(v) atomic64_sub(1, v)
7774+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7775+{
7776+ atomic64_sub_unchecked(1, v);
7777+}
7778
7779 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7780 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7781
7782 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7783+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7784+{
7785+ return cmpxchg(&v->counter, old, new);
7786+}
7787 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7788+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7789+{
7790+ return xchg(&v->counter, new);
7791+}
7792
7793 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7794 {
7795- int c, old;
7796+ int c, old, new;
7797 c = atomic_read(v);
7798 for (;;) {
7799- if (unlikely(c == (u)))
7800+ if (unlikely(c == u))
7801 break;
7802- old = atomic_cmpxchg((v), c, c + (a));
7803+
7804+ asm volatile("addcc %2, %0, %0\n"
7805+
7806+#ifdef CONFIG_PAX_REFCOUNT
7807+ "tvs %%icc, 6\n"
7808+#endif
7809+
7810+ : "=r" (new)
7811+ : "0" (c), "ir" (a)
7812+ : "cc");
7813+
7814+ old = atomic_cmpxchg(v, c, new);
7815 if (likely(old == c))
7816 break;
7817 c = old;
7818@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7819 #define atomic64_cmpxchg(v, o, n) \
7820 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7821 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7822+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7823+{
7824+ return xchg(&v->counter, new);
7825+}
7826
7827 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7828 {
7829- long c, old;
7830+ long c, old, new;
7831 c = atomic64_read(v);
7832 for (;;) {
7833- if (unlikely(c == (u)))
7834+ if (unlikely(c == u))
7835 break;
7836- old = atomic64_cmpxchg((v), c, c + (a));
7837+
7838+ asm volatile("addcc %2, %0, %0\n"
7839+
7840+#ifdef CONFIG_PAX_REFCOUNT
7841+ "tvs %%xcc, 6\n"
7842+#endif
7843+
7844+ : "=r" (new)
7845+ : "0" (c), "ir" (a)
7846+ : "cc");
7847+
7848+ old = atomic64_cmpxchg(v, c, new);
7849 if (likely(old == c))
7850 break;
7851 c = old;
7852 }
7853- return c != (u);
7854+ return c != u;
7855 }
7856
7857 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7858diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7859index 5bb6991..5c2132e 100644
7860--- a/arch/sparc/include/asm/cache.h
7861+++ b/arch/sparc/include/asm/cache.h
7862@@ -7,10 +7,12 @@
7863 #ifndef _SPARC_CACHE_H
7864 #define _SPARC_CACHE_H
7865
7866+#include <linux/const.h>
7867+
7868 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7869
7870 #define L1_CACHE_SHIFT 5
7871-#define L1_CACHE_BYTES 32
7872+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7873
7874 #ifdef CONFIG_SPARC32
7875 #define SMP_CACHE_BYTES_SHIFT 5
7876diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7877index a24e41f..47677ff 100644
7878--- a/arch/sparc/include/asm/elf_32.h
7879+++ b/arch/sparc/include/asm/elf_32.h
7880@@ -114,6 +114,13 @@ typedef struct {
7881
7882 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7883
7884+#ifdef CONFIG_PAX_ASLR
7885+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7886+
7887+#define PAX_DELTA_MMAP_LEN 16
7888+#define PAX_DELTA_STACK_LEN 16
7889+#endif
7890+
7891 /* This yields a mask that user programs can use to figure out what
7892 instruction set this cpu supports. This can NOT be done in userspace
7893 on Sparc. */
7894diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7895index 370ca1e..d4f4a98 100644
7896--- a/arch/sparc/include/asm/elf_64.h
7897+++ b/arch/sparc/include/asm/elf_64.h
7898@@ -189,6 +189,13 @@ typedef struct {
7899 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7900 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7901
7902+#ifdef CONFIG_PAX_ASLR
7903+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7904+
7905+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7906+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7907+#endif
7908+
7909 extern unsigned long sparc64_elf_hwcap;
7910 #define ELF_HWCAP sparc64_elf_hwcap
7911
7912diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7913index 9b1c36d..209298b 100644
7914--- a/arch/sparc/include/asm/pgalloc_32.h
7915+++ b/arch/sparc/include/asm/pgalloc_32.h
7916@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7917 }
7918
7919 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7920+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7921
7922 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7923 unsigned long address)
7924diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7925index bcfe063..b333142 100644
7926--- a/arch/sparc/include/asm/pgalloc_64.h
7927+++ b/arch/sparc/include/asm/pgalloc_64.h
7928@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7929 }
7930
7931 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7932+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7933
7934 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7935 {
7936diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7937index 6fc1348..390c50a 100644
7938--- a/arch/sparc/include/asm/pgtable_32.h
7939+++ b/arch/sparc/include/asm/pgtable_32.h
7940@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7941 #define PAGE_SHARED SRMMU_PAGE_SHARED
7942 #define PAGE_COPY SRMMU_PAGE_COPY
7943 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7944+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7945+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7946+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7947 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7948
7949 /* Top-level page directory - dummy used by init-mm.
7950@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7951
7952 /* xwr */
7953 #define __P000 PAGE_NONE
7954-#define __P001 PAGE_READONLY
7955-#define __P010 PAGE_COPY
7956-#define __P011 PAGE_COPY
7957+#define __P001 PAGE_READONLY_NOEXEC
7958+#define __P010 PAGE_COPY_NOEXEC
7959+#define __P011 PAGE_COPY_NOEXEC
7960 #define __P100 PAGE_READONLY
7961 #define __P101 PAGE_READONLY
7962 #define __P110 PAGE_COPY
7963 #define __P111 PAGE_COPY
7964
7965 #define __S000 PAGE_NONE
7966-#define __S001 PAGE_READONLY
7967-#define __S010 PAGE_SHARED
7968-#define __S011 PAGE_SHARED
7969+#define __S001 PAGE_READONLY_NOEXEC
7970+#define __S010 PAGE_SHARED_NOEXEC
7971+#define __S011 PAGE_SHARED_NOEXEC
7972 #define __S100 PAGE_READONLY
7973 #define __S101 PAGE_READONLY
7974 #define __S110 PAGE_SHARED
7975diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7976index 79da178..c2eede8 100644
7977--- a/arch/sparc/include/asm/pgtsrmmu.h
7978+++ b/arch/sparc/include/asm/pgtsrmmu.h
7979@@ -115,6 +115,11 @@
7980 SRMMU_EXEC | SRMMU_REF)
7981 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7982 SRMMU_EXEC | SRMMU_REF)
7983+
7984+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7985+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7986+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7987+
7988 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7989 SRMMU_DIRTY | SRMMU_REF)
7990
7991diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7992index 9689176..63c18ea 100644
7993--- a/arch/sparc/include/asm/spinlock_64.h
7994+++ b/arch/sparc/include/asm/spinlock_64.h
7995@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7996
7997 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7998
7999-static void inline arch_read_lock(arch_rwlock_t *lock)
8000+static inline void arch_read_lock(arch_rwlock_t *lock)
8001 {
8002 unsigned long tmp1, tmp2;
8003
8004 __asm__ __volatile__ (
8005 "1: ldsw [%2], %0\n"
8006 " brlz,pn %0, 2f\n"
8007-"4: add %0, 1, %1\n"
8008+"4: addcc %0, 1, %1\n"
8009+
8010+#ifdef CONFIG_PAX_REFCOUNT
8011+" tvs %%icc, 6\n"
8012+#endif
8013+
8014 " cas [%2], %0, %1\n"
8015 " cmp %0, %1\n"
8016 " bne,pn %%icc, 1b\n"
8017@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
8018 " .previous"
8019 : "=&r" (tmp1), "=&r" (tmp2)
8020 : "r" (lock)
8021- : "memory");
8022+ : "memory", "cc");
8023 }
8024
8025-static int inline arch_read_trylock(arch_rwlock_t *lock)
8026+static inline int arch_read_trylock(arch_rwlock_t *lock)
8027 {
8028 int tmp1, tmp2;
8029
8030@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8031 "1: ldsw [%2], %0\n"
8032 " brlz,a,pn %0, 2f\n"
8033 " mov 0, %0\n"
8034-" add %0, 1, %1\n"
8035+" addcc %0, 1, %1\n"
8036+
8037+#ifdef CONFIG_PAX_REFCOUNT
8038+" tvs %%icc, 6\n"
8039+#endif
8040+
8041 " cas [%2], %0, %1\n"
8042 " cmp %0, %1\n"
8043 " bne,pn %%icc, 1b\n"
8044@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
8045 return tmp1;
8046 }
8047
8048-static void inline arch_read_unlock(arch_rwlock_t *lock)
8049+static inline void arch_read_unlock(arch_rwlock_t *lock)
8050 {
8051 unsigned long tmp1, tmp2;
8052
8053 __asm__ __volatile__(
8054 "1: lduw [%2], %0\n"
8055-" sub %0, 1, %1\n"
8056+" subcc %0, 1, %1\n"
8057+
8058+#ifdef CONFIG_PAX_REFCOUNT
8059+" tvs %%icc, 6\n"
8060+#endif
8061+
8062 " cas [%2], %0, %1\n"
8063 " cmp %0, %1\n"
8064 " bne,pn %%xcc, 1b\n"
8065@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8066 : "memory");
8067 }
8068
8069-static void inline arch_write_lock(arch_rwlock_t *lock)
8070+static inline void arch_write_lock(arch_rwlock_t *lock)
8071 {
8072 unsigned long mask, tmp1, tmp2;
8073
8074@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8075 : "memory");
8076 }
8077
8078-static void inline arch_write_unlock(arch_rwlock_t *lock)
8079+static inline void arch_write_unlock(arch_rwlock_t *lock)
8080 {
8081 __asm__ __volatile__(
8082 " stw %%g0, [%0]"
8083@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8084 : "memory");
8085 }
8086
8087-static int inline arch_write_trylock(arch_rwlock_t *lock)
8088+static inline int arch_write_trylock(arch_rwlock_t *lock)
8089 {
8090 unsigned long mask, tmp1, tmp2, result;
8091
8092diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8093index dd38075..e7cac83 100644
8094--- a/arch/sparc/include/asm/thread_info_32.h
8095+++ b/arch/sparc/include/asm/thread_info_32.h
8096@@ -49,6 +49,8 @@ struct thread_info {
8097 unsigned long w_saved;
8098
8099 struct restart_block restart_block;
8100+
8101+ unsigned long lowest_stack;
8102 };
8103
8104 /*
8105diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8106index d5e5042..9bfee76 100644
8107--- a/arch/sparc/include/asm/thread_info_64.h
8108+++ b/arch/sparc/include/asm/thread_info_64.h
8109@@ -63,6 +63,8 @@ struct thread_info {
8110 struct pt_regs *kern_una_regs;
8111 unsigned int kern_una_insn;
8112
8113+ unsigned long lowest_stack;
8114+
8115 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8116 };
8117
8118@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8119 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8120 /* flag bit 6 is available */
8121 #define TIF_32BIT 7 /* 32-bit binary */
8122-/* flag bit 8 is available */
8123+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8124 #define TIF_SECCOMP 9 /* secure computing */
8125 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8126 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8127+
8128 /* NOTE: Thread flags >= 12 should be ones we have no interest
8129 * in using in assembly, else we can't use the mask as
8130 * an immediate value in instructions such as andcc.
8131@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8132 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8133 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8134 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8135+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8136
8137 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8138 _TIF_DO_NOTIFY_RESUME_MASK | \
8139 _TIF_NEED_RESCHED)
8140 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8141
8142+#define _TIF_WORK_SYSCALL \
8143+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8144+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8145+
8146+
8147 /*
8148 * Thread-synchronous status.
8149 *
8150diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8151index 0167d26..767bb0c 100644
8152--- a/arch/sparc/include/asm/uaccess.h
8153+++ b/arch/sparc/include/asm/uaccess.h
8154@@ -1,5 +1,6 @@
8155 #ifndef ___ASM_SPARC_UACCESS_H
8156 #define ___ASM_SPARC_UACCESS_H
8157+
8158 #if defined(__sparc__) && defined(__arch64__)
8159 #include <asm/uaccess_64.h>
8160 #else
8161diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8162index 53a28dd..50c38c3 100644
8163--- a/arch/sparc/include/asm/uaccess_32.h
8164+++ b/arch/sparc/include/asm/uaccess_32.h
8165@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8166
8167 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8168 {
8169- if (n && __access_ok((unsigned long) to, n))
8170+ if ((long)n < 0)
8171+ return n;
8172+
8173+ if (n && __access_ok((unsigned long) to, n)) {
8174+ if (!__builtin_constant_p(n))
8175+ check_object_size(from, n, true);
8176 return __copy_user(to, (__force void __user *) from, n);
8177- else
8178+ } else
8179 return n;
8180 }
8181
8182 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8183 {
8184+ if ((long)n < 0)
8185+ return n;
8186+
8187+ if (!__builtin_constant_p(n))
8188+ check_object_size(from, n, true);
8189+
8190 return __copy_user(to, (__force void __user *) from, n);
8191 }
8192
8193 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8194 {
8195- if (n && __access_ok((unsigned long) from, n))
8196+ if ((long)n < 0)
8197+ return n;
8198+
8199+ if (n && __access_ok((unsigned long) from, n)) {
8200+ if (!__builtin_constant_p(n))
8201+ check_object_size(to, n, false);
8202 return __copy_user((__force void __user *) to, from, n);
8203- else
8204+ } else
8205 return n;
8206 }
8207
8208 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8209 {
8210+ if ((long)n < 0)
8211+ return n;
8212+
8213 return __copy_user((__force void __user *) to, from, n);
8214 }
8215
8216diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8217index e562d3c..191f176 100644
8218--- a/arch/sparc/include/asm/uaccess_64.h
8219+++ b/arch/sparc/include/asm/uaccess_64.h
8220@@ -10,6 +10,7 @@
8221 #include <linux/compiler.h>
8222 #include <linux/string.h>
8223 #include <linux/thread_info.h>
8224+#include <linux/kernel.h>
8225 #include <asm/asi.h>
8226 #include <asm/spitfire.h>
8227 #include <asm-generic/uaccess-unaligned.h>
8228@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8229 static inline unsigned long __must_check
8230 copy_from_user(void *to, const void __user *from, unsigned long size)
8231 {
8232- unsigned long ret = ___copy_from_user(to, from, size);
8233+ unsigned long ret;
8234
8235+ if ((long)size < 0 || size > INT_MAX)
8236+ return size;
8237+
8238+ if (!__builtin_constant_p(size))
8239+ check_object_size(to, size, false);
8240+
8241+ ret = ___copy_from_user(to, from, size);
8242 if (unlikely(ret))
8243 ret = copy_from_user_fixup(to, from, size);
8244
8245@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8246 static inline unsigned long __must_check
8247 copy_to_user(void __user *to, const void *from, unsigned long size)
8248 {
8249- unsigned long ret = ___copy_to_user(to, from, size);
8250+ unsigned long ret;
8251
8252+ if ((long)size < 0 || size > INT_MAX)
8253+ return size;
8254+
8255+ if (!__builtin_constant_p(size))
8256+ check_object_size(from, size, true);
8257+
8258+ ret = ___copy_to_user(to, from, size);
8259 if (unlikely(ret))
8260 ret = copy_to_user_fixup(to, from, size);
8261 return ret;
8262diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8263index d432fb2..6056af1 100644
8264--- a/arch/sparc/kernel/Makefile
8265+++ b/arch/sparc/kernel/Makefile
8266@@ -3,7 +3,7 @@
8267 #
8268
8269 asflags-y := -ansi
8270-ccflags-y := -Werror
8271+#ccflags-y := -Werror
8272
8273 extra-y := head_$(BITS).o
8274
8275diff --git a/arch/sparc/kernel/ds.c b/arch/sparc/kernel/ds.c
8276index 5ef48da..11d460f 100644
8277--- a/arch/sparc/kernel/ds.c
8278+++ b/arch/sparc/kernel/ds.c
8279@@ -783,6 +783,16 @@ void ldom_set_var(const char *var, const char *value)
8280 char *base, *p;
8281 int msg_len, loops;
8282
8283+ if (strlen(var) + strlen(value) + 2 >
8284+ sizeof(pkt) - sizeof(pkt.header)) {
8285+ printk(KERN_ERR PFX
8286+ "contents length: %zu, which more than max: %lu,"
8287+ "so could not set (%s) variable to (%s).\n",
8288+ strlen(var) + strlen(value) + 2,
8289+ sizeof(pkt) - sizeof(pkt.header), var, value);
8290+ return;
8291+ }
8292+
8293 memset(&pkt, 0, sizeof(pkt));
8294 pkt.header.data.tag.type = DS_DATA;
8295 pkt.header.data.handle = cp->handle;
8296diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8297index fdd819d..5af08c8 100644
8298--- a/arch/sparc/kernel/process_32.c
8299+++ b/arch/sparc/kernel/process_32.c
8300@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
8301
8302 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8303 r->psr, r->pc, r->npc, r->y, print_tainted());
8304- printk("PC: <%pS>\n", (void *) r->pc);
8305+ printk("PC: <%pA>\n", (void *) r->pc);
8306 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8307 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8308 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8309 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8310 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8311 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8312- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8313+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8314
8315 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8316 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8317@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8318 rw = (struct reg_window32 *) fp;
8319 pc = rw->ins[7];
8320 printk("[%08lx : ", pc);
8321- printk("%pS ] ", (void *) pc);
8322+ printk("%pA ] ", (void *) pc);
8323 fp = rw->ins[6];
8324 } while (++count < 16);
8325 printk("\n");
8326diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8327index baebab2..9cd13b1 100644
8328--- a/arch/sparc/kernel/process_64.c
8329+++ b/arch/sparc/kernel/process_64.c
8330@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
8331 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8332 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8333 if (regs->tstate & TSTATE_PRIV)
8334- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8335+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8336 }
8337
8338 void show_regs(struct pt_regs *regs)
8339@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
8340
8341 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8342 regs->tpc, regs->tnpc, regs->y, print_tainted());
8343- printk("TPC: <%pS>\n", (void *) regs->tpc);
8344+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8345 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8346 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8347 regs->u_regs[3]);
8348@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
8349 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8350 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8351 regs->u_regs[15]);
8352- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8353+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8354 show_regwindow(regs);
8355 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8356 }
8357@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
8358 ((tp && tp->task) ? tp->task->pid : -1));
8359
8360 if (gp->tstate & TSTATE_PRIV) {
8361- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8362+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8363 (void *) gp->tpc,
8364 (void *) gp->o7,
8365 (void *) gp->i7,
8366diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8367index 79cc0d1..ec62734 100644
8368--- a/arch/sparc/kernel/prom_common.c
8369+++ b/arch/sparc/kernel/prom_common.c
8370@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8371
8372 unsigned int prom_early_allocated __initdata;
8373
8374-static struct of_pdt_ops prom_sparc_ops __initdata = {
8375+static struct of_pdt_ops prom_sparc_ops __initconst = {
8376 .nextprop = prom_common_nextprop,
8377 .getproplen = prom_getproplen,
8378 .getproperty = prom_getproperty,
8379diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8380index 7ff45e4..a58f271 100644
8381--- a/arch/sparc/kernel/ptrace_64.c
8382+++ b/arch/sparc/kernel/ptrace_64.c
8383@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8384 return ret;
8385 }
8386
8387+#ifdef CONFIG_GRKERNSEC_SETXID
8388+extern void gr_delayed_cred_worker(void);
8389+#endif
8390+
8391 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8392 {
8393 int ret = 0;
8394@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8395 /* do the secure computing check first */
8396 secure_computing_strict(regs->u_regs[UREG_G1]);
8397
8398+#ifdef CONFIG_GRKERNSEC_SETXID
8399+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8400+ gr_delayed_cred_worker();
8401+#endif
8402+
8403 if (test_thread_flag(TIF_SYSCALL_TRACE))
8404 ret = tracehook_report_syscall_entry(regs);
8405
8406@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8407
8408 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8409 {
8410+#ifdef CONFIG_GRKERNSEC_SETXID
8411+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8412+ gr_delayed_cred_worker();
8413+#endif
8414+
8415 audit_syscall_exit(regs);
8416
8417 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8418diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8419index 3a8d184..49498a8 100644
8420--- a/arch/sparc/kernel/sys_sparc_32.c
8421+++ b/arch/sparc/kernel/sys_sparc_32.c
8422@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8423 if (len > TASK_SIZE - PAGE_SIZE)
8424 return -ENOMEM;
8425 if (!addr)
8426- addr = TASK_UNMAPPED_BASE;
8427+ addr = current->mm->mmap_base;
8428
8429 info.flags = 0;
8430 info.length = len;
8431diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8432index 2daaaa6..4fb84dc 100644
8433--- a/arch/sparc/kernel/sys_sparc_64.c
8434+++ b/arch/sparc/kernel/sys_sparc_64.c
8435@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8436 struct vm_area_struct * vma;
8437 unsigned long task_size = TASK_SIZE;
8438 int do_color_align;
8439+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8440 struct vm_unmapped_area_info info;
8441
8442 if (flags & MAP_FIXED) {
8443 /* We do not accept a shared mapping if it would violate
8444 * cache aliasing constraints.
8445 */
8446- if ((flags & MAP_SHARED) &&
8447+ if ((filp || (flags & MAP_SHARED)) &&
8448 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8449 return -EINVAL;
8450 return addr;
8451@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8452 if (filp || (flags & MAP_SHARED))
8453 do_color_align = 1;
8454
8455+#ifdef CONFIG_PAX_RANDMMAP
8456+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8457+#endif
8458+
8459 if (addr) {
8460 if (do_color_align)
8461 addr = COLOR_ALIGN(addr, pgoff);
8462@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8463 addr = PAGE_ALIGN(addr);
8464
8465 vma = find_vma(mm, addr);
8466- if (task_size - len >= addr &&
8467- (!vma || addr + len <= vma->vm_start))
8468+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8469 return addr;
8470 }
8471
8472 info.flags = 0;
8473 info.length = len;
8474- info.low_limit = TASK_UNMAPPED_BASE;
8475+ info.low_limit = mm->mmap_base;
8476 info.high_limit = min(task_size, VA_EXCLUDE_START);
8477 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8478 info.align_offset = pgoff << PAGE_SHIFT;
8479+ info.threadstack_offset = offset;
8480 addr = vm_unmapped_area(&info);
8481
8482 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8483 VM_BUG_ON(addr != -ENOMEM);
8484 info.low_limit = VA_EXCLUDE_END;
8485+
8486+#ifdef CONFIG_PAX_RANDMMAP
8487+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8488+ info.low_limit += mm->delta_mmap;
8489+#endif
8490+
8491 info.high_limit = task_size;
8492 addr = vm_unmapped_area(&info);
8493 }
8494@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 unsigned long task_size = STACK_TOP32;
8496 unsigned long addr = addr0;
8497 int do_color_align;
8498+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8499 struct vm_unmapped_area_info info;
8500
8501 /* This should only ever run for 32-bit processes. */
8502@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8503 /* We do not accept a shared mapping if it would violate
8504 * cache aliasing constraints.
8505 */
8506- if ((flags & MAP_SHARED) &&
8507+ if ((filp || (flags & MAP_SHARED)) &&
8508 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8509 return -EINVAL;
8510 return addr;
8511@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8512 if (filp || (flags & MAP_SHARED))
8513 do_color_align = 1;
8514
8515+#ifdef CONFIG_PAX_RANDMMAP
8516+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8517+#endif
8518+
8519 /* requesting a specific address */
8520 if (addr) {
8521 if (do_color_align)
8522@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8523 addr = PAGE_ALIGN(addr);
8524
8525 vma = find_vma(mm, addr);
8526- if (task_size - len >= addr &&
8527- (!vma || addr + len <= vma->vm_start))
8528+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8529 return addr;
8530 }
8531
8532@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8533 info.high_limit = mm->mmap_base;
8534 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8535 info.align_offset = pgoff << PAGE_SHIFT;
8536+ info.threadstack_offset = offset;
8537 addr = vm_unmapped_area(&info);
8538
8539 /*
8540@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8541 VM_BUG_ON(addr != -ENOMEM);
8542 info.flags = 0;
8543 info.low_limit = TASK_UNMAPPED_BASE;
8544+
8545+#ifdef CONFIG_PAX_RANDMMAP
8546+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8547+ info.low_limit += mm->delta_mmap;
8548+#endif
8549+
8550 info.high_limit = STACK_TOP32;
8551 addr = vm_unmapped_area(&info);
8552 }
8553@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
8554 EXPORT_SYMBOL(get_fb_unmapped_area);
8555
8556 /* Essentially the same as PowerPC. */
8557-static unsigned long mmap_rnd(void)
8558+static unsigned long mmap_rnd(struct mm_struct *mm)
8559 {
8560 unsigned long rnd = 0UL;
8561
8562+#ifdef CONFIG_PAX_RANDMMAP
8563+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8564+#endif
8565+
8566 if (current->flags & PF_RANDOMIZE) {
8567 unsigned long val = get_random_int();
8568 if (test_thread_flag(TIF_32BIT))
8569@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
8570
8571 void arch_pick_mmap_layout(struct mm_struct *mm)
8572 {
8573- unsigned long random_factor = mmap_rnd();
8574+ unsigned long random_factor = mmap_rnd(mm);
8575 unsigned long gap;
8576
8577 /*
8578@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8579 gap == RLIM_INFINITY ||
8580 sysctl_legacy_va_layout) {
8581 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8582+
8583+#ifdef CONFIG_PAX_RANDMMAP
8584+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8585+ mm->mmap_base += mm->delta_mmap;
8586+#endif
8587+
8588 mm->get_unmapped_area = arch_get_unmapped_area;
8589 mm->unmap_area = arch_unmap_area;
8590 } else {
8591@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8592 gap = (task_size / 6 * 5);
8593
8594 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8595+
8596+#ifdef CONFIG_PAX_RANDMMAP
8597+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8598+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8599+#endif
8600+
8601 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8602 mm->unmap_area = arch_unmap_area_topdown;
8603 }
8604diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8605index 22a1098..6255eb9 100644
8606--- a/arch/sparc/kernel/syscalls.S
8607+++ b/arch/sparc/kernel/syscalls.S
8608@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
8609 #endif
8610 .align 32
8611 1: ldx [%g6 + TI_FLAGS], %l5
8612- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8613+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8614 be,pt %icc, rtrap
8615 nop
8616 call syscall_trace_leave
8617@@ -184,7 +184,7 @@ linux_sparc_syscall32:
8618
8619 srl %i5, 0, %o5 ! IEU1
8620 srl %i2, 0, %o2 ! IEU0 Group
8621- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8622+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8623 bne,pn %icc, linux_syscall_trace32 ! CTI
8624 mov %i0, %l5 ! IEU1
8625 call %l7 ! CTI Group brk forced
8626@@ -207,7 +207,7 @@ linux_sparc_syscall:
8627
8628 mov %i3, %o3 ! IEU1
8629 mov %i4, %o4 ! IEU0 Group
8630- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8631+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8632 bne,pn %icc, linux_syscall_trace ! CTI Group
8633 mov %i0, %l5 ! IEU0
8634 2: call %l7 ! CTI Group brk forced
8635@@ -223,7 +223,7 @@ ret_sys_call:
8636
8637 cmp %o0, -ERESTART_RESTARTBLOCK
8638 bgeu,pn %xcc, 1f
8639- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8640+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8641 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8642
8643 2:
8644diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8645index 654e8aa..45f431b 100644
8646--- a/arch/sparc/kernel/sysfs.c
8647+++ b/arch/sparc/kernel/sysfs.c
8648@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8649 return NOTIFY_OK;
8650 }
8651
8652-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8653+static struct notifier_block sysfs_cpu_nb = {
8654 .notifier_call = sysfs_cpu_notify,
8655 };
8656
8657diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8658index 6629829..036032d 100644
8659--- a/arch/sparc/kernel/traps_32.c
8660+++ b/arch/sparc/kernel/traps_32.c
8661@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8662 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8663 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8664
8665+extern void gr_handle_kernel_exploit(void);
8666+
8667 void die_if_kernel(char *str, struct pt_regs *regs)
8668 {
8669 static int die_counter;
8670@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8671 count++ < 30 &&
8672 (((unsigned long) rw) >= PAGE_OFFSET) &&
8673 !(((unsigned long) rw) & 0x7)) {
8674- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8675+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8676 (void *) rw->ins[7]);
8677 rw = (struct reg_window32 *)rw->ins[6];
8678 }
8679 }
8680 printk("Instruction DUMP:");
8681 instruction_dump ((unsigned long *) regs->pc);
8682- if(regs->psr & PSR_PS)
8683+ if(regs->psr & PSR_PS) {
8684+ gr_handle_kernel_exploit();
8685 do_exit(SIGKILL);
8686+ }
8687 do_exit(SIGSEGV);
8688 }
8689
8690diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8691index b3f833a..ac74b2d 100644
8692--- a/arch/sparc/kernel/traps_64.c
8693+++ b/arch/sparc/kernel/traps_64.c
8694@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8695 i + 1,
8696 p->trapstack[i].tstate, p->trapstack[i].tpc,
8697 p->trapstack[i].tnpc, p->trapstack[i].tt);
8698- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8699+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8700 }
8701 }
8702
8703@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8704
8705 lvl -= 0x100;
8706 if (regs->tstate & TSTATE_PRIV) {
8707+
8708+#ifdef CONFIG_PAX_REFCOUNT
8709+ if (lvl == 6)
8710+ pax_report_refcount_overflow(regs);
8711+#endif
8712+
8713 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8714 die_if_kernel(buffer, regs);
8715 }
8716@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8717 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8718 {
8719 char buffer[32];
8720-
8721+
8722 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8723 0, lvl, SIGTRAP) == NOTIFY_STOP)
8724 return;
8725
8726+#ifdef CONFIG_PAX_REFCOUNT
8727+ if (lvl == 6)
8728+ pax_report_refcount_overflow(regs);
8729+#endif
8730+
8731 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8732
8733 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8734@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8735 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8736 printk("%s" "ERROR(%d): ",
8737 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8738- printk("TPC<%pS>\n", (void *) regs->tpc);
8739+ printk("TPC<%pA>\n", (void *) regs->tpc);
8740 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8741 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8742 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8743@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8744 smp_processor_id(),
8745 (type & 0x1) ? 'I' : 'D',
8746 regs->tpc);
8747- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8748+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8749 panic("Irrecoverable Cheetah+ parity error.");
8750 }
8751
8752@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8753 smp_processor_id(),
8754 (type & 0x1) ? 'I' : 'D',
8755 regs->tpc);
8756- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8757+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8758 }
8759
8760 struct sun4v_error_entry {
8761@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8762
8763 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8764 regs->tpc, tl);
8765- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8766+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8767 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8768- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8769+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8770 (void *) regs->u_regs[UREG_I7]);
8771 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8772 "pte[%lx] error[%lx]\n",
8773@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8774
8775 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8776 regs->tpc, tl);
8777- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8778+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8779 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8780- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8781+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8782 (void *) regs->u_regs[UREG_I7]);
8783 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8784 "pte[%lx] error[%lx]\n",
8785@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8786 fp = (unsigned long)sf->fp + STACK_BIAS;
8787 }
8788
8789- printk(" [%016lx] %pS\n", pc, (void *) pc);
8790+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8791 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8792 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8793 int index = tsk->curr_ret_stack;
8794 if (tsk->ret_stack && index >= graph) {
8795 pc = tsk->ret_stack[index - graph].ret;
8796- printk(" [%016lx] %pS\n", pc, (void *) pc);
8797+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8798 graph++;
8799 }
8800 }
8801@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8802 return (struct reg_window *) (fp + STACK_BIAS);
8803 }
8804
8805+extern void gr_handle_kernel_exploit(void);
8806+
8807 void die_if_kernel(char *str, struct pt_regs *regs)
8808 {
8809 static int die_counter;
8810@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8811 while (rw &&
8812 count++ < 30 &&
8813 kstack_valid(tp, (unsigned long) rw)) {
8814- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8815+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8816 (void *) rw->ins[7]);
8817
8818 rw = kernel_stack_up(rw);
8819@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8820 }
8821 user_instruction_dump ((unsigned int __user *) regs->tpc);
8822 }
8823- if (regs->tstate & TSTATE_PRIV)
8824+ if (regs->tstate & TSTATE_PRIV) {
8825+ gr_handle_kernel_exploit();
8826 do_exit(SIGKILL);
8827+ }
8828 do_exit(SIGSEGV);
8829 }
8830 EXPORT_SYMBOL(die_if_kernel);
8831diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8832index 8201c25e..072a2a7 100644
8833--- a/arch/sparc/kernel/unaligned_64.c
8834+++ b/arch/sparc/kernel/unaligned_64.c
8835@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8836 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8837
8838 if (__ratelimit(&ratelimit)) {
8839- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8840+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8841 regs->tpc, (void *) regs->tpc);
8842 }
8843 }
8844diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8845index dbe119b..089c7c1 100644
8846--- a/arch/sparc/lib/Makefile
8847+++ b/arch/sparc/lib/Makefile
8848@@ -2,7 +2,7 @@
8849 #
8850
8851 asflags-y := -ansi -DST_DIV0=0x02
8852-ccflags-y := -Werror
8853+#ccflags-y := -Werror
8854
8855 lib-$(CONFIG_SPARC32) += ashrdi3.o
8856 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8857diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8858index 85c233d..68500e0 100644
8859--- a/arch/sparc/lib/atomic_64.S
8860+++ b/arch/sparc/lib/atomic_64.S
8861@@ -17,7 +17,12 @@
8862 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8863 BACKOFF_SETUP(%o2)
8864 1: lduw [%o1], %g1
8865- add %g1, %o0, %g7
8866+ addcc %g1, %o0, %g7
8867+
8868+#ifdef CONFIG_PAX_REFCOUNT
8869+ tvs %icc, 6
8870+#endif
8871+
8872 cas [%o1], %g1, %g7
8873 cmp %g1, %g7
8874 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8875@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8876 2: BACKOFF_SPIN(%o2, %o3, 1b)
8877 ENDPROC(atomic_add)
8878
8879+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8880+ BACKOFF_SETUP(%o2)
8881+1: lduw [%o1], %g1
8882+ add %g1, %o0, %g7
8883+ cas [%o1], %g1, %g7
8884+ cmp %g1, %g7
8885+ bne,pn %icc, 2f
8886+ nop
8887+ retl
8888+ nop
8889+2: BACKOFF_SPIN(%o2, %o3, 1b)
8890+ENDPROC(atomic_add_unchecked)
8891+
8892 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8893 BACKOFF_SETUP(%o2)
8894 1: lduw [%o1], %g1
8895- sub %g1, %o0, %g7
8896+ subcc %g1, %o0, %g7
8897+
8898+#ifdef CONFIG_PAX_REFCOUNT
8899+ tvs %icc, 6
8900+#endif
8901+
8902 cas [%o1], %g1, %g7
8903 cmp %g1, %g7
8904 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8905@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8906 2: BACKOFF_SPIN(%o2, %o3, 1b)
8907 ENDPROC(atomic_sub)
8908
8909+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8910+ BACKOFF_SETUP(%o2)
8911+1: lduw [%o1], %g1
8912+ sub %g1, %o0, %g7
8913+ cas [%o1], %g1, %g7
8914+ cmp %g1, %g7
8915+ bne,pn %icc, 2f
8916+ nop
8917+ retl
8918+ nop
8919+2: BACKOFF_SPIN(%o2, %o3, 1b)
8920+ENDPROC(atomic_sub_unchecked)
8921+
8922 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8923 BACKOFF_SETUP(%o2)
8924 1: lduw [%o1], %g1
8925- add %g1, %o0, %g7
8926+ addcc %g1, %o0, %g7
8927+
8928+#ifdef CONFIG_PAX_REFCOUNT
8929+ tvs %icc, 6
8930+#endif
8931+
8932 cas [%o1], %g1, %g7
8933 cmp %g1, %g7
8934 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8935@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8936 2: BACKOFF_SPIN(%o2, %o3, 1b)
8937 ENDPROC(atomic_add_ret)
8938
8939+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8940+ BACKOFF_SETUP(%o2)
8941+1: lduw [%o1], %g1
8942+ addcc %g1, %o0, %g7
8943+ cas [%o1], %g1, %g7
8944+ cmp %g1, %g7
8945+ bne,pn %icc, 2f
8946+ add %g7, %o0, %g7
8947+ sra %g7, 0, %o0
8948+ retl
8949+ nop
8950+2: BACKOFF_SPIN(%o2, %o3, 1b)
8951+ENDPROC(atomic_add_ret_unchecked)
8952+
8953 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8954 BACKOFF_SETUP(%o2)
8955 1: lduw [%o1], %g1
8956- sub %g1, %o0, %g7
8957+ subcc %g1, %o0, %g7
8958+
8959+#ifdef CONFIG_PAX_REFCOUNT
8960+ tvs %icc, 6
8961+#endif
8962+
8963 cas [%o1], %g1, %g7
8964 cmp %g1, %g7
8965 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8966@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8967 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8968 BACKOFF_SETUP(%o2)
8969 1: ldx [%o1], %g1
8970- add %g1, %o0, %g7
8971+ addcc %g1, %o0, %g7
8972+
8973+#ifdef CONFIG_PAX_REFCOUNT
8974+ tvs %xcc, 6
8975+#endif
8976+
8977 casx [%o1], %g1, %g7
8978 cmp %g1, %g7
8979 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8980@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8981 2: BACKOFF_SPIN(%o2, %o3, 1b)
8982 ENDPROC(atomic64_add)
8983
8984+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8985+ BACKOFF_SETUP(%o2)
8986+1: ldx [%o1], %g1
8987+ addcc %g1, %o0, %g7
8988+ casx [%o1], %g1, %g7
8989+ cmp %g1, %g7
8990+ bne,pn %xcc, 2f
8991+ nop
8992+ retl
8993+ nop
8994+2: BACKOFF_SPIN(%o2, %o3, 1b)
8995+ENDPROC(atomic64_add_unchecked)
8996+
8997 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8998 BACKOFF_SETUP(%o2)
8999 1: ldx [%o1], %g1
9000- sub %g1, %o0, %g7
9001+ subcc %g1, %o0, %g7
9002+
9003+#ifdef CONFIG_PAX_REFCOUNT
9004+ tvs %xcc, 6
9005+#endif
9006+
9007 casx [%o1], %g1, %g7
9008 cmp %g1, %g7
9009 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9010@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9011 2: BACKOFF_SPIN(%o2, %o3, 1b)
9012 ENDPROC(atomic64_sub)
9013
9014+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9015+ BACKOFF_SETUP(%o2)
9016+1: ldx [%o1], %g1
9017+ subcc %g1, %o0, %g7
9018+ casx [%o1], %g1, %g7
9019+ cmp %g1, %g7
9020+ bne,pn %xcc, 2f
9021+ nop
9022+ retl
9023+ nop
9024+2: BACKOFF_SPIN(%o2, %o3, 1b)
9025+ENDPROC(atomic64_sub_unchecked)
9026+
9027 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9028 BACKOFF_SETUP(%o2)
9029 1: ldx [%o1], %g1
9030- add %g1, %o0, %g7
9031+ addcc %g1, %o0, %g7
9032+
9033+#ifdef CONFIG_PAX_REFCOUNT
9034+ tvs %xcc, 6
9035+#endif
9036+
9037 casx [%o1], %g1, %g7
9038 cmp %g1, %g7
9039 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9040@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9041 2: BACKOFF_SPIN(%o2, %o3, 1b)
9042 ENDPROC(atomic64_add_ret)
9043
9044+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9045+ BACKOFF_SETUP(%o2)
9046+1: ldx [%o1], %g1
9047+ addcc %g1, %o0, %g7
9048+ casx [%o1], %g1, %g7
9049+ cmp %g1, %g7
9050+ bne,pn %xcc, 2f
9051+ add %g7, %o0, %g7
9052+ mov %g7, %o0
9053+ retl
9054+ nop
9055+2: BACKOFF_SPIN(%o2, %o3, 1b)
9056+ENDPROC(atomic64_add_ret_unchecked)
9057+
9058 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9059 BACKOFF_SETUP(%o2)
9060 1: ldx [%o1], %g1
9061- sub %g1, %o0, %g7
9062+ subcc %g1, %o0, %g7
9063+
9064+#ifdef CONFIG_PAX_REFCOUNT
9065+ tvs %xcc, 6
9066+#endif
9067+
9068 casx [%o1], %g1, %g7
9069 cmp %g1, %g7
9070 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9071diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9072index 0c4e35e..745d3e4 100644
9073--- a/arch/sparc/lib/ksyms.c
9074+++ b/arch/sparc/lib/ksyms.c
9075@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9076
9077 /* Atomic counter implementation. */
9078 EXPORT_SYMBOL(atomic_add);
9079+EXPORT_SYMBOL(atomic_add_unchecked);
9080 EXPORT_SYMBOL(atomic_add_ret);
9081+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9082 EXPORT_SYMBOL(atomic_sub);
9083+EXPORT_SYMBOL(atomic_sub_unchecked);
9084 EXPORT_SYMBOL(atomic_sub_ret);
9085 EXPORT_SYMBOL(atomic64_add);
9086+EXPORT_SYMBOL(atomic64_add_unchecked);
9087 EXPORT_SYMBOL(atomic64_add_ret);
9088+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9089 EXPORT_SYMBOL(atomic64_sub);
9090+EXPORT_SYMBOL(atomic64_sub_unchecked);
9091 EXPORT_SYMBOL(atomic64_sub_ret);
9092 EXPORT_SYMBOL(atomic64_dec_if_positive);
9093
9094diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9095index 30c3ecc..736f015 100644
9096--- a/arch/sparc/mm/Makefile
9097+++ b/arch/sparc/mm/Makefile
9098@@ -2,7 +2,7 @@
9099 #
9100
9101 asflags-y := -ansi
9102-ccflags-y := -Werror
9103+#ccflags-y := -Werror
9104
9105 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9106 obj-y += fault_$(BITS).o
9107diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9108index e98bfda..ea8d221 100644
9109--- a/arch/sparc/mm/fault_32.c
9110+++ b/arch/sparc/mm/fault_32.c
9111@@ -21,6 +21,9 @@
9112 #include <linux/perf_event.h>
9113 #include <linux/interrupt.h>
9114 #include <linux/kdebug.h>
9115+#include <linux/slab.h>
9116+#include <linux/pagemap.h>
9117+#include <linux/compiler.h>
9118
9119 #include <asm/page.h>
9120 #include <asm/pgtable.h>
9121@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9122 return safe_compute_effective_address(regs, insn);
9123 }
9124
9125+#ifdef CONFIG_PAX_PAGEEXEC
9126+#ifdef CONFIG_PAX_DLRESOLVE
9127+static void pax_emuplt_close(struct vm_area_struct *vma)
9128+{
9129+ vma->vm_mm->call_dl_resolve = 0UL;
9130+}
9131+
9132+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9133+{
9134+ unsigned int *kaddr;
9135+
9136+ vmf->page = alloc_page(GFP_HIGHUSER);
9137+ if (!vmf->page)
9138+ return VM_FAULT_OOM;
9139+
9140+ kaddr = kmap(vmf->page);
9141+ memset(kaddr, 0, PAGE_SIZE);
9142+ kaddr[0] = 0x9DE3BFA8U; /* save */
9143+ flush_dcache_page(vmf->page);
9144+ kunmap(vmf->page);
9145+ return VM_FAULT_MAJOR;
9146+}
9147+
9148+static const struct vm_operations_struct pax_vm_ops = {
9149+ .close = pax_emuplt_close,
9150+ .fault = pax_emuplt_fault
9151+};
9152+
9153+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9154+{
9155+ int ret;
9156+
9157+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9158+ vma->vm_mm = current->mm;
9159+ vma->vm_start = addr;
9160+ vma->vm_end = addr + PAGE_SIZE;
9161+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9162+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9163+ vma->vm_ops = &pax_vm_ops;
9164+
9165+ ret = insert_vm_struct(current->mm, vma);
9166+ if (ret)
9167+ return ret;
9168+
9169+ ++current->mm->total_vm;
9170+ return 0;
9171+}
9172+#endif
9173+
9174+/*
9175+ * PaX: decide what to do with offenders (regs->pc = fault address)
9176+ *
9177+ * returns 1 when task should be killed
9178+ * 2 when patched PLT trampoline was detected
9179+ * 3 when unpatched PLT trampoline was detected
9180+ */
9181+static int pax_handle_fetch_fault(struct pt_regs *regs)
9182+{
9183+
9184+#ifdef CONFIG_PAX_EMUPLT
9185+ int err;
9186+
9187+ do { /* PaX: patched PLT emulation #1 */
9188+ unsigned int sethi1, sethi2, jmpl;
9189+
9190+ err = get_user(sethi1, (unsigned int *)regs->pc);
9191+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9192+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9193+
9194+ if (err)
9195+ break;
9196+
9197+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9198+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9199+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9200+ {
9201+ unsigned int addr;
9202+
9203+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9204+ addr = regs->u_regs[UREG_G1];
9205+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9206+ regs->pc = addr;
9207+ regs->npc = addr+4;
9208+ return 2;
9209+ }
9210+ } while (0);
9211+
9212+ do { /* PaX: patched PLT emulation #2 */
9213+ unsigned int ba;
9214+
9215+ err = get_user(ba, (unsigned int *)regs->pc);
9216+
9217+ if (err)
9218+ break;
9219+
9220+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9221+ unsigned int addr;
9222+
9223+ if ((ba & 0xFFC00000U) == 0x30800000U)
9224+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9225+ else
9226+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9227+ regs->pc = addr;
9228+ regs->npc = addr+4;
9229+ return 2;
9230+ }
9231+ } while (0);
9232+
9233+ do { /* PaX: patched PLT emulation #3 */
9234+ unsigned int sethi, bajmpl, nop;
9235+
9236+ err = get_user(sethi, (unsigned int *)regs->pc);
9237+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9238+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9239+
9240+ if (err)
9241+ break;
9242+
9243+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9244+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9245+ nop == 0x01000000U)
9246+ {
9247+ unsigned int addr;
9248+
9249+ addr = (sethi & 0x003FFFFFU) << 10;
9250+ regs->u_regs[UREG_G1] = addr;
9251+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9252+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9253+ else
9254+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9255+ regs->pc = addr;
9256+ regs->npc = addr+4;
9257+ return 2;
9258+ }
9259+ } while (0);
9260+
9261+ do { /* PaX: unpatched PLT emulation step 1 */
9262+ unsigned int sethi, ba, nop;
9263+
9264+ err = get_user(sethi, (unsigned int *)regs->pc);
9265+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9266+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9267+
9268+ if (err)
9269+ break;
9270+
9271+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9272+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9273+ nop == 0x01000000U)
9274+ {
9275+ unsigned int addr, save, call;
9276+
9277+ if ((ba & 0xFFC00000U) == 0x30800000U)
9278+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9279+ else
9280+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9281+
9282+ err = get_user(save, (unsigned int *)addr);
9283+ err |= get_user(call, (unsigned int *)(addr+4));
9284+ err |= get_user(nop, (unsigned int *)(addr+8));
9285+ if (err)
9286+ break;
9287+
9288+#ifdef CONFIG_PAX_DLRESOLVE
9289+ if (save == 0x9DE3BFA8U &&
9290+ (call & 0xC0000000U) == 0x40000000U &&
9291+ nop == 0x01000000U)
9292+ {
9293+ struct vm_area_struct *vma;
9294+ unsigned long call_dl_resolve;
9295+
9296+ down_read(&current->mm->mmap_sem);
9297+ call_dl_resolve = current->mm->call_dl_resolve;
9298+ up_read(&current->mm->mmap_sem);
9299+ if (likely(call_dl_resolve))
9300+ goto emulate;
9301+
9302+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9303+
9304+ down_write(&current->mm->mmap_sem);
9305+ if (current->mm->call_dl_resolve) {
9306+ call_dl_resolve = current->mm->call_dl_resolve;
9307+ up_write(&current->mm->mmap_sem);
9308+ if (vma)
9309+ kmem_cache_free(vm_area_cachep, vma);
9310+ goto emulate;
9311+ }
9312+
9313+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9314+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9315+ up_write(&current->mm->mmap_sem);
9316+ if (vma)
9317+ kmem_cache_free(vm_area_cachep, vma);
9318+ return 1;
9319+ }
9320+
9321+ if (pax_insert_vma(vma, call_dl_resolve)) {
9322+ up_write(&current->mm->mmap_sem);
9323+ kmem_cache_free(vm_area_cachep, vma);
9324+ return 1;
9325+ }
9326+
9327+ current->mm->call_dl_resolve = call_dl_resolve;
9328+ up_write(&current->mm->mmap_sem);
9329+
9330+emulate:
9331+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9332+ regs->pc = call_dl_resolve;
9333+ regs->npc = addr+4;
9334+ return 3;
9335+ }
9336+#endif
9337+
9338+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9339+ if ((save & 0xFFC00000U) == 0x05000000U &&
9340+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9341+ nop == 0x01000000U)
9342+ {
9343+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9344+ regs->u_regs[UREG_G2] = addr + 4;
9345+ addr = (save & 0x003FFFFFU) << 10;
9346+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9347+ regs->pc = addr;
9348+ regs->npc = addr+4;
9349+ return 3;
9350+ }
9351+ }
9352+ } while (0);
9353+
9354+ do { /* PaX: unpatched PLT emulation step 2 */
9355+ unsigned int save, call, nop;
9356+
9357+ err = get_user(save, (unsigned int *)(regs->pc-4));
9358+ err |= get_user(call, (unsigned int *)regs->pc);
9359+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9360+ if (err)
9361+ break;
9362+
9363+ if (save == 0x9DE3BFA8U &&
9364+ (call & 0xC0000000U) == 0x40000000U &&
9365+ nop == 0x01000000U)
9366+ {
9367+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9368+
9369+ regs->u_regs[UREG_RETPC] = regs->pc;
9370+ regs->pc = dl_resolve;
9371+ regs->npc = dl_resolve+4;
9372+ return 3;
9373+ }
9374+ } while (0);
9375+#endif
9376+
9377+ return 1;
9378+}
9379+
9380+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9381+{
9382+ unsigned long i;
9383+
9384+ printk(KERN_ERR "PAX: bytes at PC: ");
9385+ for (i = 0; i < 8; i++) {
9386+ unsigned int c;
9387+ if (get_user(c, (unsigned int *)pc+i))
9388+ printk(KERN_CONT "???????? ");
9389+ else
9390+ printk(KERN_CONT "%08x ", c);
9391+ }
9392+ printk("\n");
9393+}
9394+#endif
9395+
9396 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9397 int text_fault)
9398 {
9399@@ -230,6 +504,24 @@ good_area:
9400 if (!(vma->vm_flags & VM_WRITE))
9401 goto bad_area;
9402 } else {
9403+
9404+#ifdef CONFIG_PAX_PAGEEXEC
9405+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9406+ up_read(&mm->mmap_sem);
9407+ switch (pax_handle_fetch_fault(regs)) {
9408+
9409+#ifdef CONFIG_PAX_EMUPLT
9410+ case 2:
9411+ case 3:
9412+ return;
9413+#endif
9414+
9415+ }
9416+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9417+ do_group_exit(SIGKILL);
9418+ }
9419+#endif
9420+
9421 /* Allow reads even for write-only mappings */
9422 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9423 goto bad_area;
9424diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9425index 5062ff3..e0b75f3 100644
9426--- a/arch/sparc/mm/fault_64.c
9427+++ b/arch/sparc/mm/fault_64.c
9428@@ -21,6 +21,9 @@
9429 #include <linux/kprobes.h>
9430 #include <linux/kdebug.h>
9431 #include <linux/percpu.h>
9432+#include <linux/slab.h>
9433+#include <linux/pagemap.h>
9434+#include <linux/compiler.h>
9435
9436 #include <asm/page.h>
9437 #include <asm/pgtable.h>
9438@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9439 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9440 regs->tpc);
9441 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9442- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9443+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9444 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9445 dump_stack();
9446 unhandled_fault(regs->tpc, current, regs);
9447@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9448 show_regs(regs);
9449 }
9450
9451+#ifdef CONFIG_PAX_PAGEEXEC
9452+#ifdef CONFIG_PAX_DLRESOLVE
9453+static void pax_emuplt_close(struct vm_area_struct *vma)
9454+{
9455+ vma->vm_mm->call_dl_resolve = 0UL;
9456+}
9457+
9458+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9459+{
9460+ unsigned int *kaddr;
9461+
9462+ vmf->page = alloc_page(GFP_HIGHUSER);
9463+ if (!vmf->page)
9464+ return VM_FAULT_OOM;
9465+
9466+ kaddr = kmap(vmf->page);
9467+ memset(kaddr, 0, PAGE_SIZE);
9468+ kaddr[0] = 0x9DE3BFA8U; /* save */
9469+ flush_dcache_page(vmf->page);
9470+ kunmap(vmf->page);
9471+ return VM_FAULT_MAJOR;
9472+}
9473+
9474+static const struct vm_operations_struct pax_vm_ops = {
9475+ .close = pax_emuplt_close,
9476+ .fault = pax_emuplt_fault
9477+};
9478+
9479+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9480+{
9481+ int ret;
9482+
9483+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9484+ vma->vm_mm = current->mm;
9485+ vma->vm_start = addr;
9486+ vma->vm_end = addr + PAGE_SIZE;
9487+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9488+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9489+ vma->vm_ops = &pax_vm_ops;
9490+
9491+ ret = insert_vm_struct(current->mm, vma);
9492+ if (ret)
9493+ return ret;
9494+
9495+ ++current->mm->total_vm;
9496+ return 0;
9497+}
9498+#endif
9499+
9500+/*
9501+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9502+ *
9503+ * returns 1 when task should be killed
9504+ * 2 when patched PLT trampoline was detected
9505+ * 3 when unpatched PLT trampoline was detected
9506+ */
9507+static int pax_handle_fetch_fault(struct pt_regs *regs)
9508+{
9509+
9510+#ifdef CONFIG_PAX_EMUPLT
9511+ int err;
9512+
9513+ do { /* PaX: patched PLT emulation #1 */
9514+ unsigned int sethi1, sethi2, jmpl;
9515+
9516+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9517+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9518+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9519+
9520+ if (err)
9521+ break;
9522+
9523+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9524+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9525+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9526+ {
9527+ unsigned long addr;
9528+
9529+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9530+ addr = regs->u_regs[UREG_G1];
9531+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9532+
9533+ if (test_thread_flag(TIF_32BIT))
9534+ addr &= 0xFFFFFFFFUL;
9535+
9536+ regs->tpc = addr;
9537+ regs->tnpc = addr+4;
9538+ return 2;
9539+ }
9540+ } while (0);
9541+
9542+ do { /* PaX: patched PLT emulation #2 */
9543+ unsigned int ba;
9544+
9545+ err = get_user(ba, (unsigned int *)regs->tpc);
9546+
9547+ if (err)
9548+ break;
9549+
9550+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9551+ unsigned long addr;
9552+
9553+ if ((ba & 0xFFC00000U) == 0x30800000U)
9554+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9555+ else
9556+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9557+
9558+ if (test_thread_flag(TIF_32BIT))
9559+ addr &= 0xFFFFFFFFUL;
9560+
9561+ regs->tpc = addr;
9562+ regs->tnpc = addr+4;
9563+ return 2;
9564+ }
9565+ } while (0);
9566+
9567+ do { /* PaX: patched PLT emulation #3 */
9568+ unsigned int sethi, bajmpl, nop;
9569+
9570+ err = get_user(sethi, (unsigned int *)regs->tpc);
9571+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9572+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9573+
9574+ if (err)
9575+ break;
9576+
9577+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9578+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9579+ nop == 0x01000000U)
9580+ {
9581+ unsigned long addr;
9582+
9583+ addr = (sethi & 0x003FFFFFU) << 10;
9584+ regs->u_regs[UREG_G1] = addr;
9585+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9586+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9587+ else
9588+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9589+
9590+ if (test_thread_flag(TIF_32BIT))
9591+ addr &= 0xFFFFFFFFUL;
9592+
9593+ regs->tpc = addr;
9594+ regs->tnpc = addr+4;
9595+ return 2;
9596+ }
9597+ } while (0);
9598+
9599+ do { /* PaX: patched PLT emulation #4 */
9600+ unsigned int sethi, mov1, call, mov2;
9601+
9602+ err = get_user(sethi, (unsigned int *)regs->tpc);
9603+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9604+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9605+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9606+
9607+ if (err)
9608+ break;
9609+
9610+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9611+ mov1 == 0x8210000FU &&
9612+ (call & 0xC0000000U) == 0x40000000U &&
9613+ mov2 == 0x9E100001U)
9614+ {
9615+ unsigned long addr;
9616+
9617+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9618+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9619+
9620+ if (test_thread_flag(TIF_32BIT))
9621+ addr &= 0xFFFFFFFFUL;
9622+
9623+ regs->tpc = addr;
9624+ regs->tnpc = addr+4;
9625+ return 2;
9626+ }
9627+ } while (0);
9628+
9629+ do { /* PaX: patched PLT emulation #5 */
9630+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9631+
9632+ err = get_user(sethi, (unsigned int *)regs->tpc);
9633+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9634+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9635+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9636+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9637+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9638+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9639+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9640+
9641+ if (err)
9642+ break;
9643+
9644+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9645+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9646+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9647+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9648+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9649+ sllx == 0x83287020U &&
9650+ jmpl == 0x81C04005U &&
9651+ nop == 0x01000000U)
9652+ {
9653+ unsigned long addr;
9654+
9655+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9656+ regs->u_regs[UREG_G1] <<= 32;
9657+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9658+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9659+ regs->tpc = addr;
9660+ regs->tnpc = addr+4;
9661+ return 2;
9662+ }
9663+ } while (0);
9664+
9665+ do { /* PaX: patched PLT emulation #6 */
9666+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9667+
9668+ err = get_user(sethi, (unsigned int *)regs->tpc);
9669+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9670+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9671+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9672+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9673+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9674+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9675+
9676+ if (err)
9677+ break;
9678+
9679+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9680+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9681+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9682+ sllx == 0x83287020U &&
9683+ (or & 0xFFFFE000U) == 0x8A116000U &&
9684+ jmpl == 0x81C04005U &&
9685+ nop == 0x01000000U)
9686+ {
9687+ unsigned long addr;
9688+
9689+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9690+ regs->u_regs[UREG_G1] <<= 32;
9691+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9692+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9693+ regs->tpc = addr;
9694+ regs->tnpc = addr+4;
9695+ return 2;
9696+ }
9697+ } while (0);
9698+
9699+ do { /* PaX: unpatched PLT emulation step 1 */
9700+ unsigned int sethi, ba, nop;
9701+
9702+ err = get_user(sethi, (unsigned int *)regs->tpc);
9703+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9704+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9705+
9706+ if (err)
9707+ break;
9708+
9709+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9710+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9711+ nop == 0x01000000U)
9712+ {
9713+ unsigned long addr;
9714+ unsigned int save, call;
9715+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9716+
9717+ if ((ba & 0xFFC00000U) == 0x30800000U)
9718+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9719+ else
9720+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9721+
9722+ if (test_thread_flag(TIF_32BIT))
9723+ addr &= 0xFFFFFFFFUL;
9724+
9725+ err = get_user(save, (unsigned int *)addr);
9726+ err |= get_user(call, (unsigned int *)(addr+4));
9727+ err |= get_user(nop, (unsigned int *)(addr+8));
9728+ if (err)
9729+ break;
9730+
9731+#ifdef CONFIG_PAX_DLRESOLVE
9732+ if (save == 0x9DE3BFA8U &&
9733+ (call & 0xC0000000U) == 0x40000000U &&
9734+ nop == 0x01000000U)
9735+ {
9736+ struct vm_area_struct *vma;
9737+ unsigned long call_dl_resolve;
9738+
9739+ down_read(&current->mm->mmap_sem);
9740+ call_dl_resolve = current->mm->call_dl_resolve;
9741+ up_read(&current->mm->mmap_sem);
9742+ if (likely(call_dl_resolve))
9743+ goto emulate;
9744+
9745+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9746+
9747+ down_write(&current->mm->mmap_sem);
9748+ if (current->mm->call_dl_resolve) {
9749+ call_dl_resolve = current->mm->call_dl_resolve;
9750+ up_write(&current->mm->mmap_sem);
9751+ if (vma)
9752+ kmem_cache_free(vm_area_cachep, vma);
9753+ goto emulate;
9754+ }
9755+
9756+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9757+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9758+ up_write(&current->mm->mmap_sem);
9759+ if (vma)
9760+ kmem_cache_free(vm_area_cachep, vma);
9761+ return 1;
9762+ }
9763+
9764+ if (pax_insert_vma(vma, call_dl_resolve)) {
9765+ up_write(&current->mm->mmap_sem);
9766+ kmem_cache_free(vm_area_cachep, vma);
9767+ return 1;
9768+ }
9769+
9770+ current->mm->call_dl_resolve = call_dl_resolve;
9771+ up_write(&current->mm->mmap_sem);
9772+
9773+emulate:
9774+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9775+ regs->tpc = call_dl_resolve;
9776+ regs->tnpc = addr+4;
9777+ return 3;
9778+ }
9779+#endif
9780+
9781+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9782+ if ((save & 0xFFC00000U) == 0x05000000U &&
9783+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9784+ nop == 0x01000000U)
9785+ {
9786+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9787+ regs->u_regs[UREG_G2] = addr + 4;
9788+ addr = (save & 0x003FFFFFU) << 10;
9789+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9790+
9791+ if (test_thread_flag(TIF_32BIT))
9792+ addr &= 0xFFFFFFFFUL;
9793+
9794+ regs->tpc = addr;
9795+ regs->tnpc = addr+4;
9796+ return 3;
9797+ }
9798+
9799+ /* PaX: 64-bit PLT stub */
9800+ err = get_user(sethi1, (unsigned int *)addr);
9801+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9802+ err |= get_user(or1, (unsigned int *)(addr+8));
9803+ err |= get_user(or2, (unsigned int *)(addr+12));
9804+ err |= get_user(sllx, (unsigned int *)(addr+16));
9805+ err |= get_user(add, (unsigned int *)(addr+20));
9806+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9807+ err |= get_user(nop, (unsigned int *)(addr+28));
9808+ if (err)
9809+ break;
9810+
9811+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9812+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9813+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9814+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9815+ sllx == 0x89293020U &&
9816+ add == 0x8A010005U &&
9817+ jmpl == 0x89C14000U &&
9818+ nop == 0x01000000U)
9819+ {
9820+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9821+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9822+ regs->u_regs[UREG_G4] <<= 32;
9823+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9824+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9825+ regs->u_regs[UREG_G4] = addr + 24;
9826+ addr = regs->u_regs[UREG_G5];
9827+ regs->tpc = addr;
9828+ regs->tnpc = addr+4;
9829+ return 3;
9830+ }
9831+ }
9832+ } while (0);
9833+
9834+#ifdef CONFIG_PAX_DLRESOLVE
9835+ do { /* PaX: unpatched PLT emulation step 2 */
9836+ unsigned int save, call, nop;
9837+
9838+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9839+ err |= get_user(call, (unsigned int *)regs->tpc);
9840+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9841+ if (err)
9842+ break;
9843+
9844+ if (save == 0x9DE3BFA8U &&
9845+ (call & 0xC0000000U) == 0x40000000U &&
9846+ nop == 0x01000000U)
9847+ {
9848+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9849+
9850+ if (test_thread_flag(TIF_32BIT))
9851+ dl_resolve &= 0xFFFFFFFFUL;
9852+
9853+ regs->u_regs[UREG_RETPC] = regs->tpc;
9854+ regs->tpc = dl_resolve;
9855+ regs->tnpc = dl_resolve+4;
9856+ return 3;
9857+ }
9858+ } while (0);
9859+#endif
9860+
9861+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9862+ unsigned int sethi, ba, nop;
9863+
9864+ err = get_user(sethi, (unsigned int *)regs->tpc);
9865+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9866+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9867+
9868+ if (err)
9869+ break;
9870+
9871+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9872+ (ba & 0xFFF00000U) == 0x30600000U &&
9873+ nop == 0x01000000U)
9874+ {
9875+ unsigned long addr;
9876+
9877+ addr = (sethi & 0x003FFFFFU) << 10;
9878+ regs->u_regs[UREG_G1] = addr;
9879+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9880+
9881+ if (test_thread_flag(TIF_32BIT))
9882+ addr &= 0xFFFFFFFFUL;
9883+
9884+ regs->tpc = addr;
9885+ regs->tnpc = addr+4;
9886+ return 2;
9887+ }
9888+ } while (0);
9889+
9890+#endif
9891+
9892+ return 1;
9893+}
9894+
9895+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9896+{
9897+ unsigned long i;
9898+
9899+ printk(KERN_ERR "PAX: bytes at PC: ");
9900+ for (i = 0; i < 8; i++) {
9901+ unsigned int c;
9902+ if (get_user(c, (unsigned int *)pc+i))
9903+ printk(KERN_CONT "???????? ");
9904+ else
9905+ printk(KERN_CONT "%08x ", c);
9906+ }
9907+ printk("\n");
9908+}
9909+#endif
9910+
9911 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9912 {
9913 struct mm_struct *mm = current->mm;
9914@@ -341,6 +804,29 @@ retry:
9915 if (!vma)
9916 goto bad_area;
9917
9918+#ifdef CONFIG_PAX_PAGEEXEC
9919+ /* PaX: detect ITLB misses on non-exec pages */
9920+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9921+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9922+ {
9923+ if (address != regs->tpc)
9924+ goto good_area;
9925+
9926+ up_read(&mm->mmap_sem);
9927+ switch (pax_handle_fetch_fault(regs)) {
9928+
9929+#ifdef CONFIG_PAX_EMUPLT
9930+ case 2:
9931+ case 3:
9932+ return;
9933+#endif
9934+
9935+ }
9936+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9937+ do_group_exit(SIGKILL);
9938+ }
9939+#endif
9940+
9941 /* Pure DTLB misses do not tell us whether the fault causing
9942 * load/store/atomic was a write or not, it only says that there
9943 * was no match. So in such a case we (carefully) read the
9944diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9945index d2b5944..bd813f2 100644
9946--- a/arch/sparc/mm/hugetlbpage.c
9947+++ b/arch/sparc/mm/hugetlbpage.c
9948@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9949
9950 info.flags = 0;
9951 info.length = len;
9952- info.low_limit = TASK_UNMAPPED_BASE;
9953+ info.low_limit = mm->mmap_base;
9954 info.high_limit = min(task_size, VA_EXCLUDE_START);
9955 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9956 info.align_offset = 0;
9957@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9958 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9959 VM_BUG_ON(addr != -ENOMEM);
9960 info.low_limit = VA_EXCLUDE_END;
9961+
9962+#ifdef CONFIG_PAX_RANDMMAP
9963+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9964+ info.low_limit += mm->delta_mmap;
9965+#endif
9966+
9967 info.high_limit = task_size;
9968 addr = vm_unmapped_area(&info);
9969 }
9970@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9971 VM_BUG_ON(addr != -ENOMEM);
9972 info.flags = 0;
9973 info.low_limit = TASK_UNMAPPED_BASE;
9974+
9975+#ifdef CONFIG_PAX_RANDMMAP
9976+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9977+ info.low_limit += mm->delta_mmap;
9978+#endif
9979+
9980 info.high_limit = STACK_TOP32;
9981 addr = vm_unmapped_area(&info);
9982 }
9983@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9984 struct mm_struct *mm = current->mm;
9985 struct vm_area_struct *vma;
9986 unsigned long task_size = TASK_SIZE;
9987+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9988
9989 if (test_thread_flag(TIF_32BIT))
9990 task_size = STACK_TOP32;
9991@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9992 return addr;
9993 }
9994
9995+#ifdef CONFIG_PAX_RANDMMAP
9996+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9997+#endif
9998+
9999 if (addr) {
10000 addr = ALIGN(addr, HPAGE_SIZE);
10001 vma = find_vma(mm, addr);
10002- if (task_size - len >= addr &&
10003- (!vma || addr + len <= vma->vm_start))
10004+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10005 return addr;
10006 }
10007 if (mm->get_unmapped_area == arch_get_unmapped_area)
10008diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10009index f4500c6..889656c 100644
10010--- a/arch/tile/include/asm/atomic_64.h
10011+++ b/arch/tile/include/asm/atomic_64.h
10012@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10013
10014 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10015
10016+#define atomic64_read_unchecked(v) atomic64_read(v)
10017+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10018+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10019+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10020+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10021+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10022+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10023+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10024+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10025+
10026 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10027 #define smp_mb__before_atomic_dec() smp_mb()
10028 #define smp_mb__after_atomic_dec() smp_mb()
10029diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10030index a9a5299..0fce79e 100644
10031--- a/arch/tile/include/asm/cache.h
10032+++ b/arch/tile/include/asm/cache.h
10033@@ -15,11 +15,12 @@
10034 #ifndef _ASM_TILE_CACHE_H
10035 #define _ASM_TILE_CACHE_H
10036
10037+#include <linux/const.h>
10038 #include <arch/chip.h>
10039
10040 /* bytes per L1 data cache line */
10041 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10042-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10043+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10044
10045 /* bytes per L2 cache line */
10046 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10047diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10048index 8a082bc..7a6bf87 100644
10049--- a/arch/tile/include/asm/uaccess.h
10050+++ b/arch/tile/include/asm/uaccess.h
10051@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10052 const void __user *from,
10053 unsigned long n)
10054 {
10055- int sz = __compiletime_object_size(to);
10056+ size_t sz = __compiletime_object_size(to);
10057
10058- if (likely(sz == -1 || sz >= n))
10059+ if (likely(sz == (size_t)-1 || sz >= n))
10060 n = _copy_from_user(to, from, n);
10061 else
10062 copy_from_user_overflow();
10063diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
10064index 650ccff..45fe2d6 100644
10065--- a/arch/tile/mm/hugetlbpage.c
10066+++ b/arch/tile/mm/hugetlbpage.c
10067@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
10068 info.high_limit = TASK_SIZE;
10069 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10070 info.align_offset = 0;
10071+ info.threadstack_offset = 0;
10072 return vm_unmapped_area(&info);
10073 }
10074
10075@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
10076 info.high_limit = current->mm->mmap_base;
10077 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10078 info.align_offset = 0;
10079+ info.threadstack_offset = 0;
10080 addr = vm_unmapped_area(&info);
10081
10082 /*
10083diff --git a/arch/um/Makefile b/arch/um/Makefile
10084index 133f7de..1d6f2f1 100644
10085--- a/arch/um/Makefile
10086+++ b/arch/um/Makefile
10087@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10088 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10089 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10090
10091+ifdef CONSTIFY_PLUGIN
10092+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10093+endif
10094+
10095 #This will adjust *FLAGS accordingly to the platform.
10096 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10097
10098diff --git a/arch/um/defconfig b/arch/um/defconfig
10099index 08107a7..ab22afe 100644
10100--- a/arch/um/defconfig
10101+++ b/arch/um/defconfig
10102@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10103 CONFIG_X86_L1_CACHE_SHIFT=5
10104 CONFIG_X86_XADD=y
10105 CONFIG_X86_PPRO_FENCE=y
10106-CONFIG_X86_WP_WORKS_OK=y
10107 CONFIG_X86_INVLPG=y
10108 CONFIG_X86_BSWAP=y
10109 CONFIG_X86_POPAD_OK=y
10110diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10111index 19e1bdd..3665b77 100644
10112--- a/arch/um/include/asm/cache.h
10113+++ b/arch/um/include/asm/cache.h
10114@@ -1,6 +1,7 @@
10115 #ifndef __UM_CACHE_H
10116 #define __UM_CACHE_H
10117
10118+#include <linux/const.h>
10119
10120 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10121 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10122@@ -12,6 +13,6 @@
10123 # define L1_CACHE_SHIFT 5
10124 #endif
10125
10126-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10127+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10128
10129 #endif
10130diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10131index 2e0a6b1..a64d0f5 100644
10132--- a/arch/um/include/asm/kmap_types.h
10133+++ b/arch/um/include/asm/kmap_types.h
10134@@ -8,6 +8,6 @@
10135
10136 /* No more #include "asm/arch/kmap_types.h" ! */
10137
10138-#define KM_TYPE_NR 14
10139+#define KM_TYPE_NR 15
10140
10141 #endif
10142diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10143index 5ff53d9..5850cdf 100644
10144--- a/arch/um/include/asm/page.h
10145+++ b/arch/um/include/asm/page.h
10146@@ -14,6 +14,9 @@
10147 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10148 #define PAGE_MASK (~(PAGE_SIZE-1))
10149
10150+#define ktla_ktva(addr) (addr)
10151+#define ktva_ktla(addr) (addr)
10152+
10153 #ifndef __ASSEMBLY__
10154
10155 struct page;
10156diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10157index 0032f92..cd151e0 100644
10158--- a/arch/um/include/asm/pgtable-3level.h
10159+++ b/arch/um/include/asm/pgtable-3level.h
10160@@ -58,6 +58,7 @@
10161 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10162 #define pud_populate(mm, pud, pmd) \
10163 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10164+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10165
10166 #ifdef CONFIG_64BIT
10167 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10168diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10169index bbcef52..6a2a483 100644
10170--- a/arch/um/kernel/process.c
10171+++ b/arch/um/kernel/process.c
10172@@ -367,22 +367,6 @@ int singlestepping(void * t)
10173 return 2;
10174 }
10175
10176-/*
10177- * Only x86 and x86_64 have an arch_align_stack().
10178- * All other arches have "#define arch_align_stack(x) (x)"
10179- * in their asm/system.h
10180- * As this is included in UML from asm-um/system-generic.h,
10181- * we can use it to behave as the subarch does.
10182- */
10183-#ifndef arch_align_stack
10184-unsigned long arch_align_stack(unsigned long sp)
10185-{
10186- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10187- sp -= get_random_int() % 8192;
10188- return sp & ~0xf;
10189-}
10190-#endif
10191-
10192 unsigned long get_wchan(struct task_struct *p)
10193 {
10194 unsigned long stack_page, sp, ip;
10195diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10196index ad8f795..2c7eec6 100644
10197--- a/arch/unicore32/include/asm/cache.h
10198+++ b/arch/unicore32/include/asm/cache.h
10199@@ -12,8 +12,10 @@
10200 #ifndef __UNICORE_CACHE_H__
10201 #define __UNICORE_CACHE_H__
10202
10203-#define L1_CACHE_SHIFT (5)
10204-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10205+#include <linux/const.h>
10206+
10207+#define L1_CACHE_SHIFT 5
10208+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10209
10210 /*
10211 * Memory returned by kmalloc() may be used for DMA, so we must make
10212diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10213index fe120da..24177f7 100644
10214--- a/arch/x86/Kconfig
10215+++ b/arch/x86/Kconfig
10216@@ -239,7 +239,7 @@ config X86_HT
10217
10218 config X86_32_LAZY_GS
10219 def_bool y
10220- depends on X86_32 && !CC_STACKPROTECTOR
10221+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10222
10223 config ARCH_HWEIGHT_CFLAGS
10224 string
10225@@ -1073,6 +1073,7 @@ config MICROCODE_EARLY
10226
10227 config X86_MSR
10228 tristate "/dev/cpu/*/msr - Model-specific register support"
10229+ depends on !GRKERNSEC_KMEM
10230 ---help---
10231 This device gives privileged processes access to the x86
10232 Model-Specific Registers (MSRs). It is a character device with
10233@@ -1096,7 +1097,7 @@ choice
10234
10235 config NOHIGHMEM
10236 bool "off"
10237- depends on !X86_NUMAQ
10238+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10239 ---help---
10240 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10241 However, the address space of 32-bit x86 processors is only 4
10242@@ -1133,7 +1134,7 @@ config NOHIGHMEM
10243
10244 config HIGHMEM4G
10245 bool "4GB"
10246- depends on !X86_NUMAQ
10247+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10248 ---help---
10249 Select this if you have a 32-bit processor and between 1 and 4
10250 gigabytes of physical RAM.
10251@@ -1186,7 +1187,7 @@ config PAGE_OFFSET
10252 hex
10253 default 0xB0000000 if VMSPLIT_3G_OPT
10254 default 0x80000000 if VMSPLIT_2G
10255- default 0x78000000 if VMSPLIT_2G_OPT
10256+ default 0x70000000 if VMSPLIT_2G_OPT
10257 default 0x40000000 if VMSPLIT_1G
10258 default 0xC0000000
10259 depends on X86_32
10260@@ -1584,6 +1585,7 @@ config SECCOMP
10261
10262 config CC_STACKPROTECTOR
10263 bool "Enable -fstack-protector buffer overflow detection"
10264+ depends on X86_64 || !PAX_MEMORY_UDEREF
10265 ---help---
10266 This option turns on the -fstack-protector GCC feature. This
10267 feature puts, at the beginning of functions, a canary value on
10268@@ -1703,6 +1705,8 @@ config X86_NEED_RELOCS
10269 config PHYSICAL_ALIGN
10270 hex "Alignment value to which kernel should be aligned" if X86_32
10271 default "0x1000000"
10272+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10273+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10274 range 0x2000 0x1000000
10275 ---help---
10276 This value puts the alignment restrictions on physical address
10277@@ -1778,9 +1782,10 @@ config DEBUG_HOTPLUG_CPU0
10278 If unsure, say N.
10279
10280 config COMPAT_VDSO
10281- def_bool y
10282+ def_bool n
10283 prompt "Compat VDSO support"
10284 depends on X86_32 || IA32_EMULATION
10285+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10286 ---help---
10287 Map the 32-bit VDSO to the predictable old-style address too.
10288
10289diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10290index c026cca..14657ae 100644
10291--- a/arch/x86/Kconfig.cpu
10292+++ b/arch/x86/Kconfig.cpu
10293@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10294
10295 config X86_F00F_BUG
10296 def_bool y
10297- depends on M586MMX || M586TSC || M586 || M486
10298+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10299
10300 config X86_INVD_BUG
10301 def_bool y
10302@@ -327,7 +327,7 @@ config X86_INVD_BUG
10303
10304 config X86_ALIGNMENT_16
10305 def_bool y
10306- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10307+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10308
10309 config X86_INTEL_USERCOPY
10310 def_bool y
10311@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10312 # generates cmov.
10313 config X86_CMOV
10314 def_bool y
10315- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10316+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10317
10318 config X86_MINIMUM_CPU_FAMILY
10319 int
10320diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10321index c198b7e..63eea60 100644
10322--- a/arch/x86/Kconfig.debug
10323+++ b/arch/x86/Kconfig.debug
10324@@ -84,7 +84,7 @@ config X86_PTDUMP
10325 config DEBUG_RODATA
10326 bool "Write protect kernel read-only data structures"
10327 default y
10328- depends on DEBUG_KERNEL
10329+ depends on DEBUG_KERNEL && BROKEN
10330 ---help---
10331 Mark the kernel read-only data as write-protected in the pagetables,
10332 in order to catch accidental (and incorrect) writes to such const
10333@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10334
10335 config DEBUG_SET_MODULE_RONX
10336 bool "Set loadable kernel module data as NX and text as RO"
10337- depends on MODULES
10338+ depends on MODULES && BROKEN
10339 ---help---
10340 This option helps catch unintended modifications to loadable
10341 kernel module's text and read-only data. It also prevents execution
10342diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10343index 5c47726..8c4fa67 100644
10344--- a/arch/x86/Makefile
10345+++ b/arch/x86/Makefile
10346@@ -54,6 +54,7 @@ else
10347 UTS_MACHINE := x86_64
10348 CHECKFLAGS += -D__x86_64__ -m64
10349
10350+ biarch := $(call cc-option,-m64)
10351 KBUILD_AFLAGS += -m64
10352 KBUILD_CFLAGS += -m64
10353
10354@@ -234,3 +235,12 @@ define archhelp
10355 echo ' FDARGS="..." arguments for the booted kernel'
10356 echo ' FDINITRD=file initrd for the booted kernel'
10357 endef
10358+
10359+define OLD_LD
10360+
10361+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10362+*** Please upgrade your binutils to 2.18 or newer
10363+endef
10364+
10365+archprepare:
10366+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10367diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10368index 379814b..add62ce 100644
10369--- a/arch/x86/boot/Makefile
10370+++ b/arch/x86/boot/Makefile
10371@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10372 $(call cc-option, -fno-stack-protector) \
10373 $(call cc-option, -mpreferred-stack-boundary=2)
10374 KBUILD_CFLAGS += $(call cc-option, -m32)
10375+ifdef CONSTIFY_PLUGIN
10376+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10377+endif
10378 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10379 GCOV_PROFILE := n
10380
10381diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10382index 878e4b9..20537ab 100644
10383--- a/arch/x86/boot/bitops.h
10384+++ b/arch/x86/boot/bitops.h
10385@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10386 u8 v;
10387 const u32 *p = (const u32 *)addr;
10388
10389- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10390+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10391 return v;
10392 }
10393
10394@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10395
10396 static inline void set_bit(int nr, void *addr)
10397 {
10398- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10399+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10400 }
10401
10402 #endif /* BOOT_BITOPS_H */
10403diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10404index 5b75319..331a4ca 100644
10405--- a/arch/x86/boot/boot.h
10406+++ b/arch/x86/boot/boot.h
10407@@ -85,7 +85,7 @@ static inline void io_delay(void)
10408 static inline u16 ds(void)
10409 {
10410 u16 seg;
10411- asm("movw %%ds,%0" : "=rm" (seg));
10412+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10413 return seg;
10414 }
10415
10416@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10417 static inline int memcmp(const void *s1, const void *s2, size_t len)
10418 {
10419 u8 diff;
10420- asm("repe; cmpsb; setnz %0"
10421+ asm volatile("repe; cmpsb; setnz %0"
10422 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10423 return diff;
10424 }
10425diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10426index 5ef205c..342191d 100644
10427--- a/arch/x86/boot/compressed/Makefile
10428+++ b/arch/x86/boot/compressed/Makefile
10429@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10430 KBUILD_CFLAGS += $(cflags-y)
10431 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10432 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10433+ifdef CONSTIFY_PLUGIN
10434+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10435+endif
10436
10437 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10438 GCOV_PROFILE := n
10439diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10440index c205035..5853587 100644
10441--- a/arch/x86/boot/compressed/eboot.c
10442+++ b/arch/x86/boot/compressed/eboot.c
10443@@ -150,7 +150,6 @@ again:
10444 *addr = max_addr;
10445 }
10446
10447-free_pool:
10448 efi_call_phys1(sys_table->boottime->free_pool, map);
10449
10450 fail:
10451@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10452 if (i == map_size / desc_size)
10453 status = EFI_NOT_FOUND;
10454
10455-free_pool:
10456 efi_call_phys1(sys_table->boottime->free_pool, map);
10457 fail:
10458 return status;
10459diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
10460index a53440e..c3dbf1e 100644
10461--- a/arch/x86/boot/compressed/efi_stub_32.S
10462+++ b/arch/x86/boot/compressed/efi_stub_32.S
10463@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
10464 * parameter 2, ..., param n. To make things easy, we save the return
10465 * address of efi_call_phys in a global variable.
10466 */
10467- popl %ecx
10468- movl %ecx, saved_return_addr(%edx)
10469- /* get the function pointer into ECX*/
10470- popl %ecx
10471- movl %ecx, efi_rt_function_ptr(%edx)
10472+ popl saved_return_addr(%edx)
10473+ popl efi_rt_function_ptr(%edx)
10474
10475 /*
10476 * 3. Call the physical function.
10477 */
10478- call *%ecx
10479+ call *efi_rt_function_ptr(%edx)
10480
10481 /*
10482 * 4. Balance the stack. And because EAX contain the return value,
10483@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
10484 1: popl %edx
10485 subl $1b, %edx
10486
10487- movl efi_rt_function_ptr(%edx), %ecx
10488- pushl %ecx
10489+ pushl efi_rt_function_ptr(%edx)
10490
10491 /*
10492 * 10. Push the saved return address onto the stack and return.
10493 */
10494- movl saved_return_addr(%edx), %ecx
10495- pushl %ecx
10496- ret
10497+ jmpl *saved_return_addr(%edx)
10498 ENDPROC(efi_call_phys)
10499 .previous
10500
10501diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10502index 1e3184f..0d11e2e 100644
10503--- a/arch/x86/boot/compressed/head_32.S
10504+++ b/arch/x86/boot/compressed/head_32.S
10505@@ -118,7 +118,7 @@ preferred_addr:
10506 notl %eax
10507 andl %eax, %ebx
10508 #else
10509- movl $LOAD_PHYSICAL_ADDR, %ebx
10510+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10511 #endif
10512
10513 /* Target address to relocate to for decompression */
10514@@ -204,7 +204,7 @@ relocated:
10515 * and where it was actually loaded.
10516 */
10517 movl %ebp, %ebx
10518- subl $LOAD_PHYSICAL_ADDR, %ebx
10519+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10520 jz 2f /* Nothing to be done if loaded at compiled addr. */
10521 /*
10522 * Process relocations.
10523@@ -212,8 +212,7 @@ relocated:
10524
10525 1: subl $4, %edi
10526 movl (%edi), %ecx
10527- testl %ecx, %ecx
10528- jz 2f
10529+ jecxz 2f
10530 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10531 jmp 1b
10532 2:
10533diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10534index 16f24e6..47491a3 100644
10535--- a/arch/x86/boot/compressed/head_64.S
10536+++ b/arch/x86/boot/compressed/head_64.S
10537@@ -97,7 +97,7 @@ ENTRY(startup_32)
10538 notl %eax
10539 andl %eax, %ebx
10540 #else
10541- movl $LOAD_PHYSICAL_ADDR, %ebx
10542+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10543 #endif
10544
10545 /* Target address to relocate to for decompression */
10546@@ -272,7 +272,7 @@ preferred_addr:
10547 notq %rax
10548 andq %rax, %rbp
10549 #else
10550- movq $LOAD_PHYSICAL_ADDR, %rbp
10551+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10552 #endif
10553
10554 /* Target address to relocate to for decompression */
10555@@ -363,8 +363,8 @@ gdt:
10556 .long gdt
10557 .word 0
10558 .quad 0x0000000000000000 /* NULL descriptor */
10559- .quad 0x00af9a000000ffff /* __KERNEL_CS */
10560- .quad 0x00cf92000000ffff /* __KERNEL_DS */
10561+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
10562+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
10563 .quad 0x0080890000000000 /* TS descriptor */
10564 .quad 0x0000000000000000 /* TS continued */
10565 gdt_end:
10566diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10567index 7cb56c6..d382d84 100644
10568--- a/arch/x86/boot/compressed/misc.c
10569+++ b/arch/x86/boot/compressed/misc.c
10570@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10571 case PT_LOAD:
10572 #ifdef CONFIG_RELOCATABLE
10573 dest = output;
10574- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10575+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10576 #else
10577 dest = (void *)(phdr->p_paddr);
10578 #endif
10579@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10580 error("Destination address too large");
10581 #endif
10582 #ifndef CONFIG_RELOCATABLE
10583- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10584+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10585 error("Wrong destination address");
10586 #endif
10587
10588diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10589index 4d3ff03..e4972ff 100644
10590--- a/arch/x86/boot/cpucheck.c
10591+++ b/arch/x86/boot/cpucheck.c
10592@@ -74,7 +74,7 @@ static int has_fpu(void)
10593 u16 fcw = -1, fsw = -1;
10594 u32 cr0;
10595
10596- asm("movl %%cr0,%0" : "=r" (cr0));
10597+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10598 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10599 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10600 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10601@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10602 {
10603 u32 f0, f1;
10604
10605- asm("pushfl ; "
10606+ asm volatile("pushfl ; "
10607 "pushfl ; "
10608 "popl %0 ; "
10609 "movl %0,%1 ; "
10610@@ -115,7 +115,7 @@ static void get_flags(void)
10611 set_bit(X86_FEATURE_FPU, cpu.flags);
10612
10613 if (has_eflag(X86_EFLAGS_ID)) {
10614- asm("cpuid"
10615+ asm volatile("cpuid"
10616 : "=a" (max_intel_level),
10617 "=b" (cpu_vendor[0]),
10618 "=d" (cpu_vendor[1]),
10619@@ -124,7 +124,7 @@ static void get_flags(void)
10620
10621 if (max_intel_level >= 0x00000001 &&
10622 max_intel_level <= 0x0000ffff) {
10623- asm("cpuid"
10624+ asm volatile("cpuid"
10625 : "=a" (tfms),
10626 "=c" (cpu.flags[4]),
10627 "=d" (cpu.flags[0])
10628@@ -136,7 +136,7 @@ static void get_flags(void)
10629 cpu.model += ((tfms >> 16) & 0xf) << 4;
10630 }
10631
10632- asm("cpuid"
10633+ asm volatile("cpuid"
10634 : "=a" (max_amd_level)
10635 : "a" (0x80000000)
10636 : "ebx", "ecx", "edx");
10637@@ -144,7 +144,7 @@ static void get_flags(void)
10638 if (max_amd_level >= 0x80000001 &&
10639 max_amd_level <= 0x8000ffff) {
10640 u32 eax = 0x80000001;
10641- asm("cpuid"
10642+ asm volatile("cpuid"
10643 : "+a" (eax),
10644 "=c" (cpu.flags[6]),
10645 "=d" (cpu.flags[1])
10646@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10647 u32 ecx = MSR_K7_HWCR;
10648 u32 eax, edx;
10649
10650- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10651+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10652 eax &= ~(1 << 15);
10653- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10654+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10655
10656 get_flags(); /* Make sure it really did something */
10657 err = check_flags();
10658@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10659 u32 ecx = MSR_VIA_FCR;
10660 u32 eax, edx;
10661
10662- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10663+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10664 eax |= (1<<1)|(1<<7);
10665- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10666+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10667
10668 set_bit(X86_FEATURE_CX8, cpu.flags);
10669 err = check_flags();
10670@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10671 u32 eax, edx;
10672 u32 level = 1;
10673
10674- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10675- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10676- asm("cpuid"
10677+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10678+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10679+ asm volatile("cpuid"
10680 : "+a" (level), "=d" (cpu.flags[0])
10681 : : "ecx", "ebx");
10682- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10683+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10684
10685 err = check_flags();
10686 }
10687diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10688index 9ec06a1..2c25e79 100644
10689--- a/arch/x86/boot/header.S
10690+++ b/arch/x86/boot/header.S
10691@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10692 # single linked list of
10693 # struct setup_data
10694
10695-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10696+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10697
10698 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10699+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10700+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10701+#else
10702 #define VO_INIT_SIZE (VO__end - VO__text)
10703+#endif
10704 #if ZO_INIT_SIZE > VO_INIT_SIZE
10705 #define INIT_SIZE ZO_INIT_SIZE
10706 #else
10707diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10708index db75d07..8e6d0af 100644
10709--- a/arch/x86/boot/memory.c
10710+++ b/arch/x86/boot/memory.c
10711@@ -19,7 +19,7 @@
10712
10713 static int detect_memory_e820(void)
10714 {
10715- int count = 0;
10716+ unsigned int count = 0;
10717 struct biosregs ireg, oreg;
10718 struct e820entry *desc = boot_params.e820_map;
10719 static struct e820entry buf; /* static so it is zeroed */
10720diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10721index 11e8c6e..fdbb1ed 100644
10722--- a/arch/x86/boot/video-vesa.c
10723+++ b/arch/x86/boot/video-vesa.c
10724@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10725
10726 boot_params.screen_info.vesapm_seg = oreg.es;
10727 boot_params.screen_info.vesapm_off = oreg.di;
10728+ boot_params.screen_info.vesapm_size = oreg.cx;
10729 }
10730
10731 /*
10732diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10733index 43eda28..5ab5fdb 100644
10734--- a/arch/x86/boot/video.c
10735+++ b/arch/x86/boot/video.c
10736@@ -96,7 +96,7 @@ static void store_mode_params(void)
10737 static unsigned int get_entry(void)
10738 {
10739 char entry_buf[4];
10740- int i, len = 0;
10741+ unsigned int i, len = 0;
10742 int key;
10743 unsigned int v;
10744
10745diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10746index 9105655..5e37f27 100644
10747--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10748+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10749@@ -8,6 +8,8 @@
10750 * including this sentence is retained in full.
10751 */
10752
10753+#include <asm/alternative-asm.h>
10754+
10755 .extern crypto_ft_tab
10756 .extern crypto_it_tab
10757 .extern crypto_fl_tab
10758@@ -70,6 +72,8 @@
10759 je B192; \
10760 leaq 32(r9),r9;
10761
10762+#define ret pax_force_retaddr 0, 1; ret
10763+
10764 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10765 movq r1,r2; \
10766 movq r3,r4; \
10767diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10768index 477e9d7..3ab339f 100644
10769--- a/arch/x86/crypto/aesni-intel_asm.S
10770+++ b/arch/x86/crypto/aesni-intel_asm.S
10771@@ -31,6 +31,7 @@
10772
10773 #include <linux/linkage.h>
10774 #include <asm/inst.h>
10775+#include <asm/alternative-asm.h>
10776
10777 #ifdef __x86_64__
10778 .data
10779@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
10780 pop %r14
10781 pop %r13
10782 pop %r12
10783+ pax_force_retaddr 0, 1
10784 ret
10785 ENDPROC(aesni_gcm_dec)
10786
10787@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
10788 pop %r14
10789 pop %r13
10790 pop %r12
10791+ pax_force_retaddr 0, 1
10792 ret
10793 ENDPROC(aesni_gcm_enc)
10794
10795@@ -1722,6 +1725,7 @@ _key_expansion_256a:
10796 pxor %xmm1, %xmm0
10797 movaps %xmm0, (TKEYP)
10798 add $0x10, TKEYP
10799+ pax_force_retaddr_bts
10800 ret
10801 ENDPROC(_key_expansion_128)
10802 ENDPROC(_key_expansion_256a)
10803@@ -1748,6 +1752,7 @@ _key_expansion_192a:
10804 shufps $0b01001110, %xmm2, %xmm1
10805 movaps %xmm1, 0x10(TKEYP)
10806 add $0x20, TKEYP
10807+ pax_force_retaddr_bts
10808 ret
10809 ENDPROC(_key_expansion_192a)
10810
10811@@ -1768,6 +1773,7 @@ _key_expansion_192b:
10812
10813 movaps %xmm0, (TKEYP)
10814 add $0x10, TKEYP
10815+ pax_force_retaddr_bts
10816 ret
10817 ENDPROC(_key_expansion_192b)
10818
10819@@ -1781,6 +1787,7 @@ _key_expansion_256b:
10820 pxor %xmm1, %xmm2
10821 movaps %xmm2, (TKEYP)
10822 add $0x10, TKEYP
10823+ pax_force_retaddr_bts
10824 ret
10825 ENDPROC(_key_expansion_256b)
10826
10827@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
10828 #ifndef __x86_64__
10829 popl KEYP
10830 #endif
10831+ pax_force_retaddr 0, 1
10832 ret
10833 ENDPROC(aesni_set_key)
10834
10835@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
10836 popl KLEN
10837 popl KEYP
10838 #endif
10839+ pax_force_retaddr 0, 1
10840 ret
10841 ENDPROC(aesni_enc)
10842
10843@@ -1974,6 +1983,7 @@ _aesni_enc1:
10844 AESENC KEY STATE
10845 movaps 0x70(TKEYP), KEY
10846 AESENCLAST KEY STATE
10847+ pax_force_retaddr_bts
10848 ret
10849 ENDPROC(_aesni_enc1)
10850
10851@@ -2083,6 +2093,7 @@ _aesni_enc4:
10852 AESENCLAST KEY STATE2
10853 AESENCLAST KEY STATE3
10854 AESENCLAST KEY STATE4
10855+ pax_force_retaddr_bts
10856 ret
10857 ENDPROC(_aesni_enc4)
10858
10859@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
10860 popl KLEN
10861 popl KEYP
10862 #endif
10863+ pax_force_retaddr 0, 1
10864 ret
10865 ENDPROC(aesni_dec)
10866
10867@@ -2164,6 +2176,7 @@ _aesni_dec1:
10868 AESDEC KEY STATE
10869 movaps 0x70(TKEYP), KEY
10870 AESDECLAST KEY STATE
10871+ pax_force_retaddr_bts
10872 ret
10873 ENDPROC(_aesni_dec1)
10874
10875@@ -2273,6 +2286,7 @@ _aesni_dec4:
10876 AESDECLAST KEY STATE2
10877 AESDECLAST KEY STATE3
10878 AESDECLAST KEY STATE4
10879+ pax_force_retaddr_bts
10880 ret
10881 ENDPROC(_aesni_dec4)
10882
10883@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
10884 popl KEYP
10885 popl LEN
10886 #endif
10887+ pax_force_retaddr 0, 1
10888 ret
10889 ENDPROC(aesni_ecb_enc)
10890
10891@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
10892 popl KEYP
10893 popl LEN
10894 #endif
10895+ pax_force_retaddr 0, 1
10896 ret
10897 ENDPROC(aesni_ecb_dec)
10898
10899@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
10900 popl LEN
10901 popl IVP
10902 #endif
10903+ pax_force_retaddr 0, 1
10904 ret
10905 ENDPROC(aesni_cbc_enc)
10906
10907@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
10908 popl LEN
10909 popl IVP
10910 #endif
10911+ pax_force_retaddr 0, 1
10912 ret
10913 ENDPROC(aesni_cbc_dec)
10914
10915@@ -2550,6 +2568,7 @@ _aesni_inc_init:
10916 mov $1, TCTR_LOW
10917 MOVQ_R64_XMM TCTR_LOW INC
10918 MOVQ_R64_XMM CTR TCTR_LOW
10919+ pax_force_retaddr_bts
10920 ret
10921 ENDPROC(_aesni_inc_init)
10922
10923@@ -2579,6 +2598,7 @@ _aesni_inc:
10924 .Linc_low:
10925 movaps CTR, IV
10926 PSHUFB_XMM BSWAP_MASK IV
10927+ pax_force_retaddr_bts
10928 ret
10929 ENDPROC(_aesni_inc)
10930
10931@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
10932 .Lctr_enc_ret:
10933 movups IV, (IVP)
10934 .Lctr_enc_just_ret:
10935+ pax_force_retaddr 0, 1
10936 ret
10937 ENDPROC(aesni_ctr_enc)
10938
10939@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
10940 pxor INC, STATE4
10941 movdqu STATE4, 0x70(OUTP)
10942
10943+ pax_force_retaddr 0, 1
10944 ret
10945 ENDPROC(aesni_xts_crypt8)
10946
10947diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10948index 246c670..4d1ed00 100644
10949--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10950+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10951@@ -21,6 +21,7 @@
10952 */
10953
10954 #include <linux/linkage.h>
10955+#include <asm/alternative-asm.h>
10956
10957 .file "blowfish-x86_64-asm.S"
10958 .text
10959@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
10960 jnz .L__enc_xor;
10961
10962 write_block();
10963+ pax_force_retaddr 0, 1
10964 ret;
10965 .L__enc_xor:
10966 xor_block();
10967+ pax_force_retaddr 0, 1
10968 ret;
10969 ENDPROC(__blowfish_enc_blk)
10970
10971@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
10972
10973 movq %r11, %rbp;
10974
10975+ pax_force_retaddr 0, 1
10976 ret;
10977 ENDPROC(blowfish_dec_blk)
10978
10979@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
10980
10981 popq %rbx;
10982 popq %rbp;
10983+ pax_force_retaddr 0, 1
10984 ret;
10985
10986 .L__enc_xor4:
10987@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
10988
10989 popq %rbx;
10990 popq %rbp;
10991+ pax_force_retaddr 0, 1
10992 ret;
10993 ENDPROC(__blowfish_enc_blk_4way)
10994
10995@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
10996 popq %rbx;
10997 popq %rbp;
10998
10999+ pax_force_retaddr 0, 1
11000 ret;
11001 ENDPROC(blowfish_dec_blk_4way)
11002diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11003index 310319c..ce174a4 100644
11004--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11005+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11006@@ -21,6 +21,7 @@
11007 */
11008
11009 #include <linux/linkage.h>
11010+#include <asm/alternative-asm.h>
11011
11012 .file "camellia-x86_64-asm_64.S"
11013 .text
11014@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
11015 enc_outunpack(mov, RT1);
11016
11017 movq RRBP, %rbp;
11018+ pax_force_retaddr 0, 1
11019 ret;
11020
11021 .L__enc_xor:
11022 enc_outunpack(xor, RT1);
11023
11024 movq RRBP, %rbp;
11025+ pax_force_retaddr 0, 1
11026 ret;
11027 ENDPROC(__camellia_enc_blk)
11028
11029@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
11030 dec_outunpack();
11031
11032 movq RRBP, %rbp;
11033+ pax_force_retaddr 0, 1
11034 ret;
11035 ENDPROC(camellia_dec_blk)
11036
11037@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
11038
11039 movq RRBP, %rbp;
11040 popq %rbx;
11041+ pax_force_retaddr 0, 1
11042 ret;
11043
11044 .L__enc2_xor:
11045@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
11046
11047 movq RRBP, %rbp;
11048 popq %rbx;
11049+ pax_force_retaddr 0, 1
11050 ret;
11051 ENDPROC(__camellia_enc_blk_2way)
11052
11053@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
11054
11055 movq RRBP, %rbp;
11056 movq RXOR, %rbx;
11057+ pax_force_retaddr 0, 1
11058 ret;
11059 ENDPROC(camellia_dec_blk_2way)
11060diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11061index c35fd5d..c1ee236 100644
11062--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11063+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11064@@ -24,6 +24,7 @@
11065 */
11066
11067 #include <linux/linkage.h>
11068+#include <asm/alternative-asm.h>
11069
11070 .file "cast5-avx-x86_64-asm_64.S"
11071
11072@@ -281,6 +282,7 @@ __cast5_enc_blk16:
11073 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11074 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11075
11076+ pax_force_retaddr 0, 1
11077 ret;
11078 ENDPROC(__cast5_enc_blk16)
11079
11080@@ -352,6 +354,7 @@ __cast5_dec_blk16:
11081 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11082 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11083
11084+ pax_force_retaddr 0, 1
11085 ret;
11086
11087 .L__skip_dec:
11088@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
11089 vmovdqu RR4, (6*4*4)(%r11);
11090 vmovdqu RL4, (7*4*4)(%r11);
11091
11092+ pax_force_retaddr
11093 ret;
11094 ENDPROC(cast5_ecb_enc_16way)
11095
11096@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
11097 vmovdqu RR4, (6*4*4)(%r11);
11098 vmovdqu RL4, (7*4*4)(%r11);
11099
11100+ pax_force_retaddr
11101 ret;
11102 ENDPROC(cast5_ecb_dec_16way)
11103
11104@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
11105
11106 popq %r12;
11107
11108+ pax_force_retaddr
11109 ret;
11110 ENDPROC(cast5_cbc_dec_16way)
11111
11112@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
11113
11114 popq %r12;
11115
11116+ pax_force_retaddr
11117 ret;
11118 ENDPROC(cast5_ctr_16way)
11119diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11120index e3531f8..18ded3a 100644
11121--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11122+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11123@@ -24,6 +24,7 @@
11124 */
11125
11126 #include <linux/linkage.h>
11127+#include <asm/alternative-asm.h>
11128 #include "glue_helper-asm-avx.S"
11129
11130 .file "cast6-avx-x86_64-asm_64.S"
11131@@ -295,6 +296,7 @@ __cast6_enc_blk8:
11132 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11133 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11134
11135+ pax_force_retaddr 0, 1
11136 ret;
11137 ENDPROC(__cast6_enc_blk8)
11138
11139@@ -340,6 +342,7 @@ __cast6_dec_blk8:
11140 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11141 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11142
11143+ pax_force_retaddr 0, 1
11144 ret;
11145 ENDPROC(__cast6_dec_blk8)
11146
11147@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
11148
11149 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11150
11151+ pax_force_retaddr
11152 ret;
11153 ENDPROC(cast6_ecb_enc_8way)
11154
11155@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
11156
11157 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11158
11159+ pax_force_retaddr
11160 ret;
11161 ENDPROC(cast6_ecb_dec_8way)
11162
11163@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
11164
11165 popq %r12;
11166
11167+ pax_force_retaddr
11168 ret;
11169 ENDPROC(cast6_cbc_dec_8way)
11170
11171@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
11172
11173 popq %r12;
11174
11175+ pax_force_retaddr
11176 ret;
11177 ENDPROC(cast6_ctr_8way)
11178
11179@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
11180 /* dst <= regs xor IVs(in dst) */
11181 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11182
11183+ pax_force_retaddr
11184 ret;
11185 ENDPROC(cast6_xts_enc_8way)
11186
11187@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
11188 /* dst <= regs xor IVs(in dst) */
11189 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11190
11191+ pax_force_retaddr
11192 ret;
11193 ENDPROC(cast6_xts_dec_8way)
11194diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11195index 9279e0b..9270820 100644
11196--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11197+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11198@@ -1,4 +1,5 @@
11199 #include <linux/linkage.h>
11200+#include <asm/alternative-asm.h>
11201
11202 # enter salsa20_encrypt_bytes
11203 ENTRY(salsa20_encrypt_bytes)
11204@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
11205 add %r11,%rsp
11206 mov %rdi,%rax
11207 mov %rsi,%rdx
11208+ pax_force_retaddr 0, 1
11209 ret
11210 # bytesatleast65:
11211 ._bytesatleast65:
11212@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
11213 add %r11,%rsp
11214 mov %rdi,%rax
11215 mov %rsi,%rdx
11216+ pax_force_retaddr
11217 ret
11218 ENDPROC(salsa20_keysetup)
11219
11220@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
11221 add %r11,%rsp
11222 mov %rdi,%rax
11223 mov %rsi,%rdx
11224+ pax_force_retaddr
11225 ret
11226 ENDPROC(salsa20_ivsetup)
11227diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11228index 2f202f4..d9164d6 100644
11229--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11230+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11231@@ -24,6 +24,7 @@
11232 */
11233
11234 #include <linux/linkage.h>
11235+#include <asm/alternative-asm.h>
11236 #include "glue_helper-asm-avx.S"
11237
11238 .file "serpent-avx-x86_64-asm_64.S"
11239@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
11240 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11241 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11242
11243+ pax_force_retaddr
11244 ret;
11245 ENDPROC(__serpent_enc_blk8_avx)
11246
11247@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
11248 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11249 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11250
11251+ pax_force_retaddr
11252 ret;
11253 ENDPROC(__serpent_dec_blk8_avx)
11254
11255@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
11256
11257 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11258
11259+ pax_force_retaddr
11260 ret;
11261 ENDPROC(serpent_ecb_enc_8way_avx)
11262
11263@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
11264
11265 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11266
11267+ pax_force_retaddr
11268 ret;
11269 ENDPROC(serpent_ecb_dec_8way_avx)
11270
11271@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
11272
11273 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11274
11275+ pax_force_retaddr
11276 ret;
11277 ENDPROC(serpent_cbc_dec_8way_avx)
11278
11279@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
11280
11281 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11282
11283+ pax_force_retaddr
11284 ret;
11285 ENDPROC(serpent_ctr_8way_avx)
11286
11287@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
11288 /* dst <= regs xor IVs(in dst) */
11289 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11290
11291+ pax_force_retaddr
11292 ret;
11293 ENDPROC(serpent_xts_enc_8way_avx)
11294
11295@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
11296 /* dst <= regs xor IVs(in dst) */
11297 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11298
11299+ pax_force_retaddr
11300 ret;
11301 ENDPROC(serpent_xts_dec_8way_avx)
11302diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11303index acc066c..1559cc4 100644
11304--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11305+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11306@@ -25,6 +25,7 @@
11307 */
11308
11309 #include <linux/linkage.h>
11310+#include <asm/alternative-asm.h>
11311
11312 .file "serpent-sse2-x86_64-asm_64.S"
11313 .text
11314@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
11315 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11316 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11317
11318+ pax_force_retaddr
11319 ret;
11320
11321 .L__enc_xor8:
11322 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11323 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11324
11325+ pax_force_retaddr
11326 ret;
11327 ENDPROC(__serpent_enc_blk_8way)
11328
11329@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
11330 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11331 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11332
11333+ pax_force_retaddr
11334 ret;
11335 ENDPROC(serpent_dec_blk_8way)
11336diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11337index a410950..3356d42 100644
11338--- a/arch/x86/crypto/sha1_ssse3_asm.S
11339+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11340@@ -29,6 +29,7 @@
11341 */
11342
11343 #include <linux/linkage.h>
11344+#include <asm/alternative-asm.h>
11345
11346 #define CTX %rdi // arg1
11347 #define BUF %rsi // arg2
11348@@ -104,6 +105,7 @@
11349 pop %r12
11350 pop %rbp
11351 pop %rbx
11352+ pax_force_retaddr 0, 1
11353 ret
11354
11355 ENDPROC(\name)
11356diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11357index 0505813..63b1d00 100644
11358--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11359+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11360@@ -24,6 +24,7 @@
11361 */
11362
11363 #include <linux/linkage.h>
11364+#include <asm/alternative-asm.h>
11365 #include "glue_helper-asm-avx.S"
11366
11367 .file "twofish-avx-x86_64-asm_64.S"
11368@@ -284,6 +285,7 @@ __twofish_enc_blk8:
11369 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11370 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11371
11372+ pax_force_retaddr 0, 1
11373 ret;
11374 ENDPROC(__twofish_enc_blk8)
11375
11376@@ -324,6 +326,7 @@ __twofish_dec_blk8:
11377 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11378 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11379
11380+ pax_force_retaddr 0, 1
11381 ret;
11382 ENDPROC(__twofish_dec_blk8)
11383
11384@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
11385
11386 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11387
11388+ pax_force_retaddr 0, 1
11389 ret;
11390 ENDPROC(twofish_ecb_enc_8way)
11391
11392@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
11393
11394 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11395
11396+ pax_force_retaddr 0, 1
11397 ret;
11398 ENDPROC(twofish_ecb_dec_8way)
11399
11400@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
11401
11402 popq %r12;
11403
11404+ pax_force_retaddr 0, 1
11405 ret;
11406 ENDPROC(twofish_cbc_dec_8way)
11407
11408@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
11409
11410 popq %r12;
11411
11412+ pax_force_retaddr 0, 1
11413 ret;
11414 ENDPROC(twofish_ctr_8way)
11415
11416@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
11417 /* dst <= regs xor IVs(in dst) */
11418 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11419
11420+ pax_force_retaddr 0, 1
11421 ret;
11422 ENDPROC(twofish_xts_enc_8way)
11423
11424@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
11425 /* dst <= regs xor IVs(in dst) */
11426 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11427
11428+ pax_force_retaddr 0, 1
11429 ret;
11430 ENDPROC(twofish_xts_dec_8way)
11431diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11432index 1c3b7ce..b365c5e 100644
11433--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11434+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11435@@ -21,6 +21,7 @@
11436 */
11437
11438 #include <linux/linkage.h>
11439+#include <asm/alternative-asm.h>
11440
11441 .file "twofish-x86_64-asm-3way.S"
11442 .text
11443@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
11444 popq %r13;
11445 popq %r14;
11446 popq %r15;
11447+ pax_force_retaddr 0, 1
11448 ret;
11449
11450 .L__enc_xor3:
11451@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
11452 popq %r13;
11453 popq %r14;
11454 popq %r15;
11455+ pax_force_retaddr 0, 1
11456 ret;
11457 ENDPROC(__twofish_enc_blk_3way)
11458
11459@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
11460 popq %r13;
11461 popq %r14;
11462 popq %r15;
11463+ pax_force_retaddr 0, 1
11464 ret;
11465 ENDPROC(twofish_dec_blk_3way)
11466diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11467index a039d21..29e7615 100644
11468--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11469+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11470@@ -22,6 +22,7 @@
11471
11472 #include <linux/linkage.h>
11473 #include <asm/asm-offsets.h>
11474+#include <asm/alternative-asm.h>
11475
11476 #define a_offset 0
11477 #define b_offset 4
11478@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
11479
11480 popq R1
11481 movq $1,%rax
11482+ pax_force_retaddr 0, 1
11483 ret
11484 ENDPROC(twofish_enc_blk)
11485
11486@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
11487
11488 popq R1
11489 movq $1,%rax
11490+ pax_force_retaddr 0, 1
11491 ret
11492 ENDPROC(twofish_dec_blk)
11493diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11494index 52ff81c..98af645 100644
11495--- a/arch/x86/ia32/ia32_aout.c
11496+++ b/arch/x86/ia32/ia32_aout.c
11497@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11498 unsigned long dump_start, dump_size;
11499 struct user32 dump;
11500
11501+ memset(&dump, 0, sizeof(dump));
11502+
11503 fs = get_fs();
11504 set_fs(KERNEL_DS);
11505 has_dumped = 1;
11506diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11507index cf1a471..3bc4cf8 100644
11508--- a/arch/x86/ia32/ia32_signal.c
11509+++ b/arch/x86/ia32/ia32_signal.c
11510@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
11511 sp -= frame_size;
11512 /* Align the stack pointer according to the i386 ABI,
11513 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11514- sp = ((sp + 4) & -16ul) - 4;
11515+ sp = ((sp - 12) & -16ul) - 4;
11516 return (void __user *) sp;
11517 }
11518
11519@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
11520 * These are actually not used anymore, but left because some
11521 * gdb versions depend on them as a marker.
11522 */
11523- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11524+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11525 } put_user_catch(err);
11526
11527 if (err)
11528@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11529 0xb8,
11530 __NR_ia32_rt_sigreturn,
11531 0x80cd,
11532- 0,
11533+ 0
11534 };
11535
11536 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
11537@@ -463,16 +463,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11538
11539 if (ksig->ka.sa.sa_flags & SA_RESTORER)
11540 restorer = ksig->ka.sa.sa_restorer;
11541+ else if (current->mm->context.vdso)
11542+ /* Return stub is in 32bit vsyscall page */
11543+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11544 else
11545- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11546- rt_sigreturn);
11547+ restorer = &frame->retcode;
11548 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11549
11550 /*
11551 * Not actually used anymore, but left because some gdb
11552 * versions need it.
11553 */
11554- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11555+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11556 } put_user_catch(err);
11557
11558 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
11559diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11560index 474dc1b..24aaa3e 100644
11561--- a/arch/x86/ia32/ia32entry.S
11562+++ b/arch/x86/ia32/ia32entry.S
11563@@ -15,8 +15,10 @@
11564 #include <asm/irqflags.h>
11565 #include <asm/asm.h>
11566 #include <asm/smap.h>
11567+#include <asm/pgtable.h>
11568 #include <linux/linkage.h>
11569 #include <linux/err.h>
11570+#include <asm/alternative-asm.h>
11571
11572 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11573 #include <linux/elf-em.h>
11574@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11575 ENDPROC(native_irq_enable_sysexit)
11576 #endif
11577
11578+ .macro pax_enter_kernel_user
11579+ pax_set_fptr_mask
11580+#ifdef CONFIG_PAX_MEMORY_UDEREF
11581+ call pax_enter_kernel_user
11582+#endif
11583+ .endm
11584+
11585+ .macro pax_exit_kernel_user
11586+#ifdef CONFIG_PAX_MEMORY_UDEREF
11587+ call pax_exit_kernel_user
11588+#endif
11589+#ifdef CONFIG_PAX_RANDKSTACK
11590+ pushq %rax
11591+ pushq %r11
11592+ call pax_randomize_kstack
11593+ popq %r11
11594+ popq %rax
11595+#endif
11596+ .endm
11597+
11598+ .macro pax_erase_kstack
11599+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11600+ call pax_erase_kstack
11601+#endif
11602+ .endm
11603+
11604 /*
11605 * 32bit SYSENTER instruction entry.
11606 *
11607@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11608 CFI_REGISTER rsp,rbp
11609 SWAPGS_UNSAFE_STACK
11610 movq PER_CPU_VAR(kernel_stack), %rsp
11611- addq $(KERNEL_STACK_OFFSET),%rsp
11612- /*
11613- * No need to follow this irqs on/off section: the syscall
11614- * disabled irqs, here we enable it straight after entry:
11615- */
11616- ENABLE_INTERRUPTS(CLBR_NONE)
11617 movl %ebp,%ebp /* zero extension */
11618 pushq_cfi $__USER32_DS
11619 /*CFI_REL_OFFSET ss,0*/
11620@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11621 CFI_REL_OFFSET rsp,0
11622 pushfq_cfi
11623 /*CFI_REL_OFFSET rflags,0*/
11624- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11625- CFI_REGISTER rip,r10
11626+ orl $X86_EFLAGS_IF,(%rsp)
11627+ GET_THREAD_INFO(%r11)
11628+ movl TI_sysenter_return(%r11), %r11d
11629+ CFI_REGISTER rip,r11
11630 pushq_cfi $__USER32_CS
11631 /*CFI_REL_OFFSET cs,0*/
11632 movl %eax, %eax
11633- pushq_cfi %r10
11634+ pushq_cfi %r11
11635 CFI_REL_OFFSET rip,0
11636 pushq_cfi %rax
11637 cld
11638 SAVE_ARGS 0,1,0
11639+ pax_enter_kernel_user
11640+
11641+#ifdef CONFIG_PAX_RANDKSTACK
11642+ pax_erase_kstack
11643+#endif
11644+
11645+ /*
11646+ * No need to follow this irqs on/off section: the syscall
11647+ * disabled irqs, here we enable it straight after entry:
11648+ */
11649+ ENABLE_INTERRUPTS(CLBR_NONE)
11650 /* no need to do an access_ok check here because rbp has been
11651 32bit zero extended */
11652+
11653+#ifdef CONFIG_PAX_MEMORY_UDEREF
11654+ mov pax_user_shadow_base,%r11
11655+ add %r11,%rbp
11656+#endif
11657+
11658 ASM_STAC
11659 1: movl (%rbp),%ebp
11660 _ASM_EXTABLE(1b,ia32_badarg)
11661 ASM_CLAC
11662- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11663- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11664+ GET_THREAD_INFO(%r11)
11665+ orl $TS_COMPAT,TI_status(%r11)
11666+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11667 CFI_REMEMBER_STATE
11668 jnz sysenter_tracesys
11669 cmpq $(IA32_NR_syscalls-1),%rax
11670@@ -162,12 +204,15 @@ sysenter_do_call:
11671 sysenter_dispatch:
11672 call *ia32_sys_call_table(,%rax,8)
11673 movq %rax,RAX-ARGOFFSET(%rsp)
11674+ GET_THREAD_INFO(%r11)
11675 DISABLE_INTERRUPTS(CLBR_NONE)
11676 TRACE_IRQS_OFF
11677- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11678+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11679 jnz sysexit_audit
11680 sysexit_from_sys_call:
11681- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11682+ pax_exit_kernel_user
11683+ pax_erase_kstack
11684+ andl $~TS_COMPAT,TI_status(%r11)
11685 /* clear IF, that popfq doesn't enable interrupts early */
11686 andl $~0x200,EFLAGS-R11(%rsp)
11687 movl RIP-R11(%rsp),%edx /* User %eip */
11688@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11689 movl %eax,%esi /* 2nd arg: syscall number */
11690 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11691 call __audit_syscall_entry
11692+
11693+ pax_erase_kstack
11694+
11695 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11696 cmpq $(IA32_NR_syscalls-1),%rax
11697 ja ia32_badsys
11698@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11699 .endm
11700
11701 .macro auditsys_exit exit
11702- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11703+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11704 jnz ia32_ret_from_sys_call
11705 TRACE_IRQS_ON
11706 ENABLE_INTERRUPTS(CLBR_NONE)
11707@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11708 1: setbe %al /* 1 if error, 0 if not */
11709 movzbl %al,%edi /* zero-extend that into %edi */
11710 call __audit_syscall_exit
11711+ GET_THREAD_INFO(%r11)
11712 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11713 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11714 DISABLE_INTERRUPTS(CLBR_NONE)
11715 TRACE_IRQS_OFF
11716- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11717+ testl %edi,TI_flags(%r11)
11718 jz \exit
11719 CLEAR_RREGS -ARGOFFSET
11720 jmp int_with_check
11721@@ -237,7 +286,7 @@ sysexit_audit:
11722
11723 sysenter_tracesys:
11724 #ifdef CONFIG_AUDITSYSCALL
11725- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11726+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11727 jz sysenter_auditsys
11728 #endif
11729 SAVE_REST
11730@@ -249,6 +298,9 @@ sysenter_tracesys:
11731 RESTORE_REST
11732 cmpq $(IA32_NR_syscalls-1),%rax
11733 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11734+
11735+ pax_erase_kstack
11736+
11737 jmp sysenter_do_call
11738 CFI_ENDPROC
11739 ENDPROC(ia32_sysenter_target)
11740@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11741 ENTRY(ia32_cstar_target)
11742 CFI_STARTPROC32 simple
11743 CFI_SIGNAL_FRAME
11744- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11745+ CFI_DEF_CFA rsp,0
11746 CFI_REGISTER rip,rcx
11747 /*CFI_REGISTER rflags,r11*/
11748 SWAPGS_UNSAFE_STACK
11749 movl %esp,%r8d
11750 CFI_REGISTER rsp,r8
11751 movq PER_CPU_VAR(kernel_stack),%rsp
11752+ SAVE_ARGS 8*6,0,0
11753+ pax_enter_kernel_user
11754+
11755+#ifdef CONFIG_PAX_RANDKSTACK
11756+ pax_erase_kstack
11757+#endif
11758+
11759 /*
11760 * No need to follow this irqs on/off section: the syscall
11761 * disabled irqs and here we enable it straight after entry:
11762 */
11763 ENABLE_INTERRUPTS(CLBR_NONE)
11764- SAVE_ARGS 8,0,0
11765 movl %eax,%eax /* zero extension */
11766 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11767 movq %rcx,RIP-ARGOFFSET(%rsp)
11768@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11769 /* no need to do an access_ok check here because r8 has been
11770 32bit zero extended */
11771 /* hardware stack frame is complete now */
11772+
11773+#ifdef CONFIG_PAX_MEMORY_UDEREF
11774+ mov pax_user_shadow_base,%r11
11775+ add %r11,%r8
11776+#endif
11777+
11778 ASM_STAC
11779 1: movl (%r8),%r9d
11780 _ASM_EXTABLE(1b,ia32_badarg)
11781 ASM_CLAC
11782- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11783- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11784+ GET_THREAD_INFO(%r11)
11785+ orl $TS_COMPAT,TI_status(%r11)
11786+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11787 CFI_REMEMBER_STATE
11788 jnz cstar_tracesys
11789 cmpq $IA32_NR_syscalls-1,%rax
11790@@ -319,12 +384,15 @@ cstar_do_call:
11791 cstar_dispatch:
11792 call *ia32_sys_call_table(,%rax,8)
11793 movq %rax,RAX-ARGOFFSET(%rsp)
11794+ GET_THREAD_INFO(%r11)
11795 DISABLE_INTERRUPTS(CLBR_NONE)
11796 TRACE_IRQS_OFF
11797- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11798+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11799 jnz sysretl_audit
11800 sysretl_from_sys_call:
11801- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11802+ pax_exit_kernel_user
11803+ pax_erase_kstack
11804+ andl $~TS_COMPAT,TI_status(%r11)
11805 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11806 movl RIP-ARGOFFSET(%rsp),%ecx
11807 CFI_REGISTER rip,rcx
11808@@ -352,7 +420,7 @@ sysretl_audit:
11809
11810 cstar_tracesys:
11811 #ifdef CONFIG_AUDITSYSCALL
11812- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11813+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11814 jz cstar_auditsys
11815 #endif
11816 xchgl %r9d,%ebp
11817@@ -366,6 +434,9 @@ cstar_tracesys:
11818 xchgl %ebp,%r9d
11819 cmpq $(IA32_NR_syscalls-1),%rax
11820 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11821+
11822+ pax_erase_kstack
11823+
11824 jmp cstar_do_call
11825 END(ia32_cstar_target)
11826
11827@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11828 CFI_REL_OFFSET rip,RIP-RIP
11829 PARAVIRT_ADJUST_EXCEPTION_FRAME
11830 SWAPGS
11831- /*
11832- * No need to follow this irqs on/off section: the syscall
11833- * disabled irqs and here we enable it straight after entry:
11834- */
11835- ENABLE_INTERRUPTS(CLBR_NONE)
11836 movl %eax,%eax
11837 pushq_cfi %rax
11838 cld
11839 /* note the registers are not zero extended to the sf.
11840 this could be a problem. */
11841 SAVE_ARGS 0,1,0
11842- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11843- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11844+ pax_enter_kernel_user
11845+
11846+#ifdef CONFIG_PAX_RANDKSTACK
11847+ pax_erase_kstack
11848+#endif
11849+
11850+ /*
11851+ * No need to follow this irqs on/off section: the syscall
11852+ * disabled irqs and here we enable it straight after entry:
11853+ */
11854+ ENABLE_INTERRUPTS(CLBR_NONE)
11855+ GET_THREAD_INFO(%r11)
11856+ orl $TS_COMPAT,TI_status(%r11)
11857+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11858 jnz ia32_tracesys
11859 cmpq $(IA32_NR_syscalls-1),%rax
11860 ja ia32_badsys
11861@@ -442,6 +520,9 @@ ia32_tracesys:
11862 RESTORE_REST
11863 cmpq $(IA32_NR_syscalls-1),%rax
11864 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11865+
11866+ pax_erase_kstack
11867+
11868 jmp ia32_do_call
11869 END(ia32_syscall)
11870
11871diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11872index 8e0ceec..af13504 100644
11873--- a/arch/x86/ia32/sys_ia32.c
11874+++ b/arch/x86/ia32/sys_ia32.c
11875@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11876 */
11877 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11878 {
11879- typeof(ubuf->st_uid) uid = 0;
11880- typeof(ubuf->st_gid) gid = 0;
11881+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11882+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11883 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11884 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11885 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11886diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11887index 372231c..a5aa1a1 100644
11888--- a/arch/x86/include/asm/alternative-asm.h
11889+++ b/arch/x86/include/asm/alternative-asm.h
11890@@ -18,6 +18,45 @@
11891 .endm
11892 #endif
11893
11894+#ifdef KERNEXEC_PLUGIN
11895+ .macro pax_force_retaddr_bts rip=0
11896+ btsq $63,\rip(%rsp)
11897+ .endm
11898+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11899+ .macro pax_force_retaddr rip=0, reload=0
11900+ btsq $63,\rip(%rsp)
11901+ .endm
11902+ .macro pax_force_fptr ptr
11903+ btsq $63,\ptr
11904+ .endm
11905+ .macro pax_set_fptr_mask
11906+ .endm
11907+#endif
11908+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11909+ .macro pax_force_retaddr rip=0, reload=0
11910+ .if \reload
11911+ pax_set_fptr_mask
11912+ .endif
11913+ orq %r10,\rip(%rsp)
11914+ .endm
11915+ .macro pax_force_fptr ptr
11916+ orq %r10,\ptr
11917+ .endm
11918+ .macro pax_set_fptr_mask
11919+ movabs $0x8000000000000000,%r10
11920+ .endm
11921+#endif
11922+#else
11923+ .macro pax_force_retaddr rip=0, reload=0
11924+ .endm
11925+ .macro pax_force_fptr ptr
11926+ .endm
11927+ .macro pax_force_retaddr_bts rip=0
11928+ .endm
11929+ .macro pax_set_fptr_mask
11930+ .endm
11931+#endif
11932+
11933 .macro altinstruction_entry orig alt feature orig_len alt_len
11934 .long \orig - .
11935 .long \alt - .
11936diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11937index 58ed6d9..f1cbe58 100644
11938--- a/arch/x86/include/asm/alternative.h
11939+++ b/arch/x86/include/asm/alternative.h
11940@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11941 ".pushsection .discard,\"aw\",@progbits\n" \
11942 DISCARD_ENTRY(1) \
11943 ".popsection\n" \
11944- ".pushsection .altinstr_replacement, \"ax\"\n" \
11945+ ".pushsection .altinstr_replacement, \"a\"\n" \
11946 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11947 ".popsection"
11948
11949@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11950 DISCARD_ENTRY(1) \
11951 DISCARD_ENTRY(2) \
11952 ".popsection\n" \
11953- ".pushsection .altinstr_replacement, \"ax\"\n" \
11954+ ".pushsection .altinstr_replacement, \"a\"\n" \
11955 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11956 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11957 ".popsection"
11958diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11959index 3388034..050f0b9 100644
11960--- a/arch/x86/include/asm/apic.h
11961+++ b/arch/x86/include/asm/apic.h
11962@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11963
11964 #ifdef CONFIG_X86_LOCAL_APIC
11965
11966-extern unsigned int apic_verbosity;
11967+extern int apic_verbosity;
11968 extern int local_apic_timer_c2_ok;
11969
11970 extern int disable_apic;
11971diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11972index 20370c6..a2eb9b0 100644
11973--- a/arch/x86/include/asm/apm.h
11974+++ b/arch/x86/include/asm/apm.h
11975@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11976 __asm__ __volatile__(APM_DO_ZERO_SEGS
11977 "pushl %%edi\n\t"
11978 "pushl %%ebp\n\t"
11979- "lcall *%%cs:apm_bios_entry\n\t"
11980+ "lcall *%%ss:apm_bios_entry\n\t"
11981 "setc %%al\n\t"
11982 "popl %%ebp\n\t"
11983 "popl %%edi\n\t"
11984@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11985 __asm__ __volatile__(APM_DO_ZERO_SEGS
11986 "pushl %%edi\n\t"
11987 "pushl %%ebp\n\t"
11988- "lcall *%%cs:apm_bios_entry\n\t"
11989+ "lcall *%%ss:apm_bios_entry\n\t"
11990 "setc %%bl\n\t"
11991 "popl %%ebp\n\t"
11992 "popl %%edi\n\t"
11993diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11994index 722aa3b..3a0bb27 100644
11995--- a/arch/x86/include/asm/atomic.h
11996+++ b/arch/x86/include/asm/atomic.h
11997@@ -22,7 +22,18 @@
11998 */
11999 static inline int atomic_read(const atomic_t *v)
12000 {
12001- return (*(volatile int *)&(v)->counter);
12002+ return (*(volatile const int *)&(v)->counter);
12003+}
12004+
12005+/**
12006+ * atomic_read_unchecked - read atomic variable
12007+ * @v: pointer of type atomic_unchecked_t
12008+ *
12009+ * Atomically reads the value of @v.
12010+ */
12011+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
12012+{
12013+ return (*(volatile const int *)&(v)->counter);
12014 }
12015
12016 /**
12017@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12018 }
12019
12020 /**
12021+ * atomic_set_unchecked - set atomic variable
12022+ * @v: pointer of type atomic_unchecked_t
12023+ * @i: required value
12024+ *
12025+ * Atomically sets the value of @v to @i.
12026+ */
12027+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12028+{
12029+ v->counter = i;
12030+}
12031+
12032+/**
12033 * atomic_add - add integer to atomic variable
12034 * @i: integer value to add
12035 * @v: pointer of type atomic_t
12036@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12037 */
12038 static inline void atomic_add(int i, atomic_t *v)
12039 {
12040- asm volatile(LOCK_PREFIX "addl %1,%0"
12041+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12042+
12043+#ifdef CONFIG_PAX_REFCOUNT
12044+ "jno 0f\n"
12045+ LOCK_PREFIX "subl %1,%0\n"
12046+ "int $4\n0:\n"
12047+ _ASM_EXTABLE(0b, 0b)
12048+#endif
12049+
12050+ : "+m" (v->counter)
12051+ : "ir" (i));
12052+}
12053+
12054+/**
12055+ * atomic_add_unchecked - add integer to atomic variable
12056+ * @i: integer value to add
12057+ * @v: pointer of type atomic_unchecked_t
12058+ *
12059+ * Atomically adds @i to @v.
12060+ */
12061+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12062+{
12063+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12064 : "+m" (v->counter)
12065 : "ir" (i));
12066 }
12067@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12068 */
12069 static inline void atomic_sub(int i, atomic_t *v)
12070 {
12071- asm volatile(LOCK_PREFIX "subl %1,%0"
12072+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12073+
12074+#ifdef CONFIG_PAX_REFCOUNT
12075+ "jno 0f\n"
12076+ LOCK_PREFIX "addl %1,%0\n"
12077+ "int $4\n0:\n"
12078+ _ASM_EXTABLE(0b, 0b)
12079+#endif
12080+
12081+ : "+m" (v->counter)
12082+ : "ir" (i));
12083+}
12084+
12085+/**
12086+ * atomic_sub_unchecked - subtract integer from atomic variable
12087+ * @i: integer value to subtract
12088+ * @v: pointer of type atomic_unchecked_t
12089+ *
12090+ * Atomically subtracts @i from @v.
12091+ */
12092+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12093+{
12094+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12095 : "+m" (v->counter)
12096 : "ir" (i));
12097 }
12098@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12099 {
12100 unsigned char c;
12101
12102- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12103+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12104+
12105+#ifdef CONFIG_PAX_REFCOUNT
12106+ "jno 0f\n"
12107+ LOCK_PREFIX "addl %2,%0\n"
12108+ "int $4\n0:\n"
12109+ _ASM_EXTABLE(0b, 0b)
12110+#endif
12111+
12112+ "sete %1\n"
12113 : "+m" (v->counter), "=qm" (c)
12114 : "ir" (i) : "memory");
12115 return c;
12116@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12117 */
12118 static inline void atomic_inc(atomic_t *v)
12119 {
12120- asm volatile(LOCK_PREFIX "incl %0"
12121+ asm volatile(LOCK_PREFIX "incl %0\n"
12122+
12123+#ifdef CONFIG_PAX_REFCOUNT
12124+ "jno 0f\n"
12125+ LOCK_PREFIX "decl %0\n"
12126+ "int $4\n0:\n"
12127+ _ASM_EXTABLE(0b, 0b)
12128+#endif
12129+
12130+ : "+m" (v->counter));
12131+}
12132+
12133+/**
12134+ * atomic_inc_unchecked - increment atomic variable
12135+ * @v: pointer of type atomic_unchecked_t
12136+ *
12137+ * Atomically increments @v by 1.
12138+ */
12139+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12140+{
12141+ asm volatile(LOCK_PREFIX "incl %0\n"
12142 : "+m" (v->counter));
12143 }
12144
12145@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12146 */
12147 static inline void atomic_dec(atomic_t *v)
12148 {
12149- asm volatile(LOCK_PREFIX "decl %0"
12150+ asm volatile(LOCK_PREFIX "decl %0\n"
12151+
12152+#ifdef CONFIG_PAX_REFCOUNT
12153+ "jno 0f\n"
12154+ LOCK_PREFIX "incl %0\n"
12155+ "int $4\n0:\n"
12156+ _ASM_EXTABLE(0b, 0b)
12157+#endif
12158+
12159+ : "+m" (v->counter));
12160+}
12161+
12162+/**
12163+ * atomic_dec_unchecked - decrement atomic variable
12164+ * @v: pointer of type atomic_unchecked_t
12165+ *
12166+ * Atomically decrements @v by 1.
12167+ */
12168+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12169+{
12170+ asm volatile(LOCK_PREFIX "decl %0\n"
12171 : "+m" (v->counter));
12172 }
12173
12174@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12175 {
12176 unsigned char c;
12177
12178- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12179+ asm volatile(LOCK_PREFIX "decl %0\n"
12180+
12181+#ifdef CONFIG_PAX_REFCOUNT
12182+ "jno 0f\n"
12183+ LOCK_PREFIX "incl %0\n"
12184+ "int $4\n0:\n"
12185+ _ASM_EXTABLE(0b, 0b)
12186+#endif
12187+
12188+ "sete %1\n"
12189 : "+m" (v->counter), "=qm" (c)
12190 : : "memory");
12191 return c != 0;
12192@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12193 {
12194 unsigned char c;
12195
12196- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12197+ asm volatile(LOCK_PREFIX "incl %0\n"
12198+
12199+#ifdef CONFIG_PAX_REFCOUNT
12200+ "jno 0f\n"
12201+ LOCK_PREFIX "decl %0\n"
12202+ "int $4\n0:\n"
12203+ _ASM_EXTABLE(0b, 0b)
12204+#endif
12205+
12206+ "sete %1\n"
12207+ : "+m" (v->counter), "=qm" (c)
12208+ : : "memory");
12209+ return c != 0;
12210+}
12211+
12212+/**
12213+ * atomic_inc_and_test_unchecked - increment and test
12214+ * @v: pointer of type atomic_unchecked_t
12215+ *
12216+ * Atomically increments @v by 1
12217+ * and returns true if the result is zero, or false for all
12218+ * other cases.
12219+ */
12220+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12221+{
12222+ unsigned char c;
12223+
12224+ asm volatile(LOCK_PREFIX "incl %0\n"
12225+ "sete %1\n"
12226 : "+m" (v->counter), "=qm" (c)
12227 : : "memory");
12228 return c != 0;
12229@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12230 {
12231 unsigned char c;
12232
12233- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12234+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12235+
12236+#ifdef CONFIG_PAX_REFCOUNT
12237+ "jno 0f\n"
12238+ LOCK_PREFIX "subl %2,%0\n"
12239+ "int $4\n0:\n"
12240+ _ASM_EXTABLE(0b, 0b)
12241+#endif
12242+
12243+ "sets %1\n"
12244 : "+m" (v->counter), "=qm" (c)
12245 : "ir" (i) : "memory");
12246 return c;
12247@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12248 */
12249 static inline int atomic_add_return(int i, atomic_t *v)
12250 {
12251+ return i + xadd_check_overflow(&v->counter, i);
12252+}
12253+
12254+/**
12255+ * atomic_add_return_unchecked - add integer and return
12256+ * @i: integer value to add
12257+ * @v: pointer of type atomic_unchecked_t
12258+ *
12259+ * Atomically adds @i to @v and returns @i + @v
12260+ */
12261+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12262+{
12263 return i + xadd(&v->counter, i);
12264 }
12265
12266@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12267 }
12268
12269 #define atomic_inc_return(v) (atomic_add_return(1, v))
12270+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12271+{
12272+ return atomic_add_return_unchecked(1, v);
12273+}
12274 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12275
12276 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12277@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12278 return cmpxchg(&v->counter, old, new);
12279 }
12280
12281+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12282+{
12283+ return cmpxchg(&v->counter, old, new);
12284+}
12285+
12286 static inline int atomic_xchg(atomic_t *v, int new)
12287 {
12288 return xchg(&v->counter, new);
12289 }
12290
12291+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12292+{
12293+ return xchg(&v->counter, new);
12294+}
12295+
12296 /**
12297 * __atomic_add_unless - add unless the number is already a given value
12298 * @v: pointer of type atomic_t
12299@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12300 */
12301 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12302 {
12303- int c, old;
12304+ int c, old, new;
12305 c = atomic_read(v);
12306 for (;;) {
12307- if (unlikely(c == (u)))
12308+ if (unlikely(c == u))
12309 break;
12310- old = atomic_cmpxchg((v), c, c + (a));
12311+
12312+ asm volatile("addl %2,%0\n"
12313+
12314+#ifdef CONFIG_PAX_REFCOUNT
12315+ "jno 0f\n"
12316+ "subl %2,%0\n"
12317+ "int $4\n0:\n"
12318+ _ASM_EXTABLE(0b, 0b)
12319+#endif
12320+
12321+ : "=r" (new)
12322+ : "0" (c), "ir" (a));
12323+
12324+ old = atomic_cmpxchg(v, c, new);
12325 if (likely(old == c))
12326 break;
12327 c = old;
12328@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12329 }
12330
12331 /**
12332+ * atomic_inc_not_zero_hint - increment if not null
12333+ * @v: pointer of type atomic_t
12334+ * @hint: probable value of the atomic before the increment
12335+ *
12336+ * This version of atomic_inc_not_zero() gives a hint of probable
12337+ * value of the atomic. This helps processor to not read the memory
12338+ * before doing the atomic read/modify/write cycle, lowering
12339+ * number of bus transactions on some arches.
12340+ *
12341+ * Returns: 0 if increment was not done, 1 otherwise.
12342+ */
12343+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12344+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12345+{
12346+ int val, c = hint, new;
12347+
12348+ /* sanity test, should be removed by compiler if hint is a constant */
12349+ if (!hint)
12350+ return __atomic_add_unless(v, 1, 0);
12351+
12352+ do {
12353+ asm volatile("incl %0\n"
12354+
12355+#ifdef CONFIG_PAX_REFCOUNT
12356+ "jno 0f\n"
12357+ "decl %0\n"
12358+ "int $4\n0:\n"
12359+ _ASM_EXTABLE(0b, 0b)
12360+#endif
12361+
12362+ : "=r" (new)
12363+ : "0" (c));
12364+
12365+ val = atomic_cmpxchg(v, c, new);
12366+ if (val == c)
12367+ return 1;
12368+ c = val;
12369+ } while (c);
12370+
12371+ return 0;
12372+}
12373+
12374+/**
12375 * atomic_inc_short - increment of a short integer
12376 * @v: pointer to type int
12377 *
12378@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12379 #endif
12380
12381 /* These are x86-specific, used by some header files */
12382-#define atomic_clear_mask(mask, addr) \
12383- asm volatile(LOCK_PREFIX "andl %0,%1" \
12384- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12385+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12386+{
12387+ asm volatile(LOCK_PREFIX "andl %1,%0"
12388+ : "+m" (v->counter)
12389+ : "r" (~(mask))
12390+ : "memory");
12391+}
12392
12393-#define atomic_set_mask(mask, addr) \
12394- asm volatile(LOCK_PREFIX "orl %0,%1" \
12395- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12396- : "memory")
12397+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12398+{
12399+ asm volatile(LOCK_PREFIX "andl %1,%0"
12400+ : "+m" (v->counter)
12401+ : "r" (~(mask))
12402+ : "memory");
12403+}
12404+
12405+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12406+{
12407+ asm volatile(LOCK_PREFIX "orl %1,%0"
12408+ : "+m" (v->counter)
12409+ : "r" (mask)
12410+ : "memory");
12411+}
12412+
12413+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12414+{
12415+ asm volatile(LOCK_PREFIX "orl %1,%0"
12416+ : "+m" (v->counter)
12417+ : "r" (mask)
12418+ : "memory");
12419+}
12420
12421 /* Atomic operations are already serializing on x86 */
12422 #define smp_mb__before_atomic_dec() barrier()
12423diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12424index b154de7..aadebd8 100644
12425--- a/arch/x86/include/asm/atomic64_32.h
12426+++ b/arch/x86/include/asm/atomic64_32.h
12427@@ -12,6 +12,14 @@ typedef struct {
12428 u64 __aligned(8) counter;
12429 } atomic64_t;
12430
12431+#ifdef CONFIG_PAX_REFCOUNT
12432+typedef struct {
12433+ u64 __aligned(8) counter;
12434+} atomic64_unchecked_t;
12435+#else
12436+typedef atomic64_t atomic64_unchecked_t;
12437+#endif
12438+
12439 #define ATOMIC64_INIT(val) { (val) }
12440
12441 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12442@@ -37,21 +45,31 @@ typedef struct {
12443 ATOMIC64_DECL_ONE(sym##_386)
12444
12445 ATOMIC64_DECL_ONE(add_386);
12446+ATOMIC64_DECL_ONE(add_unchecked_386);
12447 ATOMIC64_DECL_ONE(sub_386);
12448+ATOMIC64_DECL_ONE(sub_unchecked_386);
12449 ATOMIC64_DECL_ONE(inc_386);
12450+ATOMIC64_DECL_ONE(inc_unchecked_386);
12451 ATOMIC64_DECL_ONE(dec_386);
12452+ATOMIC64_DECL_ONE(dec_unchecked_386);
12453 #endif
12454
12455 #define alternative_atomic64(f, out, in...) \
12456 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12457
12458 ATOMIC64_DECL(read);
12459+ATOMIC64_DECL(read_unchecked);
12460 ATOMIC64_DECL(set);
12461+ATOMIC64_DECL(set_unchecked);
12462 ATOMIC64_DECL(xchg);
12463 ATOMIC64_DECL(add_return);
12464+ATOMIC64_DECL(add_return_unchecked);
12465 ATOMIC64_DECL(sub_return);
12466+ATOMIC64_DECL(sub_return_unchecked);
12467 ATOMIC64_DECL(inc_return);
12468+ATOMIC64_DECL(inc_return_unchecked);
12469 ATOMIC64_DECL(dec_return);
12470+ATOMIC64_DECL(dec_return_unchecked);
12471 ATOMIC64_DECL(dec_if_positive);
12472 ATOMIC64_DECL(inc_not_zero);
12473 ATOMIC64_DECL(add_unless);
12474@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12475 }
12476
12477 /**
12478+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12479+ * @p: pointer to type atomic64_unchecked_t
12480+ * @o: expected value
12481+ * @n: new value
12482+ *
12483+ * Atomically sets @v to @n if it was equal to @o and returns
12484+ * the old value.
12485+ */
12486+
12487+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12488+{
12489+ return cmpxchg64(&v->counter, o, n);
12490+}
12491+
12492+/**
12493 * atomic64_xchg - xchg atomic64 variable
12494 * @v: pointer to type atomic64_t
12495 * @n: value to assign
12496@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12497 }
12498
12499 /**
12500+ * atomic64_set_unchecked - set atomic64 variable
12501+ * @v: pointer to type atomic64_unchecked_t
12502+ * @n: value to assign
12503+ *
12504+ * Atomically sets the value of @v to @n.
12505+ */
12506+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12507+{
12508+ unsigned high = (unsigned)(i >> 32);
12509+ unsigned low = (unsigned)i;
12510+ alternative_atomic64(set, /* no output */,
12511+ "S" (v), "b" (low), "c" (high)
12512+ : "eax", "edx", "memory");
12513+}
12514+
12515+/**
12516 * atomic64_read - read atomic64 variable
12517 * @v: pointer to type atomic64_t
12518 *
12519@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12520 }
12521
12522 /**
12523+ * atomic64_read_unchecked - read atomic64 variable
12524+ * @v: pointer to type atomic64_unchecked_t
12525+ *
12526+ * Atomically reads the value of @v and returns it.
12527+ */
12528+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12529+{
12530+ long long r;
12531+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12532+ return r;
12533+ }
12534+
12535+/**
12536 * atomic64_add_return - add and return
12537 * @i: integer value to add
12538 * @v: pointer to type atomic64_t
12539@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12540 return i;
12541 }
12542
12543+/**
12544+ * atomic64_add_return_unchecked - add and return
12545+ * @i: integer value to add
12546+ * @v: pointer to type atomic64_unchecked_t
12547+ *
12548+ * Atomically adds @i to @v and returns @i + *@v
12549+ */
12550+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12551+{
12552+ alternative_atomic64(add_return_unchecked,
12553+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12554+ ASM_NO_INPUT_CLOBBER("memory"));
12555+ return i;
12556+}
12557+
12558 /*
12559 * Other variants with different arithmetic operators:
12560 */
12561@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12562 return a;
12563 }
12564
12565+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12566+{
12567+ long long a;
12568+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12569+ "S" (v) : "memory", "ecx");
12570+ return a;
12571+}
12572+
12573 static inline long long atomic64_dec_return(atomic64_t *v)
12574 {
12575 long long a;
12576@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12577 }
12578
12579 /**
12580+ * atomic64_add_unchecked - add integer to atomic64 variable
12581+ * @i: integer value to add
12582+ * @v: pointer to type atomic64_unchecked_t
12583+ *
12584+ * Atomically adds @i to @v.
12585+ */
12586+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12587+{
12588+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12589+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12590+ ASM_NO_INPUT_CLOBBER("memory"));
12591+ return i;
12592+}
12593+
12594+/**
12595 * atomic64_sub - subtract the atomic64 variable
12596 * @i: integer value to subtract
12597 * @v: pointer to type atomic64_t
12598diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12599index 0e1cbfc..5623683 100644
12600--- a/arch/x86/include/asm/atomic64_64.h
12601+++ b/arch/x86/include/asm/atomic64_64.h
12602@@ -18,7 +18,19 @@
12603 */
12604 static inline long atomic64_read(const atomic64_t *v)
12605 {
12606- return (*(volatile long *)&(v)->counter);
12607+ return (*(volatile const long *)&(v)->counter);
12608+}
12609+
12610+/**
12611+ * atomic64_read_unchecked - read atomic64 variable
12612+ * @v: pointer of type atomic64_unchecked_t
12613+ *
12614+ * Atomically reads the value of @v.
12615+ * Doesn't imply a read memory barrier.
12616+ */
12617+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12618+{
12619+ return (*(volatile const long *)&(v)->counter);
12620 }
12621
12622 /**
12623@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12624 }
12625
12626 /**
12627+ * atomic64_set_unchecked - set atomic64 variable
12628+ * @v: pointer to type atomic64_unchecked_t
12629+ * @i: required value
12630+ *
12631+ * Atomically sets the value of @v to @i.
12632+ */
12633+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12634+{
12635+ v->counter = i;
12636+}
12637+
12638+/**
12639 * atomic64_add - add integer to atomic64 variable
12640 * @i: integer value to add
12641 * @v: pointer to type atomic64_t
12642@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12643 */
12644 static inline void atomic64_add(long i, atomic64_t *v)
12645 {
12646+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12647+
12648+#ifdef CONFIG_PAX_REFCOUNT
12649+ "jno 0f\n"
12650+ LOCK_PREFIX "subq %1,%0\n"
12651+ "int $4\n0:\n"
12652+ _ASM_EXTABLE(0b, 0b)
12653+#endif
12654+
12655+ : "=m" (v->counter)
12656+ : "er" (i), "m" (v->counter));
12657+}
12658+
12659+/**
12660+ * atomic64_add_unchecked - add integer to atomic64 variable
12661+ * @i: integer value to add
12662+ * @v: pointer to type atomic64_unchecked_t
12663+ *
12664+ * Atomically adds @i to @v.
12665+ */
12666+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12667+{
12668 asm volatile(LOCK_PREFIX "addq %1,%0"
12669 : "=m" (v->counter)
12670 : "er" (i), "m" (v->counter));
12671@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12672 */
12673 static inline void atomic64_sub(long i, atomic64_t *v)
12674 {
12675- asm volatile(LOCK_PREFIX "subq %1,%0"
12676+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12677+
12678+#ifdef CONFIG_PAX_REFCOUNT
12679+ "jno 0f\n"
12680+ LOCK_PREFIX "addq %1,%0\n"
12681+ "int $4\n0:\n"
12682+ _ASM_EXTABLE(0b, 0b)
12683+#endif
12684+
12685+ : "=m" (v->counter)
12686+ : "er" (i), "m" (v->counter));
12687+}
12688+
12689+/**
12690+ * atomic64_sub_unchecked - subtract the atomic64 variable
12691+ * @i: integer value to subtract
12692+ * @v: pointer to type atomic64_unchecked_t
12693+ *
12694+ * Atomically subtracts @i from @v.
12695+ */
12696+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12697+{
12698+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12699 : "=m" (v->counter)
12700 : "er" (i), "m" (v->counter));
12701 }
12702@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12703 {
12704 unsigned char c;
12705
12706- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12707+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12708+
12709+#ifdef CONFIG_PAX_REFCOUNT
12710+ "jno 0f\n"
12711+ LOCK_PREFIX "addq %2,%0\n"
12712+ "int $4\n0:\n"
12713+ _ASM_EXTABLE(0b, 0b)
12714+#endif
12715+
12716+ "sete %1\n"
12717 : "=m" (v->counter), "=qm" (c)
12718 : "er" (i), "m" (v->counter) : "memory");
12719 return c;
12720@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12721 */
12722 static inline void atomic64_inc(atomic64_t *v)
12723 {
12724+ asm volatile(LOCK_PREFIX "incq %0\n"
12725+
12726+#ifdef CONFIG_PAX_REFCOUNT
12727+ "jno 0f\n"
12728+ LOCK_PREFIX "decq %0\n"
12729+ "int $4\n0:\n"
12730+ _ASM_EXTABLE(0b, 0b)
12731+#endif
12732+
12733+ : "=m" (v->counter)
12734+ : "m" (v->counter));
12735+}
12736+
12737+/**
12738+ * atomic64_inc_unchecked - increment atomic64 variable
12739+ * @v: pointer to type atomic64_unchecked_t
12740+ *
12741+ * Atomically increments @v by 1.
12742+ */
12743+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12744+{
12745 asm volatile(LOCK_PREFIX "incq %0"
12746 : "=m" (v->counter)
12747 : "m" (v->counter));
12748@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12749 */
12750 static inline void atomic64_dec(atomic64_t *v)
12751 {
12752- asm volatile(LOCK_PREFIX "decq %0"
12753+ asm volatile(LOCK_PREFIX "decq %0\n"
12754+
12755+#ifdef CONFIG_PAX_REFCOUNT
12756+ "jno 0f\n"
12757+ LOCK_PREFIX "incq %0\n"
12758+ "int $4\n0:\n"
12759+ _ASM_EXTABLE(0b, 0b)
12760+#endif
12761+
12762+ : "=m" (v->counter)
12763+ : "m" (v->counter));
12764+}
12765+
12766+/**
12767+ * atomic64_dec_unchecked - decrement atomic64 variable
12768+ * @v: pointer to type atomic64_t
12769+ *
12770+ * Atomically decrements @v by 1.
12771+ */
12772+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12773+{
12774+ asm volatile(LOCK_PREFIX "decq %0\n"
12775 : "=m" (v->counter)
12776 : "m" (v->counter));
12777 }
12778@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12779 {
12780 unsigned char c;
12781
12782- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12783+ asm volatile(LOCK_PREFIX "decq %0\n"
12784+
12785+#ifdef CONFIG_PAX_REFCOUNT
12786+ "jno 0f\n"
12787+ LOCK_PREFIX "incq %0\n"
12788+ "int $4\n0:\n"
12789+ _ASM_EXTABLE(0b, 0b)
12790+#endif
12791+
12792+ "sete %1\n"
12793 : "=m" (v->counter), "=qm" (c)
12794 : "m" (v->counter) : "memory");
12795 return c != 0;
12796@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12797 {
12798 unsigned char c;
12799
12800- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12801+ asm volatile(LOCK_PREFIX "incq %0\n"
12802+
12803+#ifdef CONFIG_PAX_REFCOUNT
12804+ "jno 0f\n"
12805+ LOCK_PREFIX "decq %0\n"
12806+ "int $4\n0:\n"
12807+ _ASM_EXTABLE(0b, 0b)
12808+#endif
12809+
12810+ "sete %1\n"
12811 : "=m" (v->counter), "=qm" (c)
12812 : "m" (v->counter) : "memory");
12813 return c != 0;
12814@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12815 {
12816 unsigned char c;
12817
12818- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12819+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12820+
12821+#ifdef CONFIG_PAX_REFCOUNT
12822+ "jno 0f\n"
12823+ LOCK_PREFIX "subq %2,%0\n"
12824+ "int $4\n0:\n"
12825+ _ASM_EXTABLE(0b, 0b)
12826+#endif
12827+
12828+ "sets %1\n"
12829 : "=m" (v->counter), "=qm" (c)
12830 : "er" (i), "m" (v->counter) : "memory");
12831 return c;
12832@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12833 */
12834 static inline long atomic64_add_return(long i, atomic64_t *v)
12835 {
12836+ return i + xadd_check_overflow(&v->counter, i);
12837+}
12838+
12839+/**
12840+ * atomic64_add_return_unchecked - add and return
12841+ * @i: integer value to add
12842+ * @v: pointer to type atomic64_unchecked_t
12843+ *
12844+ * Atomically adds @i to @v and returns @i + @v
12845+ */
12846+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12847+{
12848 return i + xadd(&v->counter, i);
12849 }
12850
12851@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12852 }
12853
12854 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12855+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12856+{
12857+ return atomic64_add_return_unchecked(1, v);
12858+}
12859 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12860
12861 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12862@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12863 return cmpxchg(&v->counter, old, new);
12864 }
12865
12866+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12867+{
12868+ return cmpxchg(&v->counter, old, new);
12869+}
12870+
12871 static inline long atomic64_xchg(atomic64_t *v, long new)
12872 {
12873 return xchg(&v->counter, new);
12874@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12875 */
12876 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12877 {
12878- long c, old;
12879+ long c, old, new;
12880 c = atomic64_read(v);
12881 for (;;) {
12882- if (unlikely(c == (u)))
12883+ if (unlikely(c == u))
12884 break;
12885- old = atomic64_cmpxchg((v), c, c + (a));
12886+
12887+ asm volatile("add %2,%0\n"
12888+
12889+#ifdef CONFIG_PAX_REFCOUNT
12890+ "jno 0f\n"
12891+ "sub %2,%0\n"
12892+ "int $4\n0:\n"
12893+ _ASM_EXTABLE(0b, 0b)
12894+#endif
12895+
12896+ : "=r" (new)
12897+ : "0" (c), "ir" (a));
12898+
12899+ old = atomic64_cmpxchg(v, c, new);
12900 if (likely(old == c))
12901 break;
12902 c = old;
12903 }
12904- return c != (u);
12905+ return c != u;
12906 }
12907
12908 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12909diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12910index 6dfd019..28e188d 100644
12911--- a/arch/x86/include/asm/bitops.h
12912+++ b/arch/x86/include/asm/bitops.h
12913@@ -40,7 +40,7 @@
12914 * a mask operation on a byte.
12915 */
12916 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12917-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12918+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12919 #define CONST_MASK(nr) (1 << ((nr) & 7))
12920
12921 /**
12922@@ -486,7 +486,7 @@ static inline int fls(int x)
12923 * at position 64.
12924 */
12925 #ifdef CONFIG_X86_64
12926-static __always_inline int fls64(__u64 x)
12927+static __always_inline long fls64(__u64 x)
12928 {
12929 int bitpos = -1;
12930 /*
12931diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12932index 4fa687a..60f2d39 100644
12933--- a/arch/x86/include/asm/boot.h
12934+++ b/arch/x86/include/asm/boot.h
12935@@ -6,10 +6,15 @@
12936 #include <uapi/asm/boot.h>
12937
12938 /* Physical address where kernel should be loaded. */
12939-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12940+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12941 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12942 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12943
12944+#ifndef __ASSEMBLY__
12945+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12946+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12947+#endif
12948+
12949 /* Minimum kernel alignment, as a power of two */
12950 #ifdef CONFIG_X86_64
12951 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12952diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12953index 48f99f1..d78ebf9 100644
12954--- a/arch/x86/include/asm/cache.h
12955+++ b/arch/x86/include/asm/cache.h
12956@@ -5,12 +5,13 @@
12957
12958 /* L1 cache line size */
12959 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12960-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12961+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12962
12963 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12964+#define __read_only __attribute__((__section__(".data..read_only")))
12965
12966 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12967-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12968+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12969
12970 #ifdef CONFIG_X86_VSMP
12971 #ifdef CONFIG_SMP
12972diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12973index 9863ee3..4a1f8e1 100644
12974--- a/arch/x86/include/asm/cacheflush.h
12975+++ b/arch/x86/include/asm/cacheflush.h
12976@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12977 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12978
12979 if (pg_flags == _PGMT_DEFAULT)
12980- return -1;
12981+ return ~0UL;
12982 else if (pg_flags == _PGMT_WC)
12983 return _PAGE_CACHE_WC;
12984 else if (pg_flags == _PGMT_UC_MINUS)
12985diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12986index 46fc474..b02b0f9 100644
12987--- a/arch/x86/include/asm/checksum_32.h
12988+++ b/arch/x86/include/asm/checksum_32.h
12989@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12990 int len, __wsum sum,
12991 int *src_err_ptr, int *dst_err_ptr);
12992
12993+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12994+ int len, __wsum sum,
12995+ int *src_err_ptr, int *dst_err_ptr);
12996+
12997+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12998+ int len, __wsum sum,
12999+ int *src_err_ptr, int *dst_err_ptr);
13000+
13001 /*
13002 * Note: when you get a NULL pointer exception here this means someone
13003 * passed in an incorrect kernel address to one of these functions.
13004@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
13005 int *err_ptr)
13006 {
13007 might_sleep();
13008- return csum_partial_copy_generic((__force void *)src, dst,
13009+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
13010 len, sum, err_ptr, NULL);
13011 }
13012
13013@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
13014 {
13015 might_sleep();
13016 if (access_ok(VERIFY_WRITE, dst, len))
13017- return csum_partial_copy_generic(src, (__force void *)dst,
13018+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13019 len, sum, NULL, err_ptr);
13020
13021 if (len)
13022diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13023index d47786a..ce1b05d 100644
13024--- a/arch/x86/include/asm/cmpxchg.h
13025+++ b/arch/x86/include/asm/cmpxchg.h
13026@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13027 __compiletime_error("Bad argument size for cmpxchg");
13028 extern void __xadd_wrong_size(void)
13029 __compiletime_error("Bad argument size for xadd");
13030+extern void __xadd_check_overflow_wrong_size(void)
13031+ __compiletime_error("Bad argument size for xadd_check_overflow");
13032 extern void __add_wrong_size(void)
13033 __compiletime_error("Bad argument size for add");
13034+extern void __add_check_overflow_wrong_size(void)
13035+ __compiletime_error("Bad argument size for add_check_overflow");
13036
13037 /*
13038 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13039@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13040 __ret; \
13041 })
13042
13043+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13044+ ({ \
13045+ __typeof__ (*(ptr)) __ret = (arg); \
13046+ switch (sizeof(*(ptr))) { \
13047+ case __X86_CASE_L: \
13048+ asm volatile (lock #op "l %0, %1\n" \
13049+ "jno 0f\n" \
13050+ "mov %0,%1\n" \
13051+ "int $4\n0:\n" \
13052+ _ASM_EXTABLE(0b, 0b) \
13053+ : "+r" (__ret), "+m" (*(ptr)) \
13054+ : : "memory", "cc"); \
13055+ break; \
13056+ case __X86_CASE_Q: \
13057+ asm volatile (lock #op "q %q0, %1\n" \
13058+ "jno 0f\n" \
13059+ "mov %0,%1\n" \
13060+ "int $4\n0:\n" \
13061+ _ASM_EXTABLE(0b, 0b) \
13062+ : "+r" (__ret), "+m" (*(ptr)) \
13063+ : : "memory", "cc"); \
13064+ break; \
13065+ default: \
13066+ __ ## op ## _check_overflow_wrong_size(); \
13067+ } \
13068+ __ret; \
13069+ })
13070+
13071 /*
13072 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13073 * Since this is generally used to protect other memory information, we
13074@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13075 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13076 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13077
13078+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13079+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13080+
13081 #define __add(ptr, inc, lock) \
13082 ({ \
13083 __typeof__ (*(ptr)) __ret = (inc); \
13084diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13085index 59c6c40..5e0b22c 100644
13086--- a/arch/x86/include/asm/compat.h
13087+++ b/arch/x86/include/asm/compat.h
13088@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13089 typedef u32 compat_uint_t;
13090 typedef u32 compat_ulong_t;
13091 typedef u64 __attribute__((aligned(4))) compat_u64;
13092-typedef u32 compat_uptr_t;
13093+typedef u32 __user compat_uptr_t;
13094
13095 struct compat_timespec {
13096 compat_time_t tv_sec;
13097diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13098index e99ac27..e89e28c 100644
13099--- a/arch/x86/include/asm/cpufeature.h
13100+++ b/arch/x86/include/asm/cpufeature.h
13101@@ -211,7 +211,7 @@
13102 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13103 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13104 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13105-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13106+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13107 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13108 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13109 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13110@@ -394,7 +394,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13111 ".section .discard,\"aw\",@progbits\n"
13112 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13113 ".previous\n"
13114- ".section .altinstr_replacement,\"ax\"\n"
13115+ ".section .altinstr_replacement,\"a\"\n"
13116 "3: movb $1,%0\n"
13117 "4:\n"
13118 ".previous\n"
13119diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13120index 8bf1c06..b6ae785 100644
13121--- a/arch/x86/include/asm/desc.h
13122+++ b/arch/x86/include/asm/desc.h
13123@@ -4,6 +4,7 @@
13124 #include <asm/desc_defs.h>
13125 #include <asm/ldt.h>
13126 #include <asm/mmu.h>
13127+#include <asm/pgtable.h>
13128
13129 #include <linux/smp.h>
13130 #include <linux/percpu.h>
13131@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13132
13133 desc->type = (info->read_exec_only ^ 1) << 1;
13134 desc->type |= info->contents << 2;
13135+ desc->type |= info->seg_not_present ^ 1;
13136
13137 desc->s = 1;
13138 desc->dpl = 0x3;
13139@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13140 }
13141
13142 extern struct desc_ptr idt_descr;
13143-extern gate_desc idt_table[];
13144 extern struct desc_ptr nmi_idt_descr;
13145-extern gate_desc nmi_idt_table[];
13146-
13147-struct gdt_page {
13148- struct desc_struct gdt[GDT_ENTRIES];
13149-} __attribute__((aligned(PAGE_SIZE)));
13150-
13151-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13152+extern gate_desc idt_table[256];
13153+extern gate_desc nmi_idt_table[256];
13154
13155+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13156 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13157 {
13158- return per_cpu(gdt_page, cpu).gdt;
13159+ return cpu_gdt_table[cpu];
13160 }
13161
13162 #ifdef CONFIG_X86_64
13163@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13164 unsigned long base, unsigned dpl, unsigned flags,
13165 unsigned short seg)
13166 {
13167- gate->a = (seg << 16) | (base & 0xffff);
13168- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13169+ gate->gate.offset_low = base;
13170+ gate->gate.seg = seg;
13171+ gate->gate.reserved = 0;
13172+ gate->gate.type = type;
13173+ gate->gate.s = 0;
13174+ gate->gate.dpl = dpl;
13175+ gate->gate.p = 1;
13176+ gate->gate.offset_high = base >> 16;
13177 }
13178
13179 #endif
13180@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13181
13182 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13183 {
13184+ pax_open_kernel();
13185 memcpy(&idt[entry], gate, sizeof(*gate));
13186+ pax_close_kernel();
13187 }
13188
13189 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13190 {
13191+ pax_open_kernel();
13192 memcpy(&ldt[entry], desc, 8);
13193+ pax_close_kernel();
13194 }
13195
13196 static inline void
13197@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13198 default: size = sizeof(*gdt); break;
13199 }
13200
13201+ pax_open_kernel();
13202 memcpy(&gdt[entry], desc, size);
13203+ pax_close_kernel();
13204 }
13205
13206 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13207@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13208
13209 static inline void native_load_tr_desc(void)
13210 {
13211+ pax_open_kernel();
13212 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13213+ pax_close_kernel();
13214 }
13215
13216 static inline void native_load_gdt(const struct desc_ptr *dtr)
13217@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13218 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13219 unsigned int i;
13220
13221+ pax_open_kernel();
13222 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13223 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13224+ pax_close_kernel();
13225 }
13226
13227 #define _LDT_empty(info) \
13228@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13229 preempt_enable();
13230 }
13231
13232-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13233+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13234 {
13235 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13236 }
13237@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13238 }
13239
13240 #ifdef CONFIG_X86_64
13241-static inline void set_nmi_gate(int gate, void *addr)
13242+static inline void set_nmi_gate(int gate, const void *addr)
13243 {
13244 gate_desc s;
13245
13246@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13247 }
13248 #endif
13249
13250-static inline void _set_gate(int gate, unsigned type, void *addr,
13251+static inline void _set_gate(int gate, unsigned type, const void *addr,
13252 unsigned dpl, unsigned ist, unsigned seg)
13253 {
13254 gate_desc s;
13255@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13256 * Pentium F0 0F bugfix can have resulted in the mapped
13257 * IDT being write-protected.
13258 */
13259-static inline void set_intr_gate(unsigned int n, void *addr)
13260+static inline void set_intr_gate(unsigned int n, const void *addr)
13261 {
13262 BUG_ON((unsigned)n > 0xFF);
13263 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13264@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13265 /*
13266 * This routine sets up an interrupt gate at directory privilege level 3.
13267 */
13268-static inline void set_system_intr_gate(unsigned int n, void *addr)
13269+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13270 {
13271 BUG_ON((unsigned)n > 0xFF);
13272 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13273 }
13274
13275-static inline void set_system_trap_gate(unsigned int n, void *addr)
13276+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13277 {
13278 BUG_ON((unsigned)n > 0xFF);
13279 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13280 }
13281
13282-static inline void set_trap_gate(unsigned int n, void *addr)
13283+static inline void set_trap_gate(unsigned int n, const void *addr)
13284 {
13285 BUG_ON((unsigned)n > 0xFF);
13286 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13287@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13288 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13289 {
13290 BUG_ON((unsigned)n > 0xFF);
13291- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13292+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13293 }
13294
13295-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13296+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13297 {
13298 BUG_ON((unsigned)n > 0xFF);
13299 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13300 }
13301
13302-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13303+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13304 {
13305 BUG_ON((unsigned)n > 0xFF);
13306 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13307 }
13308
13309+#ifdef CONFIG_X86_32
13310+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13311+{
13312+ struct desc_struct d;
13313+
13314+ if (likely(limit))
13315+ limit = (limit - 1UL) >> PAGE_SHIFT;
13316+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13317+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13318+}
13319+#endif
13320+
13321 #endif /* _ASM_X86_DESC_H */
13322diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13323index 278441f..b95a174 100644
13324--- a/arch/x86/include/asm/desc_defs.h
13325+++ b/arch/x86/include/asm/desc_defs.h
13326@@ -31,6 +31,12 @@ struct desc_struct {
13327 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13328 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13329 };
13330+ struct {
13331+ u16 offset_low;
13332+ u16 seg;
13333+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13334+ unsigned offset_high: 16;
13335+ } gate;
13336 };
13337 } __attribute__((packed));
13338
13339diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13340index ced283a..ffe04cc 100644
13341--- a/arch/x86/include/asm/div64.h
13342+++ b/arch/x86/include/asm/div64.h
13343@@ -39,7 +39,7 @@
13344 __mod; \
13345 })
13346
13347-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13348+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13349 {
13350 union {
13351 u64 v64;
13352diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13353index 9c999c1..3860cb8 100644
13354--- a/arch/x86/include/asm/elf.h
13355+++ b/arch/x86/include/asm/elf.h
13356@@ -243,7 +243,25 @@ extern int force_personality32;
13357 the loader. We need to make sure that it is out of the way of the program
13358 that it will "exec", and that there is sufficient room for the brk. */
13359
13360+#ifdef CONFIG_PAX_SEGMEXEC
13361+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13362+#else
13363 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13364+#endif
13365+
13366+#ifdef CONFIG_PAX_ASLR
13367+#ifdef CONFIG_X86_32
13368+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13369+
13370+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13371+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13372+#else
13373+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13374+
13375+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13376+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13377+#endif
13378+#endif
13379
13380 /* This yields a mask that user programs can use to figure out what
13381 instruction set this CPU supports. This could be done in user space,
13382@@ -296,16 +314,12 @@ do { \
13383
13384 #define ARCH_DLINFO \
13385 do { \
13386- if (vdso_enabled) \
13387- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13388- (unsigned long)current->mm->context.vdso); \
13389+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13390 } while (0)
13391
13392 #define ARCH_DLINFO_X32 \
13393 do { \
13394- if (vdso_enabled) \
13395- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13396- (unsigned long)current->mm->context.vdso); \
13397+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13398 } while (0)
13399
13400 #define AT_SYSINFO 32
13401@@ -320,7 +334,7 @@ else \
13402
13403 #endif /* !CONFIG_X86_32 */
13404
13405-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13406+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13407
13408 #define VDSO_ENTRY \
13409 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13410@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13411 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13412 #define compat_arch_setup_additional_pages syscall32_setup_pages
13413
13414-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13415-#define arch_randomize_brk arch_randomize_brk
13416-
13417 /*
13418 * True on X86_32 or when emulating IA32 on X86_64
13419 */
13420diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13421index 75ce3f4..882e801 100644
13422--- a/arch/x86/include/asm/emergency-restart.h
13423+++ b/arch/x86/include/asm/emergency-restart.h
13424@@ -13,6 +13,6 @@ enum reboot_type {
13425
13426 extern enum reboot_type reboot_type;
13427
13428-extern void machine_emergency_restart(void);
13429+extern void machine_emergency_restart(void) __noreturn;
13430
13431 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13432diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13433index e25cc33..425d099 100644
13434--- a/arch/x86/include/asm/fpu-internal.h
13435+++ b/arch/x86/include/asm/fpu-internal.h
13436@@ -127,7 +127,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13437 ({ \
13438 int err; \
13439 asm volatile(ASM_STAC "\n" \
13440- "1:" #insn "\n\t" \
13441+ "1:" \
13442+ __copyuser_seg \
13443+ #insn "\n\t" \
13444 "2: " ASM_CLAC "\n" \
13445 ".section .fixup,\"ax\"\n" \
13446 "3: movl $-1,%[err]\n" \
13447@@ -300,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13448 "emms\n\t" /* clear stack tags */
13449 "fildl %P[addr]", /* set F?P to defined value */
13450 X86_FEATURE_FXSAVE_LEAK,
13451- [addr] "m" (tsk->thread.fpu.has_fpu));
13452+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13453
13454 return fpu_restore_checking(&tsk->thread.fpu);
13455 }
13456diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13457index be27ba1..8f13ff9 100644
13458--- a/arch/x86/include/asm/futex.h
13459+++ b/arch/x86/include/asm/futex.h
13460@@ -12,6 +12,7 @@
13461 #include <asm/smap.h>
13462
13463 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13464+ typecheck(u32 __user *, uaddr); \
13465 asm volatile("\t" ASM_STAC "\n" \
13466 "1:\t" insn "\n" \
13467 "2:\t" ASM_CLAC "\n" \
13468@@ -20,15 +21,16 @@
13469 "\tjmp\t2b\n" \
13470 "\t.previous\n" \
13471 _ASM_EXTABLE(1b, 3b) \
13472- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13473+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13474 : "i" (-EFAULT), "0" (oparg), "1" (0))
13475
13476 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13477+ typecheck(u32 __user *, uaddr); \
13478 asm volatile("\t" ASM_STAC "\n" \
13479 "1:\tmovl %2, %0\n" \
13480 "\tmovl\t%0, %3\n" \
13481 "\t" insn "\n" \
13482- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13483+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13484 "\tjnz\t1b\n" \
13485 "3:\t" ASM_CLAC "\n" \
13486 "\t.section .fixup,\"ax\"\n" \
13487@@ -38,7 +40,7 @@
13488 _ASM_EXTABLE(1b, 4b) \
13489 _ASM_EXTABLE(2b, 4b) \
13490 : "=&a" (oldval), "=&r" (ret), \
13491- "+m" (*uaddr), "=&r" (tem) \
13492+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13493 : "r" (oparg), "i" (-EFAULT), "1" (0))
13494
13495 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13496@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13497
13498 switch (op) {
13499 case FUTEX_OP_SET:
13500- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13501+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13502 break;
13503 case FUTEX_OP_ADD:
13504- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13505+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13506 uaddr, oparg);
13507 break;
13508 case FUTEX_OP_OR:
13509@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13510 return -EFAULT;
13511
13512 asm volatile("\t" ASM_STAC "\n"
13513- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13514+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13515 "2:\t" ASM_CLAC "\n"
13516 "\t.section .fixup, \"ax\"\n"
13517 "3:\tmov %3, %0\n"
13518 "\tjmp 2b\n"
13519 "\t.previous\n"
13520 _ASM_EXTABLE(1b, 3b)
13521- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13522+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13523 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13524 : "memory"
13525 );
13526diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13527index 1da97ef..9c2ebff 100644
13528--- a/arch/x86/include/asm/hw_irq.h
13529+++ b/arch/x86/include/asm/hw_irq.h
13530@@ -148,8 +148,8 @@ extern void setup_ioapic_dest(void);
13531 extern void enable_IO_APIC(void);
13532
13533 /* Statistics */
13534-extern atomic_t irq_err_count;
13535-extern atomic_t irq_mis_count;
13536+extern atomic_unchecked_t irq_err_count;
13537+extern atomic_unchecked_t irq_mis_count;
13538
13539 /* EISA */
13540 extern void eisa_set_level_irq(unsigned int irq);
13541diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13542index a203659..9889f1c 100644
13543--- a/arch/x86/include/asm/i8259.h
13544+++ b/arch/x86/include/asm/i8259.h
13545@@ -62,7 +62,7 @@ struct legacy_pic {
13546 void (*init)(int auto_eoi);
13547 int (*irq_pending)(unsigned int irq);
13548 void (*make_irq)(unsigned int irq);
13549-};
13550+} __do_const;
13551
13552 extern struct legacy_pic *legacy_pic;
13553 extern struct legacy_pic null_legacy_pic;
13554diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13555index d8e8eef..1765f78 100644
13556--- a/arch/x86/include/asm/io.h
13557+++ b/arch/x86/include/asm/io.h
13558@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13559 "m" (*(volatile type __force *)addr) barrier); }
13560
13561 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13562-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13563-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13564+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13565+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13566
13567 build_mmio_read(__readb, "b", unsigned char, "=q", )
13568-build_mmio_read(__readw, "w", unsigned short, "=r", )
13569-build_mmio_read(__readl, "l", unsigned int, "=r", )
13570+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13571+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13572
13573 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13574 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13575@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13576 return ioremap_nocache(offset, size);
13577 }
13578
13579-extern void iounmap(volatile void __iomem *addr);
13580+extern void iounmap(const volatile void __iomem *addr);
13581
13582 extern void set_iounmap_nonlazy(void);
13583
13584@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13585
13586 #include <linux/vmalloc.h>
13587
13588+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13589+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13590+{
13591+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13592+}
13593+
13594+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13595+{
13596+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13597+}
13598+
13599 /*
13600 * Convert a virtual cached pointer to an uncached pointer
13601 */
13602diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13603index bba3cf8..06bc8da 100644
13604--- a/arch/x86/include/asm/irqflags.h
13605+++ b/arch/x86/include/asm/irqflags.h
13606@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13607 sti; \
13608 sysexit
13609
13610+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13611+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13612+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13613+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13614+
13615 #else
13616 #define INTERRUPT_RETURN iret
13617 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13618diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13619index 5a6d287..f815789 100644
13620--- a/arch/x86/include/asm/kprobes.h
13621+++ b/arch/x86/include/asm/kprobes.h
13622@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13623 #define RELATIVEJUMP_SIZE 5
13624 #define RELATIVECALL_OPCODE 0xe8
13625 #define RELATIVE_ADDR_SIZE 4
13626-#define MAX_STACK_SIZE 64
13627-#define MIN_STACK_SIZE(ADDR) \
13628- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13629- THREAD_SIZE - (unsigned long)(ADDR))) \
13630- ? (MAX_STACK_SIZE) \
13631- : (((unsigned long)current_thread_info()) + \
13632- THREAD_SIZE - (unsigned long)(ADDR)))
13633+#define MAX_STACK_SIZE 64UL
13634+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13635
13636 #define flush_insn_slot(p) do { } while (0)
13637
13638diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13639index 2d89e39..baee879 100644
13640--- a/arch/x86/include/asm/local.h
13641+++ b/arch/x86/include/asm/local.h
13642@@ -10,33 +10,97 @@ typedef struct {
13643 atomic_long_t a;
13644 } local_t;
13645
13646+typedef struct {
13647+ atomic_long_unchecked_t a;
13648+} local_unchecked_t;
13649+
13650 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13651
13652 #define local_read(l) atomic_long_read(&(l)->a)
13653+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13654 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13655+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13656
13657 static inline void local_inc(local_t *l)
13658 {
13659- asm volatile(_ASM_INC "%0"
13660+ asm volatile(_ASM_INC "%0\n"
13661+
13662+#ifdef CONFIG_PAX_REFCOUNT
13663+ "jno 0f\n"
13664+ _ASM_DEC "%0\n"
13665+ "int $4\n0:\n"
13666+ _ASM_EXTABLE(0b, 0b)
13667+#endif
13668+
13669+ : "+m" (l->a.counter));
13670+}
13671+
13672+static inline void local_inc_unchecked(local_unchecked_t *l)
13673+{
13674+ asm volatile(_ASM_INC "%0\n"
13675 : "+m" (l->a.counter));
13676 }
13677
13678 static inline void local_dec(local_t *l)
13679 {
13680- asm volatile(_ASM_DEC "%0"
13681+ asm volatile(_ASM_DEC "%0\n"
13682+
13683+#ifdef CONFIG_PAX_REFCOUNT
13684+ "jno 0f\n"
13685+ _ASM_INC "%0\n"
13686+ "int $4\n0:\n"
13687+ _ASM_EXTABLE(0b, 0b)
13688+#endif
13689+
13690+ : "+m" (l->a.counter));
13691+}
13692+
13693+static inline void local_dec_unchecked(local_unchecked_t *l)
13694+{
13695+ asm volatile(_ASM_DEC "%0\n"
13696 : "+m" (l->a.counter));
13697 }
13698
13699 static inline void local_add(long i, local_t *l)
13700 {
13701- asm volatile(_ASM_ADD "%1,%0"
13702+ asm volatile(_ASM_ADD "%1,%0\n"
13703+
13704+#ifdef CONFIG_PAX_REFCOUNT
13705+ "jno 0f\n"
13706+ _ASM_SUB "%1,%0\n"
13707+ "int $4\n0:\n"
13708+ _ASM_EXTABLE(0b, 0b)
13709+#endif
13710+
13711+ : "+m" (l->a.counter)
13712+ : "ir" (i));
13713+}
13714+
13715+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13716+{
13717+ asm volatile(_ASM_ADD "%1,%0\n"
13718 : "+m" (l->a.counter)
13719 : "ir" (i));
13720 }
13721
13722 static inline void local_sub(long i, local_t *l)
13723 {
13724- asm volatile(_ASM_SUB "%1,%0"
13725+ asm volatile(_ASM_SUB "%1,%0\n"
13726+
13727+#ifdef CONFIG_PAX_REFCOUNT
13728+ "jno 0f\n"
13729+ _ASM_ADD "%1,%0\n"
13730+ "int $4\n0:\n"
13731+ _ASM_EXTABLE(0b, 0b)
13732+#endif
13733+
13734+ : "+m" (l->a.counter)
13735+ : "ir" (i));
13736+}
13737+
13738+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13739+{
13740+ asm volatile(_ASM_SUB "%1,%0\n"
13741 : "+m" (l->a.counter)
13742 : "ir" (i));
13743 }
13744@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13745 {
13746 unsigned char c;
13747
13748- asm volatile(_ASM_SUB "%2,%0; sete %1"
13749+ asm volatile(_ASM_SUB "%2,%0\n"
13750+
13751+#ifdef CONFIG_PAX_REFCOUNT
13752+ "jno 0f\n"
13753+ _ASM_ADD "%2,%0\n"
13754+ "int $4\n0:\n"
13755+ _ASM_EXTABLE(0b, 0b)
13756+#endif
13757+
13758+ "sete %1\n"
13759 : "+m" (l->a.counter), "=qm" (c)
13760 : "ir" (i) : "memory");
13761 return c;
13762@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13763 {
13764 unsigned char c;
13765
13766- asm volatile(_ASM_DEC "%0; sete %1"
13767+ asm volatile(_ASM_DEC "%0\n"
13768+
13769+#ifdef CONFIG_PAX_REFCOUNT
13770+ "jno 0f\n"
13771+ _ASM_INC "%0\n"
13772+ "int $4\n0:\n"
13773+ _ASM_EXTABLE(0b, 0b)
13774+#endif
13775+
13776+ "sete %1\n"
13777 : "+m" (l->a.counter), "=qm" (c)
13778 : : "memory");
13779 return c != 0;
13780@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13781 {
13782 unsigned char c;
13783
13784- asm volatile(_ASM_INC "%0; sete %1"
13785+ asm volatile(_ASM_INC "%0\n"
13786+
13787+#ifdef CONFIG_PAX_REFCOUNT
13788+ "jno 0f\n"
13789+ _ASM_DEC "%0\n"
13790+ "int $4\n0:\n"
13791+ _ASM_EXTABLE(0b, 0b)
13792+#endif
13793+
13794+ "sete %1\n"
13795 : "+m" (l->a.counter), "=qm" (c)
13796 : : "memory");
13797 return c != 0;
13798@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13799 {
13800 unsigned char c;
13801
13802- asm volatile(_ASM_ADD "%2,%0; sets %1"
13803+ asm volatile(_ASM_ADD "%2,%0\n"
13804+
13805+#ifdef CONFIG_PAX_REFCOUNT
13806+ "jno 0f\n"
13807+ _ASM_SUB "%2,%0\n"
13808+ "int $4\n0:\n"
13809+ _ASM_EXTABLE(0b, 0b)
13810+#endif
13811+
13812+ "sets %1\n"
13813 : "+m" (l->a.counter), "=qm" (c)
13814 : "ir" (i) : "memory");
13815 return c;
13816@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13817 static inline long local_add_return(long i, local_t *l)
13818 {
13819 long __i = i;
13820+ asm volatile(_ASM_XADD "%0, %1\n"
13821+
13822+#ifdef CONFIG_PAX_REFCOUNT
13823+ "jno 0f\n"
13824+ _ASM_MOV "%0,%1\n"
13825+ "int $4\n0:\n"
13826+ _ASM_EXTABLE(0b, 0b)
13827+#endif
13828+
13829+ : "+r" (i), "+m" (l->a.counter)
13830+ : : "memory");
13831+ return i + __i;
13832+}
13833+
13834+/**
13835+ * local_add_return_unchecked - add and return
13836+ * @i: integer value to add
13837+ * @l: pointer to type local_unchecked_t
13838+ *
13839+ * Atomically adds @i to @l and returns @i + @l
13840+ */
13841+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13842+{
13843+ long __i = i;
13844 asm volatile(_ASM_XADD "%0, %1;"
13845 : "+r" (i), "+m" (l->a.counter)
13846 : : "memory");
13847@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13848
13849 #define local_cmpxchg(l, o, n) \
13850 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13851+#define local_cmpxchg_unchecked(l, o, n) \
13852+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13853 /* Always has a lock prefix */
13854 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13855
13856diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13857new file mode 100644
13858index 0000000..2bfd3ba
13859--- /dev/null
13860+++ b/arch/x86/include/asm/mman.h
13861@@ -0,0 +1,15 @@
13862+#ifndef _X86_MMAN_H
13863+#define _X86_MMAN_H
13864+
13865+#include <uapi/asm/mman.h>
13866+
13867+#ifdef __KERNEL__
13868+#ifndef __ASSEMBLY__
13869+#ifdef CONFIG_X86_32
13870+#define arch_mmap_check i386_mmap_check
13871+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13872+#endif
13873+#endif
13874+#endif
13875+
13876+#endif /* X86_MMAN_H */
13877diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13878index 5f55e69..e20bfb1 100644
13879--- a/arch/x86/include/asm/mmu.h
13880+++ b/arch/x86/include/asm/mmu.h
13881@@ -9,7 +9,7 @@
13882 * we put the segment information here.
13883 */
13884 typedef struct {
13885- void *ldt;
13886+ struct desc_struct *ldt;
13887 int size;
13888
13889 #ifdef CONFIG_X86_64
13890@@ -18,7 +18,19 @@ typedef struct {
13891 #endif
13892
13893 struct mutex lock;
13894- void *vdso;
13895+ unsigned long vdso;
13896+
13897+#ifdef CONFIG_X86_32
13898+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13899+ unsigned long user_cs_base;
13900+ unsigned long user_cs_limit;
13901+
13902+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13903+ cpumask_t cpu_user_cs_mask;
13904+#endif
13905+
13906+#endif
13907+#endif
13908 } mm_context_t;
13909
13910 #ifdef CONFIG_SMP
13911diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13912index cdbf367..adb37ac 100644
13913--- a/arch/x86/include/asm/mmu_context.h
13914+++ b/arch/x86/include/asm/mmu_context.h
13915@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13916
13917 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13918 {
13919+
13920+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13921+ unsigned int i;
13922+ pgd_t *pgd;
13923+
13924+ pax_open_kernel();
13925+ pgd = get_cpu_pgd(smp_processor_id());
13926+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13927+ set_pgd_batched(pgd+i, native_make_pgd(0));
13928+ pax_close_kernel();
13929+#endif
13930+
13931 #ifdef CONFIG_SMP
13932 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13933 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13934@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13935 struct task_struct *tsk)
13936 {
13937 unsigned cpu = smp_processor_id();
13938+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13939+ int tlbstate = TLBSTATE_OK;
13940+#endif
13941
13942 if (likely(prev != next)) {
13943 #ifdef CONFIG_SMP
13944+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13945+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13946+#endif
13947 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13948 this_cpu_write(cpu_tlbstate.active_mm, next);
13949 #endif
13950 cpumask_set_cpu(cpu, mm_cpumask(next));
13951
13952 /* Re-load page tables */
13953+#ifdef CONFIG_PAX_PER_CPU_PGD
13954+ pax_open_kernel();
13955+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13956+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13957+ pax_close_kernel();
13958+ load_cr3(get_cpu_pgd(cpu));
13959+#else
13960 load_cr3(next->pgd);
13961+#endif
13962
13963 /* stop flush ipis for the previous mm */
13964 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13965@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13966 */
13967 if (unlikely(prev->context.ldt != next->context.ldt))
13968 load_LDT_nolock(&next->context);
13969- }
13970+
13971+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13972+ if (!(__supported_pte_mask & _PAGE_NX)) {
13973+ smp_mb__before_clear_bit();
13974+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13975+ smp_mb__after_clear_bit();
13976+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13977+ }
13978+#endif
13979+
13980+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13981+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13982+ prev->context.user_cs_limit != next->context.user_cs_limit))
13983+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13984 #ifdef CONFIG_SMP
13985+ else if (unlikely(tlbstate != TLBSTATE_OK))
13986+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13987+#endif
13988+#endif
13989+
13990+ }
13991 else {
13992+
13993+#ifdef CONFIG_PAX_PER_CPU_PGD
13994+ pax_open_kernel();
13995+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13996+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13997+ pax_close_kernel();
13998+ load_cr3(get_cpu_pgd(cpu));
13999+#endif
14000+
14001+#ifdef CONFIG_SMP
14002 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14003 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
14004
14005@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14006 * tlb flush IPI delivery. We must reload CR3
14007 * to make sure to use no freed page tables.
14008 */
14009+
14010+#ifndef CONFIG_PAX_PER_CPU_PGD
14011 load_cr3(next->pgd);
14012+#endif
14013+
14014 load_LDT_nolock(&next->context);
14015+
14016+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14017+ if (!(__supported_pte_mask & _PAGE_NX))
14018+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14019+#endif
14020+
14021+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14022+#ifdef CONFIG_PAX_PAGEEXEC
14023+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14024+#endif
14025+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14026+#endif
14027+
14028 }
14029+#endif
14030 }
14031-#endif
14032 }
14033
14034 #define activate_mm(prev, next) \
14035diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14036index e3b7819..b257c64 100644
14037--- a/arch/x86/include/asm/module.h
14038+++ b/arch/x86/include/asm/module.h
14039@@ -5,6 +5,7 @@
14040
14041 #ifdef CONFIG_X86_64
14042 /* X86_64 does not define MODULE_PROC_FAMILY */
14043+#define MODULE_PROC_FAMILY ""
14044 #elif defined CONFIG_M486
14045 #define MODULE_PROC_FAMILY "486 "
14046 #elif defined CONFIG_M586
14047@@ -57,8 +58,20 @@
14048 #error unknown processor family
14049 #endif
14050
14051-#ifdef CONFIG_X86_32
14052-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14053+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14054+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14055+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14056+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14057+#else
14058+#define MODULE_PAX_KERNEXEC ""
14059 #endif
14060
14061+#ifdef CONFIG_PAX_MEMORY_UDEREF
14062+#define MODULE_PAX_UDEREF "UDEREF "
14063+#else
14064+#define MODULE_PAX_UDEREF ""
14065+#endif
14066+
14067+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14068+
14069 #endif /* _ASM_X86_MODULE_H */
14070diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14071index 86f9301..b365cda 100644
14072--- a/arch/x86/include/asm/nmi.h
14073+++ b/arch/x86/include/asm/nmi.h
14074@@ -40,11 +40,11 @@ struct nmiaction {
14075 nmi_handler_t handler;
14076 unsigned long flags;
14077 const char *name;
14078-};
14079+} __do_const;
14080
14081 #define register_nmi_handler(t, fn, fg, n, init...) \
14082 ({ \
14083- static struct nmiaction init fn##_na = { \
14084+ static const struct nmiaction init fn##_na = { \
14085 .handler = (fn), \
14086 .name = (n), \
14087 .flags = (fg), \
14088@@ -52,7 +52,7 @@ struct nmiaction {
14089 __register_nmi_handler((t), &fn##_na); \
14090 })
14091
14092-int __register_nmi_handler(unsigned int, struct nmiaction *);
14093+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14094
14095 void unregister_nmi_handler(unsigned int, const char *);
14096
14097diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
14098index c878924..21f4889 100644
14099--- a/arch/x86/include/asm/page.h
14100+++ b/arch/x86/include/asm/page.h
14101@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
14102 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
14103
14104 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
14105+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
14106
14107 #define __boot_va(x) __va(x)
14108 #define __boot_pa(x) __pa(x)
14109diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
14110index 0f1ddee..e2fc3d1 100644
14111--- a/arch/x86/include/asm/page_64.h
14112+++ b/arch/x86/include/asm/page_64.h
14113@@ -7,9 +7,9 @@
14114
14115 /* duplicated to the one in bootmem.h */
14116 extern unsigned long max_pfn;
14117-extern unsigned long phys_base;
14118+extern const unsigned long phys_base;
14119
14120-static inline unsigned long __phys_addr_nodebug(unsigned long x)
14121+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
14122 {
14123 unsigned long y = x - __START_KERNEL_map;
14124
14125diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14126index cfdc9ee..3f7b5d6 100644
14127--- a/arch/x86/include/asm/paravirt.h
14128+++ b/arch/x86/include/asm/paravirt.h
14129@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
14130 return (pmd_t) { ret };
14131 }
14132
14133-static inline pmdval_t pmd_val(pmd_t pmd)
14134+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14135 {
14136 pmdval_t ret;
14137
14138@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14139 val);
14140 }
14141
14142+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14143+{
14144+ pgdval_t val = native_pgd_val(pgd);
14145+
14146+ if (sizeof(pgdval_t) > sizeof(long))
14147+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14148+ val, (u64)val >> 32);
14149+ else
14150+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14151+ val);
14152+}
14153+
14154 static inline void pgd_clear(pgd_t *pgdp)
14155 {
14156 set_pgd(pgdp, __pgd(0));
14157@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14158 pv_mmu_ops.set_fixmap(idx, phys, flags);
14159 }
14160
14161+#ifdef CONFIG_PAX_KERNEXEC
14162+static inline unsigned long pax_open_kernel(void)
14163+{
14164+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14165+}
14166+
14167+static inline unsigned long pax_close_kernel(void)
14168+{
14169+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14170+}
14171+#else
14172+static inline unsigned long pax_open_kernel(void) { return 0; }
14173+static inline unsigned long pax_close_kernel(void) { return 0; }
14174+#endif
14175+
14176 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14177
14178 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14179@@ -926,7 +953,7 @@ extern void default_banner(void);
14180
14181 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14182 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14183-#define PARA_INDIRECT(addr) *%cs:addr
14184+#define PARA_INDIRECT(addr) *%ss:addr
14185 #endif
14186
14187 #define INTERRUPT_RETURN \
14188@@ -1001,6 +1028,21 @@ extern void default_banner(void);
14189 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14190 CLBR_NONE, \
14191 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14192+
14193+#define GET_CR0_INTO_RDI \
14194+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14195+ mov %rax,%rdi
14196+
14197+#define SET_RDI_INTO_CR0 \
14198+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14199+
14200+#define GET_CR3_INTO_RDI \
14201+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14202+ mov %rax,%rdi
14203+
14204+#define SET_RDI_INTO_CR3 \
14205+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14206+
14207 #endif /* CONFIG_X86_32 */
14208
14209 #endif /* __ASSEMBLY__ */
14210diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14211index 0db1fca..52310cc 100644
14212--- a/arch/x86/include/asm/paravirt_types.h
14213+++ b/arch/x86/include/asm/paravirt_types.h
14214@@ -84,7 +84,7 @@ struct pv_init_ops {
14215 */
14216 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14217 unsigned long addr, unsigned len);
14218-};
14219+} __no_const;
14220
14221
14222 struct pv_lazy_ops {
14223@@ -98,7 +98,7 @@ struct pv_time_ops {
14224 unsigned long long (*sched_clock)(void);
14225 unsigned long long (*steal_clock)(int cpu);
14226 unsigned long (*get_tsc_khz)(void);
14227-};
14228+} __no_const;
14229
14230 struct pv_cpu_ops {
14231 /* hooks for various privileged instructions */
14232@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14233
14234 void (*start_context_switch)(struct task_struct *prev);
14235 void (*end_context_switch)(struct task_struct *next);
14236-};
14237+} __no_const;
14238
14239 struct pv_irq_ops {
14240 /*
14241@@ -223,7 +223,7 @@ struct pv_apic_ops {
14242 unsigned long start_eip,
14243 unsigned long start_esp);
14244 #endif
14245-};
14246+} __no_const;
14247
14248 struct pv_mmu_ops {
14249 unsigned long (*read_cr2)(void);
14250@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14251 struct paravirt_callee_save make_pud;
14252
14253 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14254+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14255 #endif /* PAGETABLE_LEVELS == 4 */
14256 #endif /* PAGETABLE_LEVELS >= 3 */
14257
14258@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14259 an mfn. We can tell which is which from the index. */
14260 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14261 phys_addr_t phys, pgprot_t flags);
14262+
14263+#ifdef CONFIG_PAX_KERNEXEC
14264+ unsigned long (*pax_open_kernel)(void);
14265+ unsigned long (*pax_close_kernel)(void);
14266+#endif
14267+
14268 };
14269
14270 struct arch_spinlock;
14271@@ -334,7 +341,7 @@ struct pv_lock_ops {
14272 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14273 int (*spin_trylock)(struct arch_spinlock *lock);
14274 void (*spin_unlock)(struct arch_spinlock *lock);
14275-};
14276+} __no_const;
14277
14278 /* This contains all the paravirt structures: we get a convenient
14279 * number for each function using the offset which we use to indicate
14280diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14281index b4389a4..7024269 100644
14282--- a/arch/x86/include/asm/pgalloc.h
14283+++ b/arch/x86/include/asm/pgalloc.h
14284@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14285 pmd_t *pmd, pte_t *pte)
14286 {
14287 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14288+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14289+}
14290+
14291+static inline void pmd_populate_user(struct mm_struct *mm,
14292+ pmd_t *pmd, pte_t *pte)
14293+{
14294+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14295 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14296 }
14297
14298@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14299
14300 #ifdef CONFIG_X86_PAE
14301 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14302+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14303+{
14304+ pud_populate(mm, pudp, pmd);
14305+}
14306 #else /* !CONFIG_X86_PAE */
14307 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14308 {
14309 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14310 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14311 }
14312+
14313+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14314+{
14315+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14316+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14317+}
14318 #endif /* CONFIG_X86_PAE */
14319
14320 #if PAGETABLE_LEVELS > 3
14321@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14322 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14323 }
14324
14325+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14326+{
14327+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14328+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14329+}
14330+
14331 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14332 {
14333 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14334diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14335index f2b489c..4f7e2e5 100644
14336--- a/arch/x86/include/asm/pgtable-2level.h
14337+++ b/arch/x86/include/asm/pgtable-2level.h
14338@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14339
14340 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14341 {
14342+ pax_open_kernel();
14343 *pmdp = pmd;
14344+ pax_close_kernel();
14345 }
14346
14347 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14348diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14349index 4cc9f2b..5fd9226 100644
14350--- a/arch/x86/include/asm/pgtable-3level.h
14351+++ b/arch/x86/include/asm/pgtable-3level.h
14352@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(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 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14358+ pax_close_kernel();
14359 }
14360
14361 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14362 {
14363+ pax_open_kernel();
14364 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14365+ pax_close_kernel();
14366 }
14367
14368 /*
14369diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14370index 1e67223..dd6e7ea 100644
14371--- a/arch/x86/include/asm/pgtable.h
14372+++ b/arch/x86/include/asm/pgtable.h
14373@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14374
14375 #ifndef __PAGETABLE_PUD_FOLDED
14376 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14377+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14378 #define pgd_clear(pgd) native_pgd_clear(pgd)
14379 #endif
14380
14381@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14382
14383 #define arch_end_context_switch(prev) do {} while(0)
14384
14385+#define pax_open_kernel() native_pax_open_kernel()
14386+#define pax_close_kernel() native_pax_close_kernel()
14387 #endif /* CONFIG_PARAVIRT */
14388
14389+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14390+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14391+
14392+#ifdef CONFIG_PAX_KERNEXEC
14393+static inline unsigned long native_pax_open_kernel(void)
14394+{
14395+ unsigned long cr0;
14396+
14397+ preempt_disable();
14398+ barrier();
14399+ cr0 = read_cr0() ^ X86_CR0_WP;
14400+ BUG_ON(cr0 & X86_CR0_WP);
14401+ write_cr0(cr0);
14402+ return cr0 ^ X86_CR0_WP;
14403+}
14404+
14405+static inline unsigned long native_pax_close_kernel(void)
14406+{
14407+ unsigned long cr0;
14408+
14409+ cr0 = read_cr0() ^ X86_CR0_WP;
14410+ BUG_ON(!(cr0 & X86_CR0_WP));
14411+ write_cr0(cr0);
14412+ barrier();
14413+ preempt_enable_no_resched();
14414+ return cr0 ^ X86_CR0_WP;
14415+}
14416+#else
14417+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14418+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14419+#endif
14420+
14421 /*
14422 * The following only work if pte_present() is true.
14423 * Undefined behaviour if not..
14424 */
14425+static inline int pte_user(pte_t pte)
14426+{
14427+ return pte_val(pte) & _PAGE_USER;
14428+}
14429+
14430 static inline int pte_dirty(pte_t pte)
14431 {
14432 return pte_flags(pte) & _PAGE_DIRTY;
14433@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
14434 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
14435 }
14436
14437+static inline unsigned long pgd_pfn(pgd_t pgd)
14438+{
14439+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
14440+}
14441+
14442 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
14443
14444 static inline int pmd_large(pmd_t pte)
14445@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14446 return pte_clear_flags(pte, _PAGE_RW);
14447 }
14448
14449+static inline pte_t pte_mkread(pte_t pte)
14450+{
14451+ return __pte(pte_val(pte) | _PAGE_USER);
14452+}
14453+
14454 static inline pte_t pte_mkexec(pte_t pte)
14455 {
14456- return pte_clear_flags(pte, _PAGE_NX);
14457+#ifdef CONFIG_X86_PAE
14458+ if (__supported_pte_mask & _PAGE_NX)
14459+ return pte_clear_flags(pte, _PAGE_NX);
14460+ else
14461+#endif
14462+ return pte_set_flags(pte, _PAGE_USER);
14463+}
14464+
14465+static inline pte_t pte_exprotect(pte_t pte)
14466+{
14467+#ifdef CONFIG_X86_PAE
14468+ if (__supported_pte_mask & _PAGE_NX)
14469+ return pte_set_flags(pte, _PAGE_NX);
14470+ else
14471+#endif
14472+ return pte_clear_flags(pte, _PAGE_USER);
14473 }
14474
14475 static inline pte_t pte_mkdirty(pte_t pte)
14476@@ -394,6 +459,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14477 #endif
14478
14479 #ifndef __ASSEMBLY__
14480+
14481+#ifdef CONFIG_PAX_PER_CPU_PGD
14482+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14483+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14484+{
14485+ return cpu_pgd[cpu];
14486+}
14487+#endif
14488+
14489 #include <linux/mm_types.h>
14490 #include <linux/log2.h>
14491
14492@@ -529,7 +603,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
14493 * Currently stuck as a macro due to indirect forward reference to
14494 * linux/mmzone.h's __section_mem_map_addr() definition:
14495 */
14496-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
14497+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
14498
14499 /* Find an entry in the second-level page table.. */
14500 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
14501@@ -569,7 +643,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
14502 * Currently stuck as a macro due to indirect forward reference to
14503 * linux/mmzone.h's __section_mem_map_addr() definition:
14504 */
14505-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
14506+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
14507
14508 /* to find an entry in a page-table-directory. */
14509 static inline unsigned long pud_index(unsigned long address)
14510@@ -584,7 +658,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14511
14512 static inline int pgd_bad(pgd_t pgd)
14513 {
14514- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14515+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14516 }
14517
14518 static inline int pgd_none(pgd_t pgd)
14519@@ -607,7 +681,12 @@ static inline int pgd_none(pgd_t pgd)
14520 * pgd_offset() returns a (pgd_t *)
14521 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14522 */
14523-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14524+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14525+
14526+#ifdef CONFIG_PAX_PER_CPU_PGD
14527+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14528+#endif
14529+
14530 /*
14531 * a shortcut which implies the use of the kernel's pgd, instead
14532 * of a process's
14533@@ -618,6 +697,22 @@ static inline int pgd_none(pgd_t pgd)
14534 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14535 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14536
14537+#ifdef CONFIG_X86_32
14538+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14539+#else
14540+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14541+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14542+
14543+#ifdef CONFIG_PAX_MEMORY_UDEREF
14544+#ifdef __ASSEMBLY__
14545+#define pax_user_shadow_base pax_user_shadow_base(%rip)
14546+#else
14547+extern unsigned long pax_user_shadow_base;
14548+#endif
14549+#endif
14550+
14551+#endif
14552+
14553 #ifndef __ASSEMBLY__
14554
14555 extern int direct_gbpages;
14556@@ -784,11 +879,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14557 * dst and src can be on the same page, but the range must not overlap,
14558 * and must not cross a page boundary.
14559 */
14560-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14561+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14562 {
14563- memcpy(dst, src, count * sizeof(pgd_t));
14564+ pax_open_kernel();
14565+ while (count--)
14566+ *dst++ = *src++;
14567+ pax_close_kernel();
14568 }
14569
14570+#ifdef CONFIG_PAX_PER_CPU_PGD
14571+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14572+#endif
14573+
14574+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14575+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14576+#else
14577+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14578+#endif
14579+
14580 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
14581 static inline int page_level_shift(enum pg_level level)
14582 {
14583diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14584index 9ee3221..b979c6b 100644
14585--- a/arch/x86/include/asm/pgtable_32.h
14586+++ b/arch/x86/include/asm/pgtable_32.h
14587@@ -25,9 +25,6 @@
14588 struct mm_struct;
14589 struct vm_area_struct;
14590
14591-extern pgd_t swapper_pg_dir[1024];
14592-extern pgd_t initial_page_table[1024];
14593-
14594 static inline void pgtable_cache_init(void) { }
14595 static inline void check_pgt_cache(void) { }
14596 void paging_init(void);
14597@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14598 # include <asm/pgtable-2level.h>
14599 #endif
14600
14601+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14602+extern pgd_t initial_page_table[PTRS_PER_PGD];
14603+#ifdef CONFIG_X86_PAE
14604+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14605+#endif
14606+
14607 #if defined(CONFIG_HIGHPTE)
14608 #define pte_offset_map(dir, address) \
14609 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14610@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14611 /* Clear a kernel PTE and flush it from the TLB */
14612 #define kpte_clear_flush(ptep, vaddr) \
14613 do { \
14614+ pax_open_kernel(); \
14615 pte_clear(&init_mm, (vaddr), (ptep)); \
14616+ pax_close_kernel(); \
14617 __flush_tlb_one((vaddr)); \
14618 } while (0)
14619
14620 #endif /* !__ASSEMBLY__ */
14621
14622+#define HAVE_ARCH_UNMAPPED_AREA
14623+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14624+
14625 /*
14626 * kern_addr_valid() is (1) for FLATMEM and (0) for
14627 * SPARSEMEM and DISCONTIGMEM
14628diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14629index ed5903b..c7fe163 100644
14630--- a/arch/x86/include/asm/pgtable_32_types.h
14631+++ b/arch/x86/include/asm/pgtable_32_types.h
14632@@ -8,7 +8,7 @@
14633 */
14634 #ifdef CONFIG_X86_PAE
14635 # include <asm/pgtable-3level_types.h>
14636-# define PMD_SIZE (1UL << PMD_SHIFT)
14637+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14638 # define PMD_MASK (~(PMD_SIZE - 1))
14639 #else
14640 # include <asm/pgtable-2level_types.h>
14641@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14642 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14643 #endif
14644
14645+#ifdef CONFIG_PAX_KERNEXEC
14646+#ifndef __ASSEMBLY__
14647+extern unsigned char MODULES_EXEC_VADDR[];
14648+extern unsigned char MODULES_EXEC_END[];
14649+#endif
14650+#include <asm/boot.h>
14651+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14652+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14653+#else
14654+#define ktla_ktva(addr) (addr)
14655+#define ktva_ktla(addr) (addr)
14656+#endif
14657+
14658 #define MODULES_VADDR VMALLOC_START
14659 #define MODULES_END VMALLOC_END
14660 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14661diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14662index e22c1db..23a625a 100644
14663--- a/arch/x86/include/asm/pgtable_64.h
14664+++ b/arch/x86/include/asm/pgtable_64.h
14665@@ -16,10 +16,14 @@
14666
14667 extern pud_t level3_kernel_pgt[512];
14668 extern pud_t level3_ident_pgt[512];
14669+extern pud_t level3_vmalloc_start_pgt[512];
14670+extern pud_t level3_vmalloc_end_pgt[512];
14671+extern pud_t level3_vmemmap_pgt[512];
14672+extern pud_t level2_vmemmap_pgt[512];
14673 extern pmd_t level2_kernel_pgt[512];
14674 extern pmd_t level2_fixmap_pgt[512];
14675-extern pmd_t level2_ident_pgt[512];
14676-extern pgd_t init_level4_pgt[];
14677+extern pmd_t level2_ident_pgt[512*2];
14678+extern pgd_t init_level4_pgt[512];
14679
14680 #define swapper_pg_dir init_level4_pgt
14681
14682@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14683
14684 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14685 {
14686+ pax_open_kernel();
14687 *pmdp = pmd;
14688+ pax_close_kernel();
14689 }
14690
14691 static inline void native_pmd_clear(pmd_t *pmd)
14692@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14693
14694 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14695 {
14696+ pax_open_kernel();
14697 *pudp = pud;
14698+ pax_close_kernel();
14699 }
14700
14701 static inline void native_pud_clear(pud_t *pud)
14702@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14703
14704 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14705 {
14706+ pax_open_kernel();
14707+ *pgdp = pgd;
14708+ pax_close_kernel();
14709+}
14710+
14711+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14712+{
14713 *pgdp = pgd;
14714 }
14715
14716diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14717index 2d88344..4679fc3 100644
14718--- a/arch/x86/include/asm/pgtable_64_types.h
14719+++ b/arch/x86/include/asm/pgtable_64_types.h
14720@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
14721 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14722 #define MODULES_END _AC(0xffffffffff000000, UL)
14723 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14724+#define MODULES_EXEC_VADDR MODULES_VADDR
14725+#define MODULES_EXEC_END MODULES_END
14726+
14727+#define ktla_ktva(addr) (addr)
14728+#define ktva_ktla(addr) (addr)
14729
14730 #define EARLY_DYNAMIC_PAGE_TABLES 64
14731
14732diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14733index e642300..0ef8f31 100644
14734--- a/arch/x86/include/asm/pgtable_types.h
14735+++ b/arch/x86/include/asm/pgtable_types.h
14736@@ -16,13 +16,12 @@
14737 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14738 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14739 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14740-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14741+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14742 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14743 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14744 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14745-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14746-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14747-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14748+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14749+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14750 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14751
14752 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14753@@ -40,7 +39,6 @@
14754 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14755 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14756 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14757-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14758 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14759 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14760 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14761@@ -57,8 +55,10 @@
14762
14763 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14764 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14765-#else
14766+#elif defined(CONFIG_KMEMCHECK)
14767 #define _PAGE_NX (_AT(pteval_t, 0))
14768+#else
14769+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14770 #endif
14771
14772 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14773@@ -116,6 +116,9 @@
14774 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14775 _PAGE_ACCESSED)
14776
14777+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14778+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14779+
14780 #define __PAGE_KERNEL_EXEC \
14781 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14782 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14783@@ -126,7 +129,7 @@
14784 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14785 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14786 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14787-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14788+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14789 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14790 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14791 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14792@@ -188,8 +191,8 @@
14793 * bits are combined, this will alow user to access the high address mapped
14794 * VDSO in the presence of CONFIG_COMPAT_VDSO
14795 */
14796-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14797-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14798+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14799+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14800 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14801 #endif
14802
14803@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14804 {
14805 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14806 }
14807+#endif
14808
14809+#if PAGETABLE_LEVELS == 3
14810+#include <asm-generic/pgtable-nopud.h>
14811+#endif
14812+
14813+#if PAGETABLE_LEVELS == 2
14814+#include <asm-generic/pgtable-nopmd.h>
14815+#endif
14816+
14817+#ifndef __ASSEMBLY__
14818 #if PAGETABLE_LEVELS > 3
14819 typedef struct { pudval_t pud; } pud_t;
14820
14821@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14822 return pud.pud;
14823 }
14824 #else
14825-#include <asm-generic/pgtable-nopud.h>
14826-
14827 static inline pudval_t native_pud_val(pud_t pud)
14828 {
14829 return native_pgd_val(pud.pgd);
14830@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14831 return pmd.pmd;
14832 }
14833 #else
14834-#include <asm-generic/pgtable-nopmd.h>
14835-
14836 static inline pmdval_t native_pmd_val(pmd_t pmd)
14837 {
14838 return native_pgd_val(pmd.pud.pgd);
14839@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14840
14841 extern pteval_t __supported_pte_mask;
14842 extern void set_nx(void);
14843-extern int nx_enabled;
14844
14845 #define pgprot_writecombine pgprot_writecombine
14846 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14847diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14848index 22224b3..4080dab 100644
14849--- a/arch/x86/include/asm/processor.h
14850+++ b/arch/x86/include/asm/processor.h
14851@@ -282,7 +282,7 @@ struct tss_struct {
14852
14853 } ____cacheline_aligned;
14854
14855-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14856+extern struct tss_struct init_tss[NR_CPUS];
14857
14858 /*
14859 * Save the original ist values for checking stack pointers during debugging
14860@@ -823,11 +823,18 @@ static inline void spin_lock_prefetch(const void *x)
14861 */
14862 #define TASK_SIZE PAGE_OFFSET
14863 #define TASK_SIZE_MAX TASK_SIZE
14864+
14865+#ifdef CONFIG_PAX_SEGMEXEC
14866+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14867+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14868+#else
14869 #define STACK_TOP TASK_SIZE
14870-#define STACK_TOP_MAX STACK_TOP
14871+#endif
14872+
14873+#define STACK_TOP_MAX TASK_SIZE
14874
14875 #define INIT_THREAD { \
14876- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14877+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14878 .vm86_info = NULL, \
14879 .sysenter_cs = __KERNEL_CS, \
14880 .io_bitmap_ptr = NULL, \
14881@@ -841,7 +848,7 @@ static inline void spin_lock_prefetch(const void *x)
14882 */
14883 #define INIT_TSS { \
14884 .x86_tss = { \
14885- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14886+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14887 .ss0 = __KERNEL_DS, \
14888 .ss1 = __KERNEL_CS, \
14889 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14890@@ -852,11 +859,7 @@ static inline void spin_lock_prefetch(const void *x)
14891 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14892
14893 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14894-#define KSTK_TOP(info) \
14895-({ \
14896- unsigned long *__ptr = (unsigned long *)(info); \
14897- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14898-})
14899+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14900
14901 /*
14902 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14903@@ -871,7 +874,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14904 #define task_pt_regs(task) \
14905 ({ \
14906 struct pt_regs *__regs__; \
14907- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14908+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14909 __regs__ - 1; \
14910 })
14911
14912@@ -881,13 +884,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14913 /*
14914 * User space process size. 47bits minus one guard page.
14915 */
14916-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14917+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14918
14919 /* This decides where the kernel will search for a free chunk of vm
14920 * space during mmap's.
14921 */
14922 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14923- 0xc0000000 : 0xFFFFe000)
14924+ 0xc0000000 : 0xFFFFf000)
14925
14926 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14927 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14928@@ -898,11 +901,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14929 #define STACK_TOP_MAX TASK_SIZE_MAX
14930
14931 #define INIT_THREAD { \
14932- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14933+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14934 }
14935
14936 #define INIT_TSS { \
14937- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14938+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14939 }
14940
14941 /*
14942@@ -930,6 +933,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14943 */
14944 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14945
14946+#ifdef CONFIG_PAX_SEGMEXEC
14947+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14948+#endif
14949+
14950 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14951
14952 /* Get/set a process' ability to use the timestamp counter instruction */
14953@@ -970,7 +977,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
14954 return ratio;
14955 }
14956
14957-extern unsigned long arch_align_stack(unsigned long sp);
14958+#define arch_align_stack(x) ((x) & ~0xfUL)
14959 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14960
14961 void default_idle(void);
14962@@ -980,6 +987,6 @@ bool xen_set_default_idle(void);
14963 #define xen_set_default_idle 0
14964 #endif
14965
14966-void stop_this_cpu(void *dummy);
14967+void stop_this_cpu(void *dummy) __noreturn;
14968
14969 #endif /* _ASM_X86_PROCESSOR_H */
14970diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14971index 942a086..6c26446 100644
14972--- a/arch/x86/include/asm/ptrace.h
14973+++ b/arch/x86/include/asm/ptrace.h
14974@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14975 }
14976
14977 /*
14978- * user_mode_vm(regs) determines whether a register set came from user mode.
14979+ * user_mode(regs) determines whether a register set came from user mode.
14980 * This is true if V8086 mode was enabled OR if the register set was from
14981 * protected mode with RPL-3 CS value. This tricky test checks that with
14982 * one comparison. Many places in the kernel can bypass this full check
14983- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14984+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14985+ * be used.
14986 */
14987-static inline int user_mode(struct pt_regs *regs)
14988+static inline int user_mode_novm(struct pt_regs *regs)
14989 {
14990 #ifdef CONFIG_X86_32
14991 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14992 #else
14993- return !!(regs->cs & 3);
14994+ return !!(regs->cs & SEGMENT_RPL_MASK);
14995 #endif
14996 }
14997
14998-static inline int user_mode_vm(struct pt_regs *regs)
14999+static inline int user_mode(struct pt_regs *regs)
15000 {
15001 #ifdef CONFIG_X86_32
15002 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
15003 USER_RPL;
15004 #else
15005- return user_mode(regs);
15006+ return user_mode_novm(regs);
15007 #endif
15008 }
15009
15010@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
15011 #ifdef CONFIG_X86_64
15012 static inline bool user_64bit_mode(struct pt_regs *regs)
15013 {
15014+ unsigned long cs = regs->cs & 0xffff;
15015 #ifndef CONFIG_PARAVIRT
15016 /*
15017 * On non-paravirt systems, this is the only long mode CPL 3
15018 * selector. We do not allow long mode selectors in the LDT.
15019 */
15020- return regs->cs == __USER_CS;
15021+ return cs == __USER_CS;
15022 #else
15023 /* Headers are too twisted for this to go in paravirt.h. */
15024- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15025+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15026 #endif
15027 }
15028
15029@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15030 * Traps from the kernel do not save sp and ss.
15031 * Use the helper function to retrieve sp.
15032 */
15033- if (offset == offsetof(struct pt_regs, sp) &&
15034- regs->cs == __KERNEL_CS)
15035- return kernel_stack_pointer(regs);
15036+ if (offset == offsetof(struct pt_regs, sp)) {
15037+ unsigned long cs = regs->cs & 0xffff;
15038+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15039+ return kernel_stack_pointer(regs);
15040+ }
15041 #endif
15042 return *(unsigned long *)((unsigned long)regs + offset);
15043 }
15044diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15045index 9c6b890..5305f53 100644
15046--- a/arch/x86/include/asm/realmode.h
15047+++ b/arch/x86/include/asm/realmode.h
15048@@ -22,16 +22,14 @@ struct real_mode_header {
15049 #endif
15050 /* APM/BIOS reboot */
15051 u32 machine_real_restart_asm;
15052-#ifdef CONFIG_X86_64
15053 u32 machine_real_restart_seg;
15054-#endif
15055 };
15056
15057 /* This must match data at trampoline_32/64.S */
15058 struct trampoline_header {
15059 #ifdef CONFIG_X86_32
15060 u32 start;
15061- u16 gdt_pad;
15062+ u16 boot_cs;
15063 u16 gdt_limit;
15064 u32 gdt_base;
15065 #else
15066diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15067index a82c4f1..ac45053 100644
15068--- a/arch/x86/include/asm/reboot.h
15069+++ b/arch/x86/include/asm/reboot.h
15070@@ -6,13 +6,13 @@
15071 struct pt_regs;
15072
15073 struct machine_ops {
15074- void (*restart)(char *cmd);
15075- void (*halt)(void);
15076- void (*power_off)(void);
15077+ void (* __noreturn restart)(char *cmd);
15078+ void (* __noreturn halt)(void);
15079+ void (* __noreturn power_off)(void);
15080 void (*shutdown)(void);
15081 void (*crash_shutdown)(struct pt_regs *);
15082- void (*emergency_restart)(void);
15083-};
15084+ void (* __noreturn emergency_restart)(void);
15085+} __no_const;
15086
15087 extern struct machine_ops machine_ops;
15088
15089diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15090index cad82c9..2e5c5c1 100644
15091--- a/arch/x86/include/asm/rwsem.h
15092+++ b/arch/x86/include/asm/rwsem.h
15093@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15094 {
15095 asm volatile("# beginning down_read\n\t"
15096 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15097+
15098+#ifdef CONFIG_PAX_REFCOUNT
15099+ "jno 0f\n"
15100+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15101+ "int $4\n0:\n"
15102+ _ASM_EXTABLE(0b, 0b)
15103+#endif
15104+
15105 /* adds 0x00000001 */
15106 " jns 1f\n"
15107 " call call_rwsem_down_read_failed\n"
15108@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15109 "1:\n\t"
15110 " mov %1,%2\n\t"
15111 " add %3,%2\n\t"
15112+
15113+#ifdef CONFIG_PAX_REFCOUNT
15114+ "jno 0f\n"
15115+ "sub %3,%2\n"
15116+ "int $4\n0:\n"
15117+ _ASM_EXTABLE(0b, 0b)
15118+#endif
15119+
15120 " jle 2f\n\t"
15121 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15122 " jnz 1b\n\t"
15123@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15124 long tmp;
15125 asm volatile("# beginning down_write\n\t"
15126 LOCK_PREFIX " xadd %1,(%2)\n\t"
15127+
15128+#ifdef CONFIG_PAX_REFCOUNT
15129+ "jno 0f\n"
15130+ "mov %1,(%2)\n"
15131+ "int $4\n0:\n"
15132+ _ASM_EXTABLE(0b, 0b)
15133+#endif
15134+
15135 /* adds 0xffff0001, returns the old value */
15136 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
15137 /* was the active mask 0 before? */
15138@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15139 long tmp;
15140 asm volatile("# beginning __up_read\n\t"
15141 LOCK_PREFIX " xadd %1,(%2)\n\t"
15142+
15143+#ifdef CONFIG_PAX_REFCOUNT
15144+ "jno 0f\n"
15145+ "mov %1,(%2)\n"
15146+ "int $4\n0:\n"
15147+ _ASM_EXTABLE(0b, 0b)
15148+#endif
15149+
15150 /* subtracts 1, returns the old value */
15151 " jns 1f\n\t"
15152 " call call_rwsem_wake\n" /* expects old value in %edx */
15153@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15154 long tmp;
15155 asm volatile("# beginning __up_write\n\t"
15156 LOCK_PREFIX " xadd %1,(%2)\n\t"
15157+
15158+#ifdef CONFIG_PAX_REFCOUNT
15159+ "jno 0f\n"
15160+ "mov %1,(%2)\n"
15161+ "int $4\n0:\n"
15162+ _ASM_EXTABLE(0b, 0b)
15163+#endif
15164+
15165 /* subtracts 0xffff0001, returns the old value */
15166 " jns 1f\n\t"
15167 " call call_rwsem_wake\n" /* expects old value in %edx */
15168@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15169 {
15170 asm volatile("# beginning __downgrade_write\n\t"
15171 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15172+
15173+#ifdef CONFIG_PAX_REFCOUNT
15174+ "jno 0f\n"
15175+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15176+ "int $4\n0:\n"
15177+ _ASM_EXTABLE(0b, 0b)
15178+#endif
15179+
15180 /*
15181 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15182 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15183@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15184 */
15185 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15186 {
15187- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15188+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15189+
15190+#ifdef CONFIG_PAX_REFCOUNT
15191+ "jno 0f\n"
15192+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15193+ "int $4\n0:\n"
15194+ _ASM_EXTABLE(0b, 0b)
15195+#endif
15196+
15197 : "+m" (sem->count)
15198 : "er" (delta));
15199 }
15200@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15201 */
15202 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15203 {
15204- return delta + xadd(&sem->count, delta);
15205+ return delta + xadd_check_overflow(&sem->count, delta);
15206 }
15207
15208 #endif /* __KERNEL__ */
15209diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15210index c48a950..c6d7468 100644
15211--- a/arch/x86/include/asm/segment.h
15212+++ b/arch/x86/include/asm/segment.h
15213@@ -64,10 +64,15 @@
15214 * 26 - ESPFIX small SS
15215 * 27 - per-cpu [ offset to per-cpu data area ]
15216 * 28 - stack_canary-20 [ for stack protector ]
15217- * 29 - unused
15218- * 30 - unused
15219+ * 29 - PCI BIOS CS
15220+ * 30 - PCI BIOS DS
15221 * 31 - TSS for double fault handler
15222 */
15223+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15224+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15225+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15226+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15227+
15228 #define GDT_ENTRY_TLS_MIN 6
15229 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15230
15231@@ -79,6 +84,8 @@
15232
15233 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15234
15235+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15236+
15237 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15238
15239 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15240@@ -104,6 +111,12 @@
15241 #define __KERNEL_STACK_CANARY 0
15242 #endif
15243
15244+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15245+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15246+
15247+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15248+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15249+
15250 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15251
15252 /*
15253@@ -141,7 +154,7 @@
15254 */
15255
15256 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15257-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15258+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15259
15260
15261 #else
15262@@ -165,6 +178,8 @@
15263 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15264 #define __USER32_DS __USER_DS
15265
15266+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15267+
15268 #define GDT_ENTRY_TSS 8 /* needs two entries */
15269 #define GDT_ENTRY_LDT 10 /* needs two entries */
15270 #define GDT_ENTRY_TLS_MIN 12
15271@@ -185,6 +200,7 @@
15272 #endif
15273
15274 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15275+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15276 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15277 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15278 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15279@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15280 {
15281 unsigned long __limit;
15282 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15283- return __limit + 1;
15284+ return __limit;
15285 }
15286
15287 #endif /* !__ASSEMBLY__ */
15288diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15289index b073aae..39f9bdd 100644
15290--- a/arch/x86/include/asm/smp.h
15291+++ b/arch/x86/include/asm/smp.h
15292@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15293 /* cpus sharing the last level cache: */
15294 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15295 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15296-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15297+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15298
15299 static inline struct cpumask *cpu_sibling_mask(int cpu)
15300 {
15301@@ -79,7 +79,7 @@ struct smp_ops {
15302
15303 void (*send_call_func_ipi)(const struct cpumask *mask);
15304 void (*send_call_func_single_ipi)(int cpu);
15305-};
15306+} __no_const;
15307
15308 /* Globals due to paravirt */
15309 extern void set_cpu_sibling_map(int cpu);
15310@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15311 extern int safe_smp_processor_id(void);
15312
15313 #elif defined(CONFIG_X86_64_SMP)
15314-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15315-
15316-#define stack_smp_processor_id() \
15317-({ \
15318- struct thread_info *ti; \
15319- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15320- ti->cpu; \
15321-})
15322+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15323+#define stack_smp_processor_id() raw_smp_processor_id()
15324 #define safe_smp_processor_id() smp_processor_id()
15325
15326 #endif
15327diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15328index 33692ea..350a534 100644
15329--- a/arch/x86/include/asm/spinlock.h
15330+++ b/arch/x86/include/asm/spinlock.h
15331@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15332 static inline void arch_read_lock(arch_rwlock_t *rw)
15333 {
15334 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15335+
15336+#ifdef CONFIG_PAX_REFCOUNT
15337+ "jno 0f\n"
15338+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15339+ "int $4\n0:\n"
15340+ _ASM_EXTABLE(0b, 0b)
15341+#endif
15342+
15343 "jns 1f\n"
15344 "call __read_lock_failed\n\t"
15345 "1:\n"
15346@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15347 static inline void arch_write_lock(arch_rwlock_t *rw)
15348 {
15349 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15350+
15351+#ifdef CONFIG_PAX_REFCOUNT
15352+ "jno 0f\n"
15353+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15354+ "int $4\n0:\n"
15355+ _ASM_EXTABLE(0b, 0b)
15356+#endif
15357+
15358 "jz 1f\n"
15359 "call __write_lock_failed\n\t"
15360 "1:\n"
15361@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15362
15363 static inline void arch_read_unlock(arch_rwlock_t *rw)
15364 {
15365- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15366+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15367+
15368+#ifdef CONFIG_PAX_REFCOUNT
15369+ "jno 0f\n"
15370+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15371+ "int $4\n0:\n"
15372+ _ASM_EXTABLE(0b, 0b)
15373+#endif
15374+
15375 :"+m" (rw->lock) : : "memory");
15376 }
15377
15378 static inline void arch_write_unlock(arch_rwlock_t *rw)
15379 {
15380- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15381+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15382+
15383+#ifdef CONFIG_PAX_REFCOUNT
15384+ "jno 0f\n"
15385+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15386+ "int $4\n0:\n"
15387+ _ASM_EXTABLE(0b, 0b)
15388+#endif
15389+
15390 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15391 }
15392
15393diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15394index 6a99859..03cb807 100644
15395--- a/arch/x86/include/asm/stackprotector.h
15396+++ b/arch/x86/include/asm/stackprotector.h
15397@@ -47,7 +47,7 @@
15398 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15399 */
15400 #define GDT_STACK_CANARY_INIT \
15401- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15402+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15403
15404 /*
15405 * Initialize the stackprotector canary value.
15406@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15407
15408 static inline void load_stack_canary_segment(void)
15409 {
15410-#ifdef CONFIG_X86_32
15411+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15412 asm volatile ("mov %0, %%gs" : : "r" (0));
15413 #endif
15414 }
15415diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15416index 70bbe39..4ae2bd4 100644
15417--- a/arch/x86/include/asm/stacktrace.h
15418+++ b/arch/x86/include/asm/stacktrace.h
15419@@ -11,28 +11,20 @@
15420
15421 extern int kstack_depth_to_print;
15422
15423-struct thread_info;
15424+struct task_struct;
15425 struct stacktrace_ops;
15426
15427-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15428- unsigned long *stack,
15429- unsigned long bp,
15430- const struct stacktrace_ops *ops,
15431- void *data,
15432- unsigned long *end,
15433- int *graph);
15434+typedef unsigned long walk_stack_t(struct task_struct *task,
15435+ void *stack_start,
15436+ unsigned long *stack,
15437+ unsigned long bp,
15438+ const struct stacktrace_ops *ops,
15439+ void *data,
15440+ unsigned long *end,
15441+ int *graph);
15442
15443-extern unsigned long
15444-print_context_stack(struct thread_info *tinfo,
15445- unsigned long *stack, unsigned long bp,
15446- const struct stacktrace_ops *ops, void *data,
15447- unsigned long *end, int *graph);
15448-
15449-extern unsigned long
15450-print_context_stack_bp(struct thread_info *tinfo,
15451- unsigned long *stack, unsigned long bp,
15452- const struct stacktrace_ops *ops, void *data,
15453- unsigned long *end, int *graph);
15454+extern walk_stack_t print_context_stack;
15455+extern walk_stack_t print_context_stack_bp;
15456
15457 /* Generic stack tracer with callbacks */
15458
15459@@ -40,7 +32,7 @@ struct stacktrace_ops {
15460 void (*address)(void *data, unsigned long address, int reliable);
15461 /* On negative return stop dumping */
15462 int (*stack)(void *data, char *name);
15463- walk_stack_t walk_stack;
15464+ walk_stack_t *walk_stack;
15465 };
15466
15467 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15468diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15469index 4ec45b3..a4f0a8a 100644
15470--- a/arch/x86/include/asm/switch_to.h
15471+++ b/arch/x86/include/asm/switch_to.h
15472@@ -108,7 +108,7 @@ do { \
15473 "call __switch_to\n\t" \
15474 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15475 __switch_canary \
15476- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15477+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15478 "movq %%rax,%%rdi\n\t" \
15479 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15480 "jnz ret_from_fork\n\t" \
15481@@ -119,7 +119,7 @@ do { \
15482 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15483 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15484 [_tif_fork] "i" (_TIF_FORK), \
15485- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15486+ [thread_info] "m" (current_tinfo), \
15487 [current_task] "m" (current_task) \
15488 __switch_canary_iparam \
15489 : "memory", "cc" __EXTRA_CLOBBER)
15490diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15491index a1df6e8..e002940 100644
15492--- a/arch/x86/include/asm/thread_info.h
15493+++ b/arch/x86/include/asm/thread_info.h
15494@@ -10,6 +10,7 @@
15495 #include <linux/compiler.h>
15496 #include <asm/page.h>
15497 #include <asm/types.h>
15498+#include <asm/percpu.h>
15499
15500 /*
15501 * low level task data that entry.S needs immediate access to
15502@@ -23,7 +24,6 @@ struct exec_domain;
15503 #include <linux/atomic.h>
15504
15505 struct thread_info {
15506- struct task_struct *task; /* main task structure */
15507 struct exec_domain *exec_domain; /* execution domain */
15508 __u32 flags; /* low level flags */
15509 __u32 status; /* thread synchronous flags */
15510@@ -33,19 +33,13 @@ struct thread_info {
15511 mm_segment_t addr_limit;
15512 struct restart_block restart_block;
15513 void __user *sysenter_return;
15514-#ifdef CONFIG_X86_32
15515- unsigned long previous_esp; /* ESP of the previous stack in
15516- case of nested (IRQ) stacks
15517- */
15518- __u8 supervisor_stack[0];
15519-#endif
15520+ unsigned long lowest_stack;
15521 unsigned int sig_on_uaccess_error:1;
15522 unsigned int uaccess_err:1; /* uaccess failed */
15523 };
15524
15525-#define INIT_THREAD_INFO(tsk) \
15526+#define INIT_THREAD_INFO \
15527 { \
15528- .task = &tsk, \
15529 .exec_domain = &default_exec_domain, \
15530 .flags = 0, \
15531 .cpu = 0, \
15532@@ -56,7 +50,7 @@ struct thread_info {
15533 }, \
15534 }
15535
15536-#define init_thread_info (init_thread_union.thread_info)
15537+#define init_thread_info (init_thread_union.stack)
15538 #define init_stack (init_thread_union.stack)
15539
15540 #else /* !__ASSEMBLY__ */
15541@@ -97,6 +91,7 @@ struct thread_info {
15542 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15543 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15544 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15545+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15546
15547 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15548 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15549@@ -121,17 +116,18 @@ struct thread_info {
15550 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15551 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15552 #define _TIF_X32 (1 << TIF_X32)
15553+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15554
15555 /* work to do in syscall_trace_enter() */
15556 #define _TIF_WORK_SYSCALL_ENTRY \
15557 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15558 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15559- _TIF_NOHZ)
15560+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15561
15562 /* work to do in syscall_trace_leave() */
15563 #define _TIF_WORK_SYSCALL_EXIT \
15564 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15565- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15566+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15567
15568 /* work to do on interrupt/exception return */
15569 #define _TIF_WORK_MASK \
15570@@ -142,7 +138,7 @@ struct thread_info {
15571 /* work to do on any return to user space */
15572 #define _TIF_ALLWORK_MASK \
15573 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15574- _TIF_NOHZ)
15575+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15576
15577 /* Only used for 64 bit */
15578 #define _TIF_DO_NOTIFY_MASK \
15579@@ -158,45 +154,40 @@ struct thread_info {
15580
15581 #define PREEMPT_ACTIVE 0x10000000
15582
15583-#ifdef CONFIG_X86_32
15584-
15585-#define STACK_WARN (THREAD_SIZE/8)
15586-/*
15587- * macros/functions for gaining access to the thread information structure
15588- *
15589- * preempt_count needs to be 1 initially, until the scheduler is functional.
15590- */
15591-#ifndef __ASSEMBLY__
15592-
15593-
15594-/* how to get the current stack pointer from C */
15595-register unsigned long current_stack_pointer asm("esp") __used;
15596-
15597-/* how to get the thread information struct from C */
15598-static inline struct thread_info *current_thread_info(void)
15599-{
15600- return (struct thread_info *)
15601- (current_stack_pointer & ~(THREAD_SIZE - 1));
15602-}
15603-
15604-#else /* !__ASSEMBLY__ */
15605-
15606+#ifdef __ASSEMBLY__
15607 /* how to get the thread information struct from ASM */
15608 #define GET_THREAD_INFO(reg) \
15609- movl $-THREAD_SIZE, reg; \
15610- andl %esp, reg
15611+ mov PER_CPU_VAR(current_tinfo), reg
15612
15613 /* use this one if reg already contains %esp */
15614-#define GET_THREAD_INFO_WITH_ESP(reg) \
15615- andl $-THREAD_SIZE, reg
15616+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15617+#else
15618+/* how to get the thread information struct from C */
15619+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15620+
15621+static __always_inline struct thread_info *current_thread_info(void)
15622+{
15623+ return this_cpu_read_stable(current_tinfo);
15624+}
15625+#endif
15626+
15627+#ifdef CONFIG_X86_32
15628+
15629+#define STACK_WARN (THREAD_SIZE/8)
15630+/*
15631+ * macros/functions for gaining access to the thread information structure
15632+ *
15633+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15634+ */
15635+#ifndef __ASSEMBLY__
15636+
15637+/* how to get the current stack pointer from C */
15638+register unsigned long current_stack_pointer asm("esp") __used;
15639
15640 #endif
15641
15642 #else /* X86_32 */
15643
15644-#include <asm/percpu.h>
15645-#define KERNEL_STACK_OFFSET (5*8)
15646-
15647 /*
15648 * macros/functions for gaining access to the thread information structure
15649 * preempt_count needs to be 1 initially, until the scheduler is functional.
15650@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
15651 #ifndef __ASSEMBLY__
15652 DECLARE_PER_CPU(unsigned long, kernel_stack);
15653
15654-static inline struct thread_info *current_thread_info(void)
15655-{
15656- struct thread_info *ti;
15657- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15658- KERNEL_STACK_OFFSET - THREAD_SIZE);
15659- return ti;
15660-}
15661-
15662-#else /* !__ASSEMBLY__ */
15663-
15664-/* how to get the thread information struct from ASM */
15665-#define GET_THREAD_INFO(reg) \
15666- movq PER_CPU_VAR(kernel_stack),reg ; \
15667- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15668-
15669-/*
15670- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15671- * a certain register (to be used in assembler memory operands).
15672- */
15673-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15674-
15675+/* how to get the current stack pointer from C */
15676+register unsigned long current_stack_pointer asm("rsp") __used;
15677 #endif
15678
15679 #endif /* !X86_32 */
15680@@ -283,5 +255,12 @@ static inline bool is_ia32_task(void)
15681 extern void arch_task_cache_init(void);
15682 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15683 extern void arch_release_task_struct(struct task_struct *tsk);
15684+
15685+#define __HAVE_THREAD_FUNCTIONS
15686+#define task_thread_info(task) (&(task)->tinfo)
15687+#define task_stack_page(task) ((task)->stack)
15688+#define setup_thread_stack(p, org) do {} while (0)
15689+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15690+
15691 #endif
15692 #endif /* _ASM_X86_THREAD_INFO_H */
15693diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15694index 5ee2687..70d5895 100644
15695--- a/arch/x86/include/asm/uaccess.h
15696+++ b/arch/x86/include/asm/uaccess.h
15697@@ -7,6 +7,7 @@
15698 #include <linux/compiler.h>
15699 #include <linux/thread_info.h>
15700 #include <linux/string.h>
15701+#include <linux/sched.h>
15702 #include <asm/asm.h>
15703 #include <asm/page.h>
15704 #include <asm/smap.h>
15705@@ -29,7 +30,12 @@
15706
15707 #define get_ds() (KERNEL_DS)
15708 #define get_fs() (current_thread_info()->addr_limit)
15709+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15710+void __set_fs(mm_segment_t x);
15711+void set_fs(mm_segment_t x);
15712+#else
15713 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15714+#endif
15715
15716 #define segment_eq(a, b) ((a).seg == (b).seg)
15717
15718@@ -77,8 +83,33 @@
15719 * checks that the pointer is in the user space range - after calling
15720 * this function, memory access functions may still return -EFAULT.
15721 */
15722-#define access_ok(type, addr, size) \
15723- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15724+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15725+#define access_ok(type, addr, size) \
15726+({ \
15727+ long __size = size; \
15728+ unsigned long __addr = (unsigned long)addr; \
15729+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15730+ unsigned long __end_ao = __addr + __size - 1; \
15731+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15732+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15733+ while(__addr_ao <= __end_ao) { \
15734+ char __c_ao; \
15735+ __addr_ao += PAGE_SIZE; \
15736+ if (__size > PAGE_SIZE) \
15737+ cond_resched(); \
15738+ if (__get_user(__c_ao, (char __user *)__addr)) \
15739+ break; \
15740+ if (type != VERIFY_WRITE) { \
15741+ __addr = __addr_ao; \
15742+ continue; \
15743+ } \
15744+ if (__put_user(__c_ao, (char __user *)__addr)) \
15745+ break; \
15746+ __addr = __addr_ao; \
15747+ } \
15748+ } \
15749+ __ret_ao; \
15750+})
15751
15752 /*
15753 * The exception table consists of pairs of addresses relative to the
15754@@ -176,13 +207,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15755 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15756 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15757
15758-
15759+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15760+#define __copyuser_seg "gs;"
15761+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15762+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15763+#else
15764+#define __copyuser_seg
15765+#define __COPYUSER_SET_ES
15766+#define __COPYUSER_RESTORE_ES
15767+#endif
15768
15769 #ifdef CONFIG_X86_32
15770 #define __put_user_asm_u64(x, addr, err, errret) \
15771 asm volatile(ASM_STAC "\n" \
15772- "1: movl %%eax,0(%2)\n" \
15773- "2: movl %%edx,4(%2)\n" \
15774+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15775+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15776 "3: " ASM_CLAC "\n" \
15777 ".section .fixup,\"ax\"\n" \
15778 "4: movl %3,%0\n" \
15779@@ -195,8 +234,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15780
15781 #define __put_user_asm_ex_u64(x, addr) \
15782 asm volatile(ASM_STAC "\n" \
15783- "1: movl %%eax,0(%1)\n" \
15784- "2: movl %%edx,4(%1)\n" \
15785+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15786+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15787 "3: " ASM_CLAC "\n" \
15788 _ASM_EXTABLE_EX(1b, 2b) \
15789 _ASM_EXTABLE_EX(2b, 3b) \
15790@@ -246,7 +285,7 @@ extern void __put_user_8(void);
15791 __typeof__(*(ptr)) __pu_val; \
15792 __chk_user_ptr(ptr); \
15793 might_fault(); \
15794- __pu_val = x; \
15795+ __pu_val = (x); \
15796 switch (sizeof(*(ptr))) { \
15797 case 1: \
15798 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15799@@ -345,7 +384,7 @@ do { \
15800
15801 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15802 asm volatile(ASM_STAC "\n" \
15803- "1: mov"itype" %2,%"rtype"1\n" \
15804+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15805 "2: " ASM_CLAC "\n" \
15806 ".section .fixup,\"ax\"\n" \
15807 "3: mov %3,%0\n" \
15808@@ -353,7 +392,7 @@ do { \
15809 " jmp 2b\n" \
15810 ".previous\n" \
15811 _ASM_EXTABLE(1b, 3b) \
15812- : "=r" (err), ltype(x) \
15813+ : "=r" (err), ltype (x) \
15814 : "m" (__m(addr)), "i" (errret), "0" (err))
15815
15816 #define __get_user_size_ex(x, ptr, size) \
15817@@ -378,7 +417,7 @@ do { \
15818 } while (0)
15819
15820 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15821- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15822+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15823 "2:\n" \
15824 _ASM_EXTABLE_EX(1b, 2b) \
15825 : ltype(x) : "m" (__m(addr)))
15826@@ -395,13 +434,24 @@ do { \
15827 int __gu_err; \
15828 unsigned long __gu_val; \
15829 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15830- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15831+ (x) = (__typeof__(*(ptr)))__gu_val; \
15832 __gu_err; \
15833 })
15834
15835 /* FIXME: this hack is definitely wrong -AK */
15836 struct __large_struct { unsigned long buf[100]; };
15837-#define __m(x) (*(struct __large_struct __user *)(x))
15838+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15839+#define ____m(x) \
15840+({ \
15841+ unsigned long ____x = (unsigned long)(x); \
15842+ if (____x < pax_user_shadow_base) \
15843+ ____x += pax_user_shadow_base; \
15844+ (typeof(x))____x; \
15845+})
15846+#else
15847+#define ____m(x) (x)
15848+#endif
15849+#define __m(x) (*(struct __large_struct __user *)____m(x))
15850
15851 /*
15852 * Tell gcc we read from memory instead of writing: this is because
15853@@ -410,7 +460,7 @@ struct __large_struct { unsigned long buf[100]; };
15854 */
15855 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15856 asm volatile(ASM_STAC "\n" \
15857- "1: mov"itype" %"rtype"1,%2\n" \
15858+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15859 "2: " ASM_CLAC "\n" \
15860 ".section .fixup,\"ax\"\n" \
15861 "3: mov %3,%0\n" \
15862@@ -418,10 +468,10 @@ struct __large_struct { unsigned long buf[100]; };
15863 ".previous\n" \
15864 _ASM_EXTABLE(1b, 3b) \
15865 : "=r"(err) \
15866- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15867+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15868
15869 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15870- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15871+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15872 "2:\n" \
15873 _ASM_EXTABLE_EX(1b, 2b) \
15874 : : ltype(x), "m" (__m(addr)))
15875@@ -460,8 +510,12 @@ struct __large_struct { unsigned long buf[100]; };
15876 * On error, the variable @x is set to zero.
15877 */
15878
15879+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15880+#define __get_user(x, ptr) get_user((x), (ptr))
15881+#else
15882 #define __get_user(x, ptr) \
15883 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15884+#endif
15885
15886 /**
15887 * __put_user: - Write a simple value into user space, with less checking.
15888@@ -483,8 +537,12 @@ struct __large_struct { unsigned long buf[100]; };
15889 * Returns zero on success, or -EFAULT on error.
15890 */
15891
15892+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15893+#define __put_user(x, ptr) put_user((x), (ptr))
15894+#else
15895 #define __put_user(x, ptr) \
15896 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15897+#endif
15898
15899 #define __get_user_unaligned __get_user
15900 #define __put_user_unaligned __put_user
15901@@ -502,7 +560,7 @@ struct __large_struct { unsigned long buf[100]; };
15902 #define get_user_ex(x, ptr) do { \
15903 unsigned long __gue_val; \
15904 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15905- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15906+ (x) = (__typeof__(*(ptr)))__gue_val; \
15907 } while (0)
15908
15909 #define put_user_try uaccess_try
15910@@ -519,8 +577,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15911 extern __must_check long strlen_user(const char __user *str);
15912 extern __must_check long strnlen_user(const char __user *str, long n);
15913
15914-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15915-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15916+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15917+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15918
15919 /*
15920 * movsl can be slow when source and dest are not both 8-byte aligned
15921diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15922index 7f760a9..04b1c65 100644
15923--- a/arch/x86/include/asm/uaccess_32.h
15924+++ b/arch/x86/include/asm/uaccess_32.h
15925@@ -11,15 +11,15 @@
15926 #include <asm/page.h>
15927
15928 unsigned long __must_check __copy_to_user_ll
15929- (void __user *to, const void *from, unsigned long n);
15930+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15931 unsigned long __must_check __copy_from_user_ll
15932- (void *to, const void __user *from, unsigned long n);
15933+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15934 unsigned long __must_check __copy_from_user_ll_nozero
15935- (void *to, const void __user *from, unsigned long n);
15936+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15937 unsigned long __must_check __copy_from_user_ll_nocache
15938- (void *to, const void __user *from, unsigned long n);
15939+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15940 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15941- (void *to, const void __user *from, unsigned long n);
15942+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15943
15944 /**
15945 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15946@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15947 static __always_inline unsigned long __must_check
15948 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15949 {
15950+ if ((long)n < 0)
15951+ return n;
15952+
15953+ check_object_size(from, n, true);
15954+
15955 if (__builtin_constant_p(n)) {
15956 unsigned long ret;
15957
15958@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15959 __copy_to_user(void __user *to, const void *from, unsigned long n)
15960 {
15961 might_fault();
15962+
15963 return __copy_to_user_inatomic(to, from, n);
15964 }
15965
15966 static __always_inline unsigned long
15967 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15968 {
15969+ if ((long)n < 0)
15970+ return n;
15971+
15972 /* Avoid zeroing the tail if the copy fails..
15973 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15974 * but as the zeroing behaviour is only significant when n is not
15975@@ -137,6 +146,12 @@ static __always_inline unsigned long
15976 __copy_from_user(void *to, const void __user *from, unsigned long n)
15977 {
15978 might_fault();
15979+
15980+ if ((long)n < 0)
15981+ return n;
15982+
15983+ check_object_size(to, n, false);
15984+
15985 if (__builtin_constant_p(n)) {
15986 unsigned long ret;
15987
15988@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15989 const void __user *from, unsigned long n)
15990 {
15991 might_fault();
15992+
15993+ if ((long)n < 0)
15994+ return n;
15995+
15996 if (__builtin_constant_p(n)) {
15997 unsigned long ret;
15998
15999@@ -181,15 +200,19 @@ static __always_inline unsigned long
16000 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
16001 unsigned long n)
16002 {
16003- return __copy_from_user_ll_nocache_nozero(to, from, n);
16004+ if ((long)n < 0)
16005+ return n;
16006+
16007+ return __copy_from_user_ll_nocache_nozero(to, from, n);
16008 }
16009
16010-unsigned long __must_check copy_to_user(void __user *to,
16011- const void *from, unsigned long n);
16012-unsigned long __must_check _copy_from_user(void *to,
16013- const void __user *from,
16014- unsigned long n);
16015-
16016+extern void copy_to_user_overflow(void)
16017+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16018+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16019+#else
16020+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16021+#endif
16022+;
16023
16024 extern void copy_from_user_overflow(void)
16025 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16026@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16027 #endif
16028 ;
16029
16030-static inline unsigned long __must_check copy_from_user(void *to,
16031- const void __user *from,
16032- unsigned long n)
16033+/**
16034+ * copy_to_user: - Copy a block of data into user space.
16035+ * @to: Destination address, in user space.
16036+ * @from: Source address, in kernel space.
16037+ * @n: Number of bytes to copy.
16038+ *
16039+ * Context: User context only. This function may sleep.
16040+ *
16041+ * Copy data from kernel space to user space.
16042+ *
16043+ * Returns number of bytes that could not be copied.
16044+ * On success, this will be zero.
16045+ */
16046+static inline unsigned long __must_check
16047+copy_to_user(void __user *to, const void *from, unsigned long n)
16048 {
16049- int sz = __compiletime_object_size(to);
16050+ size_t sz = __compiletime_object_size(from);
16051
16052- if (likely(sz == -1 || sz >= n))
16053- n = _copy_from_user(to, from, n);
16054- else
16055+ if (unlikely(sz != (size_t)-1 && sz < n))
16056+ copy_to_user_overflow();
16057+ else if (access_ok(VERIFY_WRITE, to, n))
16058+ n = __copy_to_user(to, from, n);
16059+ return n;
16060+}
16061+
16062+/**
16063+ * copy_from_user: - Copy a block of data from user space.
16064+ * @to: Destination address, in kernel space.
16065+ * @from: Source address, in user space.
16066+ * @n: Number of bytes to copy.
16067+ *
16068+ * Context: User context only. This function may sleep.
16069+ *
16070+ * Copy data from user space to kernel space.
16071+ *
16072+ * Returns number of bytes that could not be copied.
16073+ * On success, this will be zero.
16074+ *
16075+ * If some data could not be copied, this function will pad the copied
16076+ * data to the requested size using zero bytes.
16077+ */
16078+static inline unsigned long __must_check
16079+copy_from_user(void *to, const void __user *from, unsigned long n)
16080+{
16081+ size_t sz = __compiletime_object_size(to);
16082+
16083+ check_object_size(to, n, false);
16084+
16085+ if (unlikely(sz != (size_t)-1 && sz < n))
16086 copy_from_user_overflow();
16087-
16088+ else if (access_ok(VERIFY_READ, from, n))
16089+ n = __copy_from_user(to, from, n);
16090+ else if ((long)n > 0)
16091+ memset(to, 0, n);
16092 return n;
16093 }
16094
16095diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16096index 142810c..1f2a0a7 100644
16097--- a/arch/x86/include/asm/uaccess_64.h
16098+++ b/arch/x86/include/asm/uaccess_64.h
16099@@ -10,6 +10,9 @@
16100 #include <asm/alternative.h>
16101 #include <asm/cpufeature.h>
16102 #include <asm/page.h>
16103+#include <asm/pgtable.h>
16104+
16105+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16106
16107 /*
16108 * Copy To/From Userspace
16109@@ -17,13 +20,13 @@
16110
16111 /* Handles exceptions in both to and from, but doesn't do access_ok */
16112 __must_check unsigned long
16113-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16114+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16115 __must_check unsigned long
16116-copy_user_generic_string(void *to, const void *from, unsigned len);
16117+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16118 __must_check unsigned long
16119-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16120+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16121
16122-static __always_inline __must_check unsigned long
16123+static __always_inline __must_check __size_overflow(3) unsigned long
16124 copy_user_generic(void *to, const void *from, unsigned len)
16125 {
16126 unsigned ret;
16127@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16128 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16129 "=d" (len)),
16130 "1" (to), "2" (from), "3" (len)
16131- : "memory", "rcx", "r8", "r9", "r10", "r11");
16132+ : "memory", "rcx", "r8", "r9", "r11");
16133 return ret;
16134 }
16135
16136+static __always_inline __must_check unsigned long
16137+__copy_to_user(void __user *to, const void *from, unsigned long len);
16138+static __always_inline __must_check unsigned long
16139+__copy_from_user(void *to, const void __user *from, unsigned long len);
16140 __must_check unsigned long
16141-_copy_to_user(void __user *to, const void *from, unsigned len);
16142-__must_check unsigned long
16143-_copy_from_user(void *to, const void __user *from, unsigned len);
16144-__must_check unsigned long
16145-copy_in_user(void __user *to, const void __user *from, unsigned len);
16146+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16147+
16148+extern void copy_to_user_overflow(void)
16149+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16150+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16151+#else
16152+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16153+#endif
16154+;
16155+
16156+extern void copy_from_user_overflow(void)
16157+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16158+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16159+#else
16160+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16161+#endif
16162+;
16163
16164 static inline unsigned long __must_check copy_from_user(void *to,
16165 const void __user *from,
16166 unsigned long n)
16167 {
16168- int sz = __compiletime_object_size(to);
16169-
16170 might_fault();
16171- if (likely(sz == -1 || sz >= n))
16172- n = _copy_from_user(to, from, n);
16173-#ifdef CONFIG_DEBUG_VM
16174- else
16175- WARN(1, "Buffer overflow detected!\n");
16176-#endif
16177+
16178+ check_object_size(to, n, false);
16179+
16180+ if (access_ok(VERIFY_READ, from, n))
16181+ n = __copy_from_user(to, from, n);
16182+ else if (n < INT_MAX)
16183+ memset(to, 0, n);
16184 return n;
16185 }
16186
16187 static __always_inline __must_check
16188-int copy_to_user(void __user *dst, const void *src, unsigned size)
16189+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16190 {
16191 might_fault();
16192
16193- return _copy_to_user(dst, src, size);
16194+ if (access_ok(VERIFY_WRITE, dst, size))
16195+ size = __copy_to_user(dst, src, size);
16196+ return size;
16197 }
16198
16199 static __always_inline __must_check
16200-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16201+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16202 {
16203- int ret = 0;
16204+ size_t sz = __compiletime_object_size(dst);
16205+ unsigned ret = 0;
16206
16207 might_fault();
16208+
16209+ if (size > INT_MAX)
16210+ return size;
16211+
16212+ check_object_size(dst, size, false);
16213+
16214+#ifdef CONFIG_PAX_MEMORY_UDEREF
16215+ if (!__access_ok(VERIFY_READ, src, size))
16216+ return size;
16217+#endif
16218+
16219+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16220+ copy_from_user_overflow();
16221+ return size;
16222+ }
16223+
16224 if (!__builtin_constant_p(size))
16225- return copy_user_generic(dst, (__force void *)src, size);
16226+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16227 switch (size) {
16228- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16229+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16230 ret, "b", "b", "=q", 1);
16231 return ret;
16232- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16233+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16234 ret, "w", "w", "=r", 2);
16235 return ret;
16236- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16237+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16238 ret, "l", "k", "=r", 4);
16239 return ret;
16240- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16241+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16242 ret, "q", "", "=r", 8);
16243 return ret;
16244 case 10:
16245- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16246+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16247 ret, "q", "", "=r", 10);
16248 if (unlikely(ret))
16249 return ret;
16250 __get_user_asm(*(u16 *)(8 + (char *)dst),
16251- (u16 __user *)(8 + (char __user *)src),
16252+ (const u16 __user *)(8 + (const char __user *)src),
16253 ret, "w", "w", "=r", 2);
16254 return ret;
16255 case 16:
16256- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16257+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16258 ret, "q", "", "=r", 16);
16259 if (unlikely(ret))
16260 return ret;
16261 __get_user_asm(*(u64 *)(8 + (char *)dst),
16262- (u64 __user *)(8 + (char __user *)src),
16263+ (const u64 __user *)(8 + (const char __user *)src),
16264 ret, "q", "", "=r", 8);
16265 return ret;
16266 default:
16267- return copy_user_generic(dst, (__force void *)src, size);
16268+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16269 }
16270 }
16271
16272 static __always_inline __must_check
16273-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16274+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16275 {
16276- int ret = 0;
16277+ size_t sz = __compiletime_object_size(src);
16278+ unsigned ret = 0;
16279
16280 might_fault();
16281+
16282+ if (size > INT_MAX)
16283+ return size;
16284+
16285+ check_object_size(src, size, true);
16286+
16287+#ifdef CONFIG_PAX_MEMORY_UDEREF
16288+ if (!__access_ok(VERIFY_WRITE, dst, size))
16289+ return size;
16290+#endif
16291+
16292+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16293+ copy_to_user_overflow();
16294+ return size;
16295+ }
16296+
16297 if (!__builtin_constant_p(size))
16298- return copy_user_generic((__force void *)dst, src, size);
16299+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16300 switch (size) {
16301- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16302+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16303 ret, "b", "b", "iq", 1);
16304 return ret;
16305- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16306+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16307 ret, "w", "w", "ir", 2);
16308 return ret;
16309- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16310+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16311 ret, "l", "k", "ir", 4);
16312 return ret;
16313- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16314+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16315 ret, "q", "", "er", 8);
16316 return ret;
16317 case 10:
16318- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16319+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16320 ret, "q", "", "er", 10);
16321 if (unlikely(ret))
16322 return ret;
16323 asm("":::"memory");
16324- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16325+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16326 ret, "w", "w", "ir", 2);
16327 return ret;
16328 case 16:
16329- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16330+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16331 ret, "q", "", "er", 16);
16332 if (unlikely(ret))
16333 return ret;
16334 asm("":::"memory");
16335- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16336+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16337 ret, "q", "", "er", 8);
16338 return ret;
16339 default:
16340- return copy_user_generic((__force void *)dst, src, size);
16341+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16342 }
16343 }
16344
16345 static __always_inline __must_check
16346-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16347+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16348 {
16349- int ret = 0;
16350+ unsigned ret = 0;
16351
16352 might_fault();
16353+
16354+ if (size > INT_MAX)
16355+ return size;
16356+
16357+#ifdef CONFIG_PAX_MEMORY_UDEREF
16358+ if (!__access_ok(VERIFY_READ, src, size))
16359+ return size;
16360+ if (!__access_ok(VERIFY_WRITE, dst, size))
16361+ return size;
16362+#endif
16363+
16364 if (!__builtin_constant_p(size))
16365- return copy_user_generic((__force void *)dst,
16366- (__force void *)src, size);
16367+ return copy_user_generic((__force_kernel void *)____m(dst),
16368+ (__force_kernel const void *)____m(src), size);
16369 switch (size) {
16370 case 1: {
16371 u8 tmp;
16372- __get_user_asm(tmp, (u8 __user *)src,
16373+ __get_user_asm(tmp, (const u8 __user *)src,
16374 ret, "b", "b", "=q", 1);
16375 if (likely(!ret))
16376 __put_user_asm(tmp, (u8 __user *)dst,
16377@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16378 }
16379 case 2: {
16380 u16 tmp;
16381- __get_user_asm(tmp, (u16 __user *)src,
16382+ __get_user_asm(tmp, (const u16 __user *)src,
16383 ret, "w", "w", "=r", 2);
16384 if (likely(!ret))
16385 __put_user_asm(tmp, (u16 __user *)dst,
16386@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16387
16388 case 4: {
16389 u32 tmp;
16390- __get_user_asm(tmp, (u32 __user *)src,
16391+ __get_user_asm(tmp, (const u32 __user *)src,
16392 ret, "l", "k", "=r", 4);
16393 if (likely(!ret))
16394 __put_user_asm(tmp, (u32 __user *)dst,
16395@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16396 }
16397 case 8: {
16398 u64 tmp;
16399- __get_user_asm(tmp, (u64 __user *)src,
16400+ __get_user_asm(tmp, (const u64 __user *)src,
16401 ret, "q", "", "=r", 8);
16402 if (likely(!ret))
16403 __put_user_asm(tmp, (u64 __user *)dst,
16404@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16405 return ret;
16406 }
16407 default:
16408- return copy_user_generic((__force void *)dst,
16409- (__force void *)src, size);
16410+ return copy_user_generic((__force_kernel void *)____m(dst),
16411+ (__force_kernel const void *)____m(src), size);
16412 }
16413 }
16414
16415 static __must_check __always_inline int
16416-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16417+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16418 {
16419- return copy_user_generic(dst, (__force const void *)src, size);
16420+ if (size > INT_MAX)
16421+ return size;
16422+
16423+#ifdef CONFIG_PAX_MEMORY_UDEREF
16424+ if (!__access_ok(VERIFY_READ, src, size))
16425+ return size;
16426+#endif
16427+
16428+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16429 }
16430
16431-static __must_check __always_inline int
16432-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16433+static __must_check __always_inline unsigned long
16434+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16435 {
16436- return copy_user_generic((__force void *)dst, src, size);
16437+ if (size > INT_MAX)
16438+ return size;
16439+
16440+#ifdef CONFIG_PAX_MEMORY_UDEREF
16441+ if (!__access_ok(VERIFY_WRITE, dst, size))
16442+ return size;
16443+#endif
16444+
16445+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16446 }
16447
16448-extern long __copy_user_nocache(void *dst, const void __user *src,
16449- unsigned size, int zerorest);
16450+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16451+ unsigned long size, int zerorest) __size_overflow(3);
16452
16453-static inline int
16454-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16455+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16456 {
16457 might_sleep();
16458+
16459+ if (size > INT_MAX)
16460+ return size;
16461+
16462+#ifdef CONFIG_PAX_MEMORY_UDEREF
16463+ if (!__access_ok(VERIFY_READ, src, size))
16464+ return size;
16465+#endif
16466+
16467 return __copy_user_nocache(dst, src, size, 1);
16468 }
16469
16470-static inline int
16471-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16472- unsigned size)
16473+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16474+ unsigned long size)
16475 {
16476+ if (size > INT_MAX)
16477+ return size;
16478+
16479+#ifdef CONFIG_PAX_MEMORY_UDEREF
16480+ if (!__access_ok(VERIFY_READ, src, size))
16481+ return size;
16482+#endif
16483+
16484 return __copy_user_nocache(dst, src, size, 0);
16485 }
16486
16487-unsigned long
16488-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16489+extern unsigned long
16490+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16491
16492 #endif /* _ASM_X86_UACCESS_64_H */
16493diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16494index 5b238981..77fdd78 100644
16495--- a/arch/x86/include/asm/word-at-a-time.h
16496+++ b/arch/x86/include/asm/word-at-a-time.h
16497@@ -11,7 +11,7 @@
16498 * and shift, for example.
16499 */
16500 struct word_at_a_time {
16501- const unsigned long one_bits, high_bits;
16502+ unsigned long one_bits, high_bits;
16503 };
16504
16505 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16506diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16507index d8d9922..bf6cecb 100644
16508--- a/arch/x86/include/asm/x86_init.h
16509+++ b/arch/x86/include/asm/x86_init.h
16510@@ -129,7 +129,7 @@ struct x86_init_ops {
16511 struct x86_init_timers timers;
16512 struct x86_init_iommu iommu;
16513 struct x86_init_pci pci;
16514-};
16515+} __no_const;
16516
16517 /**
16518 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16519@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
16520 void (*setup_percpu_clockev)(void);
16521 void (*early_percpu_clock_init)(void);
16522 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16523-};
16524+} __no_const;
16525
16526 /**
16527 * struct x86_platform_ops - platform specific runtime functions
16528@@ -166,7 +166,7 @@ struct x86_platform_ops {
16529 void (*save_sched_clock_state)(void);
16530 void (*restore_sched_clock_state)(void);
16531 void (*apic_post_init)(void);
16532-};
16533+} __no_const;
16534
16535 struct pci_dev;
16536 struct msi_msg;
16537@@ -180,7 +180,7 @@ struct x86_msi_ops {
16538 void (*teardown_msi_irqs)(struct pci_dev *dev);
16539 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16540 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
16541-};
16542+} __no_const;
16543
16544 struct IO_APIC_route_entry;
16545 struct io_apic_irq_attr;
16546@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
16547 unsigned int destination, int vector,
16548 struct io_apic_irq_attr *attr);
16549 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
16550-};
16551+} __no_const;
16552
16553 extern struct x86_init_ops x86_init;
16554 extern struct x86_cpuinit_ops x86_cpuinit;
16555diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16556index 0415cda..b43d877 100644
16557--- a/arch/x86/include/asm/xsave.h
16558+++ b/arch/x86/include/asm/xsave.h
16559@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16560 return -EFAULT;
16561
16562 __asm__ __volatile__(ASM_STAC "\n"
16563- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16564+ "1:"
16565+ __copyuser_seg
16566+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16567 "2: " ASM_CLAC "\n"
16568 ".section .fixup,\"ax\"\n"
16569 "3: movl $-1,%[err]\n"
16570@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16571 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16572 {
16573 int err;
16574- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16575+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16576 u32 lmask = mask;
16577 u32 hmask = mask >> 32;
16578
16579 __asm__ __volatile__(ASM_STAC "\n"
16580- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16581+ "1:"
16582+ __copyuser_seg
16583+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16584 "2: " ASM_CLAC "\n"
16585 ".section .fixup,\"ax\"\n"
16586 "3: movl $-1,%[err]\n"
16587diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16588index bbae024..e1528f9 100644
16589--- a/arch/x86/include/uapi/asm/e820.h
16590+++ b/arch/x86/include/uapi/asm/e820.h
16591@@ -63,7 +63,7 @@ struct e820map {
16592 #define ISA_START_ADDRESS 0xa0000
16593 #define ISA_END_ADDRESS 0x100000
16594
16595-#define BIOS_BEGIN 0x000a0000
16596+#define BIOS_BEGIN 0x000c0000
16597 #define BIOS_END 0x00100000
16598
16599 #define BIOS_ROM_BASE 0xffe00000
16600diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16601index 7bd3bd3..5dac791 100644
16602--- a/arch/x86/kernel/Makefile
16603+++ b/arch/x86/kernel/Makefile
16604@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16605 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16606 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16607 obj-y += probe_roms.o
16608-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16609+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16610 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16611 obj-y += syscall_$(BITS).o
16612 obj-$(CONFIG_X86_64) += vsyscall_64.o
16613diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16614index 230c8ea..f915130 100644
16615--- a/arch/x86/kernel/acpi/boot.c
16616+++ b/arch/x86/kernel/acpi/boot.c
16617@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16618 * If your system is blacklisted here, but you find that acpi=force
16619 * works for you, please contact linux-acpi@vger.kernel.org
16620 */
16621-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16622+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16623 /*
16624 * Boxes that need ACPI disabled
16625 */
16626@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16627 };
16628
16629 /* second table for DMI checks that should run after early-quirks */
16630-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16631+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16632 /*
16633 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16634 * which includes some code which overrides all temperature
16635diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16636index b44577b..27d8443 100644
16637--- a/arch/x86/kernel/acpi/sleep.c
16638+++ b/arch/x86/kernel/acpi/sleep.c
16639@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16640 #else /* CONFIG_64BIT */
16641 #ifdef CONFIG_SMP
16642 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16643+
16644+ pax_open_kernel();
16645 early_gdt_descr.address =
16646 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16647+ pax_close_kernel();
16648+
16649 initial_gs = per_cpu_offset(smp_processor_id());
16650 #endif
16651 initial_code = (unsigned long)wakeup_long64;
16652diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16653index d1daa66..59fecba 100644
16654--- a/arch/x86/kernel/acpi/wakeup_32.S
16655+++ b/arch/x86/kernel/acpi/wakeup_32.S
16656@@ -29,13 +29,11 @@ wakeup_pmode_return:
16657 # and restore the stack ... but you need gdt for this to work
16658 movl saved_context_esp, %esp
16659
16660- movl %cs:saved_magic, %eax
16661- cmpl $0x12345678, %eax
16662+ cmpl $0x12345678, saved_magic
16663 jne bogus_magic
16664
16665 # jump to place where we left off
16666- movl saved_eip, %eax
16667- jmp *%eax
16668+ jmp *(saved_eip)
16669
16670 bogus_magic:
16671 jmp bogus_magic
16672diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16673index c15cf9a..0e63558 100644
16674--- a/arch/x86/kernel/alternative.c
16675+++ b/arch/x86/kernel/alternative.c
16676@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16677 */
16678 for (a = start; a < end; a++) {
16679 instr = (u8 *)&a->instr_offset + a->instr_offset;
16680+
16681+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16682+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16683+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16684+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16685+#endif
16686+
16687 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16688 BUG_ON(a->replacementlen > a->instrlen);
16689 BUG_ON(a->instrlen > sizeof(insnbuf));
16690@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16691 for (poff = start; poff < end; poff++) {
16692 u8 *ptr = (u8 *)poff + *poff;
16693
16694+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16695+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16696+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16697+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16698+#endif
16699+
16700 if (!*poff || ptr < text || ptr >= text_end)
16701 continue;
16702 /* turn DS segment override prefix into lock prefix */
16703- if (*ptr == 0x3e)
16704+ if (*ktla_ktva(ptr) == 0x3e)
16705 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16706 }
16707 mutex_unlock(&text_mutex);
16708@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16709 for (poff = start; poff < end; poff++) {
16710 u8 *ptr = (u8 *)poff + *poff;
16711
16712+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16713+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16714+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16715+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16716+#endif
16717+
16718 if (!*poff || ptr < text || ptr >= text_end)
16719 continue;
16720 /* turn lock prefix into DS segment override prefix */
16721- if (*ptr == 0xf0)
16722+ if (*ktla_ktva(ptr) == 0xf0)
16723 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16724 }
16725 mutex_unlock(&text_mutex);
16726@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16727
16728 BUG_ON(p->len > MAX_PATCH_LEN);
16729 /* prep the buffer with the original instructions */
16730- memcpy(insnbuf, p->instr, p->len);
16731+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16732 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16733 (unsigned long)p->instr, p->len);
16734
16735@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16736 if (!uniproc_patched || num_possible_cpus() == 1)
16737 free_init_pages("SMP alternatives",
16738 (unsigned long)__smp_locks,
16739- (unsigned long)__smp_locks_end);
16740+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16741 #endif
16742
16743 apply_paravirt(__parainstructions, __parainstructions_end);
16744@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16745 * instructions. And on the local CPU you need to be protected again NMI or MCE
16746 * handlers seeing an inconsistent instruction while you patch.
16747 */
16748-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16749+void *__kprobes text_poke_early(void *addr, const void *opcode,
16750 size_t len)
16751 {
16752 unsigned long flags;
16753 local_irq_save(flags);
16754- memcpy(addr, opcode, len);
16755+
16756+ pax_open_kernel();
16757+ memcpy(ktla_ktva(addr), opcode, len);
16758 sync_core();
16759+ pax_close_kernel();
16760+
16761 local_irq_restore(flags);
16762 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16763 that causes hangs on some VIA CPUs. */
16764@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16765 */
16766 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16767 {
16768- unsigned long flags;
16769- char *vaddr;
16770+ unsigned char *vaddr = ktla_ktva(addr);
16771 struct page *pages[2];
16772- int i;
16773+ size_t i;
16774
16775 if (!core_kernel_text((unsigned long)addr)) {
16776- pages[0] = vmalloc_to_page(addr);
16777- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16778+ pages[0] = vmalloc_to_page(vaddr);
16779+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16780 } else {
16781- pages[0] = virt_to_page(addr);
16782+ pages[0] = virt_to_page(vaddr);
16783 WARN_ON(!PageReserved(pages[0]));
16784- pages[1] = virt_to_page(addr + PAGE_SIZE);
16785+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16786 }
16787 BUG_ON(!pages[0]);
16788- local_irq_save(flags);
16789- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16790- if (pages[1])
16791- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16792- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16793- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16794- clear_fixmap(FIX_TEXT_POKE0);
16795- if (pages[1])
16796- clear_fixmap(FIX_TEXT_POKE1);
16797- local_flush_tlb();
16798- sync_core();
16799- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16800- that causes hangs on some VIA CPUs. */
16801+ text_poke_early(addr, opcode, len);
16802 for (i = 0; i < len; i++)
16803- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16804- local_irq_restore(flags);
16805+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16806 return addr;
16807 }
16808
16809diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16810index 904611b..004dde6 100644
16811--- a/arch/x86/kernel/apic/apic.c
16812+++ b/arch/x86/kernel/apic/apic.c
16813@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16814 /*
16815 * Debug level, exported for io_apic.c
16816 */
16817-unsigned int apic_verbosity;
16818+int apic_verbosity;
16819
16820 int pic_mode;
16821
16822@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16823 apic_write(APIC_ESR, 0);
16824 v1 = apic_read(APIC_ESR);
16825 ack_APIC_irq();
16826- atomic_inc(&irq_err_count);
16827+ atomic_inc_unchecked(&irq_err_count);
16828
16829 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16830 smp_processor_id(), v0 , v1);
16831diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16832index 00c77cf..2dc6a2d 100644
16833--- a/arch/x86/kernel/apic/apic_flat_64.c
16834+++ b/arch/x86/kernel/apic/apic_flat_64.c
16835@@ -157,7 +157,7 @@ static int flat_probe(void)
16836 return 1;
16837 }
16838
16839-static struct apic apic_flat = {
16840+static struct apic apic_flat __read_only = {
16841 .name = "flat",
16842 .probe = flat_probe,
16843 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16844@@ -271,7 +271,7 @@ static int physflat_probe(void)
16845 return 0;
16846 }
16847
16848-static struct apic apic_physflat = {
16849+static struct apic apic_physflat __read_only = {
16850
16851 .name = "physical flat",
16852 .probe = physflat_probe,
16853diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16854index e145f28..2752888 100644
16855--- a/arch/x86/kernel/apic/apic_noop.c
16856+++ b/arch/x86/kernel/apic/apic_noop.c
16857@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16858 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16859 }
16860
16861-struct apic apic_noop = {
16862+struct apic apic_noop __read_only = {
16863 .name = "noop",
16864 .probe = noop_probe,
16865 .acpi_madt_oem_check = NULL,
16866diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16867index d50e364..543bee3 100644
16868--- a/arch/x86/kernel/apic/bigsmp_32.c
16869+++ b/arch/x86/kernel/apic/bigsmp_32.c
16870@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16871 return dmi_bigsmp;
16872 }
16873
16874-static struct apic apic_bigsmp = {
16875+static struct apic apic_bigsmp __read_only = {
16876
16877 .name = "bigsmp",
16878 .probe = probe_bigsmp,
16879diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16880index 0874799..a7a7892 100644
16881--- a/arch/x86/kernel/apic/es7000_32.c
16882+++ b/arch/x86/kernel/apic/es7000_32.c
16883@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16884 return ret && es7000_apic_is_cluster();
16885 }
16886
16887-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16888-static struct apic __refdata apic_es7000_cluster = {
16889+static struct apic apic_es7000_cluster __read_only = {
16890
16891 .name = "es7000",
16892 .probe = probe_es7000,
16893@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16894 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16895 };
16896
16897-static struct apic __refdata apic_es7000 = {
16898+static struct apic apic_es7000 __read_only = {
16899
16900 .name = "es7000",
16901 .probe = probe_es7000,
16902diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16903index 9ed796c..e930fe4 100644
16904--- a/arch/x86/kernel/apic/io_apic.c
16905+++ b/arch/x86/kernel/apic/io_apic.c
16906@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16907 }
16908 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16909
16910-void lock_vector_lock(void)
16911+void lock_vector_lock(void) __acquires(vector_lock)
16912 {
16913 /* Used to the online set of cpus does not change
16914 * during assign_irq_vector.
16915@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
16916 raw_spin_lock(&vector_lock);
16917 }
16918
16919-void unlock_vector_lock(void)
16920+void unlock_vector_lock(void) __releases(vector_lock)
16921 {
16922 raw_spin_unlock(&vector_lock);
16923 }
16924@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
16925 ack_APIC_irq();
16926 }
16927
16928-atomic_t irq_mis_count;
16929+atomic_unchecked_t irq_mis_count;
16930
16931 #ifdef CONFIG_GENERIC_PENDING_IRQ
16932 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16933@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
16934 * at the cpu.
16935 */
16936 if (!(v & (1 << (i & 0x1f)))) {
16937- atomic_inc(&irq_mis_count);
16938+ atomic_inc_unchecked(&irq_mis_count);
16939
16940 eoi_ioapic_irq(irq, cfg);
16941 }
16942diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16943index d661ee9..791fd33 100644
16944--- a/arch/x86/kernel/apic/numaq_32.c
16945+++ b/arch/x86/kernel/apic/numaq_32.c
16946@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16947 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16948 }
16949
16950-/* Use __refdata to keep false positive warning calm. */
16951-static struct apic __refdata apic_numaq = {
16952+static struct apic apic_numaq __read_only = {
16953
16954 .name = "NUMAQ",
16955 .probe = probe_numaq,
16956diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16957index eb35ef9..f184a21 100644
16958--- a/arch/x86/kernel/apic/probe_32.c
16959+++ b/arch/x86/kernel/apic/probe_32.c
16960@@ -72,7 +72,7 @@ static int probe_default(void)
16961 return 1;
16962 }
16963
16964-static struct apic apic_default = {
16965+static struct apic apic_default __read_only = {
16966
16967 .name = "default",
16968 .probe = probe_default,
16969diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16970index 77c95c0..434f8a4 100644
16971--- a/arch/x86/kernel/apic/summit_32.c
16972+++ b/arch/x86/kernel/apic/summit_32.c
16973@@ -486,7 +486,7 @@ void setup_summit(void)
16974 }
16975 #endif
16976
16977-static struct apic apic_summit = {
16978+static struct apic apic_summit __read_only = {
16979
16980 .name = "summit",
16981 .probe = probe_summit,
16982diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16983index c88baa4..757aee1 100644
16984--- a/arch/x86/kernel/apic/x2apic_cluster.c
16985+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16986@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16987 return notifier_from_errno(err);
16988 }
16989
16990-static struct notifier_block __refdata x2apic_cpu_notifier = {
16991+static struct notifier_block x2apic_cpu_notifier = {
16992 .notifier_call = update_clusterinfo,
16993 };
16994
16995@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16996 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16997 }
16998
16999-static struct apic apic_x2apic_cluster = {
17000+static struct apic apic_x2apic_cluster __read_only = {
17001
17002 .name = "cluster x2apic",
17003 .probe = x2apic_cluster_probe,
17004diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
17005index 562a76d..a003c0f 100644
17006--- a/arch/x86/kernel/apic/x2apic_phys.c
17007+++ b/arch/x86/kernel/apic/x2apic_phys.c
17008@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
17009 return apic == &apic_x2apic_phys;
17010 }
17011
17012-static struct apic apic_x2apic_phys = {
17013+static struct apic apic_x2apic_phys __read_only = {
17014
17015 .name = "physical x2apic",
17016 .probe = x2apic_phys_probe,
17017diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17018index 794f6eb..67e1db2 100644
17019--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17020+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17021@@ -342,7 +342,7 @@ static int uv_probe(void)
17022 return apic == &apic_x2apic_uv_x;
17023 }
17024
17025-static struct apic __refdata apic_x2apic_uv_x = {
17026+static struct apic apic_x2apic_uv_x __read_only = {
17027
17028 .name = "UV large system",
17029 .probe = uv_probe,
17030diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17031index 53a4e27..038760a 100644
17032--- a/arch/x86/kernel/apm_32.c
17033+++ b/arch/x86/kernel/apm_32.c
17034@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
17035 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17036 * even though they are called in protected mode.
17037 */
17038-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17039+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17040 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17041
17042 static const char driver_version[] = "1.16ac"; /* no spaces */
17043@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
17044 BUG_ON(cpu != 0);
17045 gdt = get_cpu_gdt_table(cpu);
17046 save_desc_40 = gdt[0x40 / 8];
17047+
17048+ pax_open_kernel();
17049 gdt[0x40 / 8] = bad_bios_desc;
17050+ pax_close_kernel();
17051
17052 apm_irq_save(flags);
17053 APM_DO_SAVE_SEGS;
17054@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
17055 &call->esi);
17056 APM_DO_RESTORE_SEGS;
17057 apm_irq_restore(flags);
17058+
17059+ pax_open_kernel();
17060 gdt[0x40 / 8] = save_desc_40;
17061+ pax_close_kernel();
17062+
17063 put_cpu();
17064
17065 return call->eax & 0xff;
17066@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
17067 BUG_ON(cpu != 0);
17068 gdt = get_cpu_gdt_table(cpu);
17069 save_desc_40 = gdt[0x40 / 8];
17070+
17071+ pax_open_kernel();
17072 gdt[0x40 / 8] = bad_bios_desc;
17073+ pax_close_kernel();
17074
17075 apm_irq_save(flags);
17076 APM_DO_SAVE_SEGS;
17077@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
17078 &call->eax);
17079 APM_DO_RESTORE_SEGS;
17080 apm_irq_restore(flags);
17081+
17082+ pax_open_kernel();
17083 gdt[0x40 / 8] = save_desc_40;
17084+ pax_close_kernel();
17085+
17086 put_cpu();
17087 return error;
17088 }
17089@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
17090 * code to that CPU.
17091 */
17092 gdt = get_cpu_gdt_table(0);
17093+
17094+ pax_open_kernel();
17095 set_desc_base(&gdt[APM_CS >> 3],
17096 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17097 set_desc_base(&gdt[APM_CS_16 >> 3],
17098 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17099 set_desc_base(&gdt[APM_DS >> 3],
17100 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17101+ pax_close_kernel();
17102
17103 proc_create("apm", 0, NULL, &apm_file_ops);
17104
17105diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17106index 2861082..6d4718e 100644
17107--- a/arch/x86/kernel/asm-offsets.c
17108+++ b/arch/x86/kernel/asm-offsets.c
17109@@ -33,6 +33,8 @@ void common(void) {
17110 OFFSET(TI_status, thread_info, status);
17111 OFFSET(TI_addr_limit, thread_info, addr_limit);
17112 OFFSET(TI_preempt_count, thread_info, preempt_count);
17113+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17114+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17115
17116 BLANK();
17117 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17118@@ -53,8 +55,26 @@ void common(void) {
17119 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17120 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17121 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17122+
17123+#ifdef CONFIG_PAX_KERNEXEC
17124+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17125 #endif
17126
17127+#ifdef CONFIG_PAX_MEMORY_UDEREF
17128+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17129+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17130+#ifdef CONFIG_X86_64
17131+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17132+#endif
17133+#endif
17134+
17135+#endif
17136+
17137+ BLANK();
17138+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17139+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17140+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17141+
17142 #ifdef CONFIG_XEN
17143 BLANK();
17144 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17145diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17146index e7c798b..2b2019b 100644
17147--- a/arch/x86/kernel/asm-offsets_64.c
17148+++ b/arch/x86/kernel/asm-offsets_64.c
17149@@ -77,6 +77,7 @@ int main(void)
17150 BLANK();
17151 #undef ENTRY
17152
17153+ DEFINE(TSS_size, sizeof(struct tss_struct));
17154 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17155 BLANK();
17156
17157diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17158index b0684e4..22ccfd7 100644
17159--- a/arch/x86/kernel/cpu/Makefile
17160+++ b/arch/x86/kernel/cpu/Makefile
17161@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17162 CFLAGS_REMOVE_perf_event.o = -pg
17163 endif
17164
17165-# Make sure load_percpu_segment has no stackprotector
17166-nostackp := $(call cc-option, -fno-stack-protector)
17167-CFLAGS_common.o := $(nostackp)
17168-
17169 obj-y := intel_cacheinfo.o scattered.o topology.o
17170 obj-y += proc.o capflags.o powerflags.o common.o
17171 obj-y += rdrand.o
17172diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17173index 5013a48..0782c53 100644
17174--- a/arch/x86/kernel/cpu/amd.c
17175+++ b/arch/x86/kernel/cpu/amd.c
17176@@ -744,7 +744,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17177 unsigned int size)
17178 {
17179 /* AMD errata T13 (order #21922) */
17180- if ((c->x86 == 6)) {
17181+ if (c->x86 == 6) {
17182 /* Duron Rev A0 */
17183 if (c->x86_model == 3 && c->x86_mask == 0)
17184 size = 64;
17185diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17186index 22018f7..bc6f5e3 100644
17187--- a/arch/x86/kernel/cpu/common.c
17188+++ b/arch/x86/kernel/cpu/common.c
17189@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17190
17191 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17192
17193-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17194-#ifdef CONFIG_X86_64
17195- /*
17196- * We need valid kernel segments for data and code in long mode too
17197- * IRET will check the segment types kkeil 2000/10/28
17198- * Also sysret mandates a special GDT layout
17199- *
17200- * TLS descriptors are currently at a different place compared to i386.
17201- * Hopefully nobody expects them at a fixed place (Wine?)
17202- */
17203- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17204- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17205- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17206- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17207- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17208- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17209-#else
17210- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17211- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17212- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17213- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17214- /*
17215- * Segments used for calling PnP BIOS have byte granularity.
17216- * They code segments and data segments have fixed 64k limits,
17217- * the transfer segment sizes are set at run time.
17218- */
17219- /* 32-bit code */
17220- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17221- /* 16-bit code */
17222- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17223- /* 16-bit data */
17224- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17225- /* 16-bit data */
17226- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17227- /* 16-bit data */
17228- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17229- /*
17230- * The APM segments have byte granularity and their bases
17231- * are set at run time. All have 64k limits.
17232- */
17233- /* 32-bit code */
17234- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17235- /* 16-bit code */
17236- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17237- /* data */
17238- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17239-
17240- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17241- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17242- GDT_STACK_CANARY_INIT
17243-#endif
17244-} };
17245-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17246-
17247 static int __init x86_xsave_setup(char *s)
17248 {
17249 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17250@@ -386,7 +332,7 @@ void switch_to_new_gdt(int cpu)
17251 {
17252 struct desc_ptr gdt_descr;
17253
17254- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17255+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17256 gdt_descr.size = GDT_SIZE - 1;
17257 load_gdt(&gdt_descr);
17258 /* Reload the per-cpu base */
17259@@ -882,6 +828,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17260 /* Filter out anything that depends on CPUID levels we don't have */
17261 filter_cpuid_features(c, true);
17262
17263+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17264+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17265+#endif
17266+
17267 /* If the model name is still unset, do table lookup. */
17268 if (!c->x86_model_id[0]) {
17269 const char *p;
17270@@ -1069,10 +1019,12 @@ static __init int setup_disablecpuid(char *arg)
17271 }
17272 __setup("clearcpuid=", setup_disablecpuid);
17273
17274+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17275+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17276+
17277 #ifdef CONFIG_X86_64
17278 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17279-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17280- (unsigned long) nmi_idt_table };
17281+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17282
17283 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17284 irq_stack_union) __aligned(PAGE_SIZE);
17285@@ -1086,7 +1038,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17286 EXPORT_PER_CPU_SYMBOL(current_task);
17287
17288 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17289- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17290+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17291 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17292
17293 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17294@@ -1231,7 +1183,7 @@ void __cpuinit cpu_init(void)
17295 load_ucode_ap();
17296
17297 cpu = stack_smp_processor_id();
17298- t = &per_cpu(init_tss, cpu);
17299+ t = init_tss + cpu;
17300 oist = &per_cpu(orig_ist, cpu);
17301
17302 #ifdef CONFIG_NUMA
17303@@ -1257,7 +1209,7 @@ void __cpuinit cpu_init(void)
17304 switch_to_new_gdt(cpu);
17305 loadsegment(fs, 0);
17306
17307- load_idt((const struct desc_ptr *)&idt_descr);
17308+ load_idt(&idt_descr);
17309
17310 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17311 syscall_init();
17312@@ -1266,7 +1218,6 @@ void __cpuinit cpu_init(void)
17313 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17314 barrier();
17315
17316- x86_configure_nx();
17317 enable_x2apic();
17318
17319 /*
17320@@ -1318,7 +1269,7 @@ void __cpuinit cpu_init(void)
17321 {
17322 int cpu = smp_processor_id();
17323 struct task_struct *curr = current;
17324- struct tss_struct *t = &per_cpu(init_tss, cpu);
17325+ struct tss_struct *t = init_tss + cpu;
17326 struct thread_struct *thread = &curr->thread;
17327
17328 show_ucode_info_early();
17329diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17330index 7c6f7d5..8cac382 100644
17331--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17332+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17333@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17334 };
17335
17336 #ifdef CONFIG_AMD_NB
17337+static struct attribute *default_attrs_amd_nb[] = {
17338+ &type.attr,
17339+ &level.attr,
17340+ &coherency_line_size.attr,
17341+ &physical_line_partition.attr,
17342+ &ways_of_associativity.attr,
17343+ &number_of_sets.attr,
17344+ &size.attr,
17345+ &shared_cpu_map.attr,
17346+ &shared_cpu_list.attr,
17347+ NULL,
17348+ NULL,
17349+ NULL,
17350+ NULL
17351+};
17352+
17353 static struct attribute ** __cpuinit amd_l3_attrs(void)
17354 {
17355 static struct attribute **attrs;
17356@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17357
17358 n = ARRAY_SIZE(default_attrs);
17359
17360- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17361- n += 2;
17362-
17363- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17364- n += 1;
17365-
17366- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17367- if (attrs == NULL)
17368- return attrs = default_attrs;
17369-
17370- for (n = 0; default_attrs[n]; n++)
17371- attrs[n] = default_attrs[n];
17372+ attrs = default_attrs_amd_nb;
17373
17374 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17375 attrs[n++] = &cache_disable_0.attr;
17376@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17377 .default_attrs = default_attrs,
17378 };
17379
17380+#ifdef CONFIG_AMD_NB
17381+static struct kobj_type ktype_cache_amd_nb = {
17382+ .sysfs_ops = &sysfs_ops,
17383+ .default_attrs = default_attrs_amd_nb,
17384+};
17385+#endif
17386+
17387 static struct kobj_type ktype_percpu_entry = {
17388 .sysfs_ops = &sysfs_ops,
17389 };
17390@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17391 return retval;
17392 }
17393
17394+#ifdef CONFIG_AMD_NB
17395+ amd_l3_attrs();
17396+#endif
17397+
17398 for (i = 0; i < num_cache_leaves; i++) {
17399+ struct kobj_type *ktype;
17400+
17401 this_object = INDEX_KOBJECT_PTR(cpu, i);
17402 this_object->cpu = cpu;
17403 this_object->index = i;
17404
17405 this_leaf = CPUID4_INFO_IDX(cpu, i);
17406
17407- ktype_cache.default_attrs = default_attrs;
17408+ ktype = &ktype_cache;
17409 #ifdef CONFIG_AMD_NB
17410 if (this_leaf->base.nb)
17411- ktype_cache.default_attrs = amd_l3_attrs();
17412+ ktype = &ktype_cache_amd_nb;
17413 #endif
17414 retval = kobject_init_and_add(&(this_object->kobj),
17415- &ktype_cache,
17416+ ktype,
17417 per_cpu(ici_cache_kobject, cpu),
17418 "index%1lu", i);
17419 if (unlikely(retval)) {
17420@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17421 return NOTIFY_OK;
17422 }
17423
17424-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17425+static struct notifier_block cacheinfo_cpu_notifier = {
17426 .notifier_call = cacheinfo_cpu_callback,
17427 };
17428
17429diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17430index 9239504..b2471ce 100644
17431--- a/arch/x86/kernel/cpu/mcheck/mce.c
17432+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17433@@ -45,6 +45,7 @@
17434 #include <asm/processor.h>
17435 #include <asm/mce.h>
17436 #include <asm/msr.h>
17437+#include <asm/local.h>
17438
17439 #include "mce-internal.h"
17440
17441@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17442 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17443 m->cs, m->ip);
17444
17445- if (m->cs == __KERNEL_CS)
17446+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17447 print_symbol("{%s}", m->ip);
17448 pr_cont("\n");
17449 }
17450@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17451
17452 #define PANIC_TIMEOUT 5 /* 5 seconds */
17453
17454-static atomic_t mce_paniced;
17455+static atomic_unchecked_t mce_paniced;
17456
17457 static int fake_panic;
17458-static atomic_t mce_fake_paniced;
17459+static atomic_unchecked_t mce_fake_paniced;
17460
17461 /* Panic in progress. Enable interrupts and wait for final IPI */
17462 static void wait_for_panic(void)
17463@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17464 /*
17465 * Make sure only one CPU runs in machine check panic
17466 */
17467- if (atomic_inc_return(&mce_paniced) > 1)
17468+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17469 wait_for_panic();
17470 barrier();
17471
17472@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17473 console_verbose();
17474 } else {
17475 /* Don't log too much for fake panic */
17476- if (atomic_inc_return(&mce_fake_paniced) > 1)
17477+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17478 return;
17479 }
17480 /* First print corrected ones that are still unlogged */
17481@@ -353,7 +354,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17482 if (!fake_panic) {
17483 if (panic_timeout == 0)
17484 panic_timeout = mca_cfg.panic_timeout;
17485- panic(msg);
17486+ panic("%s", msg);
17487 } else
17488 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
17489 }
17490@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
17491 * might have been modified by someone else.
17492 */
17493 rmb();
17494- if (atomic_read(&mce_paniced))
17495+ if (atomic_read_unchecked(&mce_paniced))
17496 wait_for_panic();
17497 if (!mca_cfg.monarch_timeout)
17498 goto out;
17499@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17500 }
17501
17502 /* Call the installed machine check handler for this CPU setup. */
17503-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17504+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17505 unexpected_machine_check;
17506
17507 /*
17508@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17509 return;
17510 }
17511
17512+ pax_open_kernel();
17513 machine_check_vector = do_machine_check;
17514+ pax_close_kernel();
17515
17516 __mcheck_cpu_init_generic();
17517 __mcheck_cpu_init_vendor(c);
17518@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17519 */
17520
17521 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17522-static int mce_chrdev_open_count; /* #times opened */
17523+static local_t mce_chrdev_open_count; /* #times opened */
17524 static int mce_chrdev_open_exclu; /* already open exclusive? */
17525
17526 static int mce_chrdev_open(struct inode *inode, struct file *file)
17527@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17528 spin_lock(&mce_chrdev_state_lock);
17529
17530 if (mce_chrdev_open_exclu ||
17531- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17532+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17533 spin_unlock(&mce_chrdev_state_lock);
17534
17535 return -EBUSY;
17536@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17537
17538 if (file->f_flags & O_EXCL)
17539 mce_chrdev_open_exclu = 1;
17540- mce_chrdev_open_count++;
17541+ local_inc(&mce_chrdev_open_count);
17542
17543 spin_unlock(&mce_chrdev_state_lock);
17544
17545@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17546 {
17547 spin_lock(&mce_chrdev_state_lock);
17548
17549- mce_chrdev_open_count--;
17550+ local_dec(&mce_chrdev_open_count);
17551 mce_chrdev_open_exclu = 0;
17552
17553 spin_unlock(&mce_chrdev_state_lock);
17554@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17555 return NOTIFY_OK;
17556 }
17557
17558-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17559+static struct notifier_block mce_cpu_notifier = {
17560 .notifier_call = mce_cpu_callback,
17561 };
17562
17563@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
17564
17565 for (i = 0; i < mca_cfg.banks; i++) {
17566 struct mce_bank *b = &mce_banks[i];
17567- struct device_attribute *a = &b->attr;
17568+ device_attribute_no_const *a = &b->attr;
17569
17570 sysfs_attr_init(&a->attr);
17571 a->attr.name = b->attrname;
17572@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
17573 static void mce_reset(void)
17574 {
17575 cpu_missing = 0;
17576- atomic_set(&mce_fake_paniced, 0);
17577+ atomic_set_unchecked(&mce_fake_paniced, 0);
17578 atomic_set(&mce_executing, 0);
17579 atomic_set(&mce_callin, 0);
17580 atomic_set(&global_nwo, 0);
17581diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17582index 1c044b1..37a2a43 100644
17583--- a/arch/x86/kernel/cpu/mcheck/p5.c
17584+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17585@@ -11,6 +11,7 @@
17586 #include <asm/processor.h>
17587 #include <asm/mce.h>
17588 #include <asm/msr.h>
17589+#include <asm/pgtable.h>
17590
17591 /* By default disabled */
17592 int mce_p5_enabled __read_mostly;
17593@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17594 if (!cpu_has(c, X86_FEATURE_MCE))
17595 return;
17596
17597+ pax_open_kernel();
17598 machine_check_vector = pentium_machine_check;
17599+ pax_close_kernel();
17600 /* Make sure the vector pointer is visible before we enable MCEs: */
17601 wmb();
17602
17603diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17604index 47a1870..8c019a7 100644
17605--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17606+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17607@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17608 return notifier_from_errno(err);
17609 }
17610
17611-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17612+static struct notifier_block thermal_throttle_cpu_notifier =
17613 {
17614 .notifier_call = thermal_throttle_cpu_callback,
17615 };
17616diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17617index e9a701a..35317d6 100644
17618--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17619+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17620@@ -10,6 +10,7 @@
17621 #include <asm/processor.h>
17622 #include <asm/mce.h>
17623 #include <asm/msr.h>
17624+#include <asm/pgtable.h>
17625
17626 /* Machine check handler for WinChip C6: */
17627 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17628@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17629 {
17630 u32 lo, hi;
17631
17632+ pax_open_kernel();
17633 machine_check_vector = winchip_machine_check;
17634+ pax_close_kernel();
17635 /* Make sure the vector pointer is visible before we enable MCEs: */
17636 wmb();
17637
17638diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17639index 726bf96..81f0526 100644
17640--- a/arch/x86/kernel/cpu/mtrr/main.c
17641+++ b/arch/x86/kernel/cpu/mtrr/main.c
17642@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17643 u64 size_or_mask, size_and_mask;
17644 static bool mtrr_aps_delayed_init;
17645
17646-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17647+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17648
17649 const struct mtrr_ops *mtrr_if;
17650
17651diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17652index df5e41f..816c719 100644
17653--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17654+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17655@@ -25,7 +25,7 @@ struct mtrr_ops {
17656 int (*validate_add_page)(unsigned long base, unsigned long size,
17657 unsigned int type);
17658 int (*have_wrcomb)(void);
17659-};
17660+} __do_const;
17661
17662 extern int generic_get_free_region(unsigned long base, unsigned long size,
17663 int replace_reg);
17664diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17665index 1025f3c..824f677 100644
17666--- a/arch/x86/kernel/cpu/perf_event.c
17667+++ b/arch/x86/kernel/cpu/perf_event.c
17668@@ -1311,7 +1311,7 @@ static void __init pmu_check_apic(void)
17669 pr_info("no hardware sampling interrupt available.\n");
17670 }
17671
17672-static struct attribute_group x86_pmu_format_group = {
17673+static attribute_group_no_const x86_pmu_format_group = {
17674 .name = "format",
17675 .attrs = NULL,
17676 };
17677@@ -1410,7 +1410,7 @@ static struct attribute *events_attr[] = {
17678 NULL,
17679 };
17680
17681-static struct attribute_group x86_pmu_events_group = {
17682+static attribute_group_no_const x86_pmu_events_group = {
17683 .name = "events",
17684 .attrs = events_attr,
17685 };
17686@@ -1920,7 +1920,7 @@ static unsigned long get_segment_base(unsigned int segment)
17687 if (idx > GDT_ENTRIES)
17688 return 0;
17689
17690- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17691+ desc = get_cpu_gdt_table(smp_processor_id());
17692 }
17693
17694 return get_desc_base(desc + idx);
17695@@ -2010,7 +2010,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17696 break;
17697
17698 perf_callchain_store(entry, frame.return_address);
17699- fp = frame.next_frame;
17700+ fp = (const void __force_user *)frame.next_frame;
17701 }
17702 }
17703
17704diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17705index a9e2207..d70c83a 100644
17706--- a/arch/x86/kernel/cpu/perf_event_intel.c
17707+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17708@@ -2022,10 +2022,10 @@ __init int intel_pmu_init(void)
17709 * v2 and above have a perf capabilities MSR
17710 */
17711 if (version > 1) {
17712- u64 capabilities;
17713+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17714
17715- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17716- x86_pmu.intel_cap.capabilities = capabilities;
17717+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17718+ x86_pmu.intel_cap.capabilities = capabilities;
17719 }
17720
17721 intel_ds_init();
17722diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17723index 52441a2..f94fae8 100644
17724--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17725+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17726@@ -3093,7 +3093,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17727 static int __init uncore_type_init(struct intel_uncore_type *type)
17728 {
17729 struct intel_uncore_pmu *pmus;
17730- struct attribute_group *attr_group;
17731+ attribute_group_no_const *attr_group;
17732 struct attribute **attrs;
17733 int i, j;
17734
17735@@ -3518,7 +3518,7 @@ static int
17736 return NOTIFY_OK;
17737 }
17738
17739-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17740+static struct notifier_block uncore_cpu_nb = {
17741 .notifier_call = uncore_cpu_notifier,
17742 /*
17743 * to migrate uncore events, our notifier should be executed
17744diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17745index f952891..4722ad4 100644
17746--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17747+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17748@@ -488,7 +488,7 @@ struct intel_uncore_box {
17749 struct uncore_event_desc {
17750 struct kobj_attribute attr;
17751 const char *config;
17752-};
17753+} __do_const;
17754
17755 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17756 { \
17757diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17758index 1e4dbcf..b9a34c2 100644
17759--- a/arch/x86/kernel/cpuid.c
17760+++ b/arch/x86/kernel/cpuid.c
17761@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17762 return notifier_from_errno(err);
17763 }
17764
17765-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17766+static struct notifier_block cpuid_class_cpu_notifier =
17767 {
17768 .notifier_call = cpuid_class_cpu_callback,
17769 };
17770diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17771index 74467fe..18793d5 100644
17772--- a/arch/x86/kernel/crash.c
17773+++ b/arch/x86/kernel/crash.c
17774@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17775 {
17776 #ifdef CONFIG_X86_32
17777 struct pt_regs fixed_regs;
17778-#endif
17779
17780-#ifdef CONFIG_X86_32
17781- if (!user_mode_vm(regs)) {
17782+ if (!user_mode(regs)) {
17783 crash_fixup_ss_esp(&fixed_regs, regs);
17784 regs = &fixed_regs;
17785 }
17786diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
17787index afa64ad..dce67dd 100644
17788--- a/arch/x86/kernel/crash_dump_64.c
17789+++ b/arch/x86/kernel/crash_dump_64.c
17790@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
17791 return -ENOMEM;
17792
17793 if (userbuf) {
17794- if (copy_to_user(buf, vaddr + offset, csize)) {
17795+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
17796 iounmap(vaddr);
17797 return -EFAULT;
17798 }
17799diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17800index 155a13f..1672b9b 100644
17801--- a/arch/x86/kernel/doublefault_32.c
17802+++ b/arch/x86/kernel/doublefault_32.c
17803@@ -11,7 +11,7 @@
17804
17805 #define DOUBLEFAULT_STACKSIZE (1024)
17806 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17807-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17808+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17809
17810 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17811
17812@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17813 unsigned long gdt, tss;
17814
17815 native_store_gdt(&gdt_desc);
17816- gdt = gdt_desc.address;
17817+ gdt = (unsigned long)gdt_desc.address;
17818
17819 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17820
17821@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17822 /* 0x2 bit is always set */
17823 .flags = X86_EFLAGS_SF | 0x2,
17824 .sp = STACK_START,
17825- .es = __USER_DS,
17826+ .es = __KERNEL_DS,
17827 .cs = __KERNEL_CS,
17828 .ss = __KERNEL_DS,
17829- .ds = __USER_DS,
17830+ .ds = __KERNEL_DS,
17831 .fs = __KERNEL_PERCPU,
17832
17833 .__cr3 = __pa_nodebug(swapper_pg_dir),
17834diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17835index deb6421..622e0ed 100644
17836--- a/arch/x86/kernel/dumpstack.c
17837+++ b/arch/x86/kernel/dumpstack.c
17838@@ -2,6 +2,9 @@
17839 * Copyright (C) 1991, 1992 Linus Torvalds
17840 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17841 */
17842+#ifdef CONFIG_GRKERNSEC_HIDESYM
17843+#define __INCLUDED_BY_HIDESYM 1
17844+#endif
17845 #include <linux/kallsyms.h>
17846 #include <linux/kprobes.h>
17847 #include <linux/uaccess.h>
17848@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17849 static void
17850 print_ftrace_graph_addr(unsigned long addr, void *data,
17851 const struct stacktrace_ops *ops,
17852- struct thread_info *tinfo, int *graph)
17853+ struct task_struct *task, int *graph)
17854 {
17855- struct task_struct *task;
17856 unsigned long ret_addr;
17857 int index;
17858
17859 if (addr != (unsigned long)return_to_handler)
17860 return;
17861
17862- task = tinfo->task;
17863 index = task->curr_ret_stack;
17864
17865 if (!task->ret_stack || index < *graph)
17866@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17867 static inline void
17868 print_ftrace_graph_addr(unsigned long addr, void *data,
17869 const struct stacktrace_ops *ops,
17870- struct thread_info *tinfo, int *graph)
17871+ struct task_struct *task, int *graph)
17872 { }
17873 #endif
17874
17875@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17876 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17877 */
17878
17879-static inline int valid_stack_ptr(struct thread_info *tinfo,
17880- void *p, unsigned int size, void *end)
17881+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17882 {
17883- void *t = tinfo;
17884 if (end) {
17885 if (p < end && p >= (end-THREAD_SIZE))
17886 return 1;
17887@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17888 }
17889
17890 unsigned long
17891-print_context_stack(struct thread_info *tinfo,
17892+print_context_stack(struct task_struct *task, void *stack_start,
17893 unsigned long *stack, unsigned long bp,
17894 const struct stacktrace_ops *ops, void *data,
17895 unsigned long *end, int *graph)
17896 {
17897 struct stack_frame *frame = (struct stack_frame *)bp;
17898
17899- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17900+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17901 unsigned long addr;
17902
17903 addr = *stack;
17904@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17905 } else {
17906 ops->address(data, addr, 0);
17907 }
17908- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17909+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17910 }
17911 stack++;
17912 }
17913@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17914 EXPORT_SYMBOL_GPL(print_context_stack);
17915
17916 unsigned long
17917-print_context_stack_bp(struct thread_info *tinfo,
17918+print_context_stack_bp(struct task_struct *task, void *stack_start,
17919 unsigned long *stack, unsigned long bp,
17920 const struct stacktrace_ops *ops, void *data,
17921 unsigned long *end, int *graph)
17922@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17923 struct stack_frame *frame = (struct stack_frame *)bp;
17924 unsigned long *ret_addr = &frame->return_address;
17925
17926- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17927+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17928 unsigned long addr = *ret_addr;
17929
17930 if (!__kernel_text_address(addr))
17931@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17932 ops->address(data, addr, 1);
17933 frame = frame->next_frame;
17934 ret_addr = &frame->return_address;
17935- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17936+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17937 }
17938
17939 return (unsigned long)frame;
17940@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
17941 }
17942 EXPORT_SYMBOL_GPL(oops_begin);
17943
17944+extern void gr_handle_kernel_exploit(void);
17945+
17946 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17947 {
17948 if (regs && kexec_should_crash(current))
17949@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17950 panic("Fatal exception in interrupt");
17951 if (panic_on_oops)
17952 panic("Fatal exception");
17953- do_exit(signr);
17954+
17955+ gr_handle_kernel_exploit();
17956+
17957+ do_group_exit(signr);
17958 }
17959
17960 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17961@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17962 print_modules();
17963 show_regs(regs);
17964 #ifdef CONFIG_X86_32
17965- if (user_mode_vm(regs)) {
17966+ if (user_mode(regs)) {
17967 sp = regs->sp;
17968 ss = regs->ss & 0xffff;
17969 } else {
17970@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17971 unsigned long flags = oops_begin();
17972 int sig = SIGSEGV;
17973
17974- if (!user_mode_vm(regs))
17975+ if (!user_mode(regs))
17976 report_bug(regs->ip, regs);
17977
17978 if (__die(str, regs, err))
17979diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17980index f2a1770..540657f 100644
17981--- a/arch/x86/kernel/dumpstack_32.c
17982+++ b/arch/x86/kernel/dumpstack_32.c
17983@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17984 bp = stack_frame(task, regs);
17985
17986 for (;;) {
17987- struct thread_info *context;
17988+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17989
17990- context = (struct thread_info *)
17991- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17992- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17993+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17994
17995- stack = (unsigned long *)context->previous_esp;
17996- if (!stack)
17997+ if (stack_start == task_stack_page(task))
17998 break;
17999+ stack = *(unsigned long **)stack_start;
18000 if (ops->stack(data, "IRQ") < 0)
18001 break;
18002 touch_nmi_watchdog();
18003@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
18004 int i;
18005
18006 show_regs_print_info(KERN_EMERG);
18007- __show_regs(regs, !user_mode_vm(regs));
18008+ __show_regs(regs, !user_mode(regs));
18009
18010 /*
18011 * When in-kernel, we also print out the stack and code at the
18012 * time of the fault..
18013 */
18014- if (!user_mode_vm(regs)) {
18015+ if (!user_mode(regs)) {
18016 unsigned int code_prologue = code_bytes * 43 / 64;
18017 unsigned int code_len = code_bytes;
18018 unsigned char c;
18019 u8 *ip;
18020+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18021
18022 pr_emerg("Stack:\n");
18023 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18024
18025 pr_emerg("Code:");
18026
18027- ip = (u8 *)regs->ip - code_prologue;
18028+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18029 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18030 /* try starting at IP */
18031- ip = (u8 *)regs->ip;
18032+ ip = (u8 *)regs->ip + cs_base;
18033 code_len = code_len - code_prologue + 1;
18034 }
18035 for (i = 0; i < code_len; i++, ip++) {
18036@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
18037 pr_cont(" Bad EIP value.");
18038 break;
18039 }
18040- if (ip == (u8 *)regs->ip)
18041+ if (ip == (u8 *)regs->ip + cs_base)
18042 pr_cont(" <%02x>", c);
18043 else
18044 pr_cont(" %02x", c);
18045@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
18046 {
18047 unsigned short ud2;
18048
18049+ ip = ktla_ktva(ip);
18050 if (ip < PAGE_OFFSET)
18051 return 0;
18052 if (probe_kernel_address((unsigned short *)ip, ud2))
18053@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
18054
18055 return ud2 == 0x0b0f;
18056 }
18057+
18058+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18059+void pax_check_alloca(unsigned long size)
18060+{
18061+ unsigned long sp = (unsigned long)&sp, stack_left;
18062+
18063+ /* all kernel stacks are of the same size */
18064+ stack_left = sp & (THREAD_SIZE - 1);
18065+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18066+}
18067+EXPORT_SYMBOL(pax_check_alloca);
18068+#endif
18069diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18070index addb207..99635fa 100644
18071--- a/arch/x86/kernel/dumpstack_64.c
18072+++ b/arch/x86/kernel/dumpstack_64.c
18073@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18074 unsigned long *irq_stack_end =
18075 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18076 unsigned used = 0;
18077- struct thread_info *tinfo;
18078 int graph = 0;
18079 unsigned long dummy;
18080+ void *stack_start;
18081
18082 if (!task)
18083 task = current;
18084@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18085 * current stack address. If the stacks consist of nested
18086 * exceptions
18087 */
18088- tinfo = task_thread_info(task);
18089 for (;;) {
18090 char *id;
18091 unsigned long *estack_end;
18092+
18093 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18094 &used, &id);
18095
18096@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18097 if (ops->stack(data, id) < 0)
18098 break;
18099
18100- bp = ops->walk_stack(tinfo, stack, bp, ops,
18101+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18102 data, estack_end, &graph);
18103 ops->stack(data, "<EOE>");
18104 /*
18105@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18106 * second-to-last pointer (index -2 to end) in the
18107 * exception stack:
18108 */
18109+ if ((u16)estack_end[-1] != __KERNEL_DS)
18110+ goto out;
18111 stack = (unsigned long *) estack_end[-2];
18112 continue;
18113 }
18114@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18115 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18116 if (ops->stack(data, "IRQ") < 0)
18117 break;
18118- bp = ops->walk_stack(tinfo, stack, bp,
18119+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18120 ops, data, irq_stack_end, &graph);
18121 /*
18122 * We link to the next stack (which would be
18123@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18124 /*
18125 * This handles the process stack:
18126 */
18127- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18128+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18129+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18130+out:
18131 put_cpu();
18132 }
18133 EXPORT_SYMBOL(dump_trace);
18134@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
18135
18136 return ud2 == 0x0b0f;
18137 }
18138+
18139+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18140+void pax_check_alloca(unsigned long size)
18141+{
18142+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18143+ unsigned cpu, used;
18144+ char *id;
18145+
18146+ /* check the process stack first */
18147+ stack_start = (unsigned long)task_stack_page(current);
18148+ stack_end = stack_start + THREAD_SIZE;
18149+ if (likely(stack_start <= sp && sp < stack_end)) {
18150+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18151+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18152+ return;
18153+ }
18154+
18155+ cpu = get_cpu();
18156+
18157+ /* check the irq stacks */
18158+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18159+ stack_start = stack_end - IRQ_STACK_SIZE;
18160+ if (stack_start <= sp && sp < stack_end) {
18161+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18162+ put_cpu();
18163+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18164+ return;
18165+ }
18166+
18167+ /* check the exception stacks */
18168+ used = 0;
18169+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18170+ stack_start = stack_end - EXCEPTION_STKSZ;
18171+ if (stack_end && stack_start <= sp && sp < stack_end) {
18172+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18173+ put_cpu();
18174+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18175+ return;
18176+ }
18177+
18178+ put_cpu();
18179+
18180+ /* unknown stack */
18181+ BUG();
18182+}
18183+EXPORT_SYMBOL(pax_check_alloca);
18184+#endif
18185diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
18186index d32abea..74daf4f 100644
18187--- a/arch/x86/kernel/e820.c
18188+++ b/arch/x86/kernel/e820.c
18189@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
18190
18191 static void early_panic(char *msg)
18192 {
18193- early_printk(msg);
18194- panic(msg);
18195+ early_printk("%s", msg);
18196+ panic("%s", msg);
18197 }
18198
18199 static int userdef __initdata;
18200diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18201index d15f575..d692043 100644
18202--- a/arch/x86/kernel/early_printk.c
18203+++ b/arch/x86/kernel/early_printk.c
18204@@ -7,6 +7,7 @@
18205 #include <linux/pci_regs.h>
18206 #include <linux/pci_ids.h>
18207 #include <linux/errno.h>
18208+#include <linux/sched.h>
18209 #include <asm/io.h>
18210 #include <asm/processor.h>
18211 #include <asm/fcntl.h>
18212diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18213index 8f3e2de..caecc4e 100644
18214--- a/arch/x86/kernel/entry_32.S
18215+++ b/arch/x86/kernel/entry_32.S
18216@@ -177,13 +177,153 @@
18217 /*CFI_REL_OFFSET gs, PT_GS*/
18218 .endm
18219 .macro SET_KERNEL_GS reg
18220+
18221+#ifdef CONFIG_CC_STACKPROTECTOR
18222 movl $(__KERNEL_STACK_CANARY), \reg
18223+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18224+ movl $(__USER_DS), \reg
18225+#else
18226+ xorl \reg, \reg
18227+#endif
18228+
18229 movl \reg, %gs
18230 .endm
18231
18232 #endif /* CONFIG_X86_32_LAZY_GS */
18233
18234-.macro SAVE_ALL
18235+.macro pax_enter_kernel
18236+#ifdef CONFIG_PAX_KERNEXEC
18237+ call pax_enter_kernel
18238+#endif
18239+.endm
18240+
18241+.macro pax_exit_kernel
18242+#ifdef CONFIG_PAX_KERNEXEC
18243+ call pax_exit_kernel
18244+#endif
18245+.endm
18246+
18247+#ifdef CONFIG_PAX_KERNEXEC
18248+ENTRY(pax_enter_kernel)
18249+#ifdef CONFIG_PARAVIRT
18250+ pushl %eax
18251+ pushl %ecx
18252+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18253+ mov %eax, %esi
18254+#else
18255+ mov %cr0, %esi
18256+#endif
18257+ bts $16, %esi
18258+ jnc 1f
18259+ mov %cs, %esi
18260+ cmp $__KERNEL_CS, %esi
18261+ jz 3f
18262+ ljmp $__KERNEL_CS, $3f
18263+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18264+2:
18265+#ifdef CONFIG_PARAVIRT
18266+ mov %esi, %eax
18267+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18268+#else
18269+ mov %esi, %cr0
18270+#endif
18271+3:
18272+#ifdef CONFIG_PARAVIRT
18273+ popl %ecx
18274+ popl %eax
18275+#endif
18276+ ret
18277+ENDPROC(pax_enter_kernel)
18278+
18279+ENTRY(pax_exit_kernel)
18280+#ifdef CONFIG_PARAVIRT
18281+ pushl %eax
18282+ pushl %ecx
18283+#endif
18284+ mov %cs, %esi
18285+ cmp $__KERNEXEC_KERNEL_CS, %esi
18286+ jnz 2f
18287+#ifdef CONFIG_PARAVIRT
18288+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18289+ mov %eax, %esi
18290+#else
18291+ mov %cr0, %esi
18292+#endif
18293+ btr $16, %esi
18294+ ljmp $__KERNEL_CS, $1f
18295+1:
18296+#ifdef CONFIG_PARAVIRT
18297+ mov %esi, %eax
18298+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18299+#else
18300+ mov %esi, %cr0
18301+#endif
18302+2:
18303+#ifdef CONFIG_PARAVIRT
18304+ popl %ecx
18305+ popl %eax
18306+#endif
18307+ ret
18308+ENDPROC(pax_exit_kernel)
18309+#endif
18310+
18311+ .macro pax_erase_kstack
18312+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18313+ call pax_erase_kstack
18314+#endif
18315+ .endm
18316+
18317+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18318+/*
18319+ * ebp: thread_info
18320+ */
18321+ENTRY(pax_erase_kstack)
18322+ pushl %edi
18323+ pushl %ecx
18324+ pushl %eax
18325+
18326+ mov TI_lowest_stack(%ebp), %edi
18327+ mov $-0xBEEF, %eax
18328+ std
18329+
18330+1: mov %edi, %ecx
18331+ and $THREAD_SIZE_asm - 1, %ecx
18332+ shr $2, %ecx
18333+ repne scasl
18334+ jecxz 2f
18335+
18336+ cmp $2*16, %ecx
18337+ jc 2f
18338+
18339+ mov $2*16, %ecx
18340+ repe scasl
18341+ jecxz 2f
18342+ jne 1b
18343+
18344+2: cld
18345+ mov %esp, %ecx
18346+ sub %edi, %ecx
18347+
18348+ cmp $THREAD_SIZE_asm, %ecx
18349+ jb 3f
18350+ ud2
18351+3:
18352+
18353+ shr $2, %ecx
18354+ rep stosl
18355+
18356+ mov TI_task_thread_sp0(%ebp), %edi
18357+ sub $128, %edi
18358+ mov %edi, TI_lowest_stack(%ebp)
18359+
18360+ popl %eax
18361+ popl %ecx
18362+ popl %edi
18363+ ret
18364+ENDPROC(pax_erase_kstack)
18365+#endif
18366+
18367+.macro __SAVE_ALL _DS
18368 cld
18369 PUSH_GS
18370 pushl_cfi %fs
18371@@ -206,7 +346,7 @@
18372 CFI_REL_OFFSET ecx, 0
18373 pushl_cfi %ebx
18374 CFI_REL_OFFSET ebx, 0
18375- movl $(__USER_DS), %edx
18376+ movl $\_DS, %edx
18377 movl %edx, %ds
18378 movl %edx, %es
18379 movl $(__KERNEL_PERCPU), %edx
18380@@ -214,6 +354,15 @@
18381 SET_KERNEL_GS %edx
18382 .endm
18383
18384+.macro SAVE_ALL
18385+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18386+ __SAVE_ALL __KERNEL_DS
18387+ pax_enter_kernel
18388+#else
18389+ __SAVE_ALL __USER_DS
18390+#endif
18391+.endm
18392+
18393 .macro RESTORE_INT_REGS
18394 popl_cfi %ebx
18395 CFI_RESTORE ebx
18396@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18397 popfl_cfi
18398 jmp syscall_exit
18399 CFI_ENDPROC
18400-END(ret_from_fork)
18401+ENDPROC(ret_from_fork)
18402
18403 ENTRY(ret_from_kernel_thread)
18404 CFI_STARTPROC
18405@@ -344,7 +493,15 @@ ret_from_intr:
18406 andl $SEGMENT_RPL_MASK, %eax
18407 #endif
18408 cmpl $USER_RPL, %eax
18409+
18410+#ifdef CONFIG_PAX_KERNEXEC
18411+ jae resume_userspace
18412+
18413+ pax_exit_kernel
18414+ jmp resume_kernel
18415+#else
18416 jb resume_kernel # not returning to v8086 or userspace
18417+#endif
18418
18419 ENTRY(resume_userspace)
18420 LOCKDEP_SYS_EXIT
18421@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18422 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18423 # int/exception return?
18424 jne work_pending
18425- jmp restore_all
18426-END(ret_from_exception)
18427+ jmp restore_all_pax
18428+ENDPROC(ret_from_exception)
18429
18430 #ifdef CONFIG_PREEMPT
18431 ENTRY(resume_kernel)
18432@@ -372,7 +529,7 @@ need_resched:
18433 jz restore_all
18434 call preempt_schedule_irq
18435 jmp need_resched
18436-END(resume_kernel)
18437+ENDPROC(resume_kernel)
18438 #endif
18439 CFI_ENDPROC
18440 /*
18441@@ -406,30 +563,45 @@ sysenter_past_esp:
18442 /*CFI_REL_OFFSET cs, 0*/
18443 /*
18444 * Push current_thread_info()->sysenter_return to the stack.
18445- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18446- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18447 */
18448- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18449+ pushl_cfi $0
18450 CFI_REL_OFFSET eip, 0
18451
18452 pushl_cfi %eax
18453 SAVE_ALL
18454+ GET_THREAD_INFO(%ebp)
18455+ movl TI_sysenter_return(%ebp),%ebp
18456+ movl %ebp,PT_EIP(%esp)
18457 ENABLE_INTERRUPTS(CLBR_NONE)
18458
18459 /*
18460 * Load the potential sixth argument from user stack.
18461 * Careful about security.
18462 */
18463+ movl PT_OLDESP(%esp),%ebp
18464+
18465+#ifdef CONFIG_PAX_MEMORY_UDEREF
18466+ mov PT_OLDSS(%esp),%ds
18467+1: movl %ds:(%ebp),%ebp
18468+ push %ss
18469+ pop %ds
18470+#else
18471 cmpl $__PAGE_OFFSET-3,%ebp
18472 jae syscall_fault
18473 ASM_STAC
18474 1: movl (%ebp),%ebp
18475 ASM_CLAC
18476+#endif
18477+
18478 movl %ebp,PT_EBP(%esp)
18479 _ASM_EXTABLE(1b,syscall_fault)
18480
18481 GET_THREAD_INFO(%ebp)
18482
18483+#ifdef CONFIG_PAX_RANDKSTACK
18484+ pax_erase_kstack
18485+#endif
18486+
18487 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18488 jnz sysenter_audit
18489 sysenter_do_call:
18490@@ -444,12 +616,24 @@ sysenter_do_call:
18491 testl $_TIF_ALLWORK_MASK, %ecx
18492 jne sysexit_audit
18493 sysenter_exit:
18494+
18495+#ifdef CONFIG_PAX_RANDKSTACK
18496+ pushl_cfi %eax
18497+ movl %esp, %eax
18498+ call pax_randomize_kstack
18499+ popl_cfi %eax
18500+#endif
18501+
18502+ pax_erase_kstack
18503+
18504 /* if something modifies registers it must also disable sysexit */
18505 movl PT_EIP(%esp), %edx
18506 movl PT_OLDESP(%esp), %ecx
18507 xorl %ebp,%ebp
18508 TRACE_IRQS_ON
18509 1: mov PT_FS(%esp), %fs
18510+2: mov PT_DS(%esp), %ds
18511+3: mov PT_ES(%esp), %es
18512 PTGS_TO_GS
18513 ENABLE_INTERRUPTS_SYSEXIT
18514
18515@@ -466,6 +650,9 @@ sysenter_audit:
18516 movl %eax,%edx /* 2nd arg: syscall number */
18517 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18518 call __audit_syscall_entry
18519+
18520+ pax_erase_kstack
18521+
18522 pushl_cfi %ebx
18523 movl PT_EAX(%esp),%eax /* reload syscall number */
18524 jmp sysenter_do_call
18525@@ -491,10 +678,16 @@ sysexit_audit:
18526
18527 CFI_ENDPROC
18528 .pushsection .fixup,"ax"
18529-2: movl $0,PT_FS(%esp)
18530+4: movl $0,PT_FS(%esp)
18531+ jmp 1b
18532+5: movl $0,PT_DS(%esp)
18533+ jmp 1b
18534+6: movl $0,PT_ES(%esp)
18535 jmp 1b
18536 .popsection
18537- _ASM_EXTABLE(1b,2b)
18538+ _ASM_EXTABLE(1b,4b)
18539+ _ASM_EXTABLE(2b,5b)
18540+ _ASM_EXTABLE(3b,6b)
18541 PTGS_TO_GS_EX
18542 ENDPROC(ia32_sysenter_target)
18543
18544@@ -509,6 +702,11 @@ ENTRY(system_call)
18545 pushl_cfi %eax # save orig_eax
18546 SAVE_ALL
18547 GET_THREAD_INFO(%ebp)
18548+
18549+#ifdef CONFIG_PAX_RANDKSTACK
18550+ pax_erase_kstack
18551+#endif
18552+
18553 # system call tracing in operation / emulation
18554 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18555 jnz syscall_trace_entry
18556@@ -527,6 +725,15 @@ syscall_exit:
18557 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18558 jne syscall_exit_work
18559
18560+restore_all_pax:
18561+
18562+#ifdef CONFIG_PAX_RANDKSTACK
18563+ movl %esp, %eax
18564+ call pax_randomize_kstack
18565+#endif
18566+
18567+ pax_erase_kstack
18568+
18569 restore_all:
18570 TRACE_IRQS_IRET
18571 restore_all_notrace:
18572@@ -583,14 +790,34 @@ ldt_ss:
18573 * compensating for the offset by changing to the ESPFIX segment with
18574 * a base address that matches for the difference.
18575 */
18576-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18577+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18578 mov %esp, %edx /* load kernel esp */
18579 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18580 mov %dx, %ax /* eax: new kernel esp */
18581 sub %eax, %edx /* offset (low word is 0) */
18582+#ifdef CONFIG_SMP
18583+ movl PER_CPU_VAR(cpu_number), %ebx
18584+ shll $PAGE_SHIFT_asm, %ebx
18585+ addl $cpu_gdt_table, %ebx
18586+#else
18587+ movl $cpu_gdt_table, %ebx
18588+#endif
18589 shr $16, %edx
18590- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18591- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18592+
18593+#ifdef CONFIG_PAX_KERNEXEC
18594+ mov %cr0, %esi
18595+ btr $16, %esi
18596+ mov %esi, %cr0
18597+#endif
18598+
18599+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18600+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18601+
18602+#ifdef CONFIG_PAX_KERNEXEC
18603+ bts $16, %esi
18604+ mov %esi, %cr0
18605+#endif
18606+
18607 pushl_cfi $__ESPFIX_SS
18608 pushl_cfi %eax /* new kernel esp */
18609 /* Disable interrupts, but do not irqtrace this section: we
18610@@ -619,20 +846,18 @@ work_resched:
18611 movl TI_flags(%ebp), %ecx
18612 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18613 # than syscall tracing?
18614- jz restore_all
18615+ jz restore_all_pax
18616 testb $_TIF_NEED_RESCHED, %cl
18617 jnz work_resched
18618
18619 work_notifysig: # deal with pending signals and
18620 # notify-resume requests
18621+ movl %esp, %eax
18622 #ifdef CONFIG_VM86
18623 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18624- movl %esp, %eax
18625 jne work_notifysig_v86 # returning to kernel-space or
18626 # vm86-space
18627 1:
18628-#else
18629- movl %esp, %eax
18630 #endif
18631 TRACE_IRQS_ON
18632 ENABLE_INTERRUPTS(CLBR_NONE)
18633@@ -653,7 +878,7 @@ work_notifysig_v86:
18634 movl %eax, %esp
18635 jmp 1b
18636 #endif
18637-END(work_pending)
18638+ENDPROC(work_pending)
18639
18640 # perform syscall exit tracing
18641 ALIGN
18642@@ -661,11 +886,14 @@ syscall_trace_entry:
18643 movl $-ENOSYS,PT_EAX(%esp)
18644 movl %esp, %eax
18645 call syscall_trace_enter
18646+
18647+ pax_erase_kstack
18648+
18649 /* What it returned is what we'll actually use. */
18650 cmpl $(NR_syscalls), %eax
18651 jnae syscall_call
18652 jmp syscall_exit
18653-END(syscall_trace_entry)
18654+ENDPROC(syscall_trace_entry)
18655
18656 # perform syscall exit tracing
18657 ALIGN
18658@@ -678,21 +906,25 @@ syscall_exit_work:
18659 movl %esp, %eax
18660 call syscall_trace_leave
18661 jmp resume_userspace
18662-END(syscall_exit_work)
18663+ENDPROC(syscall_exit_work)
18664 CFI_ENDPROC
18665
18666 RING0_INT_FRAME # can't unwind into user space anyway
18667 syscall_fault:
18668+#ifdef CONFIG_PAX_MEMORY_UDEREF
18669+ push %ss
18670+ pop %ds
18671+#endif
18672 ASM_CLAC
18673 GET_THREAD_INFO(%ebp)
18674 movl $-EFAULT,PT_EAX(%esp)
18675 jmp resume_userspace
18676-END(syscall_fault)
18677+ENDPROC(syscall_fault)
18678
18679 syscall_badsys:
18680 movl $-ENOSYS,PT_EAX(%esp)
18681 jmp resume_userspace
18682-END(syscall_badsys)
18683+ENDPROC(syscall_badsys)
18684 CFI_ENDPROC
18685 /*
18686 * End of kprobes section
18687@@ -708,8 +940,15 @@ END(syscall_badsys)
18688 * normal stack and adjusts ESP with the matching offset.
18689 */
18690 /* fixup the stack */
18691- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18692- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18693+#ifdef CONFIG_SMP
18694+ movl PER_CPU_VAR(cpu_number), %ebx
18695+ shll $PAGE_SHIFT_asm, %ebx
18696+ addl $cpu_gdt_table, %ebx
18697+#else
18698+ movl $cpu_gdt_table, %ebx
18699+#endif
18700+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18701+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18702 shl $16, %eax
18703 addl %esp, %eax /* the adjusted stack pointer */
18704 pushl_cfi $__KERNEL_DS
18705@@ -762,7 +1001,7 @@ vector=vector+1
18706 .endr
18707 2: jmp common_interrupt
18708 .endr
18709-END(irq_entries_start)
18710+ENDPROC(irq_entries_start)
18711
18712 .previous
18713 END(interrupt)
18714@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
18715 pushl_cfi $do_coprocessor_error
18716 jmp error_code
18717 CFI_ENDPROC
18718-END(coprocessor_error)
18719+ENDPROC(coprocessor_error)
18720
18721 ENTRY(simd_coprocessor_error)
18722 RING0_INT_FRAME
18723@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
18724 #endif
18725 jmp error_code
18726 CFI_ENDPROC
18727-END(simd_coprocessor_error)
18728+ENDPROC(simd_coprocessor_error)
18729
18730 ENTRY(device_not_available)
18731 RING0_INT_FRAME
18732@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
18733 pushl_cfi $do_device_not_available
18734 jmp error_code
18735 CFI_ENDPROC
18736-END(device_not_available)
18737+ENDPROC(device_not_available)
18738
18739 #ifdef CONFIG_PARAVIRT
18740 ENTRY(native_iret)
18741 iret
18742 _ASM_EXTABLE(native_iret, iret_exc)
18743-END(native_iret)
18744+ENDPROC(native_iret)
18745
18746 ENTRY(native_irq_enable_sysexit)
18747 sti
18748 sysexit
18749-END(native_irq_enable_sysexit)
18750+ENDPROC(native_irq_enable_sysexit)
18751 #endif
18752
18753 ENTRY(overflow)
18754@@ -865,7 +1104,7 @@ ENTRY(overflow)
18755 pushl_cfi $do_overflow
18756 jmp error_code
18757 CFI_ENDPROC
18758-END(overflow)
18759+ENDPROC(overflow)
18760
18761 ENTRY(bounds)
18762 RING0_INT_FRAME
18763@@ -874,7 +1113,7 @@ ENTRY(bounds)
18764 pushl_cfi $do_bounds
18765 jmp error_code
18766 CFI_ENDPROC
18767-END(bounds)
18768+ENDPROC(bounds)
18769
18770 ENTRY(invalid_op)
18771 RING0_INT_FRAME
18772@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
18773 pushl_cfi $do_invalid_op
18774 jmp error_code
18775 CFI_ENDPROC
18776-END(invalid_op)
18777+ENDPROC(invalid_op)
18778
18779 ENTRY(coprocessor_segment_overrun)
18780 RING0_INT_FRAME
18781@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
18782 pushl_cfi $do_coprocessor_segment_overrun
18783 jmp error_code
18784 CFI_ENDPROC
18785-END(coprocessor_segment_overrun)
18786+ENDPROC(coprocessor_segment_overrun)
18787
18788 ENTRY(invalid_TSS)
18789 RING0_EC_FRAME
18790@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
18791 pushl_cfi $do_invalid_TSS
18792 jmp error_code
18793 CFI_ENDPROC
18794-END(invalid_TSS)
18795+ENDPROC(invalid_TSS)
18796
18797 ENTRY(segment_not_present)
18798 RING0_EC_FRAME
18799@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
18800 pushl_cfi $do_segment_not_present
18801 jmp error_code
18802 CFI_ENDPROC
18803-END(segment_not_present)
18804+ENDPROC(segment_not_present)
18805
18806 ENTRY(stack_segment)
18807 RING0_EC_FRAME
18808@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
18809 pushl_cfi $do_stack_segment
18810 jmp error_code
18811 CFI_ENDPROC
18812-END(stack_segment)
18813+ENDPROC(stack_segment)
18814
18815 ENTRY(alignment_check)
18816 RING0_EC_FRAME
18817@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
18818 pushl_cfi $do_alignment_check
18819 jmp error_code
18820 CFI_ENDPROC
18821-END(alignment_check)
18822+ENDPROC(alignment_check)
18823
18824 ENTRY(divide_error)
18825 RING0_INT_FRAME
18826@@ -933,7 +1172,7 @@ ENTRY(divide_error)
18827 pushl_cfi $do_divide_error
18828 jmp error_code
18829 CFI_ENDPROC
18830-END(divide_error)
18831+ENDPROC(divide_error)
18832
18833 #ifdef CONFIG_X86_MCE
18834 ENTRY(machine_check)
18835@@ -943,7 +1182,7 @@ ENTRY(machine_check)
18836 pushl_cfi machine_check_vector
18837 jmp error_code
18838 CFI_ENDPROC
18839-END(machine_check)
18840+ENDPROC(machine_check)
18841 #endif
18842
18843 ENTRY(spurious_interrupt_bug)
18844@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
18845 pushl_cfi $do_spurious_interrupt_bug
18846 jmp error_code
18847 CFI_ENDPROC
18848-END(spurious_interrupt_bug)
18849+ENDPROC(spurious_interrupt_bug)
18850 /*
18851 * End of kprobes section
18852 */
18853@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
18854
18855 ENTRY(mcount)
18856 ret
18857-END(mcount)
18858+ENDPROC(mcount)
18859
18860 ENTRY(ftrace_caller)
18861 cmpl $0, function_trace_stop
18862@@ -1096,7 +1335,7 @@ ftrace_graph_call:
18863 .globl ftrace_stub
18864 ftrace_stub:
18865 ret
18866-END(ftrace_caller)
18867+ENDPROC(ftrace_caller)
18868
18869 ENTRY(ftrace_regs_caller)
18870 pushf /* push flags before compare (in cs location) */
18871@@ -1197,7 +1436,7 @@ trace:
18872 popl %ecx
18873 popl %eax
18874 jmp ftrace_stub
18875-END(mcount)
18876+ENDPROC(mcount)
18877 #endif /* CONFIG_DYNAMIC_FTRACE */
18878 #endif /* CONFIG_FUNCTION_TRACER */
18879
18880@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
18881 popl %ecx
18882 popl %eax
18883 ret
18884-END(ftrace_graph_caller)
18885+ENDPROC(ftrace_graph_caller)
18886
18887 .globl return_to_handler
18888 return_to_handler:
18889@@ -1271,15 +1510,18 @@ error_code:
18890 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18891 REG_TO_PTGS %ecx
18892 SET_KERNEL_GS %ecx
18893- movl $(__USER_DS), %ecx
18894+ movl $(__KERNEL_DS), %ecx
18895 movl %ecx, %ds
18896 movl %ecx, %es
18897+
18898+ pax_enter_kernel
18899+
18900 TRACE_IRQS_OFF
18901 movl %esp,%eax # pt_regs pointer
18902 call *%edi
18903 jmp ret_from_exception
18904 CFI_ENDPROC
18905-END(page_fault)
18906+ENDPROC(page_fault)
18907
18908 /*
18909 * Debug traps and NMI can happen at the one SYSENTER instruction
18910@@ -1322,7 +1564,7 @@ debug_stack_correct:
18911 call do_debug
18912 jmp ret_from_exception
18913 CFI_ENDPROC
18914-END(debug)
18915+ENDPROC(debug)
18916
18917 /*
18918 * NMI is doubly nasty. It can happen _while_ we're handling
18919@@ -1360,6 +1602,9 @@ nmi_stack_correct:
18920 xorl %edx,%edx # zero error code
18921 movl %esp,%eax # pt_regs pointer
18922 call do_nmi
18923+
18924+ pax_exit_kernel
18925+
18926 jmp restore_all_notrace
18927 CFI_ENDPROC
18928
18929@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
18930 FIXUP_ESPFIX_STACK # %eax == %esp
18931 xorl %edx,%edx # zero error code
18932 call do_nmi
18933+
18934+ pax_exit_kernel
18935+
18936 RESTORE_REGS
18937 lss 12+4(%esp), %esp # back to espfix stack
18938 CFI_ADJUST_CFA_OFFSET -24
18939 jmp irq_return
18940 CFI_ENDPROC
18941-END(nmi)
18942+ENDPROC(nmi)
18943
18944 ENTRY(int3)
18945 RING0_INT_FRAME
18946@@ -1414,14 +1662,14 @@ ENTRY(int3)
18947 call do_int3
18948 jmp ret_from_exception
18949 CFI_ENDPROC
18950-END(int3)
18951+ENDPROC(int3)
18952
18953 ENTRY(general_protection)
18954 RING0_EC_FRAME
18955 pushl_cfi $do_general_protection
18956 jmp error_code
18957 CFI_ENDPROC
18958-END(general_protection)
18959+ENDPROC(general_protection)
18960
18961 #ifdef CONFIG_KVM_GUEST
18962 ENTRY(async_page_fault)
18963@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
18964 pushl_cfi $do_async_page_fault
18965 jmp error_code
18966 CFI_ENDPROC
18967-END(async_page_fault)
18968+ENDPROC(async_page_fault)
18969 #endif
18970
18971 /*
18972diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18973index 7272089..6204f9c5 100644
18974--- a/arch/x86/kernel/entry_64.S
18975+++ b/arch/x86/kernel/entry_64.S
18976@@ -59,6 +59,8 @@
18977 #include <asm/context_tracking.h>
18978 #include <asm/smap.h>
18979 #include <linux/err.h>
18980+#include <asm/pgtable.h>
18981+#include <asm/alternative-asm.h>
18982
18983 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18984 #include <linux/elf-em.h>
18985@@ -80,8 +82,9 @@
18986 #ifdef CONFIG_DYNAMIC_FTRACE
18987
18988 ENTRY(function_hook)
18989+ pax_force_retaddr
18990 retq
18991-END(function_hook)
18992+ENDPROC(function_hook)
18993
18994 /* skip is set if stack has been adjusted */
18995 .macro ftrace_caller_setup skip=0
18996@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18997 #endif
18998
18999 GLOBAL(ftrace_stub)
19000+ pax_force_retaddr
19001 retq
19002-END(ftrace_caller)
19003+ENDPROC(ftrace_caller)
19004
19005 ENTRY(ftrace_regs_caller)
19006 /* Save the current flags before compare (in SS location)*/
19007@@ -191,7 +195,7 @@ ftrace_restore_flags:
19008 popfq
19009 jmp ftrace_stub
19010
19011-END(ftrace_regs_caller)
19012+ENDPROC(ftrace_regs_caller)
19013
19014
19015 #else /* ! CONFIG_DYNAMIC_FTRACE */
19016@@ -212,6 +216,7 @@ ENTRY(function_hook)
19017 #endif
19018
19019 GLOBAL(ftrace_stub)
19020+ pax_force_retaddr
19021 retq
19022
19023 trace:
19024@@ -225,12 +230,13 @@ trace:
19025 #endif
19026 subq $MCOUNT_INSN_SIZE, %rdi
19027
19028+ pax_force_fptr ftrace_trace_function
19029 call *ftrace_trace_function
19030
19031 MCOUNT_RESTORE_FRAME
19032
19033 jmp ftrace_stub
19034-END(function_hook)
19035+ENDPROC(function_hook)
19036 #endif /* CONFIG_DYNAMIC_FTRACE */
19037 #endif /* CONFIG_FUNCTION_TRACER */
19038
19039@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19040
19041 MCOUNT_RESTORE_FRAME
19042
19043+ pax_force_retaddr
19044 retq
19045-END(ftrace_graph_caller)
19046+ENDPROC(ftrace_graph_caller)
19047
19048 GLOBAL(return_to_handler)
19049 subq $24, %rsp
19050@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19051 movq 8(%rsp), %rdx
19052 movq (%rsp), %rax
19053 addq $24, %rsp
19054+ pax_force_fptr %rdi
19055 jmp *%rdi
19056+ENDPROC(return_to_handler)
19057 #endif
19058
19059
19060@@ -284,6 +293,309 @@ ENTRY(native_usergs_sysret64)
19061 ENDPROC(native_usergs_sysret64)
19062 #endif /* CONFIG_PARAVIRT */
19063
19064+ .macro ljmpq sel, off
19065+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19066+ .byte 0x48; ljmp *1234f(%rip)
19067+ .pushsection .rodata
19068+ .align 16
19069+ 1234: .quad \off; .word \sel
19070+ .popsection
19071+#else
19072+ pushq $\sel
19073+ pushq $\off
19074+ lretq
19075+#endif
19076+ .endm
19077+
19078+ .macro pax_enter_kernel
19079+ pax_set_fptr_mask
19080+#ifdef CONFIG_PAX_KERNEXEC
19081+ call pax_enter_kernel
19082+#endif
19083+ .endm
19084+
19085+ .macro pax_exit_kernel
19086+#ifdef CONFIG_PAX_KERNEXEC
19087+ call pax_exit_kernel
19088+#endif
19089+ .endm
19090+
19091+#ifdef CONFIG_PAX_KERNEXEC
19092+ENTRY(pax_enter_kernel)
19093+ pushq %rdi
19094+
19095+#ifdef CONFIG_PARAVIRT
19096+ PV_SAVE_REGS(CLBR_RDI)
19097+#endif
19098+
19099+ GET_CR0_INTO_RDI
19100+ bts $16,%rdi
19101+ jnc 3f
19102+ mov %cs,%edi
19103+ cmp $__KERNEL_CS,%edi
19104+ jnz 2f
19105+1:
19106+
19107+#ifdef CONFIG_PARAVIRT
19108+ PV_RESTORE_REGS(CLBR_RDI)
19109+#endif
19110+
19111+ popq %rdi
19112+ pax_force_retaddr
19113+ retq
19114+
19115+2: ljmpq __KERNEL_CS,1b
19116+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19117+4: SET_RDI_INTO_CR0
19118+ jmp 1b
19119+ENDPROC(pax_enter_kernel)
19120+
19121+ENTRY(pax_exit_kernel)
19122+ pushq %rdi
19123+
19124+#ifdef CONFIG_PARAVIRT
19125+ PV_SAVE_REGS(CLBR_RDI)
19126+#endif
19127+
19128+ mov %cs,%rdi
19129+ cmp $__KERNEXEC_KERNEL_CS,%edi
19130+ jz 2f
19131+ GET_CR0_INTO_RDI
19132+ bts $16,%rdi
19133+ jnc 4f
19134+1:
19135+
19136+#ifdef CONFIG_PARAVIRT
19137+ PV_RESTORE_REGS(CLBR_RDI);
19138+#endif
19139+
19140+ popq %rdi
19141+ pax_force_retaddr
19142+ retq
19143+
19144+2: GET_CR0_INTO_RDI
19145+ btr $16,%rdi
19146+ jnc 4f
19147+ ljmpq __KERNEL_CS,3f
19148+3: SET_RDI_INTO_CR0
19149+ jmp 1b
19150+4: ud2
19151+ jmp 4b
19152+ENDPROC(pax_exit_kernel)
19153+#endif
19154+
19155+ .macro pax_enter_kernel_user
19156+ pax_set_fptr_mask
19157+#ifdef CONFIG_PAX_MEMORY_UDEREF
19158+ call pax_enter_kernel_user
19159+#endif
19160+ .endm
19161+
19162+ .macro pax_exit_kernel_user
19163+#ifdef CONFIG_PAX_MEMORY_UDEREF
19164+ call pax_exit_kernel_user
19165+#endif
19166+#ifdef CONFIG_PAX_RANDKSTACK
19167+ pushq %rax
19168+ pushq %r11
19169+ call pax_randomize_kstack
19170+ popq %r11
19171+ popq %rax
19172+#endif
19173+ .endm
19174+
19175+#ifdef CONFIG_PAX_MEMORY_UDEREF
19176+ENTRY(pax_enter_kernel_user)
19177+ pushq %rdi
19178+ pushq %rbx
19179+
19180+#ifdef CONFIG_PARAVIRT
19181+ PV_SAVE_REGS(CLBR_RDI)
19182+#endif
19183+
19184+ GET_CR3_INTO_RDI
19185+ mov %rdi,%rbx
19186+ add $__START_KERNEL_map,%rbx
19187+ sub phys_base(%rip),%rbx
19188+
19189+#ifdef CONFIG_PARAVIRT
19190+ cmpl $0, pv_info+PARAVIRT_enabled
19191+ jz 1f
19192+ pushq %rdi
19193+ i = 0
19194+ .rept USER_PGD_PTRS
19195+ mov i*8(%rbx),%rsi
19196+ mov $0,%sil
19197+ lea i*8(%rbx),%rdi
19198+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19199+ i = i + 1
19200+ .endr
19201+ popq %rdi
19202+ jmp 2f
19203+1:
19204+#endif
19205+
19206+ i = 0
19207+ .rept USER_PGD_PTRS
19208+ movb $0,i*8(%rbx)
19209+ i = i + 1
19210+ .endr
19211+
19212+#ifdef CONFIG_PARAVIRT
19213+2:
19214+#endif
19215+ SET_RDI_INTO_CR3
19216+
19217+#ifdef CONFIG_PAX_KERNEXEC
19218+ GET_CR0_INTO_RDI
19219+ bts $16,%rdi
19220+ SET_RDI_INTO_CR0
19221+#endif
19222+
19223+#ifdef CONFIG_PARAVIRT
19224+ PV_RESTORE_REGS(CLBR_RDI)
19225+#endif
19226+
19227+ popq %rbx
19228+ popq %rdi
19229+ pax_force_retaddr
19230+ retq
19231+ENDPROC(pax_enter_kernel_user)
19232+
19233+ENTRY(pax_exit_kernel_user)
19234+ pushq %rdi
19235+ pushq %rbx
19236+
19237+#ifdef CONFIG_PARAVIRT
19238+ PV_SAVE_REGS(CLBR_RDI)
19239+#endif
19240+
19241+#ifdef CONFIG_PAX_KERNEXEC
19242+ GET_CR0_INTO_RDI
19243+ btr $16,%rdi
19244+ jnc 3f
19245+ SET_RDI_INTO_CR0
19246+#endif
19247+
19248+ GET_CR3_INTO_RDI
19249+ mov %rdi,%rbx
19250+ add $__START_KERNEL_map,%rbx
19251+ sub phys_base(%rip),%rbx
19252+
19253+#ifdef CONFIG_PARAVIRT
19254+ cmpl $0, pv_info+PARAVIRT_enabled
19255+ jz 1f
19256+ i = 0
19257+ .rept USER_PGD_PTRS
19258+ mov i*8(%rbx),%rsi
19259+ mov $0x67,%sil
19260+ lea i*8(%rbx),%rdi
19261+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19262+ i = i + 1
19263+ .endr
19264+ jmp 2f
19265+1:
19266+#endif
19267+
19268+ i = 0
19269+ .rept USER_PGD_PTRS
19270+ movb $0x67,i*8(%rbx)
19271+ i = i + 1
19272+ .endr
19273+
19274+#ifdef CONFIG_PARAVIRT
19275+2: PV_RESTORE_REGS(CLBR_RDI)
19276+#endif
19277+
19278+ popq %rbx
19279+ popq %rdi
19280+ pax_force_retaddr
19281+ retq
19282+3: ud2
19283+ jmp 3b
19284+ENDPROC(pax_exit_kernel_user)
19285+#endif
19286+
19287+ .macro pax_enter_kernel_nmi
19288+ pax_set_fptr_mask
19289+
19290+#ifdef CONFIG_PAX_KERNEXEC
19291+ GET_CR0_INTO_RDI
19292+ bts $16,%rdi
19293+ jc 110f
19294+ SET_RDI_INTO_CR0
19295+ or $2,%ebx
19296+110:
19297+#endif
19298+ .endm
19299+
19300+ .macro pax_exit_kernel_nmi
19301+#ifdef CONFIG_PAX_KERNEXEC
19302+ btr $1,%ebx
19303+ jnc 110f
19304+ GET_CR0_INTO_RDI
19305+ btr $16,%rdi
19306+ SET_RDI_INTO_CR0
19307+110:
19308+#endif
19309+ .endm
19310+
19311+ .macro pax_erase_kstack
19312+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19313+ call pax_erase_kstack
19314+#endif
19315+ .endm
19316+
19317+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19318+ENTRY(pax_erase_kstack)
19319+ pushq %rdi
19320+ pushq %rcx
19321+ pushq %rax
19322+ pushq %r11
19323+
19324+ GET_THREAD_INFO(%r11)
19325+ mov TI_lowest_stack(%r11), %rdi
19326+ mov $-0xBEEF, %rax
19327+ std
19328+
19329+1: mov %edi, %ecx
19330+ and $THREAD_SIZE_asm - 1, %ecx
19331+ shr $3, %ecx
19332+ repne scasq
19333+ jecxz 2f
19334+
19335+ cmp $2*8, %ecx
19336+ jc 2f
19337+
19338+ mov $2*8, %ecx
19339+ repe scasq
19340+ jecxz 2f
19341+ jne 1b
19342+
19343+2: cld
19344+ mov %esp, %ecx
19345+ sub %edi, %ecx
19346+
19347+ cmp $THREAD_SIZE_asm, %rcx
19348+ jb 3f
19349+ ud2
19350+3:
19351+
19352+ shr $3, %ecx
19353+ rep stosq
19354+
19355+ mov TI_task_thread_sp0(%r11), %rdi
19356+ sub $256, %rdi
19357+ mov %rdi, TI_lowest_stack(%r11)
19358+
19359+ popq %r11
19360+ popq %rax
19361+ popq %rcx
19362+ popq %rdi
19363+ pax_force_retaddr
19364+ ret
19365+ENDPROC(pax_erase_kstack)
19366+#endif
19367
19368 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19369 #ifdef CONFIG_TRACE_IRQFLAGS
19370@@ -375,8 +687,8 @@ ENDPROC(native_usergs_sysret64)
19371 .endm
19372
19373 .macro UNFAKE_STACK_FRAME
19374- addq $8*6, %rsp
19375- CFI_ADJUST_CFA_OFFSET -(6*8)
19376+ addq $8*6 + ARG_SKIP, %rsp
19377+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19378 .endm
19379
19380 /*
19381@@ -463,7 +775,7 @@ ENDPROC(native_usergs_sysret64)
19382 movq %rsp, %rsi
19383
19384 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19385- testl $3, CS-RBP(%rsi)
19386+ testb $3, CS-RBP(%rsi)
19387 je 1f
19388 SWAPGS
19389 /*
19390@@ -498,9 +810,10 @@ ENTRY(save_rest)
19391 movq_cfi r15, R15+16
19392 movq %r11, 8(%rsp) /* return address */
19393 FIXUP_TOP_OF_STACK %r11, 16
19394+ pax_force_retaddr
19395 ret
19396 CFI_ENDPROC
19397-END(save_rest)
19398+ENDPROC(save_rest)
19399
19400 /* save complete stack frame */
19401 .pushsection .kprobes.text, "ax"
19402@@ -529,9 +842,10 @@ ENTRY(save_paranoid)
19403 js 1f /* negative -> in kernel */
19404 SWAPGS
19405 xorl %ebx,%ebx
19406-1: ret
19407+1: pax_force_retaddr_bts
19408+ ret
19409 CFI_ENDPROC
19410-END(save_paranoid)
19411+ENDPROC(save_paranoid)
19412 .popsection
19413
19414 /*
19415@@ -553,7 +867,7 @@ ENTRY(ret_from_fork)
19416
19417 RESTORE_REST
19418
19419- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19420+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19421 jz 1f
19422
19423 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19424@@ -571,7 +885,7 @@ ENTRY(ret_from_fork)
19425 RESTORE_REST
19426 jmp int_ret_from_sys_call
19427 CFI_ENDPROC
19428-END(ret_from_fork)
19429+ENDPROC(ret_from_fork)
19430
19431 /*
19432 * System call entry. Up to 6 arguments in registers are supported.
19433@@ -608,7 +922,7 @@ END(ret_from_fork)
19434 ENTRY(system_call)
19435 CFI_STARTPROC simple
19436 CFI_SIGNAL_FRAME
19437- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19438+ CFI_DEF_CFA rsp,0
19439 CFI_REGISTER rip,rcx
19440 /*CFI_REGISTER rflags,r11*/
19441 SWAPGS_UNSAFE_STACK
19442@@ -621,16 +935,23 @@ GLOBAL(system_call_after_swapgs)
19443
19444 movq %rsp,PER_CPU_VAR(old_rsp)
19445 movq PER_CPU_VAR(kernel_stack),%rsp
19446+ SAVE_ARGS 8*6,0
19447+ pax_enter_kernel_user
19448+
19449+#ifdef CONFIG_PAX_RANDKSTACK
19450+ pax_erase_kstack
19451+#endif
19452+
19453 /*
19454 * No need to follow this irqs off/on section - it's straight
19455 * and short:
19456 */
19457 ENABLE_INTERRUPTS(CLBR_NONE)
19458- SAVE_ARGS 8,0
19459 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19460 movq %rcx,RIP-ARGOFFSET(%rsp)
19461 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19462- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19463+ GET_THREAD_INFO(%rcx)
19464+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19465 jnz tracesys
19466 system_call_fastpath:
19467 #if __SYSCALL_MASK == ~0
19468@@ -640,7 +961,7 @@ system_call_fastpath:
19469 cmpl $__NR_syscall_max,%eax
19470 #endif
19471 ja badsys
19472- movq %r10,%rcx
19473+ movq R10-ARGOFFSET(%rsp),%rcx
19474 call *sys_call_table(,%rax,8) # XXX: rip relative
19475 movq %rax,RAX-ARGOFFSET(%rsp)
19476 /*
19477@@ -654,10 +975,13 @@ sysret_check:
19478 LOCKDEP_SYS_EXIT
19479 DISABLE_INTERRUPTS(CLBR_NONE)
19480 TRACE_IRQS_OFF
19481- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19482+ GET_THREAD_INFO(%rcx)
19483+ movl TI_flags(%rcx),%edx
19484 andl %edi,%edx
19485 jnz sysret_careful
19486 CFI_REMEMBER_STATE
19487+ pax_exit_kernel_user
19488+ pax_erase_kstack
19489 /*
19490 * sysretq will re-enable interrupts:
19491 */
19492@@ -709,14 +1033,18 @@ badsys:
19493 * jump back to the normal fast path.
19494 */
19495 auditsys:
19496- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19497+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19498 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19499 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19500 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19501 movq %rax,%rsi /* 2nd arg: syscall number */
19502 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19503 call __audit_syscall_entry
19504+
19505+ pax_erase_kstack
19506+
19507 LOAD_ARGS 0 /* reload call-clobbered registers */
19508+ pax_set_fptr_mask
19509 jmp system_call_fastpath
19510
19511 /*
19512@@ -737,7 +1065,7 @@ sysret_audit:
19513 /* Do syscall tracing */
19514 tracesys:
19515 #ifdef CONFIG_AUDITSYSCALL
19516- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19517+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19518 jz auditsys
19519 #endif
19520 SAVE_REST
19521@@ -745,12 +1073,16 @@ tracesys:
19522 FIXUP_TOP_OF_STACK %rdi
19523 movq %rsp,%rdi
19524 call syscall_trace_enter
19525+
19526+ pax_erase_kstack
19527+
19528 /*
19529 * Reload arg registers from stack in case ptrace changed them.
19530 * We don't reload %rax because syscall_trace_enter() returned
19531 * the value it wants us to use in the table lookup.
19532 */
19533 LOAD_ARGS ARGOFFSET, 1
19534+ pax_set_fptr_mask
19535 RESTORE_REST
19536 #if __SYSCALL_MASK == ~0
19537 cmpq $__NR_syscall_max,%rax
19538@@ -759,7 +1091,7 @@ tracesys:
19539 cmpl $__NR_syscall_max,%eax
19540 #endif
19541 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19542- movq %r10,%rcx /* fixup for C */
19543+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19544 call *sys_call_table(,%rax,8)
19545 movq %rax,RAX-ARGOFFSET(%rsp)
19546 /* Use IRET because user could have changed frame */
19547@@ -780,7 +1112,9 @@ GLOBAL(int_with_check)
19548 andl %edi,%edx
19549 jnz int_careful
19550 andl $~TS_COMPAT,TI_status(%rcx)
19551- jmp retint_swapgs
19552+ pax_exit_kernel_user
19553+ pax_erase_kstack
19554+ jmp retint_swapgs_pax
19555
19556 /* Either reschedule or signal or syscall exit tracking needed. */
19557 /* First do a reschedule test. */
19558@@ -826,7 +1160,7 @@ int_restore_rest:
19559 TRACE_IRQS_OFF
19560 jmp int_with_check
19561 CFI_ENDPROC
19562-END(system_call)
19563+ENDPROC(system_call)
19564
19565 .macro FORK_LIKE func
19566 ENTRY(stub_\func)
19567@@ -839,9 +1173,10 @@ ENTRY(stub_\func)
19568 DEFAULT_FRAME 0 8 /* offset 8: return address */
19569 call sys_\func
19570 RESTORE_TOP_OF_STACK %r11, 8
19571+ pax_force_retaddr
19572 ret $REST_SKIP /* pop extended registers */
19573 CFI_ENDPROC
19574-END(stub_\func)
19575+ENDPROC(stub_\func)
19576 .endm
19577
19578 .macro FIXED_FRAME label,func
19579@@ -851,9 +1186,10 @@ ENTRY(\label)
19580 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
19581 call \func
19582 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
19583+ pax_force_retaddr
19584 ret
19585 CFI_ENDPROC
19586-END(\label)
19587+ENDPROC(\label)
19588 .endm
19589
19590 FORK_LIKE clone
19591@@ -870,9 +1206,10 @@ ENTRY(ptregscall_common)
19592 movq_cfi_restore R12+8, r12
19593 movq_cfi_restore RBP+8, rbp
19594 movq_cfi_restore RBX+8, rbx
19595+ pax_force_retaddr
19596 ret $REST_SKIP /* pop extended registers */
19597 CFI_ENDPROC
19598-END(ptregscall_common)
19599+ENDPROC(ptregscall_common)
19600
19601 ENTRY(stub_execve)
19602 CFI_STARTPROC
19603@@ -885,7 +1222,7 @@ ENTRY(stub_execve)
19604 RESTORE_REST
19605 jmp int_ret_from_sys_call
19606 CFI_ENDPROC
19607-END(stub_execve)
19608+ENDPROC(stub_execve)
19609
19610 /*
19611 * sigreturn is special because it needs to restore all registers on return.
19612@@ -902,7 +1239,7 @@ ENTRY(stub_rt_sigreturn)
19613 RESTORE_REST
19614 jmp int_ret_from_sys_call
19615 CFI_ENDPROC
19616-END(stub_rt_sigreturn)
19617+ENDPROC(stub_rt_sigreturn)
19618
19619 #ifdef CONFIG_X86_X32_ABI
19620 ENTRY(stub_x32_rt_sigreturn)
19621@@ -916,7 +1253,7 @@ ENTRY(stub_x32_rt_sigreturn)
19622 RESTORE_REST
19623 jmp int_ret_from_sys_call
19624 CFI_ENDPROC
19625-END(stub_x32_rt_sigreturn)
19626+ENDPROC(stub_x32_rt_sigreturn)
19627
19628 ENTRY(stub_x32_execve)
19629 CFI_STARTPROC
19630@@ -930,7 +1267,7 @@ ENTRY(stub_x32_execve)
19631 RESTORE_REST
19632 jmp int_ret_from_sys_call
19633 CFI_ENDPROC
19634-END(stub_x32_execve)
19635+ENDPROC(stub_x32_execve)
19636
19637 #endif
19638
19639@@ -967,7 +1304,7 @@ vector=vector+1
19640 2: jmp common_interrupt
19641 .endr
19642 CFI_ENDPROC
19643-END(irq_entries_start)
19644+ENDPROC(irq_entries_start)
19645
19646 .previous
19647 END(interrupt)
19648@@ -987,6 +1324,16 @@ END(interrupt)
19649 subq $ORIG_RAX-RBP, %rsp
19650 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19651 SAVE_ARGS_IRQ
19652+#ifdef CONFIG_PAX_MEMORY_UDEREF
19653+ testb $3, CS(%rdi)
19654+ jnz 1f
19655+ pax_enter_kernel
19656+ jmp 2f
19657+1: pax_enter_kernel_user
19658+2:
19659+#else
19660+ pax_enter_kernel
19661+#endif
19662 call \func
19663 .endm
19664
19665@@ -1019,7 +1366,7 @@ ret_from_intr:
19666
19667 exit_intr:
19668 GET_THREAD_INFO(%rcx)
19669- testl $3,CS-ARGOFFSET(%rsp)
19670+ testb $3,CS-ARGOFFSET(%rsp)
19671 je retint_kernel
19672
19673 /* Interrupt came from user space */
19674@@ -1041,12 +1388,16 @@ retint_swapgs: /* return to user-space */
19675 * The iretq could re-enable interrupts:
19676 */
19677 DISABLE_INTERRUPTS(CLBR_ANY)
19678+ pax_exit_kernel_user
19679+retint_swapgs_pax:
19680 TRACE_IRQS_IRETQ
19681 SWAPGS
19682 jmp restore_args
19683
19684 retint_restore_args: /* return to kernel space */
19685 DISABLE_INTERRUPTS(CLBR_ANY)
19686+ pax_exit_kernel
19687+ pax_force_retaddr (RIP-ARGOFFSET)
19688 /*
19689 * The iretq could re-enable interrupts:
19690 */
19691@@ -1129,7 +1480,7 @@ ENTRY(retint_kernel)
19692 #endif
19693
19694 CFI_ENDPROC
19695-END(common_interrupt)
19696+ENDPROC(common_interrupt)
19697 /*
19698 * End of kprobes section
19699 */
19700@@ -1147,7 +1498,7 @@ ENTRY(\sym)
19701 interrupt \do_sym
19702 jmp ret_from_intr
19703 CFI_ENDPROC
19704-END(\sym)
19705+ENDPROC(\sym)
19706 .endm
19707
19708 #ifdef CONFIG_SMP
19709@@ -1208,12 +1559,22 @@ ENTRY(\sym)
19710 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19711 call error_entry
19712 DEFAULT_FRAME 0
19713+#ifdef CONFIG_PAX_MEMORY_UDEREF
19714+ testb $3, CS(%rsp)
19715+ jnz 1f
19716+ pax_enter_kernel
19717+ jmp 2f
19718+1: pax_enter_kernel_user
19719+2:
19720+#else
19721+ pax_enter_kernel
19722+#endif
19723 movq %rsp,%rdi /* pt_regs pointer */
19724 xorl %esi,%esi /* no error code */
19725 call \do_sym
19726 jmp error_exit /* %ebx: no swapgs flag */
19727 CFI_ENDPROC
19728-END(\sym)
19729+ENDPROC(\sym)
19730 .endm
19731
19732 .macro paranoidzeroentry sym do_sym
19733@@ -1226,15 +1587,25 @@ ENTRY(\sym)
19734 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19735 call save_paranoid
19736 TRACE_IRQS_OFF
19737+#ifdef CONFIG_PAX_MEMORY_UDEREF
19738+ testb $3, CS(%rsp)
19739+ jnz 1f
19740+ pax_enter_kernel
19741+ jmp 2f
19742+1: pax_enter_kernel_user
19743+2:
19744+#else
19745+ pax_enter_kernel
19746+#endif
19747 movq %rsp,%rdi /* pt_regs pointer */
19748 xorl %esi,%esi /* no error code */
19749 call \do_sym
19750 jmp paranoid_exit /* %ebx: no swapgs flag */
19751 CFI_ENDPROC
19752-END(\sym)
19753+ENDPROC(\sym)
19754 .endm
19755
19756-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19757+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19758 .macro paranoidzeroentry_ist sym do_sym ist
19759 ENTRY(\sym)
19760 INTR_FRAME
19761@@ -1245,14 +1616,30 @@ ENTRY(\sym)
19762 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19763 call save_paranoid
19764 TRACE_IRQS_OFF_DEBUG
19765+#ifdef CONFIG_PAX_MEMORY_UDEREF
19766+ testb $3, CS(%rsp)
19767+ jnz 1f
19768+ pax_enter_kernel
19769+ jmp 2f
19770+1: pax_enter_kernel_user
19771+2:
19772+#else
19773+ pax_enter_kernel
19774+#endif
19775 movq %rsp,%rdi /* pt_regs pointer */
19776 xorl %esi,%esi /* no error code */
19777+#ifdef CONFIG_SMP
19778+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19779+ lea init_tss(%r12), %r12
19780+#else
19781+ lea init_tss(%rip), %r12
19782+#endif
19783 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19784 call \do_sym
19785 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19786 jmp paranoid_exit /* %ebx: no swapgs flag */
19787 CFI_ENDPROC
19788-END(\sym)
19789+ENDPROC(\sym)
19790 .endm
19791
19792 .macro errorentry sym do_sym
19793@@ -1264,13 +1651,23 @@ ENTRY(\sym)
19794 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19795 call error_entry
19796 DEFAULT_FRAME 0
19797+#ifdef CONFIG_PAX_MEMORY_UDEREF
19798+ testb $3, CS(%rsp)
19799+ jnz 1f
19800+ pax_enter_kernel
19801+ jmp 2f
19802+1: pax_enter_kernel_user
19803+2:
19804+#else
19805+ pax_enter_kernel
19806+#endif
19807 movq %rsp,%rdi /* pt_regs pointer */
19808 movq ORIG_RAX(%rsp),%rsi /* get error code */
19809 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19810 call \do_sym
19811 jmp error_exit /* %ebx: no swapgs flag */
19812 CFI_ENDPROC
19813-END(\sym)
19814+ENDPROC(\sym)
19815 .endm
19816
19817 /* error code is on the stack already */
19818@@ -1284,13 +1681,23 @@ ENTRY(\sym)
19819 call save_paranoid
19820 DEFAULT_FRAME 0
19821 TRACE_IRQS_OFF
19822+#ifdef CONFIG_PAX_MEMORY_UDEREF
19823+ testb $3, CS(%rsp)
19824+ jnz 1f
19825+ pax_enter_kernel
19826+ jmp 2f
19827+1: pax_enter_kernel_user
19828+2:
19829+#else
19830+ pax_enter_kernel
19831+#endif
19832 movq %rsp,%rdi /* pt_regs pointer */
19833 movq ORIG_RAX(%rsp),%rsi /* get error code */
19834 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19835 call \do_sym
19836 jmp paranoid_exit /* %ebx: no swapgs flag */
19837 CFI_ENDPROC
19838-END(\sym)
19839+ENDPROC(\sym)
19840 .endm
19841
19842 zeroentry divide_error do_divide_error
19843@@ -1320,9 +1727,10 @@ gs_change:
19844 2: mfence /* workaround */
19845 SWAPGS
19846 popfq_cfi
19847+ pax_force_retaddr
19848 ret
19849 CFI_ENDPROC
19850-END(native_load_gs_index)
19851+ENDPROC(native_load_gs_index)
19852
19853 _ASM_EXTABLE(gs_change,bad_gs)
19854 .section .fixup,"ax"
19855@@ -1350,9 +1758,10 @@ ENTRY(call_softirq)
19856 CFI_DEF_CFA_REGISTER rsp
19857 CFI_ADJUST_CFA_OFFSET -8
19858 decl PER_CPU_VAR(irq_count)
19859+ pax_force_retaddr
19860 ret
19861 CFI_ENDPROC
19862-END(call_softirq)
19863+ENDPROC(call_softirq)
19864
19865 #ifdef CONFIG_XEN
19866 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19867@@ -1390,7 +1799,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19868 decl PER_CPU_VAR(irq_count)
19869 jmp error_exit
19870 CFI_ENDPROC
19871-END(xen_do_hypervisor_callback)
19872+ENDPROC(xen_do_hypervisor_callback)
19873
19874 /*
19875 * Hypervisor uses this for application faults while it executes.
19876@@ -1449,7 +1858,7 @@ ENTRY(xen_failsafe_callback)
19877 SAVE_ALL
19878 jmp error_exit
19879 CFI_ENDPROC
19880-END(xen_failsafe_callback)
19881+ENDPROC(xen_failsafe_callback)
19882
19883 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
19884 xen_hvm_callback_vector xen_evtchn_do_upcall
19885@@ -1501,18 +1910,33 @@ ENTRY(paranoid_exit)
19886 DEFAULT_FRAME
19887 DISABLE_INTERRUPTS(CLBR_NONE)
19888 TRACE_IRQS_OFF_DEBUG
19889- testl %ebx,%ebx /* swapgs needed? */
19890+ testl $1,%ebx /* swapgs needed? */
19891 jnz paranoid_restore
19892- testl $3,CS(%rsp)
19893+ testb $3,CS(%rsp)
19894 jnz paranoid_userspace
19895+#ifdef CONFIG_PAX_MEMORY_UDEREF
19896+ pax_exit_kernel
19897+ TRACE_IRQS_IRETQ 0
19898+ SWAPGS_UNSAFE_STACK
19899+ RESTORE_ALL 8
19900+ pax_force_retaddr_bts
19901+ jmp irq_return
19902+#endif
19903 paranoid_swapgs:
19904+#ifdef CONFIG_PAX_MEMORY_UDEREF
19905+ pax_exit_kernel_user
19906+#else
19907+ pax_exit_kernel
19908+#endif
19909 TRACE_IRQS_IRETQ 0
19910 SWAPGS_UNSAFE_STACK
19911 RESTORE_ALL 8
19912 jmp irq_return
19913 paranoid_restore:
19914+ pax_exit_kernel
19915 TRACE_IRQS_IRETQ_DEBUG 0
19916 RESTORE_ALL 8
19917+ pax_force_retaddr_bts
19918 jmp irq_return
19919 paranoid_userspace:
19920 GET_THREAD_INFO(%rcx)
19921@@ -1541,7 +1965,7 @@ paranoid_schedule:
19922 TRACE_IRQS_OFF
19923 jmp paranoid_userspace
19924 CFI_ENDPROC
19925-END(paranoid_exit)
19926+ENDPROC(paranoid_exit)
19927
19928 /*
19929 * Exception entry point. This expects an error code/orig_rax on the stack.
19930@@ -1568,12 +1992,13 @@ ENTRY(error_entry)
19931 movq_cfi r14, R14+8
19932 movq_cfi r15, R15+8
19933 xorl %ebx,%ebx
19934- testl $3,CS+8(%rsp)
19935+ testb $3,CS+8(%rsp)
19936 je error_kernelspace
19937 error_swapgs:
19938 SWAPGS
19939 error_sti:
19940 TRACE_IRQS_OFF
19941+ pax_force_retaddr_bts
19942 ret
19943
19944 /*
19945@@ -1600,7 +2025,7 @@ bstep_iret:
19946 movq %rcx,RIP+8(%rsp)
19947 jmp error_swapgs
19948 CFI_ENDPROC
19949-END(error_entry)
19950+ENDPROC(error_entry)
19951
19952
19953 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19954@@ -1611,7 +2036,7 @@ ENTRY(error_exit)
19955 DISABLE_INTERRUPTS(CLBR_NONE)
19956 TRACE_IRQS_OFF
19957 GET_THREAD_INFO(%rcx)
19958- testl %eax,%eax
19959+ testl $1,%eax
19960 jne retint_kernel
19961 LOCKDEP_SYS_EXIT_IRQ
19962 movl TI_flags(%rcx),%edx
19963@@ -1620,7 +2045,7 @@ ENTRY(error_exit)
19964 jnz retint_careful
19965 jmp retint_swapgs
19966 CFI_ENDPROC
19967-END(error_exit)
19968+ENDPROC(error_exit)
19969
19970 /*
19971 * Test if a given stack is an NMI stack or not.
19972@@ -1678,9 +2103,11 @@ ENTRY(nmi)
19973 * If %cs was not the kernel segment, then the NMI triggered in user
19974 * space, which means it is definitely not nested.
19975 */
19976+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19977+ je 1f
19978 cmpl $__KERNEL_CS, 16(%rsp)
19979 jne first_nmi
19980-
19981+1:
19982 /*
19983 * Check the special variable on the stack to see if NMIs are
19984 * executing.
19985@@ -1714,8 +2141,7 @@ nested_nmi:
19986
19987 1:
19988 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
19989- leaq -1*8(%rsp), %rdx
19990- movq %rdx, %rsp
19991+ subq $8, %rsp
19992 CFI_ADJUST_CFA_OFFSET 1*8
19993 leaq -10*8(%rsp), %rdx
19994 pushq_cfi $__KERNEL_DS
19995@@ -1733,6 +2159,7 @@ nested_nmi_out:
19996 CFI_RESTORE rdx
19997
19998 /* No need to check faults here */
19999+# pax_force_retaddr_bts
20000 INTERRUPT_RETURN
20001
20002 CFI_RESTORE_STATE
20003@@ -1849,6 +2276,8 @@ end_repeat_nmi:
20004 */
20005 movq %cr2, %r12
20006
20007+ pax_enter_kernel_nmi
20008+
20009 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20010 movq %rsp,%rdi
20011 movq $-1,%rsi
20012@@ -1861,26 +2290,31 @@ end_repeat_nmi:
20013 movq %r12, %cr2
20014 1:
20015
20016- testl %ebx,%ebx /* swapgs needed? */
20017+ testl $1,%ebx /* swapgs needed? */
20018 jnz nmi_restore
20019 nmi_swapgs:
20020 SWAPGS_UNSAFE_STACK
20021 nmi_restore:
20022+ pax_exit_kernel_nmi
20023 /* Pop the extra iret frame at once */
20024 RESTORE_ALL 6*8
20025+ testb $3, 8(%rsp)
20026+ jnz 1f
20027+ pax_force_retaddr_bts
20028+1:
20029
20030 /* Clear the NMI executing stack variable */
20031 movq $0, 5*8(%rsp)
20032 jmp irq_return
20033 CFI_ENDPROC
20034-END(nmi)
20035+ENDPROC(nmi)
20036
20037 ENTRY(ignore_sysret)
20038 CFI_STARTPROC
20039 mov $-ENOSYS,%eax
20040 sysret
20041 CFI_ENDPROC
20042-END(ignore_sysret)
20043+ENDPROC(ignore_sysret)
20044
20045 /*
20046 * End of kprobes section
20047diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20048index 42a392a..fbbd930 100644
20049--- a/arch/x86/kernel/ftrace.c
20050+++ b/arch/x86/kernel/ftrace.c
20051@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20052 {
20053 unsigned char replaced[MCOUNT_INSN_SIZE];
20054
20055+ ip = ktla_ktva(ip);
20056+
20057 /*
20058 * Note: Due to modules and __init, code can
20059 * disappear and change, we need to protect against faulting
20060@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20061 unsigned char old[MCOUNT_INSN_SIZE], *new;
20062 int ret;
20063
20064- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20065+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20066 new = ftrace_call_replace(ip, (unsigned long)func);
20067
20068 /* See comment above by declaration of modifying_ftrace_code */
20069@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20070 /* Also update the regs callback function */
20071 if (!ret) {
20072 ip = (unsigned long)(&ftrace_regs_call);
20073- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20074+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20075 new = ftrace_call_replace(ip, (unsigned long)func);
20076 ret = ftrace_modify_code(ip, old, new);
20077 }
20078@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20079 * kernel identity mapping to modify code.
20080 */
20081 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20082- ip = (unsigned long)__va(__pa_symbol(ip));
20083+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
20084
20085 return probe_kernel_write((void *)ip, val, size);
20086 }
20087@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20088 unsigned char replaced[MCOUNT_INSN_SIZE];
20089 unsigned char brk = BREAKPOINT_INSTRUCTION;
20090
20091- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20092+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20093 return -EFAULT;
20094
20095 /* Make sure it is what we expect it to be */
20096@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20097 return ret;
20098
20099 fail_update:
20100- probe_kernel_write((void *)ip, &old_code[0], 1);
20101+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20102 goto out;
20103 }
20104
20105@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20106 {
20107 unsigned char code[MCOUNT_INSN_SIZE];
20108
20109+ ip = ktla_ktva(ip);
20110+
20111 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20112 return -EFAULT;
20113
20114diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
20115index 55b6761..a6456fc 100644
20116--- a/arch/x86/kernel/head64.c
20117+++ b/arch/x86/kernel/head64.c
20118@@ -67,12 +67,12 @@ again:
20119 pgd = *pgd_p;
20120
20121 /*
20122- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
20123- * critical -- __PAGE_OFFSET would point us back into the dynamic
20124+ * The use of __early_va rather than __va here is critical:
20125+ * __va would point us back into the dynamic
20126 * range and we might end up looping forever...
20127 */
20128 if (pgd)
20129- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20130+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
20131 else {
20132 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20133 reset_early_page_tables();
20134@@ -82,13 +82,13 @@ again:
20135 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
20136 for (i = 0; i < PTRS_PER_PUD; i++)
20137 pud_p[i] = 0;
20138- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20139+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
20140 }
20141 pud_p += pud_index(address);
20142 pud = *pud_p;
20143
20144 if (pud)
20145- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
20146+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
20147 else {
20148 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
20149 reset_early_page_tables();
20150@@ -98,7 +98,7 @@ again:
20151 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
20152 for (i = 0; i < PTRS_PER_PMD; i++)
20153 pmd_p[i] = 0;
20154- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
20155+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
20156 }
20157 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
20158 pmd_p[pmd_index(address)] = pmd;
20159@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
20160 if (console_loglevel == 10)
20161 early_printk("Kernel alive\n");
20162
20163- clear_page(init_level4_pgt);
20164 /* set init_level4_pgt kernel high mapping*/
20165 init_level4_pgt[511] = early_level4_pgt[511];
20166
20167diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20168index 73afd11..d1670f5 100644
20169--- a/arch/x86/kernel/head_32.S
20170+++ b/arch/x86/kernel/head_32.S
20171@@ -26,6 +26,12 @@
20172 /* Physical address */
20173 #define pa(X) ((X) - __PAGE_OFFSET)
20174
20175+#ifdef CONFIG_PAX_KERNEXEC
20176+#define ta(X) (X)
20177+#else
20178+#define ta(X) ((X) - __PAGE_OFFSET)
20179+#endif
20180+
20181 /*
20182 * References to members of the new_cpu_data structure.
20183 */
20184@@ -55,11 +61,7 @@
20185 * and small than max_low_pfn, otherwise will waste some page table entries
20186 */
20187
20188-#if PTRS_PER_PMD > 1
20189-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20190-#else
20191-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20192-#endif
20193+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20194
20195 /* Number of possible pages in the lowmem region */
20196 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20197@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20198 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20199
20200 /*
20201+ * Real beginning of normal "text" segment
20202+ */
20203+ENTRY(stext)
20204+ENTRY(_stext)
20205+
20206+/*
20207 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20208 * %esi points to the real-mode code as a 32-bit pointer.
20209 * CS and DS must be 4 GB flat segments, but we don't depend on
20210@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20211 * can.
20212 */
20213 __HEAD
20214+
20215+#ifdef CONFIG_PAX_KERNEXEC
20216+ jmp startup_32
20217+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20218+.fill PAGE_SIZE-5,1,0xcc
20219+#endif
20220+
20221 ENTRY(startup_32)
20222 movl pa(stack_start),%ecx
20223
20224@@ -106,6 +121,59 @@ ENTRY(startup_32)
20225 2:
20226 leal -__PAGE_OFFSET(%ecx),%esp
20227
20228+#ifdef CONFIG_SMP
20229+ movl $pa(cpu_gdt_table),%edi
20230+ movl $__per_cpu_load,%eax
20231+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20232+ rorl $16,%eax
20233+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20234+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20235+ movl $__per_cpu_end - 1,%eax
20236+ subl $__per_cpu_start,%eax
20237+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20238+#endif
20239+
20240+#ifdef CONFIG_PAX_MEMORY_UDEREF
20241+ movl $NR_CPUS,%ecx
20242+ movl $pa(cpu_gdt_table),%edi
20243+1:
20244+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20245+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20246+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20247+ addl $PAGE_SIZE_asm,%edi
20248+ loop 1b
20249+#endif
20250+
20251+#ifdef CONFIG_PAX_KERNEXEC
20252+ movl $pa(boot_gdt),%edi
20253+ movl $__LOAD_PHYSICAL_ADDR,%eax
20254+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20255+ rorl $16,%eax
20256+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20257+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20258+ rorl $16,%eax
20259+
20260+ ljmp $(__BOOT_CS),$1f
20261+1:
20262+
20263+ movl $NR_CPUS,%ecx
20264+ movl $pa(cpu_gdt_table),%edi
20265+ addl $__PAGE_OFFSET,%eax
20266+1:
20267+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20268+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20269+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20270+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20271+ rorl $16,%eax
20272+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20273+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20274+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20275+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20276+ rorl $16,%eax
20277+ addl $PAGE_SIZE_asm,%edi
20278+ loop 1b
20279+#endif
20280+
20281 /*
20282 * Clear BSS first so that there are no surprises...
20283 */
20284@@ -201,8 +269,11 @@ ENTRY(startup_32)
20285 movl %eax, pa(max_pfn_mapped)
20286
20287 /* Do early initialization of the fixmap area */
20288- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20289- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20290+#ifdef CONFIG_COMPAT_VDSO
20291+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20292+#else
20293+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20294+#endif
20295 #else /* Not PAE */
20296
20297 page_pde_offset = (__PAGE_OFFSET >> 20);
20298@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20299 movl %eax, pa(max_pfn_mapped)
20300
20301 /* Do early initialization of the fixmap area */
20302- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20303- movl %eax,pa(initial_page_table+0xffc)
20304+#ifdef CONFIG_COMPAT_VDSO
20305+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20306+#else
20307+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20308+#endif
20309 #endif
20310
20311 #ifdef CONFIG_PARAVIRT
20312@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20313 cmpl $num_subarch_entries, %eax
20314 jae bad_subarch
20315
20316- movl pa(subarch_entries)(,%eax,4), %eax
20317- subl $__PAGE_OFFSET, %eax
20318- jmp *%eax
20319+ jmp *pa(subarch_entries)(,%eax,4)
20320
20321 bad_subarch:
20322 WEAK(lguest_entry)
20323@@ -261,10 +333,10 @@ WEAK(xen_entry)
20324 __INITDATA
20325
20326 subarch_entries:
20327- .long default_entry /* normal x86/PC */
20328- .long lguest_entry /* lguest hypervisor */
20329- .long xen_entry /* Xen hypervisor */
20330- .long default_entry /* Moorestown MID */
20331+ .long ta(default_entry) /* normal x86/PC */
20332+ .long ta(lguest_entry) /* lguest hypervisor */
20333+ .long ta(xen_entry) /* Xen hypervisor */
20334+ .long ta(default_entry) /* Moorestown MID */
20335 num_subarch_entries = (. - subarch_entries) / 4
20336 .previous
20337 #else
20338@@ -355,6 +427,7 @@ default_entry:
20339 movl pa(mmu_cr4_features),%eax
20340 movl %eax,%cr4
20341
20342+#ifdef CONFIG_X86_PAE
20343 testb $X86_CR4_PAE, %al # check if PAE is enabled
20344 jz enable_paging
20345
20346@@ -383,6 +456,9 @@ default_entry:
20347 /* Make changes effective */
20348 wrmsr
20349
20350+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20351+#endif
20352+
20353 enable_paging:
20354
20355 /*
20356@@ -451,14 +527,20 @@ is486:
20357 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20358 movl %eax,%ss # after changing gdt.
20359
20360- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20361+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20362 movl %eax,%ds
20363 movl %eax,%es
20364
20365 movl $(__KERNEL_PERCPU), %eax
20366 movl %eax,%fs # set this cpu's percpu
20367
20368+#ifdef CONFIG_CC_STACKPROTECTOR
20369 movl $(__KERNEL_STACK_CANARY),%eax
20370+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20371+ movl $(__USER_DS),%eax
20372+#else
20373+ xorl %eax,%eax
20374+#endif
20375 movl %eax,%gs
20376
20377 xorl %eax,%eax # Clear LDT
20378@@ -534,8 +616,11 @@ setup_once:
20379 * relocation. Manually set base address in stack canary
20380 * segment descriptor.
20381 */
20382- movl $gdt_page,%eax
20383+ movl $cpu_gdt_table,%eax
20384 movl $stack_canary,%ecx
20385+#ifdef CONFIG_SMP
20386+ addl $__per_cpu_load,%ecx
20387+#endif
20388 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20389 shrl $16, %ecx
20390 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20391@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
20392 /* This is global to keep gas from relaxing the jumps */
20393 ENTRY(early_idt_handler)
20394 cld
20395- cmpl $2,%ss:early_recursion_flag
20396+ cmpl $1,%ss:early_recursion_flag
20397 je hlt_loop
20398 incl %ss:early_recursion_flag
20399
20400@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
20401 pushl (20+6*4)(%esp) /* trapno */
20402 pushl $fault_msg
20403 call printk
20404-#endif
20405 call dump_stack
20406+#endif
20407 hlt_loop:
20408 hlt
20409 jmp hlt_loop
20410@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
20411 /* This is the default interrupt "handler" :-) */
20412 ALIGN
20413 ignore_int:
20414- cld
20415 #ifdef CONFIG_PRINTK
20416+ cmpl $2,%ss:early_recursion_flag
20417+ je hlt_loop
20418+ incl %ss:early_recursion_flag
20419+ cld
20420 pushl %eax
20421 pushl %ecx
20422 pushl %edx
20423@@ -634,9 +722,6 @@ ignore_int:
20424 movl $(__KERNEL_DS),%eax
20425 movl %eax,%ds
20426 movl %eax,%es
20427- cmpl $2,early_recursion_flag
20428- je hlt_loop
20429- incl early_recursion_flag
20430 pushl 16(%esp)
20431 pushl 24(%esp)
20432 pushl 32(%esp)
20433@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
20434 /*
20435 * BSS section
20436 */
20437-__PAGE_ALIGNED_BSS
20438- .align PAGE_SIZE
20439 #ifdef CONFIG_X86_PAE
20440+.section .initial_pg_pmd,"a",@progbits
20441 initial_pg_pmd:
20442 .fill 1024*KPMDS,4,0
20443 #else
20444+.section .initial_page_table,"a",@progbits
20445 ENTRY(initial_page_table)
20446 .fill 1024,4,0
20447 #endif
20448+.section .initial_pg_fixmap,"a",@progbits
20449 initial_pg_fixmap:
20450 .fill 1024,4,0
20451+.section .empty_zero_page,"a",@progbits
20452 ENTRY(empty_zero_page)
20453 .fill 4096,1,0
20454+.section .swapper_pg_dir,"a",@progbits
20455 ENTRY(swapper_pg_dir)
20456+#ifdef CONFIG_X86_PAE
20457+ .fill 4,8,0
20458+#else
20459 .fill 1024,4,0
20460+#endif
20461+
20462+/*
20463+ * The IDT has to be page-aligned to simplify the Pentium
20464+ * F0 0F bug workaround.. We have a special link segment
20465+ * for this.
20466+ */
20467+.section .idt,"a",@progbits
20468+ENTRY(idt_table)
20469+ .fill 256,8,0
20470
20471 /*
20472 * This starts the data section.
20473 */
20474 #ifdef CONFIG_X86_PAE
20475-__PAGE_ALIGNED_DATA
20476- /* Page-aligned for the benefit of paravirt? */
20477- .align PAGE_SIZE
20478+.section .initial_page_table,"a",@progbits
20479 ENTRY(initial_page_table)
20480 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20481 # if KPMDS == 3
20482@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
20483 # error "Kernel PMDs should be 1, 2 or 3"
20484 # endif
20485 .align PAGE_SIZE /* needs to be page-sized too */
20486+
20487+#ifdef CONFIG_PAX_PER_CPU_PGD
20488+ENTRY(cpu_pgd)
20489+ .rept NR_CPUS
20490+ .fill 4,8,0
20491+ .endr
20492+#endif
20493+
20494 #endif
20495
20496 .data
20497 .balign 4
20498 ENTRY(stack_start)
20499- .long init_thread_union+THREAD_SIZE
20500+ .long init_thread_union+THREAD_SIZE-8
20501
20502 __INITRODATA
20503 int_msg:
20504@@ -744,7 +851,7 @@ fault_msg:
20505 * segment size, and 32-bit linear address value:
20506 */
20507
20508- .data
20509+.section .rodata,"a",@progbits
20510 .globl boot_gdt_descr
20511 .globl idt_descr
20512
20513@@ -753,7 +860,7 @@ fault_msg:
20514 .word 0 # 32 bit align gdt_desc.address
20515 boot_gdt_descr:
20516 .word __BOOT_DS+7
20517- .long boot_gdt - __PAGE_OFFSET
20518+ .long pa(boot_gdt)
20519
20520 .word 0 # 32-bit align idt_desc.address
20521 idt_descr:
20522@@ -764,7 +871,7 @@ idt_descr:
20523 .word 0 # 32 bit align gdt_desc.address
20524 ENTRY(early_gdt_descr)
20525 .word GDT_ENTRIES*8-1
20526- .long gdt_page /* Overwritten for secondary CPUs */
20527+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20528
20529 /*
20530 * The boot_gdt must mirror the equivalent in setup.S and is
20531@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
20532 .align L1_CACHE_BYTES
20533 ENTRY(boot_gdt)
20534 .fill GDT_ENTRY_BOOT_CS,8,0
20535- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20536- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20537+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20538+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20539+
20540+ .align PAGE_SIZE_asm
20541+ENTRY(cpu_gdt_table)
20542+ .rept NR_CPUS
20543+ .quad 0x0000000000000000 /* NULL descriptor */
20544+ .quad 0x0000000000000000 /* 0x0b reserved */
20545+ .quad 0x0000000000000000 /* 0x13 reserved */
20546+ .quad 0x0000000000000000 /* 0x1b reserved */
20547+
20548+#ifdef CONFIG_PAX_KERNEXEC
20549+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20550+#else
20551+ .quad 0x0000000000000000 /* 0x20 unused */
20552+#endif
20553+
20554+ .quad 0x0000000000000000 /* 0x28 unused */
20555+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20556+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20557+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20558+ .quad 0x0000000000000000 /* 0x4b reserved */
20559+ .quad 0x0000000000000000 /* 0x53 reserved */
20560+ .quad 0x0000000000000000 /* 0x5b reserved */
20561+
20562+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20563+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20564+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20565+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20566+
20567+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20568+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20569+
20570+ /*
20571+ * Segments used for calling PnP BIOS have byte granularity.
20572+ * The code segments and data segments have fixed 64k limits,
20573+ * the transfer segment sizes are set at run time.
20574+ */
20575+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20576+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20577+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20578+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20579+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20580+
20581+ /*
20582+ * The APM segments have byte granularity and their bases
20583+ * are set at run time. All have 64k limits.
20584+ */
20585+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20586+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20587+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20588+
20589+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20590+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20591+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20592+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20593+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20594+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20595+
20596+ /* Be sure this is zeroed to avoid false validations in Xen */
20597+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20598+ .endr
20599diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20600index 321d65e..863089b 100644
20601--- a/arch/x86/kernel/head_64.S
20602+++ b/arch/x86/kernel/head_64.S
20603@@ -20,6 +20,8 @@
20604 #include <asm/processor-flags.h>
20605 #include <asm/percpu.h>
20606 #include <asm/nops.h>
20607+#include <asm/cpufeature.h>
20608+#include <asm/alternative-asm.h>
20609
20610 #ifdef CONFIG_PARAVIRT
20611 #include <asm/asm-offsets.h>
20612@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20613 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20614 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20615 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20616+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20617+L3_VMALLOC_START = pud_index(VMALLOC_START)
20618+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20619+L3_VMALLOC_END = pud_index(VMALLOC_END)
20620+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20621+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20622
20623 .text
20624 __HEAD
20625@@ -89,11 +97,23 @@ startup_64:
20626 * Fixup the physical addresses in the page table
20627 */
20628 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
20629+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20630+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20631+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20632+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20633+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20634
20635- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20636- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20637+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
20638+#ifndef CONFIG_XEN
20639+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
20640+#endif
20641
20642- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20643+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20644+
20645+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20646+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
20647+
20648+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20649
20650 /*
20651 * Set up the identity mapping for the switchover. These
20652@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
20653 movq $(init_level4_pgt - __START_KERNEL_map), %rax
20654 1:
20655
20656- /* Enable PAE mode and PGE */
20657- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
20658+ /* Enable PAE mode and PSE/PGE */
20659+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
20660 movq %rcx, %cr4
20661
20662 /* Setup early boot stage 4 level pagetables. */
20663@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
20664 movl $MSR_EFER, %ecx
20665 rdmsr
20666 btsl $_EFER_SCE, %eax /* Enable System Call */
20667- btl $20,%edi /* No Execute supported? */
20668+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20669 jnc 1f
20670 btsl $_EFER_NX, %eax
20671 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
20672+ leaq init_level4_pgt(%rip), %rdi
20673+#ifndef CONFIG_EFI
20674+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20675+#endif
20676+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20677+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20678+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20679+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20680 1: wrmsr /* Make changes effective */
20681
20682 /* Setup cr0 */
20683@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
20684 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
20685 * address given in m16:64.
20686 */
20687+ pax_set_fptr_mask
20688 movq initial_code(%rip),%rax
20689 pushq $0 # fake return address to stop unwinder
20690 pushq $__KERNEL_CS # set correct cs
20691@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
20692 call dump_stack
20693 #ifdef CONFIG_KALLSYMS
20694 leaq early_idt_ripmsg(%rip),%rdi
20695- movq 40(%rsp),%rsi # %rip again
20696+ movq 88(%rsp),%rsi # %rip again
20697 call __print_symbol
20698 #endif
20699 #endif /* EARLY_PRINTK */
20700@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
20701 early_recursion_flag:
20702 .long 0
20703
20704+ .section .rodata,"a",@progbits
20705 #ifdef CONFIG_EARLY_PRINTK
20706 early_idt_msg:
20707 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20708@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
20709 NEXT_PAGE(early_dynamic_pgts)
20710 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
20711
20712- .data
20713+ .section .rodata,"a",@progbits
20714
20715-#ifndef CONFIG_XEN
20716 NEXT_PAGE(init_level4_pgt)
20717- .fill 512,8,0
20718-#else
20719-NEXT_PAGE(init_level4_pgt)
20720- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20721 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20722 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20723+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20724+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20725+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20726+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20727+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20728+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20729 .org init_level4_pgt + L4_START_KERNEL*8, 0
20730 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20731 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20732
20733+#ifdef CONFIG_PAX_PER_CPU_PGD
20734+NEXT_PAGE(cpu_pgd)
20735+ .rept NR_CPUS
20736+ .fill 512,8,0
20737+ .endr
20738+#endif
20739+
20740 NEXT_PAGE(level3_ident_pgt)
20741 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20742+#ifdef CONFIG_XEN
20743 .fill 511, 8, 0
20744+#else
20745+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20746+ .fill 510,8,0
20747+#endif
20748+
20749+NEXT_PAGE(level3_vmalloc_start_pgt)
20750+ .fill 512,8,0
20751+
20752+NEXT_PAGE(level3_vmalloc_end_pgt)
20753+ .fill 512,8,0
20754+
20755+NEXT_PAGE(level3_vmemmap_pgt)
20756+ .fill L3_VMEMMAP_START,8,0
20757+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20758+
20759 NEXT_PAGE(level2_ident_pgt)
20760- /* Since I easily can, map the first 1G.
20761+ /* Since I easily can, map the first 2G.
20762 * Don't set NX because code runs from these pages.
20763 */
20764- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20765-#endif
20766+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20767
20768 NEXT_PAGE(level3_kernel_pgt)
20769 .fill L3_START_KERNEL,8,0
20770@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
20771 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20772 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20773
20774+NEXT_PAGE(level2_vmemmap_pgt)
20775+ .fill 512,8,0
20776+
20777 NEXT_PAGE(level2_kernel_pgt)
20778 /*
20779 * 512 MB kernel mapping. We spend a full page on this pagetable
20780@@ -488,39 +544,64 @@ NEXT_PAGE(level2_kernel_pgt)
20781 KERNEL_IMAGE_SIZE/PMD_SIZE)
20782
20783 NEXT_PAGE(level2_fixmap_pgt)
20784- .fill 506,8,0
20785- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20786- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20787- .fill 5,8,0
20788+ .fill 507,8,0
20789+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20790+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20791+ .fill 4,8,0
20792
20793-NEXT_PAGE(level1_fixmap_pgt)
20794+NEXT_PAGE(level1_vsyscall_pgt)
20795 .fill 512,8,0
20796
20797 #undef PMDS
20798
20799- .data
20800+ .align PAGE_SIZE
20801+ENTRY(cpu_gdt_table)
20802+ .rept NR_CPUS
20803+ .quad 0x0000000000000000 /* NULL descriptor */
20804+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20805+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20806+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20807+ .quad 0x00cffb000000ffff /* __USER32_CS */
20808+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20809+ .quad 0x00affb000000ffff /* __USER_CS */
20810+
20811+#ifdef CONFIG_PAX_KERNEXEC
20812+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20813+#else
20814+ .quad 0x0 /* unused */
20815+#endif
20816+
20817+ .quad 0,0 /* TSS */
20818+ .quad 0,0 /* LDT */
20819+ .quad 0,0,0 /* three TLS descriptors */
20820+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20821+ /* asm/segment.h:GDT_ENTRIES must match this */
20822+
20823+ /* zero the remaining page */
20824+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20825+ .endr
20826+
20827 .align 16
20828 .globl early_gdt_descr
20829 early_gdt_descr:
20830 .word GDT_ENTRIES*8-1
20831 early_gdt_descr_base:
20832- .quad INIT_PER_CPU_VAR(gdt_page)
20833+ .quad cpu_gdt_table
20834
20835 ENTRY(phys_base)
20836 /* This must match the first entry in level2_kernel_pgt */
20837 .quad 0x0000000000000000
20838
20839 #include "../../x86/xen/xen-head.S"
20840-
20841- .section .bss, "aw", @nobits
20842- .align L1_CACHE_BYTES
20843-ENTRY(idt_table)
20844- .skip IDT_ENTRIES * 16
20845
20846- .align L1_CACHE_BYTES
20847-ENTRY(nmi_idt_table)
20848- .skip IDT_ENTRIES * 16
20849-
20850- __PAGE_ALIGNED_BSS
20851+ .section .rodata,"a",@progbits
20852 NEXT_PAGE(empty_zero_page)
20853 .skip PAGE_SIZE
20854+
20855+ .align L1_CACHE_BYTES
20856+ENTRY(idt_table)
20857+ .fill 512,8,0
20858+
20859+ .align L1_CACHE_BYTES
20860+ENTRY(nmi_idt_table)
20861+ .fill 512,8,0
20862diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20863index 0fa6912..37fce70 100644
20864--- a/arch/x86/kernel/i386_ksyms_32.c
20865+++ b/arch/x86/kernel/i386_ksyms_32.c
20866@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20867 EXPORT_SYMBOL(cmpxchg8b_emu);
20868 #endif
20869
20870+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20871+
20872 /* Networking helper routines. */
20873 EXPORT_SYMBOL(csum_partial_copy_generic);
20874+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20875+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20876
20877 EXPORT_SYMBOL(__get_user_1);
20878 EXPORT_SYMBOL(__get_user_2);
20879@@ -37,3 +41,7 @@ EXPORT_SYMBOL(strstr);
20880
20881 EXPORT_SYMBOL(csum_partial);
20882 EXPORT_SYMBOL(empty_zero_page);
20883+
20884+#ifdef CONFIG_PAX_KERNEXEC
20885+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20886+#endif
20887diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20888index cb33909..1163b40 100644
20889--- a/arch/x86/kernel/i387.c
20890+++ b/arch/x86/kernel/i387.c
20891@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20892 static inline bool interrupted_user_mode(void)
20893 {
20894 struct pt_regs *regs = get_irq_regs();
20895- return regs && user_mode_vm(regs);
20896+ return regs && user_mode(regs);
20897 }
20898
20899 /*
20900diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20901index 9a5c460..84868423 100644
20902--- a/arch/x86/kernel/i8259.c
20903+++ b/arch/x86/kernel/i8259.c
20904@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
20905 static void make_8259A_irq(unsigned int irq)
20906 {
20907 disable_irq_nosync(irq);
20908- io_apic_irqs &= ~(1<<irq);
20909+ io_apic_irqs &= ~(1UL<<irq);
20910 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
20911 i8259A_chip.name);
20912 enable_irq(irq);
20913@@ -209,7 +209,7 @@ spurious_8259A_irq:
20914 "spurious 8259A interrupt: IRQ%d.\n", irq);
20915 spurious_irq_mask |= irqmask;
20916 }
20917- atomic_inc(&irq_err_count);
20918+ atomic_inc_unchecked(&irq_err_count);
20919 /*
20920 * Theoretically we do not have to handle this IRQ,
20921 * but in Linux this does not cause problems and is
20922@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20923 /* (slave's support for AEOI in flat mode is to be investigated) */
20924 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20925
20926+ pax_open_kernel();
20927 if (auto_eoi)
20928 /*
20929 * In AEOI mode we just have to mask the interrupt
20930 * when acking.
20931 */
20932- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20933+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20934 else
20935- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20936+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20937+ pax_close_kernel();
20938
20939 udelay(100); /* wait for 8259A to initialize */
20940
20941diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20942index a979b5b..1d6db75 100644
20943--- a/arch/x86/kernel/io_delay.c
20944+++ b/arch/x86/kernel/io_delay.c
20945@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20946 * Quirk table for systems that misbehave (lock up, etc.) if port
20947 * 0x80 is used:
20948 */
20949-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20950+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20951 {
20952 .callback = dmi_io_delay_0xed_port,
20953 .ident = "Compaq Presario V6000",
20954diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20955index 4ddaf66..6292f4e 100644
20956--- a/arch/x86/kernel/ioport.c
20957+++ b/arch/x86/kernel/ioport.c
20958@@ -6,6 +6,7 @@
20959 #include <linux/sched.h>
20960 #include <linux/kernel.h>
20961 #include <linux/capability.h>
20962+#include <linux/security.h>
20963 #include <linux/errno.h>
20964 #include <linux/types.h>
20965 #include <linux/ioport.h>
20966@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20967
20968 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20969 return -EINVAL;
20970+#ifdef CONFIG_GRKERNSEC_IO
20971+ if (turn_on && grsec_disable_privio) {
20972+ gr_handle_ioperm();
20973+ return -EPERM;
20974+ }
20975+#endif
20976 if (turn_on && !capable(CAP_SYS_RAWIO))
20977 return -EPERM;
20978
20979@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20980 * because the ->io_bitmap_max value must match the bitmap
20981 * contents:
20982 */
20983- tss = &per_cpu(init_tss, get_cpu());
20984+ tss = init_tss + get_cpu();
20985
20986 if (turn_on)
20987 bitmap_clear(t->io_bitmap_ptr, from, num);
20988@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
20989 return -EINVAL;
20990 /* Trying to gain more privileges? */
20991 if (level > old) {
20992+#ifdef CONFIG_GRKERNSEC_IO
20993+ if (grsec_disable_privio) {
20994+ gr_handle_iopl();
20995+ return -EPERM;
20996+ }
20997+#endif
20998 if (!capable(CAP_SYS_RAWIO))
20999 return -EPERM;
21000 }
21001diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
21002index ac0631d..ff7cb62 100644
21003--- a/arch/x86/kernel/irq.c
21004+++ b/arch/x86/kernel/irq.c
21005@@ -18,7 +18,7 @@
21006 #include <asm/mce.h>
21007 #include <asm/hw_irq.h>
21008
21009-atomic_t irq_err_count;
21010+atomic_unchecked_t irq_err_count;
21011
21012 /* Function pointer for generic interrupt vector handling */
21013 void (*x86_platform_ipi_callback)(void) = NULL;
21014@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
21015 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
21016 seq_printf(p, " Machine check polls\n");
21017 #endif
21018- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
21019+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
21020 #if defined(CONFIG_X86_IO_APIC)
21021- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
21022+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
21023 #endif
21024 return 0;
21025 }
21026@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
21027
21028 u64 arch_irq_stat(void)
21029 {
21030- u64 sum = atomic_read(&irq_err_count);
21031+ u64 sum = atomic_read_unchecked(&irq_err_count);
21032 return sum;
21033 }
21034
21035diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
21036index 344faf8..355f60d 100644
21037--- a/arch/x86/kernel/irq_32.c
21038+++ b/arch/x86/kernel/irq_32.c
21039@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
21040 __asm__ __volatile__("andl %%esp,%0" :
21041 "=r" (sp) : "0" (THREAD_SIZE - 1));
21042
21043- return sp < (sizeof(struct thread_info) + STACK_WARN);
21044+ return sp < STACK_WARN;
21045 }
21046
21047 static void print_stack_overflow(void)
21048@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
21049 * per-CPU IRQ handling contexts (thread information and stack)
21050 */
21051 union irq_ctx {
21052- struct thread_info tinfo;
21053- u32 stack[THREAD_SIZE/sizeof(u32)];
21054+ unsigned long previous_esp;
21055+ u32 stack[THREAD_SIZE/sizeof(u32)];
21056 } __attribute__((aligned(THREAD_SIZE)));
21057
21058 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21059@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21060 static inline int
21061 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21062 {
21063- union irq_ctx *curctx, *irqctx;
21064+ union irq_ctx *irqctx;
21065 u32 *isp, arg1, arg2;
21066
21067- curctx = (union irq_ctx *) current_thread_info();
21068 irqctx = __this_cpu_read(hardirq_ctx);
21069
21070 /*
21071@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21072 * handler) we can't do that and just have to keep using the
21073 * current stack (which is the irq stack already after all)
21074 */
21075- if (unlikely(curctx == irqctx))
21076+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21077 return 0;
21078
21079 /* build the stack frame on the IRQ stack */
21080- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21081- irqctx->tinfo.task = curctx->tinfo.task;
21082- irqctx->tinfo.previous_esp = current_stack_pointer;
21083+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21084+ irqctx->previous_esp = current_stack_pointer;
21085
21086- /* Copy the preempt_count so that the [soft]irq checks work. */
21087- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21088+#ifdef CONFIG_PAX_MEMORY_UDEREF
21089+ __set_fs(MAKE_MM_SEG(0));
21090+#endif
21091
21092 if (unlikely(overflow))
21093 call_on_stack(print_stack_overflow, isp);
21094@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21095 : "0" (irq), "1" (desc), "2" (isp),
21096 "D" (desc->handle_irq)
21097 : "memory", "cc", "ecx");
21098+
21099+#ifdef CONFIG_PAX_MEMORY_UDEREF
21100+ __set_fs(current_thread_info()->addr_limit);
21101+#endif
21102+
21103 return 1;
21104 }
21105
21106@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21107 */
21108 void __cpuinit irq_ctx_init(int cpu)
21109 {
21110- union irq_ctx *irqctx;
21111-
21112 if (per_cpu(hardirq_ctx, cpu))
21113 return;
21114
21115- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21116- THREADINFO_GFP,
21117- THREAD_SIZE_ORDER));
21118- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21119- irqctx->tinfo.cpu = cpu;
21120- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21121- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21122-
21123- per_cpu(hardirq_ctx, cpu) = irqctx;
21124-
21125- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21126- THREADINFO_GFP,
21127- THREAD_SIZE_ORDER));
21128- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21129- irqctx->tinfo.cpu = cpu;
21130- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21131-
21132- per_cpu(softirq_ctx, cpu) = irqctx;
21133+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21134+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21135+
21136+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21137+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21138
21139 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21140 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21141@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21142 asmlinkage void do_softirq(void)
21143 {
21144 unsigned long flags;
21145- struct thread_info *curctx;
21146 union irq_ctx *irqctx;
21147 u32 *isp;
21148
21149@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21150 local_irq_save(flags);
21151
21152 if (local_softirq_pending()) {
21153- curctx = current_thread_info();
21154 irqctx = __this_cpu_read(softirq_ctx);
21155- irqctx->tinfo.task = curctx->task;
21156- irqctx->tinfo.previous_esp = current_stack_pointer;
21157+ irqctx->previous_esp = current_stack_pointer;
21158
21159 /* build the stack frame on the softirq stack */
21160- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21161+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21162+
21163+#ifdef CONFIG_PAX_MEMORY_UDEREF
21164+ __set_fs(MAKE_MM_SEG(0));
21165+#endif
21166
21167 call_on_stack(__do_softirq, isp);
21168+
21169+#ifdef CONFIG_PAX_MEMORY_UDEREF
21170+ __set_fs(current_thread_info()->addr_limit);
21171+#endif
21172+
21173 /*
21174 * Shouldn't happen, we returned above if in_interrupt():
21175 */
21176@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21177 if (unlikely(!desc))
21178 return false;
21179
21180- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21181+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21182 if (unlikely(overflow))
21183 print_stack_overflow();
21184 desc->handle_irq(irq, desc);
21185diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21186index d04d3ec..ea4b374 100644
21187--- a/arch/x86/kernel/irq_64.c
21188+++ b/arch/x86/kernel/irq_64.c
21189@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21190 u64 estack_top, estack_bottom;
21191 u64 curbase = (u64)task_stack_page(current);
21192
21193- if (user_mode_vm(regs))
21194+ if (user_mode(regs))
21195 return;
21196
21197 if (regs->sp >= curbase + sizeof(struct thread_info) +
21198diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21199index dc1404b..bbc43e7 100644
21200--- a/arch/x86/kernel/kdebugfs.c
21201+++ b/arch/x86/kernel/kdebugfs.c
21202@@ -27,7 +27,7 @@ struct setup_data_node {
21203 u32 len;
21204 };
21205
21206-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21207+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21208 size_t count, loff_t *ppos)
21209 {
21210 struct setup_data_node *node = file->private_data;
21211diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21212index 836f832..a8bda67 100644
21213--- a/arch/x86/kernel/kgdb.c
21214+++ b/arch/x86/kernel/kgdb.c
21215@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21216 #ifdef CONFIG_X86_32
21217 switch (regno) {
21218 case GDB_SS:
21219- if (!user_mode_vm(regs))
21220+ if (!user_mode(regs))
21221 *(unsigned long *)mem = __KERNEL_DS;
21222 break;
21223 case GDB_SP:
21224- if (!user_mode_vm(regs))
21225+ if (!user_mode(regs))
21226 *(unsigned long *)mem = kernel_stack_pointer(regs);
21227 break;
21228 case GDB_GS:
21229@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21230 bp->attr.bp_addr = breakinfo[breakno].addr;
21231 bp->attr.bp_len = breakinfo[breakno].len;
21232 bp->attr.bp_type = breakinfo[breakno].type;
21233- info->address = breakinfo[breakno].addr;
21234+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21235+ info->address = ktla_ktva(breakinfo[breakno].addr);
21236+ else
21237+ info->address = breakinfo[breakno].addr;
21238 info->len = breakinfo[breakno].len;
21239 info->type = breakinfo[breakno].type;
21240 val = arch_install_hw_breakpoint(bp);
21241@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21242 case 'k':
21243 /* clear the trace bit */
21244 linux_regs->flags &= ~X86_EFLAGS_TF;
21245- atomic_set(&kgdb_cpu_doing_single_step, -1);
21246+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21247
21248 /* set the trace bit if we're stepping */
21249 if (remcomInBuffer[0] == 's') {
21250 linux_regs->flags |= X86_EFLAGS_TF;
21251- atomic_set(&kgdb_cpu_doing_single_step,
21252+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21253 raw_smp_processor_id());
21254 }
21255
21256@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21257
21258 switch (cmd) {
21259 case DIE_DEBUG:
21260- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21261+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21262 if (user_mode(regs))
21263 return single_step_cont(regs, args);
21264 break;
21265@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21266 #endif /* CONFIG_DEBUG_RODATA */
21267
21268 bpt->type = BP_BREAKPOINT;
21269- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21270+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21271 BREAK_INSTR_SIZE);
21272 if (err)
21273 return err;
21274- err = probe_kernel_write((char *)bpt->bpt_addr,
21275+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21276 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21277 #ifdef CONFIG_DEBUG_RODATA
21278 if (!err)
21279@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21280 return -EBUSY;
21281 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21282 BREAK_INSTR_SIZE);
21283- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21284+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21285 if (err)
21286 return err;
21287 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21288@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21289 if (mutex_is_locked(&text_mutex))
21290 goto knl_write;
21291 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21292- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21293+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21294 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21295 goto knl_write;
21296 return err;
21297 knl_write:
21298 #endif /* CONFIG_DEBUG_RODATA */
21299- return probe_kernel_write((char *)bpt->bpt_addr,
21300+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21301 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21302 }
21303
21304diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
21305index 211bce4..6e2580a 100644
21306--- a/arch/x86/kernel/kprobes/core.c
21307+++ b/arch/x86/kernel/kprobes/core.c
21308@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21309 s32 raddr;
21310 } __packed *insn;
21311
21312- insn = (struct __arch_relative_insn *)from;
21313+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21314+
21315+ pax_open_kernel();
21316 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21317 insn->op = op;
21318+ pax_close_kernel();
21319 }
21320
21321 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21322@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21323 kprobe_opcode_t opcode;
21324 kprobe_opcode_t *orig_opcodes = opcodes;
21325
21326- if (search_exception_tables((unsigned long)opcodes))
21327+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21328 return 0; /* Page fault may occur on this address. */
21329
21330 retry:
21331@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21332 * for the first byte, we can recover the original instruction
21333 * from it and kp->opcode.
21334 */
21335- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21336+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21337 buf[0] = kp->opcode;
21338- return (unsigned long)buf;
21339+ return ktva_ktla((unsigned long)buf);
21340 }
21341
21342 /*
21343@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21344 /* Another subsystem puts a breakpoint, failed to recover */
21345 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21346 return 0;
21347+ pax_open_kernel();
21348 memcpy(dest, insn.kaddr, insn.length);
21349+ pax_close_kernel();
21350
21351 #ifdef CONFIG_X86_64
21352 if (insn_rip_relative(&insn)) {
21353@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21354 return 0;
21355 }
21356 disp = (u8 *) dest + insn_offset_displacement(&insn);
21357+ pax_open_kernel();
21358 *(s32 *) disp = (s32) newdisp;
21359+ pax_close_kernel();
21360 }
21361 #endif
21362 return insn.length;
21363@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21364 * nor set current_kprobe, because it doesn't use single
21365 * stepping.
21366 */
21367- regs->ip = (unsigned long)p->ainsn.insn;
21368+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21369 preempt_enable_no_resched();
21370 return;
21371 }
21372@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21373 regs->flags &= ~X86_EFLAGS_IF;
21374 /* single step inline if the instruction is an int3 */
21375 if (p->opcode == BREAKPOINT_INSTRUCTION)
21376- regs->ip = (unsigned long)p->addr;
21377+ regs->ip = ktla_ktva((unsigned long)p->addr);
21378 else
21379- regs->ip = (unsigned long)p->ainsn.insn;
21380+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21381 }
21382
21383 /*
21384@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21385 setup_singlestep(p, regs, kcb, 0);
21386 return 1;
21387 }
21388- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21389+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21390 /*
21391 * The breakpoint instruction was removed right
21392 * after we hit it. Another cpu has removed
21393@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21394 " movq %rax, 152(%rsp)\n"
21395 RESTORE_REGS_STRING
21396 " popfq\n"
21397+#ifdef KERNEXEC_PLUGIN
21398+ " btsq $63,(%rsp)\n"
21399+#endif
21400 #else
21401 " pushf\n"
21402 SAVE_REGS_STRING
21403@@ -779,7 +789,7 @@ static void __kprobes
21404 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21405 {
21406 unsigned long *tos = stack_addr(regs);
21407- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21408+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21409 unsigned long orig_ip = (unsigned long)p->addr;
21410 kprobe_opcode_t *insn = p->ainsn.insn;
21411
21412@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21413 struct die_args *args = data;
21414 int ret = NOTIFY_DONE;
21415
21416- if (args->regs && user_mode_vm(args->regs))
21417+ if (args->regs && user_mode(args->regs))
21418 return ret;
21419
21420 switch (val) {
21421diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
21422index 76dc6f0..66bdfc3 100644
21423--- a/arch/x86/kernel/kprobes/opt.c
21424+++ b/arch/x86/kernel/kprobes/opt.c
21425@@ -79,6 +79,7 @@ found:
21426 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
21427 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
21428 {
21429+ pax_open_kernel();
21430 #ifdef CONFIG_X86_64
21431 *addr++ = 0x48;
21432 *addr++ = 0xbf;
21433@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
21434 *addr++ = 0xb8;
21435 #endif
21436 *(unsigned long *)addr = val;
21437+ pax_close_kernel();
21438 }
21439
21440 static void __used __kprobes kprobes_optinsn_template_holder(void)
21441@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21442 * Verify if the address gap is in 2GB range, because this uses
21443 * a relative jump.
21444 */
21445- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21446+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21447 if (abs(rel) > 0x7fffffff)
21448 return -ERANGE;
21449
21450@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21451 op->optinsn.size = ret;
21452
21453 /* Copy arch-dep-instance from template */
21454- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21455+ pax_open_kernel();
21456+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21457+ pax_close_kernel();
21458
21459 /* Set probe information */
21460 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21461
21462 /* Set probe function call */
21463- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21464+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21465
21466 /* Set returning jmp instruction at the tail of out-of-line buffer */
21467- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21468+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21469 (u8 *)op->kp.addr + op->optinsn.size);
21470
21471 flush_icache_range((unsigned long) buf,
21472@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21473 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21474
21475 /* Backup instructions which will be replaced by jump address */
21476- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21477+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21478 RELATIVE_ADDR_SIZE);
21479
21480 insn_buf[0] = RELATIVEJUMP_OPCODE;
21481@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21482 /* This kprobe is really able to run optimized path. */
21483 op = container_of(p, struct optimized_kprobe, kp);
21484 /* Detour through copied instructions */
21485- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21486+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21487 if (!reenter)
21488 reset_current_kprobe();
21489 preempt_enable_no_resched();
21490diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21491index cd6d9a5..16245a4 100644
21492--- a/arch/x86/kernel/kvm.c
21493+++ b/arch/x86/kernel/kvm.c
21494@@ -455,7 +455,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21495 return NOTIFY_OK;
21496 }
21497
21498-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21499+static struct notifier_block kvm_cpu_notifier = {
21500 .notifier_call = kvm_cpu_notify,
21501 };
21502 #endif
21503diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21504index ebc9873..1b9724b 100644
21505--- a/arch/x86/kernel/ldt.c
21506+++ b/arch/x86/kernel/ldt.c
21507@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21508 if (reload) {
21509 #ifdef CONFIG_SMP
21510 preempt_disable();
21511- load_LDT(pc);
21512+ load_LDT_nolock(pc);
21513 if (!cpumask_equal(mm_cpumask(current->mm),
21514 cpumask_of(smp_processor_id())))
21515 smp_call_function(flush_ldt, current->mm, 1);
21516 preempt_enable();
21517 #else
21518- load_LDT(pc);
21519+ load_LDT_nolock(pc);
21520 #endif
21521 }
21522 if (oldsize) {
21523@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21524 return err;
21525
21526 for (i = 0; i < old->size; i++)
21527- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21528+ write_ldt_entry(new->ldt, i, old->ldt + i);
21529 return 0;
21530 }
21531
21532@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21533 retval = copy_ldt(&mm->context, &old_mm->context);
21534 mutex_unlock(&old_mm->context.lock);
21535 }
21536+
21537+ if (tsk == current) {
21538+ mm->context.vdso = 0;
21539+
21540+#ifdef CONFIG_X86_32
21541+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21542+ mm->context.user_cs_base = 0UL;
21543+ mm->context.user_cs_limit = ~0UL;
21544+
21545+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21546+ cpus_clear(mm->context.cpu_user_cs_mask);
21547+#endif
21548+
21549+#endif
21550+#endif
21551+
21552+ }
21553+
21554 return retval;
21555 }
21556
21557@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21558 }
21559 }
21560
21561+#ifdef CONFIG_PAX_SEGMEXEC
21562+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21563+ error = -EINVAL;
21564+ goto out_unlock;
21565+ }
21566+#endif
21567+
21568 fill_ldt(&ldt, &ldt_info);
21569 if (oldmode)
21570 ldt.avl = 0;
21571diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21572index 5b19e4d..6476a76 100644
21573--- a/arch/x86/kernel/machine_kexec_32.c
21574+++ b/arch/x86/kernel/machine_kexec_32.c
21575@@ -26,7 +26,7 @@
21576 #include <asm/cacheflush.h>
21577 #include <asm/debugreg.h>
21578
21579-static void set_idt(void *newidt, __u16 limit)
21580+static void set_idt(struct desc_struct *newidt, __u16 limit)
21581 {
21582 struct desc_ptr curidt;
21583
21584@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21585 }
21586
21587
21588-static void set_gdt(void *newgdt, __u16 limit)
21589+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21590 {
21591 struct desc_ptr curgdt;
21592
21593@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21594 }
21595
21596 control_page = page_address(image->control_code_page);
21597- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21598+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21599
21600 relocate_kernel_ptr = control_page;
21601 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21602diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21603index 22db92b..d546bec 100644
21604--- a/arch/x86/kernel/microcode_core.c
21605+++ b/arch/x86/kernel/microcode_core.c
21606@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21607 return NOTIFY_OK;
21608 }
21609
21610-static struct notifier_block __refdata mc_cpu_notifier = {
21611+static struct notifier_block mc_cpu_notifier = {
21612 .notifier_call = mc_cpu_callback,
21613 };
21614
21615diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21616index 5fb2ceb..3ae90bb 100644
21617--- a/arch/x86/kernel/microcode_intel.c
21618+++ b/arch/x86/kernel/microcode_intel.c
21619@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21620
21621 static int get_ucode_user(void *to, const void *from, size_t n)
21622 {
21623- return copy_from_user(to, from, n);
21624+ return copy_from_user(to, (const void __force_user *)from, n);
21625 }
21626
21627 static enum ucode_state
21628 request_microcode_user(int cpu, const void __user *buf, size_t size)
21629 {
21630- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21631+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21632 }
21633
21634 static void microcode_fini_cpu(int cpu)
21635diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21636index 216a4d7..228255a 100644
21637--- a/arch/x86/kernel/module.c
21638+++ b/arch/x86/kernel/module.c
21639@@ -43,15 +43,60 @@ do { \
21640 } while (0)
21641 #endif
21642
21643-void *module_alloc(unsigned long size)
21644+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21645 {
21646- if (PAGE_ALIGN(size) > MODULES_LEN)
21647+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21648 return NULL;
21649 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21650- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21651+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21652 -1, __builtin_return_address(0));
21653 }
21654
21655+void *module_alloc(unsigned long size)
21656+{
21657+
21658+#ifdef CONFIG_PAX_KERNEXEC
21659+ return __module_alloc(size, PAGE_KERNEL);
21660+#else
21661+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21662+#endif
21663+
21664+}
21665+
21666+#ifdef CONFIG_PAX_KERNEXEC
21667+#ifdef CONFIG_X86_32
21668+void *module_alloc_exec(unsigned long size)
21669+{
21670+ struct vm_struct *area;
21671+
21672+ if (size == 0)
21673+ return NULL;
21674+
21675+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21676+ return area ? area->addr : NULL;
21677+}
21678+EXPORT_SYMBOL(module_alloc_exec);
21679+
21680+void module_free_exec(struct module *mod, void *module_region)
21681+{
21682+ vunmap(module_region);
21683+}
21684+EXPORT_SYMBOL(module_free_exec);
21685+#else
21686+void module_free_exec(struct module *mod, void *module_region)
21687+{
21688+ module_free(mod, module_region);
21689+}
21690+EXPORT_SYMBOL(module_free_exec);
21691+
21692+void *module_alloc_exec(unsigned long size)
21693+{
21694+ return __module_alloc(size, PAGE_KERNEL_RX);
21695+}
21696+EXPORT_SYMBOL(module_alloc_exec);
21697+#endif
21698+#endif
21699+
21700 #ifdef CONFIG_X86_32
21701 int apply_relocate(Elf32_Shdr *sechdrs,
21702 const char *strtab,
21703@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21704 unsigned int i;
21705 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21706 Elf32_Sym *sym;
21707- uint32_t *location;
21708+ uint32_t *plocation, location;
21709
21710 DEBUGP("Applying relocate section %u to %u\n",
21711 relsec, sechdrs[relsec].sh_info);
21712 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21713 /* This is where to make the change */
21714- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21715- + rel[i].r_offset;
21716+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21717+ location = (uint32_t)plocation;
21718+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21719+ plocation = ktla_ktva((void *)plocation);
21720 /* This is the symbol it is referring to. Note that all
21721 undefined symbols have been resolved. */
21722 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21723@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21724 switch (ELF32_R_TYPE(rel[i].r_info)) {
21725 case R_386_32:
21726 /* We add the value into the location given */
21727- *location += sym->st_value;
21728+ pax_open_kernel();
21729+ *plocation += sym->st_value;
21730+ pax_close_kernel();
21731 break;
21732 case R_386_PC32:
21733 /* Add the value, subtract its position */
21734- *location += sym->st_value - (uint32_t)location;
21735+ pax_open_kernel();
21736+ *plocation += sym->st_value - location;
21737+ pax_close_kernel();
21738 break;
21739 default:
21740 pr_err("%s: Unknown relocation: %u\n",
21741@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21742 case R_X86_64_NONE:
21743 break;
21744 case R_X86_64_64:
21745+ pax_open_kernel();
21746 *(u64 *)loc = val;
21747+ pax_close_kernel();
21748 break;
21749 case R_X86_64_32:
21750+ pax_open_kernel();
21751 *(u32 *)loc = val;
21752+ pax_close_kernel();
21753 if (val != *(u32 *)loc)
21754 goto overflow;
21755 break;
21756 case R_X86_64_32S:
21757+ pax_open_kernel();
21758 *(s32 *)loc = val;
21759+ pax_close_kernel();
21760 if ((s64)val != *(s32 *)loc)
21761 goto overflow;
21762 break;
21763 case R_X86_64_PC32:
21764 val -= (u64)loc;
21765+ pax_open_kernel();
21766 *(u32 *)loc = val;
21767+ pax_close_kernel();
21768+
21769 #if 0
21770 if ((s64)val != *(s32 *)loc)
21771 goto overflow;
21772diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21773index ce13049..e2e9c3c 100644
21774--- a/arch/x86/kernel/msr.c
21775+++ b/arch/x86/kernel/msr.c
21776@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21777 return notifier_from_errno(err);
21778 }
21779
21780-static struct notifier_block __refdata msr_class_cpu_notifier = {
21781+static struct notifier_block msr_class_cpu_notifier = {
21782 .notifier_call = msr_class_cpu_callback,
21783 };
21784
21785diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21786index 6030805..2d33f21 100644
21787--- a/arch/x86/kernel/nmi.c
21788+++ b/arch/x86/kernel/nmi.c
21789@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21790 return handled;
21791 }
21792
21793-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21794+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21795 {
21796 struct nmi_desc *desc = nmi_to_desc(type);
21797 unsigned long flags;
21798@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21799 * event confuses some handlers (kdump uses this flag)
21800 */
21801 if (action->flags & NMI_FLAG_FIRST)
21802- list_add_rcu(&action->list, &desc->head);
21803+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21804 else
21805- list_add_tail_rcu(&action->list, &desc->head);
21806+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21807
21808 spin_unlock_irqrestore(&desc->lock, flags);
21809 return 0;
21810@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21811 if (!strcmp(n->name, name)) {
21812 WARN(in_nmi(),
21813 "Trying to free NMI (%s) from NMI context!\n", n->name);
21814- list_del_rcu(&n->list);
21815+ pax_list_del_rcu((struct list_head *)&n->list);
21816 break;
21817 }
21818 }
21819@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21820 dotraplinkage notrace __kprobes void
21821 do_nmi(struct pt_regs *regs, long error_code)
21822 {
21823+
21824+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21825+ if (!user_mode(regs)) {
21826+ unsigned long cs = regs->cs & 0xFFFF;
21827+ unsigned long ip = ktva_ktla(regs->ip);
21828+
21829+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21830+ regs->ip = ip;
21831+ }
21832+#endif
21833+
21834 nmi_nesting_preprocess(regs);
21835
21836 nmi_enter();
21837diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21838index 6d9582e..f746287 100644
21839--- a/arch/x86/kernel/nmi_selftest.c
21840+++ b/arch/x86/kernel/nmi_selftest.c
21841@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21842 {
21843 /* trap all the unknown NMIs we may generate */
21844 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21845- __initdata);
21846+ __initconst);
21847 }
21848
21849 static void __init cleanup_nmi_testsuite(void)
21850@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21851 unsigned long timeout;
21852
21853 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21854- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21855+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21856 nmi_fail = FAILURE;
21857 return;
21858 }
21859diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21860index 676b8c7..870ba04 100644
21861--- a/arch/x86/kernel/paravirt-spinlocks.c
21862+++ b/arch/x86/kernel/paravirt-spinlocks.c
21863@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21864 arch_spin_lock(lock);
21865 }
21866
21867-struct pv_lock_ops pv_lock_ops = {
21868+struct pv_lock_ops pv_lock_ops __read_only = {
21869 #ifdef CONFIG_SMP
21870 .spin_is_locked = __ticket_spin_is_locked,
21871 .spin_is_contended = __ticket_spin_is_contended,
21872diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21873index cd6de64..27c6af0 100644
21874--- a/arch/x86/kernel/paravirt.c
21875+++ b/arch/x86/kernel/paravirt.c
21876@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21877 {
21878 return x;
21879 }
21880+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21881+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21882+#endif
21883
21884 void __init default_banner(void)
21885 {
21886@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21887 if (opfunc == NULL)
21888 /* If there's no function, patch it with a ud2a (BUG) */
21889 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21890- else if (opfunc == _paravirt_nop)
21891+ else if (opfunc == (void *)_paravirt_nop)
21892 /* If the operation is a nop, then nop the callsite */
21893 ret = paravirt_patch_nop();
21894
21895 /* identity functions just return their single argument */
21896- else if (opfunc == _paravirt_ident_32)
21897+ else if (opfunc == (void *)_paravirt_ident_32)
21898 ret = paravirt_patch_ident_32(insnbuf, len);
21899- else if (opfunc == _paravirt_ident_64)
21900+ else if (opfunc == (void *)_paravirt_ident_64)
21901 ret = paravirt_patch_ident_64(insnbuf, len);
21902+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21903+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21904+ ret = paravirt_patch_ident_64(insnbuf, len);
21905+#endif
21906
21907 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21908 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21909@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21910 if (insn_len > len || start == NULL)
21911 insn_len = len;
21912 else
21913- memcpy(insnbuf, start, insn_len);
21914+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21915
21916 return insn_len;
21917 }
21918@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
21919 return this_cpu_read(paravirt_lazy_mode);
21920 }
21921
21922-struct pv_info pv_info = {
21923+struct pv_info pv_info __read_only = {
21924 .name = "bare hardware",
21925 .paravirt_enabled = 0,
21926 .kernel_rpl = 0,
21927@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21928 #endif
21929 };
21930
21931-struct pv_init_ops pv_init_ops = {
21932+struct pv_init_ops pv_init_ops __read_only = {
21933 .patch = native_patch,
21934 };
21935
21936-struct pv_time_ops pv_time_ops = {
21937+struct pv_time_ops pv_time_ops __read_only = {
21938 .sched_clock = native_sched_clock,
21939 .steal_clock = native_steal_clock,
21940 };
21941
21942-struct pv_irq_ops pv_irq_ops = {
21943+struct pv_irq_ops pv_irq_ops __read_only = {
21944 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21945 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21946 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21947@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21948 #endif
21949 };
21950
21951-struct pv_cpu_ops pv_cpu_ops = {
21952+struct pv_cpu_ops pv_cpu_ops __read_only = {
21953 .cpuid = native_cpuid,
21954 .get_debugreg = native_get_debugreg,
21955 .set_debugreg = native_set_debugreg,
21956@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21957 .end_context_switch = paravirt_nop,
21958 };
21959
21960-struct pv_apic_ops pv_apic_ops = {
21961+struct pv_apic_ops pv_apic_ops __read_only= {
21962 #ifdef CONFIG_X86_LOCAL_APIC
21963 .startup_ipi_hook = paravirt_nop,
21964 #endif
21965 };
21966
21967-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21968+#ifdef CONFIG_X86_32
21969+#ifdef CONFIG_X86_PAE
21970+/* 64-bit pagetable entries */
21971+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21972+#else
21973 /* 32-bit pagetable entries */
21974 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21975+#endif
21976 #else
21977 /* 64-bit pagetable entries */
21978 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21979 #endif
21980
21981-struct pv_mmu_ops pv_mmu_ops = {
21982+struct pv_mmu_ops pv_mmu_ops __read_only = {
21983
21984 .read_cr2 = native_read_cr2,
21985 .write_cr2 = native_write_cr2,
21986@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21987 .make_pud = PTE_IDENT,
21988
21989 .set_pgd = native_set_pgd,
21990+ .set_pgd_batched = native_set_pgd_batched,
21991 #endif
21992 #endif /* PAGETABLE_LEVELS >= 3 */
21993
21994@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21995 },
21996
21997 .set_fixmap = native_set_fixmap,
21998+
21999+#ifdef CONFIG_PAX_KERNEXEC
22000+ .pax_open_kernel = native_pax_open_kernel,
22001+ .pax_close_kernel = native_pax_close_kernel,
22002+#endif
22003+
22004 };
22005
22006 EXPORT_SYMBOL_GPL(pv_time_ops);
22007diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
22008index 299d493..2ccb0ee 100644
22009--- a/arch/x86/kernel/pci-calgary_64.c
22010+++ b/arch/x86/kernel/pci-calgary_64.c
22011@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
22012 tce_space = be64_to_cpu(readq(target));
22013 tce_space = tce_space & TAR_SW_BITS;
22014
22015- tce_space = tce_space & (~specified_table_size);
22016+ tce_space = tce_space & (~(unsigned long)specified_table_size);
22017 info->tce_space = (u64 *)__va(tce_space);
22018 }
22019 }
22020diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
22021index 35ccf75..7a15747 100644
22022--- a/arch/x86/kernel/pci-iommu_table.c
22023+++ b/arch/x86/kernel/pci-iommu_table.c
22024@@ -2,7 +2,7 @@
22025 #include <asm/iommu_table.h>
22026 #include <linux/string.h>
22027 #include <linux/kallsyms.h>
22028-
22029+#include <linux/sched.h>
22030
22031 #define DEBUG 1
22032
22033diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
22034index 6c483ba..d10ce2f 100644
22035--- a/arch/x86/kernel/pci-swiotlb.c
22036+++ b/arch/x86/kernel/pci-swiotlb.c
22037@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
22038 void *vaddr, dma_addr_t dma_addr,
22039 struct dma_attrs *attrs)
22040 {
22041- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
22042+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
22043 }
22044
22045 static struct dma_map_ops swiotlb_dma_ops = {
22046diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
22047index 81a5f5e..20f8b58 100644
22048--- a/arch/x86/kernel/process.c
22049+++ b/arch/x86/kernel/process.c
22050@@ -36,7 +36,8 @@
22051 * section. Since TSS's are completely CPU-local, we want them
22052 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
22053 */
22054-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22055+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22056+EXPORT_SYMBOL(init_tss);
22057
22058 #ifdef CONFIG_X86_64
22059 static DEFINE_PER_CPU(unsigned char, is_idle);
22060@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22061 task_xstate_cachep =
22062 kmem_cache_create("task_xstate", xstate_size,
22063 __alignof__(union thread_xstate),
22064- SLAB_PANIC | SLAB_NOTRACK, NULL);
22065+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22066 }
22067
22068 /*
22069@@ -105,7 +106,7 @@ void exit_thread(void)
22070 unsigned long *bp = t->io_bitmap_ptr;
22071
22072 if (bp) {
22073- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22074+ struct tss_struct *tss = init_tss + get_cpu();
22075
22076 t->io_bitmap_ptr = NULL;
22077 clear_thread_flag(TIF_IO_BITMAP);
22078@@ -125,6 +126,9 @@ void flush_thread(void)
22079 {
22080 struct task_struct *tsk = current;
22081
22082+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22083+ loadsegment(gs, 0);
22084+#endif
22085 flush_ptrace_hw_breakpoint(tsk);
22086 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22087 drop_init_fpu(tsk);
22088@@ -271,7 +275,7 @@ static void __exit_idle(void)
22089 void exit_idle(void)
22090 {
22091 /* idle loop has pid 0 */
22092- if (current->pid)
22093+ if (task_pid_nr(current))
22094 return;
22095 __exit_idle();
22096 }
22097@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
22098 return ret;
22099 }
22100 #endif
22101-void stop_this_cpu(void *dummy)
22102+__noreturn void stop_this_cpu(void *dummy)
22103 {
22104 local_irq_disable();
22105 /*
22106@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
22107 }
22108 early_param("idle", idle_setup);
22109
22110-unsigned long arch_align_stack(unsigned long sp)
22111+#ifdef CONFIG_PAX_RANDKSTACK
22112+void pax_randomize_kstack(struct pt_regs *regs)
22113 {
22114- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22115- sp -= get_random_int() % 8192;
22116- return sp & ~0xf;
22117-}
22118+ struct thread_struct *thread = &current->thread;
22119+ unsigned long time;
22120
22121-unsigned long arch_randomize_brk(struct mm_struct *mm)
22122-{
22123- unsigned long range_end = mm->brk + 0x02000000;
22124- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22125-}
22126+ if (!randomize_va_space)
22127+ return;
22128+
22129+ if (v8086_mode(regs))
22130+ return;
22131
22132+ rdtscl(time);
22133+
22134+ /* P4 seems to return a 0 LSB, ignore it */
22135+#ifdef CONFIG_MPENTIUM4
22136+ time &= 0x3EUL;
22137+ time <<= 2;
22138+#elif defined(CONFIG_X86_64)
22139+ time &= 0xFUL;
22140+ time <<= 4;
22141+#else
22142+ time &= 0x1FUL;
22143+ time <<= 3;
22144+#endif
22145+
22146+ thread->sp0 ^= time;
22147+ load_sp0(init_tss + smp_processor_id(), thread);
22148+
22149+#ifdef CONFIG_X86_64
22150+ this_cpu_write(kernel_stack, thread->sp0);
22151+#endif
22152+}
22153+#endif
22154diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22155index 7305f7d..22f73d6 100644
22156--- a/arch/x86/kernel/process_32.c
22157+++ b/arch/x86/kernel/process_32.c
22158@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22159 unsigned long thread_saved_pc(struct task_struct *tsk)
22160 {
22161 return ((unsigned long *)tsk->thread.sp)[3];
22162+//XXX return tsk->thread.eip;
22163 }
22164
22165 void __show_regs(struct pt_regs *regs, int all)
22166@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
22167 unsigned long sp;
22168 unsigned short ss, gs;
22169
22170- if (user_mode_vm(regs)) {
22171+ if (user_mode(regs)) {
22172 sp = regs->sp;
22173 ss = regs->ss & 0xffff;
22174- gs = get_user_gs(regs);
22175 } else {
22176 sp = kernel_stack_pointer(regs);
22177 savesegment(ss, ss);
22178- savesegment(gs, gs);
22179 }
22180+ gs = get_user_gs(regs);
22181
22182 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22183 (u16)regs->cs, regs->ip, regs->flags,
22184- smp_processor_id());
22185+ raw_smp_processor_id());
22186 print_symbol("EIP is at %s\n", regs->ip);
22187
22188 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22189@@ -128,20 +128,21 @@ void release_thread(struct task_struct *dead_task)
22190 int copy_thread(unsigned long clone_flags, unsigned long sp,
22191 unsigned long arg, struct task_struct *p)
22192 {
22193- struct pt_regs *childregs = task_pt_regs(p);
22194+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22195 struct task_struct *tsk;
22196 int err;
22197
22198 p->thread.sp = (unsigned long) childregs;
22199 p->thread.sp0 = (unsigned long) (childregs+1);
22200+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22201
22202 if (unlikely(p->flags & PF_KTHREAD)) {
22203 /* kernel thread */
22204 memset(childregs, 0, sizeof(struct pt_regs));
22205 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22206- task_user_gs(p) = __KERNEL_STACK_CANARY;
22207- childregs->ds = __USER_DS;
22208- childregs->es = __USER_DS;
22209+ savesegment(gs, childregs->gs);
22210+ childregs->ds = __KERNEL_DS;
22211+ childregs->es = __KERNEL_DS;
22212 childregs->fs = __KERNEL_PERCPU;
22213 childregs->bx = sp; /* function */
22214 childregs->bp = arg;
22215@@ -248,7 +249,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22216 struct thread_struct *prev = &prev_p->thread,
22217 *next = &next_p->thread;
22218 int cpu = smp_processor_id();
22219- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22220+ struct tss_struct *tss = init_tss + cpu;
22221 fpu_switch_t fpu;
22222
22223 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22224@@ -272,6 +273,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22225 */
22226 lazy_save_gs(prev->gs);
22227
22228+#ifdef CONFIG_PAX_MEMORY_UDEREF
22229+ __set_fs(task_thread_info(next_p)->addr_limit);
22230+#endif
22231+
22232 /*
22233 * Load the per-thread Thread-Local Storage descriptor.
22234 */
22235@@ -302,6 +307,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22236 */
22237 arch_end_context_switch(next_p);
22238
22239+ this_cpu_write(current_task, next_p);
22240+ this_cpu_write(current_tinfo, &next_p->tinfo);
22241+
22242 /*
22243 * Restore %gs if needed (which is common)
22244 */
22245@@ -310,8 +318,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22246
22247 switch_fpu_finish(next_p, fpu);
22248
22249- this_cpu_write(current_task, next_p);
22250-
22251 return prev_p;
22252 }
22253
22254@@ -341,4 +347,3 @@ unsigned long get_wchan(struct task_struct *p)
22255 } while (count++ < 16);
22256 return 0;
22257 }
22258-
22259diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22260index 355ae06..4530766 100644
22261--- a/arch/x86/kernel/process_64.c
22262+++ b/arch/x86/kernel/process_64.c
22263@@ -151,10 +151,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22264 struct pt_regs *childregs;
22265 struct task_struct *me = current;
22266
22267- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22268+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22269 childregs = task_pt_regs(p);
22270 p->thread.sp = (unsigned long) childregs;
22271 p->thread.usersp = me->thread.usersp;
22272+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22273 set_tsk_thread_flag(p, TIF_FORK);
22274 p->fpu_counter = 0;
22275 p->thread.io_bitmap_ptr = NULL;
22276@@ -273,7 +274,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22277 struct thread_struct *prev = &prev_p->thread;
22278 struct thread_struct *next = &next_p->thread;
22279 int cpu = smp_processor_id();
22280- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22281+ struct tss_struct *tss = init_tss + cpu;
22282 unsigned fsindex, gsindex;
22283 fpu_switch_t fpu;
22284
22285@@ -355,10 +356,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22286 prev->usersp = this_cpu_read(old_rsp);
22287 this_cpu_write(old_rsp, next->usersp);
22288 this_cpu_write(current_task, next_p);
22289+ this_cpu_write(current_tinfo, &next_p->tinfo);
22290
22291- this_cpu_write(kernel_stack,
22292- (unsigned long)task_stack_page(next_p) +
22293- THREAD_SIZE - KERNEL_STACK_OFFSET);
22294+ this_cpu_write(kernel_stack, next->sp0);
22295
22296 /*
22297 * Now maybe reload the debug registers and handle I/O bitmaps
22298@@ -427,12 +427,11 @@ unsigned long get_wchan(struct task_struct *p)
22299 if (!p || p == current || p->state == TASK_RUNNING)
22300 return 0;
22301 stack = (unsigned long)task_stack_page(p);
22302- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22303+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22304 return 0;
22305 fp = *(u64 *)(p->thread.sp);
22306 do {
22307- if (fp < (unsigned long)stack ||
22308- fp >= (unsigned long)stack+THREAD_SIZE)
22309+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22310 return 0;
22311 ip = *(u64 *)(fp+8);
22312 if (!in_sched_functions(ip))
22313diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22314index 29a8120..a50b5ee 100644
22315--- a/arch/x86/kernel/ptrace.c
22316+++ b/arch/x86/kernel/ptrace.c
22317@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22318 {
22319 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22320 unsigned long sp = (unsigned long)&regs->sp;
22321- struct thread_info *tinfo;
22322
22323- if (context == (sp & ~(THREAD_SIZE - 1)))
22324+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22325 return sp;
22326
22327- tinfo = (struct thread_info *)context;
22328- if (tinfo->previous_esp)
22329- return tinfo->previous_esp;
22330+ sp = *(unsigned long *)context;
22331+ if (sp)
22332+ return sp;
22333
22334 return (unsigned long)regs;
22335 }
22336@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22337 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22338 {
22339 int i;
22340- int dr7 = 0;
22341+ unsigned long dr7 = 0;
22342 struct arch_hw_breakpoint *info;
22343
22344 for (i = 0; i < HBP_NUM; i++) {
22345@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22346 unsigned long addr, unsigned long data)
22347 {
22348 int ret;
22349- unsigned long __user *datap = (unsigned long __user *)data;
22350+ unsigned long __user *datap = (__force unsigned long __user *)data;
22351
22352 switch (request) {
22353 /* read the word at location addr in the USER area. */
22354@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22355 if ((int) addr < 0)
22356 return -EIO;
22357 ret = do_get_thread_area(child, addr,
22358- (struct user_desc __user *)data);
22359+ (__force struct user_desc __user *) data);
22360 break;
22361
22362 case PTRACE_SET_THREAD_AREA:
22363 if ((int) addr < 0)
22364 return -EIO;
22365 ret = do_set_thread_area(child, addr,
22366- (struct user_desc __user *)data, 0);
22367+ (__force struct user_desc __user *) data, 0);
22368 break;
22369 #endif
22370
22371@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22372
22373 #ifdef CONFIG_X86_64
22374
22375-static struct user_regset x86_64_regsets[] __read_mostly = {
22376+static user_regset_no_const x86_64_regsets[] __read_only = {
22377 [REGSET_GENERAL] = {
22378 .core_note_type = NT_PRSTATUS,
22379 .n = sizeof(struct user_regs_struct) / sizeof(long),
22380@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22381 #endif /* CONFIG_X86_64 */
22382
22383 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22384-static struct user_regset x86_32_regsets[] __read_mostly = {
22385+static user_regset_no_const x86_32_regsets[] __read_only = {
22386 [REGSET_GENERAL] = {
22387 .core_note_type = NT_PRSTATUS,
22388 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22389@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22390 */
22391 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22392
22393-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22394+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22395 {
22396 #ifdef CONFIG_X86_64
22397 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22398@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22399 memset(info, 0, sizeof(*info));
22400 info->si_signo = SIGTRAP;
22401 info->si_code = si_code;
22402- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22403+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22404 }
22405
22406 void user_single_step_siginfo(struct task_struct *tsk,
22407@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22408 # define IS_IA32 0
22409 #endif
22410
22411+#ifdef CONFIG_GRKERNSEC_SETXID
22412+extern void gr_delayed_cred_worker(void);
22413+#endif
22414+
22415 /*
22416 * We must return the syscall number to actually look up in the table.
22417 * This can be -1L to skip running any syscall at all.
22418@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22419
22420 user_exit();
22421
22422+#ifdef CONFIG_GRKERNSEC_SETXID
22423+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22424+ gr_delayed_cred_worker();
22425+#endif
22426+
22427 /*
22428 * If we stepped into a sysenter/syscall insn, it trapped in
22429 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22430@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22431 */
22432 user_exit();
22433
22434+#ifdef CONFIG_GRKERNSEC_SETXID
22435+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22436+ gr_delayed_cred_worker();
22437+#endif
22438+
22439 audit_syscall_exit(regs);
22440
22441 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22442diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22443index 2cb9470..ff1fd80 100644
22444--- a/arch/x86/kernel/pvclock.c
22445+++ b/arch/x86/kernel/pvclock.c
22446@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22447 return pv_tsc_khz;
22448 }
22449
22450-static atomic64_t last_value = ATOMIC64_INIT(0);
22451+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22452
22453 void pvclock_resume(void)
22454 {
22455- atomic64_set(&last_value, 0);
22456+ atomic64_set_unchecked(&last_value, 0);
22457 }
22458
22459 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22460@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22461 * updating at the same time, and one of them could be slightly behind,
22462 * making the assumption that last_value always go forward fail to hold.
22463 */
22464- last = atomic64_read(&last_value);
22465+ last = atomic64_read_unchecked(&last_value);
22466 do {
22467 if (ret < last)
22468 return last;
22469- last = atomic64_cmpxchg(&last_value, last, ret);
22470+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22471 } while (unlikely(last != ret));
22472
22473 return ret;
22474diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22475index 76fa1e9..abf09ea 100644
22476--- a/arch/x86/kernel/reboot.c
22477+++ b/arch/x86/kernel/reboot.c
22478@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22479 EXPORT_SYMBOL(pm_power_off);
22480
22481 static const struct desc_ptr no_idt = {};
22482-static int reboot_mode;
22483+static unsigned short reboot_mode;
22484 enum reboot_type reboot_type = BOOT_ACPI;
22485 int reboot_force;
22486
22487@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22488
22489 void __noreturn machine_real_restart(unsigned int type)
22490 {
22491+
22492+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22493+ struct desc_struct *gdt;
22494+#endif
22495+
22496 local_irq_disable();
22497
22498 /*
22499@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22500
22501 /* Jump to the identity-mapped low memory code */
22502 #ifdef CONFIG_X86_32
22503- asm volatile("jmpl *%0" : :
22504+
22505+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22506+ gdt = get_cpu_gdt_table(smp_processor_id());
22507+ pax_open_kernel();
22508+#ifdef CONFIG_PAX_MEMORY_UDEREF
22509+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22510+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22511+ loadsegment(ds, __KERNEL_DS);
22512+ loadsegment(es, __KERNEL_DS);
22513+ loadsegment(ss, __KERNEL_DS);
22514+#endif
22515+#ifdef CONFIG_PAX_KERNEXEC
22516+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22517+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22518+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22519+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22520+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22521+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22522+#endif
22523+ pax_close_kernel();
22524+#endif
22525+
22526+ asm volatile("ljmpl *%0" : :
22527 "rm" (real_mode_header->machine_real_restart_asm),
22528 "a" (type));
22529 #else
22530@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22531 * try to force a triple fault and then cycle between hitting the keyboard
22532 * controller and doing that
22533 */
22534-static void native_machine_emergency_restart(void)
22535+static void __noreturn native_machine_emergency_restart(void)
22536 {
22537 int i;
22538 int attempt = 0;
22539@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22540 #endif
22541 }
22542
22543-static void __machine_emergency_restart(int emergency)
22544+static void __noreturn __machine_emergency_restart(int emergency)
22545 {
22546 reboot_emergency = emergency;
22547 machine_ops.emergency_restart();
22548 }
22549
22550-static void native_machine_restart(char *__unused)
22551+static void __noreturn native_machine_restart(char *__unused)
22552 {
22553 pr_notice("machine restart\n");
22554
22555@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22556 __machine_emergency_restart(0);
22557 }
22558
22559-static void native_machine_halt(void)
22560+static void __noreturn native_machine_halt(void)
22561 {
22562 /* Stop other cpus and apics */
22563 machine_shutdown();
22564@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22565 stop_this_cpu(NULL);
22566 }
22567
22568-static void native_machine_power_off(void)
22569+static void __noreturn native_machine_power_off(void)
22570 {
22571 if (pm_power_off) {
22572 if (!reboot_force)
22573@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22574 }
22575 /* A fallback in case there is no PM info available */
22576 tboot_shutdown(TB_SHUTDOWN_HALT);
22577+ unreachable();
22578 }
22579
22580-struct machine_ops machine_ops = {
22581+struct machine_ops machine_ops __read_only = {
22582 .power_off = native_machine_power_off,
22583 .shutdown = native_machine_shutdown,
22584 .emergency_restart = native_machine_emergency_restart,
22585diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22586index f2bb9c9..bed145d7 100644
22587--- a/arch/x86/kernel/relocate_kernel_64.S
22588+++ b/arch/x86/kernel/relocate_kernel_64.S
22589@@ -11,6 +11,7 @@
22590 #include <asm/kexec.h>
22591 #include <asm/processor-flags.h>
22592 #include <asm/pgtable_types.h>
22593+#include <asm/alternative-asm.h>
22594
22595 /*
22596 * Must be relocatable PIC code callable as a C function
22597@@ -167,6 +168,7 @@ identity_mapped:
22598 xorq %r14, %r14
22599 xorq %r15, %r15
22600
22601+ pax_force_retaddr 0, 1
22602 ret
22603
22604 1:
22605diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22606index 56f7fcf..fa229f4 100644
22607--- a/arch/x86/kernel/setup.c
22608+++ b/arch/x86/kernel/setup.c
22609@@ -110,6 +110,7 @@
22610 #include <asm/mce.h>
22611 #include <asm/alternative.h>
22612 #include <asm/prom.h>
22613+#include <asm/boot.h>
22614
22615 /*
22616 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
22617@@ -444,7 +445,7 @@ static void __init parse_setup_data(void)
22618
22619 switch (data->type) {
22620 case SETUP_E820_EXT:
22621- parse_e820_ext(data);
22622+ parse_e820_ext((struct setup_data __force_kernel *)data);
22623 break;
22624 case SETUP_DTB:
22625 add_dtb(pa_data);
22626@@ -771,7 +772,7 @@ static void __init trim_bios_range(void)
22627 * area (640->1Mb) as ram even though it is not.
22628 * take them out.
22629 */
22630- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22631+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22632
22633 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22634 }
22635@@ -779,7 +780,7 @@ static void __init trim_bios_range(void)
22636 /* called before trim_bios_range() to spare extra sanitize */
22637 static void __init e820_add_kernel_range(void)
22638 {
22639- u64 start = __pa_symbol(_text);
22640+ u64 start = __pa_symbol(ktla_ktva(_text));
22641 u64 size = __pa_symbol(_end) - start;
22642
22643 /*
22644@@ -841,8 +842,12 @@ static void __init trim_low_memory_range(void)
22645
22646 void __init setup_arch(char **cmdline_p)
22647 {
22648+#ifdef CONFIG_X86_32
22649+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
22650+#else
22651 memblock_reserve(__pa_symbol(_text),
22652 (unsigned long)__bss_stop - (unsigned long)_text);
22653+#endif
22654
22655 early_reserve_initrd();
22656
22657@@ -934,14 +939,14 @@ void __init setup_arch(char **cmdline_p)
22658
22659 if (!boot_params.hdr.root_flags)
22660 root_mountflags &= ~MS_RDONLY;
22661- init_mm.start_code = (unsigned long) _text;
22662- init_mm.end_code = (unsigned long) _etext;
22663+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22664+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22665 init_mm.end_data = (unsigned long) _edata;
22666 init_mm.brk = _brk_end;
22667
22668- code_resource.start = __pa_symbol(_text);
22669- code_resource.end = __pa_symbol(_etext)-1;
22670- data_resource.start = __pa_symbol(_etext);
22671+ code_resource.start = __pa_symbol(ktla_ktva(_text));
22672+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
22673+ data_resource.start = __pa_symbol(_sdata);
22674 data_resource.end = __pa_symbol(_edata)-1;
22675 bss_resource.start = __pa_symbol(__bss_start);
22676 bss_resource.end = __pa_symbol(__bss_stop)-1;
22677diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22678index 5cdff03..80fa283 100644
22679--- a/arch/x86/kernel/setup_percpu.c
22680+++ b/arch/x86/kernel/setup_percpu.c
22681@@ -21,19 +21,17 @@
22682 #include <asm/cpu.h>
22683 #include <asm/stackprotector.h>
22684
22685-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22686+#ifdef CONFIG_SMP
22687+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22688 EXPORT_PER_CPU_SYMBOL(cpu_number);
22689+#endif
22690
22691-#ifdef CONFIG_X86_64
22692 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22693-#else
22694-#define BOOT_PERCPU_OFFSET 0
22695-#endif
22696
22697 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22698 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22699
22700-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22701+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22702 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22703 };
22704 EXPORT_SYMBOL(__per_cpu_offset);
22705@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22706 {
22707 #ifdef CONFIG_NEED_MULTIPLE_NODES
22708 pg_data_t *last = NULL;
22709- unsigned int cpu;
22710+ int cpu;
22711
22712 for_each_possible_cpu(cpu) {
22713 int node = early_cpu_to_node(cpu);
22714@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22715 {
22716 #ifdef CONFIG_X86_32
22717 struct desc_struct gdt;
22718+ unsigned long base = per_cpu_offset(cpu);
22719
22720- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22721- 0x2 | DESCTYPE_S, 0x8);
22722- gdt.s = 1;
22723+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22724+ 0x83 | DESCTYPE_S, 0xC);
22725 write_gdt_entry(get_cpu_gdt_table(cpu),
22726 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22727 #endif
22728@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22729 /* alrighty, percpu areas up and running */
22730 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22731 for_each_possible_cpu(cpu) {
22732+#ifdef CONFIG_CC_STACKPROTECTOR
22733+#ifdef CONFIG_X86_32
22734+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22735+#endif
22736+#endif
22737 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22738 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22739 per_cpu(cpu_number, cpu) = cpu;
22740@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22741 */
22742 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22743 #endif
22744+#ifdef CONFIG_CC_STACKPROTECTOR
22745+#ifdef CONFIG_X86_32
22746+ if (!cpu)
22747+ per_cpu(stack_canary.canary, cpu) = canary;
22748+#endif
22749+#endif
22750 /*
22751 * Up to this point, the boot CPU has been using .init.data
22752 * area. Reload any changed state for the boot CPU.
22753diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22754index 6956299..f20beae 100644
22755--- a/arch/x86/kernel/signal.c
22756+++ b/arch/x86/kernel/signal.c
22757@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22758 * Align the stack pointer according to the i386 ABI,
22759 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22760 */
22761- sp = ((sp + 4) & -16ul) - 4;
22762+ sp = ((sp - 12) & -16ul) - 4;
22763 #else /* !CONFIG_X86_32 */
22764 sp = round_down(sp, 16) - 8;
22765 #endif
22766@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22767 }
22768
22769 if (current->mm->context.vdso)
22770- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22771+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22772 else
22773- restorer = &frame->retcode;
22774+ restorer = (void __user *)&frame->retcode;
22775 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22776 restorer = ksig->ka.sa.sa_restorer;
22777
22778@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22779 * reasons and because gdb uses it as a signature to notice
22780 * signal handler stack frames.
22781 */
22782- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22783+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22784
22785 if (err)
22786 return -EFAULT;
22787@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22788 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22789
22790 /* Set up to return from userspace. */
22791- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22792+ if (current->mm->context.vdso)
22793+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22794+ else
22795+ restorer = (void __user *)&frame->retcode;
22796 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22797 restorer = ksig->ka.sa.sa_restorer;
22798 put_user_ex(restorer, &frame->pretcode);
22799@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22800 * reasons and because gdb uses it as a signature to notice
22801 * signal handler stack frames.
22802 */
22803- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22804+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22805 } put_user_catch(err);
22806
22807 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
22808@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22809 {
22810 int usig = signr_convert(ksig->sig);
22811 sigset_t *set = sigmask_to_save();
22812- compat_sigset_t *cset = (compat_sigset_t *) set;
22813+ sigset_t sigcopy;
22814+ compat_sigset_t *cset;
22815+
22816+ sigcopy = *set;
22817+
22818+ cset = (compat_sigset_t *) &sigcopy;
22819
22820 /* Set up the stack frame */
22821 if (is_ia32_frame()) {
22822@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22823 } else if (is_x32_frame()) {
22824 return x32_setup_rt_frame(ksig, cset, regs);
22825 } else {
22826- return __setup_rt_frame(ksig->sig, ksig, set, regs);
22827+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
22828 }
22829 }
22830
22831diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22832index 48d2b7d..90d328a 100644
22833--- a/arch/x86/kernel/smp.c
22834+++ b/arch/x86/kernel/smp.c
22835@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22836
22837 __setup("nonmi_ipi", nonmi_ipi_setup);
22838
22839-struct smp_ops smp_ops = {
22840+struct smp_ops smp_ops __read_only = {
22841 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22842 .smp_prepare_cpus = native_smp_prepare_cpus,
22843 .smp_cpus_done = native_smp_cpus_done,
22844diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22845index bfd348e..4816ad8 100644
22846--- a/arch/x86/kernel/smpboot.c
22847+++ b/arch/x86/kernel/smpboot.c
22848@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22849 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22850 (THREAD_SIZE + task_stack_page(idle))) - 1);
22851 per_cpu(current_task, cpu) = idle;
22852+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22853
22854 #ifdef CONFIG_X86_32
22855 /* Stack for startup_32 can be just as for start_secondary onwards */
22856@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22857 #else
22858 clear_tsk_thread_flag(idle, TIF_FORK);
22859 initial_gs = per_cpu_offset(cpu);
22860- per_cpu(kernel_stack, cpu) =
22861- (unsigned long)task_stack_page(idle) -
22862- KERNEL_STACK_OFFSET + THREAD_SIZE;
22863+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22864 #endif
22865+
22866+ pax_open_kernel();
22867 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22868+ pax_close_kernel();
22869+
22870 initial_code = (unsigned long)start_secondary;
22871 stack_start = idle->thread.sp;
22872
22873@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22874 /* the FPU context is blank, nobody can own it */
22875 __cpu_disable_lazy_restore(cpu);
22876
22877+#ifdef CONFIG_PAX_PER_CPU_PGD
22878+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22879+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22880+ KERNEL_PGD_PTRS);
22881+#endif
22882+
22883+ /* the FPU context is blank, nobody can own it */
22884+ __cpu_disable_lazy_restore(cpu);
22885+
22886 err = do_boot_cpu(apicid, cpu, tidle);
22887 if (err) {
22888 pr_debug("do_boot_cpu failed %d\n", err);
22889diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22890index 9b4d51d..5d28b58 100644
22891--- a/arch/x86/kernel/step.c
22892+++ b/arch/x86/kernel/step.c
22893@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22894 struct desc_struct *desc;
22895 unsigned long base;
22896
22897- seg &= ~7UL;
22898+ seg >>= 3;
22899
22900 mutex_lock(&child->mm->context.lock);
22901- if (unlikely((seg >> 3) >= child->mm->context.size))
22902+ if (unlikely(seg >= child->mm->context.size))
22903 addr = -1L; /* bogus selector, access would fault */
22904 else {
22905 desc = child->mm->context.ldt + seg;
22906@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22907 addr += base;
22908 }
22909 mutex_unlock(&child->mm->context.lock);
22910- }
22911+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22912+ addr = ktla_ktva(addr);
22913
22914 return addr;
22915 }
22916@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22917 unsigned char opcode[15];
22918 unsigned long addr = convert_ip_to_linear(child, regs);
22919
22920+ if (addr == -EINVAL)
22921+ return 0;
22922+
22923 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22924 for (i = 0; i < copied; i++) {
22925 switch (opcode[i]) {
22926diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22927new file mode 100644
22928index 0000000..5877189
22929--- /dev/null
22930+++ b/arch/x86/kernel/sys_i386_32.c
22931@@ -0,0 +1,189 @@
22932+/*
22933+ * This file contains various random system calls that
22934+ * have a non-standard calling sequence on the Linux/i386
22935+ * platform.
22936+ */
22937+
22938+#include <linux/errno.h>
22939+#include <linux/sched.h>
22940+#include <linux/mm.h>
22941+#include <linux/fs.h>
22942+#include <linux/smp.h>
22943+#include <linux/sem.h>
22944+#include <linux/msg.h>
22945+#include <linux/shm.h>
22946+#include <linux/stat.h>
22947+#include <linux/syscalls.h>
22948+#include <linux/mman.h>
22949+#include <linux/file.h>
22950+#include <linux/utsname.h>
22951+#include <linux/ipc.h>
22952+#include <linux/elf.h>
22953+
22954+#include <linux/uaccess.h>
22955+#include <linux/unistd.h>
22956+
22957+#include <asm/syscalls.h>
22958+
22959+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22960+{
22961+ unsigned long pax_task_size = TASK_SIZE;
22962+
22963+#ifdef CONFIG_PAX_SEGMEXEC
22964+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22965+ pax_task_size = SEGMEXEC_TASK_SIZE;
22966+#endif
22967+
22968+ if (flags & MAP_FIXED)
22969+ if (len > pax_task_size || addr > pax_task_size - len)
22970+ return -EINVAL;
22971+
22972+ return 0;
22973+}
22974+
22975+/*
22976+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
22977+ */
22978+static unsigned long get_align_mask(void)
22979+{
22980+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
22981+ return 0;
22982+
22983+ if (!(current->flags & PF_RANDOMIZE))
22984+ return 0;
22985+
22986+ return va_align.mask;
22987+}
22988+
22989+unsigned long
22990+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22991+ unsigned long len, unsigned long pgoff, unsigned long flags)
22992+{
22993+ struct mm_struct *mm = current->mm;
22994+ struct vm_area_struct *vma;
22995+ unsigned long pax_task_size = TASK_SIZE;
22996+ struct vm_unmapped_area_info info;
22997+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22998+
22999+#ifdef CONFIG_PAX_SEGMEXEC
23000+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23001+ pax_task_size = SEGMEXEC_TASK_SIZE;
23002+#endif
23003+
23004+ pax_task_size -= PAGE_SIZE;
23005+
23006+ if (len > pax_task_size)
23007+ return -ENOMEM;
23008+
23009+ if (flags & MAP_FIXED)
23010+ return addr;
23011+
23012+#ifdef CONFIG_PAX_RANDMMAP
23013+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23014+#endif
23015+
23016+ if (addr) {
23017+ addr = PAGE_ALIGN(addr);
23018+ if (pax_task_size - len >= addr) {
23019+ vma = find_vma(mm, addr);
23020+ if (check_heap_stack_gap(vma, addr, len, offset))
23021+ return addr;
23022+ }
23023+ }
23024+
23025+ info.flags = 0;
23026+ info.length = len;
23027+ info.align_mask = filp ? get_align_mask() : 0;
23028+ info.align_offset = pgoff << PAGE_SHIFT;
23029+ info.threadstack_offset = offset;
23030+
23031+#ifdef CONFIG_PAX_PAGEEXEC
23032+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
23033+ info.low_limit = 0x00110000UL;
23034+ info.high_limit = mm->start_code;
23035+
23036+#ifdef CONFIG_PAX_RANDMMAP
23037+ if (mm->pax_flags & MF_PAX_RANDMMAP)
23038+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
23039+#endif
23040+
23041+ if (info.low_limit < info.high_limit) {
23042+ addr = vm_unmapped_area(&info);
23043+ if (!IS_ERR_VALUE(addr))
23044+ return addr;
23045+ }
23046+ } else
23047+#endif
23048+
23049+ info.low_limit = mm->mmap_base;
23050+ info.high_limit = pax_task_size;
23051+
23052+ return vm_unmapped_area(&info);
23053+}
23054+
23055+unsigned long
23056+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23057+ const unsigned long len, const unsigned long pgoff,
23058+ const unsigned long flags)
23059+{
23060+ struct vm_area_struct *vma;
23061+ struct mm_struct *mm = current->mm;
23062+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
23063+ struct vm_unmapped_area_info info;
23064+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23065+
23066+#ifdef CONFIG_PAX_SEGMEXEC
23067+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23068+ pax_task_size = SEGMEXEC_TASK_SIZE;
23069+#endif
23070+
23071+ pax_task_size -= PAGE_SIZE;
23072+
23073+ /* requested length too big for entire address space */
23074+ if (len > pax_task_size)
23075+ return -ENOMEM;
23076+
23077+ if (flags & MAP_FIXED)
23078+ return addr;
23079+
23080+#ifdef CONFIG_PAX_PAGEEXEC
23081+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23082+ goto bottomup;
23083+#endif
23084+
23085+#ifdef CONFIG_PAX_RANDMMAP
23086+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23087+#endif
23088+
23089+ /* requesting a specific address */
23090+ if (addr) {
23091+ addr = PAGE_ALIGN(addr);
23092+ if (pax_task_size - len >= addr) {
23093+ vma = find_vma(mm, addr);
23094+ if (check_heap_stack_gap(vma, addr, len, offset))
23095+ return addr;
23096+ }
23097+ }
23098+
23099+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
23100+ info.length = len;
23101+ info.low_limit = PAGE_SIZE;
23102+ info.high_limit = mm->mmap_base;
23103+ info.align_mask = filp ? get_align_mask() : 0;
23104+ info.align_offset = pgoff << PAGE_SHIFT;
23105+ info.threadstack_offset = offset;
23106+
23107+ addr = vm_unmapped_area(&info);
23108+ if (!(addr & ~PAGE_MASK))
23109+ return addr;
23110+ VM_BUG_ON(addr != -ENOMEM);
23111+
23112+bottomup:
23113+ /*
23114+ * A failed mmap() very likely causes application failure,
23115+ * so fall back to the bottom-up function here. This scenario
23116+ * can happen with large stack limits and large mmap()
23117+ * allocations.
23118+ */
23119+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23120+}
23121diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23122index dbded5a..ace2781 100644
23123--- a/arch/x86/kernel/sys_x86_64.c
23124+++ b/arch/x86/kernel/sys_x86_64.c
23125@@ -81,8 +81,8 @@ out:
23126 return error;
23127 }
23128
23129-static void find_start_end(unsigned long flags, unsigned long *begin,
23130- unsigned long *end)
23131+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23132+ unsigned long *begin, unsigned long *end)
23133 {
23134 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23135 unsigned long new_begin;
23136@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23137 *begin = new_begin;
23138 }
23139 } else {
23140- *begin = TASK_UNMAPPED_BASE;
23141+ *begin = mm->mmap_base;
23142 *end = TASK_SIZE;
23143 }
23144 }
23145@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23146 struct vm_area_struct *vma;
23147 struct vm_unmapped_area_info info;
23148 unsigned long begin, end;
23149+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23150
23151 if (flags & MAP_FIXED)
23152 return addr;
23153
23154- find_start_end(flags, &begin, &end);
23155+ find_start_end(mm, flags, &begin, &end);
23156
23157 if (len > end)
23158 return -ENOMEM;
23159
23160+#ifdef CONFIG_PAX_RANDMMAP
23161+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23162+#endif
23163+
23164 if (addr) {
23165 addr = PAGE_ALIGN(addr);
23166 vma = find_vma(mm, addr);
23167- if (end - len >= addr &&
23168- (!vma || addr + len <= vma->vm_start))
23169+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23170 return addr;
23171 }
23172
23173@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23174 info.high_limit = end;
23175 info.align_mask = filp ? get_align_mask() : 0;
23176 info.align_offset = pgoff << PAGE_SHIFT;
23177+ info.threadstack_offset = offset;
23178 return vm_unmapped_area(&info);
23179 }
23180
23181@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23182 struct mm_struct *mm = current->mm;
23183 unsigned long addr = addr0;
23184 struct vm_unmapped_area_info info;
23185+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23186
23187 /* requested length too big for entire address space */
23188 if (len > TASK_SIZE)
23189@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23190 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23191 goto bottomup;
23192
23193+#ifdef CONFIG_PAX_RANDMMAP
23194+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23195+#endif
23196+
23197 /* requesting a specific address */
23198 if (addr) {
23199 addr = PAGE_ALIGN(addr);
23200 vma = find_vma(mm, addr);
23201- if (TASK_SIZE - len >= addr &&
23202- (!vma || addr + len <= vma->vm_start))
23203+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23204 return addr;
23205 }
23206
23207@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23208 info.high_limit = mm->mmap_base;
23209 info.align_mask = filp ? get_align_mask() : 0;
23210 info.align_offset = pgoff << PAGE_SHIFT;
23211+ info.threadstack_offset = offset;
23212 addr = vm_unmapped_area(&info);
23213 if (!(addr & ~PAGE_MASK))
23214 return addr;
23215diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23216index f84fe00..f41d9f1 100644
23217--- a/arch/x86/kernel/tboot.c
23218+++ b/arch/x86/kernel/tboot.c
23219@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23220
23221 void tboot_shutdown(u32 shutdown_type)
23222 {
23223- void (*shutdown)(void);
23224+ void (* __noreturn shutdown)(void);
23225
23226 if (!tboot_enabled())
23227 return;
23228@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23229
23230 switch_to_tboot_pt();
23231
23232- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23233+ shutdown = (void *)tboot->shutdown_entry;
23234 shutdown();
23235
23236 /* should not reach here */
23237@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23238 return 0;
23239 }
23240
23241-static atomic_t ap_wfs_count;
23242+static atomic_unchecked_t ap_wfs_count;
23243
23244 static int tboot_wait_for_aps(int num_aps)
23245 {
23246@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23247 {
23248 switch (action) {
23249 case CPU_DYING:
23250- atomic_inc(&ap_wfs_count);
23251+ atomic_inc_unchecked(&ap_wfs_count);
23252 if (num_online_cpus() == 1)
23253- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23254+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23255 return NOTIFY_BAD;
23256 break;
23257 }
23258 return NOTIFY_OK;
23259 }
23260
23261-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23262+static struct notifier_block tboot_cpu_notifier =
23263 {
23264 .notifier_call = tboot_cpu_callback,
23265 };
23266@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23267
23268 tboot_create_trampoline();
23269
23270- atomic_set(&ap_wfs_count, 0);
23271+ atomic_set_unchecked(&ap_wfs_count, 0);
23272 register_hotcpu_notifier(&tboot_cpu_notifier);
23273
23274 acpi_os_set_prepare_sleep(&tboot_sleep);
23275diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23276index 24d3c91..d06b473 100644
23277--- a/arch/x86/kernel/time.c
23278+++ b/arch/x86/kernel/time.c
23279@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23280 {
23281 unsigned long pc = instruction_pointer(regs);
23282
23283- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23284+ if (!user_mode(regs) && in_lock_functions(pc)) {
23285 #ifdef CONFIG_FRAME_POINTER
23286- return *(unsigned long *)(regs->bp + sizeof(long));
23287+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23288 #else
23289 unsigned long *sp =
23290 (unsigned long *)kernel_stack_pointer(regs);
23291@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23292 * or above a saved flags. Eflags has bits 22-31 zero,
23293 * kernel addresses don't.
23294 */
23295+
23296+#ifdef CONFIG_PAX_KERNEXEC
23297+ return ktla_ktva(sp[0]);
23298+#else
23299 if (sp[0] >> 22)
23300 return sp[0];
23301 if (sp[1] >> 22)
23302 return sp[1];
23303 #endif
23304+
23305+#endif
23306 }
23307 return pc;
23308 }
23309diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23310index f7fec09..9991981 100644
23311--- a/arch/x86/kernel/tls.c
23312+++ b/arch/x86/kernel/tls.c
23313@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23314 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23315 return -EINVAL;
23316
23317+#ifdef CONFIG_PAX_SEGMEXEC
23318+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23319+ return -EINVAL;
23320+#endif
23321+
23322 set_tls_desc(p, idx, &info, 1);
23323
23324 return 0;
23325@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23326
23327 if (kbuf)
23328 info = kbuf;
23329- else if (__copy_from_user(infobuf, ubuf, count))
23330+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23331 return -EFAULT;
23332 else
23333 info = infobuf;
23334diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23335index 772e2a8..bad5bf6 100644
23336--- a/arch/x86/kernel/traps.c
23337+++ b/arch/x86/kernel/traps.c
23338@@ -68,12 +68,6 @@
23339 #include <asm/setup.h>
23340
23341 asmlinkage int system_call(void);
23342-
23343-/*
23344- * The IDT has to be page-aligned to simplify the Pentium
23345- * F0 0F bug workaround.
23346- */
23347-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23348 #endif
23349
23350 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23351@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23352 }
23353
23354 static int __kprobes
23355-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23356+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23357 struct pt_regs *regs, long error_code)
23358 {
23359 #ifdef CONFIG_X86_32
23360- if (regs->flags & X86_VM_MASK) {
23361+ if (v8086_mode(regs)) {
23362 /*
23363 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23364 * On nmi (interrupt 2), do_trap should not be called.
23365@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23366 return -1;
23367 }
23368 #endif
23369- if (!user_mode(regs)) {
23370+ if (!user_mode_novm(regs)) {
23371 if (!fixup_exception(regs)) {
23372 tsk->thread.error_code = error_code;
23373 tsk->thread.trap_nr = trapnr;
23374+
23375+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23376+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23377+ str = "PAX: suspicious stack segment fault";
23378+#endif
23379+
23380 die(str, regs, error_code);
23381 }
23382+
23383+#ifdef CONFIG_PAX_REFCOUNT
23384+ if (trapnr == 4)
23385+ pax_report_refcount_overflow(regs);
23386+#endif
23387+
23388 return 0;
23389 }
23390
23391@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23392 }
23393
23394 static void __kprobes
23395-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23396+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23397 long error_code, siginfo_t *info)
23398 {
23399 struct task_struct *tsk = current;
23400@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23401 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23402 printk_ratelimit()) {
23403 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23404- tsk->comm, tsk->pid, str,
23405+ tsk->comm, task_pid_nr(tsk), str,
23406 regs->ip, regs->sp, error_code);
23407 print_vma_addr(" in ", regs->ip);
23408 pr_cont("\n");
23409@@ -273,7 +279,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23410 conditional_sti(regs);
23411
23412 #ifdef CONFIG_X86_32
23413- if (regs->flags & X86_VM_MASK) {
23414+ if (v8086_mode(regs)) {
23415 local_irq_enable();
23416 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23417 goto exit;
23418@@ -281,18 +287,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23419 #endif
23420
23421 tsk = current;
23422- if (!user_mode(regs)) {
23423+ if (!user_mode_novm(regs)) {
23424 if (fixup_exception(regs))
23425 goto exit;
23426
23427 tsk->thread.error_code = error_code;
23428 tsk->thread.trap_nr = X86_TRAP_GP;
23429 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23430- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23431+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23432+
23433+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23434+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23435+ die("PAX: suspicious general protection fault", regs, error_code);
23436+ else
23437+#endif
23438+
23439 die("general protection fault", regs, error_code);
23440+ }
23441 goto exit;
23442 }
23443
23444+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23445+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23446+ struct mm_struct *mm = tsk->mm;
23447+ unsigned long limit;
23448+
23449+ down_write(&mm->mmap_sem);
23450+ limit = mm->context.user_cs_limit;
23451+ if (limit < TASK_SIZE) {
23452+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23453+ up_write(&mm->mmap_sem);
23454+ return;
23455+ }
23456+ up_write(&mm->mmap_sem);
23457+ }
23458+#endif
23459+
23460 tsk->thread.error_code = error_code;
23461 tsk->thread.trap_nr = X86_TRAP_GP;
23462
23463@@ -450,7 +480,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23464 /* It's safe to allow irq's after DR6 has been saved */
23465 preempt_conditional_sti(regs);
23466
23467- if (regs->flags & X86_VM_MASK) {
23468+ if (v8086_mode(regs)) {
23469 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23470 X86_TRAP_DB);
23471 preempt_conditional_cli(regs);
23472@@ -465,7 +495,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23473 * We already checked v86 mode above, so we can check for kernel mode
23474 * by just checking the CPL of CS.
23475 */
23476- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23477+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23478 tsk->thread.debugreg6 &= ~DR_STEP;
23479 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23480 regs->flags &= ~X86_EFLAGS_TF;
23481@@ -497,7 +527,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23482 return;
23483 conditional_sti(regs);
23484
23485- if (!user_mode_vm(regs))
23486+ if (!user_mode(regs))
23487 {
23488 if (!fixup_exception(regs)) {
23489 task->thread.error_code = error_code;
23490diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23491index 2ed8459..7cf329f 100644
23492--- a/arch/x86/kernel/uprobes.c
23493+++ b/arch/x86/kernel/uprobes.c
23494@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23495 int ret = NOTIFY_DONE;
23496
23497 /* We are only interested in userspace traps */
23498- if (regs && !user_mode_vm(regs))
23499+ if (regs && !user_mode(regs))
23500 return NOTIFY_DONE;
23501
23502 switch (val) {
23503@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
23504
23505 if (ncopied != rasize) {
23506 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
23507- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
23508+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
23509
23510 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
23511 }
23512diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23513index b9242ba..50c5edd 100644
23514--- a/arch/x86/kernel/verify_cpu.S
23515+++ b/arch/x86/kernel/verify_cpu.S
23516@@ -20,6 +20,7 @@
23517 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23518 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23519 * arch/x86/kernel/head_32.S: processor startup
23520+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23521 *
23522 * verify_cpu, returns the status of longmode and SSE in register %eax.
23523 * 0: Success 1: Failure
23524diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23525index e8edcf5..27f9344 100644
23526--- a/arch/x86/kernel/vm86_32.c
23527+++ b/arch/x86/kernel/vm86_32.c
23528@@ -44,6 +44,7 @@
23529 #include <linux/ptrace.h>
23530 #include <linux/audit.h>
23531 #include <linux/stddef.h>
23532+#include <linux/grsecurity.h>
23533
23534 #include <asm/uaccess.h>
23535 #include <asm/io.h>
23536@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23537 do_exit(SIGSEGV);
23538 }
23539
23540- tss = &per_cpu(init_tss, get_cpu());
23541+ tss = init_tss + get_cpu();
23542 current->thread.sp0 = current->thread.saved_sp0;
23543 current->thread.sysenter_cs = __KERNEL_CS;
23544 load_sp0(tss, &current->thread);
23545@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
23546
23547 if (tsk->thread.saved_sp0)
23548 return -EPERM;
23549+
23550+#ifdef CONFIG_GRKERNSEC_VM86
23551+ if (!capable(CAP_SYS_RAWIO)) {
23552+ gr_handle_vm86();
23553+ return -EPERM;
23554+ }
23555+#endif
23556+
23557 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
23558 offsetof(struct kernel_vm86_struct, vm86plus) -
23559 sizeof(info.regs));
23560@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
23561 int tmp;
23562 struct vm86plus_struct __user *v86;
23563
23564+#ifdef CONFIG_GRKERNSEC_VM86
23565+ if (!capable(CAP_SYS_RAWIO)) {
23566+ gr_handle_vm86();
23567+ return -EPERM;
23568+ }
23569+#endif
23570+
23571 tsk = current;
23572 switch (cmd) {
23573 case VM86_REQUEST_IRQ:
23574@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23575 tsk->thread.saved_fs = info->regs32->fs;
23576 tsk->thread.saved_gs = get_user_gs(info->regs32);
23577
23578- tss = &per_cpu(init_tss, get_cpu());
23579+ tss = init_tss + get_cpu();
23580 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23581 if (cpu_has_sep)
23582 tsk->thread.sysenter_cs = 0;
23583@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23584 goto cannot_handle;
23585 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23586 goto cannot_handle;
23587- intr_ptr = (unsigned long __user *) (i << 2);
23588+ intr_ptr = (__force unsigned long __user *) (i << 2);
23589 if (get_user(segoffs, intr_ptr))
23590 goto cannot_handle;
23591 if ((segoffs >> 16) == BIOSSEG)
23592diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23593index 10c4f30..57377c2 100644
23594--- a/arch/x86/kernel/vmlinux.lds.S
23595+++ b/arch/x86/kernel/vmlinux.lds.S
23596@@ -26,6 +26,13 @@
23597 #include <asm/page_types.h>
23598 #include <asm/cache.h>
23599 #include <asm/boot.h>
23600+#include <asm/segment.h>
23601+
23602+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23603+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23604+#else
23605+#define __KERNEL_TEXT_OFFSET 0
23606+#endif
23607
23608 #undef i386 /* in case the preprocessor is a 32bit one */
23609
23610@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23611
23612 PHDRS {
23613 text PT_LOAD FLAGS(5); /* R_E */
23614+#ifdef CONFIG_X86_32
23615+ module PT_LOAD FLAGS(5); /* R_E */
23616+#endif
23617+#ifdef CONFIG_XEN
23618+ rodata PT_LOAD FLAGS(5); /* R_E */
23619+#else
23620+ rodata PT_LOAD FLAGS(4); /* R__ */
23621+#endif
23622 data PT_LOAD FLAGS(6); /* RW_ */
23623-#ifdef CONFIG_X86_64
23624+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23625 #ifdef CONFIG_SMP
23626 percpu PT_LOAD FLAGS(6); /* RW_ */
23627 #endif
23628+ text.init PT_LOAD FLAGS(5); /* R_E */
23629+ text.exit PT_LOAD FLAGS(5); /* R_E */
23630 init PT_LOAD FLAGS(7); /* RWE */
23631-#endif
23632 note PT_NOTE FLAGS(0); /* ___ */
23633 }
23634
23635 SECTIONS
23636 {
23637 #ifdef CONFIG_X86_32
23638- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23639- phys_startup_32 = startup_32 - LOAD_OFFSET;
23640+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23641 #else
23642- . = __START_KERNEL;
23643- phys_startup_64 = startup_64 - LOAD_OFFSET;
23644+ . = __START_KERNEL;
23645 #endif
23646
23647 /* Text and read-only data */
23648- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23649- _text = .;
23650+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23651 /* bootstrapping code */
23652+#ifdef CONFIG_X86_32
23653+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23654+#else
23655+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23656+#endif
23657+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23658+ _text = .;
23659 HEAD_TEXT
23660 . = ALIGN(8);
23661 _stext = .;
23662@@ -104,13 +124,48 @@ SECTIONS
23663 IRQENTRY_TEXT
23664 *(.fixup)
23665 *(.gnu.warning)
23666- /* End of text section */
23667- _etext = .;
23668 } :text = 0x9090
23669
23670- NOTES :text :note
23671+ . += __KERNEL_TEXT_OFFSET;
23672
23673- EXCEPTION_TABLE(16) :text = 0x9090
23674+#ifdef CONFIG_X86_32
23675+ . = ALIGN(PAGE_SIZE);
23676+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23677+
23678+#ifdef CONFIG_PAX_KERNEXEC
23679+ MODULES_EXEC_VADDR = .;
23680+ BYTE(0)
23681+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23682+ . = ALIGN(HPAGE_SIZE) - 1;
23683+ MODULES_EXEC_END = .;
23684+#endif
23685+
23686+ } :module
23687+#endif
23688+
23689+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23690+ /* End of text section */
23691+ BYTE(0)
23692+ _etext = . - __KERNEL_TEXT_OFFSET;
23693+ }
23694+
23695+#ifdef CONFIG_X86_32
23696+ . = ALIGN(PAGE_SIZE);
23697+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23698+ *(.idt)
23699+ . = ALIGN(PAGE_SIZE);
23700+ *(.empty_zero_page)
23701+ *(.initial_pg_fixmap)
23702+ *(.initial_pg_pmd)
23703+ *(.initial_page_table)
23704+ *(.swapper_pg_dir)
23705+ } :rodata
23706+#endif
23707+
23708+ . = ALIGN(PAGE_SIZE);
23709+ NOTES :rodata :note
23710+
23711+ EXCEPTION_TABLE(16) :rodata
23712
23713 #if defined(CONFIG_DEBUG_RODATA)
23714 /* .text should occupy whole number of pages */
23715@@ -122,16 +177,20 @@ SECTIONS
23716
23717 /* Data */
23718 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23719+
23720+#ifdef CONFIG_PAX_KERNEXEC
23721+ . = ALIGN(HPAGE_SIZE);
23722+#else
23723+ . = ALIGN(PAGE_SIZE);
23724+#endif
23725+
23726 /* Start of data section */
23727 _sdata = .;
23728
23729 /* init_task */
23730 INIT_TASK_DATA(THREAD_SIZE)
23731
23732-#ifdef CONFIG_X86_32
23733- /* 32 bit has nosave before _edata */
23734 NOSAVE_DATA
23735-#endif
23736
23737 PAGE_ALIGNED_DATA(PAGE_SIZE)
23738
23739@@ -172,12 +231,19 @@ SECTIONS
23740 #endif /* CONFIG_X86_64 */
23741
23742 /* Init code and data - will be freed after init */
23743- . = ALIGN(PAGE_SIZE);
23744 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23745+ BYTE(0)
23746+
23747+#ifdef CONFIG_PAX_KERNEXEC
23748+ . = ALIGN(HPAGE_SIZE);
23749+#else
23750+ . = ALIGN(PAGE_SIZE);
23751+#endif
23752+
23753 __init_begin = .; /* paired with __init_end */
23754- }
23755+ } :init.begin
23756
23757-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23758+#ifdef CONFIG_SMP
23759 /*
23760 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23761 * output PHDR, so the next output section - .init.text - should
23762@@ -186,12 +252,27 @@ SECTIONS
23763 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23764 #endif
23765
23766- INIT_TEXT_SECTION(PAGE_SIZE)
23767-#ifdef CONFIG_X86_64
23768- :init
23769-#endif
23770+ . = ALIGN(PAGE_SIZE);
23771+ init_begin = .;
23772+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23773+ VMLINUX_SYMBOL(_sinittext) = .;
23774+ INIT_TEXT
23775+ VMLINUX_SYMBOL(_einittext) = .;
23776+ . = ALIGN(PAGE_SIZE);
23777+ } :text.init
23778
23779- INIT_DATA_SECTION(16)
23780+ /*
23781+ * .exit.text is discard at runtime, not link time, to deal with
23782+ * references from .altinstructions and .eh_frame
23783+ */
23784+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23785+ EXIT_TEXT
23786+ . = ALIGN(16);
23787+ } :text.exit
23788+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23789+
23790+ . = ALIGN(PAGE_SIZE);
23791+ INIT_DATA_SECTION(16) :init
23792
23793 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23794 __x86_cpu_dev_start = .;
23795@@ -253,19 +334,12 @@ SECTIONS
23796 }
23797
23798 . = ALIGN(8);
23799- /*
23800- * .exit.text is discard at runtime, not link time, to deal with
23801- * references from .altinstructions and .eh_frame
23802- */
23803- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23804- EXIT_TEXT
23805- }
23806
23807 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23808 EXIT_DATA
23809 }
23810
23811-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23812+#ifndef CONFIG_SMP
23813 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23814 #endif
23815
23816@@ -284,16 +358,10 @@ SECTIONS
23817 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23818 __smp_locks = .;
23819 *(.smp_locks)
23820- . = ALIGN(PAGE_SIZE);
23821 __smp_locks_end = .;
23822+ . = ALIGN(PAGE_SIZE);
23823 }
23824
23825-#ifdef CONFIG_X86_64
23826- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23827- NOSAVE_DATA
23828- }
23829-#endif
23830-
23831 /* BSS */
23832 . = ALIGN(PAGE_SIZE);
23833 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23834@@ -309,6 +377,7 @@ SECTIONS
23835 __brk_base = .;
23836 . += 64 * 1024; /* 64k alignment slop space */
23837 *(.brk_reservation) /* areas brk users have reserved */
23838+ . = ALIGN(HPAGE_SIZE);
23839 __brk_limit = .;
23840 }
23841
23842@@ -335,13 +404,12 @@ SECTIONS
23843 * for the boot processor.
23844 */
23845 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23846-INIT_PER_CPU(gdt_page);
23847 INIT_PER_CPU(irq_stack_union);
23848
23849 /*
23850 * Build-time check on the image size:
23851 */
23852-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23853+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23854 "kernel image bigger than KERNEL_IMAGE_SIZE");
23855
23856 #ifdef CONFIG_SMP
23857diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23858index 9a907a6..f83f921 100644
23859--- a/arch/x86/kernel/vsyscall_64.c
23860+++ b/arch/x86/kernel/vsyscall_64.c
23861@@ -56,15 +56,13 @@
23862 DEFINE_VVAR(int, vgetcpu_mode);
23863 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23864
23865-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23866+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23867
23868 static int __init vsyscall_setup(char *str)
23869 {
23870 if (str) {
23871 if (!strcmp("emulate", str))
23872 vsyscall_mode = EMULATE;
23873- else if (!strcmp("native", str))
23874- vsyscall_mode = NATIVE;
23875 else if (!strcmp("none", str))
23876 vsyscall_mode = NONE;
23877 else
23878@@ -323,8 +321,7 @@ do_ret:
23879 return true;
23880
23881 sigsegv:
23882- force_sig(SIGSEGV, current);
23883- return true;
23884+ do_group_exit(SIGKILL);
23885 }
23886
23887 /*
23888@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23889 extern char __vvar_page;
23890 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23891
23892- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23893- vsyscall_mode == NATIVE
23894- ? PAGE_KERNEL_VSYSCALL
23895- : PAGE_KERNEL_VVAR);
23896+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23897 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23898 (unsigned long)VSYSCALL_START);
23899
23900diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23901index b014d94..6d6ca7b 100644
23902--- a/arch/x86/kernel/x8664_ksyms_64.c
23903+++ b/arch/x86/kernel/x8664_ksyms_64.c
23904@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23905 EXPORT_SYMBOL(copy_user_generic_unrolled);
23906 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23907 EXPORT_SYMBOL(__copy_user_nocache);
23908-EXPORT_SYMBOL(_copy_from_user);
23909-EXPORT_SYMBOL(_copy_to_user);
23910
23911 EXPORT_SYMBOL(copy_page);
23912 EXPORT_SYMBOL(clear_page);
23913diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23914index 45a14db..075bb9b 100644
23915--- a/arch/x86/kernel/x86_init.c
23916+++ b/arch/x86/kernel/x86_init.c
23917@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
23918 },
23919 };
23920
23921-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23922+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23923 .early_percpu_clock_init = x86_init_noop,
23924 .setup_percpu_clockev = setup_secondary_APIC_clock,
23925 };
23926@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23927 static void default_nmi_init(void) { };
23928 static int default_i8042_detect(void) { return 1; };
23929
23930-struct x86_platform_ops x86_platform = {
23931+struct x86_platform_ops x86_platform __read_only = {
23932 .calibrate_tsc = native_calibrate_tsc,
23933 .get_wallclock = mach_get_cmos_time,
23934 .set_wallclock = mach_set_rtc_mmss,
23935@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
23936 };
23937
23938 EXPORT_SYMBOL_GPL(x86_platform);
23939-struct x86_msi_ops x86_msi = {
23940+struct x86_msi_ops x86_msi __read_only = {
23941 .setup_msi_irqs = native_setup_msi_irqs,
23942 .compose_msi_msg = native_compose_msi_msg,
23943 .teardown_msi_irq = native_teardown_msi_irq,
23944@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
23945 .setup_hpet_msi = default_setup_hpet_msi,
23946 };
23947
23948-struct x86_io_apic_ops x86_io_apic_ops = {
23949+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23950 .init = native_io_apic_init_mappings,
23951 .read = native_io_apic_read,
23952 .write = native_io_apic_write,
23953diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23954index ada87a3..afea76d 100644
23955--- a/arch/x86/kernel/xsave.c
23956+++ b/arch/x86/kernel/xsave.c
23957@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23958 {
23959 int err;
23960
23961+ buf = (struct xsave_struct __user *)____m(buf);
23962 if (use_xsave())
23963 err = xsave_user(buf);
23964 else if (use_fxsr())
23965@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23966 */
23967 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23968 {
23969+ buf = (void __user *)____m(buf);
23970 if (use_xsave()) {
23971 if ((unsigned long)buf % 64 || fx_only) {
23972 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23973diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23974index a20ecb5..d0e2194 100644
23975--- a/arch/x86/kvm/cpuid.c
23976+++ b/arch/x86/kvm/cpuid.c
23977@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23978 struct kvm_cpuid2 *cpuid,
23979 struct kvm_cpuid_entry2 __user *entries)
23980 {
23981- int r;
23982+ int r, i;
23983
23984 r = -E2BIG;
23985 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23986 goto out;
23987 r = -EFAULT;
23988- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23989- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23990+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23991 goto out;
23992+ for (i = 0; i < cpuid->nent; ++i) {
23993+ struct kvm_cpuid_entry2 cpuid_entry;
23994+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23995+ goto out;
23996+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23997+ }
23998 vcpu->arch.cpuid_nent = cpuid->nent;
23999 kvm_apic_set_version(vcpu);
24000 kvm_x86_ops->cpuid_update(vcpu);
24001@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
24002 struct kvm_cpuid2 *cpuid,
24003 struct kvm_cpuid_entry2 __user *entries)
24004 {
24005- int r;
24006+ int r, i;
24007
24008 r = -E2BIG;
24009 if (cpuid->nent < vcpu->arch.cpuid_nent)
24010 goto out;
24011 r = -EFAULT;
24012- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
24013- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24014+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
24015 goto out;
24016+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
24017+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
24018+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
24019+ goto out;
24020+ }
24021 return 0;
24022
24023 out:
24024diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
24025index 5953dce..f11a7d2 100644
24026--- a/arch/x86/kvm/emulate.c
24027+++ b/arch/x86/kvm/emulate.c
24028@@ -329,6 +329,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24029
24030 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
24031 do { \
24032+ unsigned long _tmp; \
24033 __asm__ __volatile__ ( \
24034 _PRE_EFLAGS("0", "4", "2") \
24035 _op _suffix " %"_x"3,%1; " \
24036@@ -343,8 +344,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24037 /* Raw emulation: instruction has two explicit operands. */
24038 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
24039 do { \
24040- unsigned long _tmp; \
24041- \
24042 switch ((ctxt)->dst.bytes) { \
24043 case 2: \
24044 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
24045@@ -360,7 +359,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
24046
24047 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
24048 do { \
24049- unsigned long _tmp; \
24050 switch ((ctxt)->dst.bytes) { \
24051 case 1: \
24052 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24053diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24054index 0eee2c8..94a32c3 100644
24055--- a/arch/x86/kvm/lapic.c
24056+++ b/arch/x86/kvm/lapic.c
24057@@ -55,7 +55,7 @@
24058 #define APIC_BUS_CYCLE_NS 1
24059
24060 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24061-#define apic_debug(fmt, arg...)
24062+#define apic_debug(fmt, arg...) do {} while (0)
24063
24064 #define APIC_LVT_NUM 6
24065 /* 14 is the version for Xeon and Pentium 8.4.8*/
24066diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24067index da20860..d19fdf5 100644
24068--- a/arch/x86/kvm/paging_tmpl.h
24069+++ b/arch/x86/kvm/paging_tmpl.h
24070@@ -208,7 +208,7 @@ retry_walk:
24071 if (unlikely(kvm_is_error_hva(host_addr)))
24072 goto error;
24073
24074- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24075+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24076 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24077 goto error;
24078 walker->ptep_user[walker->level - 1] = ptep_user;
24079diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24080index a14a6ea..dc86cf0 100644
24081--- a/arch/x86/kvm/svm.c
24082+++ b/arch/x86/kvm/svm.c
24083@@ -3493,7 +3493,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24084 int cpu = raw_smp_processor_id();
24085
24086 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24087+
24088+ pax_open_kernel();
24089 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24090+ pax_close_kernel();
24091+
24092 load_TR_desc();
24093 }
24094
24095@@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24096 #endif
24097 #endif
24098
24099+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24100+ __set_fs(current_thread_info()->addr_limit);
24101+#endif
24102+
24103 reload_tss(vcpu);
24104
24105 local_irq_disable();
24106diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24107index 5402c94..c3bdeee 100644
24108--- a/arch/x86/kvm/vmx.c
24109+++ b/arch/x86/kvm/vmx.c
24110@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24111 #endif
24112 }
24113
24114-static void vmcs_clear_bits(unsigned long field, u32 mask)
24115+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24116 {
24117 vmcs_writel(field, vmcs_readl(field) & ~mask);
24118 }
24119
24120-static void vmcs_set_bits(unsigned long field, u32 mask)
24121+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24122 {
24123 vmcs_writel(field, vmcs_readl(field) | mask);
24124 }
24125@@ -1517,7 +1517,11 @@ static void reload_tss(void)
24126 struct desc_struct *descs;
24127
24128 descs = (void *)gdt->address;
24129+
24130+ pax_open_kernel();
24131 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24132+ pax_close_kernel();
24133+
24134 load_TR_desc();
24135 }
24136
24137@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24138 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24139 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24140
24141+#ifdef CONFIG_PAX_PER_CPU_PGD
24142+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24143+#endif
24144+
24145 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24146 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24147 vmx->loaded_vmcs->cpu = cpu;
24148@@ -2935,8 +2943,11 @@ static __init int hardware_setup(void)
24149 if (!cpu_has_vmx_flexpriority())
24150 flexpriority_enabled = 0;
24151
24152- if (!cpu_has_vmx_tpr_shadow())
24153- kvm_x86_ops->update_cr8_intercept = NULL;
24154+ if (!cpu_has_vmx_tpr_shadow()) {
24155+ pax_open_kernel();
24156+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24157+ pax_close_kernel();
24158+ }
24159
24160 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24161 kvm_disable_largepages();
24162@@ -2947,13 +2958,15 @@ static __init int hardware_setup(void)
24163 if (!cpu_has_vmx_apicv())
24164 enable_apicv = 0;
24165
24166+ pax_open_kernel();
24167 if (enable_apicv)
24168- kvm_x86_ops->update_cr8_intercept = NULL;
24169+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24170 else {
24171- kvm_x86_ops->hwapic_irr_update = NULL;
24172- kvm_x86_ops->deliver_posted_interrupt = NULL;
24173- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
24174+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
24175+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
24176+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
24177 }
24178+ pax_close_kernel();
24179
24180 if (nested)
24181 nested_vmx_setup_ctls_msrs();
24182@@ -4076,7 +4089,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
24183
24184 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24185 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24186+
24187+#ifndef CONFIG_PAX_PER_CPU_PGD
24188 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24189+#endif
24190
24191 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24192 #ifdef CONFIG_X86_64
24193@@ -4098,7 +4114,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
24194 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24195 vmx->host_idt_base = dt.address;
24196
24197- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24198+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24199
24200 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24201 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24202@@ -7030,6 +7046,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24203 "jmp 2f \n\t"
24204 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24205 "2: "
24206+
24207+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24208+ "ljmp %[cs],$3f\n\t"
24209+ "3: "
24210+#endif
24211+
24212 /* Save guest registers, load host registers, keep flags */
24213 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24214 "pop %0 \n\t"
24215@@ -7082,6 +7104,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24216 #endif
24217 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24218 [wordsize]"i"(sizeof(ulong))
24219+
24220+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24221+ ,[cs]"i"(__KERNEL_CS)
24222+#endif
24223+
24224 : "cc", "memory"
24225 #ifdef CONFIG_X86_64
24226 , "rax", "rbx", "rdi", "rsi"
24227@@ -7095,7 +7122,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24228 if (debugctlmsr)
24229 update_debugctlmsr(debugctlmsr);
24230
24231-#ifndef CONFIG_X86_64
24232+#ifdef CONFIG_X86_32
24233 /*
24234 * The sysexit path does not restore ds/es, so we must set them to
24235 * a reasonable value ourselves.
24236@@ -7104,8 +7131,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24237 * may be executed in interrupt context, which saves and restore segments
24238 * around it, nullifying its effect.
24239 */
24240- loadsegment(ds, __USER_DS);
24241- loadsegment(es, __USER_DS);
24242+ loadsegment(ds, __KERNEL_DS);
24243+ loadsegment(es, __KERNEL_DS);
24244+ loadsegment(ss, __KERNEL_DS);
24245+
24246+#ifdef CONFIG_PAX_KERNEXEC
24247+ loadsegment(fs, __KERNEL_PERCPU);
24248+#endif
24249+
24250+#ifdef CONFIG_PAX_MEMORY_UDEREF
24251+ __set_fs(current_thread_info()->addr_limit);
24252+#endif
24253+
24254 #endif
24255
24256 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24257diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24258index e8ba99c..ee9d7d9 100644
24259--- a/arch/x86/kvm/x86.c
24260+++ b/arch/x86/kvm/x86.c
24261@@ -1725,8 +1725,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24262 {
24263 struct kvm *kvm = vcpu->kvm;
24264 int lm = is_long_mode(vcpu);
24265- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24266- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24267+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24268+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24269 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24270 : kvm->arch.xen_hvm_config.blob_size_32;
24271 u32 page_num = data & ~PAGE_MASK;
24272@@ -2609,6 +2609,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24273 if (n < msr_list.nmsrs)
24274 goto out;
24275 r = -EFAULT;
24276+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24277+ goto out;
24278 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24279 num_msrs_to_save * sizeof(u32)))
24280 goto out;
24281@@ -5297,7 +5299,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24282 };
24283 #endif
24284
24285-int kvm_arch_init(void *opaque)
24286+int kvm_arch_init(const void *opaque)
24287 {
24288 int r;
24289 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24290diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24291index 7114c63..a1018fc 100644
24292--- a/arch/x86/lguest/boot.c
24293+++ b/arch/x86/lguest/boot.c
24294@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24295 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24296 * Launcher to reboot us.
24297 */
24298-static void lguest_restart(char *reason)
24299+static __noreturn void lguest_restart(char *reason)
24300 {
24301 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24302+ BUG();
24303 }
24304
24305 /*G:050
24306diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24307index 00933d5..3a64af9 100644
24308--- a/arch/x86/lib/atomic64_386_32.S
24309+++ b/arch/x86/lib/atomic64_386_32.S
24310@@ -48,6 +48,10 @@ BEGIN(read)
24311 movl (v), %eax
24312 movl 4(v), %edx
24313 RET_ENDP
24314+BEGIN(read_unchecked)
24315+ movl (v), %eax
24316+ movl 4(v), %edx
24317+RET_ENDP
24318 #undef v
24319
24320 #define v %esi
24321@@ -55,6 +59,10 @@ BEGIN(set)
24322 movl %ebx, (v)
24323 movl %ecx, 4(v)
24324 RET_ENDP
24325+BEGIN(set_unchecked)
24326+ movl %ebx, (v)
24327+ movl %ecx, 4(v)
24328+RET_ENDP
24329 #undef v
24330
24331 #define v %esi
24332@@ -70,6 +78,20 @@ RET_ENDP
24333 BEGIN(add)
24334 addl %eax, (v)
24335 adcl %edx, 4(v)
24336+
24337+#ifdef CONFIG_PAX_REFCOUNT
24338+ jno 0f
24339+ subl %eax, (v)
24340+ sbbl %edx, 4(v)
24341+ int $4
24342+0:
24343+ _ASM_EXTABLE(0b, 0b)
24344+#endif
24345+
24346+RET_ENDP
24347+BEGIN(add_unchecked)
24348+ addl %eax, (v)
24349+ adcl %edx, 4(v)
24350 RET_ENDP
24351 #undef v
24352
24353@@ -77,6 +99,24 @@ RET_ENDP
24354 BEGIN(add_return)
24355 addl (v), %eax
24356 adcl 4(v), %edx
24357+
24358+#ifdef CONFIG_PAX_REFCOUNT
24359+ into
24360+1234:
24361+ _ASM_EXTABLE(1234b, 2f)
24362+#endif
24363+
24364+ movl %eax, (v)
24365+ movl %edx, 4(v)
24366+
24367+#ifdef CONFIG_PAX_REFCOUNT
24368+2:
24369+#endif
24370+
24371+RET_ENDP
24372+BEGIN(add_return_unchecked)
24373+ addl (v), %eax
24374+ adcl 4(v), %edx
24375 movl %eax, (v)
24376 movl %edx, 4(v)
24377 RET_ENDP
24378@@ -86,6 +126,20 @@ RET_ENDP
24379 BEGIN(sub)
24380 subl %eax, (v)
24381 sbbl %edx, 4(v)
24382+
24383+#ifdef CONFIG_PAX_REFCOUNT
24384+ jno 0f
24385+ addl %eax, (v)
24386+ adcl %edx, 4(v)
24387+ int $4
24388+0:
24389+ _ASM_EXTABLE(0b, 0b)
24390+#endif
24391+
24392+RET_ENDP
24393+BEGIN(sub_unchecked)
24394+ subl %eax, (v)
24395+ sbbl %edx, 4(v)
24396 RET_ENDP
24397 #undef v
24398
24399@@ -96,6 +150,27 @@ BEGIN(sub_return)
24400 sbbl $0, %edx
24401 addl (v), %eax
24402 adcl 4(v), %edx
24403+
24404+#ifdef CONFIG_PAX_REFCOUNT
24405+ into
24406+1234:
24407+ _ASM_EXTABLE(1234b, 2f)
24408+#endif
24409+
24410+ movl %eax, (v)
24411+ movl %edx, 4(v)
24412+
24413+#ifdef CONFIG_PAX_REFCOUNT
24414+2:
24415+#endif
24416+
24417+RET_ENDP
24418+BEGIN(sub_return_unchecked)
24419+ negl %edx
24420+ negl %eax
24421+ sbbl $0, %edx
24422+ addl (v), %eax
24423+ adcl 4(v), %edx
24424 movl %eax, (v)
24425 movl %edx, 4(v)
24426 RET_ENDP
24427@@ -105,6 +180,20 @@ RET_ENDP
24428 BEGIN(inc)
24429 addl $1, (v)
24430 adcl $0, 4(v)
24431+
24432+#ifdef CONFIG_PAX_REFCOUNT
24433+ jno 0f
24434+ subl $1, (v)
24435+ sbbl $0, 4(v)
24436+ int $4
24437+0:
24438+ _ASM_EXTABLE(0b, 0b)
24439+#endif
24440+
24441+RET_ENDP
24442+BEGIN(inc_unchecked)
24443+ addl $1, (v)
24444+ adcl $0, 4(v)
24445 RET_ENDP
24446 #undef v
24447
24448@@ -114,6 +203,26 @@ BEGIN(inc_return)
24449 movl 4(v), %edx
24450 addl $1, %eax
24451 adcl $0, %edx
24452+
24453+#ifdef CONFIG_PAX_REFCOUNT
24454+ into
24455+1234:
24456+ _ASM_EXTABLE(1234b, 2f)
24457+#endif
24458+
24459+ movl %eax, (v)
24460+ movl %edx, 4(v)
24461+
24462+#ifdef CONFIG_PAX_REFCOUNT
24463+2:
24464+#endif
24465+
24466+RET_ENDP
24467+BEGIN(inc_return_unchecked)
24468+ movl (v), %eax
24469+ movl 4(v), %edx
24470+ addl $1, %eax
24471+ adcl $0, %edx
24472 movl %eax, (v)
24473 movl %edx, 4(v)
24474 RET_ENDP
24475@@ -123,6 +232,20 @@ RET_ENDP
24476 BEGIN(dec)
24477 subl $1, (v)
24478 sbbl $0, 4(v)
24479+
24480+#ifdef CONFIG_PAX_REFCOUNT
24481+ jno 0f
24482+ addl $1, (v)
24483+ adcl $0, 4(v)
24484+ int $4
24485+0:
24486+ _ASM_EXTABLE(0b, 0b)
24487+#endif
24488+
24489+RET_ENDP
24490+BEGIN(dec_unchecked)
24491+ subl $1, (v)
24492+ sbbl $0, 4(v)
24493 RET_ENDP
24494 #undef v
24495
24496@@ -132,6 +255,26 @@ BEGIN(dec_return)
24497 movl 4(v), %edx
24498 subl $1, %eax
24499 sbbl $0, %edx
24500+
24501+#ifdef CONFIG_PAX_REFCOUNT
24502+ into
24503+1234:
24504+ _ASM_EXTABLE(1234b, 2f)
24505+#endif
24506+
24507+ movl %eax, (v)
24508+ movl %edx, 4(v)
24509+
24510+#ifdef CONFIG_PAX_REFCOUNT
24511+2:
24512+#endif
24513+
24514+RET_ENDP
24515+BEGIN(dec_return_unchecked)
24516+ movl (v), %eax
24517+ movl 4(v), %edx
24518+ subl $1, %eax
24519+ sbbl $0, %edx
24520 movl %eax, (v)
24521 movl %edx, 4(v)
24522 RET_ENDP
24523@@ -143,6 +286,13 @@ BEGIN(add_unless)
24524 adcl %edx, %edi
24525 addl (v), %eax
24526 adcl 4(v), %edx
24527+
24528+#ifdef CONFIG_PAX_REFCOUNT
24529+ into
24530+1234:
24531+ _ASM_EXTABLE(1234b, 2f)
24532+#endif
24533+
24534 cmpl %eax, %ecx
24535 je 3f
24536 1:
24537@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24538 1:
24539 addl $1, %eax
24540 adcl $0, %edx
24541+
24542+#ifdef CONFIG_PAX_REFCOUNT
24543+ into
24544+1234:
24545+ _ASM_EXTABLE(1234b, 2f)
24546+#endif
24547+
24548 movl %eax, (v)
24549 movl %edx, 4(v)
24550 movl $1, %eax
24551@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24552 movl 4(v), %edx
24553 subl $1, %eax
24554 sbbl $0, %edx
24555+
24556+#ifdef CONFIG_PAX_REFCOUNT
24557+ into
24558+1234:
24559+ _ASM_EXTABLE(1234b, 1f)
24560+#endif
24561+
24562 js 1f
24563 movl %eax, (v)
24564 movl %edx, 4(v)
24565diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24566index f5cc9eb..51fa319 100644
24567--- a/arch/x86/lib/atomic64_cx8_32.S
24568+++ b/arch/x86/lib/atomic64_cx8_32.S
24569@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24570 CFI_STARTPROC
24571
24572 read64 %ecx
24573+ pax_force_retaddr
24574 ret
24575 CFI_ENDPROC
24576 ENDPROC(atomic64_read_cx8)
24577
24578+ENTRY(atomic64_read_unchecked_cx8)
24579+ CFI_STARTPROC
24580+
24581+ read64 %ecx
24582+ pax_force_retaddr
24583+ ret
24584+ CFI_ENDPROC
24585+ENDPROC(atomic64_read_unchecked_cx8)
24586+
24587 ENTRY(atomic64_set_cx8)
24588 CFI_STARTPROC
24589
24590@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24591 cmpxchg8b (%esi)
24592 jne 1b
24593
24594+ pax_force_retaddr
24595 ret
24596 CFI_ENDPROC
24597 ENDPROC(atomic64_set_cx8)
24598
24599+ENTRY(atomic64_set_unchecked_cx8)
24600+ CFI_STARTPROC
24601+
24602+1:
24603+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24604+ * are atomic on 586 and newer */
24605+ cmpxchg8b (%esi)
24606+ jne 1b
24607+
24608+ pax_force_retaddr
24609+ ret
24610+ CFI_ENDPROC
24611+ENDPROC(atomic64_set_unchecked_cx8)
24612+
24613 ENTRY(atomic64_xchg_cx8)
24614 CFI_STARTPROC
24615
24616@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24617 cmpxchg8b (%esi)
24618 jne 1b
24619
24620+ pax_force_retaddr
24621 ret
24622 CFI_ENDPROC
24623 ENDPROC(atomic64_xchg_cx8)
24624
24625-.macro addsub_return func ins insc
24626-ENTRY(atomic64_\func\()_return_cx8)
24627+.macro addsub_return func ins insc unchecked=""
24628+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24629 CFI_STARTPROC
24630 SAVE ebp
24631 SAVE ebx
24632@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24633 movl %edx, %ecx
24634 \ins\()l %esi, %ebx
24635 \insc\()l %edi, %ecx
24636+
24637+.ifb \unchecked
24638+#ifdef CONFIG_PAX_REFCOUNT
24639+ into
24640+2:
24641+ _ASM_EXTABLE(2b, 3f)
24642+#endif
24643+.endif
24644+
24645 LOCK_PREFIX
24646 cmpxchg8b (%ebp)
24647 jne 1b
24648-
24649-10:
24650 movl %ebx, %eax
24651 movl %ecx, %edx
24652+
24653+.ifb \unchecked
24654+#ifdef CONFIG_PAX_REFCOUNT
24655+3:
24656+#endif
24657+.endif
24658+
24659 RESTORE edi
24660 RESTORE esi
24661 RESTORE ebx
24662 RESTORE ebp
24663+ pax_force_retaddr
24664 ret
24665 CFI_ENDPROC
24666-ENDPROC(atomic64_\func\()_return_cx8)
24667+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24668 .endm
24669
24670 addsub_return add add adc
24671 addsub_return sub sub sbb
24672+addsub_return add add adc _unchecked
24673+addsub_return sub sub sbb _unchecked
24674
24675-.macro incdec_return func ins insc
24676-ENTRY(atomic64_\func\()_return_cx8)
24677+.macro incdec_return func ins insc unchecked=""
24678+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24679 CFI_STARTPROC
24680 SAVE ebx
24681
24682@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24683 movl %edx, %ecx
24684 \ins\()l $1, %ebx
24685 \insc\()l $0, %ecx
24686+
24687+.ifb \unchecked
24688+#ifdef CONFIG_PAX_REFCOUNT
24689+ into
24690+2:
24691+ _ASM_EXTABLE(2b, 3f)
24692+#endif
24693+.endif
24694+
24695 LOCK_PREFIX
24696 cmpxchg8b (%esi)
24697 jne 1b
24698
24699-10:
24700 movl %ebx, %eax
24701 movl %ecx, %edx
24702+
24703+.ifb \unchecked
24704+#ifdef CONFIG_PAX_REFCOUNT
24705+3:
24706+#endif
24707+.endif
24708+
24709 RESTORE ebx
24710+ pax_force_retaddr
24711 ret
24712 CFI_ENDPROC
24713-ENDPROC(atomic64_\func\()_return_cx8)
24714+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24715 .endm
24716
24717 incdec_return inc add adc
24718 incdec_return dec sub sbb
24719+incdec_return inc add adc _unchecked
24720+incdec_return dec sub sbb _unchecked
24721
24722 ENTRY(atomic64_dec_if_positive_cx8)
24723 CFI_STARTPROC
24724@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24725 movl %edx, %ecx
24726 subl $1, %ebx
24727 sbb $0, %ecx
24728+
24729+#ifdef CONFIG_PAX_REFCOUNT
24730+ into
24731+1234:
24732+ _ASM_EXTABLE(1234b, 2f)
24733+#endif
24734+
24735 js 2f
24736 LOCK_PREFIX
24737 cmpxchg8b (%esi)
24738@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24739 movl %ebx, %eax
24740 movl %ecx, %edx
24741 RESTORE ebx
24742+ pax_force_retaddr
24743 ret
24744 CFI_ENDPROC
24745 ENDPROC(atomic64_dec_if_positive_cx8)
24746@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24747 movl %edx, %ecx
24748 addl %ebp, %ebx
24749 adcl %edi, %ecx
24750+
24751+#ifdef CONFIG_PAX_REFCOUNT
24752+ into
24753+1234:
24754+ _ASM_EXTABLE(1234b, 3f)
24755+#endif
24756+
24757 LOCK_PREFIX
24758 cmpxchg8b (%esi)
24759 jne 1b
24760@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24761 CFI_ADJUST_CFA_OFFSET -8
24762 RESTORE ebx
24763 RESTORE ebp
24764+ pax_force_retaddr
24765 ret
24766 4:
24767 cmpl %edx, 4(%esp)
24768@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24769 xorl %ecx, %ecx
24770 addl $1, %ebx
24771 adcl %edx, %ecx
24772+
24773+#ifdef CONFIG_PAX_REFCOUNT
24774+ into
24775+1234:
24776+ _ASM_EXTABLE(1234b, 3f)
24777+#endif
24778+
24779 LOCK_PREFIX
24780 cmpxchg8b (%esi)
24781 jne 1b
24782@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24783 movl $1, %eax
24784 3:
24785 RESTORE ebx
24786+ pax_force_retaddr
24787 ret
24788 CFI_ENDPROC
24789 ENDPROC(atomic64_inc_not_zero_cx8)
24790diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24791index e78b8ee..7e173a8 100644
24792--- a/arch/x86/lib/checksum_32.S
24793+++ b/arch/x86/lib/checksum_32.S
24794@@ -29,7 +29,8 @@
24795 #include <asm/dwarf2.h>
24796 #include <asm/errno.h>
24797 #include <asm/asm.h>
24798-
24799+#include <asm/segment.h>
24800+
24801 /*
24802 * computes a partial checksum, e.g. for TCP/UDP fragments
24803 */
24804@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24805
24806 #define ARGBASE 16
24807 #define FP 12
24808-
24809-ENTRY(csum_partial_copy_generic)
24810+
24811+ENTRY(csum_partial_copy_generic_to_user)
24812 CFI_STARTPROC
24813+
24814+#ifdef CONFIG_PAX_MEMORY_UDEREF
24815+ pushl_cfi %gs
24816+ popl_cfi %es
24817+ jmp csum_partial_copy_generic
24818+#endif
24819+
24820+ENTRY(csum_partial_copy_generic_from_user)
24821+
24822+#ifdef CONFIG_PAX_MEMORY_UDEREF
24823+ pushl_cfi %gs
24824+ popl_cfi %ds
24825+#endif
24826+
24827+ENTRY(csum_partial_copy_generic)
24828 subl $4,%esp
24829 CFI_ADJUST_CFA_OFFSET 4
24830 pushl_cfi %edi
24831@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24832 jmp 4f
24833 SRC(1: movw (%esi), %bx )
24834 addl $2, %esi
24835-DST( movw %bx, (%edi) )
24836+DST( movw %bx, %es:(%edi) )
24837 addl $2, %edi
24838 addw %bx, %ax
24839 adcl $0, %eax
24840@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24841 SRC(1: movl (%esi), %ebx )
24842 SRC( movl 4(%esi), %edx )
24843 adcl %ebx, %eax
24844-DST( movl %ebx, (%edi) )
24845+DST( movl %ebx, %es:(%edi) )
24846 adcl %edx, %eax
24847-DST( movl %edx, 4(%edi) )
24848+DST( movl %edx, %es:4(%edi) )
24849
24850 SRC( movl 8(%esi), %ebx )
24851 SRC( movl 12(%esi), %edx )
24852 adcl %ebx, %eax
24853-DST( movl %ebx, 8(%edi) )
24854+DST( movl %ebx, %es:8(%edi) )
24855 adcl %edx, %eax
24856-DST( movl %edx, 12(%edi) )
24857+DST( movl %edx, %es:12(%edi) )
24858
24859 SRC( movl 16(%esi), %ebx )
24860 SRC( movl 20(%esi), %edx )
24861 adcl %ebx, %eax
24862-DST( movl %ebx, 16(%edi) )
24863+DST( movl %ebx, %es:16(%edi) )
24864 adcl %edx, %eax
24865-DST( movl %edx, 20(%edi) )
24866+DST( movl %edx, %es:20(%edi) )
24867
24868 SRC( movl 24(%esi), %ebx )
24869 SRC( movl 28(%esi), %edx )
24870 adcl %ebx, %eax
24871-DST( movl %ebx, 24(%edi) )
24872+DST( movl %ebx, %es:24(%edi) )
24873 adcl %edx, %eax
24874-DST( movl %edx, 28(%edi) )
24875+DST( movl %edx, %es:28(%edi) )
24876
24877 lea 32(%esi), %esi
24878 lea 32(%edi), %edi
24879@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24880 shrl $2, %edx # This clears CF
24881 SRC(3: movl (%esi), %ebx )
24882 adcl %ebx, %eax
24883-DST( movl %ebx, (%edi) )
24884+DST( movl %ebx, %es:(%edi) )
24885 lea 4(%esi), %esi
24886 lea 4(%edi), %edi
24887 dec %edx
24888@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24889 jb 5f
24890 SRC( movw (%esi), %cx )
24891 leal 2(%esi), %esi
24892-DST( movw %cx, (%edi) )
24893+DST( movw %cx, %es:(%edi) )
24894 leal 2(%edi), %edi
24895 je 6f
24896 shll $16,%ecx
24897 SRC(5: movb (%esi), %cl )
24898-DST( movb %cl, (%edi) )
24899+DST( movb %cl, %es:(%edi) )
24900 6: addl %ecx, %eax
24901 adcl $0, %eax
24902 7:
24903@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24904
24905 6001:
24906 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24907- movl $-EFAULT, (%ebx)
24908+ movl $-EFAULT, %ss:(%ebx)
24909
24910 # zero the complete destination - computing the rest
24911 # is too much work
24912@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24913
24914 6002:
24915 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24916- movl $-EFAULT,(%ebx)
24917+ movl $-EFAULT,%ss:(%ebx)
24918 jmp 5000b
24919
24920 .previous
24921
24922+ pushl_cfi %ss
24923+ popl_cfi %ds
24924+ pushl_cfi %ss
24925+ popl_cfi %es
24926 popl_cfi %ebx
24927 CFI_RESTORE ebx
24928 popl_cfi %esi
24929@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24930 popl_cfi %ecx # equivalent to addl $4,%esp
24931 ret
24932 CFI_ENDPROC
24933-ENDPROC(csum_partial_copy_generic)
24934+ENDPROC(csum_partial_copy_generic_to_user)
24935
24936 #else
24937
24938 /* Version for PentiumII/PPro */
24939
24940 #define ROUND1(x) \
24941+ nop; nop; nop; \
24942 SRC(movl x(%esi), %ebx ) ; \
24943 addl %ebx, %eax ; \
24944- DST(movl %ebx, x(%edi) ) ;
24945+ DST(movl %ebx, %es:x(%edi)) ;
24946
24947 #define ROUND(x) \
24948+ nop; nop; nop; \
24949 SRC(movl x(%esi), %ebx ) ; \
24950 adcl %ebx, %eax ; \
24951- DST(movl %ebx, x(%edi) ) ;
24952+ DST(movl %ebx, %es:x(%edi)) ;
24953
24954 #define ARGBASE 12
24955-
24956-ENTRY(csum_partial_copy_generic)
24957+
24958+ENTRY(csum_partial_copy_generic_to_user)
24959 CFI_STARTPROC
24960+
24961+#ifdef CONFIG_PAX_MEMORY_UDEREF
24962+ pushl_cfi %gs
24963+ popl_cfi %es
24964+ jmp csum_partial_copy_generic
24965+#endif
24966+
24967+ENTRY(csum_partial_copy_generic_from_user)
24968+
24969+#ifdef CONFIG_PAX_MEMORY_UDEREF
24970+ pushl_cfi %gs
24971+ popl_cfi %ds
24972+#endif
24973+
24974+ENTRY(csum_partial_copy_generic)
24975 pushl_cfi %ebx
24976 CFI_REL_OFFSET ebx, 0
24977 pushl_cfi %edi
24978@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24979 subl %ebx, %edi
24980 lea -1(%esi),%edx
24981 andl $-32,%edx
24982- lea 3f(%ebx,%ebx), %ebx
24983+ lea 3f(%ebx,%ebx,2), %ebx
24984 testl %esi, %esi
24985 jmp *%ebx
24986 1: addl $64,%esi
24987@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24988 jb 5f
24989 SRC( movw (%esi), %dx )
24990 leal 2(%esi), %esi
24991-DST( movw %dx, (%edi) )
24992+DST( movw %dx, %es:(%edi) )
24993 leal 2(%edi), %edi
24994 je 6f
24995 shll $16,%edx
24996 5:
24997 SRC( movb (%esi), %dl )
24998-DST( movb %dl, (%edi) )
24999+DST( movb %dl, %es:(%edi) )
25000 6: addl %edx, %eax
25001 adcl $0, %eax
25002 7:
25003 .section .fixup, "ax"
25004 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
25005- movl $-EFAULT, (%ebx)
25006+ movl $-EFAULT, %ss:(%ebx)
25007 # zero the complete destination (computing the rest is too much work)
25008 movl ARGBASE+8(%esp),%edi # dst
25009 movl ARGBASE+12(%esp),%ecx # len
25010@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
25011 rep; stosb
25012 jmp 7b
25013 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
25014- movl $-EFAULT, (%ebx)
25015+ movl $-EFAULT, %ss:(%ebx)
25016 jmp 7b
25017 .previous
25018
25019+#ifdef CONFIG_PAX_MEMORY_UDEREF
25020+ pushl_cfi %ss
25021+ popl_cfi %ds
25022+ pushl_cfi %ss
25023+ popl_cfi %es
25024+#endif
25025+
25026 popl_cfi %esi
25027 CFI_RESTORE esi
25028 popl_cfi %edi
25029@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
25030 CFI_RESTORE ebx
25031 ret
25032 CFI_ENDPROC
25033-ENDPROC(csum_partial_copy_generic)
25034+ENDPROC(csum_partial_copy_generic_to_user)
25035
25036 #undef ROUND
25037 #undef ROUND1
25038diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
25039index f2145cf..cea889d 100644
25040--- a/arch/x86/lib/clear_page_64.S
25041+++ b/arch/x86/lib/clear_page_64.S
25042@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
25043 movl $4096/8,%ecx
25044 xorl %eax,%eax
25045 rep stosq
25046+ pax_force_retaddr
25047 ret
25048 CFI_ENDPROC
25049 ENDPROC(clear_page_c)
25050@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25051 movl $4096,%ecx
25052 xorl %eax,%eax
25053 rep stosb
25054+ pax_force_retaddr
25055 ret
25056 CFI_ENDPROC
25057 ENDPROC(clear_page_c_e)
25058@@ -43,6 +45,7 @@ ENTRY(clear_page)
25059 leaq 64(%rdi),%rdi
25060 jnz .Lloop
25061 nop
25062+ pax_force_retaddr
25063 ret
25064 CFI_ENDPROC
25065 .Lclear_page_end:
25066@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25067
25068 #include <asm/cpufeature.h>
25069
25070- .section .altinstr_replacement,"ax"
25071+ .section .altinstr_replacement,"a"
25072 1: .byte 0xeb /* jmp <disp8> */
25073 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25074 2: .byte 0xeb /* jmp <disp8> */
25075diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25076index 1e572c5..2a162cd 100644
25077--- a/arch/x86/lib/cmpxchg16b_emu.S
25078+++ b/arch/x86/lib/cmpxchg16b_emu.S
25079@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25080
25081 popf
25082 mov $1, %al
25083+ pax_force_retaddr
25084 ret
25085
25086 not_same:
25087 popf
25088 xor %al,%al
25089+ pax_force_retaddr
25090 ret
25091
25092 CFI_ENDPROC
25093diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25094index 176cca6..1166c50 100644
25095--- a/arch/x86/lib/copy_page_64.S
25096+++ b/arch/x86/lib/copy_page_64.S
25097@@ -9,6 +9,7 @@ copy_page_rep:
25098 CFI_STARTPROC
25099 movl $4096/8, %ecx
25100 rep movsq
25101+ pax_force_retaddr
25102 ret
25103 CFI_ENDPROC
25104 ENDPROC(copy_page_rep)
25105@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25106
25107 ENTRY(copy_page)
25108 CFI_STARTPROC
25109- subq $2*8, %rsp
25110- CFI_ADJUST_CFA_OFFSET 2*8
25111+ subq $3*8, %rsp
25112+ CFI_ADJUST_CFA_OFFSET 3*8
25113 movq %rbx, (%rsp)
25114 CFI_REL_OFFSET rbx, 0
25115 movq %r12, 1*8(%rsp)
25116 CFI_REL_OFFSET r12, 1*8
25117+ movq %r13, 2*8(%rsp)
25118+ CFI_REL_OFFSET r13, 2*8
25119
25120 movl $(4096/64)-5, %ecx
25121 .p2align 4
25122@@ -36,7 +39,7 @@ ENTRY(copy_page)
25123 movq 0x8*2(%rsi), %rdx
25124 movq 0x8*3(%rsi), %r8
25125 movq 0x8*4(%rsi), %r9
25126- movq 0x8*5(%rsi), %r10
25127+ movq 0x8*5(%rsi), %r13
25128 movq 0x8*6(%rsi), %r11
25129 movq 0x8*7(%rsi), %r12
25130
25131@@ -47,7 +50,7 @@ ENTRY(copy_page)
25132 movq %rdx, 0x8*2(%rdi)
25133 movq %r8, 0x8*3(%rdi)
25134 movq %r9, 0x8*4(%rdi)
25135- movq %r10, 0x8*5(%rdi)
25136+ movq %r13, 0x8*5(%rdi)
25137 movq %r11, 0x8*6(%rdi)
25138 movq %r12, 0x8*7(%rdi)
25139
25140@@ -66,7 +69,7 @@ ENTRY(copy_page)
25141 movq 0x8*2(%rsi), %rdx
25142 movq 0x8*3(%rsi), %r8
25143 movq 0x8*4(%rsi), %r9
25144- movq 0x8*5(%rsi), %r10
25145+ movq 0x8*5(%rsi), %r13
25146 movq 0x8*6(%rsi), %r11
25147 movq 0x8*7(%rsi), %r12
25148
25149@@ -75,7 +78,7 @@ ENTRY(copy_page)
25150 movq %rdx, 0x8*2(%rdi)
25151 movq %r8, 0x8*3(%rdi)
25152 movq %r9, 0x8*4(%rdi)
25153- movq %r10, 0x8*5(%rdi)
25154+ movq %r13, 0x8*5(%rdi)
25155 movq %r11, 0x8*6(%rdi)
25156 movq %r12, 0x8*7(%rdi)
25157
25158@@ -87,8 +90,11 @@ ENTRY(copy_page)
25159 CFI_RESTORE rbx
25160 movq 1*8(%rsp), %r12
25161 CFI_RESTORE r12
25162- addq $2*8, %rsp
25163- CFI_ADJUST_CFA_OFFSET -2*8
25164+ movq 2*8(%rsp), %r13
25165+ CFI_RESTORE r13
25166+ addq $3*8, %rsp
25167+ CFI_ADJUST_CFA_OFFSET -3*8
25168+ pax_force_retaddr
25169 ret
25170 .Lcopy_page_end:
25171 CFI_ENDPROC
25172@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25173
25174 #include <asm/cpufeature.h>
25175
25176- .section .altinstr_replacement,"ax"
25177+ .section .altinstr_replacement,"a"
25178 1: .byte 0xeb /* jmp <disp8> */
25179 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25180 2:
25181diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25182index a30ca15..d25fab6 100644
25183--- a/arch/x86/lib/copy_user_64.S
25184+++ b/arch/x86/lib/copy_user_64.S
25185@@ -18,6 +18,7 @@
25186 #include <asm/alternative-asm.h>
25187 #include <asm/asm.h>
25188 #include <asm/smap.h>
25189+#include <asm/pgtable.h>
25190
25191 /*
25192 * By placing feature2 after feature1 in altinstructions section, we logically
25193@@ -31,7 +32,7 @@
25194 .byte 0xe9 /* 32bit jump */
25195 .long \orig-1f /* by default jump to orig */
25196 1:
25197- .section .altinstr_replacement,"ax"
25198+ .section .altinstr_replacement,"a"
25199 2: .byte 0xe9 /* near jump with 32bit immediate */
25200 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25201 3: .byte 0xe9 /* near jump with 32bit immediate */
25202@@ -70,47 +71,20 @@
25203 #endif
25204 .endm
25205
25206-/* Standard copy_to_user with segment limit checking */
25207-ENTRY(_copy_to_user)
25208- CFI_STARTPROC
25209- GET_THREAD_INFO(%rax)
25210- movq %rdi,%rcx
25211- addq %rdx,%rcx
25212- jc bad_to_user
25213- cmpq TI_addr_limit(%rax),%rcx
25214- ja bad_to_user
25215- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25216- copy_user_generic_unrolled,copy_user_generic_string, \
25217- copy_user_enhanced_fast_string
25218- CFI_ENDPROC
25219-ENDPROC(_copy_to_user)
25220-
25221-/* Standard copy_from_user with segment limit checking */
25222-ENTRY(_copy_from_user)
25223- CFI_STARTPROC
25224- GET_THREAD_INFO(%rax)
25225- movq %rsi,%rcx
25226- addq %rdx,%rcx
25227- jc bad_from_user
25228- cmpq TI_addr_limit(%rax),%rcx
25229- ja bad_from_user
25230- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25231- copy_user_generic_unrolled,copy_user_generic_string, \
25232- copy_user_enhanced_fast_string
25233- CFI_ENDPROC
25234-ENDPROC(_copy_from_user)
25235-
25236 .section .fixup,"ax"
25237 /* must zero dest */
25238 ENTRY(bad_from_user)
25239 bad_from_user:
25240 CFI_STARTPROC
25241+ testl %edx,%edx
25242+ js bad_to_user
25243 movl %edx,%ecx
25244 xorl %eax,%eax
25245 rep
25246 stosb
25247 bad_to_user:
25248 movl %edx,%eax
25249+ pax_force_retaddr
25250 ret
25251 CFI_ENDPROC
25252 ENDPROC(bad_from_user)
25253@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25254 jz 17f
25255 1: movq (%rsi),%r8
25256 2: movq 1*8(%rsi),%r9
25257-3: movq 2*8(%rsi),%r10
25258+3: movq 2*8(%rsi),%rax
25259 4: movq 3*8(%rsi),%r11
25260 5: movq %r8,(%rdi)
25261 6: movq %r9,1*8(%rdi)
25262-7: movq %r10,2*8(%rdi)
25263+7: movq %rax,2*8(%rdi)
25264 8: movq %r11,3*8(%rdi)
25265 9: movq 4*8(%rsi),%r8
25266 10: movq 5*8(%rsi),%r9
25267-11: movq 6*8(%rsi),%r10
25268+11: movq 6*8(%rsi),%rax
25269 12: movq 7*8(%rsi),%r11
25270 13: movq %r8,4*8(%rdi)
25271 14: movq %r9,5*8(%rdi)
25272-15: movq %r10,6*8(%rdi)
25273+15: movq %rax,6*8(%rdi)
25274 16: movq %r11,7*8(%rdi)
25275 leaq 64(%rsi),%rsi
25276 leaq 64(%rdi),%rdi
25277@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25278 jnz 21b
25279 23: xor %eax,%eax
25280 ASM_CLAC
25281+ pax_force_retaddr
25282 ret
25283
25284 .section .fixup,"ax"
25285@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25286 movsb
25287 4: xorl %eax,%eax
25288 ASM_CLAC
25289+ pax_force_retaddr
25290 ret
25291
25292 .section .fixup,"ax"
25293@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25294 movsb
25295 2: xorl %eax,%eax
25296 ASM_CLAC
25297+ pax_force_retaddr
25298 ret
25299
25300 .section .fixup,"ax"
25301diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25302index 6a4f43c..f08b4a2 100644
25303--- a/arch/x86/lib/copy_user_nocache_64.S
25304+++ b/arch/x86/lib/copy_user_nocache_64.S
25305@@ -8,6 +8,7 @@
25306
25307 #include <linux/linkage.h>
25308 #include <asm/dwarf2.h>
25309+#include <asm/alternative-asm.h>
25310
25311 #define FIX_ALIGNMENT 1
25312
25313@@ -16,6 +17,7 @@
25314 #include <asm/thread_info.h>
25315 #include <asm/asm.h>
25316 #include <asm/smap.h>
25317+#include <asm/pgtable.h>
25318
25319 .macro ALIGN_DESTINATION
25320 #ifdef FIX_ALIGNMENT
25321@@ -49,6 +51,15 @@
25322 */
25323 ENTRY(__copy_user_nocache)
25324 CFI_STARTPROC
25325+
25326+#ifdef CONFIG_PAX_MEMORY_UDEREF
25327+ mov pax_user_shadow_base,%rcx
25328+ cmp %rcx,%rsi
25329+ jae 1f
25330+ add %rcx,%rsi
25331+1:
25332+#endif
25333+
25334 ASM_STAC
25335 cmpl $8,%edx
25336 jb 20f /* less then 8 bytes, go to byte copy loop */
25337@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25338 jz 17f
25339 1: movq (%rsi),%r8
25340 2: movq 1*8(%rsi),%r9
25341-3: movq 2*8(%rsi),%r10
25342+3: movq 2*8(%rsi),%rax
25343 4: movq 3*8(%rsi),%r11
25344 5: movnti %r8,(%rdi)
25345 6: movnti %r9,1*8(%rdi)
25346-7: movnti %r10,2*8(%rdi)
25347+7: movnti %rax,2*8(%rdi)
25348 8: movnti %r11,3*8(%rdi)
25349 9: movq 4*8(%rsi),%r8
25350 10: movq 5*8(%rsi),%r9
25351-11: movq 6*8(%rsi),%r10
25352+11: movq 6*8(%rsi),%rax
25353 12: movq 7*8(%rsi),%r11
25354 13: movnti %r8,4*8(%rdi)
25355 14: movnti %r9,5*8(%rdi)
25356-15: movnti %r10,6*8(%rdi)
25357+15: movnti %rax,6*8(%rdi)
25358 16: movnti %r11,7*8(%rdi)
25359 leaq 64(%rsi),%rsi
25360 leaq 64(%rdi),%rdi
25361@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25362 23: xorl %eax,%eax
25363 ASM_CLAC
25364 sfence
25365+ pax_force_retaddr
25366 ret
25367
25368 .section .fixup,"ax"
25369diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25370index 2419d5f..953ee51 100644
25371--- a/arch/x86/lib/csum-copy_64.S
25372+++ b/arch/x86/lib/csum-copy_64.S
25373@@ -9,6 +9,7 @@
25374 #include <asm/dwarf2.h>
25375 #include <asm/errno.h>
25376 #include <asm/asm.h>
25377+#include <asm/alternative-asm.h>
25378
25379 /*
25380 * Checksum copy with exception handling.
25381@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25382 CFI_RESTORE rbp
25383 addq $7*8, %rsp
25384 CFI_ADJUST_CFA_OFFSET -7*8
25385+ pax_force_retaddr 0, 1
25386 ret
25387 CFI_RESTORE_STATE
25388
25389diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25390index 25b7ae8..169fafc 100644
25391--- a/arch/x86/lib/csum-wrappers_64.c
25392+++ b/arch/x86/lib/csum-wrappers_64.c
25393@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25394 len -= 2;
25395 }
25396 }
25397- isum = csum_partial_copy_generic((__force const void *)src,
25398+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25399 dst, len, isum, errp, NULL);
25400 if (unlikely(*errp))
25401 goto out_err;
25402@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25403 }
25404
25405 *errp = 0;
25406- return csum_partial_copy_generic(src, (void __force *)dst,
25407+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25408 len, isum, NULL, errp);
25409 }
25410 EXPORT_SYMBOL(csum_partial_copy_to_user);
25411diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25412index a451235..79fb5cf 100644
25413--- a/arch/x86/lib/getuser.S
25414+++ b/arch/x86/lib/getuser.S
25415@@ -33,17 +33,40 @@
25416 #include <asm/thread_info.h>
25417 #include <asm/asm.h>
25418 #include <asm/smap.h>
25419+#include <asm/segment.h>
25420+#include <asm/pgtable.h>
25421+#include <asm/alternative-asm.h>
25422+
25423+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25424+#define __copyuser_seg gs;
25425+#else
25426+#define __copyuser_seg
25427+#endif
25428
25429 .text
25430 ENTRY(__get_user_1)
25431 CFI_STARTPROC
25432+
25433+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25434 GET_THREAD_INFO(%_ASM_DX)
25435 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25436 jae bad_get_user
25437 ASM_STAC
25438-1: movzbl (%_ASM_AX),%edx
25439+
25440+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25441+ mov pax_user_shadow_base,%_ASM_DX
25442+ cmp %_ASM_DX,%_ASM_AX
25443+ jae 1234f
25444+ add %_ASM_DX,%_ASM_AX
25445+1234:
25446+#endif
25447+
25448+#endif
25449+
25450+1: __copyuser_seg movzbl (%_ASM_AX),%edx
25451 xor %eax,%eax
25452 ASM_CLAC
25453+ pax_force_retaddr
25454 ret
25455 CFI_ENDPROC
25456 ENDPROC(__get_user_1)
25457@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
25458 ENTRY(__get_user_2)
25459 CFI_STARTPROC
25460 add $1,%_ASM_AX
25461+
25462+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25463 jc bad_get_user
25464 GET_THREAD_INFO(%_ASM_DX)
25465 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25466 jae bad_get_user
25467 ASM_STAC
25468-2: movzwl -1(%_ASM_AX),%edx
25469+
25470+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25471+ mov pax_user_shadow_base,%_ASM_DX
25472+ cmp %_ASM_DX,%_ASM_AX
25473+ jae 1234f
25474+ add %_ASM_DX,%_ASM_AX
25475+1234:
25476+#endif
25477+
25478+#endif
25479+
25480+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25481 xor %eax,%eax
25482 ASM_CLAC
25483+ pax_force_retaddr
25484 ret
25485 CFI_ENDPROC
25486 ENDPROC(__get_user_2)
25487@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
25488 ENTRY(__get_user_4)
25489 CFI_STARTPROC
25490 add $3,%_ASM_AX
25491+
25492+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25493 jc bad_get_user
25494 GET_THREAD_INFO(%_ASM_DX)
25495 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25496 jae bad_get_user
25497 ASM_STAC
25498-3: movl -3(%_ASM_AX),%edx
25499+
25500+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25501+ mov pax_user_shadow_base,%_ASM_DX
25502+ cmp %_ASM_DX,%_ASM_AX
25503+ jae 1234f
25504+ add %_ASM_DX,%_ASM_AX
25505+1234:
25506+#endif
25507+
25508+#endif
25509+
25510+3: __copyuser_seg movl -3(%_ASM_AX),%edx
25511 xor %eax,%eax
25512 ASM_CLAC
25513+ pax_force_retaddr
25514 ret
25515 CFI_ENDPROC
25516 ENDPROC(__get_user_4)
25517@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
25518 GET_THREAD_INFO(%_ASM_DX)
25519 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25520 jae bad_get_user
25521+
25522+#ifdef CONFIG_PAX_MEMORY_UDEREF
25523+ mov pax_user_shadow_base,%_ASM_DX
25524+ cmp %_ASM_DX,%_ASM_AX
25525+ jae 1234f
25526+ add %_ASM_DX,%_ASM_AX
25527+1234:
25528+#endif
25529+
25530 ASM_STAC
25531 4: movq -7(%_ASM_AX),%rdx
25532 xor %eax,%eax
25533 ASM_CLAC
25534+ pax_force_retaddr
25535 ret
25536 #else
25537 add $7,%_ASM_AX
25538@@ -102,6 +163,7 @@ ENTRY(__get_user_8)
25539 5: movl -3(%_ASM_AX),%ecx
25540 xor %eax,%eax
25541 ASM_CLAC
25542+ pax_force_retaddr
25543 ret
25544 #endif
25545 CFI_ENDPROC
25546@@ -113,6 +175,7 @@ bad_get_user:
25547 xor %edx,%edx
25548 mov $(-EFAULT),%_ASM_AX
25549 ASM_CLAC
25550+ pax_force_retaddr
25551 ret
25552 CFI_ENDPROC
25553 END(bad_get_user)
25554@@ -124,6 +187,7 @@ bad_get_user_8:
25555 xor %ecx,%ecx
25556 mov $(-EFAULT),%_ASM_AX
25557 ASM_CLAC
25558+ pax_force_retaddr
25559 ret
25560 CFI_ENDPROC
25561 END(bad_get_user_8)
25562diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25563index 54fcffe..7be149e 100644
25564--- a/arch/x86/lib/insn.c
25565+++ b/arch/x86/lib/insn.c
25566@@ -20,8 +20,10 @@
25567
25568 #ifdef __KERNEL__
25569 #include <linux/string.h>
25570+#include <asm/pgtable_types.h>
25571 #else
25572 #include <string.h>
25573+#define ktla_ktva(addr) addr
25574 #endif
25575 #include <asm/inat.h>
25576 #include <asm/insn.h>
25577@@ -53,8 +55,8 @@
25578 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25579 {
25580 memset(insn, 0, sizeof(*insn));
25581- insn->kaddr = kaddr;
25582- insn->next_byte = kaddr;
25583+ insn->kaddr = ktla_ktva(kaddr);
25584+ insn->next_byte = ktla_ktva(kaddr);
25585 insn->x86_64 = x86_64 ? 1 : 0;
25586 insn->opnd_bytes = 4;
25587 if (x86_64)
25588diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25589index 05a95e7..326f2fa 100644
25590--- a/arch/x86/lib/iomap_copy_64.S
25591+++ b/arch/x86/lib/iomap_copy_64.S
25592@@ -17,6 +17,7 @@
25593
25594 #include <linux/linkage.h>
25595 #include <asm/dwarf2.h>
25596+#include <asm/alternative-asm.h>
25597
25598 /*
25599 * override generic version in lib/iomap_copy.c
25600@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25601 CFI_STARTPROC
25602 movl %edx,%ecx
25603 rep movsd
25604+ pax_force_retaddr
25605 ret
25606 CFI_ENDPROC
25607 ENDPROC(__iowrite32_copy)
25608diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25609index 56313a3..aa84a79 100644
25610--- a/arch/x86/lib/memcpy_64.S
25611+++ b/arch/x86/lib/memcpy_64.S
25612@@ -33,6 +33,7 @@
25613 rep movsq
25614 movl %edx, %ecx
25615 rep movsb
25616+ pax_force_retaddr
25617 ret
25618 .Lmemcpy_e:
25619 .previous
25620@@ -49,6 +50,7 @@
25621 movq %rdi, %rax
25622 movq %rdx, %rcx
25623 rep movsb
25624+ pax_force_retaddr
25625 ret
25626 .Lmemcpy_e_e:
25627 .previous
25628@@ -76,13 +78,13 @@ ENTRY(memcpy)
25629 */
25630 movq 0*8(%rsi), %r8
25631 movq 1*8(%rsi), %r9
25632- movq 2*8(%rsi), %r10
25633+ movq 2*8(%rsi), %rcx
25634 movq 3*8(%rsi), %r11
25635 leaq 4*8(%rsi), %rsi
25636
25637 movq %r8, 0*8(%rdi)
25638 movq %r9, 1*8(%rdi)
25639- movq %r10, 2*8(%rdi)
25640+ movq %rcx, 2*8(%rdi)
25641 movq %r11, 3*8(%rdi)
25642 leaq 4*8(%rdi), %rdi
25643 jae .Lcopy_forward_loop
25644@@ -105,12 +107,12 @@ ENTRY(memcpy)
25645 subq $0x20, %rdx
25646 movq -1*8(%rsi), %r8
25647 movq -2*8(%rsi), %r9
25648- movq -3*8(%rsi), %r10
25649+ movq -3*8(%rsi), %rcx
25650 movq -4*8(%rsi), %r11
25651 leaq -4*8(%rsi), %rsi
25652 movq %r8, -1*8(%rdi)
25653 movq %r9, -2*8(%rdi)
25654- movq %r10, -3*8(%rdi)
25655+ movq %rcx, -3*8(%rdi)
25656 movq %r11, -4*8(%rdi)
25657 leaq -4*8(%rdi), %rdi
25658 jae .Lcopy_backward_loop
25659@@ -130,12 +132,13 @@ ENTRY(memcpy)
25660 */
25661 movq 0*8(%rsi), %r8
25662 movq 1*8(%rsi), %r9
25663- movq -2*8(%rsi, %rdx), %r10
25664+ movq -2*8(%rsi, %rdx), %rcx
25665 movq -1*8(%rsi, %rdx), %r11
25666 movq %r8, 0*8(%rdi)
25667 movq %r9, 1*8(%rdi)
25668- movq %r10, -2*8(%rdi, %rdx)
25669+ movq %rcx, -2*8(%rdi, %rdx)
25670 movq %r11, -1*8(%rdi, %rdx)
25671+ pax_force_retaddr
25672 retq
25673 .p2align 4
25674 .Lless_16bytes:
25675@@ -148,6 +151,7 @@ ENTRY(memcpy)
25676 movq -1*8(%rsi, %rdx), %r9
25677 movq %r8, 0*8(%rdi)
25678 movq %r9, -1*8(%rdi, %rdx)
25679+ pax_force_retaddr
25680 retq
25681 .p2align 4
25682 .Lless_8bytes:
25683@@ -161,6 +165,7 @@ ENTRY(memcpy)
25684 movl -4(%rsi, %rdx), %r8d
25685 movl %ecx, (%rdi)
25686 movl %r8d, -4(%rdi, %rdx)
25687+ pax_force_retaddr
25688 retq
25689 .p2align 4
25690 .Lless_3bytes:
25691@@ -179,6 +184,7 @@ ENTRY(memcpy)
25692 movb %cl, (%rdi)
25693
25694 .Lend:
25695+ pax_force_retaddr
25696 retq
25697 CFI_ENDPROC
25698 ENDPROC(memcpy)
25699diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25700index 65268a6..c9518d1 100644
25701--- a/arch/x86/lib/memmove_64.S
25702+++ b/arch/x86/lib/memmove_64.S
25703@@ -61,13 +61,13 @@ ENTRY(memmove)
25704 5:
25705 sub $0x20, %rdx
25706 movq 0*8(%rsi), %r11
25707- movq 1*8(%rsi), %r10
25708+ movq 1*8(%rsi), %rcx
25709 movq 2*8(%rsi), %r9
25710 movq 3*8(%rsi), %r8
25711 leaq 4*8(%rsi), %rsi
25712
25713 movq %r11, 0*8(%rdi)
25714- movq %r10, 1*8(%rdi)
25715+ movq %rcx, 1*8(%rdi)
25716 movq %r9, 2*8(%rdi)
25717 movq %r8, 3*8(%rdi)
25718 leaq 4*8(%rdi), %rdi
25719@@ -81,10 +81,10 @@ ENTRY(memmove)
25720 4:
25721 movq %rdx, %rcx
25722 movq -8(%rsi, %rdx), %r11
25723- lea -8(%rdi, %rdx), %r10
25724+ lea -8(%rdi, %rdx), %r9
25725 shrq $3, %rcx
25726 rep movsq
25727- movq %r11, (%r10)
25728+ movq %r11, (%r9)
25729 jmp 13f
25730 .Lmemmove_end_forward:
25731
25732@@ -95,14 +95,14 @@ ENTRY(memmove)
25733 7:
25734 movq %rdx, %rcx
25735 movq (%rsi), %r11
25736- movq %rdi, %r10
25737+ movq %rdi, %r9
25738 leaq -8(%rsi, %rdx), %rsi
25739 leaq -8(%rdi, %rdx), %rdi
25740 shrq $3, %rcx
25741 std
25742 rep movsq
25743 cld
25744- movq %r11, (%r10)
25745+ movq %r11, (%r9)
25746 jmp 13f
25747
25748 /*
25749@@ -127,13 +127,13 @@ ENTRY(memmove)
25750 8:
25751 subq $0x20, %rdx
25752 movq -1*8(%rsi), %r11
25753- movq -2*8(%rsi), %r10
25754+ movq -2*8(%rsi), %rcx
25755 movq -3*8(%rsi), %r9
25756 movq -4*8(%rsi), %r8
25757 leaq -4*8(%rsi), %rsi
25758
25759 movq %r11, -1*8(%rdi)
25760- movq %r10, -2*8(%rdi)
25761+ movq %rcx, -2*8(%rdi)
25762 movq %r9, -3*8(%rdi)
25763 movq %r8, -4*8(%rdi)
25764 leaq -4*8(%rdi), %rdi
25765@@ -151,11 +151,11 @@ ENTRY(memmove)
25766 * Move data from 16 bytes to 31 bytes.
25767 */
25768 movq 0*8(%rsi), %r11
25769- movq 1*8(%rsi), %r10
25770+ movq 1*8(%rsi), %rcx
25771 movq -2*8(%rsi, %rdx), %r9
25772 movq -1*8(%rsi, %rdx), %r8
25773 movq %r11, 0*8(%rdi)
25774- movq %r10, 1*8(%rdi)
25775+ movq %rcx, 1*8(%rdi)
25776 movq %r9, -2*8(%rdi, %rdx)
25777 movq %r8, -1*8(%rdi, %rdx)
25778 jmp 13f
25779@@ -167,9 +167,9 @@ ENTRY(memmove)
25780 * Move data from 8 bytes to 15 bytes.
25781 */
25782 movq 0*8(%rsi), %r11
25783- movq -1*8(%rsi, %rdx), %r10
25784+ movq -1*8(%rsi, %rdx), %r9
25785 movq %r11, 0*8(%rdi)
25786- movq %r10, -1*8(%rdi, %rdx)
25787+ movq %r9, -1*8(%rdi, %rdx)
25788 jmp 13f
25789 10:
25790 cmpq $4, %rdx
25791@@ -178,9 +178,9 @@ ENTRY(memmove)
25792 * Move data from 4 bytes to 7 bytes.
25793 */
25794 movl (%rsi), %r11d
25795- movl -4(%rsi, %rdx), %r10d
25796+ movl -4(%rsi, %rdx), %r9d
25797 movl %r11d, (%rdi)
25798- movl %r10d, -4(%rdi, %rdx)
25799+ movl %r9d, -4(%rdi, %rdx)
25800 jmp 13f
25801 11:
25802 cmp $2, %rdx
25803@@ -189,9 +189,9 @@ ENTRY(memmove)
25804 * Move data from 2 bytes to 3 bytes.
25805 */
25806 movw (%rsi), %r11w
25807- movw -2(%rsi, %rdx), %r10w
25808+ movw -2(%rsi, %rdx), %r9w
25809 movw %r11w, (%rdi)
25810- movw %r10w, -2(%rdi, %rdx)
25811+ movw %r9w, -2(%rdi, %rdx)
25812 jmp 13f
25813 12:
25814 cmp $1, %rdx
25815@@ -202,6 +202,7 @@ ENTRY(memmove)
25816 movb (%rsi), %r11b
25817 movb %r11b, (%rdi)
25818 13:
25819+ pax_force_retaddr
25820 retq
25821 CFI_ENDPROC
25822
25823@@ -210,6 +211,7 @@ ENTRY(memmove)
25824 /* Forward moving data. */
25825 movq %rdx, %rcx
25826 rep movsb
25827+ pax_force_retaddr
25828 retq
25829 .Lmemmove_end_forward_efs:
25830 .previous
25831diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25832index 2dcb380..963660a 100644
25833--- a/arch/x86/lib/memset_64.S
25834+++ b/arch/x86/lib/memset_64.S
25835@@ -30,6 +30,7 @@
25836 movl %edx,%ecx
25837 rep stosb
25838 movq %r9,%rax
25839+ pax_force_retaddr
25840 ret
25841 .Lmemset_e:
25842 .previous
25843@@ -52,6 +53,7 @@
25844 movq %rdx,%rcx
25845 rep stosb
25846 movq %r9,%rax
25847+ pax_force_retaddr
25848 ret
25849 .Lmemset_e_e:
25850 .previous
25851@@ -59,7 +61,7 @@
25852 ENTRY(memset)
25853 ENTRY(__memset)
25854 CFI_STARTPROC
25855- movq %rdi,%r10
25856+ movq %rdi,%r11
25857
25858 /* expand byte value */
25859 movzbl %sil,%ecx
25860@@ -117,7 +119,8 @@ ENTRY(__memset)
25861 jnz .Lloop_1
25862
25863 .Lende:
25864- movq %r10,%rax
25865+ movq %r11,%rax
25866+ pax_force_retaddr
25867 ret
25868
25869 CFI_RESTORE_STATE
25870diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25871index c9f2d9b..e7fd2c0 100644
25872--- a/arch/x86/lib/mmx_32.c
25873+++ b/arch/x86/lib/mmx_32.c
25874@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25875 {
25876 void *p;
25877 int i;
25878+ unsigned long cr0;
25879
25880 if (unlikely(in_interrupt()))
25881 return __memcpy(to, from, len);
25882@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25883 kernel_fpu_begin();
25884
25885 __asm__ __volatile__ (
25886- "1: prefetch (%0)\n" /* This set is 28 bytes */
25887- " prefetch 64(%0)\n"
25888- " prefetch 128(%0)\n"
25889- " prefetch 192(%0)\n"
25890- " prefetch 256(%0)\n"
25891+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25892+ " prefetch 64(%1)\n"
25893+ " prefetch 128(%1)\n"
25894+ " prefetch 192(%1)\n"
25895+ " prefetch 256(%1)\n"
25896 "2: \n"
25897 ".section .fixup, \"ax\"\n"
25898- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25899+ "3: \n"
25900+
25901+#ifdef CONFIG_PAX_KERNEXEC
25902+ " movl %%cr0, %0\n"
25903+ " movl %0, %%eax\n"
25904+ " andl $0xFFFEFFFF, %%eax\n"
25905+ " movl %%eax, %%cr0\n"
25906+#endif
25907+
25908+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25909+
25910+#ifdef CONFIG_PAX_KERNEXEC
25911+ " movl %0, %%cr0\n"
25912+#endif
25913+
25914 " jmp 2b\n"
25915 ".previous\n"
25916 _ASM_EXTABLE(1b, 3b)
25917- : : "r" (from));
25918+ : "=&r" (cr0) : "r" (from) : "ax");
25919
25920 for ( ; i > 5; i--) {
25921 __asm__ __volatile__ (
25922- "1: prefetch 320(%0)\n"
25923- "2: movq (%0), %%mm0\n"
25924- " movq 8(%0), %%mm1\n"
25925- " movq 16(%0), %%mm2\n"
25926- " movq 24(%0), %%mm3\n"
25927- " movq %%mm0, (%1)\n"
25928- " movq %%mm1, 8(%1)\n"
25929- " movq %%mm2, 16(%1)\n"
25930- " movq %%mm3, 24(%1)\n"
25931- " movq 32(%0), %%mm0\n"
25932- " movq 40(%0), %%mm1\n"
25933- " movq 48(%0), %%mm2\n"
25934- " movq 56(%0), %%mm3\n"
25935- " movq %%mm0, 32(%1)\n"
25936- " movq %%mm1, 40(%1)\n"
25937- " movq %%mm2, 48(%1)\n"
25938- " movq %%mm3, 56(%1)\n"
25939+ "1: prefetch 320(%1)\n"
25940+ "2: movq (%1), %%mm0\n"
25941+ " movq 8(%1), %%mm1\n"
25942+ " movq 16(%1), %%mm2\n"
25943+ " movq 24(%1), %%mm3\n"
25944+ " movq %%mm0, (%2)\n"
25945+ " movq %%mm1, 8(%2)\n"
25946+ " movq %%mm2, 16(%2)\n"
25947+ " movq %%mm3, 24(%2)\n"
25948+ " movq 32(%1), %%mm0\n"
25949+ " movq 40(%1), %%mm1\n"
25950+ " movq 48(%1), %%mm2\n"
25951+ " movq 56(%1), %%mm3\n"
25952+ " movq %%mm0, 32(%2)\n"
25953+ " movq %%mm1, 40(%2)\n"
25954+ " movq %%mm2, 48(%2)\n"
25955+ " movq %%mm3, 56(%2)\n"
25956 ".section .fixup, \"ax\"\n"
25957- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25958+ "3:\n"
25959+
25960+#ifdef CONFIG_PAX_KERNEXEC
25961+ " movl %%cr0, %0\n"
25962+ " movl %0, %%eax\n"
25963+ " andl $0xFFFEFFFF, %%eax\n"
25964+ " movl %%eax, %%cr0\n"
25965+#endif
25966+
25967+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25968+
25969+#ifdef CONFIG_PAX_KERNEXEC
25970+ " movl %0, %%cr0\n"
25971+#endif
25972+
25973 " jmp 2b\n"
25974 ".previous\n"
25975 _ASM_EXTABLE(1b, 3b)
25976- : : "r" (from), "r" (to) : "memory");
25977+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25978
25979 from += 64;
25980 to += 64;
25981@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25982 static void fast_copy_page(void *to, void *from)
25983 {
25984 int i;
25985+ unsigned long cr0;
25986
25987 kernel_fpu_begin();
25988
25989@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25990 * but that is for later. -AV
25991 */
25992 __asm__ __volatile__(
25993- "1: prefetch (%0)\n"
25994- " prefetch 64(%0)\n"
25995- " prefetch 128(%0)\n"
25996- " prefetch 192(%0)\n"
25997- " prefetch 256(%0)\n"
25998+ "1: prefetch (%1)\n"
25999+ " prefetch 64(%1)\n"
26000+ " prefetch 128(%1)\n"
26001+ " prefetch 192(%1)\n"
26002+ " prefetch 256(%1)\n"
26003 "2: \n"
26004 ".section .fixup, \"ax\"\n"
26005- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26006+ "3: \n"
26007+
26008+#ifdef CONFIG_PAX_KERNEXEC
26009+ " movl %%cr0, %0\n"
26010+ " movl %0, %%eax\n"
26011+ " andl $0xFFFEFFFF, %%eax\n"
26012+ " movl %%eax, %%cr0\n"
26013+#endif
26014+
26015+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26016+
26017+#ifdef CONFIG_PAX_KERNEXEC
26018+ " movl %0, %%cr0\n"
26019+#endif
26020+
26021 " jmp 2b\n"
26022 ".previous\n"
26023- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26024+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26025
26026 for (i = 0; i < (4096-320)/64; i++) {
26027 __asm__ __volatile__ (
26028- "1: prefetch 320(%0)\n"
26029- "2: movq (%0), %%mm0\n"
26030- " movntq %%mm0, (%1)\n"
26031- " movq 8(%0), %%mm1\n"
26032- " movntq %%mm1, 8(%1)\n"
26033- " movq 16(%0), %%mm2\n"
26034- " movntq %%mm2, 16(%1)\n"
26035- " movq 24(%0), %%mm3\n"
26036- " movntq %%mm3, 24(%1)\n"
26037- " movq 32(%0), %%mm4\n"
26038- " movntq %%mm4, 32(%1)\n"
26039- " movq 40(%0), %%mm5\n"
26040- " movntq %%mm5, 40(%1)\n"
26041- " movq 48(%0), %%mm6\n"
26042- " movntq %%mm6, 48(%1)\n"
26043- " movq 56(%0), %%mm7\n"
26044- " movntq %%mm7, 56(%1)\n"
26045+ "1: prefetch 320(%1)\n"
26046+ "2: movq (%1), %%mm0\n"
26047+ " movntq %%mm0, (%2)\n"
26048+ " movq 8(%1), %%mm1\n"
26049+ " movntq %%mm1, 8(%2)\n"
26050+ " movq 16(%1), %%mm2\n"
26051+ " movntq %%mm2, 16(%2)\n"
26052+ " movq 24(%1), %%mm3\n"
26053+ " movntq %%mm3, 24(%2)\n"
26054+ " movq 32(%1), %%mm4\n"
26055+ " movntq %%mm4, 32(%2)\n"
26056+ " movq 40(%1), %%mm5\n"
26057+ " movntq %%mm5, 40(%2)\n"
26058+ " movq 48(%1), %%mm6\n"
26059+ " movntq %%mm6, 48(%2)\n"
26060+ " movq 56(%1), %%mm7\n"
26061+ " movntq %%mm7, 56(%2)\n"
26062 ".section .fixup, \"ax\"\n"
26063- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26064+ "3:\n"
26065+
26066+#ifdef CONFIG_PAX_KERNEXEC
26067+ " movl %%cr0, %0\n"
26068+ " movl %0, %%eax\n"
26069+ " andl $0xFFFEFFFF, %%eax\n"
26070+ " movl %%eax, %%cr0\n"
26071+#endif
26072+
26073+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26074+
26075+#ifdef CONFIG_PAX_KERNEXEC
26076+ " movl %0, %%cr0\n"
26077+#endif
26078+
26079 " jmp 2b\n"
26080 ".previous\n"
26081- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26082+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26083
26084 from += 64;
26085 to += 64;
26086@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26087 static void fast_copy_page(void *to, void *from)
26088 {
26089 int i;
26090+ unsigned long cr0;
26091
26092 kernel_fpu_begin();
26093
26094 __asm__ __volatile__ (
26095- "1: prefetch (%0)\n"
26096- " prefetch 64(%0)\n"
26097- " prefetch 128(%0)\n"
26098- " prefetch 192(%0)\n"
26099- " prefetch 256(%0)\n"
26100+ "1: prefetch (%1)\n"
26101+ " prefetch 64(%1)\n"
26102+ " prefetch 128(%1)\n"
26103+ " prefetch 192(%1)\n"
26104+ " prefetch 256(%1)\n"
26105 "2: \n"
26106 ".section .fixup, \"ax\"\n"
26107- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26108+ "3: \n"
26109+
26110+#ifdef CONFIG_PAX_KERNEXEC
26111+ " movl %%cr0, %0\n"
26112+ " movl %0, %%eax\n"
26113+ " andl $0xFFFEFFFF, %%eax\n"
26114+ " movl %%eax, %%cr0\n"
26115+#endif
26116+
26117+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26118+
26119+#ifdef CONFIG_PAX_KERNEXEC
26120+ " movl %0, %%cr0\n"
26121+#endif
26122+
26123 " jmp 2b\n"
26124 ".previous\n"
26125- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26126+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26127
26128 for (i = 0; i < 4096/64; i++) {
26129 __asm__ __volatile__ (
26130- "1: prefetch 320(%0)\n"
26131- "2: movq (%0), %%mm0\n"
26132- " movq 8(%0), %%mm1\n"
26133- " movq 16(%0), %%mm2\n"
26134- " movq 24(%0), %%mm3\n"
26135- " movq %%mm0, (%1)\n"
26136- " movq %%mm1, 8(%1)\n"
26137- " movq %%mm2, 16(%1)\n"
26138- " movq %%mm3, 24(%1)\n"
26139- " movq 32(%0), %%mm0\n"
26140- " movq 40(%0), %%mm1\n"
26141- " movq 48(%0), %%mm2\n"
26142- " movq 56(%0), %%mm3\n"
26143- " movq %%mm0, 32(%1)\n"
26144- " movq %%mm1, 40(%1)\n"
26145- " movq %%mm2, 48(%1)\n"
26146- " movq %%mm3, 56(%1)\n"
26147+ "1: prefetch 320(%1)\n"
26148+ "2: movq (%1), %%mm0\n"
26149+ " movq 8(%1), %%mm1\n"
26150+ " movq 16(%1), %%mm2\n"
26151+ " movq 24(%1), %%mm3\n"
26152+ " movq %%mm0, (%2)\n"
26153+ " movq %%mm1, 8(%2)\n"
26154+ " movq %%mm2, 16(%2)\n"
26155+ " movq %%mm3, 24(%2)\n"
26156+ " movq 32(%1), %%mm0\n"
26157+ " movq 40(%1), %%mm1\n"
26158+ " movq 48(%1), %%mm2\n"
26159+ " movq 56(%1), %%mm3\n"
26160+ " movq %%mm0, 32(%2)\n"
26161+ " movq %%mm1, 40(%2)\n"
26162+ " movq %%mm2, 48(%2)\n"
26163+ " movq %%mm3, 56(%2)\n"
26164 ".section .fixup, \"ax\"\n"
26165- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26166+ "3:\n"
26167+
26168+#ifdef CONFIG_PAX_KERNEXEC
26169+ " movl %%cr0, %0\n"
26170+ " movl %0, %%eax\n"
26171+ " andl $0xFFFEFFFF, %%eax\n"
26172+ " movl %%eax, %%cr0\n"
26173+#endif
26174+
26175+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26176+
26177+#ifdef CONFIG_PAX_KERNEXEC
26178+ " movl %0, %%cr0\n"
26179+#endif
26180+
26181 " jmp 2b\n"
26182 ".previous\n"
26183 _ASM_EXTABLE(1b, 3b)
26184- : : "r" (from), "r" (to) : "memory");
26185+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26186
26187 from += 64;
26188 to += 64;
26189diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26190index f6d13ee..aca5f0b 100644
26191--- a/arch/x86/lib/msr-reg.S
26192+++ b/arch/x86/lib/msr-reg.S
26193@@ -3,6 +3,7 @@
26194 #include <asm/dwarf2.h>
26195 #include <asm/asm.h>
26196 #include <asm/msr.h>
26197+#include <asm/alternative-asm.h>
26198
26199 #ifdef CONFIG_X86_64
26200 /*
26201@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26202 CFI_STARTPROC
26203 pushq_cfi %rbx
26204 pushq_cfi %rbp
26205- movq %rdi, %r10 /* Save pointer */
26206+ movq %rdi, %r9 /* Save pointer */
26207 xorl %r11d, %r11d /* Return value */
26208 movl (%rdi), %eax
26209 movl 4(%rdi), %ecx
26210@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26211 movl 28(%rdi), %edi
26212 CFI_REMEMBER_STATE
26213 1: \op
26214-2: movl %eax, (%r10)
26215+2: movl %eax, (%r9)
26216 movl %r11d, %eax /* Return value */
26217- movl %ecx, 4(%r10)
26218- movl %edx, 8(%r10)
26219- movl %ebx, 12(%r10)
26220- movl %ebp, 20(%r10)
26221- movl %esi, 24(%r10)
26222- movl %edi, 28(%r10)
26223+ movl %ecx, 4(%r9)
26224+ movl %edx, 8(%r9)
26225+ movl %ebx, 12(%r9)
26226+ movl %ebp, 20(%r9)
26227+ movl %esi, 24(%r9)
26228+ movl %edi, 28(%r9)
26229 popq_cfi %rbp
26230 popq_cfi %rbx
26231+ pax_force_retaddr
26232 ret
26233 3:
26234 CFI_RESTORE_STATE
26235diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26236index fc6ba17..d4d989d 100644
26237--- a/arch/x86/lib/putuser.S
26238+++ b/arch/x86/lib/putuser.S
26239@@ -16,7 +16,9 @@
26240 #include <asm/errno.h>
26241 #include <asm/asm.h>
26242 #include <asm/smap.h>
26243-
26244+#include <asm/segment.h>
26245+#include <asm/pgtable.h>
26246+#include <asm/alternative-asm.h>
26247
26248 /*
26249 * __put_user_X
26250@@ -30,57 +32,125 @@
26251 * as they get called from within inline assembly.
26252 */
26253
26254-#define ENTER CFI_STARTPROC ; \
26255- GET_THREAD_INFO(%_ASM_BX)
26256-#define EXIT ASM_CLAC ; \
26257- ret ; \
26258+#define ENTER CFI_STARTPROC
26259+#define EXIT ASM_CLAC ; \
26260+ pax_force_retaddr ; \
26261+ ret ; \
26262 CFI_ENDPROC
26263
26264+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26265+#define _DEST %_ASM_CX,%_ASM_BX
26266+#else
26267+#define _DEST %_ASM_CX
26268+#endif
26269+
26270+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26271+#define __copyuser_seg gs;
26272+#else
26273+#define __copyuser_seg
26274+#endif
26275+
26276 .text
26277 ENTRY(__put_user_1)
26278 ENTER
26279+
26280+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26281+ GET_THREAD_INFO(%_ASM_BX)
26282 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26283 jae bad_put_user
26284 ASM_STAC
26285-1: movb %al,(%_ASM_CX)
26286+
26287+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26288+ mov pax_user_shadow_base,%_ASM_BX
26289+ cmp %_ASM_BX,%_ASM_CX
26290+ jb 1234f
26291+ xor %ebx,%ebx
26292+1234:
26293+#endif
26294+
26295+#endif
26296+
26297+1: __copyuser_seg movb %al,(_DEST)
26298 xor %eax,%eax
26299 EXIT
26300 ENDPROC(__put_user_1)
26301
26302 ENTRY(__put_user_2)
26303 ENTER
26304+
26305+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26306+ GET_THREAD_INFO(%_ASM_BX)
26307 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26308 sub $1,%_ASM_BX
26309 cmp %_ASM_BX,%_ASM_CX
26310 jae bad_put_user
26311 ASM_STAC
26312-2: movw %ax,(%_ASM_CX)
26313+
26314+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26315+ mov pax_user_shadow_base,%_ASM_BX
26316+ cmp %_ASM_BX,%_ASM_CX
26317+ jb 1234f
26318+ xor %ebx,%ebx
26319+1234:
26320+#endif
26321+
26322+#endif
26323+
26324+2: __copyuser_seg movw %ax,(_DEST)
26325 xor %eax,%eax
26326 EXIT
26327 ENDPROC(__put_user_2)
26328
26329 ENTRY(__put_user_4)
26330 ENTER
26331+
26332+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26333+ GET_THREAD_INFO(%_ASM_BX)
26334 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26335 sub $3,%_ASM_BX
26336 cmp %_ASM_BX,%_ASM_CX
26337 jae bad_put_user
26338 ASM_STAC
26339-3: movl %eax,(%_ASM_CX)
26340+
26341+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26342+ mov pax_user_shadow_base,%_ASM_BX
26343+ cmp %_ASM_BX,%_ASM_CX
26344+ jb 1234f
26345+ xor %ebx,%ebx
26346+1234:
26347+#endif
26348+
26349+#endif
26350+
26351+3: __copyuser_seg movl %eax,(_DEST)
26352 xor %eax,%eax
26353 EXIT
26354 ENDPROC(__put_user_4)
26355
26356 ENTRY(__put_user_8)
26357 ENTER
26358+
26359+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26360+ GET_THREAD_INFO(%_ASM_BX)
26361 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26362 sub $7,%_ASM_BX
26363 cmp %_ASM_BX,%_ASM_CX
26364 jae bad_put_user
26365 ASM_STAC
26366-4: mov %_ASM_AX,(%_ASM_CX)
26367+
26368+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26369+ mov pax_user_shadow_base,%_ASM_BX
26370+ cmp %_ASM_BX,%_ASM_CX
26371+ jb 1234f
26372+ xor %ebx,%ebx
26373+1234:
26374+#endif
26375+
26376+#endif
26377+
26378+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26379 #ifdef CONFIG_X86_32
26380-5: movl %edx,4(%_ASM_CX)
26381+5: __copyuser_seg movl %edx,4(_DEST)
26382 #endif
26383 xor %eax,%eax
26384 EXIT
26385diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26386index 1cad221..de671ee 100644
26387--- a/arch/x86/lib/rwlock.S
26388+++ b/arch/x86/lib/rwlock.S
26389@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26390 FRAME
26391 0: LOCK_PREFIX
26392 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26393+
26394+#ifdef CONFIG_PAX_REFCOUNT
26395+ jno 1234f
26396+ LOCK_PREFIX
26397+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26398+ int $4
26399+1234:
26400+ _ASM_EXTABLE(1234b, 1234b)
26401+#endif
26402+
26403 1: rep; nop
26404 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26405 jne 1b
26406 LOCK_PREFIX
26407 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26408+
26409+#ifdef CONFIG_PAX_REFCOUNT
26410+ jno 1234f
26411+ LOCK_PREFIX
26412+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26413+ int $4
26414+1234:
26415+ _ASM_EXTABLE(1234b, 1234b)
26416+#endif
26417+
26418 jnz 0b
26419 ENDFRAME
26420+ pax_force_retaddr
26421 ret
26422 CFI_ENDPROC
26423 END(__write_lock_failed)
26424@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26425 FRAME
26426 0: LOCK_PREFIX
26427 READ_LOCK_SIZE(inc) (%__lock_ptr)
26428+
26429+#ifdef CONFIG_PAX_REFCOUNT
26430+ jno 1234f
26431+ LOCK_PREFIX
26432+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26433+ int $4
26434+1234:
26435+ _ASM_EXTABLE(1234b, 1234b)
26436+#endif
26437+
26438 1: rep; nop
26439 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26440 js 1b
26441 LOCK_PREFIX
26442 READ_LOCK_SIZE(dec) (%__lock_ptr)
26443+
26444+#ifdef CONFIG_PAX_REFCOUNT
26445+ jno 1234f
26446+ LOCK_PREFIX
26447+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26448+ int $4
26449+1234:
26450+ _ASM_EXTABLE(1234b, 1234b)
26451+#endif
26452+
26453 js 0b
26454 ENDFRAME
26455+ pax_force_retaddr
26456 ret
26457 CFI_ENDPROC
26458 END(__read_lock_failed)
26459diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26460index 5dff5f0..cadebf4 100644
26461--- a/arch/x86/lib/rwsem.S
26462+++ b/arch/x86/lib/rwsem.S
26463@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26464 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26465 CFI_RESTORE __ASM_REG(dx)
26466 restore_common_regs
26467+ pax_force_retaddr
26468 ret
26469 CFI_ENDPROC
26470 ENDPROC(call_rwsem_down_read_failed)
26471@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26472 movq %rax,%rdi
26473 call rwsem_down_write_failed
26474 restore_common_regs
26475+ pax_force_retaddr
26476 ret
26477 CFI_ENDPROC
26478 ENDPROC(call_rwsem_down_write_failed)
26479@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26480 movq %rax,%rdi
26481 call rwsem_wake
26482 restore_common_regs
26483-1: ret
26484+1: pax_force_retaddr
26485+ ret
26486 CFI_ENDPROC
26487 ENDPROC(call_rwsem_wake)
26488
26489@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26490 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26491 CFI_RESTORE __ASM_REG(dx)
26492 restore_common_regs
26493+ pax_force_retaddr
26494 ret
26495 CFI_ENDPROC
26496 ENDPROC(call_rwsem_downgrade_wake)
26497diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26498index a63efd6..ccecad8 100644
26499--- a/arch/x86/lib/thunk_64.S
26500+++ b/arch/x86/lib/thunk_64.S
26501@@ -8,6 +8,7 @@
26502 #include <linux/linkage.h>
26503 #include <asm/dwarf2.h>
26504 #include <asm/calling.h>
26505+#include <asm/alternative-asm.h>
26506
26507 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26508 .macro THUNK name, func, put_ret_addr_in_rdi=0
26509@@ -41,5 +42,6 @@
26510 SAVE_ARGS
26511 restore:
26512 RESTORE_ARGS
26513+ pax_force_retaddr
26514 ret
26515 CFI_ENDPROC
26516diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26517index 3eb18ac..6890bc3 100644
26518--- a/arch/x86/lib/usercopy_32.c
26519+++ b/arch/x86/lib/usercopy_32.c
26520@@ -42,11 +42,13 @@ do { \
26521 int __d0; \
26522 might_fault(); \
26523 __asm__ __volatile__( \
26524+ __COPYUSER_SET_ES \
26525 ASM_STAC "\n" \
26526 "0: rep; stosl\n" \
26527 " movl %2,%0\n" \
26528 "1: rep; stosb\n" \
26529 "2: " ASM_CLAC "\n" \
26530+ __COPYUSER_RESTORE_ES \
26531 ".section .fixup,\"ax\"\n" \
26532 "3: lea 0(%2,%0,4),%0\n" \
26533 " jmp 2b\n" \
26534@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26535
26536 #ifdef CONFIG_X86_INTEL_USERCOPY
26537 static unsigned long
26538-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26539+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26540 {
26541 int d0, d1;
26542 __asm__ __volatile__(
26543@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26544 " .align 2,0x90\n"
26545 "3: movl 0(%4), %%eax\n"
26546 "4: movl 4(%4), %%edx\n"
26547- "5: movl %%eax, 0(%3)\n"
26548- "6: movl %%edx, 4(%3)\n"
26549+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26550+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26551 "7: movl 8(%4), %%eax\n"
26552 "8: movl 12(%4),%%edx\n"
26553- "9: movl %%eax, 8(%3)\n"
26554- "10: movl %%edx, 12(%3)\n"
26555+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26556+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26557 "11: movl 16(%4), %%eax\n"
26558 "12: movl 20(%4), %%edx\n"
26559- "13: movl %%eax, 16(%3)\n"
26560- "14: movl %%edx, 20(%3)\n"
26561+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26562+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26563 "15: movl 24(%4), %%eax\n"
26564 "16: movl 28(%4), %%edx\n"
26565- "17: movl %%eax, 24(%3)\n"
26566- "18: movl %%edx, 28(%3)\n"
26567+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26568+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26569 "19: movl 32(%4), %%eax\n"
26570 "20: movl 36(%4), %%edx\n"
26571- "21: movl %%eax, 32(%3)\n"
26572- "22: movl %%edx, 36(%3)\n"
26573+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26574+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26575 "23: movl 40(%4), %%eax\n"
26576 "24: movl 44(%4), %%edx\n"
26577- "25: movl %%eax, 40(%3)\n"
26578- "26: movl %%edx, 44(%3)\n"
26579+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26580+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26581 "27: movl 48(%4), %%eax\n"
26582 "28: movl 52(%4), %%edx\n"
26583- "29: movl %%eax, 48(%3)\n"
26584- "30: movl %%edx, 52(%3)\n"
26585+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26586+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26587 "31: movl 56(%4), %%eax\n"
26588 "32: movl 60(%4), %%edx\n"
26589- "33: movl %%eax, 56(%3)\n"
26590- "34: movl %%edx, 60(%3)\n"
26591+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26592+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26593 " addl $-64, %0\n"
26594 " addl $64, %4\n"
26595 " addl $64, %3\n"
26596@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26597 " shrl $2, %0\n"
26598 " andl $3, %%eax\n"
26599 " cld\n"
26600+ __COPYUSER_SET_ES
26601 "99: rep; movsl\n"
26602 "36: movl %%eax, %0\n"
26603 "37: rep; movsb\n"
26604 "100:\n"
26605+ __COPYUSER_RESTORE_ES
26606 ".section .fixup,\"ax\"\n"
26607 "101: lea 0(%%eax,%0,4),%0\n"
26608 " jmp 100b\n"
26609@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26610 }
26611
26612 static unsigned long
26613+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26614+{
26615+ int d0, d1;
26616+ __asm__ __volatile__(
26617+ " .align 2,0x90\n"
26618+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26619+ " cmpl $67, %0\n"
26620+ " jbe 3f\n"
26621+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26622+ " .align 2,0x90\n"
26623+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26624+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26625+ "5: movl %%eax, 0(%3)\n"
26626+ "6: movl %%edx, 4(%3)\n"
26627+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26628+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26629+ "9: movl %%eax, 8(%3)\n"
26630+ "10: movl %%edx, 12(%3)\n"
26631+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26632+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26633+ "13: movl %%eax, 16(%3)\n"
26634+ "14: movl %%edx, 20(%3)\n"
26635+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26636+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26637+ "17: movl %%eax, 24(%3)\n"
26638+ "18: movl %%edx, 28(%3)\n"
26639+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26640+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26641+ "21: movl %%eax, 32(%3)\n"
26642+ "22: movl %%edx, 36(%3)\n"
26643+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26644+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26645+ "25: movl %%eax, 40(%3)\n"
26646+ "26: movl %%edx, 44(%3)\n"
26647+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26648+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26649+ "29: movl %%eax, 48(%3)\n"
26650+ "30: movl %%edx, 52(%3)\n"
26651+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26652+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26653+ "33: movl %%eax, 56(%3)\n"
26654+ "34: movl %%edx, 60(%3)\n"
26655+ " addl $-64, %0\n"
26656+ " addl $64, %4\n"
26657+ " addl $64, %3\n"
26658+ " cmpl $63, %0\n"
26659+ " ja 1b\n"
26660+ "35: movl %0, %%eax\n"
26661+ " shrl $2, %0\n"
26662+ " andl $3, %%eax\n"
26663+ " cld\n"
26664+ "99: rep; "__copyuser_seg" movsl\n"
26665+ "36: movl %%eax, %0\n"
26666+ "37: rep; "__copyuser_seg" movsb\n"
26667+ "100:\n"
26668+ ".section .fixup,\"ax\"\n"
26669+ "101: lea 0(%%eax,%0,4),%0\n"
26670+ " jmp 100b\n"
26671+ ".previous\n"
26672+ _ASM_EXTABLE(1b,100b)
26673+ _ASM_EXTABLE(2b,100b)
26674+ _ASM_EXTABLE(3b,100b)
26675+ _ASM_EXTABLE(4b,100b)
26676+ _ASM_EXTABLE(5b,100b)
26677+ _ASM_EXTABLE(6b,100b)
26678+ _ASM_EXTABLE(7b,100b)
26679+ _ASM_EXTABLE(8b,100b)
26680+ _ASM_EXTABLE(9b,100b)
26681+ _ASM_EXTABLE(10b,100b)
26682+ _ASM_EXTABLE(11b,100b)
26683+ _ASM_EXTABLE(12b,100b)
26684+ _ASM_EXTABLE(13b,100b)
26685+ _ASM_EXTABLE(14b,100b)
26686+ _ASM_EXTABLE(15b,100b)
26687+ _ASM_EXTABLE(16b,100b)
26688+ _ASM_EXTABLE(17b,100b)
26689+ _ASM_EXTABLE(18b,100b)
26690+ _ASM_EXTABLE(19b,100b)
26691+ _ASM_EXTABLE(20b,100b)
26692+ _ASM_EXTABLE(21b,100b)
26693+ _ASM_EXTABLE(22b,100b)
26694+ _ASM_EXTABLE(23b,100b)
26695+ _ASM_EXTABLE(24b,100b)
26696+ _ASM_EXTABLE(25b,100b)
26697+ _ASM_EXTABLE(26b,100b)
26698+ _ASM_EXTABLE(27b,100b)
26699+ _ASM_EXTABLE(28b,100b)
26700+ _ASM_EXTABLE(29b,100b)
26701+ _ASM_EXTABLE(30b,100b)
26702+ _ASM_EXTABLE(31b,100b)
26703+ _ASM_EXTABLE(32b,100b)
26704+ _ASM_EXTABLE(33b,100b)
26705+ _ASM_EXTABLE(34b,100b)
26706+ _ASM_EXTABLE(35b,100b)
26707+ _ASM_EXTABLE(36b,100b)
26708+ _ASM_EXTABLE(37b,100b)
26709+ _ASM_EXTABLE(99b,101b)
26710+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26711+ : "1"(to), "2"(from), "0"(size)
26712+ : "eax", "edx", "memory");
26713+ return size;
26714+}
26715+
26716+static unsigned long __size_overflow(3)
26717 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26718 {
26719 int d0, d1;
26720 __asm__ __volatile__(
26721 " .align 2,0x90\n"
26722- "0: movl 32(%4), %%eax\n"
26723+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26724 " cmpl $67, %0\n"
26725 " jbe 2f\n"
26726- "1: movl 64(%4), %%eax\n"
26727+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26728 " .align 2,0x90\n"
26729- "2: movl 0(%4), %%eax\n"
26730- "21: movl 4(%4), %%edx\n"
26731+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26732+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26733 " movl %%eax, 0(%3)\n"
26734 " movl %%edx, 4(%3)\n"
26735- "3: movl 8(%4), %%eax\n"
26736- "31: movl 12(%4),%%edx\n"
26737+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26738+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26739 " movl %%eax, 8(%3)\n"
26740 " movl %%edx, 12(%3)\n"
26741- "4: movl 16(%4), %%eax\n"
26742- "41: movl 20(%4), %%edx\n"
26743+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26744+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26745 " movl %%eax, 16(%3)\n"
26746 " movl %%edx, 20(%3)\n"
26747- "10: movl 24(%4), %%eax\n"
26748- "51: movl 28(%4), %%edx\n"
26749+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26750+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26751 " movl %%eax, 24(%3)\n"
26752 " movl %%edx, 28(%3)\n"
26753- "11: movl 32(%4), %%eax\n"
26754- "61: movl 36(%4), %%edx\n"
26755+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26756+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26757 " movl %%eax, 32(%3)\n"
26758 " movl %%edx, 36(%3)\n"
26759- "12: movl 40(%4), %%eax\n"
26760- "71: movl 44(%4), %%edx\n"
26761+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26762+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26763 " movl %%eax, 40(%3)\n"
26764 " movl %%edx, 44(%3)\n"
26765- "13: movl 48(%4), %%eax\n"
26766- "81: movl 52(%4), %%edx\n"
26767+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26768+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26769 " movl %%eax, 48(%3)\n"
26770 " movl %%edx, 52(%3)\n"
26771- "14: movl 56(%4), %%eax\n"
26772- "91: movl 60(%4), %%edx\n"
26773+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26774+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26775 " movl %%eax, 56(%3)\n"
26776 " movl %%edx, 60(%3)\n"
26777 " addl $-64, %0\n"
26778@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26779 " shrl $2, %0\n"
26780 " andl $3, %%eax\n"
26781 " cld\n"
26782- "6: rep; movsl\n"
26783+ "6: rep; "__copyuser_seg" movsl\n"
26784 " movl %%eax,%0\n"
26785- "7: rep; movsb\n"
26786+ "7: rep; "__copyuser_seg" movsb\n"
26787 "8:\n"
26788 ".section .fixup,\"ax\"\n"
26789 "9: lea 0(%%eax,%0,4),%0\n"
26790@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26791 * hyoshiok@miraclelinux.com
26792 */
26793
26794-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26795+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26796 const void __user *from, unsigned long size)
26797 {
26798 int d0, d1;
26799
26800 __asm__ __volatile__(
26801 " .align 2,0x90\n"
26802- "0: movl 32(%4), %%eax\n"
26803+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26804 " cmpl $67, %0\n"
26805 " jbe 2f\n"
26806- "1: movl 64(%4), %%eax\n"
26807+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26808 " .align 2,0x90\n"
26809- "2: movl 0(%4), %%eax\n"
26810- "21: movl 4(%4), %%edx\n"
26811+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26812+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26813 " movnti %%eax, 0(%3)\n"
26814 " movnti %%edx, 4(%3)\n"
26815- "3: movl 8(%4), %%eax\n"
26816- "31: movl 12(%4),%%edx\n"
26817+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26818+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26819 " movnti %%eax, 8(%3)\n"
26820 " movnti %%edx, 12(%3)\n"
26821- "4: movl 16(%4), %%eax\n"
26822- "41: movl 20(%4), %%edx\n"
26823+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26824+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26825 " movnti %%eax, 16(%3)\n"
26826 " movnti %%edx, 20(%3)\n"
26827- "10: movl 24(%4), %%eax\n"
26828- "51: movl 28(%4), %%edx\n"
26829+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26830+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26831 " movnti %%eax, 24(%3)\n"
26832 " movnti %%edx, 28(%3)\n"
26833- "11: movl 32(%4), %%eax\n"
26834- "61: movl 36(%4), %%edx\n"
26835+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26836+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26837 " movnti %%eax, 32(%3)\n"
26838 " movnti %%edx, 36(%3)\n"
26839- "12: movl 40(%4), %%eax\n"
26840- "71: movl 44(%4), %%edx\n"
26841+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26842+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26843 " movnti %%eax, 40(%3)\n"
26844 " movnti %%edx, 44(%3)\n"
26845- "13: movl 48(%4), %%eax\n"
26846- "81: movl 52(%4), %%edx\n"
26847+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26848+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26849 " movnti %%eax, 48(%3)\n"
26850 " movnti %%edx, 52(%3)\n"
26851- "14: movl 56(%4), %%eax\n"
26852- "91: movl 60(%4), %%edx\n"
26853+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26854+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26855 " movnti %%eax, 56(%3)\n"
26856 " movnti %%edx, 60(%3)\n"
26857 " addl $-64, %0\n"
26858@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26859 " shrl $2, %0\n"
26860 " andl $3, %%eax\n"
26861 " cld\n"
26862- "6: rep; movsl\n"
26863+ "6: rep; "__copyuser_seg" movsl\n"
26864 " movl %%eax,%0\n"
26865- "7: rep; movsb\n"
26866+ "7: rep; "__copyuser_seg" movsb\n"
26867 "8:\n"
26868 ".section .fixup,\"ax\"\n"
26869 "9: lea 0(%%eax,%0,4),%0\n"
26870@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26871 return size;
26872 }
26873
26874-static unsigned long __copy_user_intel_nocache(void *to,
26875+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26876 const void __user *from, unsigned long size)
26877 {
26878 int d0, d1;
26879
26880 __asm__ __volatile__(
26881 " .align 2,0x90\n"
26882- "0: movl 32(%4), %%eax\n"
26883+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26884 " cmpl $67, %0\n"
26885 " jbe 2f\n"
26886- "1: movl 64(%4), %%eax\n"
26887+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26888 " .align 2,0x90\n"
26889- "2: movl 0(%4), %%eax\n"
26890- "21: movl 4(%4), %%edx\n"
26891+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26892+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26893 " movnti %%eax, 0(%3)\n"
26894 " movnti %%edx, 4(%3)\n"
26895- "3: movl 8(%4), %%eax\n"
26896- "31: movl 12(%4),%%edx\n"
26897+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26898+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26899 " movnti %%eax, 8(%3)\n"
26900 " movnti %%edx, 12(%3)\n"
26901- "4: movl 16(%4), %%eax\n"
26902- "41: movl 20(%4), %%edx\n"
26903+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26904+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26905 " movnti %%eax, 16(%3)\n"
26906 " movnti %%edx, 20(%3)\n"
26907- "10: movl 24(%4), %%eax\n"
26908- "51: movl 28(%4), %%edx\n"
26909+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26910+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26911 " movnti %%eax, 24(%3)\n"
26912 " movnti %%edx, 28(%3)\n"
26913- "11: movl 32(%4), %%eax\n"
26914- "61: movl 36(%4), %%edx\n"
26915+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26916+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26917 " movnti %%eax, 32(%3)\n"
26918 " movnti %%edx, 36(%3)\n"
26919- "12: movl 40(%4), %%eax\n"
26920- "71: movl 44(%4), %%edx\n"
26921+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26922+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26923 " movnti %%eax, 40(%3)\n"
26924 " movnti %%edx, 44(%3)\n"
26925- "13: movl 48(%4), %%eax\n"
26926- "81: movl 52(%4), %%edx\n"
26927+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26928+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26929 " movnti %%eax, 48(%3)\n"
26930 " movnti %%edx, 52(%3)\n"
26931- "14: movl 56(%4), %%eax\n"
26932- "91: movl 60(%4), %%edx\n"
26933+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26934+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26935 " movnti %%eax, 56(%3)\n"
26936 " movnti %%edx, 60(%3)\n"
26937 " addl $-64, %0\n"
26938@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26939 " shrl $2, %0\n"
26940 " andl $3, %%eax\n"
26941 " cld\n"
26942- "6: rep; movsl\n"
26943+ "6: rep; "__copyuser_seg" movsl\n"
26944 " movl %%eax,%0\n"
26945- "7: rep; movsb\n"
26946+ "7: rep; "__copyuser_seg" movsb\n"
26947 "8:\n"
26948 ".section .fixup,\"ax\"\n"
26949 "9: lea 0(%%eax,%0,4),%0\n"
26950@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26951 */
26952 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26953 unsigned long size);
26954-unsigned long __copy_user_intel(void __user *to, const void *from,
26955+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26956+ unsigned long size);
26957+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26958 unsigned long size);
26959 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26960 const void __user *from, unsigned long size);
26961 #endif /* CONFIG_X86_INTEL_USERCOPY */
26962
26963 /* Generic arbitrary sized copy. */
26964-#define __copy_user(to, from, size) \
26965+#define __copy_user(to, from, size, prefix, set, restore) \
26966 do { \
26967 int __d0, __d1, __d2; \
26968 __asm__ __volatile__( \
26969+ set \
26970 " cmp $7,%0\n" \
26971 " jbe 1f\n" \
26972 " movl %1,%0\n" \
26973 " negl %0\n" \
26974 " andl $7,%0\n" \
26975 " subl %0,%3\n" \
26976- "4: rep; movsb\n" \
26977+ "4: rep; "prefix"movsb\n" \
26978 " movl %3,%0\n" \
26979 " shrl $2,%0\n" \
26980 " andl $3,%3\n" \
26981 " .align 2,0x90\n" \
26982- "0: rep; movsl\n" \
26983+ "0: rep; "prefix"movsl\n" \
26984 " movl %3,%0\n" \
26985- "1: rep; movsb\n" \
26986+ "1: rep; "prefix"movsb\n" \
26987 "2:\n" \
26988+ restore \
26989 ".section .fixup,\"ax\"\n" \
26990 "5: addl %3,%0\n" \
26991 " jmp 2b\n" \
26992@@ -538,14 +650,14 @@ do { \
26993 " negl %0\n" \
26994 " andl $7,%0\n" \
26995 " subl %0,%3\n" \
26996- "4: rep; movsb\n" \
26997+ "4: rep; "__copyuser_seg"movsb\n" \
26998 " movl %3,%0\n" \
26999 " shrl $2,%0\n" \
27000 " andl $3,%3\n" \
27001 " .align 2,0x90\n" \
27002- "0: rep; movsl\n" \
27003+ "0: rep; "__copyuser_seg"movsl\n" \
27004 " movl %3,%0\n" \
27005- "1: rep; movsb\n" \
27006+ "1: rep; "__copyuser_seg"movsb\n" \
27007 "2:\n" \
27008 ".section .fixup,\"ax\"\n" \
27009 "5: addl %3,%0\n" \
27010@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
27011 {
27012 stac();
27013 if (movsl_is_ok(to, from, n))
27014- __copy_user(to, from, n);
27015+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
27016 else
27017- n = __copy_user_intel(to, from, n);
27018+ n = __generic_copy_to_user_intel(to, from, n);
27019 clac();
27020 return n;
27021 }
27022@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
27023 {
27024 stac();
27025 if (movsl_is_ok(to, from, n))
27026- __copy_user(to, from, n);
27027+ __copy_user(to, from, n, __copyuser_seg, "", "");
27028 else
27029- n = __copy_user_intel((void __user *)to,
27030- (const void *)from, n);
27031+ n = __generic_copy_from_user_intel(to, from, n);
27032 clac();
27033 return n;
27034 }
27035@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
27036 if (n > 64 && cpu_has_xmm2)
27037 n = __copy_user_intel_nocache(to, from, n);
27038 else
27039- __copy_user(to, from, n);
27040+ __copy_user(to, from, n, __copyuser_seg, "", "");
27041 #else
27042- __copy_user(to, from, n);
27043+ __copy_user(to, from, n, __copyuser_seg, "", "");
27044 #endif
27045 clac();
27046 return n;
27047 }
27048 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27049
27050-/**
27051- * copy_to_user: - Copy a block of data into user space.
27052- * @to: Destination address, in user space.
27053- * @from: Source address, in kernel space.
27054- * @n: Number of bytes to copy.
27055- *
27056- * Context: User context only. This function may sleep.
27057- *
27058- * Copy data from kernel space to user space.
27059- *
27060- * Returns number of bytes that could not be copied.
27061- * On success, this will be zero.
27062- */
27063-unsigned long
27064-copy_to_user(void __user *to, const void *from, unsigned long n)
27065+#ifdef CONFIG_PAX_MEMORY_UDEREF
27066+void __set_fs(mm_segment_t x)
27067 {
27068- if (access_ok(VERIFY_WRITE, to, n))
27069- n = __copy_to_user(to, from, n);
27070- return n;
27071+ switch (x.seg) {
27072+ case 0:
27073+ loadsegment(gs, 0);
27074+ break;
27075+ case TASK_SIZE_MAX:
27076+ loadsegment(gs, __USER_DS);
27077+ break;
27078+ case -1UL:
27079+ loadsegment(gs, __KERNEL_DS);
27080+ break;
27081+ default:
27082+ BUG();
27083+ }
27084 }
27085-EXPORT_SYMBOL(copy_to_user);
27086+EXPORT_SYMBOL(__set_fs);
27087
27088-/**
27089- * copy_from_user: - Copy a block of data from user space.
27090- * @to: Destination address, in kernel space.
27091- * @from: Source address, in user space.
27092- * @n: Number of bytes to copy.
27093- *
27094- * Context: User context only. This function may sleep.
27095- *
27096- * Copy data from user space to kernel space.
27097- *
27098- * Returns number of bytes that could not be copied.
27099- * On success, this will be zero.
27100- *
27101- * If some data could not be copied, this function will pad the copied
27102- * data to the requested size using zero bytes.
27103- */
27104-unsigned long
27105-_copy_from_user(void *to, const void __user *from, unsigned long n)
27106+void set_fs(mm_segment_t x)
27107 {
27108- if (access_ok(VERIFY_READ, from, n))
27109- n = __copy_from_user(to, from, n);
27110- else
27111- memset(to, 0, n);
27112- return n;
27113+ current_thread_info()->addr_limit = x;
27114+ __set_fs(x);
27115 }
27116-EXPORT_SYMBOL(_copy_from_user);
27117+EXPORT_SYMBOL(set_fs);
27118+#endif
27119diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27120index 906fea3..5646695 100644
27121--- a/arch/x86/lib/usercopy_64.c
27122+++ b/arch/x86/lib/usercopy_64.c
27123@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27124 _ASM_EXTABLE(0b,3b)
27125 _ASM_EXTABLE(1b,2b)
27126 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27127- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27128+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27129 [zero] "r" (0UL), [eight] "r" (8UL));
27130 clac();
27131 return size;
27132@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27133 }
27134 EXPORT_SYMBOL(clear_user);
27135
27136-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27137+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27138 {
27139- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27140- return copy_user_generic((__force void *)to, (__force void *)from, len);
27141- }
27142- return len;
27143+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27144+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27145+ return len;
27146 }
27147 EXPORT_SYMBOL(copy_in_user);
27148
27149@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27150 * it is not necessary to optimize tail handling.
27151 */
27152 unsigned long
27153-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27154+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27155 {
27156 char c;
27157 unsigned zero_len;
27158diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27159index 903ec1e..c4166b2 100644
27160--- a/arch/x86/mm/extable.c
27161+++ b/arch/x86/mm/extable.c
27162@@ -6,12 +6,24 @@
27163 static inline unsigned long
27164 ex_insn_addr(const struct exception_table_entry *x)
27165 {
27166- return (unsigned long)&x->insn + x->insn;
27167+ unsigned long reloc = 0;
27168+
27169+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27170+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27171+#endif
27172+
27173+ return (unsigned long)&x->insn + x->insn + reloc;
27174 }
27175 static inline unsigned long
27176 ex_fixup_addr(const struct exception_table_entry *x)
27177 {
27178- return (unsigned long)&x->fixup + x->fixup;
27179+ unsigned long reloc = 0;
27180+
27181+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27182+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27183+#endif
27184+
27185+ return (unsigned long)&x->fixup + x->fixup + reloc;
27186 }
27187
27188 int fixup_exception(struct pt_regs *regs)
27189@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27190 unsigned long new_ip;
27191
27192 #ifdef CONFIG_PNPBIOS
27193- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27194+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27195 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27196 extern u32 pnp_bios_is_utter_crap;
27197 pnp_bios_is_utter_crap = 1;
27198@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27199 i += 4;
27200 p->fixup -= i;
27201 i += 4;
27202+
27203+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27204+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27205+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27206+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27207+#endif
27208+
27209 }
27210 }
27211
27212diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27213index 654be4a..d36985f 100644
27214--- a/arch/x86/mm/fault.c
27215+++ b/arch/x86/mm/fault.c
27216@@ -14,11 +14,18 @@
27217 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27218 #include <linux/prefetch.h> /* prefetchw */
27219 #include <linux/context_tracking.h> /* exception_enter(), ... */
27220+#include <linux/unistd.h>
27221+#include <linux/compiler.h>
27222
27223 #include <asm/traps.h> /* dotraplinkage, ... */
27224 #include <asm/pgalloc.h> /* pgd_*(), ... */
27225 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27226 #include <asm/fixmap.h> /* VSYSCALL_START */
27227+#include <asm/tlbflush.h>
27228+
27229+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27230+#include <asm/stacktrace.h>
27231+#endif
27232
27233 /*
27234 * Page fault error code bits:
27235@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27236 int ret = 0;
27237
27238 /* kprobe_running() needs smp_processor_id() */
27239- if (kprobes_built_in() && !user_mode_vm(regs)) {
27240+ if (kprobes_built_in() && !user_mode(regs)) {
27241 preempt_disable();
27242 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27243 ret = 1;
27244@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27245 return !instr_lo || (instr_lo>>1) == 1;
27246 case 0x00:
27247 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27248- if (probe_kernel_address(instr, opcode))
27249+ if (user_mode(regs)) {
27250+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27251+ return 0;
27252+ } else if (probe_kernel_address(instr, opcode))
27253 return 0;
27254
27255 *prefetch = (instr_lo == 0xF) &&
27256@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27257 while (instr < max_instr) {
27258 unsigned char opcode;
27259
27260- if (probe_kernel_address(instr, opcode))
27261+ if (user_mode(regs)) {
27262+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27263+ break;
27264+ } else if (probe_kernel_address(instr, opcode))
27265 break;
27266
27267 instr++;
27268@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27269 force_sig_info(si_signo, &info, tsk);
27270 }
27271
27272+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27273+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27274+#endif
27275+
27276+#ifdef CONFIG_PAX_EMUTRAMP
27277+static int pax_handle_fetch_fault(struct pt_regs *regs);
27278+#endif
27279+
27280+#ifdef CONFIG_PAX_PAGEEXEC
27281+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27282+{
27283+ pgd_t *pgd;
27284+ pud_t *pud;
27285+ pmd_t *pmd;
27286+
27287+ pgd = pgd_offset(mm, address);
27288+ if (!pgd_present(*pgd))
27289+ return NULL;
27290+ pud = pud_offset(pgd, address);
27291+ if (!pud_present(*pud))
27292+ return NULL;
27293+ pmd = pmd_offset(pud, address);
27294+ if (!pmd_present(*pmd))
27295+ return NULL;
27296+ return pmd;
27297+}
27298+#endif
27299+
27300 DEFINE_SPINLOCK(pgd_lock);
27301 LIST_HEAD(pgd_list);
27302
27303@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27304 for (address = VMALLOC_START & PMD_MASK;
27305 address >= TASK_SIZE && address < FIXADDR_TOP;
27306 address += PMD_SIZE) {
27307+
27308+#ifdef CONFIG_PAX_PER_CPU_PGD
27309+ unsigned long cpu;
27310+#else
27311 struct page *page;
27312+#endif
27313
27314 spin_lock(&pgd_lock);
27315+
27316+#ifdef CONFIG_PAX_PER_CPU_PGD
27317+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27318+ pgd_t *pgd = get_cpu_pgd(cpu);
27319+ pmd_t *ret;
27320+#else
27321 list_for_each_entry(page, &pgd_list, lru) {
27322+ pgd_t *pgd;
27323 spinlock_t *pgt_lock;
27324 pmd_t *ret;
27325
27326@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27327 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27328
27329 spin_lock(pgt_lock);
27330- ret = vmalloc_sync_one(page_address(page), address);
27331+ pgd = page_address(page);
27332+#endif
27333+
27334+ ret = vmalloc_sync_one(pgd, address);
27335+
27336+#ifndef CONFIG_PAX_PER_CPU_PGD
27337 spin_unlock(pgt_lock);
27338+#endif
27339
27340 if (!ret)
27341 break;
27342@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27343 * an interrupt in the middle of a task switch..
27344 */
27345 pgd_paddr = read_cr3();
27346+
27347+#ifdef CONFIG_PAX_PER_CPU_PGD
27348+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27349+#endif
27350+
27351 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27352 if (!pmd_k)
27353 return -1;
27354@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27355 * happen within a race in page table update. In the later
27356 * case just flush:
27357 */
27358+
27359+#ifdef CONFIG_PAX_PER_CPU_PGD
27360+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27361+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27362+#else
27363 pgd = pgd_offset(current->active_mm, address);
27364+#endif
27365+
27366 pgd_ref = pgd_offset_k(address);
27367 if (pgd_none(*pgd_ref))
27368 return -1;
27369@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27370 static int is_errata100(struct pt_regs *regs, unsigned long address)
27371 {
27372 #ifdef CONFIG_X86_64
27373- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27374+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27375 return 1;
27376 #endif
27377 return 0;
27378@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27379 }
27380
27381 static const char nx_warning[] = KERN_CRIT
27382-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27383+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27384
27385 static void
27386 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27387@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27388 if (!oops_may_print())
27389 return;
27390
27391- if (error_code & PF_INSTR) {
27392+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27393 unsigned int level;
27394
27395 pte_t *pte = lookup_address(address, &level);
27396
27397 if (pte && pte_present(*pte) && !pte_exec(*pte))
27398- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27399+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27400 }
27401
27402+#ifdef CONFIG_PAX_KERNEXEC
27403+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27404+ if (current->signal->curr_ip)
27405+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27406+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27407+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27408+ else
27409+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27410+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27411+ }
27412+#endif
27413+
27414 printk(KERN_ALERT "BUG: unable to handle kernel ");
27415 if (address < PAGE_SIZE)
27416 printk(KERN_CONT "NULL pointer dereference");
27417@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27418 return;
27419 }
27420 #endif
27421+
27422+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27423+ if (pax_is_fetch_fault(regs, error_code, address)) {
27424+
27425+#ifdef CONFIG_PAX_EMUTRAMP
27426+ switch (pax_handle_fetch_fault(regs)) {
27427+ case 2:
27428+ return;
27429+ }
27430+#endif
27431+
27432+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27433+ do_group_exit(SIGKILL);
27434+ }
27435+#endif
27436+
27437 /* Kernel addresses are always protection faults: */
27438 if (address >= TASK_SIZE)
27439 error_code |= PF_PROT;
27440@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27441 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27442 printk(KERN_ERR
27443 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27444- tsk->comm, tsk->pid, address);
27445+ tsk->comm, task_pid_nr(tsk), address);
27446 code = BUS_MCEERR_AR;
27447 }
27448 #endif
27449@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27450 return 1;
27451 }
27452
27453+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27454+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27455+{
27456+ pte_t *pte;
27457+ pmd_t *pmd;
27458+ spinlock_t *ptl;
27459+ unsigned char pte_mask;
27460+
27461+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27462+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27463+ return 0;
27464+
27465+ /* PaX: it's our fault, let's handle it if we can */
27466+
27467+ /* PaX: take a look at read faults before acquiring any locks */
27468+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27469+ /* instruction fetch attempt from a protected page in user mode */
27470+ up_read(&mm->mmap_sem);
27471+
27472+#ifdef CONFIG_PAX_EMUTRAMP
27473+ switch (pax_handle_fetch_fault(regs)) {
27474+ case 2:
27475+ return 1;
27476+ }
27477+#endif
27478+
27479+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27480+ do_group_exit(SIGKILL);
27481+ }
27482+
27483+ pmd = pax_get_pmd(mm, address);
27484+ if (unlikely(!pmd))
27485+ return 0;
27486+
27487+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27488+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27489+ pte_unmap_unlock(pte, ptl);
27490+ return 0;
27491+ }
27492+
27493+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27494+ /* write attempt to a protected page in user mode */
27495+ pte_unmap_unlock(pte, ptl);
27496+ return 0;
27497+ }
27498+
27499+#ifdef CONFIG_SMP
27500+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27501+#else
27502+ if (likely(address > get_limit(regs->cs)))
27503+#endif
27504+ {
27505+ set_pte(pte, pte_mkread(*pte));
27506+ __flush_tlb_one(address);
27507+ pte_unmap_unlock(pte, ptl);
27508+ up_read(&mm->mmap_sem);
27509+ return 1;
27510+ }
27511+
27512+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27513+
27514+ /*
27515+ * PaX: fill DTLB with user rights and retry
27516+ */
27517+ __asm__ __volatile__ (
27518+ "orb %2,(%1)\n"
27519+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27520+/*
27521+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27522+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27523+ * page fault when examined during a TLB load attempt. this is true not only
27524+ * for PTEs holding a non-present entry but also present entries that will
27525+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27526+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27527+ * for our target pages since their PTEs are simply not in the TLBs at all.
27528+
27529+ * the best thing in omitting it is that we gain around 15-20% speed in the
27530+ * fast path of the page fault handler and can get rid of tracing since we
27531+ * can no longer flush unintended entries.
27532+ */
27533+ "invlpg (%0)\n"
27534+#endif
27535+ __copyuser_seg"testb $0,(%0)\n"
27536+ "xorb %3,(%1)\n"
27537+ :
27538+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27539+ : "memory", "cc");
27540+ pte_unmap_unlock(pte, ptl);
27541+ up_read(&mm->mmap_sem);
27542+ return 1;
27543+}
27544+#endif
27545+
27546 /*
27547 * Handle a spurious fault caused by a stale TLB entry.
27548 *
27549@@ -964,6 +1156,9 @@ int show_unhandled_signals = 1;
27550 static inline int
27551 access_error(unsigned long error_code, struct vm_area_struct *vma)
27552 {
27553+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27554+ return 1;
27555+
27556 if (error_code & PF_WRITE) {
27557 /* write, present and write, not present: */
27558 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27559@@ -992,7 +1187,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27560 if (error_code & PF_USER)
27561 return false;
27562
27563- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27564+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27565 return false;
27566
27567 return true;
27568@@ -1008,18 +1203,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27569 {
27570 struct vm_area_struct *vma;
27571 struct task_struct *tsk;
27572- unsigned long address;
27573 struct mm_struct *mm;
27574 int fault;
27575 int write = error_code & PF_WRITE;
27576 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27577 (write ? FAULT_FLAG_WRITE : 0);
27578
27579- tsk = current;
27580- mm = tsk->mm;
27581-
27582 /* Get the faulting address: */
27583- address = read_cr2();
27584+ unsigned long address = read_cr2();
27585+
27586+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27587+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
27588+ if (!search_exception_tables(regs->ip)) {
27589+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27590+ bad_area_nosemaphore(regs, error_code, address);
27591+ return;
27592+ }
27593+ if (address < pax_user_shadow_base) {
27594+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27595+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27596+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27597+ } else
27598+ address -= pax_user_shadow_base;
27599+ }
27600+#endif
27601+
27602+ tsk = current;
27603+ mm = tsk->mm;
27604
27605 /*
27606 * Detect and handle instructions that would cause a page fault for
27607@@ -1080,7 +1290,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27608 * User-mode registers count as a user access even for any
27609 * potential system fault or CPU buglet:
27610 */
27611- if (user_mode_vm(regs)) {
27612+ if (user_mode(regs)) {
27613 local_irq_enable();
27614 error_code |= PF_USER;
27615 } else {
27616@@ -1142,6 +1352,11 @@ retry:
27617 might_sleep();
27618 }
27619
27620+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27621+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27622+ return;
27623+#endif
27624+
27625 vma = find_vma(mm, address);
27626 if (unlikely(!vma)) {
27627 bad_area(regs, error_code, address);
27628@@ -1153,18 +1368,24 @@ retry:
27629 bad_area(regs, error_code, address);
27630 return;
27631 }
27632- if (error_code & PF_USER) {
27633- /*
27634- * Accessing the stack below %sp is always a bug.
27635- * The large cushion allows instructions like enter
27636- * and pusha to work. ("enter $65535, $31" pushes
27637- * 32 pointers and then decrements %sp by 65535.)
27638- */
27639- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27640- bad_area(regs, error_code, address);
27641- return;
27642- }
27643+ /*
27644+ * Accessing the stack below %sp is always a bug.
27645+ * The large cushion allows instructions like enter
27646+ * and pusha to work. ("enter $65535, $31" pushes
27647+ * 32 pointers and then decrements %sp by 65535.)
27648+ */
27649+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27650+ bad_area(regs, error_code, address);
27651+ return;
27652 }
27653+
27654+#ifdef CONFIG_PAX_SEGMEXEC
27655+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27656+ bad_area(regs, error_code, address);
27657+ return;
27658+ }
27659+#endif
27660+
27661 if (unlikely(expand_stack(vma, address))) {
27662 bad_area(regs, error_code, address);
27663 return;
27664@@ -1230,3 +1451,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27665 __do_page_fault(regs, error_code);
27666 exception_exit(prev_state);
27667 }
27668+
27669+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27670+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27671+{
27672+ struct mm_struct *mm = current->mm;
27673+ unsigned long ip = regs->ip;
27674+
27675+ if (v8086_mode(regs))
27676+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27677+
27678+#ifdef CONFIG_PAX_PAGEEXEC
27679+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27680+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27681+ return true;
27682+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27683+ return true;
27684+ return false;
27685+ }
27686+#endif
27687+
27688+#ifdef CONFIG_PAX_SEGMEXEC
27689+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27690+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27691+ return true;
27692+ return false;
27693+ }
27694+#endif
27695+
27696+ return false;
27697+}
27698+#endif
27699+
27700+#ifdef CONFIG_PAX_EMUTRAMP
27701+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27702+{
27703+ int err;
27704+
27705+ do { /* PaX: libffi trampoline emulation */
27706+ unsigned char mov, jmp;
27707+ unsigned int addr1, addr2;
27708+
27709+#ifdef CONFIG_X86_64
27710+ if ((regs->ip + 9) >> 32)
27711+ break;
27712+#endif
27713+
27714+ err = get_user(mov, (unsigned char __user *)regs->ip);
27715+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27716+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27717+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27718+
27719+ if (err)
27720+ break;
27721+
27722+ if (mov == 0xB8 && jmp == 0xE9) {
27723+ regs->ax = addr1;
27724+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27725+ return 2;
27726+ }
27727+ } while (0);
27728+
27729+ do { /* PaX: gcc trampoline emulation #1 */
27730+ unsigned char mov1, mov2;
27731+ unsigned short jmp;
27732+ unsigned int addr1, addr2;
27733+
27734+#ifdef CONFIG_X86_64
27735+ if ((regs->ip + 11) >> 32)
27736+ break;
27737+#endif
27738+
27739+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27740+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27741+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27742+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27743+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27744+
27745+ if (err)
27746+ break;
27747+
27748+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27749+ regs->cx = addr1;
27750+ regs->ax = addr2;
27751+ regs->ip = addr2;
27752+ return 2;
27753+ }
27754+ } while (0);
27755+
27756+ do { /* PaX: gcc trampoline emulation #2 */
27757+ unsigned char mov, jmp;
27758+ unsigned int addr1, addr2;
27759+
27760+#ifdef CONFIG_X86_64
27761+ if ((regs->ip + 9) >> 32)
27762+ break;
27763+#endif
27764+
27765+ err = get_user(mov, (unsigned char __user *)regs->ip);
27766+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27767+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27768+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27769+
27770+ if (err)
27771+ break;
27772+
27773+ if (mov == 0xB9 && jmp == 0xE9) {
27774+ regs->cx = addr1;
27775+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27776+ return 2;
27777+ }
27778+ } while (0);
27779+
27780+ return 1; /* PaX in action */
27781+}
27782+
27783+#ifdef CONFIG_X86_64
27784+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27785+{
27786+ int err;
27787+
27788+ do { /* PaX: libffi trampoline emulation */
27789+ unsigned short mov1, mov2, jmp1;
27790+ unsigned char stcclc, jmp2;
27791+ unsigned long addr1, addr2;
27792+
27793+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27794+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27795+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27796+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27797+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27798+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27799+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27800+
27801+ if (err)
27802+ break;
27803+
27804+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27805+ regs->r11 = addr1;
27806+ regs->r10 = addr2;
27807+ if (stcclc == 0xF8)
27808+ regs->flags &= ~X86_EFLAGS_CF;
27809+ else
27810+ regs->flags |= X86_EFLAGS_CF;
27811+ regs->ip = addr1;
27812+ return 2;
27813+ }
27814+ } while (0);
27815+
27816+ do { /* PaX: gcc trampoline emulation #1 */
27817+ unsigned short mov1, mov2, jmp1;
27818+ unsigned char jmp2;
27819+ unsigned int addr1;
27820+ unsigned long addr2;
27821+
27822+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27823+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27824+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27825+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27826+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27827+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27828+
27829+ if (err)
27830+ break;
27831+
27832+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27833+ regs->r11 = addr1;
27834+ regs->r10 = addr2;
27835+ regs->ip = addr1;
27836+ return 2;
27837+ }
27838+ } while (0);
27839+
27840+ do { /* PaX: gcc trampoline emulation #2 */
27841+ unsigned short mov1, mov2, jmp1;
27842+ unsigned char jmp2;
27843+ unsigned long addr1, addr2;
27844+
27845+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27846+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27847+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27848+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27849+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27850+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27851+
27852+ if (err)
27853+ break;
27854+
27855+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27856+ regs->r11 = addr1;
27857+ regs->r10 = addr2;
27858+ regs->ip = addr1;
27859+ return 2;
27860+ }
27861+ } while (0);
27862+
27863+ return 1; /* PaX in action */
27864+}
27865+#endif
27866+
27867+/*
27868+ * PaX: decide what to do with offenders (regs->ip = fault address)
27869+ *
27870+ * returns 1 when task should be killed
27871+ * 2 when gcc trampoline was detected
27872+ */
27873+static int pax_handle_fetch_fault(struct pt_regs *regs)
27874+{
27875+ if (v8086_mode(regs))
27876+ return 1;
27877+
27878+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27879+ return 1;
27880+
27881+#ifdef CONFIG_X86_32
27882+ return pax_handle_fetch_fault_32(regs);
27883+#else
27884+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27885+ return pax_handle_fetch_fault_32(regs);
27886+ else
27887+ return pax_handle_fetch_fault_64(regs);
27888+#endif
27889+}
27890+#endif
27891+
27892+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27893+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27894+{
27895+ long i;
27896+
27897+ printk(KERN_ERR "PAX: bytes at PC: ");
27898+ for (i = 0; i < 20; i++) {
27899+ unsigned char c;
27900+ if (get_user(c, (unsigned char __force_user *)pc+i))
27901+ printk(KERN_CONT "?? ");
27902+ else
27903+ printk(KERN_CONT "%02x ", c);
27904+ }
27905+ printk("\n");
27906+
27907+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27908+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27909+ unsigned long c;
27910+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27911+#ifdef CONFIG_X86_32
27912+ printk(KERN_CONT "???????? ");
27913+#else
27914+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27915+ printk(KERN_CONT "???????? ???????? ");
27916+ else
27917+ printk(KERN_CONT "???????????????? ");
27918+#endif
27919+ } else {
27920+#ifdef CONFIG_X86_64
27921+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27922+ printk(KERN_CONT "%08x ", (unsigned int)c);
27923+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27924+ } else
27925+#endif
27926+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27927+ }
27928+ }
27929+ printk("\n");
27930+}
27931+#endif
27932+
27933+/**
27934+ * probe_kernel_write(): safely attempt to write to a location
27935+ * @dst: address to write to
27936+ * @src: pointer to the data that shall be written
27937+ * @size: size of the data chunk
27938+ *
27939+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27940+ * happens, handle that and return -EFAULT.
27941+ */
27942+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27943+{
27944+ long ret;
27945+ mm_segment_t old_fs = get_fs();
27946+
27947+ set_fs(KERNEL_DS);
27948+ pagefault_disable();
27949+ pax_open_kernel();
27950+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27951+ pax_close_kernel();
27952+ pagefault_enable();
27953+ set_fs(old_fs);
27954+
27955+ return ret ? -EFAULT : 0;
27956+}
27957diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27958index dd74e46..7d26398 100644
27959--- a/arch/x86/mm/gup.c
27960+++ b/arch/x86/mm/gup.c
27961@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27962 addr = start;
27963 len = (unsigned long) nr_pages << PAGE_SHIFT;
27964 end = start + len;
27965- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27966+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27967 (void __user *)start, len)))
27968 return 0;
27969
27970diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27971index 252b8f5..4dcfdc1 100644
27972--- a/arch/x86/mm/highmem_32.c
27973+++ b/arch/x86/mm/highmem_32.c
27974@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27975 idx = type + KM_TYPE_NR*smp_processor_id();
27976 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27977 BUG_ON(!pte_none(*(kmap_pte-idx)));
27978+
27979+ pax_open_kernel();
27980 set_pte(kmap_pte-idx, mk_pte(page, prot));
27981+ pax_close_kernel();
27982+
27983 arch_flush_lazy_mmu_mode();
27984
27985 return (void *)vaddr;
27986diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27987index ae1aa71..d9bea75 100644
27988--- a/arch/x86/mm/hugetlbpage.c
27989+++ b/arch/x86/mm/hugetlbpage.c
27990@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
27991 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
27992 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27993 unsigned long addr, unsigned long len,
27994- unsigned long pgoff, unsigned long flags)
27995+ unsigned long pgoff, unsigned long flags, unsigned long offset)
27996 {
27997 struct hstate *h = hstate_file(file);
27998 struct vm_unmapped_area_info info;
27999-
28000+
28001 info.flags = 0;
28002 info.length = len;
28003 info.low_limit = TASK_UNMAPPED_BASE;
28004+
28005+#ifdef CONFIG_PAX_RANDMMAP
28006+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28007+ info.low_limit += current->mm->delta_mmap;
28008+#endif
28009+
28010 info.high_limit = TASK_SIZE;
28011 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28012 info.align_offset = 0;
28013+ info.threadstack_offset = offset;
28014 return vm_unmapped_area(&info);
28015 }
28016
28017 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28018 unsigned long addr0, unsigned long len,
28019- unsigned long pgoff, unsigned long flags)
28020+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28021 {
28022 struct hstate *h = hstate_file(file);
28023 struct vm_unmapped_area_info info;
28024@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28025 info.high_limit = current->mm->mmap_base;
28026 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28027 info.align_offset = 0;
28028+ info.threadstack_offset = offset;
28029 addr = vm_unmapped_area(&info);
28030
28031 /*
28032@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28033 VM_BUG_ON(addr != -ENOMEM);
28034 info.flags = 0;
28035 info.low_limit = TASK_UNMAPPED_BASE;
28036+
28037+#ifdef CONFIG_PAX_RANDMMAP
28038+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28039+ info.low_limit += current->mm->delta_mmap;
28040+#endif
28041+
28042 info.high_limit = TASK_SIZE;
28043 addr = vm_unmapped_area(&info);
28044 }
28045@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28046 struct hstate *h = hstate_file(file);
28047 struct mm_struct *mm = current->mm;
28048 struct vm_area_struct *vma;
28049+ unsigned long pax_task_size = TASK_SIZE;
28050+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28051
28052 if (len & ~huge_page_mask(h))
28053 return -EINVAL;
28054- if (len > TASK_SIZE)
28055+
28056+#ifdef CONFIG_PAX_SEGMEXEC
28057+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28058+ pax_task_size = SEGMEXEC_TASK_SIZE;
28059+#endif
28060+
28061+ pax_task_size -= PAGE_SIZE;
28062+
28063+ if (len > pax_task_size)
28064 return -ENOMEM;
28065
28066 if (flags & MAP_FIXED) {
28067@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28068 return addr;
28069 }
28070
28071+#ifdef CONFIG_PAX_RANDMMAP
28072+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28073+#endif
28074+
28075 if (addr) {
28076 addr = ALIGN(addr, huge_page_size(h));
28077 vma = find_vma(mm, addr);
28078- if (TASK_SIZE - len >= addr &&
28079- (!vma || addr + len <= vma->vm_start))
28080+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28081 return addr;
28082 }
28083 if (mm->get_unmapped_area == arch_get_unmapped_area)
28084 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
28085- pgoff, flags);
28086+ pgoff, flags, offset);
28087 else
28088 return hugetlb_get_unmapped_area_topdown(file, addr, len,
28089- pgoff, flags);
28090+ pgoff, flags, offset);
28091 }
28092
28093 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
28094diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28095index 1f34e92..d252637 100644
28096--- a/arch/x86/mm/init.c
28097+++ b/arch/x86/mm/init.c
28098@@ -4,6 +4,7 @@
28099 #include <linux/swap.h>
28100 #include <linux/memblock.h>
28101 #include <linux/bootmem.h> /* for max_low_pfn */
28102+#include <linux/tboot.h>
28103
28104 #include <asm/cacheflush.h>
28105 #include <asm/e820.h>
28106@@ -17,6 +18,8 @@
28107 #include <asm/proto.h>
28108 #include <asm/dma.h> /* for MAX_DMA_PFN */
28109 #include <asm/microcode.h>
28110+#include <asm/desc.h>
28111+#include <asm/bios_ebda.h>
28112
28113 #include "mm_internal.h"
28114
28115@@ -465,7 +468,15 @@ void __init init_mem_mapping(void)
28116 early_ioremap_page_table_range_init();
28117 #endif
28118
28119+#ifdef CONFIG_PAX_PER_CPU_PGD
28120+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28121+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28122+ KERNEL_PGD_PTRS);
28123+ load_cr3(get_cpu_pgd(0));
28124+#else
28125 load_cr3(swapper_pg_dir);
28126+#endif
28127+
28128 __flush_tlb_all();
28129
28130 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
28131@@ -481,10 +492,40 @@ void __init init_mem_mapping(void)
28132 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28133 * mmio resources as well as potential bios/acpi data regions.
28134 */
28135+
28136+#ifdef CONFIG_GRKERNSEC_KMEM
28137+static unsigned int ebda_start __read_only;
28138+static unsigned int ebda_end __read_only;
28139+#endif
28140+
28141 int devmem_is_allowed(unsigned long pagenr)
28142 {
28143- if (pagenr < 256)
28144+#ifdef CONFIG_GRKERNSEC_KMEM
28145+ /* allow BDA */
28146+ if (!pagenr)
28147 return 1;
28148+ /* allow EBDA */
28149+ if (pagenr >= ebda_start && pagenr < ebda_end)
28150+ return 1;
28151+ /* if tboot is in use, allow access to its hardcoded serial log range */
28152+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28153+ return 1;
28154+#else
28155+ if (!pagenr)
28156+ return 1;
28157+#ifdef CONFIG_VM86
28158+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28159+ return 1;
28160+#endif
28161+#endif
28162+
28163+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28164+ return 1;
28165+#ifdef CONFIG_GRKERNSEC_KMEM
28166+ /* throw out everything else below 1MB */
28167+ if (pagenr <= 256)
28168+ return 0;
28169+#endif
28170 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28171 return 0;
28172 if (!page_is_ram(pagenr))
28173@@ -538,8 +579,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28174 #endif
28175 }
28176
28177+#ifdef CONFIG_GRKERNSEC_KMEM
28178+static inline void gr_init_ebda(void)
28179+{
28180+ unsigned int ebda_addr;
28181+ unsigned int ebda_size = 0;
28182+
28183+ ebda_addr = get_bios_ebda();
28184+ if (ebda_addr) {
28185+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28186+ ebda_size <<= 10;
28187+ }
28188+ if (ebda_addr && ebda_size) {
28189+ ebda_start = ebda_addr >> PAGE_SHIFT;
28190+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28191+ } else {
28192+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28193+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28194+ }
28195+}
28196+#else
28197+static inline void gr_init_ebda(void) { }
28198+#endif
28199+
28200 void free_initmem(void)
28201 {
28202+#ifdef CONFIG_PAX_KERNEXEC
28203+#ifdef CONFIG_X86_32
28204+ /* PaX: limit KERNEL_CS to actual size */
28205+ unsigned long addr, limit;
28206+ struct desc_struct d;
28207+ int cpu;
28208+#else
28209+ pgd_t *pgd;
28210+ pud_t *pud;
28211+ pmd_t *pmd;
28212+ unsigned long addr, end;
28213+#endif
28214+#endif
28215+
28216+ gr_init_ebda();
28217+
28218+#ifdef CONFIG_PAX_KERNEXEC
28219+#ifdef CONFIG_X86_32
28220+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28221+ limit = (limit - 1UL) >> PAGE_SHIFT;
28222+
28223+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28224+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28225+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28226+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28227+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28228+ }
28229+
28230+ /* PaX: make KERNEL_CS read-only */
28231+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28232+ if (!paravirt_enabled())
28233+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28234+/*
28235+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28236+ pgd = pgd_offset_k(addr);
28237+ pud = pud_offset(pgd, addr);
28238+ pmd = pmd_offset(pud, addr);
28239+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28240+ }
28241+*/
28242+#ifdef CONFIG_X86_PAE
28243+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28244+/*
28245+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28246+ pgd = pgd_offset_k(addr);
28247+ pud = pud_offset(pgd, addr);
28248+ pmd = pmd_offset(pud, addr);
28249+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28250+ }
28251+*/
28252+#endif
28253+
28254+#ifdef CONFIG_MODULES
28255+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28256+#endif
28257+
28258+#else
28259+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28260+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28261+ pgd = pgd_offset_k(addr);
28262+ pud = pud_offset(pgd, addr);
28263+ pmd = pmd_offset(pud, addr);
28264+ if (!pmd_present(*pmd))
28265+ continue;
28266+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28267+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28268+ else
28269+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28270+ }
28271+
28272+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28273+ end = addr + KERNEL_IMAGE_SIZE;
28274+ for (; addr < end; addr += PMD_SIZE) {
28275+ pgd = pgd_offset_k(addr);
28276+ pud = pud_offset(pgd, addr);
28277+ pmd = pmd_offset(pud, addr);
28278+ if (!pmd_present(*pmd))
28279+ continue;
28280+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28281+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28282+ }
28283+#endif
28284+
28285+ flush_tlb_all();
28286+#endif
28287+
28288 free_init_pages("unused kernel memory",
28289 (unsigned long)(&__init_begin),
28290 (unsigned long)(&__init_end));
28291diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28292index 3ac7e31..89611b7 100644
28293--- a/arch/x86/mm/init_32.c
28294+++ b/arch/x86/mm/init_32.c
28295@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
28296 bool __read_mostly __vmalloc_start_set = false;
28297
28298 /*
28299- * Creates a middle page table and puts a pointer to it in the
28300- * given global directory entry. This only returns the gd entry
28301- * in non-PAE compilation mode, since the middle layer is folded.
28302- */
28303-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28304-{
28305- pud_t *pud;
28306- pmd_t *pmd_table;
28307-
28308-#ifdef CONFIG_X86_PAE
28309- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28310- pmd_table = (pmd_t *)alloc_low_page();
28311- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28312- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28313- pud = pud_offset(pgd, 0);
28314- BUG_ON(pmd_table != pmd_offset(pud, 0));
28315-
28316- return pmd_table;
28317- }
28318-#endif
28319- pud = pud_offset(pgd, 0);
28320- pmd_table = pmd_offset(pud, 0);
28321-
28322- return pmd_table;
28323-}
28324-
28325-/*
28326 * Create a page table and place a pointer to it in a middle page
28327 * directory entry:
28328 */
28329@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28330 pte_t *page_table = (pte_t *)alloc_low_page();
28331
28332 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28333+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28334+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28335+#else
28336 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28337+#endif
28338 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28339 }
28340
28341 return pte_offset_kernel(pmd, 0);
28342 }
28343
28344+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28345+{
28346+ pud_t *pud;
28347+ pmd_t *pmd_table;
28348+
28349+ pud = pud_offset(pgd, 0);
28350+ pmd_table = pmd_offset(pud, 0);
28351+
28352+ return pmd_table;
28353+}
28354+
28355 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28356 {
28357 int pgd_idx = pgd_index(vaddr);
28358@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28359 int pgd_idx, pmd_idx;
28360 unsigned long vaddr;
28361 pgd_t *pgd;
28362+ pud_t *pud;
28363 pmd_t *pmd;
28364 pte_t *pte = NULL;
28365 unsigned long count = page_table_range_init_count(start, end);
28366@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28367 pgd = pgd_base + pgd_idx;
28368
28369 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28370- pmd = one_md_table_init(pgd);
28371- pmd = pmd + pmd_index(vaddr);
28372+ pud = pud_offset(pgd, vaddr);
28373+ pmd = pmd_offset(pud, vaddr);
28374+
28375+#ifdef CONFIG_X86_PAE
28376+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28377+#endif
28378+
28379 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28380 pmd++, pmd_idx++) {
28381 pte = page_table_kmap_check(one_page_table_init(pmd),
28382@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28383 }
28384 }
28385
28386-static inline int is_kernel_text(unsigned long addr)
28387+static inline int is_kernel_text(unsigned long start, unsigned long end)
28388 {
28389- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28390- return 1;
28391- return 0;
28392+ if ((start > ktla_ktva((unsigned long)_etext) ||
28393+ end <= ktla_ktva((unsigned long)_stext)) &&
28394+ (start > ktla_ktva((unsigned long)_einittext) ||
28395+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28396+
28397+#ifdef CONFIG_ACPI_SLEEP
28398+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28399+#endif
28400+
28401+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28402+ return 0;
28403+ return 1;
28404 }
28405
28406 /*
28407@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
28408 unsigned long last_map_addr = end;
28409 unsigned long start_pfn, end_pfn;
28410 pgd_t *pgd_base = swapper_pg_dir;
28411- int pgd_idx, pmd_idx, pte_ofs;
28412+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28413 unsigned long pfn;
28414 pgd_t *pgd;
28415+ pud_t *pud;
28416 pmd_t *pmd;
28417 pte_t *pte;
28418 unsigned pages_2m, pages_4k;
28419@@ -291,8 +295,13 @@ repeat:
28420 pfn = start_pfn;
28421 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28422 pgd = pgd_base + pgd_idx;
28423- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28424- pmd = one_md_table_init(pgd);
28425+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28426+ pud = pud_offset(pgd, 0);
28427+ pmd = pmd_offset(pud, 0);
28428+
28429+#ifdef CONFIG_X86_PAE
28430+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28431+#endif
28432
28433 if (pfn >= end_pfn)
28434 continue;
28435@@ -304,14 +313,13 @@ repeat:
28436 #endif
28437 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28438 pmd++, pmd_idx++) {
28439- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28440+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28441
28442 /*
28443 * Map with big pages if possible, otherwise
28444 * create normal page tables:
28445 */
28446 if (use_pse) {
28447- unsigned int addr2;
28448 pgprot_t prot = PAGE_KERNEL_LARGE;
28449 /*
28450 * first pass will use the same initial
28451@@ -322,11 +330,7 @@ repeat:
28452 _PAGE_PSE);
28453
28454 pfn &= PMD_MASK >> PAGE_SHIFT;
28455- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28456- PAGE_OFFSET + PAGE_SIZE-1;
28457-
28458- if (is_kernel_text(addr) ||
28459- is_kernel_text(addr2))
28460+ if (is_kernel_text(address, address + PMD_SIZE))
28461 prot = PAGE_KERNEL_LARGE_EXEC;
28462
28463 pages_2m++;
28464@@ -343,7 +347,7 @@ repeat:
28465 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28466 pte += pte_ofs;
28467 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28468- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28469+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28470 pgprot_t prot = PAGE_KERNEL;
28471 /*
28472 * first pass will use the same initial
28473@@ -351,7 +355,7 @@ repeat:
28474 */
28475 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28476
28477- if (is_kernel_text(addr))
28478+ if (is_kernel_text(address, address + PAGE_SIZE))
28479 prot = PAGE_KERNEL_EXEC;
28480
28481 pages_4k++;
28482@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
28483
28484 pud = pud_offset(pgd, va);
28485 pmd = pmd_offset(pud, va);
28486- if (!pmd_present(*pmd))
28487+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
28488 break;
28489
28490 /* should not be large page here */
28491@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
28492
28493 static void __init pagetable_init(void)
28494 {
28495- pgd_t *pgd_base = swapper_pg_dir;
28496-
28497- permanent_kmaps_init(pgd_base);
28498+ permanent_kmaps_init(swapper_pg_dir);
28499 }
28500
28501-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28502+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28503 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28504
28505 /* user-defined highmem size */
28506@@ -772,7 +774,7 @@ void __init mem_init(void)
28507 after_bootmem = 1;
28508
28509 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28510- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28511+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28512 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28513
28514 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28515@@ -813,10 +815,10 @@ void __init mem_init(void)
28516 ((unsigned long)&__init_end -
28517 (unsigned long)&__init_begin) >> 10,
28518
28519- (unsigned long)&_etext, (unsigned long)&_edata,
28520- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28521+ (unsigned long)&_sdata, (unsigned long)&_edata,
28522+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28523
28524- (unsigned long)&_text, (unsigned long)&_etext,
28525+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28526 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28527
28528 /*
28529@@ -906,6 +908,7 @@ void set_kernel_text_rw(void)
28530 if (!kernel_set_to_readonly)
28531 return;
28532
28533+ start = ktla_ktva(start);
28534 pr_debug("Set kernel text: %lx - %lx for read write\n",
28535 start, start+size);
28536
28537@@ -920,6 +923,7 @@ void set_kernel_text_ro(void)
28538 if (!kernel_set_to_readonly)
28539 return;
28540
28541+ start = ktla_ktva(start);
28542 pr_debug("Set kernel text: %lx - %lx for read only\n",
28543 start, start+size);
28544
28545@@ -948,6 +952,7 @@ void mark_rodata_ro(void)
28546 unsigned long start = PFN_ALIGN(_text);
28547 unsigned long size = PFN_ALIGN(_etext) - start;
28548
28549+ start = ktla_ktva(start);
28550 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28551 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28552 size >> 10);
28553diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28554index bb00c46..f31d2f0 100644
28555--- a/arch/x86/mm/init_64.c
28556+++ b/arch/x86/mm/init_64.c
28557@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28558 * around without checking the pgd every time.
28559 */
28560
28561-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28562+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28563 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28564
28565 int force_personality32;
28566@@ -184,12 +184,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28567
28568 for (address = start; address <= end; address += PGDIR_SIZE) {
28569 const pgd_t *pgd_ref = pgd_offset_k(address);
28570+
28571+#ifdef CONFIG_PAX_PER_CPU_PGD
28572+ unsigned long cpu;
28573+#else
28574 struct page *page;
28575+#endif
28576
28577 if (pgd_none(*pgd_ref))
28578 continue;
28579
28580 spin_lock(&pgd_lock);
28581+
28582+#ifdef CONFIG_PAX_PER_CPU_PGD
28583+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28584+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28585+#else
28586 list_for_each_entry(page, &pgd_list, lru) {
28587 pgd_t *pgd;
28588 spinlock_t *pgt_lock;
28589@@ -198,6 +208,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28590 /* the pgt_lock only for Xen */
28591 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28592 spin_lock(pgt_lock);
28593+#endif
28594
28595 if (pgd_none(*pgd))
28596 set_pgd(pgd, *pgd_ref);
28597@@ -205,7 +216,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28598 BUG_ON(pgd_page_vaddr(*pgd)
28599 != pgd_page_vaddr(*pgd_ref));
28600
28601+#ifndef CONFIG_PAX_PER_CPU_PGD
28602 spin_unlock(pgt_lock);
28603+#endif
28604+
28605 }
28606 spin_unlock(&pgd_lock);
28607 }
28608@@ -238,7 +252,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28609 {
28610 if (pgd_none(*pgd)) {
28611 pud_t *pud = (pud_t *)spp_getpage();
28612- pgd_populate(&init_mm, pgd, pud);
28613+ pgd_populate_kernel(&init_mm, pgd, pud);
28614 if (pud != pud_offset(pgd, 0))
28615 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28616 pud, pud_offset(pgd, 0));
28617@@ -250,7 +264,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28618 {
28619 if (pud_none(*pud)) {
28620 pmd_t *pmd = (pmd_t *) spp_getpage();
28621- pud_populate(&init_mm, pud, pmd);
28622+ pud_populate_kernel(&init_mm, pud, pmd);
28623 if (pmd != pmd_offset(pud, 0))
28624 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28625 pmd, pmd_offset(pud, 0));
28626@@ -279,7 +293,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28627 pmd = fill_pmd(pud, vaddr);
28628 pte = fill_pte(pmd, vaddr);
28629
28630+ pax_open_kernel();
28631 set_pte(pte, new_pte);
28632+ pax_close_kernel();
28633
28634 /*
28635 * It's enough to flush this one mapping.
28636@@ -338,14 +354,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28637 pgd = pgd_offset_k((unsigned long)__va(phys));
28638 if (pgd_none(*pgd)) {
28639 pud = (pud_t *) spp_getpage();
28640- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28641- _PAGE_USER));
28642+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28643 }
28644 pud = pud_offset(pgd, (unsigned long)__va(phys));
28645 if (pud_none(*pud)) {
28646 pmd = (pmd_t *) spp_getpage();
28647- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28648- _PAGE_USER));
28649+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28650 }
28651 pmd = pmd_offset(pud, phys);
28652 BUG_ON(!pmd_none(*pmd));
28653@@ -586,7 +600,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28654 prot);
28655
28656 spin_lock(&init_mm.page_table_lock);
28657- pud_populate(&init_mm, pud, pmd);
28658+ pud_populate_kernel(&init_mm, pud, pmd);
28659 spin_unlock(&init_mm.page_table_lock);
28660 }
28661 __flush_tlb_all();
28662@@ -627,7 +641,7 @@ kernel_physical_mapping_init(unsigned long start,
28663 page_size_mask);
28664
28665 spin_lock(&init_mm.page_table_lock);
28666- pgd_populate(&init_mm, pgd, pud);
28667+ pgd_populate_kernel(&init_mm, pgd, pud);
28668 spin_unlock(&init_mm.page_table_lock);
28669 pgd_changed = true;
28670 }
28671@@ -1221,8 +1235,8 @@ int kern_addr_valid(unsigned long addr)
28672 static struct vm_area_struct gate_vma = {
28673 .vm_start = VSYSCALL_START,
28674 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28675- .vm_page_prot = PAGE_READONLY_EXEC,
28676- .vm_flags = VM_READ | VM_EXEC
28677+ .vm_page_prot = PAGE_READONLY,
28678+ .vm_flags = VM_READ
28679 };
28680
28681 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28682@@ -1256,7 +1270,7 @@ int in_gate_area_no_mm(unsigned long addr)
28683
28684 const char *arch_vma_name(struct vm_area_struct *vma)
28685 {
28686- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28687+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28688 return "[vdso]";
28689 if (vma == &gate_vma)
28690 return "[vsyscall]";
28691diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28692index 7b179b4..6bd17777 100644
28693--- a/arch/x86/mm/iomap_32.c
28694+++ b/arch/x86/mm/iomap_32.c
28695@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28696 type = kmap_atomic_idx_push();
28697 idx = type + KM_TYPE_NR * smp_processor_id();
28698 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28699+
28700+ pax_open_kernel();
28701 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28702+ pax_close_kernel();
28703+
28704 arch_flush_lazy_mmu_mode();
28705
28706 return (void *)vaddr;
28707diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28708index 9a1e658..da003f3 100644
28709--- a/arch/x86/mm/ioremap.c
28710+++ b/arch/x86/mm/ioremap.c
28711@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28712 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28713 int is_ram = page_is_ram(pfn);
28714
28715- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28716+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28717 return NULL;
28718 WARN_ON_ONCE(is_ram);
28719 }
28720@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28721 *
28722 * Caller must ensure there is only one unmapping for the same pointer.
28723 */
28724-void iounmap(volatile void __iomem *addr)
28725+void iounmap(const volatile void __iomem *addr)
28726 {
28727 struct vm_struct *p, *o;
28728
28729@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28730
28731 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28732 if (page_is_ram(start >> PAGE_SHIFT))
28733+#ifdef CONFIG_HIGHMEM
28734+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28735+#endif
28736 return __va(phys);
28737
28738 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28739@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28740 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
28741 {
28742 if (page_is_ram(phys >> PAGE_SHIFT))
28743+#ifdef CONFIG_HIGHMEM
28744+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
28745+#endif
28746 return;
28747
28748 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
28749@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
28750 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28751
28752 static __initdata int after_paging_init;
28753-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28754+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28755
28756 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28757 {
28758@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
28759 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28760
28761 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28762- memset(bm_pte, 0, sizeof(bm_pte));
28763- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28764+ pmd_populate_user(&init_mm, pmd, bm_pte);
28765
28766 /*
28767 * The boot-ioremap range spans multiple pmds, for which
28768diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28769index d87dd6d..bf3fa66 100644
28770--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28771+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28772@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28773 * memory (e.g. tracked pages)? For now, we need this to avoid
28774 * invoking kmemcheck for PnP BIOS calls.
28775 */
28776- if (regs->flags & X86_VM_MASK)
28777+ if (v8086_mode(regs))
28778 return false;
28779- if (regs->cs != __KERNEL_CS)
28780+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28781 return false;
28782
28783 pte = kmemcheck_pte_lookup(address);
28784diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28785index 845df68..1d8d29f 100644
28786--- a/arch/x86/mm/mmap.c
28787+++ b/arch/x86/mm/mmap.c
28788@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28789 * Leave an at least ~128 MB hole with possible stack randomization.
28790 */
28791 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28792-#define MAX_GAP (TASK_SIZE/6*5)
28793+#define MAX_GAP (pax_task_size/6*5)
28794
28795 static int mmap_is_legacy(void)
28796 {
28797@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28798 return rnd << PAGE_SHIFT;
28799 }
28800
28801-static unsigned long mmap_base(void)
28802+static unsigned long mmap_base(struct mm_struct *mm)
28803 {
28804 unsigned long gap = rlimit(RLIMIT_STACK);
28805+ unsigned long pax_task_size = TASK_SIZE;
28806+
28807+#ifdef CONFIG_PAX_SEGMEXEC
28808+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28809+ pax_task_size = SEGMEXEC_TASK_SIZE;
28810+#endif
28811
28812 if (gap < MIN_GAP)
28813 gap = MIN_GAP;
28814 else if (gap > MAX_GAP)
28815 gap = MAX_GAP;
28816
28817- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28818+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28819 }
28820
28821 /*
28822 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28823 * does, but not when emulating X86_32
28824 */
28825-static unsigned long mmap_legacy_base(void)
28826+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28827 {
28828- if (mmap_is_ia32())
28829+ if (mmap_is_ia32()) {
28830+
28831+#ifdef CONFIG_PAX_SEGMEXEC
28832+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28833+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28834+ else
28835+#endif
28836+
28837 return TASK_UNMAPPED_BASE;
28838- else
28839+ } else
28840 return TASK_UNMAPPED_BASE + mmap_rnd();
28841 }
28842
28843@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28844 void arch_pick_mmap_layout(struct mm_struct *mm)
28845 {
28846 if (mmap_is_legacy()) {
28847- mm->mmap_base = mmap_legacy_base();
28848+ mm->mmap_base = mmap_legacy_base(mm);
28849+
28850+#ifdef CONFIG_PAX_RANDMMAP
28851+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28852+ mm->mmap_base += mm->delta_mmap;
28853+#endif
28854+
28855 mm->get_unmapped_area = arch_get_unmapped_area;
28856 mm->unmap_area = arch_unmap_area;
28857 } else {
28858- mm->mmap_base = mmap_base();
28859+ mm->mmap_base = mmap_base(mm);
28860+
28861+#ifdef CONFIG_PAX_RANDMMAP
28862+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28863+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28864+#endif
28865+
28866 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28867 mm->unmap_area = arch_unmap_area_topdown;
28868 }
28869diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28870index dc0b727..f612039 100644
28871--- a/arch/x86/mm/mmio-mod.c
28872+++ b/arch/x86/mm/mmio-mod.c
28873@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28874 break;
28875 default:
28876 {
28877- unsigned char *ip = (unsigned char *)instptr;
28878+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28879 my_trace->opcode = MMIO_UNKNOWN_OP;
28880 my_trace->width = 0;
28881 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28882@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28883 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28884 void __iomem *addr)
28885 {
28886- static atomic_t next_id;
28887+ static atomic_unchecked_t next_id;
28888 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28889 /* These are page-unaligned. */
28890 struct mmiotrace_map map = {
28891@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28892 .private = trace
28893 },
28894 .phys = offset,
28895- .id = atomic_inc_return(&next_id)
28896+ .id = atomic_inc_return_unchecked(&next_id)
28897 };
28898 map.map_id = trace->id;
28899
28900@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28901 ioremap_trace_core(offset, size, addr);
28902 }
28903
28904-static void iounmap_trace_core(volatile void __iomem *addr)
28905+static void iounmap_trace_core(const volatile void __iomem *addr)
28906 {
28907 struct mmiotrace_map map = {
28908 .phys = 0,
28909@@ -328,7 +328,7 @@ not_enabled:
28910 }
28911 }
28912
28913-void mmiotrace_iounmap(volatile void __iomem *addr)
28914+void mmiotrace_iounmap(const volatile void __iomem *addr)
28915 {
28916 might_sleep();
28917 if (is_enabled()) /* recheck and proper locking in *_core() */
28918diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28919index a71c4e2..301ae44 100644
28920--- a/arch/x86/mm/numa.c
28921+++ b/arch/x86/mm/numa.c
28922@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28923 return true;
28924 }
28925
28926-static int __init numa_register_memblks(struct numa_meminfo *mi)
28927+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28928 {
28929 unsigned long uninitialized_var(pfn_align);
28930 int i, nid;
28931diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28932index d0b1773..4c3327c 100644
28933--- a/arch/x86/mm/pageattr-test.c
28934+++ b/arch/x86/mm/pageattr-test.c
28935@@ -36,7 +36,7 @@ enum {
28936
28937 static int pte_testbit(pte_t pte)
28938 {
28939- return pte_flags(pte) & _PAGE_UNUSED1;
28940+ return pte_flags(pte) & _PAGE_CPA_TEST;
28941 }
28942
28943 struct split_state {
28944diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28945index bb32480..aef8278 100644
28946--- a/arch/x86/mm/pageattr.c
28947+++ b/arch/x86/mm/pageattr.c
28948@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28949 */
28950 #ifdef CONFIG_PCI_BIOS
28951 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28952- pgprot_val(forbidden) |= _PAGE_NX;
28953+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28954 #endif
28955
28956 /*
28957@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28958 * Does not cover __inittext since that is gone later on. On
28959 * 64bit we do not enforce !NX on the low mapping
28960 */
28961- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28962- pgprot_val(forbidden) |= _PAGE_NX;
28963+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28964+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28965
28966+#ifdef CONFIG_DEBUG_RODATA
28967 /*
28968 * The .rodata section needs to be read-only. Using the pfn
28969 * catches all aliases.
28970@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28971 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
28972 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
28973 pgprot_val(forbidden) |= _PAGE_RW;
28974+#endif
28975
28976 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28977 /*
28978@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28979 }
28980 #endif
28981
28982+#ifdef CONFIG_PAX_KERNEXEC
28983+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28984+ pgprot_val(forbidden) |= _PAGE_RW;
28985+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28986+ }
28987+#endif
28988+
28989 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28990
28991 return prot;
28992@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
28993 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28994 {
28995 /* change init_mm */
28996+ pax_open_kernel();
28997 set_pte_atomic(kpte, pte);
28998+
28999 #ifdef CONFIG_X86_32
29000 if (!SHARED_KERNEL_PMD) {
29001+
29002+#ifdef CONFIG_PAX_PER_CPU_PGD
29003+ unsigned long cpu;
29004+#else
29005 struct page *page;
29006+#endif
29007
29008+#ifdef CONFIG_PAX_PER_CPU_PGD
29009+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29010+ pgd_t *pgd = get_cpu_pgd(cpu);
29011+#else
29012 list_for_each_entry(page, &pgd_list, lru) {
29013- pgd_t *pgd;
29014+ pgd_t *pgd = (pgd_t *)page_address(page);
29015+#endif
29016+
29017 pud_t *pud;
29018 pmd_t *pmd;
29019
29020- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29021+ pgd += pgd_index(address);
29022 pud = pud_offset(pgd, address);
29023 pmd = pmd_offset(pud, address);
29024 set_pte_atomic((pte_t *)pmd, pte);
29025 }
29026 }
29027 #endif
29028+ pax_close_kernel();
29029 }
29030
29031 static int
29032diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29033index 6574388..87e9bef 100644
29034--- a/arch/x86/mm/pat.c
29035+++ b/arch/x86/mm/pat.c
29036@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29037
29038 if (!entry) {
29039 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29040- current->comm, current->pid, start, end - 1);
29041+ current->comm, task_pid_nr(current), start, end - 1);
29042 return -EINVAL;
29043 }
29044
29045@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29046
29047 while (cursor < to) {
29048 if (!devmem_is_allowed(pfn)) {
29049- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29050- current->comm, from, to - 1);
29051+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29052+ current->comm, from, to - 1, cursor);
29053 return 0;
29054 }
29055 cursor += PAGE_SIZE;
29056@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29057 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29058 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29059 "for [mem %#010Lx-%#010Lx]\n",
29060- current->comm, current->pid,
29061+ current->comm, task_pid_nr(current),
29062 cattr_name(flags),
29063 base, (unsigned long long)(base + size-1));
29064 return -EINVAL;
29065@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29066 flags = lookup_memtype(paddr);
29067 if (want_flags != flags) {
29068 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29069- current->comm, current->pid,
29070+ current->comm, task_pid_nr(current),
29071 cattr_name(want_flags),
29072 (unsigned long long)paddr,
29073 (unsigned long long)(paddr + size - 1),
29074@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29075 free_memtype(paddr, paddr + size);
29076 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29077 " for [mem %#010Lx-%#010Lx], got %s\n",
29078- current->comm, current->pid,
29079+ current->comm, task_pid_nr(current),
29080 cattr_name(want_flags),
29081 (unsigned long long)paddr,
29082 (unsigned long long)(paddr + size - 1),
29083diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
29084index 415f6c4..d319983 100644
29085--- a/arch/x86/mm/pat_rbtree.c
29086+++ b/arch/x86/mm/pat_rbtree.c
29087@@ -160,7 +160,7 @@ success:
29088
29089 failure:
29090 printk(KERN_INFO "%s:%d conflicting memory types "
29091- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
29092+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
29093 end, cattr_name(found_type), cattr_name(match->type));
29094 return -EBUSY;
29095 }
29096diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29097index 9f0614d..92ae64a 100644
29098--- a/arch/x86/mm/pf_in.c
29099+++ b/arch/x86/mm/pf_in.c
29100@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29101 int i;
29102 enum reason_type rv = OTHERS;
29103
29104- p = (unsigned char *)ins_addr;
29105+ p = (unsigned char *)ktla_ktva(ins_addr);
29106 p += skip_prefix(p, &prf);
29107 p += get_opcode(p, &opcode);
29108
29109@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29110 struct prefix_bits prf;
29111 int i;
29112
29113- p = (unsigned char *)ins_addr;
29114+ p = (unsigned char *)ktla_ktva(ins_addr);
29115 p += skip_prefix(p, &prf);
29116 p += get_opcode(p, &opcode);
29117
29118@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29119 struct prefix_bits prf;
29120 int i;
29121
29122- p = (unsigned char *)ins_addr;
29123+ p = (unsigned char *)ktla_ktva(ins_addr);
29124 p += skip_prefix(p, &prf);
29125 p += get_opcode(p, &opcode);
29126
29127@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29128 struct prefix_bits prf;
29129 int i;
29130
29131- p = (unsigned char *)ins_addr;
29132+ p = (unsigned char *)ktla_ktva(ins_addr);
29133 p += skip_prefix(p, &prf);
29134 p += get_opcode(p, &opcode);
29135 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29136@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29137 struct prefix_bits prf;
29138 int i;
29139
29140- p = (unsigned char *)ins_addr;
29141+ p = (unsigned char *)ktla_ktva(ins_addr);
29142 p += skip_prefix(p, &prf);
29143 p += get_opcode(p, &opcode);
29144 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29145diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29146index 17fda6a..489c74a 100644
29147--- a/arch/x86/mm/pgtable.c
29148+++ b/arch/x86/mm/pgtable.c
29149@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29150 list_del(&page->lru);
29151 }
29152
29153-#define UNSHARED_PTRS_PER_PGD \
29154- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29155+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29156+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29157
29158+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29159+{
29160+ unsigned int count = USER_PGD_PTRS;
29161
29162+ while (count--)
29163+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29164+}
29165+#endif
29166+
29167+#ifdef CONFIG_PAX_PER_CPU_PGD
29168+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29169+{
29170+ unsigned int count = USER_PGD_PTRS;
29171+
29172+ while (count--) {
29173+ pgd_t pgd;
29174+
29175+#ifdef CONFIG_X86_64
29176+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29177+#else
29178+ pgd = *src++;
29179+#endif
29180+
29181+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29182+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29183+#endif
29184+
29185+ *dst++ = pgd;
29186+ }
29187+
29188+}
29189+#endif
29190+
29191+#ifdef CONFIG_X86_64
29192+#define pxd_t pud_t
29193+#define pyd_t pgd_t
29194+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29195+#define pxd_free(mm, pud) pud_free((mm), (pud))
29196+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29197+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29198+#define PYD_SIZE PGDIR_SIZE
29199+#else
29200+#define pxd_t pmd_t
29201+#define pyd_t pud_t
29202+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29203+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29204+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29205+#define pyd_offset(mm, address) pud_offset((mm), (address))
29206+#define PYD_SIZE PUD_SIZE
29207+#endif
29208+
29209+#ifdef CONFIG_PAX_PER_CPU_PGD
29210+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29211+static inline void pgd_dtor(pgd_t *pgd) {}
29212+#else
29213 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29214 {
29215 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29216@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29217 pgd_list_del(pgd);
29218 spin_unlock(&pgd_lock);
29219 }
29220+#endif
29221
29222 /*
29223 * List of all pgd's needed for non-PAE so it can invalidate entries
29224@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29225 * -- nyc
29226 */
29227
29228-#ifdef CONFIG_X86_PAE
29229+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29230 /*
29231 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29232 * updating the top-level pagetable entries to guarantee the
29233@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29234 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29235 * and initialize the kernel pmds here.
29236 */
29237-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29238+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29239
29240 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29241 {
29242@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29243 */
29244 flush_tlb_mm(mm);
29245 }
29246+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29247+#define PREALLOCATED_PXDS USER_PGD_PTRS
29248 #else /* !CONFIG_X86_PAE */
29249
29250 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29251-#define PREALLOCATED_PMDS 0
29252+#define PREALLOCATED_PXDS 0
29253
29254 #endif /* CONFIG_X86_PAE */
29255
29256-static void free_pmds(pmd_t *pmds[])
29257+static void free_pxds(pxd_t *pxds[])
29258 {
29259 int i;
29260
29261- for(i = 0; i < PREALLOCATED_PMDS; i++)
29262- if (pmds[i])
29263- free_page((unsigned long)pmds[i]);
29264+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29265+ if (pxds[i])
29266+ free_page((unsigned long)pxds[i]);
29267 }
29268
29269-static int preallocate_pmds(pmd_t *pmds[])
29270+static int preallocate_pxds(pxd_t *pxds[])
29271 {
29272 int i;
29273 bool failed = false;
29274
29275- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29276- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29277- if (pmd == NULL)
29278+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29279+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29280+ if (pxd == NULL)
29281 failed = true;
29282- pmds[i] = pmd;
29283+ pxds[i] = pxd;
29284 }
29285
29286 if (failed) {
29287- free_pmds(pmds);
29288+ free_pxds(pxds);
29289 return -ENOMEM;
29290 }
29291
29292@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29293 * preallocate which never got a corresponding vma will need to be
29294 * freed manually.
29295 */
29296-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29297+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29298 {
29299 int i;
29300
29301- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29302+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29303 pgd_t pgd = pgdp[i];
29304
29305 if (pgd_val(pgd) != 0) {
29306- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29307+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29308
29309- pgdp[i] = native_make_pgd(0);
29310+ set_pgd(pgdp + i, native_make_pgd(0));
29311
29312- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29313- pmd_free(mm, pmd);
29314+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29315+ pxd_free(mm, pxd);
29316 }
29317 }
29318 }
29319
29320-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29321+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29322 {
29323- pud_t *pud;
29324+ pyd_t *pyd;
29325 unsigned long addr;
29326 int i;
29327
29328- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29329+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29330 return;
29331
29332- pud = pud_offset(pgd, 0);
29333+#ifdef CONFIG_X86_64
29334+ pyd = pyd_offset(mm, 0L);
29335+#else
29336+ pyd = pyd_offset(pgd, 0L);
29337+#endif
29338
29339- for (addr = i = 0; i < PREALLOCATED_PMDS;
29340- i++, pud++, addr += PUD_SIZE) {
29341- pmd_t *pmd = pmds[i];
29342+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29343+ i++, pyd++, addr += PYD_SIZE) {
29344+ pxd_t *pxd = pxds[i];
29345
29346 if (i >= KERNEL_PGD_BOUNDARY)
29347- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29348- sizeof(pmd_t) * PTRS_PER_PMD);
29349+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29350+ sizeof(pxd_t) * PTRS_PER_PMD);
29351
29352- pud_populate(mm, pud, pmd);
29353+ pyd_populate(mm, pyd, pxd);
29354 }
29355 }
29356
29357 pgd_t *pgd_alloc(struct mm_struct *mm)
29358 {
29359 pgd_t *pgd;
29360- pmd_t *pmds[PREALLOCATED_PMDS];
29361+ pxd_t *pxds[PREALLOCATED_PXDS];
29362
29363 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29364
29365@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29366
29367 mm->pgd = pgd;
29368
29369- if (preallocate_pmds(pmds) != 0)
29370+ if (preallocate_pxds(pxds) != 0)
29371 goto out_free_pgd;
29372
29373 if (paravirt_pgd_alloc(mm) != 0)
29374- goto out_free_pmds;
29375+ goto out_free_pxds;
29376
29377 /*
29378 * Make sure that pre-populating the pmds is atomic with
29379@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29380 spin_lock(&pgd_lock);
29381
29382 pgd_ctor(mm, pgd);
29383- pgd_prepopulate_pmd(mm, pgd, pmds);
29384+ pgd_prepopulate_pxd(mm, pgd, pxds);
29385
29386 spin_unlock(&pgd_lock);
29387
29388 return pgd;
29389
29390-out_free_pmds:
29391- free_pmds(pmds);
29392+out_free_pxds:
29393+ free_pxds(pxds);
29394 out_free_pgd:
29395 free_page((unsigned long)pgd);
29396 out:
29397@@ -302,7 +363,7 @@ out:
29398
29399 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29400 {
29401- pgd_mop_up_pmds(mm, pgd);
29402+ pgd_mop_up_pxds(mm, pgd);
29403 pgd_dtor(pgd);
29404 paravirt_pgd_free(mm, pgd);
29405 free_page((unsigned long)pgd);
29406diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29407index a69bcb8..19068ab 100644
29408--- a/arch/x86/mm/pgtable_32.c
29409+++ b/arch/x86/mm/pgtable_32.c
29410@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29411 return;
29412 }
29413 pte = pte_offset_kernel(pmd, vaddr);
29414+
29415+ pax_open_kernel();
29416 if (pte_val(pteval))
29417 set_pte_at(&init_mm, vaddr, pte, pteval);
29418 else
29419 pte_clear(&init_mm, vaddr, pte);
29420+ pax_close_kernel();
29421
29422 /*
29423 * It's enough to flush this one mapping.
29424diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29425index e666cbb..61788c45 100644
29426--- a/arch/x86/mm/physaddr.c
29427+++ b/arch/x86/mm/physaddr.c
29428@@ -10,7 +10,7 @@
29429 #ifdef CONFIG_X86_64
29430
29431 #ifdef CONFIG_DEBUG_VIRTUAL
29432-unsigned long __phys_addr(unsigned long x)
29433+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29434 {
29435 unsigned long y = x - __START_KERNEL_map;
29436
29437@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29438 #else
29439
29440 #ifdef CONFIG_DEBUG_VIRTUAL
29441-unsigned long __phys_addr(unsigned long x)
29442+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29443 {
29444 unsigned long phys_addr = x - PAGE_OFFSET;
29445 /* VMALLOC_* aren't constants */
29446diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29447index 410531d..0f16030 100644
29448--- a/arch/x86/mm/setup_nx.c
29449+++ b/arch/x86/mm/setup_nx.c
29450@@ -5,8 +5,10 @@
29451 #include <asm/pgtable.h>
29452 #include <asm/proto.h>
29453
29454+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29455 static int disable_nx __cpuinitdata;
29456
29457+#ifndef CONFIG_PAX_PAGEEXEC
29458 /*
29459 * noexec = on|off
29460 *
29461@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29462 return 0;
29463 }
29464 early_param("noexec", noexec_setup);
29465+#endif
29466+
29467+#endif
29468
29469 void __cpuinit x86_configure_nx(void)
29470 {
29471+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29472 if (cpu_has_nx && !disable_nx)
29473 __supported_pte_mask |= _PAGE_NX;
29474 else
29475+#endif
29476 __supported_pte_mask &= ~_PAGE_NX;
29477 }
29478
29479diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29480index 282375f..e03a98f 100644
29481--- a/arch/x86/mm/tlb.c
29482+++ b/arch/x86/mm/tlb.c
29483@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29484 BUG();
29485 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29486 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29487+
29488+#ifndef CONFIG_PAX_PER_CPU_PGD
29489 load_cr3(swapper_pg_dir);
29490+#endif
29491+
29492 }
29493 }
29494 EXPORT_SYMBOL_GPL(leave_mm);
29495diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29496index 877b9a1..a8ecf42 100644
29497--- a/arch/x86/net/bpf_jit.S
29498+++ b/arch/x86/net/bpf_jit.S
29499@@ -9,6 +9,7 @@
29500 */
29501 #include <linux/linkage.h>
29502 #include <asm/dwarf2.h>
29503+#include <asm/alternative-asm.h>
29504
29505 /*
29506 * Calling convention :
29507@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29508 jle bpf_slow_path_word
29509 mov (SKBDATA,%rsi),%eax
29510 bswap %eax /* ntohl() */
29511+ pax_force_retaddr
29512 ret
29513
29514 sk_load_half:
29515@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29516 jle bpf_slow_path_half
29517 movzwl (SKBDATA,%rsi),%eax
29518 rol $8,%ax # ntohs()
29519+ pax_force_retaddr
29520 ret
29521
29522 sk_load_byte:
29523@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29524 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29525 jle bpf_slow_path_byte
29526 movzbl (SKBDATA,%rsi),%eax
29527+ pax_force_retaddr
29528 ret
29529
29530 /**
29531@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29532 movzbl (SKBDATA,%rsi),%ebx
29533 and $15,%bl
29534 shl $2,%bl
29535+ pax_force_retaddr
29536 ret
29537
29538 /* rsi contains offset and can be scratched */
29539@@ -109,6 +114,7 @@ bpf_slow_path_word:
29540 js bpf_error
29541 mov -12(%rbp),%eax
29542 bswap %eax
29543+ pax_force_retaddr
29544 ret
29545
29546 bpf_slow_path_half:
29547@@ -117,12 +123,14 @@ bpf_slow_path_half:
29548 mov -12(%rbp),%ax
29549 rol $8,%ax
29550 movzwl %ax,%eax
29551+ pax_force_retaddr
29552 ret
29553
29554 bpf_slow_path_byte:
29555 bpf_slow_path_common(1)
29556 js bpf_error
29557 movzbl -12(%rbp),%eax
29558+ pax_force_retaddr
29559 ret
29560
29561 bpf_slow_path_byte_msh:
29562@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29563 and $15,%al
29564 shl $2,%al
29565 xchg %eax,%ebx
29566+ pax_force_retaddr
29567 ret
29568
29569 #define sk_negative_common(SIZE) \
29570@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29571 sk_negative_common(4)
29572 mov (%rax), %eax
29573 bswap %eax
29574+ pax_force_retaddr
29575 ret
29576
29577 bpf_slow_path_half_neg:
29578@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29579 mov (%rax),%ax
29580 rol $8,%ax
29581 movzwl %ax,%eax
29582+ pax_force_retaddr
29583 ret
29584
29585 bpf_slow_path_byte_neg:
29586@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29587 .globl sk_load_byte_negative_offset
29588 sk_negative_common(1)
29589 movzbl (%rax), %eax
29590+ pax_force_retaddr
29591 ret
29592
29593 bpf_slow_path_byte_msh_neg:
29594@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29595 and $15,%al
29596 shl $2,%al
29597 xchg %eax,%ebx
29598+ pax_force_retaddr
29599 ret
29600
29601 bpf_error:
29602@@ -197,4 +210,5 @@ bpf_error:
29603 xor %eax,%eax
29604 mov -8(%rbp),%rbx
29605 leaveq
29606+ pax_force_retaddr
29607 ret
29608diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29609index f66b540..3e88dfb 100644
29610--- a/arch/x86/net/bpf_jit_comp.c
29611+++ b/arch/x86/net/bpf_jit_comp.c
29612@@ -12,6 +12,7 @@
29613 #include <linux/netdevice.h>
29614 #include <linux/filter.h>
29615 #include <linux/if_vlan.h>
29616+#include <linux/random.h>
29617
29618 /*
29619 * Conventions :
29620@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29621 return ptr + len;
29622 }
29623
29624+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29625+#define MAX_INSTR_CODE_SIZE 96
29626+#else
29627+#define MAX_INSTR_CODE_SIZE 64
29628+#endif
29629+
29630 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29631
29632 #define EMIT1(b1) EMIT(b1, 1)
29633 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29634 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29635 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29636+
29637+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29638+/* original constant will appear in ecx */
29639+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29640+do { \
29641+ /* mov ecx, randkey */ \
29642+ EMIT1(0xb9); \
29643+ EMIT(_key, 4); \
29644+ /* xor ecx, randkey ^ off */ \
29645+ EMIT2(0x81, 0xf1); \
29646+ EMIT((_key) ^ (_off), 4); \
29647+} while (0)
29648+
29649+#define EMIT1_off32(b1, _off) \
29650+do { \
29651+ switch (b1) { \
29652+ case 0x05: /* add eax, imm32 */ \
29653+ case 0x2d: /* sub eax, imm32 */ \
29654+ case 0x25: /* and eax, imm32 */ \
29655+ case 0x0d: /* or eax, imm32 */ \
29656+ case 0xb8: /* mov eax, imm32 */ \
29657+ case 0x35: /* xor eax, imm32 */ \
29658+ case 0x3d: /* cmp eax, imm32 */ \
29659+ case 0xa9: /* test eax, imm32 */ \
29660+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29661+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29662+ break; \
29663+ case 0xbb: /* mov ebx, imm32 */ \
29664+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29665+ /* mov ebx, ecx */ \
29666+ EMIT2(0x89, 0xcb); \
29667+ break; \
29668+ case 0xbe: /* mov esi, imm32 */ \
29669+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29670+ /* mov esi, ecx */ \
29671+ EMIT2(0x89, 0xce); \
29672+ break; \
29673+ case 0xe8: /* call rel imm32, always to known funcs */ \
29674+ EMIT1(b1); \
29675+ EMIT(_off, 4); \
29676+ break; \
29677+ case 0xe9: /* jmp rel imm32 */ \
29678+ EMIT1(b1); \
29679+ EMIT(_off, 4); \
29680+ /* prevent fall-through, we're not called if off = 0 */ \
29681+ EMIT(0xcccccccc, 4); \
29682+ EMIT(0xcccccccc, 4); \
29683+ break; \
29684+ default: \
29685+ BUILD_BUG(); \
29686+ } \
29687+} while (0)
29688+
29689+#define EMIT2_off32(b1, b2, _off) \
29690+do { \
29691+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29692+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29693+ EMIT(randkey, 4); \
29694+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29695+ EMIT((_off) - randkey, 4); \
29696+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29697+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29698+ /* imul eax, ecx */ \
29699+ EMIT3(0x0f, 0xaf, 0xc1); \
29700+ } else { \
29701+ BUILD_BUG(); \
29702+ } \
29703+} while (0)
29704+#else
29705 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29706+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29707+#endif
29708
29709 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29710 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29711@@ -90,6 +168,24 @@ do { \
29712 #define X86_JBE 0x76
29713 #define X86_JA 0x77
29714
29715+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29716+#define APPEND_FLOW_VERIFY() \
29717+do { \
29718+ /* mov ecx, randkey */ \
29719+ EMIT1(0xb9); \
29720+ EMIT(randkey, 4); \
29721+ /* cmp ecx, randkey */ \
29722+ EMIT2(0x81, 0xf9); \
29723+ EMIT(randkey, 4); \
29724+ /* jz after 8 int 3s */ \
29725+ EMIT2(0x74, 0x08); \
29726+ EMIT(0xcccccccc, 4); \
29727+ EMIT(0xcccccccc, 4); \
29728+} while (0)
29729+#else
29730+#define APPEND_FLOW_VERIFY() do { } while (0)
29731+#endif
29732+
29733 #define EMIT_COND_JMP(op, offset) \
29734 do { \
29735 if (is_near(offset)) \
29736@@ -97,6 +193,7 @@ do { \
29737 else { \
29738 EMIT2(0x0f, op + 0x10); \
29739 EMIT(offset, 4); /* jxx .+off32 */ \
29740+ APPEND_FLOW_VERIFY(); \
29741 } \
29742 } while (0)
29743
29744@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
29745 set_fs(old_fs);
29746 }
29747
29748+struct bpf_jit_work {
29749+ struct work_struct work;
29750+ void *image;
29751+};
29752+
29753 #define CHOOSE_LOAD_FUNC(K, func) \
29754 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29755
29756@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
29757
29758 void bpf_jit_compile(struct sk_filter *fp)
29759 {
29760- u8 temp[64];
29761+ u8 temp[MAX_INSTR_CODE_SIZE];
29762 u8 *prog;
29763 unsigned int proglen, oldproglen = 0;
29764 int ilen, i;
29765@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29766 unsigned int *addrs;
29767 const struct sock_filter *filter = fp->insns;
29768 int flen = fp->len;
29769+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29770+ unsigned int randkey;
29771+#endif
29772
29773 if (!bpf_jit_enable)
29774 return;
29775@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29776 if (addrs == NULL)
29777 return;
29778
29779+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29780+ if (!fp->work)
29781+ goto out;
29782+
29783+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29784+ randkey = get_random_int();
29785+#endif
29786+
29787 /* Before first pass, make a rough estimation of addrs[]
29788- * each bpf instruction is translated to less than 64 bytes
29789+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29790 */
29791 for (proglen = 0, i = 0; i < flen; i++) {
29792- proglen += 64;
29793+ proglen += MAX_INSTR_CODE_SIZE;
29794 addrs[i] = proglen;
29795 }
29796 cleanup_addr = proglen; /* epilogue address */
29797@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29798 case BPF_S_ALU_MUL_K: /* A *= K */
29799 if (is_imm8(K))
29800 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29801- else {
29802- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29803- EMIT(K, 4);
29804- }
29805+ else
29806+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29807 break;
29808 case BPF_S_ALU_DIV_X: /* A /= X; */
29809 seen |= SEEN_XREG;
29810@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29811 break;
29812 case BPF_S_ALU_MOD_K: /* A %= K; */
29813 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29814+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29815+ DILUTE_CONST_SEQUENCE(K, randkey);
29816+#else
29817 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29818+#endif
29819 EMIT2(0xf7, 0xf1); /* div %ecx */
29820 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29821 break;
29822 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29823+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29824+ DILUTE_CONST_SEQUENCE(K, randkey);
29825+ // imul rax, rcx
29826+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29827+#else
29828 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29829 EMIT(K, 4);
29830+#endif
29831 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29832 break;
29833 case BPF_S_ALU_AND_X:
29834@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29835 if (is_imm8(K)) {
29836 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29837 } else {
29838- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29839- EMIT(K, 4);
29840+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29841 }
29842 } else {
29843 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29844@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29845 break;
29846 default:
29847 /* hmm, too complex filter, give up with jit compiler */
29848- goto out;
29849+ goto error;
29850 }
29851 ilen = prog - temp;
29852 if (image) {
29853 if (unlikely(proglen + ilen > oldproglen)) {
29854 pr_err("bpb_jit_compile fatal error\n");
29855- kfree(addrs);
29856- module_free(NULL, image);
29857- return;
29858+ module_free_exec(NULL, image);
29859+ goto error;
29860 }
29861+ pax_open_kernel();
29862 memcpy(image + proglen, temp, ilen);
29863+ pax_close_kernel();
29864 }
29865 proglen += ilen;
29866 addrs[i] = proglen;
29867@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29868 break;
29869 }
29870 if (proglen == oldproglen) {
29871- image = module_alloc(max_t(unsigned int,
29872- proglen,
29873- sizeof(struct work_struct)));
29874+ image = module_alloc_exec(proglen);
29875 if (!image)
29876- goto out;
29877+ goto error;
29878 }
29879 oldproglen = proglen;
29880 }
29881@@ -732,7 +851,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29882 if (image) {
29883 bpf_flush_icache(image, image + proglen);
29884 fp->bpf_func = (void *)image;
29885- }
29886+ } else
29887+error:
29888+ kfree(fp->work);
29889+
29890 out:
29891 kfree(addrs);
29892 return;
29893@@ -740,18 +862,20 @@ out:
29894
29895 static void jit_free_defer(struct work_struct *arg)
29896 {
29897- module_free(NULL, arg);
29898+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29899+ kfree(arg);
29900 }
29901
29902 /* run from softirq, we must use a work_struct to call
29903- * module_free() from process context
29904+ * module_free_exec() from process context
29905 */
29906 void bpf_jit_free(struct sk_filter *fp)
29907 {
29908 if (fp->bpf_func != sk_run_filter) {
29909- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29910+ struct work_struct *work = &fp->work->work;
29911
29912 INIT_WORK(work, jit_free_defer);
29913+ fp->work->image = fp->bpf_func;
29914 schedule_work(work);
29915 }
29916 }
29917diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29918index d6aa6e8..266395a 100644
29919--- a/arch/x86/oprofile/backtrace.c
29920+++ b/arch/x86/oprofile/backtrace.c
29921@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29922 struct stack_frame_ia32 *fp;
29923 unsigned long bytes;
29924
29925- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29926+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29927 if (bytes != sizeof(bufhead))
29928 return NULL;
29929
29930- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29931+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29932
29933 oprofile_add_trace(bufhead[0].return_address);
29934
29935@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29936 struct stack_frame bufhead[2];
29937 unsigned long bytes;
29938
29939- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29940+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29941 if (bytes != sizeof(bufhead))
29942 return NULL;
29943
29944@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29945 {
29946 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29947
29948- if (!user_mode_vm(regs)) {
29949+ if (!user_mode(regs)) {
29950 unsigned long stack = kernel_stack_pointer(regs);
29951 if (depth)
29952 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29953diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29954index 48768df..ba9143c 100644
29955--- a/arch/x86/oprofile/nmi_int.c
29956+++ b/arch/x86/oprofile/nmi_int.c
29957@@ -23,6 +23,7 @@
29958 #include <asm/nmi.h>
29959 #include <asm/msr.h>
29960 #include <asm/apic.h>
29961+#include <asm/pgtable.h>
29962
29963 #include "op_counter.h"
29964 #include "op_x86_model.h"
29965@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29966 if (ret)
29967 return ret;
29968
29969- if (!model->num_virt_counters)
29970- model->num_virt_counters = model->num_counters;
29971+ if (!model->num_virt_counters) {
29972+ pax_open_kernel();
29973+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29974+ pax_close_kernel();
29975+ }
29976
29977 mux_init(ops);
29978
29979diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29980index b2b9443..be58856 100644
29981--- a/arch/x86/oprofile/op_model_amd.c
29982+++ b/arch/x86/oprofile/op_model_amd.c
29983@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29984 num_counters = AMD64_NUM_COUNTERS;
29985 }
29986
29987- op_amd_spec.num_counters = num_counters;
29988- op_amd_spec.num_controls = num_counters;
29989- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29990+ pax_open_kernel();
29991+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29992+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29993+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29994+ pax_close_kernel();
29995
29996 return 0;
29997 }
29998diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29999index d90528e..0127e2b 100644
30000--- a/arch/x86/oprofile/op_model_ppro.c
30001+++ b/arch/x86/oprofile/op_model_ppro.c
30002@@ -19,6 +19,7 @@
30003 #include <asm/msr.h>
30004 #include <asm/apic.h>
30005 #include <asm/nmi.h>
30006+#include <asm/pgtable.h>
30007
30008 #include "op_x86_model.h"
30009 #include "op_counter.h"
30010@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
30011
30012 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
30013
30014- op_arch_perfmon_spec.num_counters = num_counters;
30015- op_arch_perfmon_spec.num_controls = num_counters;
30016+ pax_open_kernel();
30017+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30018+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30019+ pax_close_kernel();
30020 }
30021
30022 static int arch_perfmon_init(struct oprofile_operations *ignore)
30023diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30024index 71e8a67..6a313bb 100644
30025--- a/arch/x86/oprofile/op_x86_model.h
30026+++ b/arch/x86/oprofile/op_x86_model.h
30027@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30028 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30029 struct op_msrs const * const msrs);
30030 #endif
30031-};
30032+} __do_const;
30033
30034 struct op_counter_config;
30035
30036diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30037index e9e6ed5..e47ae67 100644
30038--- a/arch/x86/pci/amd_bus.c
30039+++ b/arch/x86/pci/amd_bus.c
30040@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30041 return NOTIFY_OK;
30042 }
30043
30044-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30045+static struct notifier_block amd_cpu_notifier = {
30046 .notifier_call = amd_cpu_notify,
30047 };
30048
30049diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30050index 372e9b8..e775a6c 100644
30051--- a/arch/x86/pci/irq.c
30052+++ b/arch/x86/pci/irq.c
30053@@ -50,7 +50,7 @@ struct irq_router {
30054 struct irq_router_handler {
30055 u16 vendor;
30056 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30057-};
30058+} __do_const;
30059
30060 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30061 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30062@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30063 return 0;
30064 }
30065
30066-static __initdata struct irq_router_handler pirq_routers[] = {
30067+static __initconst const struct irq_router_handler pirq_routers[] = {
30068 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30069 { PCI_VENDOR_ID_AL, ali_router_probe },
30070 { PCI_VENDOR_ID_ITE, ite_router_probe },
30071@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30072 static void __init pirq_find_router(struct irq_router *r)
30073 {
30074 struct irq_routing_table *rt = pirq_table;
30075- struct irq_router_handler *h;
30076+ const struct irq_router_handler *h;
30077
30078 #ifdef CONFIG_PCI_BIOS
30079 if (!rt->signature) {
30080@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30081 return 0;
30082 }
30083
30084-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30085+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30086 {
30087 .callback = fix_broken_hp_bios_irq9,
30088 .ident = "HP Pavilion N5400 Series Laptop",
30089diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30090index 6eb18c4..20d83de 100644
30091--- a/arch/x86/pci/mrst.c
30092+++ b/arch/x86/pci/mrst.c
30093@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30094 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30095 pci_mmcfg_late_init();
30096 pcibios_enable_irq = mrst_pci_irq_enable;
30097- pci_root_ops = pci_mrst_ops;
30098+ pax_open_kernel();
30099+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30100+ pax_close_kernel();
30101 pci_soc_mode = 1;
30102 /* Continue with standard init */
30103 return 1;
30104diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30105index c77b24a..c979855 100644
30106--- a/arch/x86/pci/pcbios.c
30107+++ b/arch/x86/pci/pcbios.c
30108@@ -79,7 +79,7 @@ union bios32 {
30109 static struct {
30110 unsigned long address;
30111 unsigned short segment;
30112-} bios32_indirect = { 0, __KERNEL_CS };
30113+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30114
30115 /*
30116 * Returns the entry point for the given service, NULL on error
30117@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30118 unsigned long length; /* %ecx */
30119 unsigned long entry; /* %edx */
30120 unsigned long flags;
30121+ struct desc_struct d, *gdt;
30122
30123 local_irq_save(flags);
30124- __asm__("lcall *(%%edi); cld"
30125+
30126+ gdt = get_cpu_gdt_table(smp_processor_id());
30127+
30128+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30129+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30130+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30131+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30132+
30133+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30134 : "=a" (return_code),
30135 "=b" (address),
30136 "=c" (length),
30137 "=d" (entry)
30138 : "0" (service),
30139 "1" (0),
30140- "D" (&bios32_indirect));
30141+ "D" (&bios32_indirect),
30142+ "r"(__PCIBIOS_DS)
30143+ : "memory");
30144+
30145+ pax_open_kernel();
30146+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30147+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30148+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30149+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30150+ pax_close_kernel();
30151+
30152 local_irq_restore(flags);
30153
30154 switch (return_code) {
30155- case 0:
30156- return address + entry;
30157- case 0x80: /* Not present */
30158- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30159- return 0;
30160- default: /* Shouldn't happen */
30161- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30162- service, return_code);
30163+ case 0: {
30164+ int cpu;
30165+ unsigned char flags;
30166+
30167+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30168+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30169+ printk(KERN_WARNING "bios32_service: not valid\n");
30170 return 0;
30171+ }
30172+ address = address + PAGE_OFFSET;
30173+ length += 16UL; /* some BIOSs underreport this... */
30174+ flags = 4;
30175+ if (length >= 64*1024*1024) {
30176+ length >>= PAGE_SHIFT;
30177+ flags |= 8;
30178+ }
30179+
30180+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30181+ gdt = get_cpu_gdt_table(cpu);
30182+ pack_descriptor(&d, address, length, 0x9b, flags);
30183+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30184+ pack_descriptor(&d, address, length, 0x93, flags);
30185+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30186+ }
30187+ return entry;
30188+ }
30189+ case 0x80: /* Not present */
30190+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30191+ return 0;
30192+ default: /* Shouldn't happen */
30193+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30194+ service, return_code);
30195+ return 0;
30196 }
30197 }
30198
30199 static struct {
30200 unsigned long address;
30201 unsigned short segment;
30202-} pci_indirect = { 0, __KERNEL_CS };
30203+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30204
30205-static int pci_bios_present;
30206+static int pci_bios_present __read_only;
30207
30208 static int check_pcibios(void)
30209 {
30210@@ -131,11 +174,13 @@ static int check_pcibios(void)
30211 unsigned long flags, pcibios_entry;
30212
30213 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30214- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30215+ pci_indirect.address = pcibios_entry;
30216
30217 local_irq_save(flags);
30218- __asm__(
30219- "lcall *(%%edi); cld\n\t"
30220+ __asm__("movw %w6, %%ds\n\t"
30221+ "lcall *%%ss:(%%edi); cld\n\t"
30222+ "push %%ss\n\t"
30223+ "pop %%ds\n\t"
30224 "jc 1f\n\t"
30225 "xor %%ah, %%ah\n"
30226 "1:"
30227@@ -144,7 +189,8 @@ static int check_pcibios(void)
30228 "=b" (ebx),
30229 "=c" (ecx)
30230 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30231- "D" (&pci_indirect)
30232+ "D" (&pci_indirect),
30233+ "r" (__PCIBIOS_DS)
30234 : "memory");
30235 local_irq_restore(flags);
30236
30237@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30238
30239 switch (len) {
30240 case 1:
30241- __asm__("lcall *(%%esi); cld\n\t"
30242+ __asm__("movw %w6, %%ds\n\t"
30243+ "lcall *%%ss:(%%esi); cld\n\t"
30244+ "push %%ss\n\t"
30245+ "pop %%ds\n\t"
30246 "jc 1f\n\t"
30247 "xor %%ah, %%ah\n"
30248 "1:"
30249@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30250 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30251 "b" (bx),
30252 "D" ((long)reg),
30253- "S" (&pci_indirect));
30254+ "S" (&pci_indirect),
30255+ "r" (__PCIBIOS_DS));
30256 /*
30257 * Zero-extend the result beyond 8 bits, do not trust the
30258 * BIOS having done it:
30259@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30260 *value &= 0xff;
30261 break;
30262 case 2:
30263- __asm__("lcall *(%%esi); cld\n\t"
30264+ __asm__("movw %w6, %%ds\n\t"
30265+ "lcall *%%ss:(%%esi); cld\n\t"
30266+ "push %%ss\n\t"
30267+ "pop %%ds\n\t"
30268 "jc 1f\n\t"
30269 "xor %%ah, %%ah\n"
30270 "1:"
30271@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30272 : "1" (PCIBIOS_READ_CONFIG_WORD),
30273 "b" (bx),
30274 "D" ((long)reg),
30275- "S" (&pci_indirect));
30276+ "S" (&pci_indirect),
30277+ "r" (__PCIBIOS_DS));
30278 /*
30279 * Zero-extend the result beyond 16 bits, do not trust the
30280 * BIOS having done it:
30281@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30282 *value &= 0xffff;
30283 break;
30284 case 4:
30285- __asm__("lcall *(%%esi); cld\n\t"
30286+ __asm__("movw %w6, %%ds\n\t"
30287+ "lcall *%%ss:(%%esi); cld\n\t"
30288+ "push %%ss\n\t"
30289+ "pop %%ds\n\t"
30290 "jc 1f\n\t"
30291 "xor %%ah, %%ah\n"
30292 "1:"
30293@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30294 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30295 "b" (bx),
30296 "D" ((long)reg),
30297- "S" (&pci_indirect));
30298+ "S" (&pci_indirect),
30299+ "r" (__PCIBIOS_DS));
30300 break;
30301 }
30302
30303@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30304
30305 switch (len) {
30306 case 1:
30307- __asm__("lcall *(%%esi); cld\n\t"
30308+ __asm__("movw %w6, %%ds\n\t"
30309+ "lcall *%%ss:(%%esi); cld\n\t"
30310+ "push %%ss\n\t"
30311+ "pop %%ds\n\t"
30312 "jc 1f\n\t"
30313 "xor %%ah, %%ah\n"
30314 "1:"
30315@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30316 "c" (value),
30317 "b" (bx),
30318 "D" ((long)reg),
30319- "S" (&pci_indirect));
30320+ "S" (&pci_indirect),
30321+ "r" (__PCIBIOS_DS));
30322 break;
30323 case 2:
30324- __asm__("lcall *(%%esi); cld\n\t"
30325+ __asm__("movw %w6, %%ds\n\t"
30326+ "lcall *%%ss:(%%esi); cld\n\t"
30327+ "push %%ss\n\t"
30328+ "pop %%ds\n\t"
30329 "jc 1f\n\t"
30330 "xor %%ah, %%ah\n"
30331 "1:"
30332@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30333 "c" (value),
30334 "b" (bx),
30335 "D" ((long)reg),
30336- "S" (&pci_indirect));
30337+ "S" (&pci_indirect),
30338+ "r" (__PCIBIOS_DS));
30339 break;
30340 case 4:
30341- __asm__("lcall *(%%esi); cld\n\t"
30342+ __asm__("movw %w6, %%ds\n\t"
30343+ "lcall *%%ss:(%%esi); cld\n\t"
30344+ "push %%ss\n\t"
30345+ "pop %%ds\n\t"
30346 "jc 1f\n\t"
30347 "xor %%ah, %%ah\n"
30348 "1:"
30349@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30350 "c" (value),
30351 "b" (bx),
30352 "D" ((long)reg),
30353- "S" (&pci_indirect));
30354+ "S" (&pci_indirect),
30355+ "r" (__PCIBIOS_DS));
30356 break;
30357 }
30358
30359@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30360
30361 DBG("PCI: Fetching IRQ routing table... ");
30362 __asm__("push %%es\n\t"
30363+ "movw %w8, %%ds\n\t"
30364 "push %%ds\n\t"
30365 "pop %%es\n\t"
30366- "lcall *(%%esi); cld\n\t"
30367+ "lcall *%%ss:(%%esi); cld\n\t"
30368 "pop %%es\n\t"
30369+ "push %%ss\n\t"
30370+ "pop %%ds\n"
30371 "jc 1f\n\t"
30372 "xor %%ah, %%ah\n"
30373 "1:"
30374@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30375 "1" (0),
30376 "D" ((long) &opt),
30377 "S" (&pci_indirect),
30378- "m" (opt)
30379+ "m" (opt),
30380+ "r" (__PCIBIOS_DS)
30381 : "memory");
30382 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30383 if (ret & 0xff00)
30384@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30385 {
30386 int ret;
30387
30388- __asm__("lcall *(%%esi); cld\n\t"
30389+ __asm__("movw %w5, %%ds\n\t"
30390+ "lcall *%%ss:(%%esi); cld\n\t"
30391+ "push %%ss\n\t"
30392+ "pop %%ds\n"
30393 "jc 1f\n\t"
30394 "xor %%ah, %%ah\n"
30395 "1:"
30396@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30397 : "0" (PCIBIOS_SET_PCI_HW_INT),
30398 "b" ((dev->bus->number << 8) | dev->devfn),
30399 "c" ((irq << 8) | (pin + 10)),
30400- "S" (&pci_indirect));
30401+ "S" (&pci_indirect),
30402+ "r" (__PCIBIOS_DS));
30403 return !(ret & 0xff00);
30404 }
30405 EXPORT_SYMBOL(pcibios_set_irq_routing);
30406diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30407index 40e4469..0592924 100644
30408--- a/arch/x86/platform/efi/efi_32.c
30409+++ b/arch/x86/platform/efi/efi_32.c
30410@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30411 {
30412 struct desc_ptr gdt_descr;
30413
30414+#ifdef CONFIG_PAX_KERNEXEC
30415+ struct desc_struct d;
30416+#endif
30417+
30418 local_irq_save(efi_rt_eflags);
30419
30420 load_cr3(initial_page_table);
30421 __flush_tlb_all();
30422
30423+#ifdef CONFIG_PAX_KERNEXEC
30424+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30425+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30426+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30427+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30428+#endif
30429+
30430 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30431 gdt_descr.size = GDT_SIZE - 1;
30432 load_gdt(&gdt_descr);
30433@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
30434 {
30435 struct desc_ptr gdt_descr;
30436
30437+#ifdef CONFIG_PAX_KERNEXEC
30438+ struct desc_struct d;
30439+
30440+ memset(&d, 0, sizeof d);
30441+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30442+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30443+#endif
30444+
30445 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30446 gdt_descr.size = GDT_SIZE - 1;
30447 load_gdt(&gdt_descr);
30448
30449+#ifdef CONFIG_PAX_PER_CPU_PGD
30450+ load_cr3(get_cpu_pgd(smp_processor_id()));
30451+#else
30452 load_cr3(swapper_pg_dir);
30453+#endif
30454+
30455 __flush_tlb_all();
30456
30457 local_irq_restore(efi_rt_eflags);
30458diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
30459index 39a0e7f1..ecc2f1e 100644
30460--- a/arch/x86/platform/efi/efi_64.c
30461+++ b/arch/x86/platform/efi/efi_64.c
30462@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
30463 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
30464 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
30465 }
30466+
30467+#ifdef CONFIG_PAX_PER_CPU_PGD
30468+ load_cr3(swapper_pg_dir);
30469+#endif
30470+
30471 __flush_tlb_all();
30472 }
30473
30474@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
30475 for (pgd = 0; pgd < n_pgds; pgd++)
30476 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
30477 kfree(save_pgd);
30478+
30479+#ifdef CONFIG_PAX_PER_CPU_PGD
30480+ load_cr3(get_cpu_pgd(smp_processor_id()));
30481+#endif
30482+
30483 __flush_tlb_all();
30484 local_irq_restore(efi_flags);
30485 early_code_mapping_set_exec(0);
30486diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30487index fbe66e6..eae5e38 100644
30488--- a/arch/x86/platform/efi/efi_stub_32.S
30489+++ b/arch/x86/platform/efi/efi_stub_32.S
30490@@ -6,7 +6,9 @@
30491 */
30492
30493 #include <linux/linkage.h>
30494+#include <linux/init.h>
30495 #include <asm/page_types.h>
30496+#include <asm/segment.h>
30497
30498 /*
30499 * efi_call_phys(void *, ...) is a function with variable parameters.
30500@@ -20,7 +22,7 @@
30501 * service functions will comply with gcc calling convention, too.
30502 */
30503
30504-.text
30505+__INIT
30506 ENTRY(efi_call_phys)
30507 /*
30508 * 0. The function can only be called in Linux kernel. So CS has been
30509@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30510 * The mapping of lower virtual memory has been created in prelog and
30511 * epilog.
30512 */
30513- movl $1f, %edx
30514- subl $__PAGE_OFFSET, %edx
30515- jmp *%edx
30516+#ifdef CONFIG_PAX_KERNEXEC
30517+ movl $(__KERNEXEC_EFI_DS), %edx
30518+ mov %edx, %ds
30519+ mov %edx, %es
30520+ mov %edx, %ss
30521+ addl $2f,(1f)
30522+ ljmp *(1f)
30523+
30524+__INITDATA
30525+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30526+.previous
30527+
30528+2:
30529+ subl $2b,(1b)
30530+#else
30531+ jmp 1f-__PAGE_OFFSET
30532 1:
30533+#endif
30534
30535 /*
30536 * 2. Now on the top of stack is the return
30537@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30538 * parameter 2, ..., param n. To make things easy, we save the return
30539 * address of efi_call_phys in a global variable.
30540 */
30541- popl %edx
30542- movl %edx, saved_return_addr
30543- /* get the function pointer into ECX*/
30544- popl %ecx
30545- movl %ecx, efi_rt_function_ptr
30546- movl $2f, %edx
30547- subl $__PAGE_OFFSET, %edx
30548- pushl %edx
30549+ popl (saved_return_addr)
30550+ popl (efi_rt_function_ptr)
30551
30552 /*
30553 * 3. Clear PG bit in %CR0.
30554@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30555 /*
30556 * 5. Call the physical function.
30557 */
30558- jmp *%ecx
30559+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30560
30561-2:
30562 /*
30563 * 6. After EFI runtime service returns, control will return to
30564 * following instruction. We'd better readjust stack pointer first.
30565@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30566 movl %cr0, %edx
30567 orl $0x80000000, %edx
30568 movl %edx, %cr0
30569- jmp 1f
30570-1:
30571+
30572 /*
30573 * 8. Now restore the virtual mode from flat mode by
30574 * adding EIP with PAGE_OFFSET.
30575 */
30576- movl $1f, %edx
30577- jmp *%edx
30578+#ifdef CONFIG_PAX_KERNEXEC
30579+ movl $(__KERNEL_DS), %edx
30580+ mov %edx, %ds
30581+ mov %edx, %es
30582+ mov %edx, %ss
30583+ ljmp $(__KERNEL_CS),$1f
30584+#else
30585+ jmp 1f+__PAGE_OFFSET
30586+#endif
30587 1:
30588
30589 /*
30590 * 9. Balance the stack. And because EAX contain the return value,
30591 * we'd better not clobber it.
30592 */
30593- leal efi_rt_function_ptr, %edx
30594- movl (%edx), %ecx
30595- pushl %ecx
30596+ pushl (efi_rt_function_ptr)
30597
30598 /*
30599- * 10. Push the saved return address onto the stack and return.
30600+ * 10. Return to the saved return address.
30601 */
30602- leal saved_return_addr, %edx
30603- movl (%edx), %ecx
30604- pushl %ecx
30605- ret
30606+ jmpl *(saved_return_addr)
30607 ENDPROC(efi_call_phys)
30608 .previous
30609
30610-.data
30611+__INITDATA
30612 saved_return_addr:
30613 .long 0
30614 efi_rt_function_ptr:
30615diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30616index 4c07cca..2c8427d 100644
30617--- a/arch/x86/platform/efi/efi_stub_64.S
30618+++ b/arch/x86/platform/efi/efi_stub_64.S
30619@@ -7,6 +7,7 @@
30620 */
30621
30622 #include <linux/linkage.h>
30623+#include <asm/alternative-asm.h>
30624
30625 #define SAVE_XMM \
30626 mov %rsp, %rax; \
30627@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30628 call *%rdi
30629 addq $32, %rsp
30630 RESTORE_XMM
30631+ pax_force_retaddr 0, 1
30632 ret
30633 ENDPROC(efi_call0)
30634
30635@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30636 call *%rdi
30637 addq $32, %rsp
30638 RESTORE_XMM
30639+ pax_force_retaddr 0, 1
30640 ret
30641 ENDPROC(efi_call1)
30642
30643@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30644 call *%rdi
30645 addq $32, %rsp
30646 RESTORE_XMM
30647+ pax_force_retaddr 0, 1
30648 ret
30649 ENDPROC(efi_call2)
30650
30651@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30652 call *%rdi
30653 addq $32, %rsp
30654 RESTORE_XMM
30655+ pax_force_retaddr 0, 1
30656 ret
30657 ENDPROC(efi_call3)
30658
30659@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30660 call *%rdi
30661 addq $32, %rsp
30662 RESTORE_XMM
30663+ pax_force_retaddr 0, 1
30664 ret
30665 ENDPROC(efi_call4)
30666
30667@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30668 call *%rdi
30669 addq $48, %rsp
30670 RESTORE_XMM
30671+ pax_force_retaddr 0, 1
30672 ret
30673 ENDPROC(efi_call5)
30674
30675@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30676 call *%rdi
30677 addq $48, %rsp
30678 RESTORE_XMM
30679+ pax_force_retaddr 0, 1
30680 ret
30681 ENDPROC(efi_call6)
30682diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30683index a0a0a43..a48e233 100644
30684--- a/arch/x86/platform/mrst/mrst.c
30685+++ b/arch/x86/platform/mrst/mrst.c
30686@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30687 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30688 int sfi_mrtc_num;
30689
30690-static void mrst_power_off(void)
30691+static __noreturn void mrst_power_off(void)
30692 {
30693+ BUG();
30694 }
30695
30696-static void mrst_reboot(void)
30697+static __noreturn void mrst_reboot(void)
30698 {
30699 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30700+ BUG();
30701 }
30702
30703 /* parse all the mtimer info to a static mtimer array */
30704diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30705index d6ee929..3637cb5 100644
30706--- a/arch/x86/platform/olpc/olpc_dt.c
30707+++ b/arch/x86/platform/olpc/olpc_dt.c
30708@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30709 return res;
30710 }
30711
30712-static struct of_pdt_ops prom_olpc_ops __initdata = {
30713+static struct of_pdt_ops prom_olpc_ops __initconst = {
30714 .nextprop = olpc_dt_nextprop,
30715 .getproplen = olpc_dt_getproplen,
30716 .getproperty = olpc_dt_getproperty,
30717diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30718index 1cf5b30..fd45732 100644
30719--- a/arch/x86/power/cpu.c
30720+++ b/arch/x86/power/cpu.c
30721@@ -137,11 +137,8 @@ static void do_fpu_end(void)
30722 static void fix_processor_context(void)
30723 {
30724 int cpu = smp_processor_id();
30725- struct tss_struct *t = &per_cpu(init_tss, cpu);
30726-#ifdef CONFIG_X86_64
30727- struct desc_struct *desc = get_cpu_gdt_table(cpu);
30728- tss_desc tss;
30729-#endif
30730+ struct tss_struct *t = init_tss + cpu;
30731+
30732 set_tss_desc(cpu, t); /*
30733 * This just modifies memory; should not be
30734 * necessary. But... This is necessary, because
30735@@ -150,10 +147,6 @@ static void fix_processor_context(void)
30736 */
30737
30738 #ifdef CONFIG_X86_64
30739- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
30740- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
30741- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
30742-
30743 syscall_init(); /* This sets MSR_*STAR and related */
30744 #endif
30745 load_TR_desc(); /* This does ltr */
30746diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30747index a44f457..9140171 100644
30748--- a/arch/x86/realmode/init.c
30749+++ b/arch/x86/realmode/init.c
30750@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
30751 __va(real_mode_header->trampoline_header);
30752
30753 #ifdef CONFIG_X86_32
30754- trampoline_header->start = __pa_symbol(startup_32_smp);
30755+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
30756+
30757+#ifdef CONFIG_PAX_KERNEXEC
30758+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30759+#endif
30760+
30761+ trampoline_header->boot_cs = __BOOT_CS;
30762 trampoline_header->gdt_limit = __BOOT_DS + 7;
30763 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
30764 #else
30765@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
30766 *trampoline_cr4_features = read_cr4();
30767
30768 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
30769- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
30770+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
30771 trampoline_pgd[511] = init_level4_pgt[511].pgd;
30772 #endif
30773 }
30774diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30775index 8869287..d577672 100644
30776--- a/arch/x86/realmode/rm/Makefile
30777+++ b/arch/x86/realmode/rm/Makefile
30778@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30779 $(call cc-option, -fno-unit-at-a-time)) \
30780 $(call cc-option, -fno-stack-protector) \
30781 $(call cc-option, -mpreferred-stack-boundary=2)
30782+ifdef CONSTIFY_PLUGIN
30783+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30784+endif
30785 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30786 GCOV_PROFILE := n
30787diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30788index a28221d..93c40f1 100644
30789--- a/arch/x86/realmode/rm/header.S
30790+++ b/arch/x86/realmode/rm/header.S
30791@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30792 #endif
30793 /* APM/BIOS reboot */
30794 .long pa_machine_real_restart_asm
30795-#ifdef CONFIG_X86_64
30796+#ifdef CONFIG_X86_32
30797+ .long __KERNEL_CS
30798+#else
30799 .long __KERNEL32_CS
30800 #endif
30801 END(real_mode_header)
30802diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30803index c1b2791..f9e31c7 100644
30804--- a/arch/x86/realmode/rm/trampoline_32.S
30805+++ b/arch/x86/realmode/rm/trampoline_32.S
30806@@ -25,6 +25,12 @@
30807 #include <asm/page_types.h>
30808 #include "realmode.h"
30809
30810+#ifdef CONFIG_PAX_KERNEXEC
30811+#define ta(X) (X)
30812+#else
30813+#define ta(X) (pa_ ## X)
30814+#endif
30815+
30816 .text
30817 .code16
30818
30819@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30820
30821 cli # We should be safe anyway
30822
30823- movl tr_start, %eax # where we need to go
30824-
30825 movl $0xA5A5A5A5, trampoline_status
30826 # write marker for master knows we're running
30827
30828@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30829 movw $1, %dx # protected mode (PE) bit
30830 lmsw %dx # into protected mode
30831
30832- ljmpl $__BOOT_CS, $pa_startup_32
30833+ ljmpl *(trampoline_header)
30834
30835 .section ".text32","ax"
30836 .code32
30837@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30838 .balign 8
30839 GLOBAL(trampoline_header)
30840 tr_start: .space 4
30841- tr_gdt_pad: .space 2
30842+ tr_boot_cs: .space 2
30843 tr_gdt: .space 6
30844 END(trampoline_header)
30845
30846diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30847index bb360dc..3e5945f 100644
30848--- a/arch/x86/realmode/rm/trampoline_64.S
30849+++ b/arch/x86/realmode/rm/trampoline_64.S
30850@@ -107,7 +107,7 @@ ENTRY(startup_32)
30851 wrmsr
30852
30853 # Enable paging and in turn activate Long Mode
30854- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30855+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30856 movl %eax, %cr0
30857
30858 /*
30859diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
30860index e812034..c747134 100644
30861--- a/arch/x86/tools/Makefile
30862+++ b/arch/x86/tools/Makefile
30863@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
30864
30865 $(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
30866
30867-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
30868+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
30869 hostprogs-y += relocs
30870 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
30871 relocs: $(obj)/relocs
30872diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30873index f7bab68..b6d9886 100644
30874--- a/arch/x86/tools/relocs.c
30875+++ b/arch/x86/tools/relocs.c
30876@@ -1,5 +1,7 @@
30877 /* This is included from relocs_32/64.c */
30878
30879+#include "../../../include/generated/autoconf.h"
30880+
30881 #define ElfW(type) _ElfW(ELF_BITS, type)
30882 #define _ElfW(bits, type) __ElfW(bits, type)
30883 #define __ElfW(bits, type) Elf##bits##_##type
30884@@ -11,6 +13,7 @@
30885 #define Elf_Sym ElfW(Sym)
30886
30887 static Elf_Ehdr ehdr;
30888+static Elf_Phdr *phdr;
30889
30890 struct relocs {
30891 uint32_t *offset;
30892@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
30893 }
30894 }
30895
30896+static void read_phdrs(FILE *fp)
30897+{
30898+ unsigned int i;
30899+
30900+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
30901+ if (!phdr) {
30902+ die("Unable to allocate %d program headers\n",
30903+ ehdr.e_phnum);
30904+ }
30905+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30906+ die("Seek to %d failed: %s\n",
30907+ ehdr.e_phoff, strerror(errno));
30908+ }
30909+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30910+ die("Cannot read ELF program headers: %s\n",
30911+ strerror(errno));
30912+ }
30913+ for(i = 0; i < ehdr.e_phnum; i++) {
30914+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
30915+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
30916+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
30917+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
30918+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
30919+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
30920+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
30921+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
30922+ }
30923+
30924+}
30925+
30926 static void read_shdrs(FILE *fp)
30927 {
30928- int i;
30929+ unsigned int i;
30930 Elf_Shdr shdr;
30931
30932 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30933@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
30934
30935 static void read_strtabs(FILE *fp)
30936 {
30937- int i;
30938+ unsigned int i;
30939 for (i = 0; i < ehdr.e_shnum; i++) {
30940 struct section *sec = &secs[i];
30941 if (sec->shdr.sh_type != SHT_STRTAB) {
30942@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
30943
30944 static void read_symtabs(FILE *fp)
30945 {
30946- int i,j;
30947+ unsigned int i,j;
30948 for (i = 0; i < ehdr.e_shnum; i++) {
30949 struct section *sec = &secs[i];
30950 if (sec->shdr.sh_type != SHT_SYMTAB) {
30951@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
30952 }
30953
30954
30955-static void read_relocs(FILE *fp)
30956+static void read_relocs(FILE *fp, int use_real_mode)
30957 {
30958- int i,j;
30959+ unsigned int i,j;
30960+ uint32_t base;
30961+
30962 for (i = 0; i < ehdr.e_shnum; i++) {
30963 struct section *sec = &secs[i];
30964 if (sec->shdr.sh_type != SHT_REL_TYPE) {
30965@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
30966 die("Cannot read symbol table: %s\n",
30967 strerror(errno));
30968 }
30969+ base = 0;
30970+
30971+#ifdef CONFIG_X86_32
30972+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30973+ if (phdr[j].p_type != PT_LOAD )
30974+ continue;
30975+ 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)
30976+ continue;
30977+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30978+ break;
30979+ }
30980+#endif
30981+
30982 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
30983 Elf_Rel *rel = &sec->reltab[j];
30984- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
30985+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
30986 rel->r_info = elf_xword_to_cpu(rel->r_info);
30987 #if (SHT_REL_TYPE == SHT_RELA)
30988 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
30989@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
30990
30991 static void print_absolute_symbols(void)
30992 {
30993- int i;
30994+ unsigned int i;
30995 const char *format;
30996
30997 if (ELF_BITS == 64)
30998@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
30999 for (i = 0; i < ehdr.e_shnum; i++) {
31000 struct section *sec = &secs[i];
31001 char *sym_strtab;
31002- int j;
31003+ unsigned int j;
31004
31005 if (sec->shdr.sh_type != SHT_SYMTAB) {
31006 continue;
31007@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
31008
31009 static void print_absolute_relocs(void)
31010 {
31011- int i, printed = 0;
31012+ unsigned int i, printed = 0;
31013 const char *format;
31014
31015 if (ELF_BITS == 64)
31016@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
31017 struct section *sec_applies, *sec_symtab;
31018 char *sym_strtab;
31019 Elf_Sym *sh_symtab;
31020- int j;
31021+ unsigned int j;
31022 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31023 continue;
31024 }
31025@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
31026 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
31027 Elf_Sym *sym, const char *symname))
31028 {
31029- int i;
31030+ unsigned int i;
31031 /* Walk through the relocations */
31032 for (i = 0; i < ehdr.e_shnum; i++) {
31033 char *sym_strtab;
31034 Elf_Sym *sh_symtab;
31035 struct section *sec_applies, *sec_symtab;
31036- int j;
31037+ unsigned int j;
31038 struct section *sec = &secs[i];
31039
31040 if (sec->shdr.sh_type != SHT_REL_TYPE) {
31041@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
31042 {
31043 unsigned r_type = ELF32_R_TYPE(rel->r_info);
31044 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
31045+ char *sym_strtab = sec->link->link->strtab;
31046+
31047+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
31048+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
31049+ return 0;
31050+
31051+#ifdef CONFIG_PAX_KERNEXEC
31052+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
31053+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
31054+ return 0;
31055+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
31056+ return 0;
31057+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
31058+ return 0;
31059+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
31060+ return 0;
31061+#endif
31062
31063 switch (r_type) {
31064 case R_386_NONE:
31065@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
31066
31067 static void emit_relocs(int as_text, int use_real_mode)
31068 {
31069- int i;
31070+ unsigned int i;
31071 int (*write_reloc)(uint32_t, FILE *) = write32;
31072 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
31073 const char *symname);
31074@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
31075 {
31076 regex_init(use_real_mode);
31077 read_ehdr(fp);
31078+ read_phdrs(fp);
31079 read_shdrs(fp);
31080 read_strtabs(fp);
31081 read_symtabs(fp);
31082- read_relocs(fp);
31083+ read_relocs(fp, use_real_mode);
31084 if (ELF_BITS == 64)
31085 percpu_init();
31086 if (show_absolute_syms) {
31087diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
31088index 80ffa5b..a33bd15 100644
31089--- a/arch/x86/um/tls_32.c
31090+++ b/arch/x86/um/tls_32.c
31091@@ -260,7 +260,7 @@ out:
31092 if (unlikely(task == current &&
31093 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
31094 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
31095- "without flushed TLS.", current->pid);
31096+ "without flushed TLS.", task_pid_nr(current));
31097 }
31098
31099 return 0;
31100diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31101index fd14be1..e3c79c0 100644
31102--- a/arch/x86/vdso/Makefile
31103+++ b/arch/x86/vdso/Makefile
31104@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31105 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31106 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31107
31108-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31109+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31110 GCOV_PROFILE := n
31111
31112 #
31113diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31114index 0faad64..39ef157 100644
31115--- a/arch/x86/vdso/vdso32-setup.c
31116+++ b/arch/x86/vdso/vdso32-setup.c
31117@@ -25,6 +25,7 @@
31118 #include <asm/tlbflush.h>
31119 #include <asm/vdso.h>
31120 #include <asm/proto.h>
31121+#include <asm/mman.h>
31122
31123 enum {
31124 VDSO_DISABLED = 0,
31125@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31126 void enable_sep_cpu(void)
31127 {
31128 int cpu = get_cpu();
31129- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31130+ struct tss_struct *tss = init_tss + cpu;
31131
31132 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31133 put_cpu();
31134@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31135 gate_vma.vm_start = FIXADDR_USER_START;
31136 gate_vma.vm_end = FIXADDR_USER_END;
31137 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31138- gate_vma.vm_page_prot = __P101;
31139+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31140
31141 return 0;
31142 }
31143@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31144 if (compat)
31145 addr = VDSO_HIGH_BASE;
31146 else {
31147- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31148+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31149 if (IS_ERR_VALUE(addr)) {
31150 ret = addr;
31151 goto up_fail;
31152 }
31153 }
31154
31155- current->mm->context.vdso = (void *)addr;
31156+ current->mm->context.vdso = addr;
31157
31158 if (compat_uses_vma || !compat) {
31159 /*
31160@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31161 }
31162
31163 current_thread_info()->sysenter_return =
31164- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31165+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31166
31167 up_fail:
31168 if (ret)
31169- current->mm->context.vdso = NULL;
31170+ current->mm->context.vdso = 0;
31171
31172 up_write(&mm->mmap_sem);
31173
31174@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31175
31176 const char *arch_vma_name(struct vm_area_struct *vma)
31177 {
31178- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31179+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31180 return "[vdso]";
31181+
31182+#ifdef CONFIG_PAX_SEGMEXEC
31183+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31184+ return "[vdso]";
31185+#endif
31186+
31187 return NULL;
31188 }
31189
31190@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31191 * Check to see if the corresponding task was created in compat vdso
31192 * mode.
31193 */
31194- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31195+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31196 return &gate_vma;
31197 return NULL;
31198 }
31199diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31200index 431e875..cbb23f3 100644
31201--- a/arch/x86/vdso/vma.c
31202+++ b/arch/x86/vdso/vma.c
31203@@ -16,8 +16,6 @@
31204 #include <asm/vdso.h>
31205 #include <asm/page.h>
31206
31207-unsigned int __read_mostly vdso_enabled = 1;
31208-
31209 extern char vdso_start[], vdso_end[];
31210 extern unsigned short vdso_sync_cpuid;
31211
31212@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31213 * unaligned here as a result of stack start randomization.
31214 */
31215 addr = PAGE_ALIGN(addr);
31216- addr = align_vdso_addr(addr);
31217
31218 return addr;
31219 }
31220@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31221 unsigned size)
31222 {
31223 struct mm_struct *mm = current->mm;
31224- unsigned long addr;
31225+ unsigned long addr = 0;
31226 int ret;
31227
31228- if (!vdso_enabled)
31229- return 0;
31230-
31231 down_write(&mm->mmap_sem);
31232+
31233+#ifdef CONFIG_PAX_RANDMMAP
31234+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31235+#endif
31236+
31237 addr = vdso_addr(mm->start_stack, size);
31238+ addr = align_vdso_addr(addr);
31239 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31240 if (IS_ERR_VALUE(addr)) {
31241 ret = addr;
31242 goto up_fail;
31243 }
31244
31245- current->mm->context.vdso = (void *)addr;
31246+ mm->context.vdso = addr;
31247
31248 ret = install_special_mapping(mm, addr, size,
31249 VM_READ|VM_EXEC|
31250 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31251 pages);
31252- if (ret) {
31253- current->mm->context.vdso = NULL;
31254- goto up_fail;
31255- }
31256+ if (ret)
31257+ mm->context.vdso = 0;
31258
31259 up_fail:
31260 up_write(&mm->mmap_sem);
31261@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31262 vdsox32_size);
31263 }
31264 #endif
31265-
31266-static __init int vdso_setup(char *s)
31267-{
31268- vdso_enabled = simple_strtoul(s, NULL, 0);
31269- return 0;
31270-}
31271-__setup("vdso=", vdso_setup);
31272diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31273index a492be2..08678da 100644
31274--- a/arch/x86/xen/enlighten.c
31275+++ b/arch/x86/xen/enlighten.c
31276@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31277
31278 struct shared_info xen_dummy_shared_info;
31279
31280-void *xen_initial_gdt;
31281-
31282 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31283 __read_mostly int xen_have_vector_callback;
31284 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31285@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31286 {
31287 unsigned long va = dtr->address;
31288 unsigned int size = dtr->size + 1;
31289- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31290- unsigned long frames[pages];
31291+ unsigned long frames[65536 / PAGE_SIZE];
31292 int f;
31293
31294 /*
31295@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31296 {
31297 unsigned long va = dtr->address;
31298 unsigned int size = dtr->size + 1;
31299- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31300- unsigned long frames[pages];
31301+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31302 int f;
31303
31304 /*
31305@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31306 * 8-byte entries, or 16 4k pages..
31307 */
31308
31309- BUG_ON(size > 65536);
31310+ BUG_ON(size > GDT_SIZE);
31311 BUG_ON(va & ~PAGE_MASK);
31312
31313 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31314@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31315 return 0;
31316 }
31317
31318-static void set_xen_basic_apic_ops(void)
31319+static void __init set_xen_basic_apic_ops(void)
31320 {
31321 apic->read = xen_apic_read;
31322 apic->write = xen_apic_write;
31323@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31324 #endif
31325 };
31326
31327-static void xen_reboot(int reason)
31328+static __noreturn void xen_reboot(int reason)
31329 {
31330 struct sched_shutdown r = { .reason = reason };
31331
31332- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31333- BUG();
31334+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31335+ BUG();
31336 }
31337
31338-static void xen_restart(char *msg)
31339+static __noreturn void xen_restart(char *msg)
31340 {
31341 xen_reboot(SHUTDOWN_reboot);
31342 }
31343
31344-static void xen_emergency_restart(void)
31345+static __noreturn void xen_emergency_restart(void)
31346 {
31347 xen_reboot(SHUTDOWN_reboot);
31348 }
31349
31350-static void xen_machine_halt(void)
31351+static __noreturn void xen_machine_halt(void)
31352 {
31353 xen_reboot(SHUTDOWN_poweroff);
31354 }
31355
31356-static void xen_machine_power_off(void)
31357+static __noreturn void xen_machine_power_off(void)
31358 {
31359 if (pm_power_off)
31360 pm_power_off();
31361@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
31362 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31363
31364 /* Work out if we support NX */
31365- x86_configure_nx();
31366+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31367+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31368+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31369+ unsigned l, h;
31370+
31371+ __supported_pte_mask |= _PAGE_NX;
31372+ rdmsr(MSR_EFER, l, h);
31373+ l |= EFER_NX;
31374+ wrmsr(MSR_EFER, l, h);
31375+ }
31376+#endif
31377
31378 xen_setup_features();
31379
31380@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
31381
31382 machine_ops = xen_machine_ops;
31383
31384- /*
31385- * The only reliable way to retain the initial address of the
31386- * percpu gdt_page is to remember it here, so we can go and
31387- * mark it RW later, when the initial percpu area is freed.
31388- */
31389- xen_initial_gdt = &per_cpu(gdt_page, 0);
31390-
31391 xen_smp_init();
31392
31393 #ifdef CONFIG_ACPI_NUMA
31394@@ -1700,7 +1699,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31395 return NOTIFY_OK;
31396 }
31397
31398-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31399+static struct notifier_block xen_hvm_cpu_notifier = {
31400 .notifier_call = xen_hvm_cpu_notify,
31401 };
31402
31403diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31404index fdc3ba2..3daee39 100644
31405--- a/arch/x86/xen/mmu.c
31406+++ b/arch/x86/xen/mmu.c
31407@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31408 /* L3_k[510] -> level2_kernel_pgt
31409 * L3_i[511] -> level2_fixmap_pgt */
31410 convert_pfn_mfn(level3_kernel_pgt);
31411+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31412+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31413+ convert_pfn_mfn(level3_vmemmap_pgt);
31414
31415 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31416 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31417@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31418 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31419 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31420 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31421+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31422+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31423+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31424 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31425 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31426+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31427 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31428 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31429
31430@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
31431 pv_mmu_ops.set_pud = xen_set_pud;
31432 #if PAGETABLE_LEVELS == 4
31433 pv_mmu_ops.set_pgd = xen_set_pgd;
31434+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31435 #endif
31436
31437 /* This will work as long as patching hasn't happened yet
31438@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31439 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31440 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31441 .set_pgd = xen_set_pgd_hyper,
31442+ .set_pgd_batched = xen_set_pgd_hyper,
31443
31444 .alloc_pud = xen_alloc_pmd_init,
31445 .release_pud = xen_release_pmd_init,
31446diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31447index d99cae8..18401e1 100644
31448--- a/arch/x86/xen/smp.c
31449+++ b/arch/x86/xen/smp.c
31450@@ -240,11 +240,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31451 {
31452 BUG_ON(smp_processor_id() != 0);
31453 native_smp_prepare_boot_cpu();
31454-
31455- /* We've switched to the "real" per-cpu gdt, so make sure the
31456- old memory can be recycled */
31457- make_lowmem_page_readwrite(xen_initial_gdt);
31458-
31459 xen_filter_cpu_maps();
31460 xen_setup_vcpu_info_placement();
31461 }
31462@@ -314,7 +309,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31463 ctxt->user_regs.ss = __KERNEL_DS;
31464 #ifdef CONFIG_X86_32
31465 ctxt->user_regs.fs = __KERNEL_PERCPU;
31466- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31467+ savesegment(gs, ctxt->user_regs.gs);
31468 #else
31469 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31470 #endif
31471@@ -324,8 +319,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31472
31473 {
31474 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
31475- ctxt->user_regs.ds = __USER_DS;
31476- ctxt->user_regs.es = __USER_DS;
31477+ ctxt->user_regs.ds = __KERNEL_DS;
31478+ ctxt->user_regs.es = __KERNEL_DS;
31479
31480 xen_copy_trap_info(ctxt->trap_ctxt);
31481
31482@@ -370,13 +365,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31483 int rc;
31484
31485 per_cpu(current_task, cpu) = idle;
31486+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31487 #ifdef CONFIG_X86_32
31488 irq_ctx_init(cpu);
31489 #else
31490 clear_tsk_thread_flag(idle, TIF_FORK);
31491- per_cpu(kernel_stack, cpu) =
31492- (unsigned long)task_stack_page(idle) -
31493- KERNEL_STACK_OFFSET + THREAD_SIZE;
31494+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31495 #endif
31496 xen_setup_runstate_info(cpu);
31497 xen_setup_timer(cpu);
31498@@ -651,7 +645,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31499
31500 void __init xen_smp_init(void)
31501 {
31502- smp_ops = xen_smp_ops;
31503+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31504 xen_fill_possible_map();
31505 xen_init_spinlocks();
31506 }
31507diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31508index 33ca6e4..0ded929 100644
31509--- a/arch/x86/xen/xen-asm_32.S
31510+++ b/arch/x86/xen/xen-asm_32.S
31511@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31512 ESP_OFFSET=4 # bytes pushed onto stack
31513
31514 /*
31515- * Store vcpu_info pointer for easy access. Do it this way to
31516- * avoid having to reload %fs
31517+ * Store vcpu_info pointer for easy access.
31518 */
31519 #ifdef CONFIG_SMP
31520- GET_THREAD_INFO(%eax)
31521- movl %ss:TI_cpu(%eax), %eax
31522- movl %ss:__per_cpu_offset(,%eax,4), %eax
31523- mov %ss:xen_vcpu(%eax), %eax
31524+ push %fs
31525+ mov $(__KERNEL_PERCPU), %eax
31526+ mov %eax, %fs
31527+ mov PER_CPU_VAR(xen_vcpu), %eax
31528+ pop %fs
31529 #else
31530 movl %ss:xen_vcpu, %eax
31531 #endif
31532diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31533index 7faed58..ba4427c 100644
31534--- a/arch/x86/xen/xen-head.S
31535+++ b/arch/x86/xen/xen-head.S
31536@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31537 #ifdef CONFIG_X86_32
31538 mov %esi,xen_start_info
31539 mov $init_thread_union+THREAD_SIZE,%esp
31540+#ifdef CONFIG_SMP
31541+ movl $cpu_gdt_table,%edi
31542+ movl $__per_cpu_load,%eax
31543+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31544+ rorl $16,%eax
31545+ movb %al,__KERNEL_PERCPU + 4(%edi)
31546+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31547+ movl $__per_cpu_end - 1,%eax
31548+ subl $__per_cpu_start,%eax
31549+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31550+#endif
31551 #else
31552 mov %rsi,xen_start_info
31553 mov $init_thread_union+THREAD_SIZE,%rsp
31554diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31555index a95b417..b6dbd0b 100644
31556--- a/arch/x86/xen/xen-ops.h
31557+++ b/arch/x86/xen/xen-ops.h
31558@@ -10,8 +10,6 @@
31559 extern const char xen_hypervisor_callback[];
31560 extern const char xen_failsafe_callback[];
31561
31562-extern void *xen_initial_gdt;
31563-
31564 struct trap_info;
31565 void xen_copy_trap_info(struct trap_info *traps);
31566
31567diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31568index 525bd3d..ef888b1 100644
31569--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31570+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31571@@ -119,9 +119,9 @@
31572 ----------------------------------------------------------------------*/
31573
31574 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31575-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31576 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31577 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31578+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31579
31580 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31581 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31582diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31583index 2f33760..835e50a 100644
31584--- a/arch/xtensa/variants/fsf/include/variant/core.h
31585+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31586@@ -11,6 +11,7 @@
31587 #ifndef _XTENSA_CORE_H
31588 #define _XTENSA_CORE_H
31589
31590+#include <linux/const.h>
31591
31592 /****************************************************************************
31593 Parameters Useful for Any Code, USER or PRIVILEGED
31594@@ -112,9 +113,9 @@
31595 ----------------------------------------------------------------------*/
31596
31597 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31598-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31599 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31600 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31601+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31602
31603 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31604 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31605diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31606index af00795..2bb8105 100644
31607--- a/arch/xtensa/variants/s6000/include/variant/core.h
31608+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31609@@ -11,6 +11,7 @@
31610 #ifndef _XTENSA_CORE_CONFIGURATION_H
31611 #define _XTENSA_CORE_CONFIGURATION_H
31612
31613+#include <linux/const.h>
31614
31615 /****************************************************************************
31616 Parameters Useful for Any Code, USER or PRIVILEGED
31617@@ -118,9 +119,9 @@
31618 ----------------------------------------------------------------------*/
31619
31620 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31621-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31622 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31623 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31624+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31625
31626 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31627 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31628diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31629index 58916af..eb9dbcf6 100644
31630--- a/block/blk-iopoll.c
31631+++ b/block/blk-iopoll.c
31632@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31633 }
31634 EXPORT_SYMBOL(blk_iopoll_complete);
31635
31636-static void blk_iopoll_softirq(struct softirq_action *h)
31637+static void blk_iopoll_softirq(void)
31638 {
31639 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31640 int rearm = 0, budget = blk_iopoll_budget;
31641@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31642 return NOTIFY_OK;
31643 }
31644
31645-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31646+static struct notifier_block blk_iopoll_cpu_notifier = {
31647 .notifier_call = blk_iopoll_cpu_notify,
31648 };
31649
31650diff --git a/block/blk-map.c b/block/blk-map.c
31651index 623e1cd..ca1e109 100644
31652--- a/block/blk-map.c
31653+++ b/block/blk-map.c
31654@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31655 if (!len || !kbuf)
31656 return -EINVAL;
31657
31658- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31659+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31660 if (do_copy)
31661 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31662 else
31663diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31664index 467c8de..f3628c5 100644
31665--- a/block/blk-softirq.c
31666+++ b/block/blk-softirq.c
31667@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31668 * Softirq action handler - move entries to local list and loop over them
31669 * while passing them to the queue registered handler.
31670 */
31671-static void blk_done_softirq(struct softirq_action *h)
31672+static void blk_done_softirq(void)
31673 {
31674 struct list_head *cpu_list, local_list;
31675
31676@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31677 return NOTIFY_OK;
31678 }
31679
31680-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31681+static struct notifier_block blk_cpu_notifier = {
31682 .notifier_call = blk_cpu_notify,
31683 };
31684
31685diff --git a/block/bsg.c b/block/bsg.c
31686index 420a5a9..23834aa 100644
31687--- a/block/bsg.c
31688+++ b/block/bsg.c
31689@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31690 struct sg_io_v4 *hdr, struct bsg_device *bd,
31691 fmode_t has_write_perm)
31692 {
31693+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31694+ unsigned char *cmdptr;
31695+
31696 if (hdr->request_len > BLK_MAX_CDB) {
31697 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31698 if (!rq->cmd)
31699 return -ENOMEM;
31700- }
31701+ cmdptr = rq->cmd;
31702+ } else
31703+ cmdptr = tmpcmd;
31704
31705- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31706+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31707 hdr->request_len))
31708 return -EFAULT;
31709
31710+ if (cmdptr != rq->cmd)
31711+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31712+
31713 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31714 if (blk_verify_command(rq->cmd, has_write_perm))
31715 return -EPERM;
31716diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31717index 7c668c8..db3521c 100644
31718--- a/block/compat_ioctl.c
31719+++ b/block/compat_ioctl.c
31720@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31721 err |= __get_user(f->spec1, &uf->spec1);
31722 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31723 err |= __get_user(name, &uf->name);
31724- f->name = compat_ptr(name);
31725+ f->name = (void __force_kernel *)compat_ptr(name);
31726 if (err) {
31727 err = -EFAULT;
31728 goto out;
31729diff --git a/block/genhd.c b/block/genhd.c
31730index cdeb527..10aa34d 100644
31731--- a/block/genhd.c
31732+++ b/block/genhd.c
31733@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
31734
31735 /*
31736 * Register device numbers dev..(dev+range-1)
31737- * range must be nonzero
31738+ * Noop if @range is zero.
31739 * The hash chain is sorted on range, so that subranges can override.
31740 */
31741 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
31742 struct kobject *(*probe)(dev_t, int *, void *),
31743 int (*lock)(dev_t, void *), void *data)
31744 {
31745- kobj_map(bdev_map, devt, range, module, probe, lock, data);
31746+ if (range)
31747+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
31748 }
31749
31750 EXPORT_SYMBOL(blk_register_region);
31751
31752+/* undo blk_register_region(), noop if @range is zero */
31753 void blk_unregister_region(dev_t devt, unsigned long range)
31754 {
31755- kobj_unmap(bdev_map, devt, range);
31756+ if (range)
31757+ kobj_unmap(bdev_map, devt, range);
31758 }
31759
31760 EXPORT_SYMBOL(blk_unregister_region);
31761diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31762index c85fc89..51e690b 100644
31763--- a/block/partitions/efi.c
31764+++ b/block/partitions/efi.c
31765@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31766 if (!gpt)
31767 return NULL;
31768
31769+ if (!le32_to_cpu(gpt->num_partition_entries))
31770+ return NULL;
31771+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31772+ if (!pte)
31773+ return NULL;
31774+
31775 count = le32_to_cpu(gpt->num_partition_entries) *
31776 le32_to_cpu(gpt->sizeof_partition_entry);
31777- if (!count)
31778- return NULL;
31779- pte = kmalloc(count, GFP_KERNEL);
31780- if (!pte)
31781- return NULL;
31782-
31783 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31784 (u8 *) pte,
31785 count) < count) {
31786diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31787index a5ffcc9..3cedc9c 100644
31788--- a/block/scsi_ioctl.c
31789+++ b/block/scsi_ioctl.c
31790@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
31791 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31792 struct sg_io_hdr *hdr, fmode_t mode)
31793 {
31794- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31795+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31796+ unsigned char *cmdptr;
31797+
31798+ if (rq->cmd != rq->__cmd)
31799+ cmdptr = rq->cmd;
31800+ else
31801+ cmdptr = tmpcmd;
31802+
31803+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31804 return -EFAULT;
31805+
31806+ if (cmdptr != rq->cmd)
31807+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31808+
31809 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31810 return -EPERM;
31811
31812@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31813 int err;
31814 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31815 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31816+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31817+ unsigned char *cmdptr;
31818
31819 if (!sic)
31820 return -EINVAL;
31821@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31822 */
31823 err = -EFAULT;
31824 rq->cmd_len = cmdlen;
31825- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31826+
31827+ if (rq->cmd != rq->__cmd)
31828+ cmdptr = rq->cmd;
31829+ else
31830+ cmdptr = tmpcmd;
31831+
31832+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31833 goto error;
31834
31835+ if (rq->cmd != cmdptr)
31836+ memcpy(rq->cmd, cmdptr, cmdlen);
31837+
31838 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31839 goto error;
31840
31841diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31842index 7bdd61b..afec999 100644
31843--- a/crypto/cryptd.c
31844+++ b/crypto/cryptd.c
31845@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31846
31847 struct cryptd_blkcipher_request_ctx {
31848 crypto_completion_t complete;
31849-};
31850+} __no_const;
31851
31852 struct cryptd_hash_ctx {
31853 struct crypto_shash *child;
31854@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31855
31856 struct cryptd_aead_request_ctx {
31857 crypto_completion_t complete;
31858-};
31859+} __no_const;
31860
31861 static void cryptd_queue_worker(struct work_struct *work);
31862
31863diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
31864index b2c99dc..476c9fb 100644
31865--- a/crypto/pcrypt.c
31866+++ b/crypto/pcrypt.c
31867@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
31868 int ret;
31869
31870 pinst->kobj.kset = pcrypt_kset;
31871- ret = kobject_add(&pinst->kobj, NULL, name);
31872+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
31873 if (!ret)
31874 kobject_uevent(&pinst->kobj, KOBJ_ADD);
31875
31876@@ -455,8 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
31877
31878 get_online_cpus();
31879
31880- pcrypt->wq = alloc_workqueue(name,
31881- WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
31882+ pcrypt->wq = alloc_workqueue("%s",
31883+ WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1, name);
31884 if (!pcrypt->wq)
31885 goto err;
31886
31887diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31888index f220d64..d359ad6 100644
31889--- a/drivers/acpi/apei/apei-internal.h
31890+++ b/drivers/acpi/apei/apei-internal.h
31891@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31892 struct apei_exec_ins_type {
31893 u32 flags;
31894 apei_exec_ins_func_t run;
31895-};
31896+} __do_const;
31897
31898 struct apei_exec_context {
31899 u32 ip;
31900diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31901index 33dc6a0..4b24b47 100644
31902--- a/drivers/acpi/apei/cper.c
31903+++ b/drivers/acpi/apei/cper.c
31904@@ -39,12 +39,12 @@
31905 */
31906 u64 cper_next_record_id(void)
31907 {
31908- static atomic64_t seq;
31909+ static atomic64_unchecked_t seq;
31910
31911- if (!atomic64_read(&seq))
31912- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31913+ if (!atomic64_read_unchecked(&seq))
31914+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31915
31916- return atomic64_inc_return(&seq);
31917+ return atomic64_inc_return_unchecked(&seq);
31918 }
31919 EXPORT_SYMBOL_GPL(cper_next_record_id);
31920
31921diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31922index be60399..778b33e8 100644
31923--- a/drivers/acpi/bgrt.c
31924+++ b/drivers/acpi/bgrt.c
31925@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31926 return -ENODEV;
31927
31928 sysfs_bin_attr_init(&image_attr);
31929- image_attr.private = bgrt_image;
31930- image_attr.size = bgrt_image_size;
31931+ pax_open_kernel();
31932+ *(void **)&image_attr.private = bgrt_image;
31933+ *(size_t *)&image_attr.size = bgrt_image_size;
31934+ pax_close_kernel();
31935
31936 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31937 if (!bgrt_kobj)
31938diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31939index cb96296..b81293b 100644
31940--- a/drivers/acpi/blacklist.c
31941+++ b/drivers/acpi/blacklist.c
31942@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31943 u32 is_critical_error;
31944 };
31945
31946-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31947+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31948
31949 /*
31950 * POLICY: If *anything* doesn't work, put it on the blacklist.
31951@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31952 return 0;
31953 }
31954
31955-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31956+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31957 {
31958 .callback = dmi_disable_osi_vista,
31959 .ident = "Fujitsu Siemens",
31960diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31961index 7586544..636a2f0 100644
31962--- a/drivers/acpi/ec_sys.c
31963+++ b/drivers/acpi/ec_sys.c
31964@@ -12,6 +12,7 @@
31965 #include <linux/acpi.h>
31966 #include <linux/debugfs.h>
31967 #include <linux/module.h>
31968+#include <linux/uaccess.h>
31969 #include "internal.h"
31970
31971 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31972@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31973 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31974 */
31975 unsigned int size = EC_SPACE_SIZE;
31976- u8 *data = (u8 *) buf;
31977+ u8 data;
31978 loff_t init_off = *off;
31979 int err = 0;
31980
31981@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31982 size = count;
31983
31984 while (size) {
31985- err = ec_read(*off, &data[*off - init_off]);
31986+ err = ec_read(*off, &data);
31987 if (err)
31988 return err;
31989+ if (put_user(data, &buf[*off - init_off]))
31990+ return -EFAULT;
31991 *off += 1;
31992 size--;
31993 }
31994@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31995
31996 unsigned int size = count;
31997 loff_t init_off = *off;
31998- u8 *data = (u8 *) buf;
31999 int err = 0;
32000
32001 if (*off >= EC_SPACE_SIZE)
32002@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
32003 }
32004
32005 while (size) {
32006- u8 byte_write = data[*off - init_off];
32007+ u8 byte_write;
32008+ if (get_user(byte_write, &buf[*off - init_off]))
32009+ return -EFAULT;
32010 err = ec_write(*off, byte_write);
32011 if (err)
32012 return err;
32013diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
32014index eb133c7..f571552 100644
32015--- a/drivers/acpi/processor_idle.c
32016+++ b/drivers/acpi/processor_idle.c
32017@@ -994,7 +994,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
32018 {
32019 int i, count = CPUIDLE_DRIVER_STATE_START;
32020 struct acpi_processor_cx *cx;
32021- struct cpuidle_state *state;
32022+ cpuidle_state_no_const *state;
32023 struct cpuidle_driver *drv = &acpi_idle_driver;
32024
32025 if (!pr->flags.power_setup_done)
32026diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
32027index fcae5fa..e9f71ea 100644
32028--- a/drivers/acpi/sysfs.c
32029+++ b/drivers/acpi/sysfs.c
32030@@ -423,11 +423,11 @@ static u32 num_counters;
32031 static struct attribute **all_attrs;
32032 static u32 acpi_gpe_count;
32033
32034-static struct attribute_group interrupt_stats_attr_group = {
32035+static attribute_group_no_const interrupt_stats_attr_group = {
32036 .name = "interrupts",
32037 };
32038
32039-static struct kobj_attribute *counter_attrs;
32040+static kobj_attribute_no_const *counter_attrs;
32041
32042 static void delete_gpe_attr_array(void)
32043 {
32044diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
32045index a70ff15..f1ff44e 100644
32046--- a/drivers/ata/libahci.c
32047+++ b/drivers/ata/libahci.c
32048@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
32049 }
32050 EXPORT_SYMBOL_GPL(ahci_kick_engine);
32051
32052-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32053+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
32054 struct ata_taskfile *tf, int is_cmd, u16 flags,
32055 unsigned long timeout_msec)
32056 {
32057diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
32058index adf002a..39bb8f9 100644
32059--- a/drivers/ata/libata-core.c
32060+++ b/drivers/ata/libata-core.c
32061@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
32062 struct ata_port *ap;
32063 unsigned int tag;
32064
32065- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32066+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32067 ap = qc->ap;
32068
32069 qc->flags = 0;
32070@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32071 struct ata_port *ap;
32072 struct ata_link *link;
32073
32074- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32075+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32076 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32077 ap = qc->ap;
32078 link = qc->dev->link;
32079@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32080 return;
32081
32082 spin_lock(&lock);
32083+ pax_open_kernel();
32084
32085 for (cur = ops->inherits; cur; cur = cur->inherits) {
32086 void **inherit = (void **)cur;
32087@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32088 if (IS_ERR(*pp))
32089 *pp = NULL;
32090
32091- ops->inherits = NULL;
32092+ *(struct ata_port_operations **)&ops->inherits = NULL;
32093
32094+ pax_close_kernel();
32095 spin_unlock(&lock);
32096 }
32097
32098diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32099index 7638121..357a965 100644
32100--- a/drivers/ata/pata_arasan_cf.c
32101+++ b/drivers/ata/pata_arasan_cf.c
32102@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32103 /* Handle platform specific quirks */
32104 if (quirk) {
32105 if (quirk & CF_BROKEN_PIO) {
32106- ap->ops->set_piomode = NULL;
32107+ pax_open_kernel();
32108+ *(void **)&ap->ops->set_piomode = NULL;
32109+ pax_close_kernel();
32110 ap->pio_mask = 0;
32111 }
32112 if (quirk & CF_BROKEN_MWDMA)
32113diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32114index f9b983a..887b9d8 100644
32115--- a/drivers/atm/adummy.c
32116+++ b/drivers/atm/adummy.c
32117@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32118 vcc->pop(vcc, skb);
32119 else
32120 dev_kfree_skb_any(skb);
32121- atomic_inc(&vcc->stats->tx);
32122+ atomic_inc_unchecked(&vcc->stats->tx);
32123
32124 return 0;
32125 }
32126diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32127index 77a7480d..05cde58 100644
32128--- a/drivers/atm/ambassador.c
32129+++ b/drivers/atm/ambassador.c
32130@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32131 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32132
32133 // VC layer stats
32134- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32135+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32136
32137 // free the descriptor
32138 kfree (tx_descr);
32139@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32140 dump_skb ("<<<", vc, skb);
32141
32142 // VC layer stats
32143- atomic_inc(&atm_vcc->stats->rx);
32144+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32145 __net_timestamp(skb);
32146 // end of our responsibility
32147 atm_vcc->push (atm_vcc, skb);
32148@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32149 } else {
32150 PRINTK (KERN_INFO, "dropped over-size frame");
32151 // should we count this?
32152- atomic_inc(&atm_vcc->stats->rx_drop);
32153+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32154 }
32155
32156 } else {
32157@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32158 }
32159
32160 if (check_area (skb->data, skb->len)) {
32161- atomic_inc(&atm_vcc->stats->tx_err);
32162+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32163 return -ENOMEM; // ?
32164 }
32165
32166diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32167index 0e3f8f9..765a7a5 100644
32168--- a/drivers/atm/atmtcp.c
32169+++ b/drivers/atm/atmtcp.c
32170@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32171 if (vcc->pop) vcc->pop(vcc,skb);
32172 else dev_kfree_skb(skb);
32173 if (dev_data) return 0;
32174- atomic_inc(&vcc->stats->tx_err);
32175+ atomic_inc_unchecked(&vcc->stats->tx_err);
32176 return -ENOLINK;
32177 }
32178 size = skb->len+sizeof(struct atmtcp_hdr);
32179@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32180 if (!new_skb) {
32181 if (vcc->pop) vcc->pop(vcc,skb);
32182 else dev_kfree_skb(skb);
32183- atomic_inc(&vcc->stats->tx_err);
32184+ atomic_inc_unchecked(&vcc->stats->tx_err);
32185 return -ENOBUFS;
32186 }
32187 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32188@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32189 if (vcc->pop) vcc->pop(vcc,skb);
32190 else dev_kfree_skb(skb);
32191 out_vcc->push(out_vcc,new_skb);
32192- atomic_inc(&vcc->stats->tx);
32193- atomic_inc(&out_vcc->stats->rx);
32194+ atomic_inc_unchecked(&vcc->stats->tx);
32195+ atomic_inc_unchecked(&out_vcc->stats->rx);
32196 return 0;
32197 }
32198
32199@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32200 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32201 read_unlock(&vcc_sklist_lock);
32202 if (!out_vcc) {
32203- atomic_inc(&vcc->stats->tx_err);
32204+ atomic_inc_unchecked(&vcc->stats->tx_err);
32205 goto done;
32206 }
32207 skb_pull(skb,sizeof(struct atmtcp_hdr));
32208@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32209 __net_timestamp(new_skb);
32210 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32211 out_vcc->push(out_vcc,new_skb);
32212- atomic_inc(&vcc->stats->tx);
32213- atomic_inc(&out_vcc->stats->rx);
32214+ atomic_inc_unchecked(&vcc->stats->tx);
32215+ atomic_inc_unchecked(&out_vcc->stats->rx);
32216 done:
32217 if (vcc->pop) vcc->pop(vcc,skb);
32218 else dev_kfree_skb(skb);
32219diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32220index b1955ba..b179940 100644
32221--- a/drivers/atm/eni.c
32222+++ b/drivers/atm/eni.c
32223@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32224 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32225 vcc->dev->number);
32226 length = 0;
32227- atomic_inc(&vcc->stats->rx_err);
32228+ atomic_inc_unchecked(&vcc->stats->rx_err);
32229 }
32230 else {
32231 length = ATM_CELL_SIZE-1; /* no HEC */
32232@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32233 size);
32234 }
32235 eff = length = 0;
32236- atomic_inc(&vcc->stats->rx_err);
32237+ atomic_inc_unchecked(&vcc->stats->rx_err);
32238 }
32239 else {
32240 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32241@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32242 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32243 vcc->dev->number,vcc->vci,length,size << 2,descr);
32244 length = eff = 0;
32245- atomic_inc(&vcc->stats->rx_err);
32246+ atomic_inc_unchecked(&vcc->stats->rx_err);
32247 }
32248 }
32249 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32250@@ -767,7 +767,7 @@ rx_dequeued++;
32251 vcc->push(vcc,skb);
32252 pushed++;
32253 }
32254- atomic_inc(&vcc->stats->rx);
32255+ atomic_inc_unchecked(&vcc->stats->rx);
32256 }
32257 wake_up(&eni_dev->rx_wait);
32258 }
32259@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32260 PCI_DMA_TODEVICE);
32261 if (vcc->pop) vcc->pop(vcc,skb);
32262 else dev_kfree_skb_irq(skb);
32263- atomic_inc(&vcc->stats->tx);
32264+ atomic_inc_unchecked(&vcc->stats->tx);
32265 wake_up(&eni_dev->tx_wait);
32266 dma_complete++;
32267 }
32268diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32269index b41c948..a002b17 100644
32270--- a/drivers/atm/firestream.c
32271+++ b/drivers/atm/firestream.c
32272@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32273 }
32274 }
32275
32276- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32277+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32278
32279 fs_dprintk (FS_DEBUG_TXMEM, "i");
32280 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32281@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32282 #endif
32283 skb_put (skb, qe->p1 & 0xffff);
32284 ATM_SKB(skb)->vcc = atm_vcc;
32285- atomic_inc(&atm_vcc->stats->rx);
32286+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32287 __net_timestamp(skb);
32288 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32289 atm_vcc->push (atm_vcc, skb);
32290@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32291 kfree (pe);
32292 }
32293 if (atm_vcc)
32294- atomic_inc(&atm_vcc->stats->rx_drop);
32295+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32296 break;
32297 case 0x1f: /* Reassembly abort: no buffers. */
32298 /* Silently increment error counter. */
32299 if (atm_vcc)
32300- atomic_inc(&atm_vcc->stats->rx_drop);
32301+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32302 break;
32303 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32304 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32305diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32306index 204814e..cede831 100644
32307--- a/drivers/atm/fore200e.c
32308+++ b/drivers/atm/fore200e.c
32309@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32310 #endif
32311 /* check error condition */
32312 if (*entry->status & STATUS_ERROR)
32313- atomic_inc(&vcc->stats->tx_err);
32314+ atomic_inc_unchecked(&vcc->stats->tx_err);
32315 else
32316- atomic_inc(&vcc->stats->tx);
32317+ atomic_inc_unchecked(&vcc->stats->tx);
32318 }
32319 }
32320
32321@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32322 if (skb == NULL) {
32323 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32324
32325- atomic_inc(&vcc->stats->rx_drop);
32326+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32327 return -ENOMEM;
32328 }
32329
32330@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32331
32332 dev_kfree_skb_any(skb);
32333
32334- atomic_inc(&vcc->stats->rx_drop);
32335+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32336 return -ENOMEM;
32337 }
32338
32339 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32340
32341 vcc->push(vcc, skb);
32342- atomic_inc(&vcc->stats->rx);
32343+ atomic_inc_unchecked(&vcc->stats->rx);
32344
32345 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32346
32347@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32348 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32349 fore200e->atm_dev->number,
32350 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32351- atomic_inc(&vcc->stats->rx_err);
32352+ atomic_inc_unchecked(&vcc->stats->rx_err);
32353 }
32354 }
32355
32356@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32357 goto retry_here;
32358 }
32359
32360- atomic_inc(&vcc->stats->tx_err);
32361+ atomic_inc_unchecked(&vcc->stats->tx_err);
32362
32363 fore200e->tx_sat++;
32364 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32365diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32366index 507362a..a845e57 100644
32367--- a/drivers/atm/he.c
32368+++ b/drivers/atm/he.c
32369@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32370
32371 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32372 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32373- atomic_inc(&vcc->stats->rx_drop);
32374+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32375 goto return_host_buffers;
32376 }
32377
32378@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32379 RBRQ_LEN_ERR(he_dev->rbrq_head)
32380 ? "LEN_ERR" : "",
32381 vcc->vpi, vcc->vci);
32382- atomic_inc(&vcc->stats->rx_err);
32383+ atomic_inc_unchecked(&vcc->stats->rx_err);
32384 goto return_host_buffers;
32385 }
32386
32387@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32388 vcc->push(vcc, skb);
32389 spin_lock(&he_dev->global_lock);
32390
32391- atomic_inc(&vcc->stats->rx);
32392+ atomic_inc_unchecked(&vcc->stats->rx);
32393
32394 return_host_buffers:
32395 ++pdus_assembled;
32396@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32397 tpd->vcc->pop(tpd->vcc, tpd->skb);
32398 else
32399 dev_kfree_skb_any(tpd->skb);
32400- atomic_inc(&tpd->vcc->stats->tx_err);
32401+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32402 }
32403 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32404 return;
32405@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32406 vcc->pop(vcc, skb);
32407 else
32408 dev_kfree_skb_any(skb);
32409- atomic_inc(&vcc->stats->tx_err);
32410+ atomic_inc_unchecked(&vcc->stats->tx_err);
32411 return -EINVAL;
32412 }
32413
32414@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32415 vcc->pop(vcc, skb);
32416 else
32417 dev_kfree_skb_any(skb);
32418- atomic_inc(&vcc->stats->tx_err);
32419+ atomic_inc_unchecked(&vcc->stats->tx_err);
32420 return -EINVAL;
32421 }
32422 #endif
32423@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32424 vcc->pop(vcc, skb);
32425 else
32426 dev_kfree_skb_any(skb);
32427- atomic_inc(&vcc->stats->tx_err);
32428+ atomic_inc_unchecked(&vcc->stats->tx_err);
32429 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32430 return -ENOMEM;
32431 }
32432@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32433 vcc->pop(vcc, skb);
32434 else
32435 dev_kfree_skb_any(skb);
32436- atomic_inc(&vcc->stats->tx_err);
32437+ atomic_inc_unchecked(&vcc->stats->tx_err);
32438 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32439 return -ENOMEM;
32440 }
32441@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32442 __enqueue_tpd(he_dev, tpd, cid);
32443 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32444
32445- atomic_inc(&vcc->stats->tx);
32446+ atomic_inc_unchecked(&vcc->stats->tx);
32447
32448 return 0;
32449 }
32450diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32451index 1dc0519..1aadaf7 100644
32452--- a/drivers/atm/horizon.c
32453+++ b/drivers/atm/horizon.c
32454@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32455 {
32456 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32457 // VC layer stats
32458- atomic_inc(&vcc->stats->rx);
32459+ atomic_inc_unchecked(&vcc->stats->rx);
32460 __net_timestamp(skb);
32461 // end of our responsibility
32462 vcc->push (vcc, skb);
32463@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32464 dev->tx_iovec = NULL;
32465
32466 // VC layer stats
32467- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32468+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32469
32470 // free the skb
32471 hrz_kfree_skb (skb);
32472diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32473index 272f009..a18ba55 100644
32474--- a/drivers/atm/idt77252.c
32475+++ b/drivers/atm/idt77252.c
32476@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32477 else
32478 dev_kfree_skb(skb);
32479
32480- atomic_inc(&vcc->stats->tx);
32481+ atomic_inc_unchecked(&vcc->stats->tx);
32482 }
32483
32484 atomic_dec(&scq->used);
32485@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32486 if ((sb = dev_alloc_skb(64)) == NULL) {
32487 printk("%s: Can't allocate buffers for aal0.\n",
32488 card->name);
32489- atomic_add(i, &vcc->stats->rx_drop);
32490+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32491 break;
32492 }
32493 if (!atm_charge(vcc, sb->truesize)) {
32494 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32495 card->name);
32496- atomic_add(i - 1, &vcc->stats->rx_drop);
32497+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32498 dev_kfree_skb(sb);
32499 break;
32500 }
32501@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32502 ATM_SKB(sb)->vcc = vcc;
32503 __net_timestamp(sb);
32504 vcc->push(vcc, sb);
32505- atomic_inc(&vcc->stats->rx);
32506+ atomic_inc_unchecked(&vcc->stats->rx);
32507
32508 cell += ATM_CELL_PAYLOAD;
32509 }
32510@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32511 "(CDC: %08x)\n",
32512 card->name, len, rpp->len, readl(SAR_REG_CDC));
32513 recycle_rx_pool_skb(card, rpp);
32514- atomic_inc(&vcc->stats->rx_err);
32515+ atomic_inc_unchecked(&vcc->stats->rx_err);
32516 return;
32517 }
32518 if (stat & SAR_RSQE_CRC) {
32519 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32520 recycle_rx_pool_skb(card, rpp);
32521- atomic_inc(&vcc->stats->rx_err);
32522+ atomic_inc_unchecked(&vcc->stats->rx_err);
32523 return;
32524 }
32525 if (skb_queue_len(&rpp->queue) > 1) {
32526@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32527 RXPRINTK("%s: Can't alloc RX skb.\n",
32528 card->name);
32529 recycle_rx_pool_skb(card, rpp);
32530- atomic_inc(&vcc->stats->rx_err);
32531+ atomic_inc_unchecked(&vcc->stats->rx_err);
32532 return;
32533 }
32534 if (!atm_charge(vcc, skb->truesize)) {
32535@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32536 __net_timestamp(skb);
32537
32538 vcc->push(vcc, skb);
32539- atomic_inc(&vcc->stats->rx);
32540+ atomic_inc_unchecked(&vcc->stats->rx);
32541
32542 return;
32543 }
32544@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32545 __net_timestamp(skb);
32546
32547 vcc->push(vcc, skb);
32548- atomic_inc(&vcc->stats->rx);
32549+ atomic_inc_unchecked(&vcc->stats->rx);
32550
32551 if (skb->truesize > SAR_FB_SIZE_3)
32552 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32553@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32554 if (vcc->qos.aal != ATM_AAL0) {
32555 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32556 card->name, vpi, vci);
32557- atomic_inc(&vcc->stats->rx_drop);
32558+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32559 goto drop;
32560 }
32561
32562 if ((sb = dev_alloc_skb(64)) == NULL) {
32563 printk("%s: Can't allocate buffers for AAL0.\n",
32564 card->name);
32565- atomic_inc(&vcc->stats->rx_err);
32566+ atomic_inc_unchecked(&vcc->stats->rx_err);
32567 goto drop;
32568 }
32569
32570@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32571 ATM_SKB(sb)->vcc = vcc;
32572 __net_timestamp(sb);
32573 vcc->push(vcc, sb);
32574- atomic_inc(&vcc->stats->rx);
32575+ atomic_inc_unchecked(&vcc->stats->rx);
32576
32577 drop:
32578 skb_pull(queue, 64);
32579@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32580
32581 if (vc == NULL) {
32582 printk("%s: NULL connection in send().\n", card->name);
32583- atomic_inc(&vcc->stats->tx_err);
32584+ atomic_inc_unchecked(&vcc->stats->tx_err);
32585 dev_kfree_skb(skb);
32586 return -EINVAL;
32587 }
32588 if (!test_bit(VCF_TX, &vc->flags)) {
32589 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32590- atomic_inc(&vcc->stats->tx_err);
32591+ atomic_inc_unchecked(&vcc->stats->tx_err);
32592 dev_kfree_skb(skb);
32593 return -EINVAL;
32594 }
32595@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32596 break;
32597 default:
32598 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32599- atomic_inc(&vcc->stats->tx_err);
32600+ atomic_inc_unchecked(&vcc->stats->tx_err);
32601 dev_kfree_skb(skb);
32602 return -EINVAL;
32603 }
32604
32605 if (skb_shinfo(skb)->nr_frags != 0) {
32606 printk("%s: No scatter-gather yet.\n", card->name);
32607- atomic_inc(&vcc->stats->tx_err);
32608+ atomic_inc_unchecked(&vcc->stats->tx_err);
32609 dev_kfree_skb(skb);
32610 return -EINVAL;
32611 }
32612@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32613
32614 err = queue_skb(card, vc, skb, oam);
32615 if (err) {
32616- atomic_inc(&vcc->stats->tx_err);
32617+ atomic_inc_unchecked(&vcc->stats->tx_err);
32618 dev_kfree_skb(skb);
32619 return err;
32620 }
32621@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32622 skb = dev_alloc_skb(64);
32623 if (!skb) {
32624 printk("%s: Out of memory in send_oam().\n", card->name);
32625- atomic_inc(&vcc->stats->tx_err);
32626+ atomic_inc_unchecked(&vcc->stats->tx_err);
32627 return -ENOMEM;
32628 }
32629 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32630diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32631index 4217f29..88f547a 100644
32632--- a/drivers/atm/iphase.c
32633+++ b/drivers/atm/iphase.c
32634@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32635 status = (u_short) (buf_desc_ptr->desc_mode);
32636 if (status & (RX_CER | RX_PTE | RX_OFL))
32637 {
32638- atomic_inc(&vcc->stats->rx_err);
32639+ atomic_inc_unchecked(&vcc->stats->rx_err);
32640 IF_ERR(printk("IA: bad packet, dropping it");)
32641 if (status & RX_CER) {
32642 IF_ERR(printk(" cause: packet CRC error\n");)
32643@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32644 len = dma_addr - buf_addr;
32645 if (len > iadev->rx_buf_sz) {
32646 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32647- atomic_inc(&vcc->stats->rx_err);
32648+ atomic_inc_unchecked(&vcc->stats->rx_err);
32649 goto out_free_desc;
32650 }
32651
32652@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32653 ia_vcc = INPH_IA_VCC(vcc);
32654 if (ia_vcc == NULL)
32655 {
32656- atomic_inc(&vcc->stats->rx_err);
32657+ atomic_inc_unchecked(&vcc->stats->rx_err);
32658 atm_return(vcc, skb->truesize);
32659 dev_kfree_skb_any(skb);
32660 goto INCR_DLE;
32661@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32662 if ((length > iadev->rx_buf_sz) || (length >
32663 (skb->len - sizeof(struct cpcs_trailer))))
32664 {
32665- atomic_inc(&vcc->stats->rx_err);
32666+ atomic_inc_unchecked(&vcc->stats->rx_err);
32667 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32668 length, skb->len);)
32669 atm_return(vcc, skb->truesize);
32670@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32671
32672 IF_RX(printk("rx_dle_intr: skb push");)
32673 vcc->push(vcc,skb);
32674- atomic_inc(&vcc->stats->rx);
32675+ atomic_inc_unchecked(&vcc->stats->rx);
32676 iadev->rx_pkt_cnt++;
32677 }
32678 INCR_DLE:
32679@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32680 {
32681 struct k_sonet_stats *stats;
32682 stats = &PRIV(_ia_dev[board])->sonet_stats;
32683- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32684- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32685- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32686- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32687- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32688- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32689- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32690- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32691- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32692+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32693+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32694+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32695+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32696+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32697+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32698+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32699+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32700+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32701 }
32702 ia_cmds.status = 0;
32703 break;
32704@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32705 if ((desc == 0) || (desc > iadev->num_tx_desc))
32706 {
32707 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32708- atomic_inc(&vcc->stats->tx);
32709+ atomic_inc_unchecked(&vcc->stats->tx);
32710 if (vcc->pop)
32711 vcc->pop(vcc, skb);
32712 else
32713@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32714 ATM_DESC(skb) = vcc->vci;
32715 skb_queue_tail(&iadev->tx_dma_q, skb);
32716
32717- atomic_inc(&vcc->stats->tx);
32718+ atomic_inc_unchecked(&vcc->stats->tx);
32719 iadev->tx_pkt_cnt++;
32720 /* Increment transaction counter */
32721 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32722
32723 #if 0
32724 /* add flow control logic */
32725- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32726+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32727 if (iavcc->vc_desc_cnt > 10) {
32728 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32729 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32730diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32731index fa7d701..1e404c7 100644
32732--- a/drivers/atm/lanai.c
32733+++ b/drivers/atm/lanai.c
32734@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32735 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32736 lanai_endtx(lanai, lvcc);
32737 lanai_free_skb(lvcc->tx.atmvcc, skb);
32738- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32739+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32740 }
32741
32742 /* Try to fill the buffer - don't call unless there is backlog */
32743@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32744 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32745 __net_timestamp(skb);
32746 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32747- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32748+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32749 out:
32750 lvcc->rx.buf.ptr = end;
32751 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32752@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32753 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32754 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32755 lanai->stats.service_rxnotaal5++;
32756- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32757+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32758 return 0;
32759 }
32760 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32761@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32762 int bytes;
32763 read_unlock(&vcc_sklist_lock);
32764 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32765- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32766+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32767 lvcc->stats.x.aal5.service_trash++;
32768 bytes = (SERVICE_GET_END(s) * 16) -
32769 (((unsigned long) lvcc->rx.buf.ptr) -
32770@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32771 }
32772 if (s & SERVICE_STREAM) {
32773 read_unlock(&vcc_sklist_lock);
32774- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32775+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32776 lvcc->stats.x.aal5.service_stream++;
32777 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32778 "PDU on VCI %d!\n", lanai->number, vci);
32779@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32780 return 0;
32781 }
32782 DPRINTK("got rx crc error on vci %d\n", vci);
32783- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32784+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32785 lvcc->stats.x.aal5.service_rxcrc++;
32786 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32787 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32788diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32789index 6587dc2..149833d 100644
32790--- a/drivers/atm/nicstar.c
32791+++ b/drivers/atm/nicstar.c
32792@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32793 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32794 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32795 card->index);
32796- atomic_inc(&vcc->stats->tx_err);
32797+ atomic_inc_unchecked(&vcc->stats->tx_err);
32798 dev_kfree_skb_any(skb);
32799 return -EINVAL;
32800 }
32801@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32802 if (!vc->tx) {
32803 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32804 card->index);
32805- atomic_inc(&vcc->stats->tx_err);
32806+ atomic_inc_unchecked(&vcc->stats->tx_err);
32807 dev_kfree_skb_any(skb);
32808 return -EINVAL;
32809 }
32810@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32811 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32812 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32813 card->index);
32814- atomic_inc(&vcc->stats->tx_err);
32815+ atomic_inc_unchecked(&vcc->stats->tx_err);
32816 dev_kfree_skb_any(skb);
32817 return -EINVAL;
32818 }
32819
32820 if (skb_shinfo(skb)->nr_frags != 0) {
32821 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32822- atomic_inc(&vcc->stats->tx_err);
32823+ atomic_inc_unchecked(&vcc->stats->tx_err);
32824 dev_kfree_skb_any(skb);
32825 return -EINVAL;
32826 }
32827@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32828 }
32829
32830 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32831- atomic_inc(&vcc->stats->tx_err);
32832+ atomic_inc_unchecked(&vcc->stats->tx_err);
32833 dev_kfree_skb_any(skb);
32834 return -EIO;
32835 }
32836- atomic_inc(&vcc->stats->tx);
32837+ atomic_inc_unchecked(&vcc->stats->tx);
32838
32839 return 0;
32840 }
32841@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32842 printk
32843 ("nicstar%d: Can't allocate buffers for aal0.\n",
32844 card->index);
32845- atomic_add(i, &vcc->stats->rx_drop);
32846+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32847 break;
32848 }
32849 if (!atm_charge(vcc, sb->truesize)) {
32850 RXPRINTK
32851 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32852 card->index);
32853- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32854+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32855 dev_kfree_skb_any(sb);
32856 break;
32857 }
32858@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32859 ATM_SKB(sb)->vcc = vcc;
32860 __net_timestamp(sb);
32861 vcc->push(vcc, sb);
32862- atomic_inc(&vcc->stats->rx);
32863+ atomic_inc_unchecked(&vcc->stats->rx);
32864 cell += ATM_CELL_PAYLOAD;
32865 }
32866
32867@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32868 if (iovb == NULL) {
32869 printk("nicstar%d: Out of iovec buffers.\n",
32870 card->index);
32871- atomic_inc(&vcc->stats->rx_drop);
32872+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32873 recycle_rx_buf(card, skb);
32874 return;
32875 }
32876@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32877 small or large buffer itself. */
32878 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32879 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32880- atomic_inc(&vcc->stats->rx_err);
32881+ atomic_inc_unchecked(&vcc->stats->rx_err);
32882 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32883 NS_MAX_IOVECS);
32884 NS_PRV_IOVCNT(iovb) = 0;
32885@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32886 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32887 card->index);
32888 which_list(card, skb);
32889- atomic_inc(&vcc->stats->rx_err);
32890+ atomic_inc_unchecked(&vcc->stats->rx_err);
32891 recycle_rx_buf(card, skb);
32892 vc->rx_iov = NULL;
32893 recycle_iov_buf(card, iovb);
32894@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32895 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32896 card->index);
32897 which_list(card, skb);
32898- atomic_inc(&vcc->stats->rx_err);
32899+ atomic_inc_unchecked(&vcc->stats->rx_err);
32900 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32901 NS_PRV_IOVCNT(iovb));
32902 vc->rx_iov = NULL;
32903@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32904 printk(" - PDU size mismatch.\n");
32905 else
32906 printk(".\n");
32907- atomic_inc(&vcc->stats->rx_err);
32908+ atomic_inc_unchecked(&vcc->stats->rx_err);
32909 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32910 NS_PRV_IOVCNT(iovb));
32911 vc->rx_iov = NULL;
32912@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32913 /* skb points to a small buffer */
32914 if (!atm_charge(vcc, skb->truesize)) {
32915 push_rxbufs(card, skb);
32916- atomic_inc(&vcc->stats->rx_drop);
32917+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32918 } else {
32919 skb_put(skb, len);
32920 dequeue_sm_buf(card, skb);
32921@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32922 ATM_SKB(skb)->vcc = vcc;
32923 __net_timestamp(skb);
32924 vcc->push(vcc, skb);
32925- atomic_inc(&vcc->stats->rx);
32926+ atomic_inc_unchecked(&vcc->stats->rx);
32927 }
32928 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32929 struct sk_buff *sb;
32930@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32931 if (len <= NS_SMBUFSIZE) {
32932 if (!atm_charge(vcc, sb->truesize)) {
32933 push_rxbufs(card, sb);
32934- atomic_inc(&vcc->stats->rx_drop);
32935+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32936 } else {
32937 skb_put(sb, len);
32938 dequeue_sm_buf(card, sb);
32939@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32940 ATM_SKB(sb)->vcc = vcc;
32941 __net_timestamp(sb);
32942 vcc->push(vcc, sb);
32943- atomic_inc(&vcc->stats->rx);
32944+ atomic_inc_unchecked(&vcc->stats->rx);
32945 }
32946
32947 push_rxbufs(card, skb);
32948@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32949
32950 if (!atm_charge(vcc, skb->truesize)) {
32951 push_rxbufs(card, skb);
32952- atomic_inc(&vcc->stats->rx_drop);
32953+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32954 } else {
32955 dequeue_lg_buf(card, skb);
32956 #ifdef NS_USE_DESTRUCTORS
32957@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32958 ATM_SKB(skb)->vcc = vcc;
32959 __net_timestamp(skb);
32960 vcc->push(vcc, skb);
32961- atomic_inc(&vcc->stats->rx);
32962+ atomic_inc_unchecked(&vcc->stats->rx);
32963 }
32964
32965 push_rxbufs(card, sb);
32966@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32967 printk
32968 ("nicstar%d: Out of huge buffers.\n",
32969 card->index);
32970- atomic_inc(&vcc->stats->rx_drop);
32971+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32972 recycle_iovec_rx_bufs(card,
32973 (struct iovec *)
32974 iovb->data,
32975@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32976 card->hbpool.count++;
32977 } else
32978 dev_kfree_skb_any(hb);
32979- atomic_inc(&vcc->stats->rx_drop);
32980+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32981 } else {
32982 /* Copy the small buffer to the huge buffer */
32983 sb = (struct sk_buff *)iov->iov_base;
32984@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32985 #endif /* NS_USE_DESTRUCTORS */
32986 __net_timestamp(hb);
32987 vcc->push(vcc, hb);
32988- atomic_inc(&vcc->stats->rx);
32989+ atomic_inc_unchecked(&vcc->stats->rx);
32990 }
32991 }
32992
32993diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32994index 32784d1..4a8434a 100644
32995--- a/drivers/atm/solos-pci.c
32996+++ b/drivers/atm/solos-pci.c
32997@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32998 }
32999 atm_charge(vcc, skb->truesize);
33000 vcc->push(vcc, skb);
33001- atomic_inc(&vcc->stats->rx);
33002+ atomic_inc_unchecked(&vcc->stats->rx);
33003 break;
33004
33005 case PKT_STATUS:
33006@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
33007 vcc = SKB_CB(oldskb)->vcc;
33008
33009 if (vcc) {
33010- atomic_inc(&vcc->stats->tx);
33011+ atomic_inc_unchecked(&vcc->stats->tx);
33012 solos_pop(vcc, oldskb);
33013 } else {
33014 dev_kfree_skb_irq(oldskb);
33015diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
33016index 0215934..ce9f5b1 100644
33017--- a/drivers/atm/suni.c
33018+++ b/drivers/atm/suni.c
33019@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
33020
33021
33022 #define ADD_LIMITED(s,v) \
33023- atomic_add((v),&stats->s); \
33024- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
33025+ atomic_add_unchecked((v),&stats->s); \
33026+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
33027
33028
33029 static void suni_hz(unsigned long from_timer)
33030diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
33031index 5120a96..e2572bd 100644
33032--- a/drivers/atm/uPD98402.c
33033+++ b/drivers/atm/uPD98402.c
33034@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
33035 struct sonet_stats tmp;
33036 int error = 0;
33037
33038- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33039+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
33040 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
33041 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
33042 if (zero && !error) {
33043@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
33044
33045
33046 #define ADD_LIMITED(s,v) \
33047- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
33048- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
33049- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33050+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
33051+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
33052+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
33053
33054
33055 static void stat_event(struct atm_dev *dev)
33056@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
33057 if (reason & uPD98402_INT_PFM) stat_event(dev);
33058 if (reason & uPD98402_INT_PCO) {
33059 (void) GET(PCOCR); /* clear interrupt cause */
33060- atomic_add(GET(HECCT),
33061+ atomic_add_unchecked(GET(HECCT),
33062 &PRIV(dev)->sonet_stats.uncorr_hcs);
33063 }
33064 if ((reason & uPD98402_INT_RFO) &&
33065@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
33066 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33067 uPD98402_INT_LOS),PIMR); /* enable them */
33068 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33069- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33070- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33071- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33072+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33073+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33074+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33075 return 0;
33076 }
33077
33078diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33079index 969c3c2..9b72956 100644
33080--- a/drivers/atm/zatm.c
33081+++ b/drivers/atm/zatm.c
33082@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33083 }
33084 if (!size) {
33085 dev_kfree_skb_irq(skb);
33086- if (vcc) atomic_inc(&vcc->stats->rx_err);
33087+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33088 continue;
33089 }
33090 if (!atm_charge(vcc,skb->truesize)) {
33091@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33092 skb->len = size;
33093 ATM_SKB(skb)->vcc = vcc;
33094 vcc->push(vcc,skb);
33095- atomic_inc(&vcc->stats->rx);
33096+ atomic_inc_unchecked(&vcc->stats->rx);
33097 }
33098 zout(pos & 0xffff,MTA(mbx));
33099 #if 0 /* probably a stupid idea */
33100@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33101 skb_queue_head(&zatm_vcc->backlog,skb);
33102 break;
33103 }
33104- atomic_inc(&vcc->stats->tx);
33105+ atomic_inc_unchecked(&vcc->stats->tx);
33106 wake_up(&zatm_vcc->tx_wait);
33107 }
33108
33109diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
33110index d78b204..ecc1929 100644
33111--- a/drivers/base/attribute_container.c
33112+++ b/drivers/base/attribute_container.c
33113@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
33114 ic->classdev.parent = get_device(dev);
33115 ic->classdev.class = cont->class;
33116 cont->class->dev_release = attribute_container_release;
33117- dev_set_name(&ic->classdev, dev_name(dev));
33118+ dev_set_name(&ic->classdev, "%s", dev_name(dev));
33119 if (fn)
33120 fn(cont, dev, &ic->classdev);
33121 else
33122diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33123index d414331..b4dd4ba 100644
33124--- a/drivers/base/bus.c
33125+++ b/drivers/base/bus.c
33126@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33127 return -EINVAL;
33128
33129 mutex_lock(&subsys->p->mutex);
33130- list_add_tail(&sif->node, &subsys->p->interfaces);
33131+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33132 if (sif->add_dev) {
33133 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33134 while ((dev = subsys_dev_iter_next(&iter)))
33135@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33136 subsys = sif->subsys;
33137
33138 mutex_lock(&subsys->p->mutex);
33139- list_del_init(&sif->node);
33140+ pax_list_del_init((struct list_head *)&sif->node);
33141 if (sif->remove_dev) {
33142 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33143 while ((dev = subsys_dev_iter_next(&iter)))
33144diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33145index 7413d06..79155fa 100644
33146--- a/drivers/base/devtmpfs.c
33147+++ b/drivers/base/devtmpfs.c
33148@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
33149 if (!thread)
33150 return 0;
33151
33152- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33153+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33154 if (err)
33155 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33156 else
33157@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
33158 *err = sys_unshare(CLONE_NEWNS);
33159 if (*err)
33160 goto out;
33161- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
33162+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
33163 if (*err)
33164 goto out;
33165- sys_chdir("/.."); /* will traverse into overmounted root */
33166- sys_chroot(".");
33167+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
33168+ sys_chroot((char __force_user *)".");
33169 complete(&setup_done);
33170 while (1) {
33171 spin_lock(&req_lock);
33172diff --git a/drivers/base/node.c b/drivers/base/node.c
33173index 7616a77c..8f57f51 100644
33174--- a/drivers/base/node.c
33175+++ b/drivers/base/node.c
33176@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33177 struct node_attr {
33178 struct device_attribute attr;
33179 enum node_states state;
33180-};
33181+} __do_const;
33182
33183 static ssize_t show_node_state(struct device *dev,
33184 struct device_attribute *attr, char *buf)
33185diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33186index 7072404..76dcebd 100644
33187--- a/drivers/base/power/domain.c
33188+++ b/drivers/base/power/domain.c
33189@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33190 {
33191 struct cpuidle_driver *cpuidle_drv;
33192 struct gpd_cpu_data *cpu_data;
33193- struct cpuidle_state *idle_state;
33194+ cpuidle_state_no_const *idle_state;
33195 int ret = 0;
33196
33197 if (IS_ERR_OR_NULL(genpd) || state < 0)
33198@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33199 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33200 {
33201 struct gpd_cpu_data *cpu_data;
33202- struct cpuidle_state *idle_state;
33203+ cpuidle_state_no_const *idle_state;
33204 int ret = 0;
33205
33206 if (IS_ERR_OR_NULL(genpd))
33207diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
33208index a53ebd2..8f73eeb 100644
33209--- a/drivers/base/power/sysfs.c
33210+++ b/drivers/base/power/sysfs.c
33211@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
33212 return -EIO;
33213 }
33214 }
33215- return sprintf(buf, p);
33216+ return sprintf(buf, "%s", p);
33217 }
33218
33219 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
33220diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33221index 79715e7..df06b3b 100644
33222--- a/drivers/base/power/wakeup.c
33223+++ b/drivers/base/power/wakeup.c
33224@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33225 * They need to be modified together atomically, so it's better to use one
33226 * atomic variable to hold them both.
33227 */
33228-static atomic_t combined_event_count = ATOMIC_INIT(0);
33229+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33230
33231 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33232 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33233
33234 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33235 {
33236- unsigned int comb = atomic_read(&combined_event_count);
33237+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33238
33239 *cnt = (comb >> IN_PROGRESS_BITS);
33240 *inpr = comb & MAX_IN_PROGRESS;
33241@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33242 ws->start_prevent_time = ws->last_time;
33243
33244 /* Increment the counter of events in progress. */
33245- cec = atomic_inc_return(&combined_event_count);
33246+ cec = atomic_inc_return_unchecked(&combined_event_count);
33247
33248 trace_wakeup_source_activate(ws->name, cec);
33249 }
33250@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33251 * Increment the counter of registered wakeup events and decrement the
33252 * couter of wakeup events in progress simultaneously.
33253 */
33254- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33255+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33256 trace_wakeup_source_deactivate(ws->name, cec);
33257
33258 split_counters(&cnt, &inpr);
33259diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33260index e8d11b6..7b1b36f 100644
33261--- a/drivers/base/syscore.c
33262+++ b/drivers/base/syscore.c
33263@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33264 void register_syscore_ops(struct syscore_ops *ops)
33265 {
33266 mutex_lock(&syscore_ops_lock);
33267- list_add_tail(&ops->node, &syscore_ops_list);
33268+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33269 mutex_unlock(&syscore_ops_lock);
33270 }
33271 EXPORT_SYMBOL_GPL(register_syscore_ops);
33272@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33273 void unregister_syscore_ops(struct syscore_ops *ops)
33274 {
33275 mutex_lock(&syscore_ops_lock);
33276- list_del(&ops->node);
33277+ pax_list_del((struct list_head *)&ops->node);
33278 mutex_unlock(&syscore_ops_lock);
33279 }
33280 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33281diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33282index 62b6c2c..4a11354 100644
33283--- a/drivers/block/cciss.c
33284+++ b/drivers/block/cciss.c
33285@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33286 int err;
33287 u32 cp;
33288
33289+ memset(&arg64, 0, sizeof(arg64));
33290+
33291 err = 0;
33292 err |=
33293 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33294@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
33295 while (!list_empty(&h->reqQ)) {
33296 c = list_entry(h->reqQ.next, CommandList_struct, list);
33297 /* can't do anything if fifo is full */
33298- if ((h->access.fifo_full(h))) {
33299+ if ((h->access->fifo_full(h))) {
33300 dev_warn(&h->pdev->dev, "fifo full\n");
33301 break;
33302 }
33303@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
33304 h->Qdepth--;
33305
33306 /* Tell the controller execute command */
33307- h->access.submit_command(h, c);
33308+ h->access->submit_command(h, c);
33309
33310 /* Put job onto the completed Q */
33311 addQ(&h->cmpQ, c);
33312@@ -3446,17 +3448,17 @@ startio:
33313
33314 static inline unsigned long get_next_completion(ctlr_info_t *h)
33315 {
33316- return h->access.command_completed(h);
33317+ return h->access->command_completed(h);
33318 }
33319
33320 static inline int interrupt_pending(ctlr_info_t *h)
33321 {
33322- return h->access.intr_pending(h);
33323+ return h->access->intr_pending(h);
33324 }
33325
33326 static inline long interrupt_not_for_us(ctlr_info_t *h)
33327 {
33328- return ((h->access.intr_pending(h) == 0) ||
33329+ return ((h->access->intr_pending(h) == 0) ||
33330 (h->interrupts_enabled == 0));
33331 }
33332
33333@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
33334 u32 a;
33335
33336 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33337- return h->access.command_completed(h);
33338+ return h->access->command_completed(h);
33339
33340 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33341 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33342@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33343 trans_support & CFGTBL_Trans_use_short_tags);
33344
33345 /* Change the access methods to the performant access methods */
33346- h->access = SA5_performant_access;
33347+ h->access = &SA5_performant_access;
33348 h->transMethod = CFGTBL_Trans_Performant;
33349
33350 return;
33351@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33352 if (prod_index < 0)
33353 return -ENODEV;
33354 h->product_name = products[prod_index].product_name;
33355- h->access = *(products[prod_index].access);
33356+ h->access = products[prod_index].access;
33357
33358 if (cciss_board_disabled(h)) {
33359 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33360@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
33361 }
33362
33363 /* make sure the board interrupts are off */
33364- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33365+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33366 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33367 if (rc)
33368 goto clean2;
33369@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
33370 * fake ones to scoop up any residual completions.
33371 */
33372 spin_lock_irqsave(&h->lock, flags);
33373- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33374+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33375 spin_unlock_irqrestore(&h->lock, flags);
33376 free_irq(h->intr[h->intr_mode], h);
33377 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33378@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
33379 dev_info(&h->pdev->dev, "Board READY.\n");
33380 dev_info(&h->pdev->dev,
33381 "Waiting for stale completions to drain.\n");
33382- h->access.set_intr_mask(h, CCISS_INTR_ON);
33383+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33384 msleep(10000);
33385- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33386+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33387
33388 rc = controller_reset_failed(h->cfgtable);
33389 if (rc)
33390@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
33391 cciss_scsi_setup(h);
33392
33393 /* Turn the interrupts on so we can service requests */
33394- h->access.set_intr_mask(h, CCISS_INTR_ON);
33395+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33396
33397 /* Get the firmware version */
33398 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33399@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33400 kfree(flush_buf);
33401 if (return_code != IO_OK)
33402 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33403- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33404+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33405 free_irq(h->intr[h->intr_mode], h);
33406 }
33407
33408diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33409index 7fda30e..eb5dfe0 100644
33410--- a/drivers/block/cciss.h
33411+++ b/drivers/block/cciss.h
33412@@ -101,7 +101,7 @@ struct ctlr_info
33413 /* information about each logical volume */
33414 drive_info_struct *drv[CISS_MAX_LUN];
33415
33416- struct access_method access;
33417+ struct access_method *access;
33418
33419 /* queue and queue Info */
33420 struct list_head reqQ;
33421diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33422index 639d26b..fd6ad1f 100644
33423--- a/drivers/block/cpqarray.c
33424+++ b/drivers/block/cpqarray.c
33425@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33426 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33427 goto Enomem4;
33428 }
33429- hba[i]->access.set_intr_mask(hba[i], 0);
33430+ hba[i]->access->set_intr_mask(hba[i], 0);
33431 if (request_irq(hba[i]->intr, do_ida_intr,
33432 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33433 {
33434@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33435 add_timer(&hba[i]->timer);
33436
33437 /* Enable IRQ now that spinlock and rate limit timer are set up */
33438- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33439+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33440
33441 for(j=0; j<NWD; j++) {
33442 struct gendisk *disk = ida_gendisk[i][j];
33443@@ -694,7 +694,7 @@ DBGINFO(
33444 for(i=0; i<NR_PRODUCTS; i++) {
33445 if (board_id == products[i].board_id) {
33446 c->product_name = products[i].product_name;
33447- c->access = *(products[i].access);
33448+ c->access = products[i].access;
33449 break;
33450 }
33451 }
33452@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33453 hba[ctlr]->intr = intr;
33454 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33455 hba[ctlr]->product_name = products[j].product_name;
33456- hba[ctlr]->access = *(products[j].access);
33457+ hba[ctlr]->access = products[j].access;
33458 hba[ctlr]->ctlr = ctlr;
33459 hba[ctlr]->board_id = board_id;
33460 hba[ctlr]->pci_dev = NULL; /* not PCI */
33461@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
33462
33463 while((c = h->reqQ) != NULL) {
33464 /* Can't do anything if we're busy */
33465- if (h->access.fifo_full(h) == 0)
33466+ if (h->access->fifo_full(h) == 0)
33467 return;
33468
33469 /* Get the first entry from the request Q */
33470@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
33471 h->Qdepth--;
33472
33473 /* Tell the controller to do our bidding */
33474- h->access.submit_command(h, c);
33475+ h->access->submit_command(h, c);
33476
33477 /* Get onto the completion Q */
33478 addQ(&h->cmpQ, c);
33479@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33480 unsigned long flags;
33481 __u32 a,a1;
33482
33483- istat = h->access.intr_pending(h);
33484+ istat = h->access->intr_pending(h);
33485 /* Is this interrupt for us? */
33486 if (istat == 0)
33487 return IRQ_NONE;
33488@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33489 */
33490 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33491 if (istat & FIFO_NOT_EMPTY) {
33492- while((a = h->access.command_completed(h))) {
33493+ while((a = h->access->command_completed(h))) {
33494 a1 = a; a &= ~3;
33495 if ((c = h->cmpQ) == NULL)
33496 {
33497@@ -1193,6 +1193,7 @@ out_passthru:
33498 ida_pci_info_struct pciinfo;
33499
33500 if (!arg) return -EINVAL;
33501+ memset(&pciinfo, 0, sizeof(pciinfo));
33502 pciinfo.bus = host->pci_dev->bus->number;
33503 pciinfo.dev_fn = host->pci_dev->devfn;
33504 pciinfo.board_id = host->board_id;
33505@@ -1447,11 +1448,11 @@ static int sendcmd(
33506 /*
33507 * Disable interrupt
33508 */
33509- info_p->access.set_intr_mask(info_p, 0);
33510+ info_p->access->set_intr_mask(info_p, 0);
33511 /* Make sure there is room in the command FIFO */
33512 /* Actually it should be completely empty at this time. */
33513 for (i = 200000; i > 0; i--) {
33514- temp = info_p->access.fifo_full(info_p);
33515+ temp = info_p->access->fifo_full(info_p);
33516 if (temp != 0) {
33517 break;
33518 }
33519@@ -1464,7 +1465,7 @@ DBG(
33520 /*
33521 * Send the cmd
33522 */
33523- info_p->access.submit_command(info_p, c);
33524+ info_p->access->submit_command(info_p, c);
33525 complete = pollcomplete(ctlr);
33526
33527 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33528@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33529 * we check the new geometry. Then turn interrupts back on when
33530 * we're done.
33531 */
33532- host->access.set_intr_mask(host, 0);
33533+ host->access->set_intr_mask(host, 0);
33534 getgeometry(ctlr);
33535- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33536+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33537
33538 for(i=0; i<NWD; i++) {
33539 struct gendisk *disk = ida_gendisk[ctlr][i];
33540@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
33541 /* Wait (up to 2 seconds) for a command to complete */
33542
33543 for (i = 200000; i > 0; i--) {
33544- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33545+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33546 if (done == 0) {
33547 udelay(10); /* a short fixed delay */
33548 } else
33549diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33550index be73e9d..7fbf140 100644
33551--- a/drivers/block/cpqarray.h
33552+++ b/drivers/block/cpqarray.h
33553@@ -99,7 +99,7 @@ struct ctlr_info {
33554 drv_info_t drv[NWD];
33555 struct proc_dir_entry *proc;
33556
33557- struct access_method access;
33558+ struct access_method *access;
33559
33560 cmdlist_t *reqQ;
33561 cmdlist_t *cmpQ;
33562diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33563index f943aac..99bfd19 100644
33564--- a/drivers/block/drbd/drbd_int.h
33565+++ b/drivers/block/drbd/drbd_int.h
33566@@ -582,7 +582,7 @@ struct drbd_epoch {
33567 struct drbd_tconn *tconn;
33568 struct list_head list;
33569 unsigned int barrier_nr;
33570- atomic_t epoch_size; /* increased on every request added. */
33571+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33572 atomic_t active; /* increased on every req. added, and dec on every finished. */
33573 unsigned long flags;
33574 };
33575@@ -1021,7 +1021,7 @@ struct drbd_conf {
33576 unsigned int al_tr_number;
33577 int al_tr_cycle;
33578 wait_queue_head_t seq_wait;
33579- atomic_t packet_seq;
33580+ atomic_unchecked_t packet_seq;
33581 unsigned int peer_seq;
33582 spinlock_t peer_seq_lock;
33583 unsigned int minor;
33584@@ -1562,7 +1562,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33585 char __user *uoptval;
33586 int err;
33587
33588- uoptval = (char __user __force *)optval;
33589+ uoptval = (char __force_user *)optval;
33590
33591 set_fs(KERNEL_DS);
33592 if (level == SOL_SOCKET)
33593diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33594index a5dca6a..bb27967 100644
33595--- a/drivers/block/drbd/drbd_main.c
33596+++ b/drivers/block/drbd/drbd_main.c
33597@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33598 p->sector = sector;
33599 p->block_id = block_id;
33600 p->blksize = blksize;
33601- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33602+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33603 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33604 }
33605
33606@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33607 return -EIO;
33608 p->sector = cpu_to_be64(req->i.sector);
33609 p->block_id = (unsigned long)req;
33610- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33611+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33612 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33613 if (mdev->state.conn >= C_SYNC_SOURCE &&
33614 mdev->state.conn <= C_PAUSED_SYNC_T)
33615@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33616 {
33617 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33618
33619- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33620- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33621+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33622+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33623 kfree(tconn->current_epoch);
33624
33625 idr_destroy(&tconn->volumes);
33626diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33627index 4222aff..1f79506 100644
33628--- a/drivers/block/drbd/drbd_receiver.c
33629+++ b/drivers/block/drbd/drbd_receiver.c
33630@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
33631 {
33632 int err;
33633
33634- atomic_set(&mdev->packet_seq, 0);
33635+ atomic_set_unchecked(&mdev->packet_seq, 0);
33636 mdev->peer_seq = 0;
33637
33638 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33639@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33640 do {
33641 next_epoch = NULL;
33642
33643- epoch_size = atomic_read(&epoch->epoch_size);
33644+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33645
33646 switch (ev & ~EV_CLEANUP) {
33647 case EV_PUT:
33648@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33649 rv = FE_DESTROYED;
33650 } else {
33651 epoch->flags = 0;
33652- atomic_set(&epoch->epoch_size, 0);
33653+ atomic_set_unchecked(&epoch->epoch_size, 0);
33654 /* atomic_set(&epoch->active, 0); is already zero */
33655 if (rv == FE_STILL_LIVE)
33656 rv = FE_RECYCLED;
33657@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33658 conn_wait_active_ee_empty(tconn);
33659 drbd_flush(tconn);
33660
33661- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33662+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33663 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33664 if (epoch)
33665 break;
33666@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33667 }
33668
33669 epoch->flags = 0;
33670- atomic_set(&epoch->epoch_size, 0);
33671+ atomic_set_unchecked(&epoch->epoch_size, 0);
33672 atomic_set(&epoch->active, 0);
33673
33674 spin_lock(&tconn->epoch_lock);
33675- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33676+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33677 list_add(&epoch->list, &tconn->current_epoch->list);
33678 tconn->current_epoch = epoch;
33679 tconn->epochs++;
33680@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33681
33682 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33683 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33684- atomic_inc(&tconn->current_epoch->epoch_size);
33685+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33686 err2 = drbd_drain_block(mdev, pi->size);
33687 if (!err)
33688 err = err2;
33689@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33690
33691 spin_lock(&tconn->epoch_lock);
33692 peer_req->epoch = tconn->current_epoch;
33693- atomic_inc(&peer_req->epoch->epoch_size);
33694+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33695 atomic_inc(&peer_req->epoch->active);
33696 spin_unlock(&tconn->epoch_lock);
33697
33698@@ -4347,7 +4347,7 @@ struct data_cmd {
33699 int expect_payload;
33700 size_t pkt_size;
33701 int (*fn)(struct drbd_tconn *, struct packet_info *);
33702-};
33703+} __do_const;
33704
33705 static struct data_cmd drbd_cmd_handler[] = {
33706 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33707@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33708 if (!list_empty(&tconn->current_epoch->list))
33709 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33710 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33711- atomic_set(&tconn->current_epoch->epoch_size, 0);
33712+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33713 tconn->send.seen_any_write_yet = false;
33714
33715 conn_info(tconn, "Connection closed\n");
33716@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33717 struct asender_cmd {
33718 size_t pkt_size;
33719 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33720-};
33721+} __do_const;
33722
33723 static struct asender_cmd asender_tbl[] = {
33724 [P_PING] = { 0, got_Ping },
33725diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33726index d92d50f..a7e9d97 100644
33727--- a/drivers/block/loop.c
33728+++ b/drivers/block/loop.c
33729@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
33730
33731 file_start_write(file);
33732 set_fs(get_ds());
33733- bw = file->f_op->write(file, buf, len, &pos);
33734+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33735 set_fs(old_fs);
33736 file_end_write(file);
33737 if (likely(bw == len))
33738diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33739index f5d0ea1..c62380a 100644
33740--- a/drivers/block/pktcdvd.c
33741+++ b/drivers/block/pktcdvd.c
33742@@ -84,7 +84,7 @@
33743 #define MAX_SPEED 0xffff
33744
33745 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
33746- ~(sector_t)((pd)->settings.size - 1))
33747+ ~(sector_t)((pd)->settings.size - 1UL))
33748
33749 static DEFINE_MUTEX(pktcdvd_mutex);
33750 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33751diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33752index 8a3aff7..d7538c2 100644
33753--- a/drivers/cdrom/cdrom.c
33754+++ b/drivers/cdrom/cdrom.c
33755@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33756 ENSURE(reset, CDC_RESET);
33757 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33758 cdi->mc_flags = 0;
33759- cdo->n_minors = 0;
33760 cdi->options = CDO_USE_FFLAGS;
33761
33762 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33763@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33764 else
33765 cdi->cdda_method = CDDA_OLD;
33766
33767- if (!cdo->generic_packet)
33768- cdo->generic_packet = cdrom_dummy_generic_packet;
33769+ if (!cdo->generic_packet) {
33770+ pax_open_kernel();
33771+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33772+ pax_close_kernel();
33773+ }
33774
33775 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33776 mutex_lock(&cdrom_mutex);
33777@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33778 if (cdi->exit)
33779 cdi->exit(cdi);
33780
33781- cdi->ops->n_minors--;
33782 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33783 }
33784
33785@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
33786 */
33787 nr = nframes;
33788 do {
33789- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33790+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33791 if (cgc.buffer)
33792 break;
33793
33794@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
33795 struct cdrom_device_info *cdi;
33796 int ret;
33797
33798- ret = scnprintf(info + *pos, max_size - *pos, header);
33799+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
33800 if (!ret)
33801 return 1;
33802
33803diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33804index 4afcb65..a68a32d 100644
33805--- a/drivers/cdrom/gdrom.c
33806+++ b/drivers/cdrom/gdrom.c
33807@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33808 .audio_ioctl = gdrom_audio_ioctl,
33809 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33810 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33811- .n_minors = 1,
33812 };
33813
33814 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33815diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33816index 3bb6fa3..34013fb 100644
33817--- a/drivers/char/Kconfig
33818+++ b/drivers/char/Kconfig
33819@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33820
33821 config DEVKMEM
33822 bool "/dev/kmem virtual device support"
33823- default y
33824+ default n
33825+ depends on !GRKERNSEC_KMEM
33826 help
33827 Say Y here if you want to support the /dev/kmem device. The
33828 /dev/kmem device is rarely used, but can be used for certain
33829@@ -582,6 +583,7 @@ config DEVPORT
33830 bool
33831 depends on !M68K
33832 depends on ISA || PCI
33833+ depends on !GRKERNSEC_KMEM
33834 default y
33835
33836 source "drivers/s390/char/Kconfig"
33837diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
33838index a48e05b..6bac831 100644
33839--- a/drivers/char/agp/compat_ioctl.c
33840+++ b/drivers/char/agp/compat_ioctl.c
33841@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
33842 return -ENOMEM;
33843 }
33844
33845- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
33846+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
33847 sizeof(*usegment) * ureserve.seg_count)) {
33848 kfree(usegment);
33849 kfree(ksegment);
33850diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33851index 2e04433..771f2cc 100644
33852--- a/drivers/char/agp/frontend.c
33853+++ b/drivers/char/agp/frontend.c
33854@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33855 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33856 return -EFAULT;
33857
33858- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33859+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33860 return -EFAULT;
33861
33862 client = agp_find_client_by_pid(reserve.pid);
33863@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33864 if (segment == NULL)
33865 return -ENOMEM;
33866
33867- if (copy_from_user(segment, (void __user *) reserve.seg_list,
33868+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
33869 sizeof(struct agp_segment) * reserve.seg_count)) {
33870 kfree(segment);
33871 return -EFAULT;
33872diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33873index 4f94375..413694e 100644
33874--- a/drivers/char/genrtc.c
33875+++ b/drivers/char/genrtc.c
33876@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
33877 switch (cmd) {
33878
33879 case RTC_PLL_GET:
33880+ memset(&pll, 0, sizeof(pll));
33881 if (get_rtc_pll(&pll))
33882 return -EINVAL;
33883 else
33884diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33885index d784650..e8bfd69 100644
33886--- a/drivers/char/hpet.c
33887+++ b/drivers/char/hpet.c
33888@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33889 }
33890
33891 static int
33892-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33893+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33894 struct hpet_info *info)
33895 {
33896 struct hpet_timer __iomem *timer;
33897diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
33898index 86fe45c..c0ea948 100644
33899--- a/drivers/char/hw_random/intel-rng.c
33900+++ b/drivers/char/hw_random/intel-rng.c
33901@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
33902
33903 if (no_fwh_detect)
33904 return -ENODEV;
33905- printk(warning);
33906+ printk("%s", warning);
33907 return -EBUSY;
33908 }
33909
33910diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33911index 4445fa1..7c6de37 100644
33912--- a/drivers/char/ipmi/ipmi_msghandler.c
33913+++ b/drivers/char/ipmi/ipmi_msghandler.c
33914@@ -420,7 +420,7 @@ struct ipmi_smi {
33915 struct proc_dir_entry *proc_dir;
33916 char proc_dir_name[10];
33917
33918- atomic_t stats[IPMI_NUM_STATS];
33919+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33920
33921 /*
33922 * run_to_completion duplicate of smb_info, smi_info
33923@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33924
33925
33926 #define ipmi_inc_stat(intf, stat) \
33927- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33928+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33929 #define ipmi_get_stat(intf, stat) \
33930- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33931+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33932
33933 static int is_lan_addr(struct ipmi_addr *addr)
33934 {
33935@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33936 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33937 init_waitqueue_head(&intf->waitq);
33938 for (i = 0; i < IPMI_NUM_STATS; i++)
33939- atomic_set(&intf->stats[i], 0);
33940+ atomic_set_unchecked(&intf->stats[i], 0);
33941
33942 intf->proc_dir = NULL;
33943
33944diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33945index af4b23f..79806fc 100644
33946--- a/drivers/char/ipmi/ipmi_si_intf.c
33947+++ b/drivers/char/ipmi/ipmi_si_intf.c
33948@@ -275,7 +275,7 @@ struct smi_info {
33949 unsigned char slave_addr;
33950
33951 /* Counters and things for the proc filesystem. */
33952- atomic_t stats[SI_NUM_STATS];
33953+ atomic_unchecked_t stats[SI_NUM_STATS];
33954
33955 struct task_struct *thread;
33956
33957@@ -284,9 +284,9 @@ struct smi_info {
33958 };
33959
33960 #define smi_inc_stat(smi, stat) \
33961- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33962+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33963 #define smi_get_stat(smi, stat) \
33964- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33965+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33966
33967 #define SI_MAX_PARMS 4
33968
33969@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
33970 atomic_set(&new_smi->req_events, 0);
33971 new_smi->run_to_completion = 0;
33972 for (i = 0; i < SI_NUM_STATS; i++)
33973- atomic_set(&new_smi->stats[i], 0);
33974+ atomic_set_unchecked(&new_smi->stats[i], 0);
33975
33976 new_smi->interrupt_disabled = 1;
33977 atomic_set(&new_smi->stop_operation, 0);
33978diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33979index 1ccbe94..6ad651a 100644
33980--- a/drivers/char/mem.c
33981+++ b/drivers/char/mem.c
33982@@ -18,6 +18,7 @@
33983 #include <linux/raw.h>
33984 #include <linux/tty.h>
33985 #include <linux/capability.h>
33986+#include <linux/security.h>
33987 #include <linux/ptrace.h>
33988 #include <linux/device.h>
33989 #include <linux/highmem.h>
33990@@ -38,6 +39,10 @@
33991
33992 #define DEVPORT_MINOR 4
33993
33994+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33995+extern const struct file_operations grsec_fops;
33996+#endif
33997+
33998 static inline unsigned long size_inside_page(unsigned long start,
33999 unsigned long size)
34000 {
34001@@ -69,9 +74,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34002
34003 while (cursor < to) {
34004 if (!devmem_is_allowed(pfn)) {
34005+#ifdef CONFIG_GRKERNSEC_KMEM
34006+ gr_handle_mem_readwrite(from, to);
34007+#else
34008 printk(KERN_INFO
34009 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
34010 current->comm, from, to);
34011+#endif
34012 return 0;
34013 }
34014 cursor += PAGE_SIZE;
34015@@ -79,6 +88,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34016 }
34017 return 1;
34018 }
34019+#elif defined(CONFIG_GRKERNSEC_KMEM)
34020+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34021+{
34022+ return 0;
34023+}
34024 #else
34025 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34026 {
34027@@ -121,6 +135,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34028
34029 while (count > 0) {
34030 unsigned long remaining;
34031+ char *temp;
34032
34033 sz = size_inside_page(p, count);
34034
34035@@ -136,7 +151,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
34036 if (!ptr)
34037 return -EFAULT;
34038
34039- remaining = copy_to_user(buf, ptr, sz);
34040+#ifdef CONFIG_PAX_USERCOPY
34041+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34042+ if (!temp) {
34043+ unxlate_dev_mem_ptr(p, ptr);
34044+ return -ENOMEM;
34045+ }
34046+ memcpy(temp, ptr, sz);
34047+#else
34048+ temp = ptr;
34049+#endif
34050+
34051+ remaining = copy_to_user(buf, temp, sz);
34052+
34053+#ifdef CONFIG_PAX_USERCOPY
34054+ kfree(temp);
34055+#endif
34056+
34057 unxlate_dev_mem_ptr(p, ptr);
34058 if (remaining)
34059 return -EFAULT;
34060@@ -379,7 +410,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
34061 else
34062 csize = count;
34063
34064- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
34065+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
34066 if (rc < 0)
34067 return rc;
34068 buf += csize;
34069@@ -399,9 +430,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34070 size_t count, loff_t *ppos)
34071 {
34072 unsigned long p = *ppos;
34073- ssize_t low_count, read, sz;
34074+ ssize_t low_count, read, sz, err = 0;
34075 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34076- int err = 0;
34077
34078 read = 0;
34079 if (p < (unsigned long) high_memory) {
34080@@ -423,6 +453,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34081 }
34082 #endif
34083 while (low_count > 0) {
34084+ char *temp;
34085+
34086 sz = size_inside_page(p, low_count);
34087
34088 /*
34089@@ -432,7 +464,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34090 */
34091 kbuf = xlate_dev_kmem_ptr((char *)p);
34092
34093- if (copy_to_user(buf, kbuf, sz))
34094+#ifdef CONFIG_PAX_USERCOPY
34095+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34096+ if (!temp)
34097+ return -ENOMEM;
34098+ memcpy(temp, kbuf, sz);
34099+#else
34100+ temp = kbuf;
34101+#endif
34102+
34103+ err = copy_to_user(buf, temp, sz);
34104+
34105+#ifdef CONFIG_PAX_USERCOPY
34106+ kfree(temp);
34107+#endif
34108+
34109+ if (err)
34110 return -EFAULT;
34111 buf += sz;
34112 p += sz;
34113@@ -869,6 +916,9 @@ static const struct memdev {
34114 #ifdef CONFIG_CRASH_DUMP
34115 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34116 #endif
34117+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34118+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34119+#endif
34120 };
34121
34122 static int memory_open(struct inode *inode, struct file *filp)
34123@@ -940,7 +990,7 @@ static int __init chr_dev_init(void)
34124 continue;
34125
34126 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
34127- NULL, devlist[minor].name);
34128+ NULL, "%s", devlist[minor].name);
34129 }
34130
34131 return tty_init();
34132diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
34133index c689697..04e6d6a2 100644
34134--- a/drivers/char/mwave/tp3780i.c
34135+++ b/drivers/char/mwave/tp3780i.c
34136@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
34137 PRINTK_2(TRACE_TP3780I,
34138 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
34139
34140+ memset(pAbilities, 0, sizeof(*pAbilities));
34141 /* fill out standard constant fields */
34142 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
34143 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
34144diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34145index 9df78e2..01ba9ae 100644
34146--- a/drivers/char/nvram.c
34147+++ b/drivers/char/nvram.c
34148@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34149
34150 spin_unlock_irq(&rtc_lock);
34151
34152- if (copy_to_user(buf, contents, tmp - contents))
34153+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34154 return -EFAULT;
34155
34156 *ppos = i;
34157diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34158index 5c5cc00..ac9edb7 100644
34159--- a/drivers/char/pcmcia/synclink_cs.c
34160+++ b/drivers/char/pcmcia/synclink_cs.c
34161@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34162
34163 if (debug_level >= DEBUG_LEVEL_INFO)
34164 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34165- __FILE__, __LINE__, info->device_name, port->count);
34166+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
34167
34168- WARN_ON(!port->count);
34169+ WARN_ON(!atomic_read(&port->count));
34170
34171 if (tty_port_close_start(port, tty, filp) == 0)
34172 goto cleanup;
34173@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34174 cleanup:
34175 if (debug_level >= DEBUG_LEVEL_INFO)
34176 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
34177- tty->driver->name, port->count);
34178+ tty->driver->name, atomic_read(&port->count));
34179 }
34180
34181 /* Wait until the transmitter is empty.
34182@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34183
34184 if (debug_level >= DEBUG_LEVEL_INFO)
34185 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34186- __FILE__, __LINE__, tty->driver->name, port->count);
34187+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
34188
34189 /* If port is closing, signal caller to try again */
34190 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34191@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34192 goto cleanup;
34193 }
34194 spin_lock(&port->lock);
34195- port->count++;
34196+ atomic_inc(&port->count);
34197 spin_unlock(&port->lock);
34198 spin_unlock_irqrestore(&info->netlock, flags);
34199
34200- if (port->count == 1) {
34201+ if (atomic_read(&port->count) == 1) {
34202 /* 1st open on this device, init hardware */
34203 retval = startup(info, tty);
34204 if (retval < 0)
34205@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34206 unsigned short new_crctype;
34207
34208 /* return error if TTY interface open */
34209- if (info->port.count)
34210+ if (atomic_read(&info->port.count))
34211 return -EBUSY;
34212
34213 switch (encoding)
34214@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
34215
34216 /* arbitrate between network and tty opens */
34217 spin_lock_irqsave(&info->netlock, flags);
34218- if (info->port.count != 0 || info->netcount != 0) {
34219+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34220 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34221 spin_unlock_irqrestore(&info->netlock, flags);
34222 return -EBUSY;
34223@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34224 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
34225
34226 /* return error if TTY interface open */
34227- if (info->port.count)
34228+ if (atomic_read(&info->port.count))
34229 return -EBUSY;
34230
34231 if (cmd != SIOCWANDEV)
34232diff --git a/drivers/char/random.c b/drivers/char/random.c
34233index 35487e8..dac8bd1 100644
34234--- a/drivers/char/random.c
34235+++ b/drivers/char/random.c
34236@@ -272,8 +272,13 @@
34237 /*
34238 * Configuration information
34239 */
34240+#ifdef CONFIG_GRKERNSEC_RANDNET
34241+#define INPUT_POOL_WORDS 512
34242+#define OUTPUT_POOL_WORDS 128
34243+#else
34244 #define INPUT_POOL_WORDS 128
34245 #define OUTPUT_POOL_WORDS 32
34246+#endif
34247 #define SEC_XFER_SIZE 512
34248 #define EXTRACT_SIZE 10
34249
34250@@ -313,10 +318,17 @@ static struct poolinfo {
34251 int poolwords;
34252 int tap1, tap2, tap3, tap4, tap5;
34253 } poolinfo_table[] = {
34254+#ifdef CONFIG_GRKERNSEC_RANDNET
34255+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34256+ { 512, 411, 308, 208, 104, 1 },
34257+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34258+ { 128, 103, 76, 51, 25, 1 },
34259+#else
34260 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34261 { 128, 103, 76, 51, 25, 1 },
34262 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34263 { 32, 26, 20, 14, 7, 1 },
34264+#endif
34265 #if 0
34266 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34267 { 2048, 1638, 1231, 819, 411, 1 },
34268@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34269 input_rotate += i ? 7 : 14;
34270 }
34271
34272- ACCESS_ONCE(r->input_rotate) = input_rotate;
34273- ACCESS_ONCE(r->add_ptr) = i;
34274+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34275+ ACCESS_ONCE_RW(r->add_ptr) = i;
34276 smp_wmb();
34277
34278 if (out)
34279@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34280
34281 extract_buf(r, tmp);
34282 i = min_t(int, nbytes, EXTRACT_SIZE);
34283- if (copy_to_user(buf, tmp, i)) {
34284+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34285 ret = -EFAULT;
34286 break;
34287 }
34288@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34289 #include <linux/sysctl.h>
34290
34291 static int min_read_thresh = 8, min_write_thresh;
34292-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34293+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34294 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34295 static char sysctl_bootid[16];
34296
34297@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
34298 static int proc_do_uuid(ctl_table *table, int write,
34299 void __user *buffer, size_t *lenp, loff_t *ppos)
34300 {
34301- ctl_table fake_table;
34302+ ctl_table_no_const fake_table;
34303 unsigned char buf[64], tmp_uuid[16], *uuid;
34304
34305 uuid = table->data;
34306diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34307index bf2349db..5456d53 100644
34308--- a/drivers/char/sonypi.c
34309+++ b/drivers/char/sonypi.c
34310@@ -54,6 +54,7 @@
34311
34312 #include <asm/uaccess.h>
34313 #include <asm/io.h>
34314+#include <asm/local.h>
34315
34316 #include <linux/sonypi.h>
34317
34318@@ -490,7 +491,7 @@ static struct sonypi_device {
34319 spinlock_t fifo_lock;
34320 wait_queue_head_t fifo_proc_list;
34321 struct fasync_struct *fifo_async;
34322- int open_count;
34323+ local_t open_count;
34324 int model;
34325 struct input_dev *input_jog_dev;
34326 struct input_dev *input_key_dev;
34327@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34328 static int sonypi_misc_release(struct inode *inode, struct file *file)
34329 {
34330 mutex_lock(&sonypi_device.lock);
34331- sonypi_device.open_count--;
34332+ local_dec(&sonypi_device.open_count);
34333 mutex_unlock(&sonypi_device.lock);
34334 return 0;
34335 }
34336@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34337 {
34338 mutex_lock(&sonypi_device.lock);
34339 /* Flush input queue on first open */
34340- if (!sonypi_device.open_count)
34341+ if (!local_read(&sonypi_device.open_count))
34342 kfifo_reset(&sonypi_device.fifo);
34343- sonypi_device.open_count++;
34344+ local_inc(&sonypi_device.open_count);
34345 mutex_unlock(&sonypi_device.lock);
34346
34347 return 0;
34348diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34349index 64420b3..5c40b56 100644
34350--- a/drivers/char/tpm/tpm_acpi.c
34351+++ b/drivers/char/tpm/tpm_acpi.c
34352@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34353 virt = acpi_os_map_memory(start, len);
34354 if (!virt) {
34355 kfree(log->bios_event_log);
34356+ log->bios_event_log = NULL;
34357 printk("%s: ERROR - Unable to map memory\n", __func__);
34358 return -EIO;
34359 }
34360
34361- memcpy_fromio(log->bios_event_log, virt, len);
34362+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34363
34364 acpi_os_unmap_memory(virt, len);
34365 return 0;
34366diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34367index 84ddc55..1d32f1e 100644
34368--- a/drivers/char/tpm/tpm_eventlog.c
34369+++ b/drivers/char/tpm/tpm_eventlog.c
34370@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34371 event = addr;
34372
34373 if ((event->event_type == 0 && event->event_size == 0) ||
34374- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34375+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34376 return NULL;
34377
34378 return addr;
34379@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34380 return NULL;
34381
34382 if ((event->event_type == 0 && event->event_size == 0) ||
34383- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34384+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34385 return NULL;
34386
34387 (*pos)++;
34388@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34389 int i;
34390
34391 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34392- seq_putc(m, data[i]);
34393+ if (!seq_putc(m, data[i]))
34394+ return -EFAULT;
34395
34396 return 0;
34397 }
34398diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34399index 1b456fe..2510242 100644
34400--- a/drivers/char/virtio_console.c
34401+++ b/drivers/char/virtio_console.c
34402@@ -679,7 +679,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34403 if (to_user) {
34404 ssize_t ret;
34405
34406- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34407+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34408 if (ret)
34409 return -EFAULT;
34410 } else {
34411@@ -778,7 +778,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34412 if (!port_has_data(port) && !port->host_connected)
34413 return 0;
34414
34415- return fill_readbuf(port, ubuf, count, true);
34416+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34417 }
34418
34419 static int wait_port_writable(struct port *port, bool nonblock)
34420diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
34421index a33f46f..a720eed 100644
34422--- a/drivers/clk/clk-composite.c
34423+++ b/drivers/clk/clk-composite.c
34424@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
34425 struct clk *clk;
34426 struct clk_init_data init;
34427 struct clk_composite *composite;
34428- struct clk_ops *clk_composite_ops;
34429+ clk_ops_no_const *clk_composite_ops;
34430
34431 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
34432 if (!composite) {
34433diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
34434index bd11315..2f14eae 100644
34435--- a/drivers/clk/socfpga/clk.c
34436+++ b/drivers/clk/socfpga/clk.c
34437@@ -135,8 +135,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
34438 if (strcmp(clk_name, "main_pll") || strcmp(clk_name, "periph_pll") ||
34439 strcmp(clk_name, "sdram_pll")) {
34440 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
34441- clk_pll_ops.enable = clk_gate_ops.enable;
34442- clk_pll_ops.disable = clk_gate_ops.disable;
34443+ pax_open_kernel();
34444+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
34445+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
34446+ pax_close_kernel();
34447 }
34448
34449 clk = clk_register(NULL, &socfpga_clk->hw.hw);
34450diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
34451index a2b2541..bc1e7ff 100644
34452--- a/drivers/clocksource/arm_arch_timer.c
34453+++ b/drivers/clocksource/arm_arch_timer.c
34454@@ -264,7 +264,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34455 return NOTIFY_OK;
34456 }
34457
34458-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
34459+static struct notifier_block arch_timer_cpu_nb = {
34460 .notifier_call = arch_timer_cpu_notify,
34461 };
34462
34463diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
34464index ade7513..069445f 100644
34465--- a/drivers/clocksource/metag_generic.c
34466+++ b/drivers/clocksource/metag_generic.c
34467@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34468 return NOTIFY_OK;
34469 }
34470
34471-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34472+static struct notifier_block arch_timer_cpu_nb = {
34473 .notifier_call = arch_timer_cpu_notify,
34474 };
34475
34476diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34477index edc089e..bc7c0bc 100644
34478--- a/drivers/cpufreq/acpi-cpufreq.c
34479+++ b/drivers/cpufreq/acpi-cpufreq.c
34480@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34481 return sprintf(buf, "%u\n", boost_enabled);
34482 }
34483
34484-static struct global_attr global_boost = __ATTR(boost, 0644,
34485+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34486 show_global_boost,
34487 store_global_boost);
34488
34489@@ -705,8 +705,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34490 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34491 per_cpu(acfreq_data, cpu) = data;
34492
34493- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34494- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34495+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34496+ pax_open_kernel();
34497+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34498+ pax_close_kernel();
34499+ }
34500
34501 result = acpi_processor_register_performance(data->acpi_data, cpu);
34502 if (result)
34503@@ -832,7 +835,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34504 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34505 break;
34506 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34507- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34508+ pax_open_kernel();
34509+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34510+ pax_close_kernel();
34511 policy->cur = get_cur_freq_on_cpu(cpu);
34512 break;
34513 default:
34514@@ -843,8 +848,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34515 acpi_processor_notify_smm(THIS_MODULE);
34516
34517 /* Check for APERF/MPERF support in hardware */
34518- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34519- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34520+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34521+ pax_open_kernel();
34522+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34523+ pax_close_kernel();
34524+ }
34525
34526 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34527 for (i = 0; i < perf->state_count; i++)
34528diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34529index 2d53f47..eb3803e 100644
34530--- a/drivers/cpufreq/cpufreq.c
34531+++ b/drivers/cpufreq/cpufreq.c
34532@@ -1851,7 +1851,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34533 return NOTIFY_OK;
34534 }
34535
34536-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34537+static struct notifier_block cpufreq_cpu_notifier = {
34538 .notifier_call = cpufreq_cpu_callback,
34539 };
34540
34541@@ -1883,8 +1883,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34542
34543 pr_debug("trying to register driver %s\n", driver_data->name);
34544
34545- if (driver_data->setpolicy)
34546- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34547+ if (driver_data->setpolicy) {
34548+ pax_open_kernel();
34549+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34550+ pax_close_kernel();
34551+ }
34552
34553 write_lock_irqsave(&cpufreq_driver_lock, flags);
34554 if (cpufreq_driver) {
34555diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34556index dc9b72e..11c0302 100644
34557--- a/drivers/cpufreq/cpufreq_governor.c
34558+++ b/drivers/cpufreq/cpufreq_governor.c
34559@@ -238,7 +238,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34560 struct dbs_data *dbs_data;
34561 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
34562 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
34563- struct od_ops *od_ops = NULL;
34564+ const struct od_ops *od_ops = NULL;
34565 struct od_dbs_tuners *od_tuners = NULL;
34566 struct cs_dbs_tuners *cs_tuners = NULL;
34567 struct cpu_dbs_common_info *cpu_cdbs;
34568@@ -301,7 +301,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34569
34570 if ((cdata->governor == GOV_CONSERVATIVE) &&
34571 (!policy->governor->initialized)) {
34572- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34573+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34574
34575 cpufreq_register_notifier(cs_ops->notifier_block,
34576 CPUFREQ_TRANSITION_NOTIFIER);
34577@@ -318,7 +318,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
34578
34579 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
34580 (policy->governor->initialized == 1)) {
34581- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34582+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
34583
34584 cpufreq_unregister_notifier(cs_ops->notifier_block,
34585 CPUFREQ_TRANSITION_NOTIFIER);
34586diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34587index e16a961..0e68927 100644
34588--- a/drivers/cpufreq/cpufreq_governor.h
34589+++ b/drivers/cpufreq/cpufreq_governor.h
34590@@ -204,7 +204,7 @@ struct common_dbs_data {
34591 void (*exit)(struct dbs_data *dbs_data);
34592
34593 /* Governor specific ops, see below */
34594- void *gov_ops;
34595+ const void *gov_ops;
34596 };
34597
34598 /* Governer Per policy data */
34599diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
34600index 93eb5cb..f8ab572 100644
34601--- a/drivers/cpufreq/cpufreq_ondemand.c
34602+++ b/drivers/cpufreq/cpufreq_ondemand.c
34603@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
34604 (struct cpufreq_policy *, unsigned int, unsigned int),
34605 unsigned int powersave_bias)
34606 {
34607- od_ops.powersave_bias_target = f;
34608+ pax_open_kernel();
34609+ *(void **)&od_ops.powersave_bias_target = f;
34610+ pax_close_kernel();
34611 od_set_powersave_bias(powersave_bias);
34612 }
34613 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
34614
34615 void od_unregister_powersave_bias_handler(void)
34616 {
34617- od_ops.powersave_bias_target = generic_powersave_bias_target;
34618+ pax_open_kernel();
34619+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
34620+ pax_close_kernel();
34621 od_set_powersave_bias(0);
34622 }
34623 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
34624diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34625index 591b6fb..2a01183 100644
34626--- a/drivers/cpufreq/cpufreq_stats.c
34627+++ b/drivers/cpufreq/cpufreq_stats.c
34628@@ -367,7 +367,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34629 }
34630
34631 /* priority=1 so this will get called before cpufreq_remove_dev */
34632-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34633+static struct notifier_block cpufreq_stat_cpu_notifier = {
34634 .notifier_call = cpufreq_stat_cpu_callback,
34635 .priority = 1,
34636 };
34637diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34638index 421ef37..e708530c 100644
34639--- a/drivers/cpufreq/p4-clockmod.c
34640+++ b/drivers/cpufreq/p4-clockmod.c
34641@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34642 case 0x0F: /* Core Duo */
34643 case 0x16: /* Celeron Core */
34644 case 0x1C: /* Atom */
34645- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34646+ pax_open_kernel();
34647+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34648+ pax_close_kernel();
34649 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34650 case 0x0D: /* Pentium M (Dothan) */
34651- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34652+ pax_open_kernel();
34653+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34654+ pax_close_kernel();
34655 /* fall through */
34656 case 0x09: /* Pentium M (Banias) */
34657 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34658@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34659
34660 /* on P-4s, the TSC runs with constant frequency independent whether
34661 * throttling is active or not. */
34662- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34663+ pax_open_kernel();
34664+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34665+ pax_close_kernel();
34666
34667 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34668 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34669diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
34670index c71ee14..7c2e183 100644
34671--- a/drivers/cpufreq/sparc-us3-cpufreq.c
34672+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
34673@@ -18,14 +18,12 @@
34674 #include <asm/head.h>
34675 #include <asm/timer.h>
34676
34677-static struct cpufreq_driver *cpufreq_us3_driver;
34678-
34679 struct us3_freq_percpu_info {
34680 struct cpufreq_frequency_table table[4];
34681 };
34682
34683 /* Indexed by cpu number. */
34684-static struct us3_freq_percpu_info *us3_freq_table;
34685+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
34686
34687 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
34688 * in the Safari config register.
34689@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
34690
34691 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
34692 {
34693- if (cpufreq_us3_driver)
34694- us3_set_cpu_divider_index(policy, 0);
34695+ us3_set_cpu_divider_index(policy->cpu, 0);
34696
34697 return 0;
34698 }
34699
34700+static int __init us3_freq_init(void);
34701+static void __exit us3_freq_exit(void);
34702+
34703+static struct cpufreq_driver cpufreq_us3_driver = {
34704+ .init = us3_freq_cpu_init,
34705+ .verify = us3_freq_verify,
34706+ .target = us3_freq_target,
34707+ .get = us3_freq_get,
34708+ .exit = us3_freq_cpu_exit,
34709+ .owner = THIS_MODULE,
34710+ .name = "UltraSPARC-III",
34711+
34712+};
34713+
34714 static int __init us3_freq_init(void)
34715 {
34716 unsigned long manuf, impl, ver;
34717@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
34718 (impl == CHEETAH_IMPL ||
34719 impl == CHEETAH_PLUS_IMPL ||
34720 impl == JAGUAR_IMPL ||
34721- impl == PANTHER_IMPL)) {
34722- struct cpufreq_driver *driver;
34723-
34724- ret = -ENOMEM;
34725- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
34726- if (!driver)
34727- goto err_out;
34728-
34729- us3_freq_table = kzalloc(
34730- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
34731- GFP_KERNEL);
34732- if (!us3_freq_table)
34733- goto err_out;
34734-
34735- driver->init = us3_freq_cpu_init;
34736- driver->verify = us3_freq_verify;
34737- driver->target = us3_freq_target;
34738- driver->get = us3_freq_get;
34739- driver->exit = us3_freq_cpu_exit;
34740- driver->owner = THIS_MODULE,
34741- strcpy(driver->name, "UltraSPARC-III");
34742-
34743- cpufreq_us3_driver = driver;
34744- ret = cpufreq_register_driver(driver);
34745- if (ret)
34746- goto err_out;
34747-
34748- return 0;
34749-
34750-err_out:
34751- if (driver) {
34752- kfree(driver);
34753- cpufreq_us3_driver = NULL;
34754- }
34755- kfree(us3_freq_table);
34756- us3_freq_table = NULL;
34757- return ret;
34758- }
34759+ impl == PANTHER_IMPL))
34760+ return cpufreq_register_driver(&cpufreq_us3_driver);
34761
34762 return -ENODEV;
34763 }
34764
34765 static void __exit us3_freq_exit(void)
34766 {
34767- if (cpufreq_us3_driver) {
34768- cpufreq_unregister_driver(cpufreq_us3_driver);
34769- kfree(cpufreq_us3_driver);
34770- cpufreq_us3_driver = NULL;
34771- kfree(us3_freq_table);
34772- us3_freq_table = NULL;
34773- }
34774+ cpufreq_unregister_driver(&cpufreq_us3_driver);
34775 }
34776
34777 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
34778diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34779index 618e6f4..e89d915 100644
34780--- a/drivers/cpufreq/speedstep-centrino.c
34781+++ b/drivers/cpufreq/speedstep-centrino.c
34782@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34783 !cpu_has(cpu, X86_FEATURE_EST))
34784 return -ENODEV;
34785
34786- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34787- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34788+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34789+ pax_open_kernel();
34790+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34791+ pax_close_kernel();
34792+ }
34793
34794 if (policy->cpu != 0)
34795 return -ENODEV;
34796diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34797index c3a93fe..e808f24 100644
34798--- a/drivers/cpuidle/cpuidle.c
34799+++ b/drivers/cpuidle/cpuidle.c
34800@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
34801
34802 static void poll_idle_init(struct cpuidle_driver *drv)
34803 {
34804- struct cpuidle_state *state = &drv->states[0];
34805+ cpuidle_state_no_const *state = &drv->states[0];
34806
34807 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34808 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34809diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34810index ea2f8e7..70ac501 100644
34811--- a/drivers/cpuidle/governor.c
34812+++ b/drivers/cpuidle/governor.c
34813@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34814 mutex_lock(&cpuidle_lock);
34815 if (__cpuidle_find_governor(gov->name) == NULL) {
34816 ret = 0;
34817- list_add_tail(&gov->governor_list, &cpuidle_governors);
34818+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34819 if (!cpuidle_curr_governor ||
34820 cpuidle_curr_governor->rating < gov->rating)
34821 cpuidle_switch_governor(gov);
34822@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34823 new_gov = cpuidle_replace_governor(gov->rating);
34824 cpuidle_switch_governor(new_gov);
34825 }
34826- list_del(&gov->governor_list);
34827+ pax_list_del((struct list_head *)&gov->governor_list);
34828 mutex_unlock(&cpuidle_lock);
34829 }
34830
34831diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34832index 428754a..8bdf9cc 100644
34833--- a/drivers/cpuidle/sysfs.c
34834+++ b/drivers/cpuidle/sysfs.c
34835@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34836 NULL
34837 };
34838
34839-static struct attribute_group cpuidle_attr_group = {
34840+static attribute_group_no_const cpuidle_attr_group = {
34841 .attrs = cpuidle_default_attrs,
34842 .name = "cpuidle",
34843 };
34844diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34845index 3b36797..db0b0c0 100644
34846--- a/drivers/devfreq/devfreq.c
34847+++ b/drivers/devfreq/devfreq.c
34848@@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
34849 GFP_KERNEL);
34850 devfreq->last_stat_updated = jiffies;
34851
34852- dev_set_name(&devfreq->dev, dev_name(dev));
34853+ dev_set_name(&devfreq->dev, "%s", dev_name(dev));
34854 err = device_register(&devfreq->dev);
34855 if (err) {
34856 put_device(&devfreq->dev);
34857@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34858 goto err_out;
34859 }
34860
34861- list_add(&governor->node, &devfreq_governor_list);
34862+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34863
34864 list_for_each_entry(devfreq, &devfreq_list, node) {
34865 int ret = 0;
34866@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34867 }
34868 }
34869
34870- list_del(&governor->node);
34871+ pax_list_del((struct list_head *)&governor->node);
34872 err_out:
34873 mutex_unlock(&devfreq_list_lock);
34874
34875diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34876index b70709b..1d8d02a 100644
34877--- a/drivers/dma/sh/shdma.c
34878+++ b/drivers/dma/sh/shdma.c
34879@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34880 return ret;
34881 }
34882
34883-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34884+static struct notifier_block sh_dmae_nmi_notifier = {
34885 .notifier_call = sh_dmae_nmi_handler,
34886
34887 /* Run before NMI debug handler and KGDB */
34888diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34889index 67610a6..30f8a11 100644
34890--- a/drivers/edac/edac_mc_sysfs.c
34891+++ b/drivers/edac/edac_mc_sysfs.c
34892@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
34893 struct dev_ch_attribute {
34894 struct device_attribute attr;
34895 int channel;
34896-};
34897+} __do_const;
34898
34899 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34900 struct dev_ch_attribute dev_attr_legacy_##_name = \
34901@@ -1003,14 +1003,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
34902 }
34903
34904 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
34905+ pax_open_kernel();
34906 if (mci->get_sdram_scrub_rate) {
34907- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34908- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34909+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34910+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34911 }
34912 if (mci->set_sdram_scrub_rate) {
34913- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34914- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34915+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34916+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34917 }
34918+ pax_close_kernel();
34919 err = device_create_file(&mci->dev,
34920 &dev_attr_sdram_scrub_rate);
34921 if (err) {
34922diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34923index e8658e4..22746d6 100644
34924--- a/drivers/edac/edac_pci_sysfs.c
34925+++ b/drivers/edac/edac_pci_sysfs.c
34926@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34927 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34928 static int edac_pci_poll_msec = 1000; /* one second workq period */
34929
34930-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34931-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34932+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34933+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34934
34935 static struct kobject *edac_pci_top_main_kobj;
34936 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34937@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34938 void *value;
34939 ssize_t(*show) (void *, char *);
34940 ssize_t(*store) (void *, const char *, size_t);
34941-};
34942+} __do_const;
34943
34944 /* Set of show/store abstract level functions for PCI Parity object */
34945 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34946@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34947 edac_printk(KERN_CRIT, EDAC_PCI,
34948 "Signaled System Error on %s\n",
34949 pci_name(dev));
34950- atomic_inc(&pci_nonparity_count);
34951+ atomic_inc_unchecked(&pci_nonparity_count);
34952 }
34953
34954 if (status & (PCI_STATUS_PARITY)) {
34955@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34956 "Master Data Parity Error on %s\n",
34957 pci_name(dev));
34958
34959- atomic_inc(&pci_parity_count);
34960+ atomic_inc_unchecked(&pci_parity_count);
34961 }
34962
34963 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34964@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34965 "Detected Parity Error on %s\n",
34966 pci_name(dev));
34967
34968- atomic_inc(&pci_parity_count);
34969+ atomic_inc_unchecked(&pci_parity_count);
34970 }
34971 }
34972
34973@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34974 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34975 "Signaled System Error on %s\n",
34976 pci_name(dev));
34977- atomic_inc(&pci_nonparity_count);
34978+ atomic_inc_unchecked(&pci_nonparity_count);
34979 }
34980
34981 if (status & (PCI_STATUS_PARITY)) {
34982@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34983 "Master Data Parity Error on "
34984 "%s\n", pci_name(dev));
34985
34986- atomic_inc(&pci_parity_count);
34987+ atomic_inc_unchecked(&pci_parity_count);
34988 }
34989
34990 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34991@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34992 "Detected Parity Error on %s\n",
34993 pci_name(dev));
34994
34995- atomic_inc(&pci_parity_count);
34996+ atomic_inc_unchecked(&pci_parity_count);
34997 }
34998 }
34999 }
35000@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
35001 if (!check_pci_errors)
35002 return;
35003
35004- before_count = atomic_read(&pci_parity_count);
35005+ before_count = atomic_read_unchecked(&pci_parity_count);
35006
35007 /* scan all PCI devices looking for a Parity Error on devices and
35008 * bridges.
35009@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
35010 /* Only if operator has selected panic on PCI Error */
35011 if (edac_pci_get_panic_on_pe()) {
35012 /* If the count is different 'after' from 'before' */
35013- if (before_count != atomic_read(&pci_parity_count))
35014+ if (before_count != atomic_read_unchecked(&pci_parity_count))
35015 panic("EDAC: PCI Parity Error");
35016 }
35017 }
35018diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
35019index 51b7e3a..aa8a3e8 100644
35020--- a/drivers/edac/mce_amd.h
35021+++ b/drivers/edac/mce_amd.h
35022@@ -77,7 +77,7 @@ struct amd_decoder_ops {
35023 bool (*mc0_mce)(u16, u8);
35024 bool (*mc1_mce)(u16, u8);
35025 bool (*mc2_mce)(u16, u8);
35026-};
35027+} __no_const;
35028
35029 void amd_report_gart_errors(bool);
35030 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
35031diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
35032index 57ea7f4..789e3c3 100644
35033--- a/drivers/firewire/core-card.c
35034+++ b/drivers/firewire/core-card.c
35035@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
35036
35037 void fw_core_remove_card(struct fw_card *card)
35038 {
35039- struct fw_card_driver dummy_driver = dummy_driver_template;
35040+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
35041
35042 card->driver->update_phy_reg(card, 4,
35043 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
35044diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
35045index 664a6ff..af13580 100644
35046--- a/drivers/firewire/core-device.c
35047+++ b/drivers/firewire/core-device.c
35048@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
35049 struct config_rom_attribute {
35050 struct device_attribute attr;
35051 u32 key;
35052-};
35053+} __do_const;
35054
35055 static ssize_t show_immediate(struct device *dev,
35056 struct device_attribute *dattr, char *buf)
35057diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
35058index 28a94c7..58da63a 100644
35059--- a/drivers/firewire/core-transaction.c
35060+++ b/drivers/firewire/core-transaction.c
35061@@ -38,6 +38,7 @@
35062 #include <linux/timer.h>
35063 #include <linux/types.h>
35064 #include <linux/workqueue.h>
35065+#include <linux/sched.h>
35066
35067 #include <asm/byteorder.h>
35068
35069diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
35070index 515a42c..5ecf3ba 100644
35071--- a/drivers/firewire/core.h
35072+++ b/drivers/firewire/core.h
35073@@ -111,6 +111,7 @@ struct fw_card_driver {
35074
35075 int (*stop_iso)(struct fw_iso_context *ctx);
35076 };
35077+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
35078
35079 void fw_card_initialize(struct fw_card *card,
35080 const struct fw_card_driver *driver, struct device *device);
35081diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
35082index 94a58a0..f5eba42 100644
35083--- a/drivers/firmware/dmi-id.c
35084+++ b/drivers/firmware/dmi-id.c
35085@@ -16,7 +16,7 @@
35086 struct dmi_device_attribute{
35087 struct device_attribute dev_attr;
35088 int field;
35089-};
35090+} __do_const;
35091 #define to_dmi_dev_attr(_dev_attr) \
35092 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
35093
35094diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
35095index b95159b..841ae55 100644
35096--- a/drivers/firmware/dmi_scan.c
35097+++ b/drivers/firmware/dmi_scan.c
35098@@ -497,11 +497,6 @@ void __init dmi_scan_machine(void)
35099 }
35100 }
35101 else {
35102- /*
35103- * no iounmap() for that ioremap(); it would be a no-op, but
35104- * it's so early in setup that sucker gets confused into doing
35105- * what it shouldn't if we actually call it.
35106- */
35107 p = dmi_ioremap(0xF0000, 0x10000);
35108 if (p == NULL)
35109 goto error;
35110@@ -786,7 +781,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
35111 if (buf == NULL)
35112 return -1;
35113
35114- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
35115+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
35116
35117 iounmap(buf);
35118 return 0;
35119diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
35120index 5145fa3..0d3babd 100644
35121--- a/drivers/firmware/efi/efi.c
35122+++ b/drivers/firmware/efi/efi.c
35123@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
35124 };
35125
35126 static struct efivars generic_efivars;
35127-static struct efivar_operations generic_ops;
35128+static efivar_operations_no_const generic_ops __read_only;
35129
35130 static int generic_ops_register(void)
35131 {
35132- generic_ops.get_variable = efi.get_variable;
35133- generic_ops.set_variable = efi.set_variable;
35134- generic_ops.get_next_variable = efi.get_next_variable;
35135- generic_ops.query_variable_store = efi_query_variable_store;
35136+ pax_open_kernel();
35137+ *(void **)&generic_ops.get_variable = efi.get_variable;
35138+ *(void **)&generic_ops.set_variable = efi.set_variable;
35139+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
35140+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
35141+ pax_close_kernel();
35142
35143 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
35144 }
35145diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
35146index 8bd1bb6..c48b0c6 100644
35147--- a/drivers/firmware/efi/efivars.c
35148+++ b/drivers/firmware/efi/efivars.c
35149@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
35150 static int
35151 create_efivars_bin_attributes(void)
35152 {
35153- struct bin_attribute *attr;
35154+ bin_attribute_no_const *attr;
35155 int error;
35156
35157 /* new_var */
35158diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
35159index 2a90ba6..07f3733 100644
35160--- a/drivers/firmware/google/memconsole.c
35161+++ b/drivers/firmware/google/memconsole.c
35162@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
35163 if (!found_memconsole())
35164 return -ENODEV;
35165
35166- memconsole_bin_attr.size = memconsole_length;
35167+ pax_open_kernel();
35168+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
35169+ pax_close_kernel();
35170
35171 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
35172
35173diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
35174index e16d932..f0206ef 100644
35175--- a/drivers/gpio/gpio-ich.c
35176+++ b/drivers/gpio/gpio-ich.c
35177@@ -69,7 +69,7 @@ struct ichx_desc {
35178 /* Some chipsets have quirks, let these use their own request/get */
35179 int (*request)(struct gpio_chip *chip, unsigned offset);
35180 int (*get)(struct gpio_chip *chip, unsigned offset);
35181-};
35182+} __do_const;
35183
35184 static struct {
35185 spinlock_t lock;
35186diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
35187index 9902732..64b62dd 100644
35188--- a/drivers/gpio/gpio-vr41xx.c
35189+++ b/drivers/gpio/gpio-vr41xx.c
35190@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
35191 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
35192 maskl, pendl, maskh, pendh);
35193
35194- atomic_inc(&irq_err_count);
35195+ atomic_inc_unchecked(&irq_err_count);
35196
35197 return -EINVAL;
35198 }
35199diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
35200index ed1334e..ee0dd42 100644
35201--- a/drivers/gpu/drm/drm_crtc_helper.c
35202+++ b/drivers/gpu/drm/drm_crtc_helper.c
35203@@ -321,7 +321,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
35204 struct drm_crtc *tmp;
35205 int crtc_mask = 1;
35206
35207- WARN(!crtc, "checking null crtc?\n");
35208+ BUG_ON(!crtc);
35209
35210 dev = crtc->dev;
35211
35212diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
35213index 9cc247f..36aa285 100644
35214--- a/drivers/gpu/drm/drm_drv.c
35215+++ b/drivers/gpu/drm/drm_drv.c
35216@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
35217 /**
35218 * Copy and IOCTL return string to user space
35219 */
35220-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
35221+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
35222 {
35223 int len;
35224
35225@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
35226 struct drm_file *file_priv = filp->private_data;
35227 struct drm_device *dev;
35228 const struct drm_ioctl_desc *ioctl = NULL;
35229- drm_ioctl_t *func;
35230+ drm_ioctl_no_const_t func;
35231 unsigned int nr = DRM_IOCTL_NR(cmd);
35232 int retcode = -EINVAL;
35233 char stack_kdata[128];
35234@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
35235 return -ENODEV;
35236
35237 atomic_inc(&dev->ioctl_count);
35238- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35239+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35240 ++file_priv->ioctl_count;
35241
35242 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
35243diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35244index 429e07d..e681a2c 100644
35245--- a/drivers/gpu/drm/drm_fops.c
35246+++ b/drivers/gpu/drm/drm_fops.c
35247@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35248 }
35249
35250 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35251- atomic_set(&dev->counts[i], 0);
35252+ atomic_set_unchecked(&dev->counts[i], 0);
35253
35254 dev->sigdata.lock = NULL;
35255
35256@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35257 if (drm_device_is_unplugged(dev))
35258 return -ENODEV;
35259
35260- if (!dev->open_count++)
35261+ if (local_inc_return(&dev->open_count) == 1)
35262 need_setup = 1;
35263 mutex_lock(&dev->struct_mutex);
35264 old_imapping = inode->i_mapping;
35265@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35266 retcode = drm_open_helper(inode, filp, dev);
35267 if (retcode)
35268 goto err_undo;
35269- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35270+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35271 if (need_setup) {
35272 retcode = drm_setup(dev);
35273 if (retcode)
35274@@ -166,7 +166,7 @@ err_undo:
35275 iput(container_of(dev->dev_mapping, struct inode, i_data));
35276 dev->dev_mapping = old_mapping;
35277 mutex_unlock(&dev->struct_mutex);
35278- dev->open_count--;
35279+ local_dec(&dev->open_count);
35280 return retcode;
35281 }
35282 EXPORT_SYMBOL(drm_open);
35283@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
35284
35285 mutex_lock(&drm_global_mutex);
35286
35287- DRM_DEBUG("open_count = %d\n", dev->open_count);
35288+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35289
35290 if (dev->driver->preclose)
35291 dev->driver->preclose(dev, file_priv);
35292@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
35293 * Begin inline drm_release
35294 */
35295
35296- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35297+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35298 task_pid_nr(current),
35299 (long)old_encode_dev(file_priv->minor->device),
35300- dev->open_count);
35301+ local_read(&dev->open_count));
35302
35303 /* Release any auth tokens that might point to this file_priv,
35304 (do that under the drm_global_mutex) */
35305@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
35306 * End inline drm_release
35307 */
35308
35309- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35310- if (!--dev->open_count) {
35311+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35312+ if (local_dec_and_test(&dev->open_count)) {
35313 if (atomic_read(&dev->ioctl_count)) {
35314 DRM_ERROR("Device busy: %d\n",
35315 atomic_read(&dev->ioctl_count));
35316diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35317index f731116..629842c 100644
35318--- a/drivers/gpu/drm/drm_global.c
35319+++ b/drivers/gpu/drm/drm_global.c
35320@@ -36,7 +36,7 @@
35321 struct drm_global_item {
35322 struct mutex mutex;
35323 void *object;
35324- int refcount;
35325+ atomic_t refcount;
35326 };
35327
35328 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35329@@ -49,7 +49,7 @@ void drm_global_init(void)
35330 struct drm_global_item *item = &glob[i];
35331 mutex_init(&item->mutex);
35332 item->object = NULL;
35333- item->refcount = 0;
35334+ atomic_set(&item->refcount, 0);
35335 }
35336 }
35337
35338@@ -59,7 +59,7 @@ void drm_global_release(void)
35339 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35340 struct drm_global_item *item = &glob[i];
35341 BUG_ON(item->object != NULL);
35342- BUG_ON(item->refcount != 0);
35343+ BUG_ON(atomic_read(&item->refcount) != 0);
35344 }
35345 }
35346
35347@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35348 void *object;
35349
35350 mutex_lock(&item->mutex);
35351- if (item->refcount == 0) {
35352+ if (atomic_read(&item->refcount) == 0) {
35353 item->object = kzalloc(ref->size, GFP_KERNEL);
35354 if (unlikely(item->object == NULL)) {
35355 ret = -ENOMEM;
35356@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35357 goto out_err;
35358
35359 }
35360- ++item->refcount;
35361+ atomic_inc(&item->refcount);
35362 ref->object = item->object;
35363 object = item->object;
35364 mutex_unlock(&item->mutex);
35365@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35366 struct drm_global_item *item = &glob[ref->global_type];
35367
35368 mutex_lock(&item->mutex);
35369- BUG_ON(item->refcount == 0);
35370+ BUG_ON(atomic_read(&item->refcount) == 0);
35371 BUG_ON(ref->object != item->object);
35372- if (--item->refcount == 0) {
35373+ if (atomic_dec_and_test(&item->refcount)) {
35374 ref->release(ref);
35375 item->object = NULL;
35376 }
35377diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35378index d4b20ce..77a8d41 100644
35379--- a/drivers/gpu/drm/drm_info.c
35380+++ b/drivers/gpu/drm/drm_info.c
35381@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35382 struct drm_local_map *map;
35383 struct drm_map_list *r_list;
35384
35385- /* Hardcoded from _DRM_FRAME_BUFFER,
35386- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35387- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35388- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35389+ static const char * const types[] = {
35390+ [_DRM_FRAME_BUFFER] = "FB",
35391+ [_DRM_REGISTERS] = "REG",
35392+ [_DRM_SHM] = "SHM",
35393+ [_DRM_AGP] = "AGP",
35394+ [_DRM_SCATTER_GATHER] = "SG",
35395+ [_DRM_CONSISTENT] = "PCI",
35396+ [_DRM_GEM] = "GEM" };
35397 const char *type;
35398 int i;
35399
35400@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35401 map = r_list->map;
35402 if (!map)
35403 continue;
35404- if (map->type < 0 || map->type > 5)
35405+ if (map->type >= ARRAY_SIZE(types))
35406 type = "??";
35407 else
35408 type = types[map->type];
35409@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35410 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35411 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35412 vma->vm_flags & VM_IO ? 'i' : '-',
35413+#ifdef CONFIG_GRKERNSEC_HIDESYM
35414+ 0);
35415+#else
35416 vma->vm_pgoff);
35417+#endif
35418
35419 #if defined(__i386__)
35420 pgprot = pgprot_val(vma->vm_page_prot);
35421diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35422index 2f4c434..dd12cd2 100644
35423--- a/drivers/gpu/drm/drm_ioc32.c
35424+++ b/drivers/gpu/drm/drm_ioc32.c
35425@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35426 request = compat_alloc_user_space(nbytes);
35427 if (!access_ok(VERIFY_WRITE, request, nbytes))
35428 return -EFAULT;
35429- list = (struct drm_buf_desc *) (request + 1);
35430+ list = (struct drm_buf_desc __user *) (request + 1);
35431
35432 if (__put_user(count, &request->count)
35433 || __put_user(list, &request->list))
35434@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35435 request = compat_alloc_user_space(nbytes);
35436 if (!access_ok(VERIFY_WRITE, request, nbytes))
35437 return -EFAULT;
35438- list = (struct drm_buf_pub *) (request + 1);
35439+ list = (struct drm_buf_pub __user *) (request + 1);
35440
35441 if (__put_user(count, &request->count)
35442 || __put_user(list, &request->list))
35443@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35444 return 0;
35445 }
35446
35447-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35448+drm_ioctl_compat_t drm_compat_ioctls[] = {
35449 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35450 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35451 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35452@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35453 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35454 {
35455 unsigned int nr = DRM_IOCTL_NR(cmd);
35456- drm_ioctl_compat_t *fn;
35457 int ret;
35458
35459 /* Assume that ioctls without an explicit compat routine will just
35460@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35461 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35462 return drm_ioctl(filp, cmd, arg);
35463
35464- fn = drm_compat_ioctls[nr];
35465-
35466- if (fn != NULL)
35467- ret = (*fn) (filp, cmd, arg);
35468+ if (drm_compat_ioctls[nr] != NULL)
35469+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35470 else
35471 ret = drm_ioctl(filp, cmd, arg);
35472
35473diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35474index e77bd8b..1571b85 100644
35475--- a/drivers/gpu/drm/drm_ioctl.c
35476+++ b/drivers/gpu/drm/drm_ioctl.c
35477@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35478 stats->data[i].value =
35479 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35480 else
35481- stats->data[i].value = atomic_read(&dev->counts[i]);
35482+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35483 stats->data[i].type = dev->types[i];
35484 }
35485
35486diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35487index d752c96..fe08455 100644
35488--- a/drivers/gpu/drm/drm_lock.c
35489+++ b/drivers/gpu/drm/drm_lock.c
35490@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35491 if (drm_lock_take(&master->lock, lock->context)) {
35492 master->lock.file_priv = file_priv;
35493 master->lock.lock_time = jiffies;
35494- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35495+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35496 break; /* Got lock */
35497 }
35498
35499@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35500 return -EINVAL;
35501 }
35502
35503- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35504+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35505
35506 if (drm_lock_free(&master->lock, lock->context)) {
35507 /* FIXME: Should really bail out here. */
35508diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35509index 16f3ec5..b28f9ca 100644
35510--- a/drivers/gpu/drm/drm_stub.c
35511+++ b/drivers/gpu/drm/drm_stub.c
35512@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
35513
35514 drm_device_set_unplugged(dev);
35515
35516- if (dev->open_count == 0) {
35517+ if (local_read(&dev->open_count) == 0) {
35518 drm_put_dev(dev);
35519 }
35520 mutex_unlock(&drm_global_mutex);
35521diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
35522index 0229665..f61329c 100644
35523--- a/drivers/gpu/drm/drm_sysfs.c
35524+++ b/drivers/gpu/drm/drm_sysfs.c
35525@@ -499,7 +499,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
35526 int drm_sysfs_device_add(struct drm_minor *minor)
35527 {
35528 int err;
35529- char *minor_str;
35530+ const char *minor_str;
35531
35532 minor->kdev.parent = minor->dev->dev;
35533
35534diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35535index 004ecdf..db1f6e0 100644
35536--- a/drivers/gpu/drm/i810/i810_dma.c
35537+++ b/drivers/gpu/drm/i810/i810_dma.c
35538@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35539 dma->buflist[vertex->idx],
35540 vertex->discard, vertex->used);
35541
35542- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35543- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35544+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35545+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35546 sarea_priv->last_enqueue = dev_priv->counter - 1;
35547 sarea_priv->last_dispatch = (int)hw_status[5];
35548
35549@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35550 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35551 mc->last_render);
35552
35553- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35554- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35555+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35556+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35557 sarea_priv->last_enqueue = dev_priv->counter - 1;
35558 sarea_priv->last_dispatch = (int)hw_status[5];
35559
35560diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35561index 6e0acad..93c8289 100644
35562--- a/drivers/gpu/drm/i810/i810_drv.h
35563+++ b/drivers/gpu/drm/i810/i810_drv.h
35564@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35565 int page_flipping;
35566
35567 wait_queue_head_t irq_queue;
35568- atomic_t irq_received;
35569- atomic_t irq_emitted;
35570+ atomic_unchecked_t irq_received;
35571+ atomic_unchecked_t irq_emitted;
35572
35573 int front_offset;
35574 } drm_i810_private_t;
35575diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35576index e913d32..4d9b351 100644
35577--- a/drivers/gpu/drm/i915/i915_debugfs.c
35578+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35579@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35580 I915_READ(GTIMR));
35581 }
35582 seq_printf(m, "Interrupts received: %d\n",
35583- atomic_read(&dev_priv->irq_received));
35584+ atomic_read_unchecked(&dev_priv->irq_received));
35585 for_each_ring(ring, dev_priv, i) {
35586 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35587 seq_printf(m,
35588diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35589index 3b315ba..aac280f 100644
35590--- a/drivers/gpu/drm/i915/i915_dma.c
35591+++ b/drivers/gpu/drm/i915/i915_dma.c
35592@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35593 bool can_switch;
35594
35595 spin_lock(&dev->count_lock);
35596- can_switch = (dev->open_count == 0);
35597+ can_switch = (local_read(&dev->open_count) == 0);
35598 spin_unlock(&dev->count_lock);
35599 return can_switch;
35600 }
35601diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35602index 9669a0b..bb65176 100644
35603--- a/drivers/gpu/drm/i915/i915_drv.h
35604+++ b/drivers/gpu/drm/i915/i915_drv.h
35605@@ -915,7 +915,7 @@ typedef struct drm_i915_private {
35606 drm_dma_handle_t *status_page_dmah;
35607 struct resource mch_res;
35608
35609- atomic_t irq_received;
35610+ atomic_unchecked_t irq_received;
35611
35612 /* protects the irq masks */
35613 spinlock_t irq_lock;
35614@@ -1811,7 +1811,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35615 struct drm_i915_private *dev_priv, unsigned port);
35616 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35617 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35618-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35619+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35620 {
35621 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35622 }
35623diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35624index 117ce38..eefd237 100644
35625--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35626+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35627@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35628
35629 static int
35630 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35631- int count)
35632+ unsigned int count)
35633 {
35634- int i;
35635+ unsigned int i;
35636 int relocs_total = 0;
35637 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35638
35639diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35640index 3c59584..500f2e9 100644
35641--- a/drivers/gpu/drm/i915/i915_ioc32.c
35642+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35643@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35644 (unsigned long)request);
35645 }
35646
35647-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35648+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35649 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35650 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35651 [DRM_I915_GETPARAM] = compat_i915_getparam,
35652@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35653 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35654 {
35655 unsigned int nr = DRM_IOCTL_NR(cmd);
35656- drm_ioctl_compat_t *fn = NULL;
35657 int ret;
35658
35659 if (nr < DRM_COMMAND_BASE)
35660 return drm_compat_ioctl(filp, cmd, arg);
35661
35662- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35663- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35664-
35665- if (fn != NULL)
35666+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35667+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35668 ret = (*fn) (filp, cmd, arg);
35669- else
35670+ } else
35671 ret = drm_ioctl(filp, cmd, arg);
35672
35673 return ret;
35674diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35675index 0aa2ef0..77c03d0 100644
35676--- a/drivers/gpu/drm/i915/i915_irq.c
35677+++ b/drivers/gpu/drm/i915/i915_irq.c
35678@@ -679,7 +679,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35679 int pipe;
35680 u32 pipe_stats[I915_MAX_PIPES];
35681
35682- atomic_inc(&dev_priv->irq_received);
35683+ atomic_inc_unchecked(&dev_priv->irq_received);
35684
35685 while (true) {
35686 iir = I915_READ(VLV_IIR);
35687@@ -844,7 +844,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35688 irqreturn_t ret = IRQ_NONE;
35689 int i;
35690
35691- atomic_inc(&dev_priv->irq_received);
35692+ atomic_inc_unchecked(&dev_priv->irq_received);
35693
35694 /* disable master interrupt before clearing iir */
35695 de_ier = I915_READ(DEIER);
35696@@ -934,7 +934,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35697 int ret = IRQ_NONE;
35698 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
35699
35700- atomic_inc(&dev_priv->irq_received);
35701+ atomic_inc_unchecked(&dev_priv->irq_received);
35702
35703 /* disable master interrupt before clearing iir */
35704 de_ier = I915_READ(DEIER);
35705@@ -2098,7 +2098,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35706 {
35707 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35708
35709- atomic_set(&dev_priv->irq_received, 0);
35710+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35711
35712 I915_WRITE(HWSTAM, 0xeffe);
35713
35714@@ -2133,7 +2133,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35715 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35716 int pipe;
35717
35718- atomic_set(&dev_priv->irq_received, 0);
35719+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35720
35721 /* VLV magic */
35722 I915_WRITE(VLV_IMR, 0);
35723@@ -2420,7 +2420,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35724 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35725 int pipe;
35726
35727- atomic_set(&dev_priv->irq_received, 0);
35728+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35729
35730 for_each_pipe(pipe)
35731 I915_WRITE(PIPESTAT(pipe), 0);
35732@@ -2499,7 +2499,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35733 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35734 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35735
35736- atomic_inc(&dev_priv->irq_received);
35737+ atomic_inc_unchecked(&dev_priv->irq_received);
35738
35739 iir = I915_READ16(IIR);
35740 if (iir == 0)
35741@@ -2574,7 +2574,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35742 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35743 int pipe;
35744
35745- atomic_set(&dev_priv->irq_received, 0);
35746+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35747
35748 if (I915_HAS_HOTPLUG(dev)) {
35749 I915_WRITE(PORT_HOTPLUG_EN, 0);
35750@@ -2673,7 +2673,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35751 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35752 int pipe, ret = IRQ_NONE;
35753
35754- atomic_inc(&dev_priv->irq_received);
35755+ atomic_inc_unchecked(&dev_priv->irq_received);
35756
35757 iir = I915_READ(IIR);
35758 do {
35759@@ -2800,7 +2800,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35760 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35761 int pipe;
35762
35763- atomic_set(&dev_priv->irq_received, 0);
35764+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35765
35766 I915_WRITE(PORT_HOTPLUG_EN, 0);
35767 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35768@@ -2907,7 +2907,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35769 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35770 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35771
35772- atomic_inc(&dev_priv->irq_received);
35773+ atomic_inc_unchecked(&dev_priv->irq_received);
35774
35775 iir = I915_READ(IIR);
35776
35777diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35778index 56746dc..b5a214f 100644
35779--- a/drivers/gpu/drm/i915/intel_display.c
35780+++ b/drivers/gpu/drm/i915/intel_display.c
35781@@ -8919,13 +8919,13 @@ struct intel_quirk {
35782 int subsystem_vendor;
35783 int subsystem_device;
35784 void (*hook)(struct drm_device *dev);
35785-};
35786+} __do_const;
35787
35788 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35789 struct intel_dmi_quirk {
35790 void (*hook)(struct drm_device *dev);
35791 const struct dmi_system_id (*dmi_id_list)[];
35792-};
35793+} __do_const;
35794
35795 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35796 {
35797@@ -8933,18 +8933,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35798 return 1;
35799 }
35800
35801-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35802+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35803 {
35804- .dmi_id_list = &(const struct dmi_system_id[]) {
35805- {
35806- .callback = intel_dmi_reverse_brightness,
35807- .ident = "NCR Corporation",
35808- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35809- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35810- },
35811- },
35812- { } /* terminating entry */
35813+ .callback = intel_dmi_reverse_brightness,
35814+ .ident = "NCR Corporation",
35815+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35816+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35817 },
35818+ },
35819+ { } /* terminating entry */
35820+};
35821+
35822+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35823+ {
35824+ .dmi_id_list = &intel_dmi_quirks_table,
35825 .hook = quirk_invert_brightness,
35826 },
35827 };
35828diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35829index 54558a0..2d97005 100644
35830--- a/drivers/gpu/drm/mga/mga_drv.h
35831+++ b/drivers/gpu/drm/mga/mga_drv.h
35832@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35833 u32 clear_cmd;
35834 u32 maccess;
35835
35836- atomic_t vbl_received; /**< Number of vblanks received. */
35837+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35838 wait_queue_head_t fence_queue;
35839- atomic_t last_fence_retired;
35840+ atomic_unchecked_t last_fence_retired;
35841 u32 next_fence_to_post;
35842
35843 unsigned int fb_cpp;
35844diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35845index 709e90d..89a1c0d 100644
35846--- a/drivers/gpu/drm/mga/mga_ioc32.c
35847+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35848@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35849 return 0;
35850 }
35851
35852-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35853+drm_ioctl_compat_t mga_compat_ioctls[] = {
35854 [DRM_MGA_INIT] = compat_mga_init,
35855 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35856 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35857@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35858 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35859 {
35860 unsigned int nr = DRM_IOCTL_NR(cmd);
35861- drm_ioctl_compat_t *fn = NULL;
35862 int ret;
35863
35864 if (nr < DRM_COMMAND_BASE)
35865 return drm_compat_ioctl(filp, cmd, arg);
35866
35867- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35868- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35869-
35870- if (fn != NULL)
35871+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35872+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35873 ret = (*fn) (filp, cmd, arg);
35874- else
35875+ } else
35876 ret = drm_ioctl(filp, cmd, arg);
35877
35878 return ret;
35879diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35880index 598c281..60d590e 100644
35881--- a/drivers/gpu/drm/mga/mga_irq.c
35882+++ b/drivers/gpu/drm/mga/mga_irq.c
35883@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35884 if (crtc != 0)
35885 return 0;
35886
35887- return atomic_read(&dev_priv->vbl_received);
35888+ return atomic_read_unchecked(&dev_priv->vbl_received);
35889 }
35890
35891
35892@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35893 /* VBLANK interrupt */
35894 if (status & MGA_VLINEPEN) {
35895 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35896- atomic_inc(&dev_priv->vbl_received);
35897+ atomic_inc_unchecked(&dev_priv->vbl_received);
35898 drm_handle_vblank(dev, 0);
35899 handled = 1;
35900 }
35901@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35902 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35903 MGA_WRITE(MGA_PRIMEND, prim_end);
35904
35905- atomic_inc(&dev_priv->last_fence_retired);
35906+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35907 DRM_WAKEUP(&dev_priv->fence_queue);
35908 handled = 1;
35909 }
35910@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35911 * using fences.
35912 */
35913 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35914- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35915+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35916 - *sequence) <= (1 << 23)));
35917
35918 *sequence = cur_fence;
35919diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35920index 6aa2137..fe8dc55 100644
35921--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35922+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35923@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35924 struct bit_table {
35925 const char id;
35926 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35927-};
35928+} __no_const;
35929
35930 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35931
35932diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35933index f2b30f8..d0f9a95 100644
35934--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35935+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35936@@ -92,7 +92,7 @@ struct nouveau_drm {
35937 struct drm_global_reference mem_global_ref;
35938 struct ttm_bo_global_ref bo_global_ref;
35939 struct ttm_bo_device bdev;
35940- atomic_t validate_sequence;
35941+ atomic_unchecked_t validate_sequence;
35942 int (*move)(struct nouveau_channel *,
35943 struct ttm_buffer_object *,
35944 struct ttm_mem_reg *, struct ttm_mem_reg *);
35945diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35946index b4b4d0c..b7edc15 100644
35947--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35948+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35949@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35950 int ret, i;
35951 struct nouveau_bo *res_bo = NULL;
35952
35953- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35954+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35955 retry:
35956 if (++trycnt > 100000) {
35957 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
35958@@ -359,7 +359,7 @@ retry:
35959 if (ret) {
35960 validate_fini(op, NULL);
35961 if (unlikely(ret == -EAGAIN)) {
35962- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35963+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35964 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
35965 sequence);
35966 if (!ret)
35967diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35968index 08214bc..9208577 100644
35969--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35970+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35971@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35972 unsigned long arg)
35973 {
35974 unsigned int nr = DRM_IOCTL_NR(cmd);
35975- drm_ioctl_compat_t *fn = NULL;
35976+ drm_ioctl_compat_t fn = NULL;
35977 int ret;
35978
35979 if (nr < DRM_COMMAND_BASE)
35980diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35981index 25d3495..d81aaf6 100644
35982--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35983+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35984@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35985 bool can_switch;
35986
35987 spin_lock(&dev->count_lock);
35988- can_switch = (dev->open_count == 0);
35989+ can_switch = (local_read(&dev->open_count) == 0);
35990 spin_unlock(&dev->count_lock);
35991 return can_switch;
35992 }
35993diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
35994index 489cb8c..0b8d0d3 100644
35995--- a/drivers/gpu/drm/qxl/qxl_ttm.c
35996+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
35997@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
35998 }
35999 }
36000
36001-static struct vm_operations_struct qxl_ttm_vm_ops;
36002+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
36003 static const struct vm_operations_struct *ttm_vm_ops;
36004
36005 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36006@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
36007 return r;
36008 if (unlikely(ttm_vm_ops == NULL)) {
36009 ttm_vm_ops = vma->vm_ops;
36010+ pax_open_kernel();
36011 qxl_ttm_vm_ops = *ttm_vm_ops;
36012 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
36013+ pax_close_kernel();
36014 }
36015 vma->vm_ops = &qxl_ttm_vm_ops;
36016 return 0;
36017@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
36018 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
36019 {
36020 #if defined(CONFIG_DEBUG_FS)
36021- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
36022- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
36023- unsigned i;
36024+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
36025+ {
36026+ .name = "qxl_mem_mm",
36027+ .show = &qxl_mm_dump_table,
36028+ },
36029+ {
36030+ .name = "qxl_surf_mm",
36031+ .show = &qxl_mm_dump_table,
36032+ }
36033+ };
36034
36035- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
36036- if (i == 0)
36037- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
36038- else
36039- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
36040- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
36041- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
36042- qxl_mem_types_list[i].driver_features = 0;
36043- if (i == 0)
36044- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
36045- else
36046- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
36047+ pax_open_kernel();
36048+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
36049+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
36050+ pax_close_kernel();
36051
36052- }
36053- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
36054+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
36055 #else
36056 return 0;
36057 #endif
36058diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
36059index d4660cf..70dbe65 100644
36060--- a/drivers/gpu/drm/r128/r128_cce.c
36061+++ b/drivers/gpu/drm/r128/r128_cce.c
36062@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
36063
36064 /* GH: Simple idle check.
36065 */
36066- atomic_set(&dev_priv->idle_count, 0);
36067+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36068
36069 /* We don't support anything other than bus-mastering ring mode,
36070 * but the ring can be in either AGP or PCI space for the ring
36071diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
36072index 930c71b..499aded 100644
36073--- a/drivers/gpu/drm/r128/r128_drv.h
36074+++ b/drivers/gpu/drm/r128/r128_drv.h
36075@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
36076 int is_pci;
36077 unsigned long cce_buffers_offset;
36078
36079- atomic_t idle_count;
36080+ atomic_unchecked_t idle_count;
36081
36082 int page_flipping;
36083 int current_page;
36084 u32 crtc_offset;
36085 u32 crtc_offset_cntl;
36086
36087- atomic_t vbl_received;
36088+ atomic_unchecked_t vbl_received;
36089
36090 u32 color_fmt;
36091 unsigned int front_offset;
36092diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
36093index a954c54..9cc595c 100644
36094--- a/drivers/gpu/drm/r128/r128_ioc32.c
36095+++ b/drivers/gpu/drm/r128/r128_ioc32.c
36096@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
36097 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
36098 }
36099
36100-drm_ioctl_compat_t *r128_compat_ioctls[] = {
36101+drm_ioctl_compat_t r128_compat_ioctls[] = {
36102 [DRM_R128_INIT] = compat_r128_init,
36103 [DRM_R128_DEPTH] = compat_r128_depth,
36104 [DRM_R128_STIPPLE] = compat_r128_stipple,
36105@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
36106 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36107 {
36108 unsigned int nr = DRM_IOCTL_NR(cmd);
36109- drm_ioctl_compat_t *fn = NULL;
36110 int ret;
36111
36112 if (nr < DRM_COMMAND_BASE)
36113 return drm_compat_ioctl(filp, cmd, arg);
36114
36115- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
36116- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36117-
36118- if (fn != NULL)
36119+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
36120+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
36121 ret = (*fn) (filp, cmd, arg);
36122- else
36123+ } else
36124 ret = drm_ioctl(filp, cmd, arg);
36125
36126 return ret;
36127diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
36128index 2ea4f09..d391371 100644
36129--- a/drivers/gpu/drm/r128/r128_irq.c
36130+++ b/drivers/gpu/drm/r128/r128_irq.c
36131@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
36132 if (crtc != 0)
36133 return 0;
36134
36135- return atomic_read(&dev_priv->vbl_received);
36136+ return atomic_read_unchecked(&dev_priv->vbl_received);
36137 }
36138
36139 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36140@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
36141 /* VBLANK interrupt */
36142 if (status & R128_CRTC_VBLANK_INT) {
36143 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
36144- atomic_inc(&dev_priv->vbl_received);
36145+ atomic_inc_unchecked(&dev_priv->vbl_received);
36146 drm_handle_vblank(dev, 0);
36147 return IRQ_HANDLED;
36148 }
36149diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
36150index 19bb7e6..de7e2a2 100644
36151--- a/drivers/gpu/drm/r128/r128_state.c
36152+++ b/drivers/gpu/drm/r128/r128_state.c
36153@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
36154
36155 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
36156 {
36157- if (atomic_read(&dev_priv->idle_count) == 0)
36158+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
36159 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
36160 else
36161- atomic_set(&dev_priv->idle_count, 0);
36162+ atomic_set_unchecked(&dev_priv->idle_count, 0);
36163 }
36164
36165 #endif
36166diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
36167index 5a82b6b..9e69c73 100644
36168--- a/drivers/gpu/drm/radeon/mkregtable.c
36169+++ b/drivers/gpu/drm/radeon/mkregtable.c
36170@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
36171 regex_t mask_rex;
36172 regmatch_t match[4];
36173 char buf[1024];
36174- size_t end;
36175+ long end;
36176 int len;
36177 int done = 0;
36178 int r;
36179 unsigned o;
36180 struct offset *offset;
36181 char last_reg_s[10];
36182- int last_reg;
36183+ unsigned long last_reg;
36184
36185 if (regcomp
36186 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
36187diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
36188index b0dc0b6..a9bfe9c 100644
36189--- a/drivers/gpu/drm/radeon/radeon_device.c
36190+++ b/drivers/gpu/drm/radeon/radeon_device.c
36191@@ -1014,7 +1014,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
36192 bool can_switch;
36193
36194 spin_lock(&dev->count_lock);
36195- can_switch = (dev->open_count == 0);
36196+ can_switch = (local_read(&dev->open_count) == 0);
36197 spin_unlock(&dev->count_lock);
36198 return can_switch;
36199 }
36200diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
36201index b369d42..8dd04eb 100644
36202--- a/drivers/gpu/drm/radeon/radeon_drv.h
36203+++ b/drivers/gpu/drm/radeon/radeon_drv.h
36204@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
36205
36206 /* SW interrupt */
36207 wait_queue_head_t swi_queue;
36208- atomic_t swi_emitted;
36209+ atomic_unchecked_t swi_emitted;
36210 int vblank_crtc;
36211 uint32_t irq_enable_reg;
36212 uint32_t r500_disp_irq_reg;
36213diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
36214index c180df8..5fd8186 100644
36215--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
36216+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
36217@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36218 request = compat_alloc_user_space(sizeof(*request));
36219 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
36220 || __put_user(req32.param, &request->param)
36221- || __put_user((void __user *)(unsigned long)req32.value,
36222+ || __put_user((unsigned long)req32.value,
36223 &request->value))
36224 return -EFAULT;
36225
36226@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
36227 #define compat_radeon_cp_setparam NULL
36228 #endif /* X86_64 || IA64 */
36229
36230-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36231+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
36232 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
36233 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
36234 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
36235@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
36236 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
36237 {
36238 unsigned int nr = DRM_IOCTL_NR(cmd);
36239- drm_ioctl_compat_t *fn = NULL;
36240 int ret;
36241
36242 if (nr < DRM_COMMAND_BASE)
36243 return drm_compat_ioctl(filp, cmd, arg);
36244
36245- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
36246- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36247-
36248- if (fn != NULL)
36249+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
36250+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
36251 ret = (*fn) (filp, cmd, arg);
36252- else
36253+ } else
36254 ret = drm_ioctl(filp, cmd, arg);
36255
36256 return ret;
36257diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
36258index 8d68e97..9dcfed8 100644
36259--- a/drivers/gpu/drm/radeon/radeon_irq.c
36260+++ b/drivers/gpu/drm/radeon/radeon_irq.c
36261@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36262 unsigned int ret;
36263 RING_LOCALS;
36264
36265- atomic_inc(&dev_priv->swi_emitted);
36266- ret = atomic_read(&dev_priv->swi_emitted);
36267+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36268+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36269
36270 BEGIN_RING(4);
36271 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36272@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36273 drm_radeon_private_t *dev_priv =
36274 (drm_radeon_private_t *) dev->dev_private;
36275
36276- atomic_set(&dev_priv->swi_emitted, 0);
36277+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36278 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36279
36280 dev->max_vblank_count = 0x001fffff;
36281diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36282index 4d20910..6726b6d 100644
36283--- a/drivers/gpu/drm/radeon/radeon_state.c
36284+++ b/drivers/gpu/drm/radeon/radeon_state.c
36285@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36286 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36287 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36288
36289- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36290+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36291 sarea_priv->nbox * sizeof(depth_boxes[0])))
36292 return -EFAULT;
36293
36294@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36295 {
36296 drm_radeon_private_t *dev_priv = dev->dev_private;
36297 drm_radeon_getparam_t *param = data;
36298- int value;
36299+ int value = 0;
36300
36301 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36302
36303diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36304index 6c0ce89..57a2529 100644
36305--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36306+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36307@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36308 man->size = size >> PAGE_SHIFT;
36309 }
36310
36311-static struct vm_operations_struct radeon_ttm_vm_ops;
36312+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36313 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36314
36315 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36316@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36317 }
36318 if (unlikely(ttm_vm_ops == NULL)) {
36319 ttm_vm_ops = vma->vm_ops;
36320+ pax_open_kernel();
36321 radeon_ttm_vm_ops = *ttm_vm_ops;
36322 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36323+ pax_close_kernel();
36324 }
36325 vma->vm_ops = &radeon_ttm_vm_ops;
36326 return 0;
36327@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
36328 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36329 {
36330 #if defined(CONFIG_DEBUG_FS)
36331- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
36332- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
36333+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
36334+ {
36335+ .name = "radeon_vram_mm",
36336+ .show = &radeon_mm_dump_table,
36337+ },
36338+ {
36339+ .name = "radeon_gtt_mm",
36340+ .show = &radeon_mm_dump_table,
36341+ },
36342+ {
36343+ .name = "ttm_page_pool",
36344+ .show = &ttm_page_alloc_debugfs,
36345+ },
36346+ {
36347+ .name = "ttm_dma_page_pool",
36348+ .show = &ttm_dma_page_alloc_debugfs,
36349+ },
36350+ };
36351 unsigned i;
36352
36353- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
36354- if (i == 0)
36355- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36356- else
36357- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36358- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36359- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36360- radeon_mem_types_list[i].driver_features = 0;
36361- if (i == 0)
36362- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36363- else
36364- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36365-
36366- }
36367- /* Add ttm page pool to debugfs */
36368- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36369- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36370- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36371- radeon_mem_types_list[i].driver_features = 0;
36372- radeon_mem_types_list[i++].data = NULL;
36373+ pax_open_kernel();
36374+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36375+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36376+ pax_close_kernel();
36377 #ifdef CONFIG_SWIOTLB
36378- if (swiotlb_nr_tbl()) {
36379- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36380- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36381- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36382- radeon_mem_types_list[i].driver_features = 0;
36383- radeon_mem_types_list[i++].data = NULL;
36384- }
36385+ if (swiotlb_nr_tbl())
36386+ i++;
36387 #endif
36388 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36389
36390diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36391index 55880d5..9e95342 100644
36392--- a/drivers/gpu/drm/radeon/rs690.c
36393+++ b/drivers/gpu/drm/radeon/rs690.c
36394@@ -327,9 +327,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36395 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36396 rdev->pm.sideport_bandwidth.full)
36397 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36398- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36399+ read_delay_latency.full = dfixed_const(800 * 1000);
36400 read_delay_latency.full = dfixed_div(read_delay_latency,
36401 rdev->pm.igp_sideport_mclk);
36402+ a.full = dfixed_const(370);
36403+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36404 } else {
36405 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36406 rdev->pm.k8_bandwidth.full)
36407diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
36408index dbc2def..0a9f710 100644
36409--- a/drivers/gpu/drm/ttm/ttm_memory.c
36410+++ b/drivers/gpu/drm/ttm/ttm_memory.c
36411@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
36412 zone->glob = glob;
36413 glob->zone_kernel = zone;
36414 ret = kobject_init_and_add(
36415- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36416+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36417 if (unlikely(ret != 0)) {
36418 kobject_put(&zone->kobj);
36419 return ret;
36420@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
36421 zone->glob = glob;
36422 glob->zone_dma32 = zone;
36423 ret = kobject_init_and_add(
36424- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36425+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36426 if (unlikely(ret != 0)) {
36427 kobject_put(&zone->kobj);
36428 return ret;
36429diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36430index bd2a3b4..122d9ad 100644
36431--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36432+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36433@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36434 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36435 struct shrink_control *sc)
36436 {
36437- static atomic_t start_pool = ATOMIC_INIT(0);
36438+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36439 unsigned i;
36440- unsigned pool_offset = atomic_add_return(1, &start_pool);
36441+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36442 struct ttm_page_pool *pool;
36443 int shrink_pages = sc->nr_to_scan;
36444
36445diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36446index dc0c065..58a0782 100644
36447--- a/drivers/gpu/drm/udl/udl_fb.c
36448+++ b/drivers/gpu/drm/udl/udl_fb.c
36449@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36450 fb_deferred_io_cleanup(info);
36451 kfree(info->fbdefio);
36452 info->fbdefio = NULL;
36453- info->fbops->fb_mmap = udl_fb_mmap;
36454 }
36455
36456 pr_warn("released /dev/fb%d user=%d count=%d\n",
36457diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36458index 893a650..6190d3b 100644
36459--- a/drivers/gpu/drm/via/via_drv.h
36460+++ b/drivers/gpu/drm/via/via_drv.h
36461@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36462 typedef uint32_t maskarray_t[5];
36463
36464 typedef struct drm_via_irq {
36465- atomic_t irq_received;
36466+ atomic_unchecked_t irq_received;
36467 uint32_t pending_mask;
36468 uint32_t enable_mask;
36469 wait_queue_head_t irq_queue;
36470@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36471 struct timeval last_vblank;
36472 int last_vblank_valid;
36473 unsigned usec_per_vblank;
36474- atomic_t vbl_received;
36475+ atomic_unchecked_t vbl_received;
36476 drm_via_state_t hc_state;
36477 char pci_buf[VIA_PCI_BUF_SIZE];
36478 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36479diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36480index ac98964..5dbf512 100644
36481--- a/drivers/gpu/drm/via/via_irq.c
36482+++ b/drivers/gpu/drm/via/via_irq.c
36483@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36484 if (crtc != 0)
36485 return 0;
36486
36487- return atomic_read(&dev_priv->vbl_received);
36488+ return atomic_read_unchecked(&dev_priv->vbl_received);
36489 }
36490
36491 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36492@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36493
36494 status = VIA_READ(VIA_REG_INTERRUPT);
36495 if (status & VIA_IRQ_VBLANK_PENDING) {
36496- atomic_inc(&dev_priv->vbl_received);
36497- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36498+ atomic_inc_unchecked(&dev_priv->vbl_received);
36499+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36500 do_gettimeofday(&cur_vblank);
36501 if (dev_priv->last_vblank_valid) {
36502 dev_priv->usec_per_vblank =
36503@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36504 dev_priv->last_vblank = cur_vblank;
36505 dev_priv->last_vblank_valid = 1;
36506 }
36507- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36508+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36509 DRM_DEBUG("US per vblank is: %u\n",
36510 dev_priv->usec_per_vblank);
36511 }
36512@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36513
36514 for (i = 0; i < dev_priv->num_irqs; ++i) {
36515 if (status & cur_irq->pending_mask) {
36516- atomic_inc(&cur_irq->irq_received);
36517+ atomic_inc_unchecked(&cur_irq->irq_received);
36518 DRM_WAKEUP(&cur_irq->irq_queue);
36519 handled = 1;
36520 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36521@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36522 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36523 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36524 masks[irq][4]));
36525- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36526+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36527 } else {
36528 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36529 (((cur_irq_sequence =
36530- atomic_read(&cur_irq->irq_received)) -
36531+ atomic_read_unchecked(&cur_irq->irq_received)) -
36532 *sequence) <= (1 << 23)));
36533 }
36534 *sequence = cur_irq_sequence;
36535@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36536 }
36537
36538 for (i = 0; i < dev_priv->num_irqs; ++i) {
36539- atomic_set(&cur_irq->irq_received, 0);
36540+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36541 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36542 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36543 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36544@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36545 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36546 case VIA_IRQ_RELATIVE:
36547 irqwait->request.sequence +=
36548- atomic_read(&cur_irq->irq_received);
36549+ atomic_read_unchecked(&cur_irq->irq_received);
36550 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36551 case VIA_IRQ_ABSOLUTE:
36552 break;
36553diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36554index 13aeda7..4a952d1 100644
36555--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36556+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36557@@ -290,7 +290,7 @@ struct vmw_private {
36558 * Fencing and IRQs.
36559 */
36560
36561- atomic_t marker_seq;
36562+ atomic_unchecked_t marker_seq;
36563 wait_queue_head_t fence_queue;
36564 wait_queue_head_t fifo_queue;
36565 int fence_queue_waiters; /* Protected by hw_mutex */
36566diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36567index 3eb1486..0a47ee9 100644
36568--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36569+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36570@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36571 (unsigned int) min,
36572 (unsigned int) fifo->capabilities);
36573
36574- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36575+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36576 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36577 vmw_marker_queue_init(&fifo->marker_queue);
36578 return vmw_fifo_send_fence(dev_priv, &dummy);
36579@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36580 if (reserveable)
36581 iowrite32(bytes, fifo_mem +
36582 SVGA_FIFO_RESERVED);
36583- return fifo_mem + (next_cmd >> 2);
36584+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36585 } else {
36586 need_bounce = true;
36587 }
36588@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36589
36590 fm = vmw_fifo_reserve(dev_priv, bytes);
36591 if (unlikely(fm == NULL)) {
36592- *seqno = atomic_read(&dev_priv->marker_seq);
36593+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36594 ret = -ENOMEM;
36595 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36596 false, 3*HZ);
36597@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36598 }
36599
36600 do {
36601- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36602+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36603 } while (*seqno == 0);
36604
36605 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36606diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36607index c509d40..3b640c3 100644
36608--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36609+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36610@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
36611 int ret;
36612
36613 num_clips = arg->num_clips;
36614- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36615+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36616
36617 if (unlikely(num_clips == 0))
36618 return 0;
36619@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
36620 int ret;
36621
36622 num_clips = arg->num_clips;
36623- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36624+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36625
36626 if (unlikely(num_clips == 0))
36627 return 0;
36628diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36629index 4640adb..e1384ed 100644
36630--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36631+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36632@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36633 * emitted. Then the fence is stale and signaled.
36634 */
36635
36636- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36637+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36638 > VMW_FENCE_WRAP);
36639
36640 return ret;
36641@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36642
36643 if (fifo_idle)
36644 down_read(&fifo_state->rwsem);
36645- signal_seq = atomic_read(&dev_priv->marker_seq);
36646+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36647 ret = 0;
36648
36649 for (;;) {
36650diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36651index 8a8725c2..afed796 100644
36652--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36653+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36654@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36655 while (!vmw_lag_lt(queue, us)) {
36656 spin_lock(&queue->lock);
36657 if (list_empty(&queue->head))
36658- seqno = atomic_read(&dev_priv->marker_seq);
36659+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36660 else {
36661 marker = list_first_entry(&queue->head,
36662 struct vmw_marker, head);
36663diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36664index 264f550..f92dd8c 100644
36665--- a/drivers/hid/hid-core.c
36666+++ b/drivers/hid/hid-core.c
36667@@ -2269,7 +2269,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36668
36669 int hid_add_device(struct hid_device *hdev)
36670 {
36671- static atomic_t id = ATOMIC_INIT(0);
36672+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36673 int ret;
36674
36675 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36676@@ -2303,7 +2303,7 @@ int hid_add_device(struct hid_device *hdev)
36677 /* XXX hack, any other cleaner solution after the driver core
36678 * is converted to allow more than 20 bytes as the device name? */
36679 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36680- hdev->vendor, hdev->product, atomic_inc_return(&id));
36681+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36682
36683 hid_debug_register(hdev, dev_name(&hdev->dev));
36684 ret = device_add(&hdev->dev);
36685diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36686index 90124ff..3761764 100644
36687--- a/drivers/hid/hid-wiimote-debug.c
36688+++ b/drivers/hid/hid-wiimote-debug.c
36689@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36690 else if (size == 0)
36691 return -EIO;
36692
36693- if (copy_to_user(u, buf, size))
36694+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36695 return -EFAULT;
36696
36697 *off += size;
36698diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36699index 0b122f8..b1d8160 100644
36700--- a/drivers/hv/channel.c
36701+++ b/drivers/hv/channel.c
36702@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36703 int ret = 0;
36704 int t;
36705
36706- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36707- atomic_inc(&vmbus_connection.next_gpadl_handle);
36708+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36709+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36710
36711 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36712 if (ret)
36713diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36714index ae49237..380d4c9 100644
36715--- a/drivers/hv/hv.c
36716+++ b/drivers/hv/hv.c
36717@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36718 u64 output_address = (output) ? virt_to_phys(output) : 0;
36719 u32 output_address_hi = output_address >> 32;
36720 u32 output_address_lo = output_address & 0xFFFFFFFF;
36721- void *hypercall_page = hv_context.hypercall_page;
36722+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36723
36724 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36725 "=a"(hv_status_lo) : "d" (control_hi),
36726diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36727index 12f2f9e..679603c 100644
36728--- a/drivers/hv/hyperv_vmbus.h
36729+++ b/drivers/hv/hyperv_vmbus.h
36730@@ -591,7 +591,7 @@ enum vmbus_connect_state {
36731 struct vmbus_connection {
36732 enum vmbus_connect_state conn_state;
36733
36734- atomic_t next_gpadl_handle;
36735+ atomic_unchecked_t next_gpadl_handle;
36736
36737 /*
36738 * Represents channel interrupts. Each bit position represents a
36739diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36740index bf421e0..ce2c897 100644
36741--- a/drivers/hv/vmbus_drv.c
36742+++ b/drivers/hv/vmbus_drv.c
36743@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36744 {
36745 int ret = 0;
36746
36747- static atomic_t device_num = ATOMIC_INIT(0);
36748+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36749
36750 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36751- atomic_inc_return(&device_num));
36752+ atomic_inc_return_unchecked(&device_num));
36753
36754 child_device_obj->device.bus = &hv_bus;
36755 child_device_obj->device.parent = &hv_acpi_dev->dev;
36756diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36757index 6351aba..dc4aaf4 100644
36758--- a/drivers/hwmon/acpi_power_meter.c
36759+++ b/drivers/hwmon/acpi_power_meter.c
36760@@ -117,7 +117,7 @@ struct sensor_template {
36761 struct device_attribute *devattr,
36762 const char *buf, size_t count);
36763 int index;
36764-};
36765+} __do_const;
36766
36767 /* Averaging interval */
36768 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36769@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36770 struct sensor_template *attrs)
36771 {
36772 struct device *dev = &resource->acpi_dev->dev;
36773- struct sensor_device_attribute *sensors =
36774+ sensor_device_attribute_no_const *sensors =
36775 &resource->sensors[resource->num_sensors];
36776 int res = 0;
36777
36778diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36779index 62c2e32..8f2859a 100644
36780--- a/drivers/hwmon/applesmc.c
36781+++ b/drivers/hwmon/applesmc.c
36782@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36783 {
36784 struct applesmc_node_group *grp;
36785 struct applesmc_dev_attr *node;
36786- struct attribute *attr;
36787+ attribute_no_const *attr;
36788 int ret, i;
36789
36790 for (grp = groups; grp->format; grp++) {
36791diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36792index b25c643..a13460d 100644
36793--- a/drivers/hwmon/asus_atk0110.c
36794+++ b/drivers/hwmon/asus_atk0110.c
36795@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36796 struct atk_sensor_data {
36797 struct list_head list;
36798 struct atk_data *data;
36799- struct device_attribute label_attr;
36800- struct device_attribute input_attr;
36801- struct device_attribute limit1_attr;
36802- struct device_attribute limit2_attr;
36803+ device_attribute_no_const label_attr;
36804+ device_attribute_no_const input_attr;
36805+ device_attribute_no_const limit1_attr;
36806+ device_attribute_no_const limit2_attr;
36807 char label_attr_name[ATTR_NAME_SIZE];
36808 char input_attr_name[ATTR_NAME_SIZE];
36809 char limit1_attr_name[ATTR_NAME_SIZE];
36810@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36811 static struct device_attribute atk_name_attr =
36812 __ATTR(name, 0444, atk_name_show, NULL);
36813
36814-static void atk_init_attribute(struct device_attribute *attr, char *name,
36815+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36816 sysfs_show_func show)
36817 {
36818 sysfs_attr_init(&attr->attr);
36819diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36820index 658ce3a..0d0c2f3 100644
36821--- a/drivers/hwmon/coretemp.c
36822+++ b/drivers/hwmon/coretemp.c
36823@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36824 return NOTIFY_OK;
36825 }
36826
36827-static struct notifier_block coretemp_cpu_notifier __refdata = {
36828+static struct notifier_block coretemp_cpu_notifier = {
36829 .notifier_call = coretemp_cpu_callback,
36830 };
36831
36832diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36833index 1429f6e..ee03d59 100644
36834--- a/drivers/hwmon/ibmaem.c
36835+++ b/drivers/hwmon/ibmaem.c
36836@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
36837 struct aem_rw_sensor_template *rw)
36838 {
36839 struct device *dev = &data->pdev->dev;
36840- struct sensor_device_attribute *sensors = data->sensors;
36841+ sensor_device_attribute_no_const *sensors = data->sensors;
36842 int err;
36843
36844 /* Set up read-only sensors */
36845diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
36846index 52b77af..aed1ddf 100644
36847--- a/drivers/hwmon/iio_hwmon.c
36848+++ b/drivers/hwmon/iio_hwmon.c
36849@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
36850 {
36851 struct device *dev = &pdev->dev;
36852 struct iio_hwmon_state *st;
36853- struct sensor_device_attribute *a;
36854+ sensor_device_attribute_no_const *a;
36855 int ret, i;
36856 int in_i = 1, temp_i = 1, curr_i = 1;
36857 enum iio_chan_type type;
36858diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36859index 9add6092..ee7ba3f 100644
36860--- a/drivers/hwmon/pmbus/pmbus_core.c
36861+++ b/drivers/hwmon/pmbus/pmbus_core.c
36862@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
36863 return 0;
36864 }
36865
36866-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36867+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
36868 const char *name,
36869 umode_t mode,
36870 ssize_t (*show)(struct device *dev,
36871@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36872 dev_attr->store = store;
36873 }
36874
36875-static void pmbus_attr_init(struct sensor_device_attribute *a,
36876+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
36877 const char *name,
36878 umode_t mode,
36879 ssize_t (*show)(struct device *dev,
36880@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
36881 u16 reg, u8 mask)
36882 {
36883 struct pmbus_boolean *boolean;
36884- struct sensor_device_attribute *a;
36885+ sensor_device_attribute_no_const *a;
36886
36887 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
36888 if (!boolean)
36889@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
36890 bool update, bool readonly)
36891 {
36892 struct pmbus_sensor *sensor;
36893- struct device_attribute *a;
36894+ device_attribute_no_const *a;
36895
36896 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
36897 if (!sensor)
36898@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
36899 const char *lstring, int index)
36900 {
36901 struct pmbus_label *label;
36902- struct device_attribute *a;
36903+ device_attribute_no_const *a;
36904
36905 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
36906 if (!label)
36907diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36908index 2507f90..1645765 100644
36909--- a/drivers/hwmon/sht15.c
36910+++ b/drivers/hwmon/sht15.c
36911@@ -169,7 +169,7 @@ struct sht15_data {
36912 int supply_uv;
36913 bool supply_uv_valid;
36914 struct work_struct update_supply_work;
36915- atomic_t interrupt_handled;
36916+ atomic_unchecked_t interrupt_handled;
36917 };
36918
36919 /**
36920@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
36921 ret = gpio_direction_input(data->pdata->gpio_data);
36922 if (ret)
36923 return ret;
36924- atomic_set(&data->interrupt_handled, 0);
36925+ atomic_set_unchecked(&data->interrupt_handled, 0);
36926
36927 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36928 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36929 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36930 /* Only relevant if the interrupt hasn't occurred. */
36931- if (!atomic_read(&data->interrupt_handled))
36932+ if (!atomic_read_unchecked(&data->interrupt_handled))
36933 schedule_work(&data->read_work);
36934 }
36935 ret = wait_event_timeout(data->wait_queue,
36936@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36937
36938 /* First disable the interrupt */
36939 disable_irq_nosync(irq);
36940- atomic_inc(&data->interrupt_handled);
36941+ atomic_inc_unchecked(&data->interrupt_handled);
36942 /* Then schedule a reading work struct */
36943 if (data->state != SHT15_READING_NOTHING)
36944 schedule_work(&data->read_work);
36945@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36946 * If not, then start the interrupt again - care here as could
36947 * have gone low in meantime so verify it hasn't!
36948 */
36949- atomic_set(&data->interrupt_handled, 0);
36950+ atomic_set_unchecked(&data->interrupt_handled, 0);
36951 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36952 /* If still not occurred or another handler was scheduled */
36953 if (gpio_get_value(data->pdata->gpio_data)
36954- || atomic_read(&data->interrupt_handled))
36955+ || atomic_read_unchecked(&data->interrupt_handled))
36956 return;
36957 }
36958
36959diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36960index 76f157b..9c0db1b 100644
36961--- a/drivers/hwmon/via-cputemp.c
36962+++ b/drivers/hwmon/via-cputemp.c
36963@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36964 return NOTIFY_OK;
36965 }
36966
36967-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36968+static struct notifier_block via_cputemp_cpu_notifier = {
36969 .notifier_call = via_cputemp_cpu_callback,
36970 };
36971
36972diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36973index 07f01ac..d79ad3d 100644
36974--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36975+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36976@@ -43,7 +43,7 @@
36977 extern struct i2c_adapter amd756_smbus;
36978
36979 static struct i2c_adapter *s4882_adapter;
36980-static struct i2c_algorithm *s4882_algo;
36981+static i2c_algorithm_no_const *s4882_algo;
36982
36983 /* Wrapper access functions for multiplexed SMBus */
36984 static DEFINE_MUTEX(amd756_lock);
36985diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36986index 2ca268d..c6acbdf 100644
36987--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36988+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36989@@ -41,7 +41,7 @@
36990 extern struct i2c_adapter *nforce2_smbus;
36991
36992 static struct i2c_adapter *s4985_adapter;
36993-static struct i2c_algorithm *s4985_algo;
36994+static i2c_algorithm_no_const *s4985_algo;
36995
36996 /* Wrapper access functions for multiplexed SMBus */
36997 static DEFINE_MUTEX(nforce2_lock);
36998diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
36999index c3ccdea..5b3dc1a 100644
37000--- a/drivers/i2c/i2c-dev.c
37001+++ b/drivers/i2c/i2c-dev.c
37002@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
37003 break;
37004 }
37005
37006- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
37007+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
37008 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
37009 if (IS_ERR(rdwr_pa[i].buf)) {
37010 res = PTR_ERR(rdwr_pa[i].buf);
37011diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
37012index 2ff6204..218c16e 100644
37013--- a/drivers/ide/ide-cd.c
37014+++ b/drivers/ide/ide-cd.c
37015@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
37016 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
37017 if ((unsigned long)buf & alignment
37018 || blk_rq_bytes(rq) & q->dma_pad_mask
37019- || object_is_on_stack(buf))
37020+ || object_starts_on_stack(buf))
37021 drive->dma = 0;
37022 }
37023 }
37024diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
37025index e145931..08bfc59 100644
37026--- a/drivers/iio/industrialio-core.c
37027+++ b/drivers/iio/industrialio-core.c
37028@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
37029 }
37030
37031 static
37032-int __iio_device_attr_init(struct device_attribute *dev_attr,
37033+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
37034 const char *postfix,
37035 struct iio_chan_spec const *chan,
37036 ssize_t (*readfunc)(struct device *dev,
37037diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
37038index 784b97c..c9ceadf 100644
37039--- a/drivers/infiniband/core/cm.c
37040+++ b/drivers/infiniband/core/cm.c
37041@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
37042
37043 struct cm_counter_group {
37044 struct kobject obj;
37045- atomic_long_t counter[CM_ATTR_COUNT];
37046+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
37047 };
37048
37049 struct cm_counter_attribute {
37050@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
37051 struct ib_mad_send_buf *msg = NULL;
37052 int ret;
37053
37054- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37055+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37056 counter[CM_REQ_COUNTER]);
37057
37058 /* Quick state check to discard duplicate REQs. */
37059@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
37060 if (!cm_id_priv)
37061 return;
37062
37063- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37064+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37065 counter[CM_REP_COUNTER]);
37066 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
37067 if (ret)
37068@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
37069 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
37070 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
37071 spin_unlock_irq(&cm_id_priv->lock);
37072- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37073+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37074 counter[CM_RTU_COUNTER]);
37075 goto out;
37076 }
37077@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
37078 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
37079 dreq_msg->local_comm_id);
37080 if (!cm_id_priv) {
37081- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37082+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37083 counter[CM_DREQ_COUNTER]);
37084 cm_issue_drep(work->port, work->mad_recv_wc);
37085 return -EINVAL;
37086@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
37087 case IB_CM_MRA_REP_RCVD:
37088 break;
37089 case IB_CM_TIMEWAIT:
37090- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37091+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37092 counter[CM_DREQ_COUNTER]);
37093 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37094 goto unlock;
37095@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
37096 cm_free_msg(msg);
37097 goto deref;
37098 case IB_CM_DREQ_RCVD:
37099- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37100+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37101 counter[CM_DREQ_COUNTER]);
37102 goto unlock;
37103 default:
37104@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
37105 ib_modify_mad(cm_id_priv->av.port->mad_agent,
37106 cm_id_priv->msg, timeout)) {
37107 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
37108- atomic_long_inc(&work->port->
37109+ atomic_long_inc_unchecked(&work->port->
37110 counter_group[CM_RECV_DUPLICATES].
37111 counter[CM_MRA_COUNTER]);
37112 goto out;
37113@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
37114 break;
37115 case IB_CM_MRA_REQ_RCVD:
37116 case IB_CM_MRA_REP_RCVD:
37117- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37118+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37119 counter[CM_MRA_COUNTER]);
37120 /* fall through */
37121 default:
37122@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
37123 case IB_CM_LAP_IDLE:
37124 break;
37125 case IB_CM_MRA_LAP_SENT:
37126- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37127+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37128 counter[CM_LAP_COUNTER]);
37129 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
37130 goto unlock;
37131@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
37132 cm_free_msg(msg);
37133 goto deref;
37134 case IB_CM_LAP_RCVD:
37135- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37136+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37137 counter[CM_LAP_COUNTER]);
37138 goto unlock;
37139 default:
37140@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
37141 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
37142 if (cur_cm_id_priv) {
37143 spin_unlock_irq(&cm.lock);
37144- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
37145+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
37146 counter[CM_SIDR_REQ_COUNTER]);
37147 goto out; /* Duplicate message. */
37148 }
37149@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
37150 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
37151 msg->retries = 1;
37152
37153- atomic_long_add(1 + msg->retries,
37154+ atomic_long_add_unchecked(1 + msg->retries,
37155 &port->counter_group[CM_XMIT].counter[attr_index]);
37156 if (msg->retries)
37157- atomic_long_add(msg->retries,
37158+ atomic_long_add_unchecked(msg->retries,
37159 &port->counter_group[CM_XMIT_RETRIES].
37160 counter[attr_index]);
37161
37162@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
37163 }
37164
37165 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
37166- atomic_long_inc(&port->counter_group[CM_RECV].
37167+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
37168 counter[attr_id - CM_ATTR_ID_OFFSET]);
37169
37170 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
37171@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
37172 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
37173
37174 return sprintf(buf, "%ld\n",
37175- atomic_long_read(&group->counter[cm_attr->index]));
37176+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
37177 }
37178
37179 static const struct sysfs_ops cm_counter_ops = {
37180diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
37181index 9f5ad7c..588cd84 100644
37182--- a/drivers/infiniband/core/fmr_pool.c
37183+++ b/drivers/infiniband/core/fmr_pool.c
37184@@ -98,8 +98,8 @@ struct ib_fmr_pool {
37185
37186 struct task_struct *thread;
37187
37188- atomic_t req_ser;
37189- atomic_t flush_ser;
37190+ atomic_unchecked_t req_ser;
37191+ atomic_unchecked_t flush_ser;
37192
37193 wait_queue_head_t force_wait;
37194 };
37195@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37196 struct ib_fmr_pool *pool = pool_ptr;
37197
37198 do {
37199- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
37200+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
37201 ib_fmr_batch_release(pool);
37202
37203- atomic_inc(&pool->flush_ser);
37204+ atomic_inc_unchecked(&pool->flush_ser);
37205 wake_up_interruptible(&pool->force_wait);
37206
37207 if (pool->flush_function)
37208@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
37209 }
37210
37211 set_current_state(TASK_INTERRUPTIBLE);
37212- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
37213+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
37214 !kthread_should_stop())
37215 schedule();
37216 __set_current_state(TASK_RUNNING);
37217@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
37218 pool->dirty_watermark = params->dirty_watermark;
37219 pool->dirty_len = 0;
37220 spin_lock_init(&pool->pool_lock);
37221- atomic_set(&pool->req_ser, 0);
37222- atomic_set(&pool->flush_ser, 0);
37223+ atomic_set_unchecked(&pool->req_ser, 0);
37224+ atomic_set_unchecked(&pool->flush_ser, 0);
37225 init_waitqueue_head(&pool->force_wait);
37226
37227 pool->thread = kthread_run(ib_fmr_cleanup_thread,
37228@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
37229 }
37230 spin_unlock_irq(&pool->pool_lock);
37231
37232- serial = atomic_inc_return(&pool->req_ser);
37233+ serial = atomic_inc_return_unchecked(&pool->req_ser);
37234 wake_up_process(pool->thread);
37235
37236 if (wait_event_interruptible(pool->force_wait,
37237- atomic_read(&pool->flush_ser) - serial >= 0))
37238+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
37239 return -EINTR;
37240
37241 return 0;
37242@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
37243 } else {
37244 list_add_tail(&fmr->list, &pool->dirty_list);
37245 if (++pool->dirty_len >= pool->dirty_watermark) {
37246- atomic_inc(&pool->req_ser);
37247+ atomic_inc_unchecked(&pool->req_ser);
37248 wake_up_process(pool->thread);
37249 }
37250 }
37251diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
37252index 4cb8eb2..146bf60 100644
37253--- a/drivers/infiniband/hw/cxgb4/mem.c
37254+++ b/drivers/infiniband/hw/cxgb4/mem.c
37255@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37256 int err;
37257 struct fw_ri_tpte tpt;
37258 u32 stag_idx;
37259- static atomic_t key;
37260+ static atomic_unchecked_t key;
37261
37262 if (c4iw_fatal_error(rdev))
37263 return -EIO;
37264@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
37265 if (rdev->stats.stag.cur > rdev->stats.stag.max)
37266 rdev->stats.stag.max = rdev->stats.stag.cur;
37267 mutex_unlock(&rdev->stats.lock);
37268- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
37269+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
37270 }
37271 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
37272 __func__, stag_state, type, pdid, stag_idx);
37273diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
37274index 79b3dbc..96e5fcc 100644
37275--- a/drivers/infiniband/hw/ipath/ipath_rc.c
37276+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
37277@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37278 struct ib_atomic_eth *ateth;
37279 struct ipath_ack_entry *e;
37280 u64 vaddr;
37281- atomic64_t *maddr;
37282+ atomic64_unchecked_t *maddr;
37283 u64 sdata;
37284 u32 rkey;
37285 u8 next;
37286@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
37287 IB_ACCESS_REMOTE_ATOMIC)))
37288 goto nack_acc_unlck;
37289 /* Perform atomic OP and save result. */
37290- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37291+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37292 sdata = be64_to_cpu(ateth->swap_data);
37293 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37294 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37295- (u64) atomic64_add_return(sdata, maddr) - sdata :
37296+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37297 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37298 be64_to_cpu(ateth->compare_data),
37299 sdata);
37300diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37301index 1f95bba..9530f87 100644
37302--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37303+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37304@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37305 unsigned long flags;
37306 struct ib_wc wc;
37307 u64 sdata;
37308- atomic64_t *maddr;
37309+ atomic64_unchecked_t *maddr;
37310 enum ib_wc_status send_status;
37311
37312 /*
37313@@ -382,11 +382,11 @@ again:
37314 IB_ACCESS_REMOTE_ATOMIC)))
37315 goto acc_err;
37316 /* Perform atomic OP and save result. */
37317- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37318+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37319 sdata = wqe->wr.wr.atomic.compare_add;
37320 *(u64 *) sqp->s_sge.sge.vaddr =
37321 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37322- (u64) atomic64_add_return(sdata, maddr) - sdata :
37323+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37324 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37325 sdata, wqe->wr.wr.atomic.swap);
37326 goto send_comp;
37327diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37328index 9d3e5c1..d9afe4a 100644
37329--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37330+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37331@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37332 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37333 }
37334
37335-int mthca_QUERY_FW(struct mthca_dev *dev)
37336+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37337 {
37338 struct mthca_mailbox *mailbox;
37339 u32 *outbox;
37340diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37341index ed9a989..e0c5871 100644
37342--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37343+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37344@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37345 return key;
37346 }
37347
37348-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37349+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37350 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37351 {
37352 struct mthca_mailbox *mailbox;
37353diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37354index 4291410..d2ab1fb 100644
37355--- a/drivers/infiniband/hw/nes/nes.c
37356+++ b/drivers/infiniband/hw/nes/nes.c
37357@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37358 LIST_HEAD(nes_adapter_list);
37359 static LIST_HEAD(nes_dev_list);
37360
37361-atomic_t qps_destroyed;
37362+atomic_unchecked_t qps_destroyed;
37363
37364 static unsigned int ee_flsh_adapter;
37365 static unsigned int sysfs_nonidx_addr;
37366@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37367 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37368 struct nes_adapter *nesadapter = nesdev->nesadapter;
37369
37370- atomic_inc(&qps_destroyed);
37371+ atomic_inc_unchecked(&qps_destroyed);
37372
37373 /* Free the control structures */
37374
37375diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37376index 33cc589..3bd6538 100644
37377--- a/drivers/infiniband/hw/nes/nes.h
37378+++ b/drivers/infiniband/hw/nes/nes.h
37379@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37380 extern unsigned int wqm_quanta;
37381 extern struct list_head nes_adapter_list;
37382
37383-extern atomic_t cm_connects;
37384-extern atomic_t cm_accepts;
37385-extern atomic_t cm_disconnects;
37386-extern atomic_t cm_closes;
37387-extern atomic_t cm_connecteds;
37388-extern atomic_t cm_connect_reqs;
37389-extern atomic_t cm_rejects;
37390-extern atomic_t mod_qp_timouts;
37391-extern atomic_t qps_created;
37392-extern atomic_t qps_destroyed;
37393-extern atomic_t sw_qps_destroyed;
37394+extern atomic_unchecked_t cm_connects;
37395+extern atomic_unchecked_t cm_accepts;
37396+extern atomic_unchecked_t cm_disconnects;
37397+extern atomic_unchecked_t cm_closes;
37398+extern atomic_unchecked_t cm_connecteds;
37399+extern atomic_unchecked_t cm_connect_reqs;
37400+extern atomic_unchecked_t cm_rejects;
37401+extern atomic_unchecked_t mod_qp_timouts;
37402+extern atomic_unchecked_t qps_created;
37403+extern atomic_unchecked_t qps_destroyed;
37404+extern atomic_unchecked_t sw_qps_destroyed;
37405 extern u32 mh_detected;
37406 extern u32 mh_pauses_sent;
37407 extern u32 cm_packets_sent;
37408@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37409 extern u32 cm_packets_received;
37410 extern u32 cm_packets_dropped;
37411 extern u32 cm_packets_retrans;
37412-extern atomic_t cm_listens_created;
37413-extern atomic_t cm_listens_destroyed;
37414+extern atomic_unchecked_t cm_listens_created;
37415+extern atomic_unchecked_t cm_listens_destroyed;
37416 extern u32 cm_backlog_drops;
37417-extern atomic_t cm_loopbacks;
37418-extern atomic_t cm_nodes_created;
37419-extern atomic_t cm_nodes_destroyed;
37420-extern atomic_t cm_accel_dropped_pkts;
37421-extern atomic_t cm_resets_recvd;
37422-extern atomic_t pau_qps_created;
37423-extern atomic_t pau_qps_destroyed;
37424+extern atomic_unchecked_t cm_loopbacks;
37425+extern atomic_unchecked_t cm_nodes_created;
37426+extern atomic_unchecked_t cm_nodes_destroyed;
37427+extern atomic_unchecked_t cm_accel_dropped_pkts;
37428+extern atomic_unchecked_t cm_resets_recvd;
37429+extern atomic_unchecked_t pau_qps_created;
37430+extern atomic_unchecked_t pau_qps_destroyed;
37431
37432 extern u32 int_mod_timer_init;
37433 extern u32 int_mod_cq_depth_256;
37434diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37435index 24b9f1a..00fd004 100644
37436--- a/drivers/infiniband/hw/nes/nes_cm.c
37437+++ b/drivers/infiniband/hw/nes/nes_cm.c
37438@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37439 u32 cm_packets_retrans;
37440 u32 cm_packets_created;
37441 u32 cm_packets_received;
37442-atomic_t cm_listens_created;
37443-atomic_t cm_listens_destroyed;
37444+atomic_unchecked_t cm_listens_created;
37445+atomic_unchecked_t cm_listens_destroyed;
37446 u32 cm_backlog_drops;
37447-atomic_t cm_loopbacks;
37448-atomic_t cm_nodes_created;
37449-atomic_t cm_nodes_destroyed;
37450-atomic_t cm_accel_dropped_pkts;
37451-atomic_t cm_resets_recvd;
37452+atomic_unchecked_t cm_loopbacks;
37453+atomic_unchecked_t cm_nodes_created;
37454+atomic_unchecked_t cm_nodes_destroyed;
37455+atomic_unchecked_t cm_accel_dropped_pkts;
37456+atomic_unchecked_t cm_resets_recvd;
37457
37458 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37459 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37460@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37461
37462 static struct nes_cm_core *g_cm_core;
37463
37464-atomic_t cm_connects;
37465-atomic_t cm_accepts;
37466-atomic_t cm_disconnects;
37467-atomic_t cm_closes;
37468-atomic_t cm_connecteds;
37469-atomic_t cm_connect_reqs;
37470-atomic_t cm_rejects;
37471+atomic_unchecked_t cm_connects;
37472+atomic_unchecked_t cm_accepts;
37473+atomic_unchecked_t cm_disconnects;
37474+atomic_unchecked_t cm_closes;
37475+atomic_unchecked_t cm_connecteds;
37476+atomic_unchecked_t cm_connect_reqs;
37477+atomic_unchecked_t cm_rejects;
37478
37479 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37480 {
37481@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37482 kfree(listener);
37483 listener = NULL;
37484 ret = 0;
37485- atomic_inc(&cm_listens_destroyed);
37486+ atomic_inc_unchecked(&cm_listens_destroyed);
37487 } else {
37488 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37489 }
37490@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37491 cm_node->rem_mac);
37492
37493 add_hte_node(cm_core, cm_node);
37494- atomic_inc(&cm_nodes_created);
37495+ atomic_inc_unchecked(&cm_nodes_created);
37496
37497 return cm_node;
37498 }
37499@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37500 }
37501
37502 atomic_dec(&cm_core->node_cnt);
37503- atomic_inc(&cm_nodes_destroyed);
37504+ atomic_inc_unchecked(&cm_nodes_destroyed);
37505 nesqp = cm_node->nesqp;
37506 if (nesqp) {
37507 nesqp->cm_node = NULL;
37508@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37509
37510 static void drop_packet(struct sk_buff *skb)
37511 {
37512- atomic_inc(&cm_accel_dropped_pkts);
37513+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37514 dev_kfree_skb_any(skb);
37515 }
37516
37517@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37518 {
37519
37520 int reset = 0; /* whether to send reset in case of err.. */
37521- atomic_inc(&cm_resets_recvd);
37522+ atomic_inc_unchecked(&cm_resets_recvd);
37523 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37524 " refcnt=%d\n", cm_node, cm_node->state,
37525 atomic_read(&cm_node->ref_count));
37526@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37527 rem_ref_cm_node(cm_node->cm_core, cm_node);
37528 return NULL;
37529 }
37530- atomic_inc(&cm_loopbacks);
37531+ atomic_inc_unchecked(&cm_loopbacks);
37532 loopbackremotenode->loopbackpartner = cm_node;
37533 loopbackremotenode->tcp_cntxt.rcv_wscale =
37534 NES_CM_DEFAULT_RCV_WND_SCALE;
37535@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37536 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37537 else {
37538 rem_ref_cm_node(cm_core, cm_node);
37539- atomic_inc(&cm_accel_dropped_pkts);
37540+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37541 dev_kfree_skb_any(skb);
37542 }
37543 break;
37544@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37545
37546 if ((cm_id) && (cm_id->event_handler)) {
37547 if (issue_disconn) {
37548- atomic_inc(&cm_disconnects);
37549+ atomic_inc_unchecked(&cm_disconnects);
37550 cm_event.event = IW_CM_EVENT_DISCONNECT;
37551 cm_event.status = disconn_status;
37552 cm_event.local_addr = cm_id->local_addr;
37553@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37554 }
37555
37556 if (issue_close) {
37557- atomic_inc(&cm_closes);
37558+ atomic_inc_unchecked(&cm_closes);
37559 nes_disconnect(nesqp, 1);
37560
37561 cm_id->provider_data = nesqp;
37562@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37563
37564 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37565 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37566- atomic_inc(&cm_accepts);
37567+ atomic_inc_unchecked(&cm_accepts);
37568
37569 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37570 netdev_refcnt_read(nesvnic->netdev));
37571@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37572 struct nes_cm_core *cm_core;
37573 u8 *start_buff;
37574
37575- atomic_inc(&cm_rejects);
37576+ atomic_inc_unchecked(&cm_rejects);
37577 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37578 loopback = cm_node->loopbackpartner;
37579 cm_core = cm_node->cm_core;
37580@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37581 ntohl(cm_id->local_addr.sin_addr.s_addr),
37582 ntohs(cm_id->local_addr.sin_port));
37583
37584- atomic_inc(&cm_connects);
37585+ atomic_inc_unchecked(&cm_connects);
37586 nesqp->active_conn = 1;
37587
37588 /* cache the cm_id in the qp */
37589@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37590 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37591 return err;
37592 }
37593- atomic_inc(&cm_listens_created);
37594+ atomic_inc_unchecked(&cm_listens_created);
37595 }
37596
37597 cm_id->add_ref(cm_id);
37598@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37599
37600 if (nesqp->destroyed)
37601 return;
37602- atomic_inc(&cm_connecteds);
37603+ atomic_inc_unchecked(&cm_connecteds);
37604 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37605 " local port 0x%04X. jiffies = %lu.\n",
37606 nesqp->hwqp.qp_id,
37607@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37608
37609 cm_id->add_ref(cm_id);
37610 ret = cm_id->event_handler(cm_id, &cm_event);
37611- atomic_inc(&cm_closes);
37612+ atomic_inc_unchecked(&cm_closes);
37613 cm_event.event = IW_CM_EVENT_CLOSE;
37614 cm_event.status = 0;
37615 cm_event.provider_data = cm_id->provider_data;
37616@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37617 return;
37618 cm_id = cm_node->cm_id;
37619
37620- atomic_inc(&cm_connect_reqs);
37621+ atomic_inc_unchecked(&cm_connect_reqs);
37622 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37623 cm_node, cm_id, jiffies);
37624
37625@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37626 return;
37627 cm_id = cm_node->cm_id;
37628
37629- atomic_inc(&cm_connect_reqs);
37630+ atomic_inc_unchecked(&cm_connect_reqs);
37631 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37632 cm_node, cm_id, jiffies);
37633
37634diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37635index 4166452..fc952c3 100644
37636--- a/drivers/infiniband/hw/nes/nes_mgt.c
37637+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37638@@ -40,8 +40,8 @@
37639 #include "nes.h"
37640 #include "nes_mgt.h"
37641
37642-atomic_t pau_qps_created;
37643-atomic_t pau_qps_destroyed;
37644+atomic_unchecked_t pau_qps_created;
37645+atomic_unchecked_t pau_qps_destroyed;
37646
37647 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37648 {
37649@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37650 {
37651 struct sk_buff *skb;
37652 unsigned long flags;
37653- atomic_inc(&pau_qps_destroyed);
37654+ atomic_inc_unchecked(&pau_qps_destroyed);
37655
37656 /* Free packets that have not yet been forwarded */
37657 /* Lock is acquired by skb_dequeue when removing the skb */
37658@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37659 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37660 skb_queue_head_init(&nesqp->pau_list);
37661 spin_lock_init(&nesqp->pau_lock);
37662- atomic_inc(&pau_qps_created);
37663+ atomic_inc_unchecked(&pau_qps_created);
37664 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37665 }
37666
37667diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37668index 49eb511..a774366 100644
37669--- a/drivers/infiniband/hw/nes/nes_nic.c
37670+++ b/drivers/infiniband/hw/nes/nes_nic.c
37671@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37672 target_stat_values[++index] = mh_detected;
37673 target_stat_values[++index] = mh_pauses_sent;
37674 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37675- target_stat_values[++index] = atomic_read(&cm_connects);
37676- target_stat_values[++index] = atomic_read(&cm_accepts);
37677- target_stat_values[++index] = atomic_read(&cm_disconnects);
37678- target_stat_values[++index] = atomic_read(&cm_connecteds);
37679- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37680- target_stat_values[++index] = atomic_read(&cm_rejects);
37681- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37682- target_stat_values[++index] = atomic_read(&qps_created);
37683- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37684- target_stat_values[++index] = atomic_read(&qps_destroyed);
37685- target_stat_values[++index] = atomic_read(&cm_closes);
37686+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37687+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37688+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37689+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37690+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37691+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37692+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37693+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37694+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37695+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37696+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37697 target_stat_values[++index] = cm_packets_sent;
37698 target_stat_values[++index] = cm_packets_bounced;
37699 target_stat_values[++index] = cm_packets_created;
37700 target_stat_values[++index] = cm_packets_received;
37701 target_stat_values[++index] = cm_packets_dropped;
37702 target_stat_values[++index] = cm_packets_retrans;
37703- target_stat_values[++index] = atomic_read(&cm_listens_created);
37704- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37705+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37706+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37707 target_stat_values[++index] = cm_backlog_drops;
37708- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37709- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37710- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37711- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37712- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37713+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37714+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37715+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37716+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37717+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37718 target_stat_values[++index] = nesadapter->free_4kpbl;
37719 target_stat_values[++index] = nesadapter->free_256pbl;
37720 target_stat_values[++index] = int_mod_timer_init;
37721 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37722 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37723 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37724- target_stat_values[++index] = atomic_read(&pau_qps_created);
37725- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37726+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37727+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37728 }
37729
37730 /**
37731diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37732index 8f67fe2..8960859 100644
37733--- a/drivers/infiniband/hw/nes/nes_verbs.c
37734+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37735@@ -46,9 +46,9 @@
37736
37737 #include <rdma/ib_umem.h>
37738
37739-atomic_t mod_qp_timouts;
37740-atomic_t qps_created;
37741-atomic_t sw_qps_destroyed;
37742+atomic_unchecked_t mod_qp_timouts;
37743+atomic_unchecked_t qps_created;
37744+atomic_unchecked_t sw_qps_destroyed;
37745
37746 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37747
37748@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37749 if (init_attr->create_flags)
37750 return ERR_PTR(-EINVAL);
37751
37752- atomic_inc(&qps_created);
37753+ atomic_inc_unchecked(&qps_created);
37754 switch (init_attr->qp_type) {
37755 case IB_QPT_RC:
37756 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37757@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37758 struct iw_cm_event cm_event;
37759 int ret = 0;
37760
37761- atomic_inc(&sw_qps_destroyed);
37762+ atomic_inc_unchecked(&sw_qps_destroyed);
37763 nesqp->destroyed = 1;
37764
37765 /* Blow away the connection if it exists. */
37766diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37767index 4d11575..3e890e5 100644
37768--- a/drivers/infiniband/hw/qib/qib.h
37769+++ b/drivers/infiniband/hw/qib/qib.h
37770@@ -51,6 +51,7 @@
37771 #include <linux/completion.h>
37772 #include <linux/kref.h>
37773 #include <linux/sched.h>
37774+#include <linux/slab.h>
37775
37776 #include "qib_common.h"
37777 #include "qib_verbs.h"
37778diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37779index da739d9..da1c7f4 100644
37780--- a/drivers/input/gameport/gameport.c
37781+++ b/drivers/input/gameport/gameport.c
37782@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37783 */
37784 static void gameport_init_port(struct gameport *gameport)
37785 {
37786- static atomic_t gameport_no = ATOMIC_INIT(0);
37787+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37788
37789 __module_get(THIS_MODULE);
37790
37791 mutex_init(&gameport->drv_mutex);
37792 device_initialize(&gameport->dev);
37793 dev_set_name(&gameport->dev, "gameport%lu",
37794- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37795+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37796 gameport->dev.bus = &gameport_bus;
37797 gameport->dev.release = gameport_release_port;
37798 if (gameport->parent)
37799diff --git a/drivers/input/input.c b/drivers/input/input.c
37800index c044699..174d71a 100644
37801--- a/drivers/input/input.c
37802+++ b/drivers/input/input.c
37803@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37804 */
37805 int input_register_device(struct input_dev *dev)
37806 {
37807- static atomic_t input_no = ATOMIC_INIT(0);
37808+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37809 struct input_devres *devres = NULL;
37810 struct input_handler *handler;
37811 unsigned int packet_size;
37812@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37813 dev->setkeycode = input_default_setkeycode;
37814
37815 dev_set_name(&dev->dev, "input%ld",
37816- (unsigned long) atomic_inc_return(&input_no) - 1);
37817+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37818
37819 error = device_add(&dev->dev);
37820 if (error)
37821diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37822index 04c69af..5f92d00 100644
37823--- a/drivers/input/joystick/sidewinder.c
37824+++ b/drivers/input/joystick/sidewinder.c
37825@@ -30,6 +30,7 @@
37826 #include <linux/kernel.h>
37827 #include <linux/module.h>
37828 #include <linux/slab.h>
37829+#include <linux/sched.h>
37830 #include <linux/init.h>
37831 #include <linux/input.h>
37832 #include <linux/gameport.h>
37833diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37834index fa061d4..4a6957c 100644
37835--- a/drivers/input/joystick/xpad.c
37836+++ b/drivers/input/joystick/xpad.c
37837@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37838
37839 static int xpad_led_probe(struct usb_xpad *xpad)
37840 {
37841- static atomic_t led_seq = ATOMIC_INIT(0);
37842+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37843 long led_no;
37844 struct xpad_led *led;
37845 struct led_classdev *led_cdev;
37846@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37847 if (!led)
37848 return -ENOMEM;
37849
37850- led_no = (long)atomic_inc_return(&led_seq) - 1;
37851+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37852
37853 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37854 led->xpad = xpad;
37855diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37856index 2f0b39d..7370f13 100644
37857--- a/drivers/input/mouse/psmouse.h
37858+++ b/drivers/input/mouse/psmouse.h
37859@@ -116,7 +116,7 @@ struct psmouse_attribute {
37860 ssize_t (*set)(struct psmouse *psmouse, void *data,
37861 const char *buf, size_t count);
37862 bool protect;
37863-};
37864+} __do_const;
37865 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37866
37867 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37868diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37869index 4c842c3..590b0bf 100644
37870--- a/drivers/input/mousedev.c
37871+++ b/drivers/input/mousedev.c
37872@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37873
37874 spin_unlock_irq(&client->packet_lock);
37875
37876- if (copy_to_user(buffer, data, count))
37877+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37878 return -EFAULT;
37879
37880 return count;
37881diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37882index 25fc597..558bf3b3 100644
37883--- a/drivers/input/serio/serio.c
37884+++ b/drivers/input/serio/serio.c
37885@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37886 */
37887 static void serio_init_port(struct serio *serio)
37888 {
37889- static atomic_t serio_no = ATOMIC_INIT(0);
37890+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37891
37892 __module_get(THIS_MODULE);
37893
37894@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37895 mutex_init(&serio->drv_mutex);
37896 device_initialize(&serio->dev);
37897 dev_set_name(&serio->dev, "serio%ld",
37898- (long)atomic_inc_return(&serio_no) - 1);
37899+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37900 serio->dev.bus = &serio_bus;
37901 serio->dev.release = serio_release_port;
37902 serio->dev.groups = serio_device_attr_groups;
37903diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37904index d8f98b1..f62a640 100644
37905--- a/drivers/iommu/iommu.c
37906+++ b/drivers/iommu/iommu.c
37907@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
37908 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37909 {
37910 bus_register_notifier(bus, &iommu_bus_nb);
37911- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37912+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37913 }
37914
37915 /**
37916diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
37917index dcfea4e..f4226b2 100644
37918--- a/drivers/iommu/irq_remapping.c
37919+++ b/drivers/iommu/irq_remapping.c
37920@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
37921 void panic_if_irq_remap(const char *msg)
37922 {
37923 if (irq_remapping_enabled)
37924- panic(msg);
37925+ panic("%s", msg);
37926 }
37927
37928 static void ir_ack_apic_edge(struct irq_data *data)
37929@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
37930
37931 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
37932 {
37933- chip->irq_print_chip = ir_print_prefix;
37934- chip->irq_ack = ir_ack_apic_edge;
37935- chip->irq_eoi = ir_ack_apic_level;
37936- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37937+ pax_open_kernel();
37938+ *(void **)&chip->irq_print_chip = ir_print_prefix;
37939+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
37940+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
37941+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37942+ pax_close_kernel();
37943 }
37944
37945 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
37946diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
37947index 19ceaa6..3625818 100644
37948--- a/drivers/irqchip/irq-gic.c
37949+++ b/drivers/irqchip/irq-gic.c
37950@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
37951 * Supported arch specific GIC irq extension.
37952 * Default make them NULL.
37953 */
37954-struct irq_chip gic_arch_extn = {
37955+irq_chip_no_const gic_arch_extn = {
37956 .irq_eoi = NULL,
37957 .irq_mask = NULL,
37958 .irq_unmask = NULL,
37959@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
37960 chained_irq_exit(chip, desc);
37961 }
37962
37963-static struct irq_chip gic_chip = {
37964+static irq_chip_no_const gic_chip __read_only = {
37965 .name = "GIC",
37966 .irq_mask = gic_mask_irq,
37967 .irq_unmask = gic_unmask_irq,
37968diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37969index ac6f72b..81150f2 100644
37970--- a/drivers/isdn/capi/capi.c
37971+++ b/drivers/isdn/capi/capi.c
37972@@ -81,8 +81,8 @@ struct capiminor {
37973
37974 struct capi20_appl *ap;
37975 u32 ncci;
37976- atomic_t datahandle;
37977- atomic_t msgid;
37978+ atomic_unchecked_t datahandle;
37979+ atomic_unchecked_t msgid;
37980
37981 struct tty_port port;
37982 int ttyinstop;
37983@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37984 capimsg_setu16(s, 2, mp->ap->applid);
37985 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37986 capimsg_setu8 (s, 5, CAPI_RESP);
37987- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37988+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37989 capimsg_setu32(s, 8, mp->ncci);
37990 capimsg_setu16(s, 12, datahandle);
37991 }
37992@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37993 mp->outbytes -= len;
37994 spin_unlock_bh(&mp->outlock);
37995
37996- datahandle = atomic_inc_return(&mp->datahandle);
37997+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37998 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37999 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
38000 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
38001 capimsg_setu16(skb->data, 2, mp->ap->applid);
38002 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
38003 capimsg_setu8 (skb->data, 5, CAPI_REQ);
38004- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
38005+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
38006 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
38007 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
38008 capimsg_setu16(skb->data, 16, len); /* Data length */
38009diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
38010index 600c79b..3752bab 100644
38011--- a/drivers/isdn/gigaset/interface.c
38012+++ b/drivers/isdn/gigaset/interface.c
38013@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
38014 }
38015 tty->driver_data = cs;
38016
38017- ++cs->port.count;
38018+ atomic_inc(&cs->port.count);
38019
38020- if (cs->port.count == 1) {
38021+ if (atomic_read(&cs->port.count) == 1) {
38022 tty_port_tty_set(&cs->port, tty);
38023 cs->port.low_latency = 1;
38024 }
38025@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
38026
38027 if (!cs->connected)
38028 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
38029- else if (!cs->port.count)
38030+ else if (!atomic_read(&cs->port.count))
38031 dev_warn(cs->dev, "%s: device not opened\n", __func__);
38032- else if (!--cs->port.count)
38033+ else if (!atomic_dec_return(&cs->port.count))
38034 tty_port_tty_set(&cs->port, NULL);
38035
38036 mutex_unlock(&cs->mutex);
38037diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
38038index 4d9b195..455075c 100644
38039--- a/drivers/isdn/hardware/avm/b1.c
38040+++ b/drivers/isdn/hardware/avm/b1.c
38041@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
38042 }
38043 if (left) {
38044 if (t4file->user) {
38045- if (copy_from_user(buf, dp, left))
38046+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38047 return -EFAULT;
38048 } else {
38049 memcpy(buf, dp, left);
38050@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
38051 }
38052 if (left) {
38053 if (config->user) {
38054- if (copy_from_user(buf, dp, left))
38055+ if (left > sizeof buf || copy_from_user(buf, dp, left))
38056 return -EFAULT;
38057 } else {
38058 memcpy(buf, dp, left);
38059diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
38060index 3c5f249..5fac4d0 100644
38061--- a/drivers/isdn/i4l/isdn_tty.c
38062+++ b/drivers/isdn/i4l/isdn_tty.c
38063@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
38064
38065 #ifdef ISDN_DEBUG_MODEM_OPEN
38066 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
38067- port->count);
38068+ atomic_read(&port->count));
38069 #endif
38070- port->count++;
38071+ atomic_inc(&port->count);
38072 port->tty = tty;
38073 /*
38074 * Start up serial port
38075@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38076 #endif
38077 return;
38078 }
38079- if ((tty->count == 1) && (port->count != 1)) {
38080+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
38081 /*
38082 * Uh, oh. tty->count is 1, which means that the tty
38083 * structure will be freed. Info->count should always
38084@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
38085 * serial port won't be shutdown.
38086 */
38087 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
38088- "info->count is %d\n", port->count);
38089- port->count = 1;
38090+ "info->count is %d\n", atomic_read(&port->count));
38091+ atomic_set(&port->count, 1);
38092 }
38093- if (--port->count < 0) {
38094+ if (atomic_dec_return(&port->count) < 0) {
38095 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
38096- info->line, port->count);
38097- port->count = 0;
38098+ info->line, atomic_read(&port->count));
38099+ atomic_set(&port->count, 0);
38100 }
38101- if (port->count) {
38102+ if (atomic_read(&port->count)) {
38103 #ifdef ISDN_DEBUG_MODEM_OPEN
38104 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
38105 #endif
38106@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
38107 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
38108 return;
38109 isdn_tty_shutdown(info);
38110- port->count = 0;
38111+ atomic_set(&port->count, 0);
38112 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38113 port->tty = NULL;
38114 wake_up_interruptible(&port->open_wait);
38115@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
38116 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
38117 modem_info *info = &dev->mdm.info[i];
38118
38119- if (info->port.count == 0)
38120+ if (atomic_read(&info->port.count) == 0)
38121 continue;
38122 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
38123 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
38124diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
38125index e74df7c..03a03ba 100644
38126--- a/drivers/isdn/icn/icn.c
38127+++ b/drivers/isdn/icn/icn.c
38128@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
38129 if (count > len)
38130 count = len;
38131 if (user) {
38132- if (copy_from_user(msg, buf, count))
38133+ if (count > sizeof msg || copy_from_user(msg, buf, count))
38134 return -EFAULT;
38135 } else
38136 memcpy(msg, buf, count);
38137diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
38138index 6a8405d..0bd1c7e 100644
38139--- a/drivers/leds/leds-clevo-mail.c
38140+++ b/drivers/leds/leds-clevo-mail.c
38141@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
38142 * detected as working, but in reality it is not) as low as
38143 * possible.
38144 */
38145-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
38146+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
38147 {
38148 .callback = clevo_mail_led_dmi_callback,
38149 .ident = "Clevo D410J",
38150diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
38151index 64e204e..c6bf189 100644
38152--- a/drivers/leds/leds-ss4200.c
38153+++ b/drivers/leds/leds-ss4200.c
38154@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
38155 * detected as working, but in reality it is not) as low as
38156 * possible.
38157 */
38158-static struct dmi_system_id __initdata nas_led_whitelist[] = {
38159+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
38160 {
38161 .callback = ss4200_led_dmi_callback,
38162 .ident = "Intel SS4200-E",
38163diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
38164index 0bf1e4e..b4bf44e 100644
38165--- a/drivers/lguest/core.c
38166+++ b/drivers/lguest/core.c
38167@@ -97,9 +97,17 @@ static __init int map_switcher(void)
38168 * The end address needs +1 because __get_vm_area allocates an
38169 * extra guard page, so we need space for that.
38170 */
38171+
38172+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
38173+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38174+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
38175+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38176+#else
38177 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
38178 VM_ALLOC, switcher_addr, switcher_addr
38179 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
38180+#endif
38181+
38182 if (!switcher_vma) {
38183 err = -ENOMEM;
38184 printk("lguest: could not map switcher pages high\n");
38185@@ -124,7 +132,7 @@ static __init int map_switcher(void)
38186 * Now the Switcher is mapped at the right address, we can't fail!
38187 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
38188 */
38189- memcpy(switcher_vma->addr, start_switcher_text,
38190+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
38191 end_switcher_text - start_switcher_text);
38192
38193 printk(KERN_INFO "lguest: mapped switcher at %p\n",
38194diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
38195index 5b9ac32..2ef4f26 100644
38196--- a/drivers/lguest/page_tables.c
38197+++ b/drivers/lguest/page_tables.c
38198@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
38199 /*:*/
38200
38201 #ifdef CONFIG_X86_PAE
38202-static void release_pmd(pmd_t *spmd)
38203+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
38204 {
38205 /* If the entry's not present, there's nothing to release. */
38206 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
38207diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
38208index f0a3347..f6608b2 100644
38209--- a/drivers/lguest/x86/core.c
38210+++ b/drivers/lguest/x86/core.c
38211@@ -59,7 +59,7 @@ static struct {
38212 /* Offset from where switcher.S was compiled to where we've copied it */
38213 static unsigned long switcher_offset(void)
38214 {
38215- return switcher_addr - (unsigned long)start_switcher_text;
38216+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
38217 }
38218
38219 /* This cpu's struct lguest_pages (after the Switcher text page) */
38220@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
38221 * These copies are pretty cheap, so we do them unconditionally: */
38222 /* Save the current Host top-level page directory.
38223 */
38224+
38225+#ifdef CONFIG_PAX_PER_CPU_PGD
38226+ pages->state.host_cr3 = read_cr3();
38227+#else
38228 pages->state.host_cr3 = __pa(current->mm->pgd);
38229+#endif
38230+
38231 /*
38232 * Set up the Guest's page tables to see this CPU's pages (and no
38233 * other CPU's pages).
38234@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
38235 * compiled-in switcher code and the high-mapped copy we just made.
38236 */
38237 for (i = 0; i < IDT_ENTRIES; i++)
38238- default_idt_entries[i] += switcher_offset();
38239+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
38240
38241 /*
38242 * Set up the Switcher's per-cpu areas.
38243@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
38244 * it will be undisturbed when we switch. To change %cs and jump we
38245 * need this structure to feed to Intel's "lcall" instruction.
38246 */
38247- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
38248+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
38249 lguest_entry.segment = LGUEST_CS;
38250
38251 /*
38252diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
38253index 40634b0..4f5855e 100644
38254--- a/drivers/lguest/x86/switcher_32.S
38255+++ b/drivers/lguest/x86/switcher_32.S
38256@@ -87,6 +87,7 @@
38257 #include <asm/page.h>
38258 #include <asm/segment.h>
38259 #include <asm/lguest.h>
38260+#include <asm/processor-flags.h>
38261
38262 // We mark the start of the code to copy
38263 // It's placed in .text tho it's never run here
38264@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38265 // Changes type when we load it: damn Intel!
38266 // For after we switch over our page tables
38267 // That entry will be read-only: we'd crash.
38268+
38269+#ifdef CONFIG_PAX_KERNEXEC
38270+ mov %cr0, %edx
38271+ xor $X86_CR0_WP, %edx
38272+ mov %edx, %cr0
38273+#endif
38274+
38275 movl $(GDT_ENTRY_TSS*8), %edx
38276 ltr %dx
38277
38278@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38279 // Let's clear it again for our return.
38280 // The GDT descriptor of the Host
38281 // Points to the table after two "size" bytes
38282- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38283+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38284 // Clear "used" from type field (byte 5, bit 2)
38285- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38286+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38287+
38288+#ifdef CONFIG_PAX_KERNEXEC
38289+ mov %cr0, %eax
38290+ xor $X86_CR0_WP, %eax
38291+ mov %eax, %cr0
38292+#endif
38293
38294 // Once our page table's switched, the Guest is live!
38295 // The Host fades as we run this final step.
38296@@ -295,13 +309,12 @@ deliver_to_host:
38297 // I consulted gcc, and it gave
38298 // These instructions, which I gladly credit:
38299 leal (%edx,%ebx,8), %eax
38300- movzwl (%eax),%edx
38301- movl 4(%eax), %eax
38302- xorw %ax, %ax
38303- orl %eax, %edx
38304+ movl 4(%eax), %edx
38305+ movw (%eax), %dx
38306 // Now the address of the handler's in %edx
38307 // We call it now: its "iret" drops us home.
38308- jmp *%edx
38309+ ljmp $__KERNEL_CS, $1f
38310+1: jmp *%edx
38311
38312 // Every interrupt can come to us here
38313 // But we must truly tell each apart.
38314diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
38315index 0003992..854bbce 100644
38316--- a/drivers/md/bcache/closure.h
38317+++ b/drivers/md/bcache/closure.h
38318@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
38319 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
38320 struct workqueue_struct *wq)
38321 {
38322- BUG_ON(object_is_on_stack(cl));
38323+ BUG_ON(object_starts_on_stack(cl));
38324 closure_set_ip(cl);
38325 cl->fn = fn;
38326 cl->wq = wq;
38327diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38328index 5a2c754..0fa55db 100644
38329--- a/drivers/md/bitmap.c
38330+++ b/drivers/md/bitmap.c
38331@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38332 chunk_kb ? "KB" : "B");
38333 if (bitmap->storage.file) {
38334 seq_printf(seq, ", file: ");
38335- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38336+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38337 }
38338
38339 seq_printf(seq, "\n");
38340diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38341index aa04f02..2a1309e 100644
38342--- a/drivers/md/dm-ioctl.c
38343+++ b/drivers/md/dm-ioctl.c
38344@@ -1694,7 +1694,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38345 cmd == DM_LIST_VERSIONS_CMD)
38346 return 0;
38347
38348- if ((cmd == DM_DEV_CREATE_CMD)) {
38349+ if (cmd == DM_DEV_CREATE_CMD) {
38350 if (!*param->name) {
38351 DMWARN("name not supplied when creating device");
38352 return -EINVAL;
38353diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38354index 699b5be..eac0a15 100644
38355--- a/drivers/md/dm-raid1.c
38356+++ b/drivers/md/dm-raid1.c
38357@@ -40,7 +40,7 @@ enum dm_raid1_error {
38358
38359 struct mirror {
38360 struct mirror_set *ms;
38361- atomic_t error_count;
38362+ atomic_unchecked_t error_count;
38363 unsigned long error_type;
38364 struct dm_dev *dev;
38365 sector_t offset;
38366@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38367 struct mirror *m;
38368
38369 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38370- if (!atomic_read(&m->error_count))
38371+ if (!atomic_read_unchecked(&m->error_count))
38372 return m;
38373
38374 return NULL;
38375@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38376 * simple way to tell if a device has encountered
38377 * errors.
38378 */
38379- atomic_inc(&m->error_count);
38380+ atomic_inc_unchecked(&m->error_count);
38381
38382 if (test_and_set_bit(error_type, &m->error_type))
38383 return;
38384@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38385 struct mirror *m = get_default_mirror(ms);
38386
38387 do {
38388- if (likely(!atomic_read(&m->error_count)))
38389+ if (likely(!atomic_read_unchecked(&m->error_count)))
38390 return m;
38391
38392 if (m-- == ms->mirror)
38393@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
38394 {
38395 struct mirror *default_mirror = get_default_mirror(m->ms);
38396
38397- return !atomic_read(&default_mirror->error_count);
38398+ return !atomic_read_unchecked(&default_mirror->error_count);
38399 }
38400
38401 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38402@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38403 */
38404 if (likely(region_in_sync(ms, region, 1)))
38405 m = choose_mirror(ms, bio->bi_sector);
38406- else if (m && atomic_read(&m->error_count))
38407+ else if (m && atomic_read_unchecked(&m->error_count))
38408 m = NULL;
38409
38410 if (likely(m))
38411@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38412 }
38413
38414 ms->mirror[mirror].ms = ms;
38415- atomic_set(&(ms->mirror[mirror].error_count), 0);
38416+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38417 ms->mirror[mirror].error_type = 0;
38418 ms->mirror[mirror].offset = offset;
38419
38420@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
38421 */
38422 static char device_status_char(struct mirror *m)
38423 {
38424- if (!atomic_read(&(m->error_count)))
38425+ if (!atomic_read_unchecked(&(m->error_count)))
38426 return 'A';
38427
38428 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38429diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38430index d907ca6..cfb8384 100644
38431--- a/drivers/md/dm-stripe.c
38432+++ b/drivers/md/dm-stripe.c
38433@@ -20,7 +20,7 @@ struct stripe {
38434 struct dm_dev *dev;
38435 sector_t physical_start;
38436
38437- atomic_t error_count;
38438+ atomic_unchecked_t error_count;
38439 };
38440
38441 struct stripe_c {
38442@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38443 kfree(sc);
38444 return r;
38445 }
38446- atomic_set(&(sc->stripe[i].error_count), 0);
38447+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38448 }
38449
38450 ti->private = sc;
38451@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38452 DMEMIT("%d ", sc->stripes);
38453 for (i = 0; i < sc->stripes; i++) {
38454 DMEMIT("%s ", sc->stripe[i].dev->name);
38455- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38456+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38457 'D' : 'A';
38458 }
38459 buffer[i] = '\0';
38460@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38461 */
38462 for (i = 0; i < sc->stripes; i++)
38463 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38464- atomic_inc(&(sc->stripe[i].error_count));
38465- if (atomic_read(&(sc->stripe[i].error_count)) <
38466+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38467+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38468 DM_IO_ERROR_THRESHOLD)
38469 schedule_work(&sc->trigger_event);
38470 }
38471diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38472index 1ff252a..ee384c1 100644
38473--- a/drivers/md/dm-table.c
38474+++ b/drivers/md/dm-table.c
38475@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38476 if (!dev_size)
38477 return 0;
38478
38479- if ((start >= dev_size) || (start + len > dev_size)) {
38480+ if ((start >= dev_size) || (len > dev_size - start)) {
38481 DMWARN("%s: %s too small for target: "
38482 "start=%llu, len=%llu, dev_size=%llu",
38483 dm_device_name(ti->table->md), bdevname(bdev, b),
38484diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38485index 60bce43..9b997d0 100644
38486--- a/drivers/md/dm-thin-metadata.c
38487+++ b/drivers/md/dm-thin-metadata.c
38488@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38489 {
38490 pmd->info.tm = pmd->tm;
38491 pmd->info.levels = 2;
38492- pmd->info.value_type.context = pmd->data_sm;
38493+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38494 pmd->info.value_type.size = sizeof(__le64);
38495 pmd->info.value_type.inc = data_block_inc;
38496 pmd->info.value_type.dec = data_block_dec;
38497@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38498
38499 pmd->bl_info.tm = pmd->tm;
38500 pmd->bl_info.levels = 1;
38501- pmd->bl_info.value_type.context = pmd->data_sm;
38502+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38503 pmd->bl_info.value_type.size = sizeof(__le64);
38504 pmd->bl_info.value_type.inc = data_block_inc;
38505 pmd->bl_info.value_type.dec = data_block_dec;
38506diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38507index d5370a9..8761bbc 100644
38508--- a/drivers/md/dm.c
38509+++ b/drivers/md/dm.c
38510@@ -169,9 +169,9 @@ struct mapped_device {
38511 /*
38512 * Event handling.
38513 */
38514- atomic_t event_nr;
38515+ atomic_unchecked_t event_nr;
38516 wait_queue_head_t eventq;
38517- atomic_t uevent_seq;
38518+ atomic_unchecked_t uevent_seq;
38519 struct list_head uevent_list;
38520 spinlock_t uevent_lock; /* Protect access to uevent_list */
38521
38522@@ -1877,8 +1877,8 @@ static struct mapped_device *alloc_dev(int minor)
38523 rwlock_init(&md->map_lock);
38524 atomic_set(&md->holders, 1);
38525 atomic_set(&md->open_count, 0);
38526- atomic_set(&md->event_nr, 0);
38527- atomic_set(&md->uevent_seq, 0);
38528+ atomic_set_unchecked(&md->event_nr, 0);
38529+ atomic_set_unchecked(&md->uevent_seq, 0);
38530 INIT_LIST_HEAD(&md->uevent_list);
38531 spin_lock_init(&md->uevent_lock);
38532
38533@@ -2026,7 +2026,7 @@ static void event_callback(void *context)
38534
38535 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38536
38537- atomic_inc(&md->event_nr);
38538+ atomic_inc_unchecked(&md->event_nr);
38539 wake_up(&md->eventq);
38540 }
38541
38542@@ -2683,18 +2683,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38543
38544 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38545 {
38546- return atomic_add_return(1, &md->uevent_seq);
38547+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38548 }
38549
38550 uint32_t dm_get_event_nr(struct mapped_device *md)
38551 {
38552- return atomic_read(&md->event_nr);
38553+ return atomic_read_unchecked(&md->event_nr);
38554 }
38555
38556 int dm_wait_event(struct mapped_device *md, int event_nr)
38557 {
38558 return wait_event_interruptible(md->eventq,
38559- (event_nr != atomic_read(&md->event_nr)));
38560+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38561 }
38562
38563 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38564diff --git a/drivers/md/md.c b/drivers/md/md.c
38565index 9b82377..6b6922d 100644
38566--- a/drivers/md/md.c
38567+++ b/drivers/md/md.c
38568@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38569 * start build, activate spare
38570 */
38571 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38572-static atomic_t md_event_count;
38573+static atomic_unchecked_t md_event_count;
38574 void md_new_event(struct mddev *mddev)
38575 {
38576- atomic_inc(&md_event_count);
38577+ atomic_inc_unchecked(&md_event_count);
38578 wake_up(&md_event_waiters);
38579 }
38580 EXPORT_SYMBOL_GPL(md_new_event);
38581@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38582 */
38583 static void md_new_event_inintr(struct mddev *mddev)
38584 {
38585- atomic_inc(&md_event_count);
38586+ atomic_inc_unchecked(&md_event_count);
38587 wake_up(&md_event_waiters);
38588 }
38589
38590@@ -1501,7 +1501,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38591 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38592 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38593 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38594- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38595+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38596
38597 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38598 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38599@@ -1745,7 +1745,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38600 else
38601 sb->resync_offset = cpu_to_le64(0);
38602
38603- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38604+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38605
38606 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38607 sb->size = cpu_to_le64(mddev->dev_sectors);
38608@@ -2750,7 +2750,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38609 static ssize_t
38610 errors_show(struct md_rdev *rdev, char *page)
38611 {
38612- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38613+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38614 }
38615
38616 static ssize_t
38617@@ -2759,7 +2759,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38618 char *e;
38619 unsigned long n = simple_strtoul(buf, &e, 10);
38620 if (*buf && (*e == 0 || *e == '\n')) {
38621- atomic_set(&rdev->corrected_errors, n);
38622+ atomic_set_unchecked(&rdev->corrected_errors, n);
38623 return len;
38624 }
38625 return -EINVAL;
38626@@ -3207,8 +3207,8 @@ int md_rdev_init(struct md_rdev *rdev)
38627 rdev->sb_loaded = 0;
38628 rdev->bb_page = NULL;
38629 atomic_set(&rdev->nr_pending, 0);
38630- atomic_set(&rdev->read_errors, 0);
38631- atomic_set(&rdev->corrected_errors, 0);
38632+ atomic_set_unchecked(&rdev->read_errors, 0);
38633+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38634
38635 INIT_LIST_HEAD(&rdev->same_set);
38636 init_waitqueue_head(&rdev->blocked_wait);
38637@@ -7009,7 +7009,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38638
38639 spin_unlock(&pers_lock);
38640 seq_printf(seq, "\n");
38641- seq->poll_event = atomic_read(&md_event_count);
38642+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38643 return 0;
38644 }
38645 if (v == (void*)2) {
38646@@ -7112,7 +7112,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38647 return error;
38648
38649 seq = file->private_data;
38650- seq->poll_event = atomic_read(&md_event_count);
38651+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38652 return error;
38653 }
38654
38655@@ -7126,7 +7126,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38656 /* always allow read */
38657 mask = POLLIN | POLLRDNORM;
38658
38659- if (seq->poll_event != atomic_read(&md_event_count))
38660+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38661 mask |= POLLERR | POLLPRI;
38662 return mask;
38663 }
38664@@ -7170,7 +7170,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38665 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38666 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38667 (int)part_stat_read(&disk->part0, sectors[1]) -
38668- atomic_read(&disk->sync_io);
38669+ atomic_read_unchecked(&disk->sync_io);
38670 /* sync IO will cause sync_io to increase before the disk_stats
38671 * as sync_io is counted when a request starts, and
38672 * disk_stats is counted when it completes.
38673diff --git a/drivers/md/md.h b/drivers/md/md.h
38674index 653f992b6..6af6c40 100644
38675--- a/drivers/md/md.h
38676+++ b/drivers/md/md.h
38677@@ -94,13 +94,13 @@ struct md_rdev {
38678 * only maintained for arrays that
38679 * support hot removal
38680 */
38681- atomic_t read_errors; /* number of consecutive read errors that
38682+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38683 * we have tried to ignore.
38684 */
38685 struct timespec last_read_error; /* monotonic time since our
38686 * last read error
38687 */
38688- atomic_t corrected_errors; /* number of corrected read errors,
38689+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38690 * for reporting to userspace and storing
38691 * in superblock.
38692 */
38693@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38694
38695 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38696 {
38697- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38698+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38699 }
38700
38701 struct md_personality
38702diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38703index 3e6d115..ffecdeb 100644
38704--- a/drivers/md/persistent-data/dm-space-map.h
38705+++ b/drivers/md/persistent-data/dm-space-map.h
38706@@ -71,6 +71,7 @@ struct dm_space_map {
38707 dm_sm_threshold_fn fn,
38708 void *context);
38709 };
38710+typedef struct dm_space_map __no_const dm_space_map_no_const;
38711
38712 /*----------------------------------------------------------------*/
38713
38714diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38715index 6e17f81..140f717 100644
38716--- a/drivers/md/raid1.c
38717+++ b/drivers/md/raid1.c
38718@@ -1822,7 +1822,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38719 if (r1_sync_page_io(rdev, sect, s,
38720 bio->bi_io_vec[idx].bv_page,
38721 READ) != 0)
38722- atomic_add(s, &rdev->corrected_errors);
38723+ atomic_add_unchecked(s, &rdev->corrected_errors);
38724 }
38725 sectors -= s;
38726 sect += s;
38727@@ -2042,7 +2042,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38728 test_bit(In_sync, &rdev->flags)) {
38729 if (r1_sync_page_io(rdev, sect, s,
38730 conf->tmppage, READ)) {
38731- atomic_add(s, &rdev->corrected_errors);
38732+ atomic_add_unchecked(s, &rdev->corrected_errors);
38733 printk(KERN_INFO
38734 "md/raid1:%s: read error corrected "
38735 "(%d sectors at %llu on %s)\n",
38736diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38737index 6ddae25..514caa9 100644
38738--- a/drivers/md/raid10.c
38739+++ b/drivers/md/raid10.c
38740@@ -1940,7 +1940,7 @@ static void end_sync_read(struct bio *bio, int error)
38741 /* The write handler will notice the lack of
38742 * R10BIO_Uptodate and record any errors etc
38743 */
38744- atomic_add(r10_bio->sectors,
38745+ atomic_add_unchecked(r10_bio->sectors,
38746 &conf->mirrors[d].rdev->corrected_errors);
38747
38748 /* for reconstruct, we always reschedule after a read.
38749@@ -2286,7 +2286,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38750 {
38751 struct timespec cur_time_mon;
38752 unsigned long hours_since_last;
38753- unsigned int read_errors = atomic_read(&rdev->read_errors);
38754+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38755
38756 ktime_get_ts(&cur_time_mon);
38757
38758@@ -2308,9 +2308,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38759 * overflowing the shift of read_errors by hours_since_last.
38760 */
38761 if (hours_since_last >= 8 * sizeof(read_errors))
38762- atomic_set(&rdev->read_errors, 0);
38763+ atomic_set_unchecked(&rdev->read_errors, 0);
38764 else
38765- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38766+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38767 }
38768
38769 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38770@@ -2364,8 +2364,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38771 return;
38772
38773 check_decay_read_errors(mddev, rdev);
38774- atomic_inc(&rdev->read_errors);
38775- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38776+ atomic_inc_unchecked(&rdev->read_errors);
38777+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38778 char b[BDEVNAME_SIZE];
38779 bdevname(rdev->bdev, b);
38780
38781@@ -2373,7 +2373,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38782 "md/raid10:%s: %s: Raid device exceeded "
38783 "read_error threshold [cur %d:max %d]\n",
38784 mdname(mddev), b,
38785- atomic_read(&rdev->read_errors), max_read_errors);
38786+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38787 printk(KERN_NOTICE
38788 "md/raid10:%s: %s: Failing raid device\n",
38789 mdname(mddev), b);
38790@@ -2528,7 +2528,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38791 sect +
38792 choose_data_offset(r10_bio, rdev)),
38793 bdevname(rdev->bdev, b));
38794- atomic_add(s, &rdev->corrected_errors);
38795+ atomic_add_unchecked(s, &rdev->corrected_errors);
38796 }
38797
38798 rdev_dec_pending(rdev, mddev);
38799diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38800index 05e4a10..48fbe37 100644
38801--- a/drivers/md/raid5.c
38802+++ b/drivers/md/raid5.c
38803@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38804 mdname(conf->mddev), STRIPE_SECTORS,
38805 (unsigned long long)s,
38806 bdevname(rdev->bdev, b));
38807- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38808+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38809 clear_bit(R5_ReadError, &sh->dev[i].flags);
38810 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38811 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38812 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38813
38814- if (atomic_read(&rdev->read_errors))
38815- atomic_set(&rdev->read_errors, 0);
38816+ if (atomic_read_unchecked(&rdev->read_errors))
38817+ atomic_set_unchecked(&rdev->read_errors, 0);
38818 } else {
38819 const char *bdn = bdevname(rdev->bdev, b);
38820 int retry = 0;
38821 int set_bad = 0;
38822
38823 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38824- atomic_inc(&rdev->read_errors);
38825+ atomic_inc_unchecked(&rdev->read_errors);
38826 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38827 printk_ratelimited(
38828 KERN_WARNING
38829@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38830 mdname(conf->mddev),
38831 (unsigned long long)s,
38832 bdn);
38833- } else if (atomic_read(&rdev->read_errors)
38834+ } else if (atomic_read_unchecked(&rdev->read_errors)
38835 > conf->max_nr_stripes)
38836 printk(KERN_WARNING
38837 "md/raid:%s: Too many read errors, failing device %s.\n",
38838diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38839index 401ef64..836e563 100644
38840--- a/drivers/media/dvb-core/dvbdev.c
38841+++ b/drivers/media/dvb-core/dvbdev.c
38842@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38843 const struct dvb_device *template, void *priv, int type)
38844 {
38845 struct dvb_device *dvbdev;
38846- struct file_operations *dvbdevfops;
38847+ file_operations_no_const *dvbdevfops;
38848 struct device *clsdev;
38849 int minor;
38850 int id;
38851diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38852index 9b6c3bb..baeb5c7 100644
38853--- a/drivers/media/dvb-frontends/dib3000.h
38854+++ b/drivers/media/dvb-frontends/dib3000.h
38855@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38856 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38857 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38858 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38859-};
38860+} __no_const;
38861
38862 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
38863 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38864diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38865index c7a9be1..683f6f8 100644
38866--- a/drivers/media/pci/cx88/cx88-video.c
38867+++ b/drivers/media/pci/cx88/cx88-video.c
38868@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38869
38870 /* ------------------------------------------------------------------ */
38871
38872-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38873-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38874-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38875+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38876+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38877+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38878
38879 module_param_array(video_nr, int, NULL, 0444);
38880 module_param_array(vbi_nr, int, NULL, 0444);
38881diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38882index d338b19..aae4f9e 100644
38883--- a/drivers/media/platform/omap/omap_vout.c
38884+++ b/drivers/media/platform/omap/omap_vout.c
38885@@ -63,7 +63,6 @@ enum omap_vout_channels {
38886 OMAP_VIDEO2,
38887 };
38888
38889-static struct videobuf_queue_ops video_vbq_ops;
38890 /* Variables configurable through module params*/
38891 static u32 video1_numbuffers = 3;
38892 static u32 video2_numbuffers = 3;
38893@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
38894 {
38895 struct videobuf_queue *q;
38896 struct omap_vout_device *vout = NULL;
38897+ static struct videobuf_queue_ops video_vbq_ops = {
38898+ .buf_setup = omap_vout_buffer_setup,
38899+ .buf_prepare = omap_vout_buffer_prepare,
38900+ .buf_release = omap_vout_buffer_release,
38901+ .buf_queue = omap_vout_buffer_queue,
38902+ };
38903
38904 vout = video_drvdata(file);
38905 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38906@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
38907 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38908
38909 q = &vout->vbq;
38910- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38911- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38912- video_vbq_ops.buf_release = omap_vout_buffer_release;
38913- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38914 spin_lock_init(&vout->vbq_lock);
38915
38916 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38917diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38918index 04e6490..2df65bf 100644
38919--- a/drivers/media/platform/s5p-tv/mixer.h
38920+++ b/drivers/media/platform/s5p-tv/mixer.h
38921@@ -156,7 +156,7 @@ struct mxr_layer {
38922 /** layer index (unique identifier) */
38923 int idx;
38924 /** callbacks for layer methods */
38925- struct mxr_layer_ops ops;
38926+ struct mxr_layer_ops *ops;
38927 /** format array */
38928 const struct mxr_format **fmt_array;
38929 /** size of format array */
38930diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38931index b93a21f..2535195 100644
38932--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38933+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38934@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38935 {
38936 struct mxr_layer *layer;
38937 int ret;
38938- struct mxr_layer_ops ops = {
38939+ static struct mxr_layer_ops ops = {
38940 .release = mxr_graph_layer_release,
38941 .buffer_set = mxr_graph_buffer_set,
38942 .stream_set = mxr_graph_stream_set,
38943diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38944index b713403..53cb5ad 100644
38945--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38946+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38947@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38948 layer->update_buf = next;
38949 }
38950
38951- layer->ops.buffer_set(layer, layer->update_buf);
38952+ layer->ops->buffer_set(layer, layer->update_buf);
38953
38954 if (done && done != layer->shadow_buf)
38955 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38956diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38957index ef0efdf..8c78eb6 100644
38958--- a/drivers/media/platform/s5p-tv/mixer_video.c
38959+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38960@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38961 layer->geo.src.height = layer->geo.src.full_height;
38962
38963 mxr_geometry_dump(mdev, &layer->geo);
38964- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38965+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38966 mxr_geometry_dump(mdev, &layer->geo);
38967 }
38968
38969@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38970 layer->geo.dst.full_width = mbus_fmt.width;
38971 layer->geo.dst.full_height = mbus_fmt.height;
38972 layer->geo.dst.field = mbus_fmt.field;
38973- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38974+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38975
38976 mxr_geometry_dump(mdev, &layer->geo);
38977 }
38978@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38979 /* set source size to highest accepted value */
38980 geo->src.full_width = max(geo->dst.full_width, pix->width);
38981 geo->src.full_height = max(geo->dst.full_height, pix->height);
38982- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38983+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38984 mxr_geometry_dump(mdev, &layer->geo);
38985 /* set cropping to total visible screen */
38986 geo->src.width = pix->width;
38987@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38988 geo->src.x_offset = 0;
38989 geo->src.y_offset = 0;
38990 /* assure consistency of geometry */
38991- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38992+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38993 mxr_geometry_dump(mdev, &layer->geo);
38994 /* set full size to lowest possible value */
38995 geo->src.full_width = 0;
38996 geo->src.full_height = 0;
38997- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38998+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38999 mxr_geometry_dump(mdev, &layer->geo);
39000
39001 /* returning results */
39002@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
39003 target->width = s->r.width;
39004 target->height = s->r.height;
39005
39006- layer->ops.fix_geometry(layer, stage, s->flags);
39007+ layer->ops->fix_geometry(layer, stage, s->flags);
39008
39009 /* retrieve update selection rectangle */
39010 res.left = target->x_offset;
39011@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
39012 mxr_output_get(mdev);
39013
39014 mxr_layer_update_output(layer);
39015- layer->ops.format_set(layer);
39016+ layer->ops->format_set(layer);
39017 /* enabling layer in hardware */
39018 spin_lock_irqsave(&layer->enq_slock, flags);
39019 layer->state = MXR_LAYER_STREAMING;
39020 spin_unlock_irqrestore(&layer->enq_slock, flags);
39021
39022- layer->ops.stream_set(layer, MXR_ENABLE);
39023+ layer->ops->stream_set(layer, MXR_ENABLE);
39024 mxr_streamer_get(mdev);
39025
39026 return 0;
39027@@ -1030,7 +1030,7 @@ static int stop_streaming(struct vb2_queue *vq)
39028 spin_unlock_irqrestore(&layer->enq_slock, flags);
39029
39030 /* disabling layer in hardware */
39031- layer->ops.stream_set(layer, MXR_DISABLE);
39032+ layer->ops->stream_set(layer, MXR_DISABLE);
39033 /* remove one streamer */
39034 mxr_streamer_put(mdev);
39035 /* allow changes in output configuration */
39036@@ -1069,8 +1069,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
39037
39038 void mxr_layer_release(struct mxr_layer *layer)
39039 {
39040- if (layer->ops.release)
39041- layer->ops.release(layer);
39042+ if (layer->ops->release)
39043+ layer->ops->release(layer);
39044 }
39045
39046 void mxr_base_layer_release(struct mxr_layer *layer)
39047@@ -1096,7 +1096,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
39048
39049 layer->mdev = mdev;
39050 layer->idx = idx;
39051- layer->ops = *ops;
39052+ layer->ops = ops;
39053
39054 spin_lock_init(&layer->enq_slock);
39055 INIT_LIST_HEAD(&layer->enq_list);
39056diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39057index 3d13a63..da31bf1 100644
39058--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39059+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
39060@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
39061 {
39062 struct mxr_layer *layer;
39063 int ret;
39064- struct mxr_layer_ops ops = {
39065+ static struct mxr_layer_ops ops = {
39066 .release = mxr_vp_layer_release,
39067 .buffer_set = mxr_vp_buffer_set,
39068 .stream_set = mxr_vp_stream_set,
39069diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
39070index 545c04c..a14bded 100644
39071--- a/drivers/media/radio/radio-cadet.c
39072+++ b/drivers/media/radio/radio-cadet.c
39073@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39074 unsigned char readbuf[RDS_BUFFER];
39075 int i = 0;
39076
39077+ if (count > RDS_BUFFER)
39078+ return -EFAULT;
39079 mutex_lock(&dev->lock);
39080 if (dev->rdsstat == 0)
39081 cadet_start_rds(dev);
39082@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
39083 while (i < count && dev->rdsin != dev->rdsout)
39084 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
39085
39086- if (i && copy_to_user(data, readbuf, i))
39087+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
39088 i = -EFAULT;
39089 unlock:
39090 mutex_unlock(&dev->lock);
39091diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
39092index 3940bb0..fb3952a 100644
39093--- a/drivers/media/usb/dvb-usb/cxusb.c
39094+++ b/drivers/media/usb/dvb-usb/cxusb.c
39095@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
39096
39097 struct dib0700_adapter_state {
39098 int (*set_param_save) (struct dvb_frontend *);
39099-};
39100+} __no_const;
39101
39102 static int dib7070_set_param_override(struct dvb_frontend *fe)
39103 {
39104diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
39105index 6e237b6..dc25556 100644
39106--- a/drivers/media/usb/dvb-usb/dw2102.c
39107+++ b/drivers/media/usb/dvb-usb/dw2102.c
39108@@ -118,7 +118,7 @@ struct su3000_state {
39109
39110 struct s6x0_state {
39111 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
39112-};
39113+} __no_const;
39114
39115 /* debug */
39116 static int dvb_usb_dw2102_debug;
39117diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39118index f129551..ecf6514 100644
39119--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39120+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
39121@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
39122 __u32 reserved;
39123 };
39124
39125-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39126+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
39127 enum v4l2_memory memory)
39128 {
39129 void __user *up_pln;
39130@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39131 return 0;
39132 }
39133
39134-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
39135+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
39136 enum v4l2_memory memory)
39137 {
39138 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
39139@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
39140 put_user(kp->start_block, &up->start_block) ||
39141 put_user(kp->blocks, &up->blocks) ||
39142 put_user(tmp, &up->edid) ||
39143- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
39144+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
39145 return -EFAULT;
39146 return 0;
39147 }
39148diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
39149index 7658586..1079260 100644
39150--- a/drivers/media/v4l2-core/v4l2-ioctl.c
39151+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
39152@@ -1995,7 +1995,8 @@ struct v4l2_ioctl_info {
39153 struct file *file, void *fh, void *p);
39154 } u;
39155 void (*debug)(const void *arg, bool write_only);
39156-};
39157+} __do_const;
39158+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
39159
39160 /* This control needs a priority check */
39161 #define INFO_FL_PRIO (1 << 0)
39162@@ -2177,7 +2178,7 @@ static long __video_do_ioctl(struct file *file,
39163 struct video_device *vfd = video_devdata(file);
39164 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
39165 bool write_only = false;
39166- struct v4l2_ioctl_info default_info;
39167+ v4l2_ioctl_info_no_const default_info;
39168 const struct v4l2_ioctl_info *info;
39169 void *fh = file->private_data;
39170 struct v4l2_fh *vfh = NULL;
39171@@ -2251,7 +2252,7 @@ done:
39172 }
39173
39174 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39175- void * __user *user_ptr, void ***kernel_ptr)
39176+ void __user **user_ptr, void ***kernel_ptr)
39177 {
39178 int ret = 0;
39179
39180@@ -2267,7 +2268,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39181 ret = -EINVAL;
39182 break;
39183 }
39184- *user_ptr = (void __user *)buf->m.planes;
39185+ *user_ptr = (void __force_user *)buf->m.planes;
39186 *kernel_ptr = (void *)&buf->m.planes;
39187 *array_size = sizeof(struct v4l2_plane) * buf->length;
39188 ret = 1;
39189@@ -2302,7 +2303,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
39190 ret = -EINVAL;
39191 break;
39192 }
39193- *user_ptr = (void __user *)ctrls->controls;
39194+ *user_ptr = (void __force_user *)ctrls->controls;
39195 *kernel_ptr = (void *)&ctrls->controls;
39196 *array_size = sizeof(struct v4l2_ext_control)
39197 * ctrls->count;
39198diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
39199index 767ff4d..c69d259 100644
39200--- a/drivers/message/fusion/mptbase.c
39201+++ b/drivers/message/fusion/mptbase.c
39202@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39203 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
39204 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
39205
39206+#ifdef CONFIG_GRKERNSEC_HIDESYM
39207+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
39208+#else
39209 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
39210 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
39211+#endif
39212+
39213 /*
39214 * Rounding UP to nearest 4-kB boundary here...
39215 */
39216@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
39217 ioc->facts.GlobalCredits);
39218
39219 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
39220+#ifdef CONFIG_GRKERNSEC_HIDESYM
39221+ NULL, NULL);
39222+#else
39223 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
39224+#endif
39225 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
39226 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
39227 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
39228diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
39229index dd239bd..689c4f7 100644
39230--- a/drivers/message/fusion/mptsas.c
39231+++ b/drivers/message/fusion/mptsas.c
39232@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
39233 return 0;
39234 }
39235
39236+static inline void
39237+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39238+{
39239+ if (phy_info->port_details) {
39240+ phy_info->port_details->rphy = rphy;
39241+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39242+ ioc->name, rphy));
39243+ }
39244+
39245+ if (rphy) {
39246+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39247+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39248+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39249+ ioc->name, rphy, rphy->dev.release));
39250+ }
39251+}
39252+
39253 /* no mutex */
39254 static void
39255 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
39256@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
39257 return NULL;
39258 }
39259
39260-static inline void
39261-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39262-{
39263- if (phy_info->port_details) {
39264- phy_info->port_details->rphy = rphy;
39265- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39266- ioc->name, rphy));
39267- }
39268-
39269- if (rphy) {
39270- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39271- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39272- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39273- ioc->name, rphy, rphy->dev.release));
39274- }
39275-}
39276-
39277 static inline struct sas_port *
39278 mptsas_get_port(struct mptsas_phyinfo *phy_info)
39279 {
39280diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
39281index 727819c..ad74694 100644
39282--- a/drivers/message/fusion/mptscsih.c
39283+++ b/drivers/message/fusion/mptscsih.c
39284@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
39285
39286 h = shost_priv(SChost);
39287
39288- if (h) {
39289- if (h->info_kbuf == NULL)
39290- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39291- return h->info_kbuf;
39292- h->info_kbuf[0] = '\0';
39293+ if (!h)
39294+ return NULL;
39295
39296- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39297- h->info_kbuf[size-1] = '\0';
39298- }
39299+ if (h->info_kbuf == NULL)
39300+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39301+ return h->info_kbuf;
39302+ h->info_kbuf[0] = '\0';
39303+
39304+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39305+ h->info_kbuf[size-1] = '\0';
39306
39307 return h->info_kbuf;
39308 }
39309diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39310index b7d87cd..9890039 100644
39311--- a/drivers/message/i2o/i2o_proc.c
39312+++ b/drivers/message/i2o/i2o_proc.c
39313@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39314 "Array Controller Device"
39315 };
39316
39317-static char *chtostr(char *tmp, u8 *chars, int n)
39318-{
39319- tmp[0] = 0;
39320- return strncat(tmp, (char *)chars, n);
39321-}
39322-
39323 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39324 char *group)
39325 {
39326@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39327 } *result;
39328
39329 i2o_exec_execute_ddm_table ddm_table;
39330- char tmp[28 + 1];
39331
39332 result = kmalloc(sizeof(*result), GFP_KERNEL);
39333 if (!result)
39334@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39335
39336 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39337 seq_printf(seq, "%-#8x", ddm_table.module_id);
39338- seq_printf(seq, "%-29s",
39339- chtostr(tmp, ddm_table.module_name_version, 28));
39340+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39341 seq_printf(seq, "%9d ", ddm_table.data_size);
39342 seq_printf(seq, "%8d", ddm_table.code_size);
39343
39344@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39345
39346 i2o_driver_result_table *result;
39347 i2o_driver_store_table *dst;
39348- char tmp[28 + 1];
39349
39350 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39351 if (result == NULL)
39352@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39353
39354 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39355 seq_printf(seq, "%-#8x", dst->module_id);
39356- seq_printf(seq, "%-29s",
39357- chtostr(tmp, dst->module_name_version, 28));
39358- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39359+ seq_printf(seq, "%-.28s", dst->module_name_version);
39360+ seq_printf(seq, "%-.8s", dst->date);
39361 seq_printf(seq, "%8d ", dst->module_size);
39362 seq_printf(seq, "%8d ", dst->mpb_size);
39363 seq_printf(seq, "0x%04x", dst->module_flags);
39364@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39365 // == (allow) 512d bytes (max)
39366 static u16 *work16 = (u16 *) work32;
39367 int token;
39368- char tmp[16 + 1];
39369
39370 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39371
39372@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39373 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39374 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39375 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39376- seq_printf(seq, "Vendor info : %s\n",
39377- chtostr(tmp, (u8 *) (work32 + 2), 16));
39378- seq_printf(seq, "Product info : %s\n",
39379- chtostr(tmp, (u8 *) (work32 + 6), 16));
39380- seq_printf(seq, "Description : %s\n",
39381- chtostr(tmp, (u8 *) (work32 + 10), 16));
39382- seq_printf(seq, "Product rev. : %s\n",
39383- chtostr(tmp, (u8 *) (work32 + 14), 8));
39384+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39385+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39386+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39387+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39388
39389 seq_printf(seq, "Serial number : ");
39390 print_serial_number(seq, (u8 *) (work32 + 16),
39391@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39392 u8 pad[256]; // allow up to 256 byte (max) serial number
39393 } result;
39394
39395- char tmp[24 + 1];
39396-
39397 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39398
39399 if (token < 0) {
39400@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39401 }
39402
39403 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39404- seq_printf(seq, "Module name : %s\n",
39405- chtostr(tmp, result.module_name, 24));
39406- seq_printf(seq, "Module revision : %s\n",
39407- chtostr(tmp, result.module_rev, 8));
39408+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39409+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39410
39411 seq_printf(seq, "Serial number : ");
39412 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39413@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39414 u8 instance_number[4];
39415 } result;
39416
39417- char tmp[64 + 1];
39418-
39419 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39420
39421 if (token < 0) {
39422@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39423 return 0;
39424 }
39425
39426- seq_printf(seq, "Device name : %s\n",
39427- chtostr(tmp, result.device_name, 64));
39428- seq_printf(seq, "Service name : %s\n",
39429- chtostr(tmp, result.service_name, 64));
39430- seq_printf(seq, "Physical name : %s\n",
39431- chtostr(tmp, result.physical_location, 64));
39432- seq_printf(seq, "Instance number : %s\n",
39433- chtostr(tmp, result.instance_number, 4));
39434+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39435+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39436+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39437+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39438
39439 return 0;
39440 }
39441diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39442index a8c08f3..155fe3d 100644
39443--- a/drivers/message/i2o/iop.c
39444+++ b/drivers/message/i2o/iop.c
39445@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39446
39447 spin_lock_irqsave(&c->context_list_lock, flags);
39448
39449- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39450- atomic_inc(&c->context_list_counter);
39451+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39452+ atomic_inc_unchecked(&c->context_list_counter);
39453
39454- entry->context = atomic_read(&c->context_list_counter);
39455+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39456
39457 list_add(&entry->list, &c->context_list);
39458
39459@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39460
39461 #if BITS_PER_LONG == 64
39462 spin_lock_init(&c->context_list_lock);
39463- atomic_set(&c->context_list_counter, 0);
39464+ atomic_set_unchecked(&c->context_list_counter, 0);
39465 INIT_LIST_HEAD(&c->context_list);
39466 #endif
39467
39468diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39469index 45ece11..8efa218 100644
39470--- a/drivers/mfd/janz-cmodio.c
39471+++ b/drivers/mfd/janz-cmodio.c
39472@@ -13,6 +13,7 @@
39473
39474 #include <linux/kernel.h>
39475 #include <linux/module.h>
39476+#include <linux/slab.h>
39477 #include <linux/init.h>
39478 #include <linux/pci.h>
39479 #include <linux/interrupt.h>
39480diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39481index a5f9888..1c0ed56 100644
39482--- a/drivers/mfd/twl4030-irq.c
39483+++ b/drivers/mfd/twl4030-irq.c
39484@@ -35,6 +35,7 @@
39485 #include <linux/of.h>
39486 #include <linux/irqdomain.h>
39487 #include <linux/i2c/twl.h>
39488+#include <asm/pgtable.h>
39489
39490 #include "twl-core.h"
39491
39492@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39493 * Install an irq handler for each of the SIH modules;
39494 * clone dummy irq_chip since PIH can't *do* anything
39495 */
39496- twl4030_irq_chip = dummy_irq_chip;
39497- twl4030_irq_chip.name = "twl4030";
39498+ pax_open_kernel();
39499+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39500+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39501
39502- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39503+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39504+ pax_close_kernel();
39505
39506 for (i = irq_base; i < irq_end; i++) {
39507 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39508diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39509index 277a8db..0e0b754 100644
39510--- a/drivers/mfd/twl6030-irq.c
39511+++ b/drivers/mfd/twl6030-irq.c
39512@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39513 * install an irq handler for each of the modules;
39514 * clone dummy irq_chip since PIH can't *do* anything
39515 */
39516- twl6030_irq_chip = dummy_irq_chip;
39517- twl6030_irq_chip.name = "twl6030";
39518- twl6030_irq_chip.irq_set_type = NULL;
39519- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39520+ pax_open_kernel();
39521+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39522+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39523+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39524+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39525+ pax_close_kernel();
39526
39527 for (i = irq_base; i < irq_end; i++) {
39528 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39529diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39530index f32550a..e3e52a2 100644
39531--- a/drivers/misc/c2port/core.c
39532+++ b/drivers/misc/c2port/core.c
39533@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
39534 mutex_init(&c2dev->mutex);
39535
39536 /* Create binary file */
39537- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39538+ pax_open_kernel();
39539+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39540+ pax_close_kernel();
39541 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39542 if (unlikely(ret))
39543 goto error_device_create_bin_file;
39544diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39545index 36f5d52..32311c3 100644
39546--- a/drivers/misc/kgdbts.c
39547+++ b/drivers/misc/kgdbts.c
39548@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
39549 char before[BREAK_INSTR_SIZE];
39550 char after[BREAK_INSTR_SIZE];
39551
39552- probe_kernel_read(before, (char *)kgdbts_break_test,
39553+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39554 BREAK_INSTR_SIZE);
39555 init_simple_test();
39556 ts.tst = plant_and_detach_test;
39557@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
39558 /* Activate test with initial breakpoint */
39559 if (!is_early)
39560 kgdb_breakpoint();
39561- probe_kernel_read(after, (char *)kgdbts_break_test,
39562+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39563 BREAK_INSTR_SIZE);
39564 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39565 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39566diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39567index 4cd4a3d..b48cbc7 100644
39568--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39569+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39570@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39571 * the lid is closed. This leads to interrupts as soon as a little move
39572 * is done.
39573 */
39574- atomic_inc(&lis3->count);
39575+ atomic_inc_unchecked(&lis3->count);
39576
39577 wake_up_interruptible(&lis3->misc_wait);
39578 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39579@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39580 if (lis3->pm_dev)
39581 pm_runtime_get_sync(lis3->pm_dev);
39582
39583- atomic_set(&lis3->count, 0);
39584+ atomic_set_unchecked(&lis3->count, 0);
39585 return 0;
39586 }
39587
39588@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39589 add_wait_queue(&lis3->misc_wait, &wait);
39590 while (true) {
39591 set_current_state(TASK_INTERRUPTIBLE);
39592- data = atomic_xchg(&lis3->count, 0);
39593+ data = atomic_xchg_unchecked(&lis3->count, 0);
39594 if (data)
39595 break;
39596
39597@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39598 struct lis3lv02d, miscdev);
39599
39600 poll_wait(file, &lis3->misc_wait, wait);
39601- if (atomic_read(&lis3->count))
39602+ if (atomic_read_unchecked(&lis3->count))
39603 return POLLIN | POLLRDNORM;
39604 return 0;
39605 }
39606diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39607index c439c82..1f20f57 100644
39608--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39609+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39610@@ -297,7 +297,7 @@ struct lis3lv02d {
39611 struct input_polled_dev *idev; /* input device */
39612 struct platform_device *pdev; /* platform device */
39613 struct regulator_bulk_data regulators[2];
39614- atomic_t count; /* interrupt count after last read */
39615+ atomic_unchecked_t count; /* interrupt count after last read */
39616 union axis_conversion ac; /* hw -> logical axis */
39617 int mapped_btns[3];
39618
39619diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39620index 2f30bad..c4c13d0 100644
39621--- a/drivers/misc/sgi-gru/gruhandles.c
39622+++ b/drivers/misc/sgi-gru/gruhandles.c
39623@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39624 unsigned long nsec;
39625
39626 nsec = CLKS2NSEC(clks);
39627- atomic_long_inc(&mcs_op_statistics[op].count);
39628- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39629+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39630+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39631 if (mcs_op_statistics[op].max < nsec)
39632 mcs_op_statistics[op].max = nsec;
39633 }
39634diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39635index 797d796..ae8f01e 100644
39636--- a/drivers/misc/sgi-gru/gruprocfs.c
39637+++ b/drivers/misc/sgi-gru/gruprocfs.c
39638@@ -32,9 +32,9 @@
39639
39640 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39641
39642-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39643+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39644 {
39645- unsigned long val = atomic_long_read(v);
39646+ unsigned long val = atomic_long_read_unchecked(v);
39647
39648 seq_printf(s, "%16lu %s\n", val, id);
39649 }
39650@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39651
39652 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39653 for (op = 0; op < mcsop_last; op++) {
39654- count = atomic_long_read(&mcs_op_statistics[op].count);
39655- total = atomic_long_read(&mcs_op_statistics[op].total);
39656+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39657+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39658 max = mcs_op_statistics[op].max;
39659 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39660 count ? total / count : 0, max);
39661diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39662index 5c3ce24..4915ccb 100644
39663--- a/drivers/misc/sgi-gru/grutables.h
39664+++ b/drivers/misc/sgi-gru/grutables.h
39665@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39666 * GRU statistics.
39667 */
39668 struct gru_stats_s {
39669- atomic_long_t vdata_alloc;
39670- atomic_long_t vdata_free;
39671- atomic_long_t gts_alloc;
39672- atomic_long_t gts_free;
39673- atomic_long_t gms_alloc;
39674- atomic_long_t gms_free;
39675- atomic_long_t gts_double_allocate;
39676- atomic_long_t assign_context;
39677- atomic_long_t assign_context_failed;
39678- atomic_long_t free_context;
39679- atomic_long_t load_user_context;
39680- atomic_long_t load_kernel_context;
39681- atomic_long_t lock_kernel_context;
39682- atomic_long_t unlock_kernel_context;
39683- atomic_long_t steal_user_context;
39684- atomic_long_t steal_kernel_context;
39685- atomic_long_t steal_context_failed;
39686- atomic_long_t nopfn;
39687- atomic_long_t asid_new;
39688- atomic_long_t asid_next;
39689- atomic_long_t asid_wrap;
39690- atomic_long_t asid_reuse;
39691- atomic_long_t intr;
39692- atomic_long_t intr_cbr;
39693- atomic_long_t intr_tfh;
39694- atomic_long_t intr_spurious;
39695- atomic_long_t intr_mm_lock_failed;
39696- atomic_long_t call_os;
39697- atomic_long_t call_os_wait_queue;
39698- atomic_long_t user_flush_tlb;
39699- atomic_long_t user_unload_context;
39700- atomic_long_t user_exception;
39701- atomic_long_t set_context_option;
39702- atomic_long_t check_context_retarget_intr;
39703- atomic_long_t check_context_unload;
39704- atomic_long_t tlb_dropin;
39705- atomic_long_t tlb_preload_page;
39706- atomic_long_t tlb_dropin_fail_no_asid;
39707- atomic_long_t tlb_dropin_fail_upm;
39708- atomic_long_t tlb_dropin_fail_invalid;
39709- atomic_long_t tlb_dropin_fail_range_active;
39710- atomic_long_t tlb_dropin_fail_idle;
39711- atomic_long_t tlb_dropin_fail_fmm;
39712- atomic_long_t tlb_dropin_fail_no_exception;
39713- atomic_long_t tfh_stale_on_fault;
39714- atomic_long_t mmu_invalidate_range;
39715- atomic_long_t mmu_invalidate_page;
39716- atomic_long_t flush_tlb;
39717- atomic_long_t flush_tlb_gru;
39718- atomic_long_t flush_tlb_gru_tgh;
39719- atomic_long_t flush_tlb_gru_zero_asid;
39720+ atomic_long_unchecked_t vdata_alloc;
39721+ atomic_long_unchecked_t vdata_free;
39722+ atomic_long_unchecked_t gts_alloc;
39723+ atomic_long_unchecked_t gts_free;
39724+ atomic_long_unchecked_t gms_alloc;
39725+ atomic_long_unchecked_t gms_free;
39726+ atomic_long_unchecked_t gts_double_allocate;
39727+ atomic_long_unchecked_t assign_context;
39728+ atomic_long_unchecked_t assign_context_failed;
39729+ atomic_long_unchecked_t free_context;
39730+ atomic_long_unchecked_t load_user_context;
39731+ atomic_long_unchecked_t load_kernel_context;
39732+ atomic_long_unchecked_t lock_kernel_context;
39733+ atomic_long_unchecked_t unlock_kernel_context;
39734+ atomic_long_unchecked_t steal_user_context;
39735+ atomic_long_unchecked_t steal_kernel_context;
39736+ atomic_long_unchecked_t steal_context_failed;
39737+ atomic_long_unchecked_t nopfn;
39738+ atomic_long_unchecked_t asid_new;
39739+ atomic_long_unchecked_t asid_next;
39740+ atomic_long_unchecked_t asid_wrap;
39741+ atomic_long_unchecked_t asid_reuse;
39742+ atomic_long_unchecked_t intr;
39743+ atomic_long_unchecked_t intr_cbr;
39744+ atomic_long_unchecked_t intr_tfh;
39745+ atomic_long_unchecked_t intr_spurious;
39746+ atomic_long_unchecked_t intr_mm_lock_failed;
39747+ atomic_long_unchecked_t call_os;
39748+ atomic_long_unchecked_t call_os_wait_queue;
39749+ atomic_long_unchecked_t user_flush_tlb;
39750+ atomic_long_unchecked_t user_unload_context;
39751+ atomic_long_unchecked_t user_exception;
39752+ atomic_long_unchecked_t set_context_option;
39753+ atomic_long_unchecked_t check_context_retarget_intr;
39754+ atomic_long_unchecked_t check_context_unload;
39755+ atomic_long_unchecked_t tlb_dropin;
39756+ atomic_long_unchecked_t tlb_preload_page;
39757+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39758+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39759+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39760+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39761+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39762+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39763+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39764+ atomic_long_unchecked_t tfh_stale_on_fault;
39765+ atomic_long_unchecked_t mmu_invalidate_range;
39766+ atomic_long_unchecked_t mmu_invalidate_page;
39767+ atomic_long_unchecked_t flush_tlb;
39768+ atomic_long_unchecked_t flush_tlb_gru;
39769+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39770+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39771
39772- atomic_long_t copy_gpa;
39773- atomic_long_t read_gpa;
39774+ atomic_long_unchecked_t copy_gpa;
39775+ atomic_long_unchecked_t read_gpa;
39776
39777- atomic_long_t mesq_receive;
39778- atomic_long_t mesq_receive_none;
39779- atomic_long_t mesq_send;
39780- atomic_long_t mesq_send_failed;
39781- atomic_long_t mesq_noop;
39782- atomic_long_t mesq_send_unexpected_error;
39783- atomic_long_t mesq_send_lb_overflow;
39784- atomic_long_t mesq_send_qlimit_reached;
39785- atomic_long_t mesq_send_amo_nacked;
39786- atomic_long_t mesq_send_put_nacked;
39787- atomic_long_t mesq_page_overflow;
39788- atomic_long_t mesq_qf_locked;
39789- atomic_long_t mesq_qf_noop_not_full;
39790- atomic_long_t mesq_qf_switch_head_failed;
39791- atomic_long_t mesq_qf_unexpected_error;
39792- atomic_long_t mesq_noop_unexpected_error;
39793- atomic_long_t mesq_noop_lb_overflow;
39794- atomic_long_t mesq_noop_qlimit_reached;
39795- atomic_long_t mesq_noop_amo_nacked;
39796- atomic_long_t mesq_noop_put_nacked;
39797- atomic_long_t mesq_noop_page_overflow;
39798+ atomic_long_unchecked_t mesq_receive;
39799+ atomic_long_unchecked_t mesq_receive_none;
39800+ atomic_long_unchecked_t mesq_send;
39801+ atomic_long_unchecked_t mesq_send_failed;
39802+ atomic_long_unchecked_t mesq_noop;
39803+ atomic_long_unchecked_t mesq_send_unexpected_error;
39804+ atomic_long_unchecked_t mesq_send_lb_overflow;
39805+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39806+ atomic_long_unchecked_t mesq_send_amo_nacked;
39807+ atomic_long_unchecked_t mesq_send_put_nacked;
39808+ atomic_long_unchecked_t mesq_page_overflow;
39809+ atomic_long_unchecked_t mesq_qf_locked;
39810+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39811+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39812+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39813+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39814+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39815+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39816+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39817+ atomic_long_unchecked_t mesq_noop_put_nacked;
39818+ atomic_long_unchecked_t mesq_noop_page_overflow;
39819
39820 };
39821
39822@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39823 tghop_invalidate, mcsop_last};
39824
39825 struct mcs_op_statistic {
39826- atomic_long_t count;
39827- atomic_long_t total;
39828+ atomic_long_unchecked_t count;
39829+ atomic_long_unchecked_t total;
39830 unsigned long max;
39831 };
39832
39833@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39834
39835 #define STAT(id) do { \
39836 if (gru_options & OPT_STATS) \
39837- atomic_long_inc(&gru_stats.id); \
39838+ atomic_long_inc_unchecked(&gru_stats.id); \
39839 } while (0)
39840
39841 #ifdef CONFIG_SGI_GRU_DEBUG
39842diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39843index c862cd4..0d176fe 100644
39844--- a/drivers/misc/sgi-xp/xp.h
39845+++ b/drivers/misc/sgi-xp/xp.h
39846@@ -288,7 +288,7 @@ struct xpc_interface {
39847 xpc_notify_func, void *);
39848 void (*received) (short, int, void *);
39849 enum xp_retval (*partid_to_nasids) (short, void *);
39850-};
39851+} __no_const;
39852
39853 extern struct xpc_interface xpc_interface;
39854
39855diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39856index b94d5f7..7f494c5 100644
39857--- a/drivers/misc/sgi-xp/xpc.h
39858+++ b/drivers/misc/sgi-xp/xpc.h
39859@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39860 void (*received_payload) (struct xpc_channel *, void *);
39861 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39862 };
39863+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39864
39865 /* struct xpc_partition act_state values (for XPC HB) */
39866
39867@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39868 /* found in xpc_main.c */
39869 extern struct device *xpc_part;
39870 extern struct device *xpc_chan;
39871-extern struct xpc_arch_operations xpc_arch_ops;
39872+extern xpc_arch_operations_no_const xpc_arch_ops;
39873 extern int xpc_disengage_timelimit;
39874 extern int xpc_disengage_timedout;
39875 extern int xpc_activate_IRQ_rcvd;
39876diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39877index d971817..33bdca5 100644
39878--- a/drivers/misc/sgi-xp/xpc_main.c
39879+++ b/drivers/misc/sgi-xp/xpc_main.c
39880@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39881 .notifier_call = xpc_system_die,
39882 };
39883
39884-struct xpc_arch_operations xpc_arch_ops;
39885+xpc_arch_operations_no_const xpc_arch_ops;
39886
39887 /*
39888 * Timer function to enforce the timelimit on the partition disengage.
39889@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39890
39891 if (((die_args->trapnr == X86_TRAP_MF) ||
39892 (die_args->trapnr == X86_TRAP_XF)) &&
39893- !user_mode_vm(die_args->regs))
39894+ !user_mode(die_args->regs))
39895 xpc_die_deactivate();
39896
39897 break;
39898diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39899index 49f04bc..65660c2 100644
39900--- a/drivers/mmc/core/mmc_ops.c
39901+++ b/drivers/mmc/core/mmc_ops.c
39902@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39903 void *data_buf;
39904 int is_on_stack;
39905
39906- is_on_stack = object_is_on_stack(buf);
39907+ is_on_stack = object_starts_on_stack(buf);
39908 if (is_on_stack) {
39909 /*
39910 * dma onto stack is unsafe/nonportable, but callers to this
39911diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39912index 0b74189..818358f 100644
39913--- a/drivers/mmc/host/dw_mmc.h
39914+++ b/drivers/mmc/host/dw_mmc.h
39915@@ -202,5 +202,5 @@ struct dw_mci_drv_data {
39916 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
39917 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
39918 int (*parse_dt)(struct dw_mci *host);
39919-};
39920+} __do_const;
39921 #endif /* _DW_MMC_H_ */
39922diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39923index c6f6246..60760a8 100644
39924--- a/drivers/mmc/host/sdhci-s3c.c
39925+++ b/drivers/mmc/host/sdhci-s3c.c
39926@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39927 * we can use overriding functions instead of default.
39928 */
39929 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39930- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39931- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39932- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39933+ pax_open_kernel();
39934+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39935+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39936+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39937+ pax_close_kernel();
39938 }
39939
39940 /* It supports additional host capabilities if needed */
39941diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39942index 0c8bb6b..6f35deb 100644
39943--- a/drivers/mtd/nand/denali.c
39944+++ b/drivers/mtd/nand/denali.c
39945@@ -24,6 +24,7 @@
39946 #include <linux/slab.h>
39947 #include <linux/mtd/mtd.h>
39948 #include <linux/module.h>
39949+#include <linux/slab.h>
39950
39951 #include "denali.h"
39952
39953diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39954index 51b9d6a..52af9a7 100644
39955--- a/drivers/mtd/nftlmount.c
39956+++ b/drivers/mtd/nftlmount.c
39957@@ -24,6 +24,7 @@
39958 #include <asm/errno.h>
39959 #include <linux/delay.h>
39960 #include <linux/slab.h>
39961+#include <linux/sched.h>
39962 #include <linux/mtd/mtd.h>
39963 #include <linux/mtd/nand.h>
39964 #include <linux/mtd/nftl.h>
39965diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39966index f9d5615..99dd95f 100644
39967--- a/drivers/mtd/sm_ftl.c
39968+++ b/drivers/mtd/sm_ftl.c
39969@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39970 #define SM_CIS_VENDOR_OFFSET 0x59
39971 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39972 {
39973- struct attribute_group *attr_group;
39974+ attribute_group_no_const *attr_group;
39975 struct attribute **attributes;
39976 struct sm_sysfs_attribute *vendor_attribute;
39977
39978diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39979index f975696..4597e21 100644
39980--- a/drivers/net/bonding/bond_main.c
39981+++ b/drivers/net/bonding/bond_main.c
39982@@ -4870,7 +4870,7 @@ static unsigned int bond_get_num_tx_queues(void)
39983 return tx_queues;
39984 }
39985
39986-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39987+static struct rtnl_link_ops bond_link_ops = {
39988 .kind = "bond",
39989 .priv_size = sizeof(struct bonding),
39990 .setup = bond_setup,
39991@@ -4995,8 +4995,8 @@ static void __exit bonding_exit(void)
39992
39993 bond_destroy_debugfs();
39994
39995- rtnl_link_unregister(&bond_link_ops);
39996 unregister_pernet_subsys(&bond_net_ops);
39997+ rtnl_link_unregister(&bond_link_ops);
39998
39999 #ifdef CONFIG_NET_POLL_CONTROLLER
40000 /*
40001diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
40002index e1d2643..7f4133b 100644
40003--- a/drivers/net/ethernet/8390/ax88796.c
40004+++ b/drivers/net/ethernet/8390/ax88796.c
40005@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
40006 if (ax->plat->reg_offsets)
40007 ei_local->reg_offset = ax->plat->reg_offsets;
40008 else {
40009+ resource_size_t _mem_size = mem_size;
40010+ do_div(_mem_size, 0x18);
40011 ei_local->reg_offset = ax->reg_offsets;
40012 for (ret = 0; ret < 0x18; ret++)
40013- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
40014+ ax->reg_offsets[ret] = _mem_size * ret;
40015 }
40016
40017 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
40018diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40019index 151675d..0139a9d 100644
40020--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40021+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
40022@@ -1112,7 +1112,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
40023 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
40024 {
40025 /* RX_MODE controlling object */
40026- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
40027+ bnx2x_init_rx_mode_obj(bp);
40028
40029 /* multicast configuration controlling object */
40030 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
40031diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40032index ce1a916..10b52b0 100644
40033--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40034+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c
40035@@ -960,6 +960,9 @@ static int bnx2x_set_dump(struct net_device *dev, struct ethtool_dump *val)
40036 struct bnx2x *bp = netdev_priv(dev);
40037
40038 /* Use the ethtool_dump "flag" field as the dump preset index */
40039+ if (val->flag < 1 || val->flag > DUMP_MAX_PRESETS)
40040+ return -EINVAL;
40041+
40042 bp->dump_preset_idx = val->flag;
40043 return 0;
40044 }
40045@@ -986,8 +989,6 @@ static int bnx2x_get_dump_data(struct net_device *dev,
40046 struct bnx2x *bp = netdev_priv(dev);
40047 struct dump_header dump_hdr = {0};
40048
40049- memset(p, 0, dump->len);
40050-
40051 /* Disable parity attentions as long as following dump may
40052 * cause false alarms by reading never written registers. We
40053 * will re-enable parity attentions right after the dump.
40054diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40055index b4c9dea..2a9927f 100644
40056--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40057+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
40058@@ -11497,6 +11497,8 @@ static int bnx2x_init_bp(struct bnx2x *bp)
40059 bp->min_msix_vec_cnt = 2;
40060 BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
40061
40062+ bp->dump_preset_idx = 1;
40063+
40064 return rc;
40065 }
40066
40067diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40068index 32a9609..0b1c53a 100644
40069--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40070+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
40071@@ -2387,15 +2387,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
40072 return rc;
40073 }
40074
40075-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40076- struct bnx2x_rx_mode_obj *o)
40077+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
40078 {
40079 if (CHIP_IS_E1x(bp)) {
40080- o->wait_comp = bnx2x_empty_rx_mode_wait;
40081- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
40082+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
40083+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
40084 } else {
40085- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
40086- o->config_rx_mode = bnx2x_set_rx_mode_e2;
40087+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
40088+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
40089 }
40090 }
40091
40092diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40093index 43c00bc..dd1d03d 100644
40094--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40095+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
40096@@ -1321,8 +1321,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
40097
40098 /********************* RX MODE ****************/
40099
40100-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
40101- struct bnx2x_rx_mode_obj *o);
40102+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
40103
40104 /**
40105 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
40106diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
40107index ff6e30e..87e8452 100644
40108--- a/drivers/net/ethernet/broadcom/tg3.h
40109+++ b/drivers/net/ethernet/broadcom/tg3.h
40110@@ -147,6 +147,7 @@
40111 #define CHIPREV_ID_5750_A0 0x4000
40112 #define CHIPREV_ID_5750_A1 0x4001
40113 #define CHIPREV_ID_5750_A3 0x4003
40114+#define CHIPREV_ID_5750_C1 0x4201
40115 #define CHIPREV_ID_5750_C2 0x4202
40116 #define CHIPREV_ID_5752_A0_HW 0x5000
40117 #define CHIPREV_ID_5752_A0 0x6000
40118diff --git a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40119index 71497e8..b650951 100644
40120--- a/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40121+++ b/drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c
40122@@ -3037,7 +3037,9 @@ static void t3_io_resume(struct pci_dev *pdev)
40123 CH_ALERT(adapter, "adapter recovering, PEX ERR 0x%x\n",
40124 t3_read_reg(adapter, A_PCIE_PEX_ERR));
40125
40126+ rtnl_lock();
40127 t3_resume_ports(adapter);
40128+ rtnl_unlock();
40129 }
40130
40131 static const struct pci_error_handlers t3_err_handler = {
40132diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40133index 8cffcdf..aadf043 100644
40134--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40135+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
40136@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
40137 */
40138 struct l2t_skb_cb {
40139 arp_failure_handler_func arp_failure_handler;
40140-};
40141+} __no_const;
40142
40143 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
40144
40145diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
40146index 4c83003..2a2a5b9 100644
40147--- a/drivers/net/ethernet/dec/tulip/de4x5.c
40148+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
40149@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40150 for (i=0; i<ETH_ALEN; i++) {
40151 tmp.addr[i] = dev->dev_addr[i];
40152 }
40153- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40154+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
40155 break;
40156
40157 case DE4X5_SET_HWADDR: /* Set the hardware address */
40158@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
40159 spin_lock_irqsave(&lp->lock, flags);
40160 memcpy(&statbuf, &lp->pktStats, ioc->len);
40161 spin_unlock_irqrestore(&lp->lock, flags);
40162- if (copy_to_user(ioc->data, &statbuf, ioc->len))
40163+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
40164 return -EFAULT;
40165 break;
40166 }
40167diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
40168index a0b4be5..d8cb082 100644
40169--- a/drivers/net/ethernet/emulex/benet/be_main.c
40170+++ b/drivers/net/ethernet/emulex/benet/be_main.c
40171@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
40172
40173 if (wrapped)
40174 newacc += 65536;
40175- ACCESS_ONCE(*acc) = newacc;
40176+ ACCESS_ONCE_RW(*acc) = newacc;
40177 }
40178
40179 void populate_erx_stats(struct be_adapter *adapter,
40180diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
40181index 21b85fb..b49e5fc 100644
40182--- a/drivers/net/ethernet/faraday/ftgmac100.c
40183+++ b/drivers/net/ethernet/faraday/ftgmac100.c
40184@@ -31,6 +31,8 @@
40185 #include <linux/netdevice.h>
40186 #include <linux/phy.h>
40187 #include <linux/platform_device.h>
40188+#include <linux/interrupt.h>
40189+#include <linux/irqreturn.h>
40190 #include <net/ip.h>
40191
40192 #include "ftgmac100.h"
40193diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
40194index a6eda8d..935d273 100644
40195--- a/drivers/net/ethernet/faraday/ftmac100.c
40196+++ b/drivers/net/ethernet/faraday/ftmac100.c
40197@@ -31,6 +31,8 @@
40198 #include <linux/module.h>
40199 #include <linux/netdevice.h>
40200 #include <linux/platform_device.h>
40201+#include <linux/interrupt.h>
40202+#include <linux/irqreturn.h>
40203
40204 #include "ftmac100.h"
40205
40206diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40207index 331987d..3be1135 100644
40208--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40209+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
40210@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
40211 }
40212
40213 /* update the base incval used to calculate frequency adjustment */
40214- ACCESS_ONCE(adapter->base_incval) = incval;
40215+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
40216 smp_mb();
40217
40218 /* need lock to prevent incorrect read while modifying cyclecounter */
40219diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40220index fbe5363..266b4e3 100644
40221--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
40222+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
40223@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40224 struct __vxge_hw_fifo *fifo;
40225 struct vxge_hw_fifo_config *config;
40226 u32 txdl_size, txdl_per_memblock;
40227- struct vxge_hw_mempool_cbs fifo_mp_callback;
40228+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
40229+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
40230+ };
40231+
40232 struct __vxge_hw_virtualpath *vpath;
40233
40234 if ((vp == NULL) || (attr == NULL)) {
40235@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
40236 goto exit;
40237 }
40238
40239- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
40240-
40241 fifo->mempool =
40242 __vxge_hw_mempool_create(vpath->hldev,
40243 fifo->config->memblock_size,
40244diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40245index 5e7fb1d..f8d1810 100644
40246--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40247+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
40248@@ -1948,7 +1948,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
40249 op_mode = QLC_83XX_DEFAULT_OPMODE;
40250
40251 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
40252- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40253+ pax_open_kernel();
40254+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
40255+ pax_close_kernel();
40256 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40257 } else {
40258 return -EIO;
40259diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40260index b0c3de9..fc5857e 100644
40261--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40262+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
40263@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
40264 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
40265 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
40266 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40267- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40268+ pax_open_kernel();
40269+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40270+ pax_close_kernel();
40271 } else if (priv_level == QLCNIC_PRIV_FUNC) {
40272 ahw->op_mode = QLCNIC_PRIV_FUNC;
40273 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
40274- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40275+ pax_open_kernel();
40276+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40277+ pax_close_kernel();
40278 } else if (priv_level == QLCNIC_MGMT_FUNC) {
40279 ahw->op_mode = QLCNIC_MGMT_FUNC;
40280 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40281- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40282+ pax_open_kernel();
40283+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40284+ pax_close_kernel();
40285 } else {
40286 return -EIO;
40287 }
40288diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40289index 393f961..d343034 100644
40290--- a/drivers/net/ethernet/realtek/r8169.c
40291+++ b/drivers/net/ethernet/realtek/r8169.c
40292@@ -753,22 +753,22 @@ struct rtl8169_private {
40293 struct mdio_ops {
40294 void (*write)(struct rtl8169_private *, int, int);
40295 int (*read)(struct rtl8169_private *, int);
40296- } mdio_ops;
40297+ } __no_const mdio_ops;
40298
40299 struct pll_power_ops {
40300 void (*down)(struct rtl8169_private *);
40301 void (*up)(struct rtl8169_private *);
40302- } pll_power_ops;
40303+ } __no_const pll_power_ops;
40304
40305 struct jumbo_ops {
40306 void (*enable)(struct rtl8169_private *);
40307 void (*disable)(struct rtl8169_private *);
40308- } jumbo_ops;
40309+ } __no_const jumbo_ops;
40310
40311 struct csi_ops {
40312 void (*write)(struct rtl8169_private *, int, int);
40313 u32 (*read)(struct rtl8169_private *, int);
40314- } csi_ops;
40315+ } __no_const csi_ops;
40316
40317 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40318 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40319diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40320index 9a95abf..36df7f9 100644
40321--- a/drivers/net/ethernet/sfc/ptp.c
40322+++ b/drivers/net/ethernet/sfc/ptp.c
40323@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40324 (u32)((u64)ptp->start.dma_addr >> 32));
40325
40326 /* Clear flag that signals MC ready */
40327- ACCESS_ONCE(*start) = 0;
40328+ ACCESS_ONCE_RW(*start) = 0;
40329 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40330 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40331
40332diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40333index 50617c5..b13724c 100644
40334--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40335+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40336@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40337
40338 writel(value, ioaddr + MMC_CNTRL);
40339
40340- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40341- MMC_CNTRL, value);
40342+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40343+// MMC_CNTRL, value);
40344 }
40345
40346 /* To mask all all interrupts.*/
40347diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40348index e6fe0d8..2b7d752 100644
40349--- a/drivers/net/hyperv/hyperv_net.h
40350+++ b/drivers/net/hyperv/hyperv_net.h
40351@@ -101,7 +101,7 @@ struct rndis_device {
40352
40353 enum rndis_device_state state;
40354 bool link_state;
40355- atomic_t new_req_id;
40356+ atomic_unchecked_t new_req_id;
40357
40358 spinlock_t request_lock;
40359 struct list_head req_list;
40360diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40361index 0775f0a..d4fb316 100644
40362--- a/drivers/net/hyperv/rndis_filter.c
40363+++ b/drivers/net/hyperv/rndis_filter.c
40364@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40365 * template
40366 */
40367 set = &rndis_msg->msg.set_req;
40368- set->req_id = atomic_inc_return(&dev->new_req_id);
40369+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40370
40371 /* Add to the request list */
40372 spin_lock_irqsave(&dev->request_lock, flags);
40373@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40374
40375 /* Setup the rndis set */
40376 halt = &request->request_msg.msg.halt_req;
40377- halt->req_id = atomic_inc_return(&dev->new_req_id);
40378+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40379
40380 /* Ignore return since this msg is optional. */
40381 rndis_filter_send_request(dev, request);
40382diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40383index bf0d55e..82bcfbd1 100644
40384--- a/drivers/net/ieee802154/fakehard.c
40385+++ b/drivers/net/ieee802154/fakehard.c
40386@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40387 phy->transmit_power = 0xbf;
40388
40389 dev->netdev_ops = &fake_ops;
40390- dev->ml_priv = &fake_mlme;
40391+ dev->ml_priv = (void *)&fake_mlme;
40392
40393 priv = netdev_priv(dev);
40394 priv->phy = phy;
40395diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40396index 6e91931..2b0ebe7 100644
40397--- a/drivers/net/macvlan.c
40398+++ b/drivers/net/macvlan.c
40399@@ -905,13 +905,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40400 int macvlan_link_register(struct rtnl_link_ops *ops)
40401 {
40402 /* common fields */
40403- ops->priv_size = sizeof(struct macvlan_dev);
40404- ops->validate = macvlan_validate;
40405- ops->maxtype = IFLA_MACVLAN_MAX;
40406- ops->policy = macvlan_policy;
40407- ops->changelink = macvlan_changelink;
40408- ops->get_size = macvlan_get_size;
40409- ops->fill_info = macvlan_fill_info;
40410+ pax_open_kernel();
40411+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40412+ *(void **)&ops->validate = macvlan_validate;
40413+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40414+ *(const void **)&ops->policy = macvlan_policy;
40415+ *(void **)&ops->changelink = macvlan_changelink;
40416+ *(void **)&ops->get_size = macvlan_get_size;
40417+ *(void **)&ops->fill_info = macvlan_fill_info;
40418+ pax_close_kernel();
40419
40420 return rtnl_link_register(ops);
40421 };
40422@@ -967,7 +969,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40423 return NOTIFY_DONE;
40424 }
40425
40426-static struct notifier_block macvlan_notifier_block __read_mostly = {
40427+static struct notifier_block macvlan_notifier_block = {
40428 .notifier_call = macvlan_device_event,
40429 };
40430
40431diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40432index b6dd6a7..5c38a02 100644
40433--- a/drivers/net/macvtap.c
40434+++ b/drivers/net/macvtap.c
40435@@ -1094,7 +1094,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40436 return NOTIFY_DONE;
40437 }
40438
40439-static struct notifier_block macvtap_notifier_block __read_mostly = {
40440+static struct notifier_block macvtap_notifier_block = {
40441 .notifier_call = macvtap_device_event,
40442 };
40443
40444diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40445index daec9b0..6428fcb 100644
40446--- a/drivers/net/phy/mdio-bitbang.c
40447+++ b/drivers/net/phy/mdio-bitbang.c
40448@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40449 struct mdiobb_ctrl *ctrl = bus->priv;
40450
40451 module_put(ctrl->ops->owner);
40452+ mdiobus_unregister(bus);
40453 mdiobus_free(bus);
40454 }
40455 EXPORT_SYMBOL(free_mdio_bitbang);
40456diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40457index 72ff14b..11d442d 100644
40458--- a/drivers/net/ppp/ppp_generic.c
40459+++ b/drivers/net/ppp/ppp_generic.c
40460@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40461 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40462 struct ppp_stats stats;
40463 struct ppp_comp_stats cstats;
40464- char *vers;
40465
40466 switch (cmd) {
40467 case SIOCGPPPSTATS:
40468@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40469 break;
40470
40471 case SIOCGPPPVER:
40472- vers = PPP_VERSION;
40473- if (copy_to_user(addr, vers, strlen(vers) + 1))
40474+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40475 break;
40476 err = 0;
40477 break;
40478diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
40479index 1252d9c..80e660b 100644
40480--- a/drivers/net/slip/slhc.c
40481+++ b/drivers/net/slip/slhc.c
40482@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
40483 register struct tcphdr *thp;
40484 register struct iphdr *ip;
40485 register struct cstate *cs;
40486- int len, hdrlen;
40487+ long len, hdrlen;
40488 unsigned char *cp = icp;
40489
40490 /* We've got a compressed packet; read the change byte */
40491diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40492index b305105..8ead6df 100644
40493--- a/drivers/net/team/team.c
40494+++ b/drivers/net/team/team.c
40495@@ -2682,7 +2682,7 @@ static int team_device_event(struct notifier_block *unused,
40496 return NOTIFY_DONE;
40497 }
40498
40499-static struct notifier_block team_notifier_block __read_mostly = {
40500+static struct notifier_block team_notifier_block = {
40501 .notifier_call = team_device_event,
40502 };
40503
40504diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40505index 9c61f87..213609e 100644
40506--- a/drivers/net/tun.c
40507+++ b/drivers/net/tun.c
40508@@ -1852,7 +1852,7 @@ unlock:
40509 }
40510
40511 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40512- unsigned long arg, int ifreq_len)
40513+ unsigned long arg, size_t ifreq_len)
40514 {
40515 struct tun_file *tfile = file->private_data;
40516 struct tun_struct *tun;
40517@@ -1864,6 +1864,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40518 int vnet_hdr_sz;
40519 int ret;
40520
40521+ if (ifreq_len > sizeof ifr)
40522+ return -EFAULT;
40523+
40524 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40525 if (copy_from_user(&ifr, argp, ifreq_len))
40526 return -EFAULT;
40527diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40528index cba1d46..f703766 100644
40529--- a/drivers/net/usb/hso.c
40530+++ b/drivers/net/usb/hso.c
40531@@ -71,7 +71,7 @@
40532 #include <asm/byteorder.h>
40533 #include <linux/serial_core.h>
40534 #include <linux/serial.h>
40535-
40536+#include <asm/local.h>
40537
40538 #define MOD_AUTHOR "Option Wireless"
40539 #define MOD_DESCRIPTION "USB High Speed Option driver"
40540@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40541 struct urb *urb;
40542
40543 urb = serial->rx_urb[0];
40544- if (serial->port.count > 0) {
40545+ if (atomic_read(&serial->port.count) > 0) {
40546 count = put_rxbuf_data(urb, serial);
40547 if (count == -1)
40548 return;
40549@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40550 DUMP1(urb->transfer_buffer, urb->actual_length);
40551
40552 /* Anyone listening? */
40553- if (serial->port.count == 0)
40554+ if (atomic_read(&serial->port.count) == 0)
40555 return;
40556
40557 if (status == 0) {
40558@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40559 tty_port_tty_set(&serial->port, tty);
40560
40561 /* check for port already opened, if not set the termios */
40562- serial->port.count++;
40563- if (serial->port.count == 1) {
40564+ if (atomic_inc_return(&serial->port.count) == 1) {
40565 serial->rx_state = RX_IDLE;
40566 /* Force default termio settings */
40567 _hso_serial_set_termios(tty, NULL);
40568@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40569 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40570 if (result) {
40571 hso_stop_serial_device(serial->parent);
40572- serial->port.count--;
40573+ atomic_dec(&serial->port.count);
40574 kref_put(&serial->parent->ref, hso_serial_ref_free);
40575 }
40576 } else {
40577@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40578
40579 /* reset the rts and dtr */
40580 /* do the actual close */
40581- serial->port.count--;
40582+ atomic_dec(&serial->port.count);
40583
40584- if (serial->port.count <= 0) {
40585- serial->port.count = 0;
40586+ if (atomic_read(&serial->port.count) <= 0) {
40587+ atomic_set(&serial->port.count, 0);
40588 tty_port_tty_set(&serial->port, NULL);
40589 if (!usb_gone)
40590 hso_stop_serial_device(serial->parent);
40591@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40592
40593 /* the actual setup */
40594 spin_lock_irqsave(&serial->serial_lock, flags);
40595- if (serial->port.count)
40596+ if (atomic_read(&serial->port.count))
40597 _hso_serial_set_termios(tty, old);
40598 else
40599 tty->termios = *old;
40600@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40601 D1("Pending read interrupt on port %d\n", i);
40602 spin_lock(&serial->serial_lock);
40603 if (serial->rx_state == RX_IDLE &&
40604- serial->port.count > 0) {
40605+ atomic_read(&serial->port.count) > 0) {
40606 /* Setup and send a ctrl req read on
40607 * port i */
40608 if (!serial->rx_urb_filled[0]) {
40609@@ -3057,7 +3056,7 @@ static int hso_resume(struct usb_interface *iface)
40610 /* Start all serial ports */
40611 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40612 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40613- if (dev2ser(serial_table[i])->port.count) {
40614+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40615 result =
40616 hso_start_serial_device(serial_table[i], GFP_NOIO);
40617 hso_kick_transmit(dev2ser(serial_table[i]));
40618diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40619index 57325f3..36b181f 100644
40620--- a/drivers/net/vxlan.c
40621+++ b/drivers/net/vxlan.c
40622@@ -1579,7 +1579,7 @@ nla_put_failure:
40623 return -EMSGSIZE;
40624 }
40625
40626-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40627+static struct rtnl_link_ops vxlan_link_ops = {
40628 .kind = "vxlan",
40629 .maxtype = IFLA_VXLAN_MAX,
40630 .policy = vxlan_policy,
40631diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40632index 34c8a33..3261fdc 100644
40633--- a/drivers/net/wireless/at76c50x-usb.c
40634+++ b/drivers/net/wireless/at76c50x-usb.c
40635@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40636 }
40637
40638 /* Convert timeout from the DFU status to jiffies */
40639-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40640+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40641 {
40642 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40643 | (s->poll_timeout[1] << 8)
40644diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40645index 8d78253..bebbb68 100644
40646--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40647+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40648@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40649 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40650 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40651
40652- ACCESS_ONCE(ads->ds_link) = i->link;
40653- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40654+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40655+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40656
40657 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40658 ctl6 = SM(i->keytype, AR_EncrType);
40659@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40660
40661 if ((i->is_first || i->is_last) &&
40662 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40663- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40664+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40665 | set11nTries(i->rates, 1)
40666 | set11nTries(i->rates, 2)
40667 | set11nTries(i->rates, 3)
40668 | (i->dur_update ? AR_DurUpdateEna : 0)
40669 | SM(0, AR_BurstDur);
40670
40671- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40672+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40673 | set11nRate(i->rates, 1)
40674 | set11nRate(i->rates, 2)
40675 | set11nRate(i->rates, 3);
40676 } else {
40677- ACCESS_ONCE(ads->ds_ctl2) = 0;
40678- ACCESS_ONCE(ads->ds_ctl3) = 0;
40679+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40680+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40681 }
40682
40683 if (!i->is_first) {
40684- ACCESS_ONCE(ads->ds_ctl0) = 0;
40685- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40686- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40687+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40688+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40689+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40690 return;
40691 }
40692
40693@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40694 break;
40695 }
40696
40697- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40698+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40699 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40700 | SM(i->txpower, AR_XmitPower)
40701 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40702@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40703 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40704 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40705
40706- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40707- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40708+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40709+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40710
40711 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40712 return;
40713
40714- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40715+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40716 | set11nPktDurRTSCTS(i->rates, 1);
40717
40718- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40719+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40720 | set11nPktDurRTSCTS(i->rates, 3);
40721
40722- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40723+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40724 | set11nRateFlags(i->rates, 1)
40725 | set11nRateFlags(i->rates, 2)
40726 | set11nRateFlags(i->rates, 3)
40727diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40728index 301bf72..3f5654f 100644
40729--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40730+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40731@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40732 (i->qcu << AR_TxQcuNum_S) | desc_len;
40733
40734 checksum += val;
40735- ACCESS_ONCE(ads->info) = val;
40736+ ACCESS_ONCE_RW(ads->info) = val;
40737
40738 checksum += i->link;
40739- ACCESS_ONCE(ads->link) = i->link;
40740+ ACCESS_ONCE_RW(ads->link) = i->link;
40741
40742 checksum += i->buf_addr[0];
40743- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40744+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40745 checksum += i->buf_addr[1];
40746- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40747+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40748 checksum += i->buf_addr[2];
40749- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40750+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40751 checksum += i->buf_addr[3];
40752- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40753+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40754
40755 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40756- ACCESS_ONCE(ads->ctl3) = val;
40757+ ACCESS_ONCE_RW(ads->ctl3) = val;
40758 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40759- ACCESS_ONCE(ads->ctl5) = val;
40760+ ACCESS_ONCE_RW(ads->ctl5) = val;
40761 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40762- ACCESS_ONCE(ads->ctl7) = val;
40763+ ACCESS_ONCE_RW(ads->ctl7) = val;
40764 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40765- ACCESS_ONCE(ads->ctl9) = val;
40766+ ACCESS_ONCE_RW(ads->ctl9) = val;
40767
40768 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40769- ACCESS_ONCE(ads->ctl10) = checksum;
40770+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40771
40772 if (i->is_first || i->is_last) {
40773- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40774+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40775 | set11nTries(i->rates, 1)
40776 | set11nTries(i->rates, 2)
40777 | set11nTries(i->rates, 3)
40778 | (i->dur_update ? AR_DurUpdateEna : 0)
40779 | SM(0, AR_BurstDur);
40780
40781- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40782+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40783 | set11nRate(i->rates, 1)
40784 | set11nRate(i->rates, 2)
40785 | set11nRate(i->rates, 3);
40786 } else {
40787- ACCESS_ONCE(ads->ctl13) = 0;
40788- ACCESS_ONCE(ads->ctl14) = 0;
40789+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40790+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40791 }
40792
40793 ads->ctl20 = 0;
40794@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40795
40796 ctl17 = SM(i->keytype, AR_EncrType);
40797 if (!i->is_first) {
40798- ACCESS_ONCE(ads->ctl11) = 0;
40799- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40800- ACCESS_ONCE(ads->ctl15) = 0;
40801- ACCESS_ONCE(ads->ctl16) = 0;
40802- ACCESS_ONCE(ads->ctl17) = ctl17;
40803- ACCESS_ONCE(ads->ctl18) = 0;
40804- ACCESS_ONCE(ads->ctl19) = 0;
40805+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40806+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40807+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40808+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40809+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40810+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40811+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40812 return;
40813 }
40814
40815- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40816+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40817 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40818 | SM(i->txpower, AR_XmitPower)
40819 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40820@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40821 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40822 ctl12 |= SM(val, AR_PAPRDChainMask);
40823
40824- ACCESS_ONCE(ads->ctl12) = ctl12;
40825- ACCESS_ONCE(ads->ctl17) = ctl17;
40826+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40827+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40828
40829- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40830+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40831 | set11nPktDurRTSCTS(i->rates, 1);
40832
40833- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40834+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40835 | set11nPktDurRTSCTS(i->rates, 3);
40836
40837- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40838+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40839 | set11nRateFlags(i->rates, 1)
40840 | set11nRateFlags(i->rates, 2)
40841 | set11nRateFlags(i->rates, 3)
40842 | SM(i->rtscts_rate, AR_RTSCTSRate);
40843
40844- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40845+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40846 }
40847
40848 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40849diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40850index ae30343..a117806 100644
40851--- a/drivers/net/wireless/ath/ath9k/hw.h
40852+++ b/drivers/net/wireless/ath/ath9k/hw.h
40853@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
40854
40855 /* ANI */
40856 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40857-};
40858+} __no_const;
40859
40860 /**
40861 * struct ath_spec_scan - parameters for Atheros spectral scan
40862@@ -721,7 +721,7 @@ struct ath_hw_ops {
40863 struct ath_spec_scan *param);
40864 void (*spectral_scan_trigger)(struct ath_hw *ah);
40865 void (*spectral_scan_wait)(struct ath_hw *ah);
40866-};
40867+} __no_const;
40868
40869 struct ath_nf_limits {
40870 s16 max;
40871diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40872index b37a582..680835d 100644
40873--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40874+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40875@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40876 */
40877 if (il3945_mod_params.disable_hw_scan) {
40878 D_INFO("Disabling hw_scan\n");
40879- il3945_mac_ops.hw_scan = NULL;
40880+ pax_open_kernel();
40881+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40882+ pax_close_kernel();
40883 }
40884
40885 D_INFO("*** LOAD DRIVER ***\n");
40886diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40887index d532948..a1cb592 100644
40888--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40889+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40890@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40891 {
40892 struct iwl_priv *priv = file->private_data;
40893 char buf[64];
40894- int buf_size;
40895+ size_t buf_size;
40896 u32 offset, len;
40897
40898 memset(buf, 0, sizeof(buf));
40899@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40900 struct iwl_priv *priv = file->private_data;
40901
40902 char buf[8];
40903- int buf_size;
40904+ size_t buf_size;
40905 u32 reset_flag;
40906
40907 memset(buf, 0, sizeof(buf));
40908@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40909 {
40910 struct iwl_priv *priv = file->private_data;
40911 char buf[8];
40912- int buf_size;
40913+ size_t buf_size;
40914 int ht40;
40915
40916 memset(buf, 0, sizeof(buf));
40917@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40918 {
40919 struct iwl_priv *priv = file->private_data;
40920 char buf[8];
40921- int buf_size;
40922+ size_t buf_size;
40923 int value;
40924
40925 memset(buf, 0, sizeof(buf));
40926@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40927 {
40928 struct iwl_priv *priv = file->private_data;
40929 char buf[8];
40930- int buf_size;
40931+ size_t buf_size;
40932 int clear;
40933
40934 memset(buf, 0, sizeof(buf));
40935@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40936 {
40937 struct iwl_priv *priv = file->private_data;
40938 char buf[8];
40939- int buf_size;
40940+ size_t buf_size;
40941 int trace;
40942
40943 memset(buf, 0, sizeof(buf));
40944@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40945 {
40946 struct iwl_priv *priv = file->private_data;
40947 char buf[8];
40948- int buf_size;
40949+ size_t buf_size;
40950 int missed;
40951
40952 memset(buf, 0, sizeof(buf));
40953@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40954
40955 struct iwl_priv *priv = file->private_data;
40956 char buf[8];
40957- int buf_size;
40958+ size_t buf_size;
40959 int plcp;
40960
40961 memset(buf, 0, sizeof(buf));
40962@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40963
40964 struct iwl_priv *priv = file->private_data;
40965 char buf[8];
40966- int buf_size;
40967+ size_t buf_size;
40968 int flush;
40969
40970 memset(buf, 0, sizeof(buf));
40971@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40972
40973 struct iwl_priv *priv = file->private_data;
40974 char buf[8];
40975- int buf_size;
40976+ size_t buf_size;
40977 int rts;
40978
40979 if (!priv->cfg->ht_params)
40980@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40981 {
40982 struct iwl_priv *priv = file->private_data;
40983 char buf[8];
40984- int buf_size;
40985+ size_t buf_size;
40986
40987 memset(buf, 0, sizeof(buf));
40988 buf_size = min(count, sizeof(buf) - 1);
40989@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40990 struct iwl_priv *priv = file->private_data;
40991 u32 event_log_flag;
40992 char buf[8];
40993- int buf_size;
40994+ size_t buf_size;
40995
40996 /* check that the interface is up */
40997 if (!iwl_is_ready(priv))
40998@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40999 struct iwl_priv *priv = file->private_data;
41000 char buf[8];
41001 u32 calib_disabled;
41002- int buf_size;
41003+ size_t buf_size;
41004
41005 memset(buf, 0, sizeof(buf));
41006 buf_size = min(count, sizeof(buf) - 1);
41007diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
41008index 50ba0a4..29424e7 100644
41009--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
41010+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
41011@@ -1329,7 +1329,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
41012 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
41013
41014 char buf[8];
41015- int buf_size;
41016+ size_t buf_size;
41017 u32 reset_flag;
41018
41019 memset(buf, 0, sizeof(buf));
41020@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
41021 {
41022 struct iwl_trans *trans = file->private_data;
41023 char buf[8];
41024- int buf_size;
41025+ size_t buf_size;
41026 int csr;
41027
41028 memset(buf, 0, sizeof(buf));
41029diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
41030index cb34c78..9fec0dc 100644
41031--- a/drivers/net/wireless/mac80211_hwsim.c
41032+++ b/drivers/net/wireless/mac80211_hwsim.c
41033@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
41034
41035 if (channels > 1) {
41036 hwsim_if_comb.num_different_channels = channels;
41037- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41038- mac80211_hwsim_ops.cancel_hw_scan =
41039- mac80211_hwsim_cancel_hw_scan;
41040- mac80211_hwsim_ops.sw_scan_start = NULL;
41041- mac80211_hwsim_ops.sw_scan_complete = NULL;
41042- mac80211_hwsim_ops.remain_on_channel =
41043- mac80211_hwsim_roc;
41044- mac80211_hwsim_ops.cancel_remain_on_channel =
41045- mac80211_hwsim_croc;
41046- mac80211_hwsim_ops.add_chanctx =
41047- mac80211_hwsim_add_chanctx;
41048- mac80211_hwsim_ops.remove_chanctx =
41049- mac80211_hwsim_remove_chanctx;
41050- mac80211_hwsim_ops.change_chanctx =
41051- mac80211_hwsim_change_chanctx;
41052- mac80211_hwsim_ops.assign_vif_chanctx =
41053- mac80211_hwsim_assign_vif_chanctx;
41054- mac80211_hwsim_ops.unassign_vif_chanctx =
41055- mac80211_hwsim_unassign_vif_chanctx;
41056+ pax_open_kernel();
41057+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
41058+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
41059+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
41060+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
41061+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
41062+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
41063+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
41064+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
41065+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
41066+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
41067+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
41068+ pax_close_kernel();
41069 }
41070
41071 spin_lock_init(&hwsim_radio_lock);
41072diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
41073index 8169a85..7fa3b47 100644
41074--- a/drivers/net/wireless/rndis_wlan.c
41075+++ b/drivers/net/wireless/rndis_wlan.c
41076@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
41077
41078 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
41079
41080- if (rts_threshold < 0 || rts_threshold > 2347)
41081+ if (rts_threshold > 2347)
41082 rts_threshold = 2347;
41083
41084 tmp = cpu_to_le32(rts_threshold);
41085diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
41086index 7510723..5ba37f5 100644
41087--- a/drivers/net/wireless/rt2x00/rt2x00.h
41088+++ b/drivers/net/wireless/rt2x00/rt2x00.h
41089@@ -386,7 +386,7 @@ struct rt2x00_intf {
41090 * for hardware which doesn't support hardware
41091 * sequence counting.
41092 */
41093- atomic_t seqno;
41094+ atomic_unchecked_t seqno;
41095 };
41096
41097 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
41098diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
41099index 2c12311..7b77f24 100644
41100--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
41101+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
41102@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
41103 * sequence counter given by mac80211.
41104 */
41105 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
41106- seqno = atomic_add_return(0x10, &intf->seqno);
41107+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
41108 else
41109- seqno = atomic_read(&intf->seqno);
41110+ seqno = atomic_read_unchecked(&intf->seqno);
41111
41112 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
41113 hdr->seq_ctrl |= cpu_to_le16(seqno);
41114diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
41115index e2b3d9c..67a5184 100644
41116--- a/drivers/net/wireless/ti/wl1251/sdio.c
41117+++ b/drivers/net/wireless/ti/wl1251/sdio.c
41118@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
41119
41120 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
41121
41122- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41123- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41124+ pax_open_kernel();
41125+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
41126+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
41127+ pax_close_kernel();
41128
41129 wl1251_info("using dedicated interrupt line");
41130 } else {
41131- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41132- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41133+ pax_open_kernel();
41134+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
41135+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
41136+ pax_close_kernel();
41137
41138 wl1251_info("using SDIO interrupt");
41139 }
41140diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
41141index 1c627da..69f7d17 100644
41142--- a/drivers/net/wireless/ti/wl12xx/main.c
41143+++ b/drivers/net/wireless/ti/wl12xx/main.c
41144@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41145 sizeof(wl->conf.mem));
41146
41147 /* read data preparation is only needed by wl127x */
41148- wl->ops->prepare_read = wl127x_prepare_read;
41149+ pax_open_kernel();
41150+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41151+ pax_close_kernel();
41152
41153 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41154 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41155@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41156 sizeof(wl->conf.mem));
41157
41158 /* read data preparation is only needed by wl127x */
41159- wl->ops->prepare_read = wl127x_prepare_read;
41160+ pax_open_kernel();
41161+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41162+ pax_close_kernel();
41163
41164 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41165 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41166diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41167index 9fa692d..b31fee0 100644
41168--- a/drivers/net/wireless/ti/wl18xx/main.c
41169+++ b/drivers/net/wireless/ti/wl18xx/main.c
41170@@ -1687,8 +1687,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41171 }
41172
41173 if (!checksum_param) {
41174- wl18xx_ops.set_rx_csum = NULL;
41175- wl18xx_ops.init_vif = NULL;
41176+ pax_open_kernel();
41177+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41178+ *(void **)&wl18xx_ops.init_vif = NULL;
41179+ pax_close_kernel();
41180 }
41181
41182 /* Enable 11a Band only if we have 5G antennas */
41183diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41184index 7ef0b4a..ff65c28 100644
41185--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41186+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41187@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
41188 {
41189 struct zd_usb *usb = urb->context;
41190 struct zd_usb_interrupt *intr = &usb->intr;
41191- int len;
41192+ unsigned int len;
41193 u16 int_num;
41194
41195 ZD_ASSERT(in_interrupt());
41196diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41197index d93b2b6..ae50401 100644
41198--- a/drivers/oprofile/buffer_sync.c
41199+++ b/drivers/oprofile/buffer_sync.c
41200@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41201 if (cookie == NO_COOKIE)
41202 offset = pc;
41203 if (cookie == INVALID_COOKIE) {
41204- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41205+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41206 offset = pc;
41207 }
41208 if (cookie != last_cookie) {
41209@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41210 /* add userspace sample */
41211
41212 if (!mm) {
41213- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41214+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41215 return 0;
41216 }
41217
41218 cookie = lookup_dcookie(mm, s->eip, &offset);
41219
41220 if (cookie == INVALID_COOKIE) {
41221- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41222+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41223 return 0;
41224 }
41225
41226@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41227 /* ignore backtraces if failed to add a sample */
41228 if (state == sb_bt_start) {
41229 state = sb_bt_ignore;
41230- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41231+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41232 }
41233 }
41234 release_mm(mm);
41235diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41236index c0cc4e7..44d4e54 100644
41237--- a/drivers/oprofile/event_buffer.c
41238+++ b/drivers/oprofile/event_buffer.c
41239@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41240 }
41241
41242 if (buffer_pos == buffer_size) {
41243- atomic_inc(&oprofile_stats.event_lost_overflow);
41244+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41245 return;
41246 }
41247
41248diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41249index ed2c3ec..deda85a 100644
41250--- a/drivers/oprofile/oprof.c
41251+++ b/drivers/oprofile/oprof.c
41252@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41253 if (oprofile_ops.switch_events())
41254 return;
41255
41256- atomic_inc(&oprofile_stats.multiplex_counter);
41257+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41258 start_switch_worker();
41259 }
41260
41261diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41262index 84a208d..d61b0a1 100644
41263--- a/drivers/oprofile/oprofile_files.c
41264+++ b/drivers/oprofile/oprofile_files.c
41265@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41266
41267 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41268
41269-static ssize_t timeout_read(struct file *file, char __user *buf,
41270+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41271 size_t count, loff_t *offset)
41272 {
41273 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41274diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41275index 917d28e..d62d981 100644
41276--- a/drivers/oprofile/oprofile_stats.c
41277+++ b/drivers/oprofile/oprofile_stats.c
41278@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41279 cpu_buf->sample_invalid_eip = 0;
41280 }
41281
41282- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41283- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41284- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41285- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41286- atomic_set(&oprofile_stats.multiplex_counter, 0);
41287+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41288+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41289+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41290+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41291+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41292 }
41293
41294
41295diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41296index 38b6fc0..b5cbfce 100644
41297--- a/drivers/oprofile/oprofile_stats.h
41298+++ b/drivers/oprofile/oprofile_stats.h
41299@@ -13,11 +13,11 @@
41300 #include <linux/atomic.h>
41301
41302 struct oprofile_stat_struct {
41303- atomic_t sample_lost_no_mm;
41304- atomic_t sample_lost_no_mapping;
41305- atomic_t bt_lost_no_mapping;
41306- atomic_t event_lost_overflow;
41307- atomic_t multiplex_counter;
41308+ atomic_unchecked_t sample_lost_no_mm;
41309+ atomic_unchecked_t sample_lost_no_mapping;
41310+ atomic_unchecked_t bt_lost_no_mapping;
41311+ atomic_unchecked_t event_lost_overflow;
41312+ atomic_unchecked_t multiplex_counter;
41313 };
41314
41315 extern struct oprofile_stat_struct oprofile_stats;
41316diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41317index 7c12d9c..558bf3bb 100644
41318--- a/drivers/oprofile/oprofilefs.c
41319+++ b/drivers/oprofile/oprofilefs.c
41320@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
41321
41322
41323 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41324- char const *name, atomic_t *val)
41325+ char const *name, atomic_unchecked_t *val)
41326 {
41327 return __oprofilefs_create_file(sb, root, name,
41328 &atomic_ro_fops, 0444, val);
41329diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41330index 93404f7..4a313d8 100644
41331--- a/drivers/oprofile/timer_int.c
41332+++ b/drivers/oprofile/timer_int.c
41333@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41334 return NOTIFY_OK;
41335 }
41336
41337-static struct notifier_block __refdata oprofile_cpu_notifier = {
41338+static struct notifier_block oprofile_cpu_notifier = {
41339 .notifier_call = oprofile_cpu_notify,
41340 };
41341
41342diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41343index 92ed045..62d39bd7 100644
41344--- a/drivers/parport/procfs.c
41345+++ b/drivers/parport/procfs.c
41346@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41347
41348 *ppos += len;
41349
41350- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41351+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41352 }
41353
41354 #ifdef CONFIG_PARPORT_1284
41355@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41356
41357 *ppos += len;
41358
41359- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41360+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41361 }
41362 #endif /* IEEE1284.3 support. */
41363
41364diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41365index c35e8ad..fc33beb 100644
41366--- a/drivers/pci/hotplug/acpiphp_ibm.c
41367+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41368@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41369 goto init_cleanup;
41370 }
41371
41372- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41373+ pax_open_kernel();
41374+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41375+ pax_close_kernel();
41376 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41377
41378 return retval;
41379diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41380index a6a71c4..c91097b 100644
41381--- a/drivers/pci/hotplug/cpcihp_generic.c
41382+++ b/drivers/pci/hotplug/cpcihp_generic.c
41383@@ -73,7 +73,6 @@ static u16 port;
41384 static unsigned int enum_bit;
41385 static u8 enum_mask;
41386
41387-static struct cpci_hp_controller_ops generic_hpc_ops;
41388 static struct cpci_hp_controller generic_hpc;
41389
41390 static int __init validate_parameters(void)
41391@@ -139,6 +138,10 @@ static int query_enum(void)
41392 return ((value & enum_mask) == enum_mask);
41393 }
41394
41395+static struct cpci_hp_controller_ops generic_hpc_ops = {
41396+ .query_enum = query_enum,
41397+};
41398+
41399 static int __init cpcihp_generic_init(void)
41400 {
41401 int status;
41402@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41403 pci_dev_put(dev);
41404
41405 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41406- generic_hpc_ops.query_enum = query_enum;
41407 generic_hpc.ops = &generic_hpc_ops;
41408
41409 status = cpci_hp_register_controller(&generic_hpc);
41410diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41411index 449b4bb..257e2e8 100644
41412--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41413+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41414@@ -59,7 +59,6 @@
41415 /* local variables */
41416 static bool debug;
41417 static bool poll;
41418-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41419 static struct cpci_hp_controller zt5550_hpc;
41420
41421 /* Primary cPCI bus bridge device */
41422@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41423 return 0;
41424 }
41425
41426+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41427+ .query_enum = zt5550_hc_query_enum,
41428+};
41429+
41430 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41431 {
41432 int status;
41433@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41434 dbg("returned from zt5550_hc_config");
41435
41436 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41437- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41438 zt5550_hpc.ops = &zt5550_hpc_ops;
41439 if(!poll) {
41440 zt5550_hpc.irq = hc_dev->irq;
41441 zt5550_hpc.irq_flags = IRQF_SHARED;
41442 zt5550_hpc.dev_id = hc_dev;
41443
41444- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41445- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41446- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41447+ pax_open_kernel();
41448+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41449+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41450+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41451+ pax_open_kernel();
41452 } else {
41453 info("using ENUM# polling mode");
41454 }
41455diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41456index 76ba8a1..20ca857 100644
41457--- a/drivers/pci/hotplug/cpqphp_nvram.c
41458+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41459@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41460
41461 void compaq_nvram_init (void __iomem *rom_start)
41462 {
41463+
41464+#ifndef CONFIG_PAX_KERNEXEC
41465 if (rom_start) {
41466 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41467 }
41468+#endif
41469+
41470 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41471
41472 /* initialize our int15 lock */
41473diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41474index ec20f74..c1d961e 100644
41475--- a/drivers/pci/hotplug/pci_hotplug_core.c
41476+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41477@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41478 return -EINVAL;
41479 }
41480
41481- slot->ops->owner = owner;
41482- slot->ops->mod_name = mod_name;
41483+ pax_open_kernel();
41484+ *(struct module **)&slot->ops->owner = owner;
41485+ *(const char **)&slot->ops->mod_name = mod_name;
41486+ pax_close_kernel();
41487
41488 mutex_lock(&pci_hp_mutex);
41489 /*
41490diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41491index 7d72c5e..edce02c 100644
41492--- a/drivers/pci/hotplug/pciehp_core.c
41493+++ b/drivers/pci/hotplug/pciehp_core.c
41494@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41495 struct slot *slot = ctrl->slot;
41496 struct hotplug_slot *hotplug = NULL;
41497 struct hotplug_slot_info *info = NULL;
41498- struct hotplug_slot_ops *ops = NULL;
41499+ hotplug_slot_ops_no_const *ops = NULL;
41500 char name[SLOT_NAME_SIZE];
41501 int retval = -ENOMEM;
41502
41503diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41504index 5b4a9d9..cd5ac1f 100644
41505--- a/drivers/pci/pci-sysfs.c
41506+++ b/drivers/pci/pci-sysfs.c
41507@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41508 {
41509 /* allocate attribute structure, piggyback attribute name */
41510 int name_len = write_combine ? 13 : 10;
41511- struct bin_attribute *res_attr;
41512+ bin_attribute_no_const *res_attr;
41513 int retval;
41514
41515 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41516@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41517 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41518 {
41519 int retval;
41520- struct bin_attribute *attr;
41521+ bin_attribute_no_const *attr;
41522
41523 /* If the device has VPD, try to expose it in sysfs. */
41524 if (dev->vpd) {
41525@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41526 {
41527 int retval;
41528 int rom_size = 0;
41529- struct bin_attribute *attr;
41530+ bin_attribute_no_const *attr;
41531
41532 if (!sysfs_initialized)
41533 return -EACCES;
41534diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41535index d1182c4..2a138ec 100644
41536--- a/drivers/pci/pci.h
41537+++ b/drivers/pci/pci.h
41538@@ -92,7 +92,7 @@ struct pci_vpd_ops {
41539 struct pci_vpd {
41540 unsigned int len;
41541 const struct pci_vpd_ops *ops;
41542- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41543+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41544 };
41545
41546 int pci_vpd_pci22_init(struct pci_dev *dev);
41547diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41548index d320df6..ca9a8f6 100644
41549--- a/drivers/pci/pcie/aspm.c
41550+++ b/drivers/pci/pcie/aspm.c
41551@@ -27,9 +27,9 @@
41552 #define MODULE_PARAM_PREFIX "pcie_aspm."
41553
41554 /* Note: those are not register definitions */
41555-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41556-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41557-#define ASPM_STATE_L1 (4) /* L1 state */
41558+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41559+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41560+#define ASPM_STATE_L1 (4U) /* L1 state */
41561 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41562 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41563
41564diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41565index 70f10fa..cb5e917 100644
41566--- a/drivers/pci/probe.c
41567+++ b/drivers/pci/probe.c
41568@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41569 struct pci_bus_region region;
41570 bool bar_too_big = false, bar_disabled = false;
41571
41572- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41573+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41574
41575 /* No printks while decoding is disabled! */
41576 if (!dev->mmio_always_on) {
41577diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41578index 0812608..b04018c4 100644
41579--- a/drivers/pci/proc.c
41580+++ b/drivers/pci/proc.c
41581@@ -453,7 +453,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41582 static int __init pci_proc_init(void)
41583 {
41584 struct pci_dev *dev = NULL;
41585+
41586+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41587+#ifdef CONFIG_GRKERNSEC_PROC_USER
41588+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41589+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41590+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41591+#endif
41592+#else
41593 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41594+#endif
41595 proc_create("devices", 0, proc_bus_pci_dir,
41596 &proc_bus_pci_dev_operations);
41597 proc_initialized = 1;
41598diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
41599index 3e5b4497..dcdfb70 100644
41600--- a/drivers/platform/x86/chromeos_laptop.c
41601+++ b/drivers/platform/x86/chromeos_laptop.c
41602@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
41603 return 0;
41604 }
41605
41606-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
41607+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
41608 {
41609 .ident = "Samsung Series 5 550 - Touchpad",
41610 .matches = {
41611diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41612index 6b22938..bc9700e 100644
41613--- a/drivers/platform/x86/msi-laptop.c
41614+++ b/drivers/platform/x86/msi-laptop.c
41615@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41616
41617 if (!quirks->ec_read_only) {
41618 /* allow userland write sysfs file */
41619- dev_attr_bluetooth.store = store_bluetooth;
41620- dev_attr_wlan.store = store_wlan;
41621- dev_attr_threeg.store = store_threeg;
41622- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41623- dev_attr_wlan.attr.mode |= S_IWUSR;
41624- dev_attr_threeg.attr.mode |= S_IWUSR;
41625+ pax_open_kernel();
41626+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41627+ *(void **)&dev_attr_wlan.store = store_wlan;
41628+ *(void **)&dev_attr_threeg.store = store_threeg;
41629+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41630+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41631+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41632+ pax_close_kernel();
41633 }
41634
41635 /* disable hardware control by fn key */
41636diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41637index 2ac045f..39c443d 100644
41638--- a/drivers/platform/x86/sony-laptop.c
41639+++ b/drivers/platform/x86/sony-laptop.c
41640@@ -2483,7 +2483,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
41641 }
41642
41643 /* High speed charging function */
41644-static struct device_attribute *hsc_handle;
41645+static device_attribute_no_const *hsc_handle;
41646
41647 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41648 struct device_attribute *attr,
41649diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41650index 54d31c0..3f896d3 100644
41651--- a/drivers/platform/x86/thinkpad_acpi.c
41652+++ b/drivers/platform/x86/thinkpad_acpi.c
41653@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
41654 return 0;
41655 }
41656
41657-void static hotkey_mask_warn_incomplete_mask(void)
41658+static void hotkey_mask_warn_incomplete_mask(void)
41659 {
41660 /* log only what the user can fix... */
41661 const u32 wantedmask = hotkey_driver_mask &
41662@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41663 }
41664 }
41665
41666-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41667- struct tp_nvram_state *newn,
41668- const u32 event_mask)
41669-{
41670-
41671 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41672 do { \
41673 if ((event_mask & (1 << __scancode)) && \
41674@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41675 tpacpi_hotkey_send_key(__scancode); \
41676 } while (0)
41677
41678- void issue_volchange(const unsigned int oldvol,
41679- const unsigned int newvol)
41680- {
41681- unsigned int i = oldvol;
41682+static void issue_volchange(const unsigned int oldvol,
41683+ const unsigned int newvol,
41684+ const u32 event_mask)
41685+{
41686+ unsigned int i = oldvol;
41687
41688- while (i > newvol) {
41689- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41690- i--;
41691- }
41692- while (i < newvol) {
41693- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41694- i++;
41695- }
41696+ while (i > newvol) {
41697+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41698+ i--;
41699 }
41700+ while (i < newvol) {
41701+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41702+ i++;
41703+ }
41704+}
41705
41706- void issue_brightnesschange(const unsigned int oldbrt,
41707- const unsigned int newbrt)
41708- {
41709- unsigned int i = oldbrt;
41710+static void issue_brightnesschange(const unsigned int oldbrt,
41711+ const unsigned int newbrt,
41712+ const u32 event_mask)
41713+{
41714+ unsigned int i = oldbrt;
41715
41716- while (i > newbrt) {
41717- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41718- i--;
41719- }
41720- while (i < newbrt) {
41721- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41722- i++;
41723- }
41724+ while (i > newbrt) {
41725+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41726+ i--;
41727+ }
41728+ while (i < newbrt) {
41729+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41730+ i++;
41731 }
41732+}
41733
41734+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41735+ struct tp_nvram_state *newn,
41736+ const u32 event_mask)
41737+{
41738 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41739 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41740 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41741@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41742 oldn->volume_level != newn->volume_level) {
41743 /* recently muted, or repeated mute keypress, or
41744 * multiple presses ending in mute */
41745- issue_volchange(oldn->volume_level, newn->volume_level);
41746+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41747 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41748 }
41749 } else {
41750@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41751 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41752 }
41753 if (oldn->volume_level != newn->volume_level) {
41754- issue_volchange(oldn->volume_level, newn->volume_level);
41755+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41756 } else if (oldn->volume_toggle != newn->volume_toggle) {
41757 /* repeated vol up/down keypress at end of scale ? */
41758 if (newn->volume_level == 0)
41759@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41760 /* handle brightness */
41761 if (oldn->brightness_level != newn->brightness_level) {
41762 issue_brightnesschange(oldn->brightness_level,
41763- newn->brightness_level);
41764+ newn->brightness_level,
41765+ event_mask);
41766 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41767 /* repeated key presses that didn't change state */
41768 if (newn->brightness_level == 0)
41769@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41770 && !tp_features.bright_unkfw)
41771 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41772 }
41773+}
41774
41775 #undef TPACPI_COMPARE_KEY
41776 #undef TPACPI_MAY_SEND_KEY
41777-}
41778
41779 /*
41780 * Polling driver
41781diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41782index 769d265..a3a05ca 100644
41783--- a/drivers/pnp/pnpbios/bioscalls.c
41784+++ b/drivers/pnp/pnpbios/bioscalls.c
41785@@ -58,7 +58,7 @@ do { \
41786 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41787 } while(0)
41788
41789-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41790+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41791 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41792
41793 /*
41794@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41795
41796 cpu = get_cpu();
41797 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41798+
41799+ pax_open_kernel();
41800 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41801+ pax_close_kernel();
41802
41803 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41804 spin_lock_irqsave(&pnp_bios_lock, flags);
41805@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41806 :"memory");
41807 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41808
41809+ pax_open_kernel();
41810 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41811+ pax_close_kernel();
41812+
41813 put_cpu();
41814
41815 /* If we get here and this is set then the PnP BIOS faulted on us. */
41816@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41817 return status;
41818 }
41819
41820-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41821+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41822 {
41823 int i;
41824
41825@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41826 pnp_bios_callpoint.offset = header->fields.pm16offset;
41827 pnp_bios_callpoint.segment = PNP_CS16;
41828
41829+ pax_open_kernel();
41830+
41831 for_each_possible_cpu(i) {
41832 struct desc_struct *gdt = get_cpu_gdt_table(i);
41833 if (!gdt)
41834@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41835 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41836 (unsigned long)__va(header->fields.pm16dseg));
41837 }
41838+
41839+ pax_close_kernel();
41840 }
41841diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41842index 3e6db1c..1fbbdae 100644
41843--- a/drivers/pnp/resource.c
41844+++ b/drivers/pnp/resource.c
41845@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41846 return 1;
41847
41848 /* check if the resource is valid */
41849- if (*irq < 0 || *irq > 15)
41850+ if (*irq > 15)
41851 return 0;
41852
41853 /* check if the resource is reserved */
41854@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41855 return 1;
41856
41857 /* check if the resource is valid */
41858- if (*dma < 0 || *dma == 4 || *dma > 7)
41859+ if (*dma == 4 || *dma > 7)
41860 return 0;
41861
41862 /* check if the resource is reserved */
41863diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41864index 0c52e2a..3421ab7 100644
41865--- a/drivers/power/pda_power.c
41866+++ b/drivers/power/pda_power.c
41867@@ -37,7 +37,11 @@ static int polling;
41868
41869 #if IS_ENABLED(CONFIG_USB_PHY)
41870 static struct usb_phy *transceiver;
41871-static struct notifier_block otg_nb;
41872+static int otg_handle_notification(struct notifier_block *nb,
41873+ unsigned long event, void *unused);
41874+static struct notifier_block otg_nb = {
41875+ .notifier_call = otg_handle_notification
41876+};
41877 #endif
41878
41879 static struct regulator *ac_draw;
41880@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41881
41882 #if IS_ENABLED(CONFIG_USB_PHY)
41883 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41884- otg_nb.notifier_call = otg_handle_notification;
41885 ret = usb_register_notifier(transceiver, &otg_nb);
41886 if (ret) {
41887 dev_err(dev, "failure to register otg notifier\n");
41888diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41889index cc439fd..8fa30df 100644
41890--- a/drivers/power/power_supply.h
41891+++ b/drivers/power/power_supply.h
41892@@ -16,12 +16,12 @@ struct power_supply;
41893
41894 #ifdef CONFIG_SYSFS
41895
41896-extern void power_supply_init_attrs(struct device_type *dev_type);
41897+extern void power_supply_init_attrs(void);
41898 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41899
41900 #else
41901
41902-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41903+static inline void power_supply_init_attrs(void) {}
41904 #define power_supply_uevent NULL
41905
41906 #endif /* CONFIG_SYSFS */
41907diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41908index 1c517c3..ffa2f17 100644
41909--- a/drivers/power/power_supply_core.c
41910+++ b/drivers/power/power_supply_core.c
41911@@ -24,7 +24,10 @@
41912 struct class *power_supply_class;
41913 EXPORT_SYMBOL_GPL(power_supply_class);
41914
41915-static struct device_type power_supply_dev_type;
41916+extern const struct attribute_group *power_supply_attr_groups[];
41917+static struct device_type power_supply_dev_type = {
41918+ .groups = power_supply_attr_groups,
41919+};
41920
41921 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
41922 struct power_supply *supply)
41923@@ -554,7 +557,7 @@ static int __init power_supply_class_init(void)
41924 return PTR_ERR(power_supply_class);
41925
41926 power_supply_class->dev_uevent = power_supply_uevent;
41927- power_supply_init_attrs(&power_supply_dev_type);
41928+ power_supply_init_attrs();
41929
41930 return 0;
41931 }
41932diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41933index 29178f7..c65f324 100644
41934--- a/drivers/power/power_supply_sysfs.c
41935+++ b/drivers/power/power_supply_sysfs.c
41936@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
41937 .is_visible = power_supply_attr_is_visible,
41938 };
41939
41940-static const struct attribute_group *power_supply_attr_groups[] = {
41941+const struct attribute_group *power_supply_attr_groups[] = {
41942 &power_supply_attr_group,
41943 NULL,
41944 };
41945
41946-void power_supply_init_attrs(struct device_type *dev_type)
41947+void power_supply_init_attrs(void)
41948 {
41949 int i;
41950
41951- dev_type->groups = power_supply_attr_groups;
41952-
41953 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41954 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41955 }
41956diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41957index d428ef9..fdc0357 100644
41958--- a/drivers/regulator/max8660.c
41959+++ b/drivers/regulator/max8660.c
41960@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41961 max8660->shadow_regs[MAX8660_OVER1] = 5;
41962 } else {
41963 /* Otherwise devices can be toggled via software */
41964- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41965- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41966+ pax_open_kernel();
41967+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41968+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41969+ pax_close_kernel();
41970 }
41971
41972 /*
41973diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41974index adb1414..c13e0ce 100644
41975--- a/drivers/regulator/max8973-regulator.c
41976+++ b/drivers/regulator/max8973-regulator.c
41977@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41978 if (!pdata->enable_ext_control) {
41979 max->desc.enable_reg = MAX8973_VOUT;
41980 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41981- max8973_dcdc_ops.enable = regulator_enable_regmap;
41982- max8973_dcdc_ops.disable = regulator_disable_regmap;
41983- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41984+ pax_open_kernel();
41985+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41986+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41987+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41988+ pax_close_kernel();
41989 }
41990
41991 max->enable_external_control = pdata->enable_ext_control;
41992diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41993index b716283..3cc4349 100644
41994--- a/drivers/regulator/mc13892-regulator.c
41995+++ b/drivers/regulator/mc13892-regulator.c
41996@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41997 }
41998 mc13xxx_unlock(mc13892);
41999
42000- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
42001+ pax_open_kernel();
42002+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
42003 = mc13892_vcam_set_mode;
42004- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
42005+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
42006 = mc13892_vcam_get_mode;
42007+ pax_close_kernel();
42008
42009 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
42010 ARRAY_SIZE(mc13892_regulators));
42011diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
42012index f1cb706..4c7832a 100644
42013--- a/drivers/rtc/rtc-cmos.c
42014+++ b/drivers/rtc/rtc-cmos.c
42015@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
42016 hpet_rtc_timer_init();
42017
42018 /* export at least the first block of NVRAM */
42019- nvram.size = address_space - NVRAM_OFFSET;
42020+ pax_open_kernel();
42021+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
42022+ pax_close_kernel();
42023 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
42024 if (retval < 0) {
42025 dev_dbg(dev, "can't create nvram file? %d\n", retval);
42026diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
42027index d049393..bb20be0 100644
42028--- a/drivers/rtc/rtc-dev.c
42029+++ b/drivers/rtc/rtc-dev.c
42030@@ -16,6 +16,7 @@
42031 #include <linux/module.h>
42032 #include <linux/rtc.h>
42033 #include <linux/sched.h>
42034+#include <linux/grsecurity.h>
42035 #include "rtc-core.h"
42036
42037 static dev_t rtc_devt;
42038@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
42039 if (copy_from_user(&tm, uarg, sizeof(tm)))
42040 return -EFAULT;
42041
42042+ gr_log_timechange();
42043+
42044 return rtc_set_time(rtc, &tm);
42045
42046 case RTC_PIE_ON:
42047diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
42048index b53992a..776df84 100644
42049--- a/drivers/rtc/rtc-ds1307.c
42050+++ b/drivers/rtc/rtc-ds1307.c
42051@@ -107,7 +107,7 @@ struct ds1307 {
42052 u8 offset; /* register's offset */
42053 u8 regs[11];
42054 u16 nvram_offset;
42055- struct bin_attribute *nvram;
42056+ bin_attribute_no_const *nvram;
42057 enum ds_type type;
42058 unsigned long flags;
42059 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
42060diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
42061index 130f29a..6179d03 100644
42062--- a/drivers/rtc/rtc-m48t59.c
42063+++ b/drivers/rtc/rtc-m48t59.c
42064@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
42065 goto out;
42066 }
42067
42068- m48t59_nvram_attr.size = pdata->offset;
42069+ pax_open_kernel();
42070+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
42071+ pax_close_kernel();
42072
42073 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
42074 if (ret) {
42075diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
42076index e693af6..2e525b6 100644
42077--- a/drivers/scsi/bfa/bfa_fcpim.h
42078+++ b/drivers/scsi/bfa/bfa_fcpim.h
42079@@ -36,7 +36,7 @@ struct bfa_iotag_s {
42080
42081 struct bfa_itn_s {
42082 bfa_isr_func_t isr;
42083-};
42084+} __no_const;
42085
42086 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
42087 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
42088diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
42089index 23a90e7..9cf04ee 100644
42090--- a/drivers/scsi/bfa/bfa_ioc.h
42091+++ b/drivers/scsi/bfa/bfa_ioc.h
42092@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
42093 bfa_ioc_disable_cbfn_t disable_cbfn;
42094 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
42095 bfa_ioc_reset_cbfn_t reset_cbfn;
42096-};
42097+} __no_const;
42098
42099 /*
42100 * IOC event notification mechanism.
42101@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
42102 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
42103 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
42104 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
42105-};
42106+} __no_const;
42107
42108 /*
42109 * Queue element to wait for room in request queue. FIFO order is
42110diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
42111index df0c3c7..b00e1d0 100644
42112--- a/drivers/scsi/hosts.c
42113+++ b/drivers/scsi/hosts.c
42114@@ -42,7 +42,7 @@
42115 #include "scsi_logging.h"
42116
42117
42118-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42119+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42120
42121
42122 static void scsi_host_cls_release(struct device *dev)
42123@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
42124 * subtract one because we increment first then return, but we need to
42125 * know what the next host number was before increment
42126 */
42127- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
42128+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
42129 shost->dma_channel = 0xff;
42130
42131 /* These three are default values which can be overridden */
42132diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
42133index 7f4f790..b75b92a 100644
42134--- a/drivers/scsi/hpsa.c
42135+++ b/drivers/scsi/hpsa.c
42136@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
42137 unsigned long flags;
42138
42139 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42140- return h->access.command_completed(h, q);
42141+ return h->access->command_completed(h, q);
42142
42143 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42144 a = rq->head[rq->current_entry];
42145@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
42146 while (!list_empty(&h->reqQ)) {
42147 c = list_entry(h->reqQ.next, struct CommandList, list);
42148 /* can't do anything if fifo is full */
42149- if ((h->access.fifo_full(h))) {
42150+ if ((h->access->fifo_full(h))) {
42151 dev_warn(&h->pdev->dev, "fifo full\n");
42152 break;
42153 }
42154@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
42155
42156 /* Tell the controller execute command */
42157 spin_unlock_irqrestore(&h->lock, flags);
42158- h->access.submit_command(h, c);
42159+ h->access->submit_command(h, c);
42160 spin_lock_irqsave(&h->lock, flags);
42161 }
42162 spin_unlock_irqrestore(&h->lock, flags);
42163@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
42164
42165 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42166 {
42167- return h->access.command_completed(h, q);
42168+ return h->access->command_completed(h, q);
42169 }
42170
42171 static inline bool interrupt_pending(struct ctlr_info *h)
42172 {
42173- return h->access.intr_pending(h);
42174+ return h->access->intr_pending(h);
42175 }
42176
42177 static inline long interrupt_not_for_us(struct ctlr_info *h)
42178 {
42179- return (h->access.intr_pending(h) == 0) ||
42180+ return (h->access->intr_pending(h) == 0) ||
42181 (h->interrupts_enabled == 0);
42182 }
42183
42184@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42185 if (prod_index < 0)
42186 return -ENODEV;
42187 h->product_name = products[prod_index].product_name;
42188- h->access = *(products[prod_index].access);
42189+ h->access = products[prod_index].access;
42190
42191 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42192 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42193@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42194
42195 assert_spin_locked(&lockup_detector_lock);
42196 remove_ctlr_from_lockup_detector_list(h);
42197- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42198+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42199 spin_lock_irqsave(&h->lock, flags);
42200 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42201 spin_unlock_irqrestore(&h->lock, flags);
42202@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
42203 }
42204
42205 /* make sure the board interrupts are off */
42206- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42207+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42208
42209 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42210 goto clean2;
42211@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
42212 * fake ones to scoop up any residual completions.
42213 */
42214 spin_lock_irqsave(&h->lock, flags);
42215- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42216+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42217 spin_unlock_irqrestore(&h->lock, flags);
42218 free_irqs(h);
42219 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42220@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
42221 dev_info(&h->pdev->dev, "Board READY.\n");
42222 dev_info(&h->pdev->dev,
42223 "Waiting for stale completions to drain.\n");
42224- h->access.set_intr_mask(h, HPSA_INTR_ON);
42225+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42226 msleep(10000);
42227- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42228+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42229
42230 rc = controller_reset_failed(h->cfgtable);
42231 if (rc)
42232@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
42233 }
42234
42235 /* Turn the interrupts on so we can service requests */
42236- h->access.set_intr_mask(h, HPSA_INTR_ON);
42237+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42238
42239 hpsa_hba_inquiry(h);
42240 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42241@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42242 * To write all data in the battery backed cache to disks
42243 */
42244 hpsa_flush_cache(h);
42245- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42246+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42247 hpsa_free_irqs_and_disable_msix(h);
42248 }
42249
42250@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42251 return;
42252 }
42253 /* Change the access methods to the performant access methods */
42254- h->access = SA5_performant_access;
42255+ h->access = &SA5_performant_access;
42256 h->transMethod = CFGTBL_Trans_Performant;
42257 }
42258
42259diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42260index 9816479..c5d4e97 100644
42261--- a/drivers/scsi/hpsa.h
42262+++ b/drivers/scsi/hpsa.h
42263@@ -79,7 +79,7 @@ struct ctlr_info {
42264 unsigned int msix_vector;
42265 unsigned int msi_vector;
42266 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42267- struct access_method access;
42268+ struct access_method *access;
42269
42270 /* queue and queue Info */
42271 struct list_head reqQ;
42272diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42273index 8b928c6..9c76300 100644
42274--- a/drivers/scsi/libfc/fc_exch.c
42275+++ b/drivers/scsi/libfc/fc_exch.c
42276@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42277 u16 pool_max_index;
42278
42279 struct {
42280- atomic_t no_free_exch;
42281- atomic_t no_free_exch_xid;
42282- atomic_t xid_not_found;
42283- atomic_t xid_busy;
42284- atomic_t seq_not_found;
42285- atomic_t non_bls_resp;
42286+ atomic_unchecked_t no_free_exch;
42287+ atomic_unchecked_t no_free_exch_xid;
42288+ atomic_unchecked_t xid_not_found;
42289+ atomic_unchecked_t xid_busy;
42290+ atomic_unchecked_t seq_not_found;
42291+ atomic_unchecked_t non_bls_resp;
42292 } stats;
42293 };
42294
42295@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42296 /* allocate memory for exchange */
42297 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42298 if (!ep) {
42299- atomic_inc(&mp->stats.no_free_exch);
42300+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42301 goto out;
42302 }
42303 memset(ep, 0, sizeof(*ep));
42304@@ -797,7 +797,7 @@ out:
42305 return ep;
42306 err:
42307 spin_unlock_bh(&pool->lock);
42308- atomic_inc(&mp->stats.no_free_exch_xid);
42309+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42310 mempool_free(ep, mp->ep_pool);
42311 return NULL;
42312 }
42313@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42314 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42315 ep = fc_exch_find(mp, xid);
42316 if (!ep) {
42317- atomic_inc(&mp->stats.xid_not_found);
42318+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42319 reject = FC_RJT_OX_ID;
42320 goto out;
42321 }
42322@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42323 ep = fc_exch_find(mp, xid);
42324 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42325 if (ep) {
42326- atomic_inc(&mp->stats.xid_busy);
42327+ atomic_inc_unchecked(&mp->stats.xid_busy);
42328 reject = FC_RJT_RX_ID;
42329 goto rel;
42330 }
42331@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42332 }
42333 xid = ep->xid; /* get our XID */
42334 } else if (!ep) {
42335- atomic_inc(&mp->stats.xid_not_found);
42336+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42337 reject = FC_RJT_RX_ID; /* XID not found */
42338 goto out;
42339 }
42340@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42341 } else {
42342 sp = &ep->seq;
42343 if (sp->id != fh->fh_seq_id) {
42344- atomic_inc(&mp->stats.seq_not_found);
42345+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42346 if (f_ctl & FC_FC_END_SEQ) {
42347 /*
42348 * Update sequence_id based on incoming last
42349@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42350
42351 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42352 if (!ep) {
42353- atomic_inc(&mp->stats.xid_not_found);
42354+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42355 goto out;
42356 }
42357 if (ep->esb_stat & ESB_ST_COMPLETE) {
42358- atomic_inc(&mp->stats.xid_not_found);
42359+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42360 goto rel;
42361 }
42362 if (ep->rxid == FC_XID_UNKNOWN)
42363 ep->rxid = ntohs(fh->fh_rx_id);
42364 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42365- atomic_inc(&mp->stats.xid_not_found);
42366+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42367 goto rel;
42368 }
42369 if (ep->did != ntoh24(fh->fh_s_id) &&
42370 ep->did != FC_FID_FLOGI) {
42371- atomic_inc(&mp->stats.xid_not_found);
42372+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42373 goto rel;
42374 }
42375 sof = fr_sof(fp);
42376@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42377 sp->ssb_stat |= SSB_ST_RESP;
42378 sp->id = fh->fh_seq_id;
42379 } else if (sp->id != fh->fh_seq_id) {
42380- atomic_inc(&mp->stats.seq_not_found);
42381+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42382 goto rel;
42383 }
42384
42385@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42386 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42387
42388 if (!sp)
42389- atomic_inc(&mp->stats.xid_not_found);
42390+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42391 else
42392- atomic_inc(&mp->stats.non_bls_resp);
42393+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42394
42395 fc_frame_free(fp);
42396 }
42397@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42398
42399 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42400 mp = ema->mp;
42401- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42402+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42403 st->fc_no_free_exch_xid +=
42404- atomic_read(&mp->stats.no_free_exch_xid);
42405- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42406- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42407- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42408- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42409+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42410+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42411+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42412+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42413+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42414 }
42415 }
42416 EXPORT_SYMBOL(fc_exch_update_stats);
42417diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42418index 161c98e..6d563b3 100644
42419--- a/drivers/scsi/libsas/sas_ata.c
42420+++ b/drivers/scsi/libsas/sas_ata.c
42421@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42422 .postreset = ata_std_postreset,
42423 .error_handler = ata_std_error_handler,
42424 .post_internal_cmd = sas_ata_post_internal,
42425- .qc_defer = ata_std_qc_defer,
42426+ .qc_defer = ata_std_qc_defer,
42427 .qc_prep = ata_noop_qc_prep,
42428 .qc_issue = sas_ata_qc_issue,
42429 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42430diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42431index bcc56ca..6f4174a 100644
42432--- a/drivers/scsi/lpfc/lpfc.h
42433+++ b/drivers/scsi/lpfc/lpfc.h
42434@@ -431,7 +431,7 @@ struct lpfc_vport {
42435 struct dentry *debug_nodelist;
42436 struct dentry *vport_debugfs_root;
42437 struct lpfc_debugfs_trc *disc_trc;
42438- atomic_t disc_trc_cnt;
42439+ atomic_unchecked_t disc_trc_cnt;
42440 #endif
42441 uint8_t stat_data_enabled;
42442 uint8_t stat_data_blocked;
42443@@ -865,8 +865,8 @@ struct lpfc_hba {
42444 struct timer_list fabric_block_timer;
42445 unsigned long bit_flags;
42446 #define FABRIC_COMANDS_BLOCKED 0
42447- atomic_t num_rsrc_err;
42448- atomic_t num_cmd_success;
42449+ atomic_unchecked_t num_rsrc_err;
42450+ atomic_unchecked_t num_cmd_success;
42451 unsigned long last_rsrc_error_time;
42452 unsigned long last_ramp_down_time;
42453 unsigned long last_ramp_up_time;
42454@@ -902,7 +902,7 @@ struct lpfc_hba {
42455
42456 struct dentry *debug_slow_ring_trc;
42457 struct lpfc_debugfs_trc *slow_ring_trc;
42458- atomic_t slow_ring_trc_cnt;
42459+ atomic_unchecked_t slow_ring_trc_cnt;
42460 /* iDiag debugfs sub-directory */
42461 struct dentry *idiag_root;
42462 struct dentry *idiag_pci_cfg;
42463diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42464index f525ecb..32549a4 100644
42465--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42466+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42467@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42468
42469 #include <linux/debugfs.h>
42470
42471-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42472+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42473 static unsigned long lpfc_debugfs_start_time = 0L;
42474
42475 /* iDiag */
42476@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42477 lpfc_debugfs_enable = 0;
42478
42479 len = 0;
42480- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42481+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42482 (lpfc_debugfs_max_disc_trc - 1);
42483 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42484 dtp = vport->disc_trc + i;
42485@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42486 lpfc_debugfs_enable = 0;
42487
42488 len = 0;
42489- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42490+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42491 (lpfc_debugfs_max_slow_ring_trc - 1);
42492 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42493 dtp = phba->slow_ring_trc + i;
42494@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42495 !vport || !vport->disc_trc)
42496 return;
42497
42498- index = atomic_inc_return(&vport->disc_trc_cnt) &
42499+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42500 (lpfc_debugfs_max_disc_trc - 1);
42501 dtp = vport->disc_trc + index;
42502 dtp->fmt = fmt;
42503 dtp->data1 = data1;
42504 dtp->data2 = data2;
42505 dtp->data3 = data3;
42506- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42507+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42508 dtp->jif = jiffies;
42509 #endif
42510 return;
42511@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42512 !phba || !phba->slow_ring_trc)
42513 return;
42514
42515- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42516+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42517 (lpfc_debugfs_max_slow_ring_trc - 1);
42518 dtp = phba->slow_ring_trc + index;
42519 dtp->fmt = fmt;
42520 dtp->data1 = data1;
42521 dtp->data2 = data2;
42522 dtp->data3 = data3;
42523- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42524+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42525 dtp->jif = jiffies;
42526 #endif
42527 return;
42528@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42529 "slow_ring buffer\n");
42530 goto debug_failed;
42531 }
42532- atomic_set(&phba->slow_ring_trc_cnt, 0);
42533+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42534 memset(phba->slow_ring_trc, 0,
42535 (sizeof(struct lpfc_debugfs_trc) *
42536 lpfc_debugfs_max_slow_ring_trc));
42537@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42538 "buffer\n");
42539 goto debug_failed;
42540 }
42541- atomic_set(&vport->disc_trc_cnt, 0);
42542+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42543
42544 snprintf(name, sizeof(name), "discovery_trace");
42545 vport->debug_disc_trc =
42546diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42547index cb465b2..2e7b25f 100644
42548--- a/drivers/scsi/lpfc/lpfc_init.c
42549+++ b/drivers/scsi/lpfc/lpfc_init.c
42550@@ -10950,8 +10950,10 @@ lpfc_init(void)
42551 "misc_register returned with status %d", error);
42552
42553 if (lpfc_enable_npiv) {
42554- lpfc_transport_functions.vport_create = lpfc_vport_create;
42555- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42556+ pax_open_kernel();
42557+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42558+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42559+ pax_close_kernel();
42560 }
42561 lpfc_transport_template =
42562 fc_attach_transport(&lpfc_transport_functions);
42563diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42564index 8523b278e..ce1d812 100644
42565--- a/drivers/scsi/lpfc/lpfc_scsi.c
42566+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42567@@ -331,7 +331,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42568 uint32_t evt_posted;
42569
42570 spin_lock_irqsave(&phba->hbalock, flags);
42571- atomic_inc(&phba->num_rsrc_err);
42572+ atomic_inc_unchecked(&phba->num_rsrc_err);
42573 phba->last_rsrc_error_time = jiffies;
42574
42575 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42576@@ -372,7 +372,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42577 unsigned long flags;
42578 struct lpfc_hba *phba = vport->phba;
42579 uint32_t evt_posted;
42580- atomic_inc(&phba->num_cmd_success);
42581+ atomic_inc_unchecked(&phba->num_cmd_success);
42582
42583 if (vport->cfg_lun_queue_depth <= queue_depth)
42584 return;
42585@@ -416,8 +416,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42586 unsigned long num_rsrc_err, num_cmd_success;
42587 int i;
42588
42589- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42590- num_cmd_success = atomic_read(&phba->num_cmd_success);
42591+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42592+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42593
42594 /*
42595 * The error and success command counters are global per
42596@@ -445,8 +445,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42597 }
42598 }
42599 lpfc_destroy_vport_work_array(phba, vports);
42600- atomic_set(&phba->num_rsrc_err, 0);
42601- atomic_set(&phba->num_cmd_success, 0);
42602+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42603+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42604 }
42605
42606 /**
42607@@ -480,8 +480,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42608 }
42609 }
42610 lpfc_destroy_vport_work_array(phba, vports);
42611- atomic_set(&phba->num_rsrc_err, 0);
42612- atomic_set(&phba->num_cmd_success, 0);
42613+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42614+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42615 }
42616
42617 /**
42618diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42619index 8e1b737..50ff510 100644
42620--- a/drivers/scsi/pmcraid.c
42621+++ b/drivers/scsi/pmcraid.c
42622@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42623 res->scsi_dev = scsi_dev;
42624 scsi_dev->hostdata = res;
42625 res->change_detected = 0;
42626- atomic_set(&res->read_failures, 0);
42627- atomic_set(&res->write_failures, 0);
42628+ atomic_set_unchecked(&res->read_failures, 0);
42629+ atomic_set_unchecked(&res->write_failures, 0);
42630 rc = 0;
42631 }
42632 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42633@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42634
42635 /* If this was a SCSI read/write command keep count of errors */
42636 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42637- atomic_inc(&res->read_failures);
42638+ atomic_inc_unchecked(&res->read_failures);
42639 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42640- atomic_inc(&res->write_failures);
42641+ atomic_inc_unchecked(&res->write_failures);
42642
42643 if (!RES_IS_GSCSI(res->cfg_entry) &&
42644 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42645@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42646 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42647 * hrrq_id assigned here in queuecommand
42648 */
42649- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42650+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42651 pinstance->num_hrrq;
42652 cmd->cmd_done = pmcraid_io_done;
42653
42654@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
42655 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42656 * hrrq_id assigned here in queuecommand
42657 */
42658- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42659+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42660 pinstance->num_hrrq;
42661
42662 if (request_size) {
42663@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42664
42665 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42666 /* add resources only after host is added into system */
42667- if (!atomic_read(&pinstance->expose_resources))
42668+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42669 return;
42670
42671 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42672@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42673 init_waitqueue_head(&pinstance->reset_wait_q);
42674
42675 atomic_set(&pinstance->outstanding_cmds, 0);
42676- atomic_set(&pinstance->last_message_id, 0);
42677- atomic_set(&pinstance->expose_resources, 0);
42678+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42679+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42680
42681 INIT_LIST_HEAD(&pinstance->free_res_q);
42682 INIT_LIST_HEAD(&pinstance->used_res_q);
42683@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42684 /* Schedule worker thread to handle CCN and take care of adding and
42685 * removing devices to OS
42686 */
42687- atomic_set(&pinstance->expose_resources, 1);
42688+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42689 schedule_work(&pinstance->worker_q);
42690 return rc;
42691
42692diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42693index e1d150f..6c6df44 100644
42694--- a/drivers/scsi/pmcraid.h
42695+++ b/drivers/scsi/pmcraid.h
42696@@ -748,7 +748,7 @@ struct pmcraid_instance {
42697 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42698
42699 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42700- atomic_t last_message_id;
42701+ atomic_unchecked_t last_message_id;
42702
42703 /* configuration table */
42704 struct pmcraid_config_table *cfg_table;
42705@@ -777,7 +777,7 @@ struct pmcraid_instance {
42706 atomic_t outstanding_cmds;
42707
42708 /* should add/delete resources to mid-layer now ?*/
42709- atomic_t expose_resources;
42710+ atomic_unchecked_t expose_resources;
42711
42712
42713
42714@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42715 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42716 };
42717 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42718- atomic_t read_failures; /* count of failed READ commands */
42719- atomic_t write_failures; /* count of failed WRITE commands */
42720+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42721+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42722
42723 /* To indicate add/delete/modify during CCN */
42724 u8 change_detected;
42725diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42726index bf60c63..74d4dce 100644
42727--- a/drivers/scsi/qla2xxx/qla_attr.c
42728+++ b/drivers/scsi/qla2xxx/qla_attr.c
42729@@ -2001,7 +2001,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42730 return 0;
42731 }
42732
42733-struct fc_function_template qla2xxx_transport_functions = {
42734+fc_function_template_no_const qla2xxx_transport_functions = {
42735
42736 .show_host_node_name = 1,
42737 .show_host_port_name = 1,
42738@@ -2048,7 +2048,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42739 .bsg_timeout = qla24xx_bsg_timeout,
42740 };
42741
42742-struct fc_function_template qla2xxx_transport_vport_functions = {
42743+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42744
42745 .show_host_node_name = 1,
42746 .show_host_port_name = 1,
42747diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42748index 026bfde..90c4018 100644
42749--- a/drivers/scsi/qla2xxx/qla_gbl.h
42750+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42751@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42752 struct device_attribute;
42753 extern struct device_attribute *qla2x00_host_attrs[];
42754 struct fc_function_template;
42755-extern struct fc_function_template qla2xxx_transport_functions;
42756-extern struct fc_function_template qla2xxx_transport_vport_functions;
42757+extern fc_function_template_no_const qla2xxx_transport_functions;
42758+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42759 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42760 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42761 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42762diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42763index ad72c1d..afc9a98 100644
42764--- a/drivers/scsi/qla2xxx/qla_os.c
42765+++ b/drivers/scsi/qla2xxx/qla_os.c
42766@@ -1571,8 +1571,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42767 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42768 /* Ok, a 64bit DMA mask is applicable. */
42769 ha->flags.enable_64bit_addressing = 1;
42770- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42771- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42772+ pax_open_kernel();
42773+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42774+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42775+ pax_close_kernel();
42776 return;
42777 }
42778 }
42779diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42780index ddf16a8..80f4dd0 100644
42781--- a/drivers/scsi/qla4xxx/ql4_def.h
42782+++ b/drivers/scsi/qla4xxx/ql4_def.h
42783@@ -291,7 +291,7 @@ struct ddb_entry {
42784 * (4000 only) */
42785 atomic_t relogin_timer; /* Max Time to wait for
42786 * relogin to complete */
42787- atomic_t relogin_retry_count; /* Num of times relogin has been
42788+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42789 * retried */
42790 uint32_t default_time2wait; /* Default Min time between
42791 * relogins (+aens) */
42792diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42793index 4d231c1..2892c37 100644
42794--- a/drivers/scsi/qla4xxx/ql4_os.c
42795+++ b/drivers/scsi/qla4xxx/ql4_os.c
42796@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42797 */
42798 if (!iscsi_is_session_online(cls_sess)) {
42799 /* Reset retry relogin timer */
42800- atomic_inc(&ddb_entry->relogin_retry_count);
42801+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42802 DEBUG2(ql4_printk(KERN_INFO, ha,
42803 "%s: index[%d] relogin timed out-retrying"
42804 " relogin (%d), retry (%d)\n", __func__,
42805 ddb_entry->fw_ddb_index,
42806- atomic_read(&ddb_entry->relogin_retry_count),
42807+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42808 ddb_entry->default_time2wait + 4));
42809 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42810 atomic_set(&ddb_entry->retry_relogin_timer,
42811@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42812
42813 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42814 atomic_set(&ddb_entry->relogin_timer, 0);
42815- atomic_set(&ddb_entry->relogin_retry_count, 0);
42816+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42817 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42818 ddb_entry->default_relogin_timeout =
42819 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42820diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42821index 2c0d0ec..4e8681a 100644
42822--- a/drivers/scsi/scsi.c
42823+++ b/drivers/scsi/scsi.c
42824@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42825 unsigned long timeout;
42826 int rtn = 0;
42827
42828- atomic_inc(&cmd->device->iorequest_cnt);
42829+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42830
42831 /* check if the device is still usable */
42832 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42833diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42834index 86d5220..f22c51a 100644
42835--- a/drivers/scsi/scsi_lib.c
42836+++ b/drivers/scsi/scsi_lib.c
42837@@ -1458,7 +1458,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42838 shost = sdev->host;
42839 scsi_init_cmd_errh(cmd);
42840 cmd->result = DID_NO_CONNECT << 16;
42841- atomic_inc(&cmd->device->iorequest_cnt);
42842+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42843
42844 /*
42845 * SCSI request completion path will do scsi_device_unbusy(),
42846@@ -1484,9 +1484,9 @@ static void scsi_softirq_done(struct request *rq)
42847
42848 INIT_LIST_HEAD(&cmd->eh_entry);
42849
42850- atomic_inc(&cmd->device->iodone_cnt);
42851+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42852 if (cmd->result)
42853- atomic_inc(&cmd->device->ioerr_cnt);
42854+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42855
42856 disposition = scsi_decide_disposition(cmd);
42857 if (disposition != SUCCESS &&
42858diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42859index 931a7d9..0c2a754 100644
42860--- a/drivers/scsi/scsi_sysfs.c
42861+++ b/drivers/scsi/scsi_sysfs.c
42862@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42863 char *buf) \
42864 { \
42865 struct scsi_device *sdev = to_scsi_device(dev); \
42866- unsigned long long count = atomic_read(&sdev->field); \
42867+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42868 return snprintf(buf, 20, "0x%llx\n", count); \
42869 } \
42870 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42871diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42872index 84a1fdf..693b0d6 100644
42873--- a/drivers/scsi/scsi_tgt_lib.c
42874+++ b/drivers/scsi/scsi_tgt_lib.c
42875@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42876 int err;
42877
42878 dprintk("%lx %u\n", uaddr, len);
42879- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42880+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42881 if (err) {
42882 /*
42883 * TODO: need to fixup sg_tablesize, max_segment_size,
42884diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42885index e106c27..11a380e 100644
42886--- a/drivers/scsi/scsi_transport_fc.c
42887+++ b/drivers/scsi/scsi_transport_fc.c
42888@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42889 * Netlink Infrastructure
42890 */
42891
42892-static atomic_t fc_event_seq;
42893+static atomic_unchecked_t fc_event_seq;
42894
42895 /**
42896 * fc_get_event_number - Obtain the next sequential FC event number
42897@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
42898 u32
42899 fc_get_event_number(void)
42900 {
42901- return atomic_add_return(1, &fc_event_seq);
42902+ return atomic_add_return_unchecked(1, &fc_event_seq);
42903 }
42904 EXPORT_SYMBOL(fc_get_event_number);
42905
42906@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
42907 {
42908 int error;
42909
42910- atomic_set(&fc_event_seq, 0);
42911+ atomic_set_unchecked(&fc_event_seq, 0);
42912
42913 error = transport_class_register(&fc_host_class);
42914 if (error)
42915@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42916 char *cp;
42917
42918 *val = simple_strtoul(buf, &cp, 0);
42919- if ((*cp && (*cp != '\n')) || (*val < 0))
42920+ if (*cp && (*cp != '\n'))
42921 return -EINVAL;
42922 /*
42923 * Check for overflow; dev_loss_tmo is u32
42924diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42925index 133926b..903000d 100644
42926--- a/drivers/scsi/scsi_transport_iscsi.c
42927+++ b/drivers/scsi/scsi_transport_iscsi.c
42928@@ -80,7 +80,7 @@ struct iscsi_internal {
42929 struct transport_container session_cont;
42930 };
42931
42932-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42933+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42934 static struct workqueue_struct *iscsi_eh_timer_workq;
42935
42936 static DEFINE_IDA(iscsi_sess_ida);
42937@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42938 int err;
42939
42940 ihost = shost->shost_data;
42941- session->sid = atomic_add_return(1, &iscsi_session_nr);
42942+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42943
42944 if (target_id == ISCSI_MAX_TARGET) {
42945 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42946@@ -3944,7 +3944,7 @@ static __init int iscsi_transport_init(void)
42947 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42948 ISCSI_TRANSPORT_VERSION);
42949
42950- atomic_set(&iscsi_session_nr, 0);
42951+ atomic_set_unchecked(&iscsi_session_nr, 0);
42952
42953 err = class_register(&iscsi_transport_class);
42954 if (err)
42955diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42956index f379c7f..e8fc69c 100644
42957--- a/drivers/scsi/scsi_transport_srp.c
42958+++ b/drivers/scsi/scsi_transport_srp.c
42959@@ -33,7 +33,7 @@
42960 #include "scsi_transport_srp_internal.h"
42961
42962 struct srp_host_attrs {
42963- atomic_t next_port_id;
42964+ atomic_unchecked_t next_port_id;
42965 };
42966 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42967
42968@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42969 struct Scsi_Host *shost = dev_to_shost(dev);
42970 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42971
42972- atomic_set(&srp_host->next_port_id, 0);
42973+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42974 return 0;
42975 }
42976
42977@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42978 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42979 rport->roles = ids->roles;
42980
42981- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42982+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42983 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42984
42985 transport_setup_device(&rport->dev);
42986diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42987index 6f6a1b4..80704a9 100644
42988--- a/drivers/scsi/sd.c
42989+++ b/drivers/scsi/sd.c
42990@@ -2918,7 +2918,7 @@ static int sd_probe(struct device *dev)
42991 sdkp->disk = gd;
42992 sdkp->index = index;
42993 atomic_set(&sdkp->openers, 0);
42994- atomic_set(&sdkp->device->ioerr_cnt, 0);
42995+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42996
42997 if (!sdp->request_queue->rq_timeout) {
42998 if (sdp->type != TYPE_MOD)
42999diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
43000index df5e961..df6b97f 100644
43001--- a/drivers/scsi/sg.c
43002+++ b/drivers/scsi/sg.c
43003@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
43004 sdp->disk->disk_name,
43005 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
43006 NULL,
43007- (char *)arg);
43008+ (char __user *)arg);
43009 case BLKTRACESTART:
43010 return blk_trace_startstop(sdp->device->request_queue, 1);
43011 case BLKTRACESTOP:
43012diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
43013index 32b7bb1..2f1c4bd 100644
43014--- a/drivers/spi/spi.c
43015+++ b/drivers/spi/spi.c
43016@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
43017 EXPORT_SYMBOL_GPL(spi_bus_unlock);
43018
43019 /* portable code must never pass more than 32 bytes */
43020-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
43021+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
43022
43023 static u8 *buf;
43024
43025diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
43026index 3675020..e80d92c 100644
43027--- a/drivers/staging/media/solo6x10/solo6x10-core.c
43028+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
43029@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
43030
43031 static int solo_sysfs_init(struct solo_dev *solo_dev)
43032 {
43033- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
43034+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
43035 struct device *dev = &solo_dev->dev;
43036 const char *driver;
43037 int i;
43038diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
43039index 34afc16..ffe44dd 100644
43040--- a/drivers/staging/octeon/ethernet-rx.c
43041+++ b/drivers/staging/octeon/ethernet-rx.c
43042@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43043 /* Increment RX stats for virtual ports */
43044 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
43045 #ifdef CONFIG_64BIT
43046- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
43047- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
43048+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
43049+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
43050 #else
43051- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
43052- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
43053+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
43054+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
43055 #endif
43056 }
43057 netif_receive_skb(skb);
43058@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
43059 dev->name);
43060 */
43061 #ifdef CONFIG_64BIT
43062- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
43063+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43064 #else
43065- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
43066+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
43067 #endif
43068 dev_kfree_skb_irq(skb);
43069 }
43070diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
43071index c3a90e7..023619a 100644
43072--- a/drivers/staging/octeon/ethernet.c
43073+++ b/drivers/staging/octeon/ethernet.c
43074@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
43075 * since the RX tasklet also increments it.
43076 */
43077 #ifdef CONFIG_64BIT
43078- atomic64_add(rx_status.dropped_packets,
43079- (atomic64_t *)&priv->stats.rx_dropped);
43080+ atomic64_add_unchecked(rx_status.dropped_packets,
43081+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
43082 #else
43083- atomic_add(rx_status.dropped_packets,
43084- (atomic_t *)&priv->stats.rx_dropped);
43085+ atomic_add_unchecked(rx_status.dropped_packets,
43086+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
43087 #endif
43088 }
43089
43090diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
43091index dc23395..cf7e9b1 100644
43092--- a/drivers/staging/rtl8712/rtl871x_io.h
43093+++ b/drivers/staging/rtl8712/rtl871x_io.h
43094@@ -108,7 +108,7 @@ struct _io_ops {
43095 u8 *pmem);
43096 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
43097 u8 *pmem);
43098-};
43099+} __no_const;
43100
43101 struct io_req {
43102 struct list_head list;
43103diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
43104index 1f5088b..0e59820 100644
43105--- a/drivers/staging/sbe-2t3e3/netdev.c
43106+++ b/drivers/staging/sbe-2t3e3/netdev.c
43107@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43108 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43109
43110 if (rlen)
43111- if (copy_to_user(data, &resp, rlen))
43112+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43113 return -EFAULT;
43114
43115 return 0;
43116diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43117index a863a98..d272795 100644
43118--- a/drivers/staging/usbip/vhci.h
43119+++ b/drivers/staging/usbip/vhci.h
43120@@ -83,7 +83,7 @@ struct vhci_hcd {
43121 unsigned resuming:1;
43122 unsigned long re_timeout;
43123
43124- atomic_t seqnum;
43125+ atomic_unchecked_t seqnum;
43126
43127 /*
43128 * NOTE:
43129diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43130index d7974cb..d78076b 100644
43131--- a/drivers/staging/usbip/vhci_hcd.c
43132+++ b/drivers/staging/usbip/vhci_hcd.c
43133@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
43134
43135 spin_lock(&vdev->priv_lock);
43136
43137- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43138+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43139 if (priv->seqnum == 0xffff)
43140 dev_info(&urb->dev->dev, "seqnum max\n");
43141
43142@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43143 return -ENOMEM;
43144 }
43145
43146- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43147+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43148 if (unlink->seqnum == 0xffff)
43149 pr_info("seqnum max\n");
43150
43151@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
43152 vdev->rhport = rhport;
43153 }
43154
43155- atomic_set(&vhci->seqnum, 0);
43156+ atomic_set_unchecked(&vhci->seqnum, 0);
43157 spin_lock_init(&vhci->lock);
43158
43159 hcd->power_budget = 0; /* no limit */
43160diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43161index d07fcb5..358e1e1 100644
43162--- a/drivers/staging/usbip/vhci_rx.c
43163+++ b/drivers/staging/usbip/vhci_rx.c
43164@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43165 if (!urb) {
43166 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43167 pr_info("max seqnum %d\n",
43168- atomic_read(&the_controller->seqnum));
43169+ atomic_read_unchecked(&the_controller->seqnum));
43170 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43171 return;
43172 }
43173diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43174index 8417c2f..ef5ebd6 100644
43175--- a/drivers/staging/vt6655/hostap.c
43176+++ b/drivers/staging/vt6655/hostap.c
43177@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
43178 *
43179 */
43180
43181+static net_device_ops_no_const apdev_netdev_ops;
43182+
43183 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43184 {
43185 PSDevice apdev_priv;
43186 struct net_device *dev = pDevice->dev;
43187 int ret;
43188- const struct net_device_ops apdev_netdev_ops = {
43189- .ndo_start_xmit = pDevice->tx_80211,
43190- };
43191
43192 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43193
43194@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43195 *apdev_priv = *pDevice;
43196 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43197
43198+ /* only half broken now */
43199+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43200 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43201
43202 pDevice->apdev->type = ARPHRD_IEEE80211;
43203diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43204index c699a30..b90a5fd 100644
43205--- a/drivers/staging/vt6656/hostap.c
43206+++ b/drivers/staging/vt6656/hostap.c
43207@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43208 *
43209 */
43210
43211+static net_device_ops_no_const apdev_netdev_ops;
43212+
43213 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43214 {
43215 struct vnt_private *apdev_priv;
43216 struct net_device *dev = pDevice->dev;
43217 int ret;
43218- const struct net_device_ops apdev_netdev_ops = {
43219- .ndo_start_xmit = pDevice->tx_80211,
43220- };
43221
43222 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43223
43224@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43225 *apdev_priv = *pDevice;
43226 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43227
43228+ /* only half broken now */
43229+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43230 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43231
43232 pDevice->apdev->type = ARPHRD_IEEE80211;
43233diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43234index d7e51e4..d07eaab 100644
43235--- a/drivers/staging/zcache/tmem.c
43236+++ b/drivers/staging/zcache/tmem.c
43237@@ -51,7 +51,7 @@
43238 * A tmem host implementation must use this function to register callbacks
43239 * for memory allocation.
43240 */
43241-static struct tmem_hostops tmem_hostops;
43242+static tmem_hostops_no_const tmem_hostops;
43243
43244 static void tmem_objnode_tree_init(void);
43245
43246@@ -65,7 +65,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43247 * A tmem host implementation must use this function to register
43248 * callbacks for a page-accessible memory (PAM) implementation.
43249 */
43250-static struct tmem_pamops tmem_pamops;
43251+static tmem_pamops_no_const tmem_pamops;
43252
43253 void tmem_register_pamops(struct tmem_pamops *m)
43254 {
43255diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43256index d128ce2..a43980c 100644
43257--- a/drivers/staging/zcache/tmem.h
43258+++ b/drivers/staging/zcache/tmem.h
43259@@ -226,6 +226,7 @@ struct tmem_pamops {
43260 int (*replace_in_obj)(void *, struct tmem_obj *);
43261 #endif
43262 };
43263+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43264 extern void tmem_register_pamops(struct tmem_pamops *m);
43265
43266 /* memory allocation methods provided by the host implementation */
43267@@ -235,6 +236,7 @@ struct tmem_hostops {
43268 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43269 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43270 };
43271+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43272 extern void tmem_register_hostops(struct tmem_hostops *m);
43273
43274 /* core tmem accessor functions */
43275diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43276index 4630481..c26782a 100644
43277--- a/drivers/target/target_core_device.c
43278+++ b/drivers/target/target_core_device.c
43279@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43280 spin_lock_init(&dev->se_port_lock);
43281 spin_lock_init(&dev->se_tmr_lock);
43282 spin_lock_init(&dev->qf_cmd_lock);
43283- atomic_set(&dev->dev_ordered_id, 0);
43284+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43285 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43286 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43287 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43288diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43289index 21e3158..43c6004 100644
43290--- a/drivers/target/target_core_transport.c
43291+++ b/drivers/target/target_core_transport.c
43292@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43293 * Used to determine when ORDERED commands should go from
43294 * Dormant to Active status.
43295 */
43296- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43297+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43298 smp_mb__after_atomic_inc();
43299 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43300 cmd->se_ordered_id, cmd->sam_task_attr,
43301diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43302index 33f83fe..d80f8e1 100644
43303--- a/drivers/tty/cyclades.c
43304+++ b/drivers/tty/cyclades.c
43305@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43306 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43307 info->port.count);
43308 #endif
43309- info->port.count++;
43310+ atomic_inc(&info->port.count);
43311 #ifdef CY_DEBUG_COUNT
43312 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43313- current->pid, info->port.count);
43314+ current->pid, atomic_read(&info->port.count));
43315 #endif
43316
43317 /*
43318@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43319 for (j = 0; j < cy_card[i].nports; j++) {
43320 info = &cy_card[i].ports[j];
43321
43322- if (info->port.count) {
43323+ if (atomic_read(&info->port.count)) {
43324 /* XXX is the ldisc num worth this? */
43325 struct tty_struct *tty;
43326 struct tty_ldisc *ld;
43327diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43328index eb255e8..f637a57 100644
43329--- a/drivers/tty/hvc/hvc_console.c
43330+++ b/drivers/tty/hvc/hvc_console.c
43331@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43332
43333 spin_lock_irqsave(&hp->port.lock, flags);
43334 /* Check and then increment for fast path open. */
43335- if (hp->port.count++ > 0) {
43336+ if (atomic_inc_return(&hp->port.count) > 1) {
43337 spin_unlock_irqrestore(&hp->port.lock, flags);
43338 hvc_kick();
43339 return 0;
43340@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43341
43342 spin_lock_irqsave(&hp->port.lock, flags);
43343
43344- if (--hp->port.count == 0) {
43345+ if (atomic_dec_return(&hp->port.count) == 0) {
43346 spin_unlock_irqrestore(&hp->port.lock, flags);
43347 /* We are done with the tty pointer now. */
43348 tty_port_tty_set(&hp->port, NULL);
43349@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43350 */
43351 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43352 } else {
43353- if (hp->port.count < 0)
43354+ if (atomic_read(&hp->port.count) < 0)
43355 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43356- hp->vtermno, hp->port.count);
43357+ hp->vtermno, atomic_read(&hp->port.count));
43358 spin_unlock_irqrestore(&hp->port.lock, flags);
43359 }
43360 }
43361@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43362 * open->hangup case this can be called after the final close so prevent
43363 * that from happening for now.
43364 */
43365- if (hp->port.count <= 0) {
43366+ if (atomic_read(&hp->port.count) <= 0) {
43367 spin_unlock_irqrestore(&hp->port.lock, flags);
43368 return;
43369 }
43370
43371- hp->port.count = 0;
43372+ atomic_set(&hp->port.count, 0);
43373 spin_unlock_irqrestore(&hp->port.lock, flags);
43374 tty_port_tty_set(&hp->port, NULL);
43375
43376@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43377 return -EPIPE;
43378
43379 /* FIXME what's this (unprotected) check for? */
43380- if (hp->port.count <= 0)
43381+ if (atomic_read(&hp->port.count) <= 0)
43382 return -EIO;
43383
43384 spin_lock_irqsave(&hp->lock, flags);
43385diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43386index 81e939e..95ead10 100644
43387--- a/drivers/tty/hvc/hvcs.c
43388+++ b/drivers/tty/hvc/hvcs.c
43389@@ -83,6 +83,7 @@
43390 #include <asm/hvcserver.h>
43391 #include <asm/uaccess.h>
43392 #include <asm/vio.h>
43393+#include <asm/local.h>
43394
43395 /*
43396 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43397@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43398
43399 spin_lock_irqsave(&hvcsd->lock, flags);
43400
43401- if (hvcsd->port.count > 0) {
43402+ if (atomic_read(&hvcsd->port.count) > 0) {
43403 spin_unlock_irqrestore(&hvcsd->lock, flags);
43404 printk(KERN_INFO "HVCS: vterm state unchanged. "
43405 "The hvcs device node is still in use.\n");
43406@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43407 }
43408 }
43409
43410- hvcsd->port.count = 0;
43411+ atomic_set(&hvcsd->port.count, 0);
43412 hvcsd->port.tty = tty;
43413 tty->driver_data = hvcsd;
43414
43415@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43416 unsigned long flags;
43417
43418 spin_lock_irqsave(&hvcsd->lock, flags);
43419- hvcsd->port.count++;
43420+ atomic_inc(&hvcsd->port.count);
43421 hvcsd->todo_mask |= HVCS_SCHED_READ;
43422 spin_unlock_irqrestore(&hvcsd->lock, flags);
43423
43424@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43425 hvcsd = tty->driver_data;
43426
43427 spin_lock_irqsave(&hvcsd->lock, flags);
43428- if (--hvcsd->port.count == 0) {
43429+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43430
43431 vio_disable_interrupts(hvcsd->vdev);
43432
43433@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43434
43435 free_irq(irq, hvcsd);
43436 return;
43437- } else if (hvcsd->port.count < 0) {
43438+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43439 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43440 " is missmanaged.\n",
43441- hvcsd->vdev->unit_address, hvcsd->port.count);
43442+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43443 }
43444
43445 spin_unlock_irqrestore(&hvcsd->lock, flags);
43446@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43447
43448 spin_lock_irqsave(&hvcsd->lock, flags);
43449 /* Preserve this so that we know how many kref refs to put */
43450- temp_open_count = hvcsd->port.count;
43451+ temp_open_count = atomic_read(&hvcsd->port.count);
43452
43453 /*
43454 * Don't kref put inside the spinlock because the destruction
43455@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43456 tty->driver_data = NULL;
43457 hvcsd->port.tty = NULL;
43458
43459- hvcsd->port.count = 0;
43460+ atomic_set(&hvcsd->port.count, 0);
43461
43462 /* This will drop any buffered data on the floor which is OK in a hangup
43463 * scenario. */
43464@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
43465 * the middle of a write operation? This is a crummy place to do this
43466 * but we want to keep it all in the spinlock.
43467 */
43468- if (hvcsd->port.count <= 0) {
43469+ if (atomic_read(&hvcsd->port.count) <= 0) {
43470 spin_unlock_irqrestore(&hvcsd->lock, flags);
43471 return -ENODEV;
43472 }
43473@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43474 {
43475 struct hvcs_struct *hvcsd = tty->driver_data;
43476
43477- if (!hvcsd || hvcsd->port.count <= 0)
43478+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43479 return 0;
43480
43481 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43482diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43483index 8fd72ff..34a0bed 100644
43484--- a/drivers/tty/ipwireless/tty.c
43485+++ b/drivers/tty/ipwireless/tty.c
43486@@ -29,6 +29,7 @@
43487 #include <linux/tty_driver.h>
43488 #include <linux/tty_flip.h>
43489 #include <linux/uaccess.h>
43490+#include <asm/local.h>
43491
43492 #include "tty.h"
43493 #include "network.h"
43494@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43495 mutex_unlock(&tty->ipw_tty_mutex);
43496 return -ENODEV;
43497 }
43498- if (tty->port.count == 0)
43499+ if (atomic_read(&tty->port.count) == 0)
43500 tty->tx_bytes_queued = 0;
43501
43502- tty->port.count++;
43503+ atomic_inc(&tty->port.count);
43504
43505 tty->port.tty = linux_tty;
43506 linux_tty->driver_data = tty;
43507@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43508
43509 static void do_ipw_close(struct ipw_tty *tty)
43510 {
43511- tty->port.count--;
43512-
43513- if (tty->port.count == 0) {
43514+ if (atomic_dec_return(&tty->port.count) == 0) {
43515 struct tty_struct *linux_tty = tty->port.tty;
43516
43517 if (linux_tty != NULL) {
43518@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43519 return;
43520
43521 mutex_lock(&tty->ipw_tty_mutex);
43522- if (tty->port.count == 0) {
43523+ if (atomic_read(&tty->port.count) == 0) {
43524 mutex_unlock(&tty->ipw_tty_mutex);
43525 return;
43526 }
43527@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43528
43529 mutex_lock(&tty->ipw_tty_mutex);
43530
43531- if (!tty->port.count) {
43532+ if (!atomic_read(&tty->port.count)) {
43533 mutex_unlock(&tty->ipw_tty_mutex);
43534 return;
43535 }
43536@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43537 return -ENODEV;
43538
43539 mutex_lock(&tty->ipw_tty_mutex);
43540- if (!tty->port.count) {
43541+ if (!atomic_read(&tty->port.count)) {
43542 mutex_unlock(&tty->ipw_tty_mutex);
43543 return -EINVAL;
43544 }
43545@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43546 if (!tty)
43547 return -ENODEV;
43548
43549- if (!tty->port.count)
43550+ if (!atomic_read(&tty->port.count))
43551 return -EINVAL;
43552
43553 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43554@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43555 if (!tty)
43556 return 0;
43557
43558- if (!tty->port.count)
43559+ if (!atomic_read(&tty->port.count))
43560 return 0;
43561
43562 return tty->tx_bytes_queued;
43563@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43564 if (!tty)
43565 return -ENODEV;
43566
43567- if (!tty->port.count)
43568+ if (!atomic_read(&tty->port.count))
43569 return -EINVAL;
43570
43571 return get_control_lines(tty);
43572@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43573 if (!tty)
43574 return -ENODEV;
43575
43576- if (!tty->port.count)
43577+ if (!atomic_read(&tty->port.count))
43578 return -EINVAL;
43579
43580 return set_control_lines(tty, set, clear);
43581@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43582 if (!tty)
43583 return -ENODEV;
43584
43585- if (!tty->port.count)
43586+ if (!atomic_read(&tty->port.count))
43587 return -EINVAL;
43588
43589 /* FIXME: Exactly how is the tty object locked here .. */
43590@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43591 * are gone */
43592 mutex_lock(&ttyj->ipw_tty_mutex);
43593 }
43594- while (ttyj->port.count)
43595+ while (atomic_read(&ttyj->port.count))
43596 do_ipw_close(ttyj);
43597 ipwireless_disassociate_network_ttys(network,
43598 ttyj->channel_idx);
43599diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43600index 1deaca4..c8582d4 100644
43601--- a/drivers/tty/moxa.c
43602+++ b/drivers/tty/moxa.c
43603@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43604 }
43605
43606 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43607- ch->port.count++;
43608+ atomic_inc(&ch->port.count);
43609 tty->driver_data = ch;
43610 tty_port_tty_set(&ch->port, tty);
43611 mutex_lock(&ch->port.mutex);
43612diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43613index 6422390..49003ac8 100644
43614--- a/drivers/tty/n_gsm.c
43615+++ b/drivers/tty/n_gsm.c
43616@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43617 spin_lock_init(&dlci->lock);
43618 mutex_init(&dlci->mutex);
43619 dlci->fifo = &dlci->_fifo;
43620- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43621+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43622 kfree(dlci);
43623 return NULL;
43624 }
43625@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43626 struct gsm_dlci *dlci = tty->driver_data;
43627 struct tty_port *port = &dlci->port;
43628
43629- port->count++;
43630+ atomic_inc(&port->count);
43631 dlci_get(dlci);
43632 dlci_get(dlci->gsm->dlci[0]);
43633 mux_get(dlci->gsm);
43634diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43635index 6c7fe90..9241dab 100644
43636--- a/drivers/tty/n_tty.c
43637+++ b/drivers/tty/n_tty.c
43638@@ -2203,6 +2203,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43639 {
43640 *ops = tty_ldisc_N_TTY;
43641 ops->owner = NULL;
43642- ops->refcount = ops->flags = 0;
43643+ atomic_set(&ops->refcount, 0);
43644+ ops->flags = 0;
43645 }
43646 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43647diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43648index abfd990..5ab5da9 100644
43649--- a/drivers/tty/pty.c
43650+++ b/drivers/tty/pty.c
43651@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
43652 panic("Couldn't register Unix98 pts driver");
43653
43654 /* Now create the /dev/ptmx special device */
43655+ pax_open_kernel();
43656 tty_default_fops(&ptmx_fops);
43657- ptmx_fops.open = ptmx_open;
43658+ *(void **)&ptmx_fops.open = ptmx_open;
43659+ pax_close_kernel();
43660
43661 cdev_init(&ptmx_cdev, &ptmx_fops);
43662 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43663diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43664index 354564e..fe50d9a 100644
43665--- a/drivers/tty/rocket.c
43666+++ b/drivers/tty/rocket.c
43667@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43668 tty->driver_data = info;
43669 tty_port_tty_set(port, tty);
43670
43671- if (port->count++ == 0) {
43672+ if (atomic_inc_return(&port->count) == 1) {
43673 atomic_inc(&rp_num_ports_open);
43674
43675 #ifdef ROCKET_DEBUG_OPEN
43676@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43677 #endif
43678 }
43679 #ifdef ROCKET_DEBUG_OPEN
43680- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43681+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43682 #endif
43683
43684 /*
43685@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
43686 spin_unlock_irqrestore(&info->port.lock, flags);
43687 return;
43688 }
43689- if (info->port.count)
43690+ if (atomic_read(&info->port.count))
43691 atomic_dec(&rp_num_ports_open);
43692 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43693 spin_unlock_irqrestore(&info->port.lock, flags);
43694diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43695index 1002054..dd644a8 100644
43696--- a/drivers/tty/serial/kgdboc.c
43697+++ b/drivers/tty/serial/kgdboc.c
43698@@ -24,8 +24,9 @@
43699 #define MAX_CONFIG_LEN 40
43700
43701 static struct kgdb_io kgdboc_io_ops;
43702+static struct kgdb_io kgdboc_io_ops_console;
43703
43704-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43705+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43706 static int configured = -1;
43707
43708 static char config[MAX_CONFIG_LEN];
43709@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43710 kgdboc_unregister_kbd();
43711 if (configured == 1)
43712 kgdb_unregister_io_module(&kgdboc_io_ops);
43713+ else if (configured == 2)
43714+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43715 }
43716
43717 static int configure_kgdboc(void)
43718@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43719 int err;
43720 char *cptr = config;
43721 struct console *cons;
43722+ int is_console = 0;
43723
43724 err = kgdboc_option_setup(config);
43725 if (err || !strlen(config) || isspace(config[0]))
43726 goto noconfig;
43727
43728 err = -ENODEV;
43729- kgdboc_io_ops.is_console = 0;
43730 kgdb_tty_driver = NULL;
43731
43732 kgdboc_use_kms = 0;
43733@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43734 int idx;
43735 if (cons->device && cons->device(cons, &idx) == p &&
43736 idx == tty_line) {
43737- kgdboc_io_ops.is_console = 1;
43738+ is_console = 1;
43739 break;
43740 }
43741 cons = cons->next;
43742@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43743 kgdb_tty_line = tty_line;
43744
43745 do_register:
43746- err = kgdb_register_io_module(&kgdboc_io_ops);
43747+ if (is_console) {
43748+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43749+ configured = 2;
43750+ } else {
43751+ err = kgdb_register_io_module(&kgdboc_io_ops);
43752+ configured = 1;
43753+ }
43754 if (err)
43755 goto noconfig;
43756
43757@@ -205,8 +214,6 @@ do_register:
43758 if (err)
43759 goto nmi_con_failed;
43760
43761- configured = 1;
43762-
43763 return 0;
43764
43765 nmi_con_failed:
43766@@ -223,7 +230,7 @@ noconfig:
43767 static int __init init_kgdboc(void)
43768 {
43769 /* Already configured? */
43770- if (configured == 1)
43771+ if (configured >= 1)
43772 return 0;
43773
43774 return configure_kgdboc();
43775@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43776 if (config[len - 1] == '\n')
43777 config[len - 1] = '\0';
43778
43779- if (configured == 1)
43780+ if (configured >= 1)
43781 cleanup_kgdboc();
43782
43783 /* Go and configure with the new params. */
43784@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43785 .post_exception = kgdboc_post_exp_handler,
43786 };
43787
43788+static struct kgdb_io kgdboc_io_ops_console = {
43789+ .name = "kgdboc",
43790+ .read_char = kgdboc_get_char,
43791+ .write_char = kgdboc_put_char,
43792+ .pre_exception = kgdboc_pre_exp_handler,
43793+ .post_exception = kgdboc_post_exp_handler,
43794+ .is_console = 1
43795+};
43796+
43797 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43798 /* This is only available if kgdboc is a built in for early debugging */
43799 static int __init kgdboc_early_init(char *opt)
43800diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43801index 0c8a9fa..234a95f 100644
43802--- a/drivers/tty/serial/samsung.c
43803+++ b/drivers/tty/serial/samsung.c
43804@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43805 }
43806 }
43807
43808+static int s3c64xx_serial_startup(struct uart_port *port);
43809 static int s3c24xx_serial_startup(struct uart_port *port)
43810 {
43811 struct s3c24xx_uart_port *ourport = to_ourport(port);
43812 int ret;
43813
43814+ /* Startup sequence is different for s3c64xx and higher SoC's */
43815+ if (s3c24xx_serial_has_interrupt_mask(port))
43816+ return s3c64xx_serial_startup(port);
43817+
43818 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43819 port->mapbase, port->membase);
43820
43821@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43822 /* setup info for port */
43823 port->dev = &platdev->dev;
43824
43825- /* Startup sequence is different for s3c64xx and higher SoC's */
43826- if (s3c24xx_serial_has_interrupt_mask(port))
43827- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43828-
43829 port->uartclk = 1;
43830
43831 if (cfg->uart_flags & UPF_CONS_FLOW) {
43832diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43833index f87dbfd..42ad4b1 100644
43834--- a/drivers/tty/serial/serial_core.c
43835+++ b/drivers/tty/serial/serial_core.c
43836@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
43837 uart_flush_buffer(tty);
43838 uart_shutdown(tty, state);
43839 spin_lock_irqsave(&port->lock, flags);
43840- port->count = 0;
43841+ atomic_set(&port->count, 0);
43842 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43843 spin_unlock_irqrestore(&port->lock, flags);
43844 tty_port_tty_set(port, NULL);
43845@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43846 goto end;
43847 }
43848
43849- port->count++;
43850+ atomic_inc(&port->count);
43851 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43852 retval = -ENXIO;
43853 goto err_dec_count;
43854@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43855 /*
43856 * Make sure the device is in D0 state.
43857 */
43858- if (port->count == 1)
43859+ if (atomic_read(&port->count) == 1)
43860 uart_change_pm(state, UART_PM_STATE_ON);
43861
43862 /*
43863@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43864 end:
43865 return retval;
43866 err_dec_count:
43867- port->count--;
43868+ atomic_inc(&port->count);
43869 mutex_unlock(&port->mutex);
43870 goto end;
43871 }
43872diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43873index 8eaf1ab..85c030d 100644
43874--- a/drivers/tty/synclink.c
43875+++ b/drivers/tty/synclink.c
43876@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43877
43878 if (debug_level >= DEBUG_LEVEL_INFO)
43879 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43880- __FILE__,__LINE__, info->device_name, info->port.count);
43881+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43882
43883 if (tty_port_close_start(&info->port, tty, filp) == 0)
43884 goto cleanup;
43885@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43886 cleanup:
43887 if (debug_level >= DEBUG_LEVEL_INFO)
43888 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43889- tty->driver->name, info->port.count);
43890+ tty->driver->name, atomic_read(&info->port.count));
43891
43892 } /* end of mgsl_close() */
43893
43894@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43895
43896 mgsl_flush_buffer(tty);
43897 shutdown(info);
43898-
43899- info->port.count = 0;
43900+
43901+ atomic_set(&info->port.count, 0);
43902 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43903 info->port.tty = NULL;
43904
43905@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43906
43907 if (debug_level >= DEBUG_LEVEL_INFO)
43908 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43909- __FILE__,__LINE__, tty->driver->name, port->count );
43910+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43911
43912 spin_lock_irqsave(&info->irq_spinlock, flags);
43913 if (!tty_hung_up_p(filp)) {
43914 extra_count = true;
43915- port->count--;
43916+ atomic_dec(&port->count);
43917 }
43918 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43919 port->blocked_open++;
43920@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43921
43922 if (debug_level >= DEBUG_LEVEL_INFO)
43923 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43924- __FILE__,__LINE__, tty->driver->name, port->count );
43925+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43926
43927 tty_unlock(tty);
43928 schedule();
43929@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43930
43931 /* FIXME: Racy on hangup during close wait */
43932 if (extra_count)
43933- port->count++;
43934+ atomic_inc(&port->count);
43935 port->blocked_open--;
43936
43937 if (debug_level >= DEBUG_LEVEL_INFO)
43938 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43939- __FILE__,__LINE__, tty->driver->name, port->count );
43940+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43941
43942 if (!retval)
43943 port->flags |= ASYNC_NORMAL_ACTIVE;
43944@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43945
43946 if (debug_level >= DEBUG_LEVEL_INFO)
43947 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43948- __FILE__,__LINE__,tty->driver->name, info->port.count);
43949+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43950
43951 /* If port is closing, signal caller to try again */
43952 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43953@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43954 spin_unlock_irqrestore(&info->netlock, flags);
43955 goto cleanup;
43956 }
43957- info->port.count++;
43958+ atomic_inc(&info->port.count);
43959 spin_unlock_irqrestore(&info->netlock, flags);
43960
43961- if (info->port.count == 1) {
43962+ if (atomic_read(&info->port.count) == 1) {
43963 /* 1st open on this device, init hardware */
43964 retval = startup(info);
43965 if (retval < 0)
43966@@ -3446,8 +3446,8 @@ cleanup:
43967 if (retval) {
43968 if (tty->count == 1)
43969 info->port.tty = NULL; /* tty layer will release tty struct */
43970- if(info->port.count)
43971- info->port.count--;
43972+ if (atomic_read(&info->port.count))
43973+ atomic_dec(&info->port.count);
43974 }
43975
43976 return retval;
43977@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43978 unsigned short new_crctype;
43979
43980 /* return error if TTY interface open */
43981- if (info->port.count)
43982+ if (atomic_read(&info->port.count))
43983 return -EBUSY;
43984
43985 switch (encoding)
43986@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
43987
43988 /* arbitrate between network and tty opens */
43989 spin_lock_irqsave(&info->netlock, flags);
43990- if (info->port.count != 0 || info->netcount != 0) {
43991+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43992 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43993 spin_unlock_irqrestore(&info->netlock, flags);
43994 return -EBUSY;
43995@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43996 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43997
43998 /* return error if TTY interface open */
43999- if (info->port.count)
44000+ if (atomic_read(&info->port.count))
44001 return -EBUSY;
44002
44003 if (cmd != SIOCWANDEV)
44004diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
44005index 1abf946..1ee34fc 100644
44006--- a/drivers/tty/synclink_gt.c
44007+++ b/drivers/tty/synclink_gt.c
44008@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44009 tty->driver_data = info;
44010 info->port.tty = tty;
44011
44012- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
44013+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
44014
44015 /* If port is closing, signal caller to try again */
44016 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44017@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44018 mutex_unlock(&info->port.mutex);
44019 goto cleanup;
44020 }
44021- info->port.count++;
44022+ atomic_inc(&info->port.count);
44023 spin_unlock_irqrestore(&info->netlock, flags);
44024
44025- if (info->port.count == 1) {
44026+ if (atomic_read(&info->port.count) == 1) {
44027 /* 1st open on this device, init hardware */
44028 retval = startup(info);
44029 if (retval < 0) {
44030@@ -715,8 +715,8 @@ cleanup:
44031 if (retval) {
44032 if (tty->count == 1)
44033 info->port.tty = NULL; /* tty layer will release tty struct */
44034- if(info->port.count)
44035- info->port.count--;
44036+ if(atomic_read(&info->port.count))
44037+ atomic_dec(&info->port.count);
44038 }
44039
44040 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
44041@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44042
44043 if (sanity_check(info, tty->name, "close"))
44044 return;
44045- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
44046+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
44047
44048 if (tty_port_close_start(&info->port, tty, filp) == 0)
44049 goto cleanup;
44050@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44051 tty_port_close_end(&info->port, tty);
44052 info->port.tty = NULL;
44053 cleanup:
44054- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
44055+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
44056 }
44057
44058 static void hangup(struct tty_struct *tty)
44059@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
44060 shutdown(info);
44061
44062 spin_lock_irqsave(&info->port.lock, flags);
44063- info->port.count = 0;
44064+ atomic_set(&info->port.count, 0);
44065 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44066 info->port.tty = NULL;
44067 spin_unlock_irqrestore(&info->port.lock, flags);
44068@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44069 unsigned short new_crctype;
44070
44071 /* return error if TTY interface open */
44072- if (info->port.count)
44073+ if (atomic_read(&info->port.count))
44074 return -EBUSY;
44075
44076 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
44077@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
44078
44079 /* arbitrate between network and tty opens */
44080 spin_lock_irqsave(&info->netlock, flags);
44081- if (info->port.count != 0 || info->netcount != 0) {
44082+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44083 DBGINFO(("%s hdlc_open busy\n", dev->name));
44084 spin_unlock_irqrestore(&info->netlock, flags);
44085 return -EBUSY;
44086@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44087 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
44088
44089 /* return error if TTY interface open */
44090- if (info->port.count)
44091+ if (atomic_read(&info->port.count))
44092 return -EBUSY;
44093
44094 if (cmd != SIOCWANDEV)
44095@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
44096 if (port == NULL)
44097 continue;
44098 spin_lock(&port->lock);
44099- if ((port->port.count || port->netcount) &&
44100+ if ((atomic_read(&port->port.count) || port->netcount) &&
44101 port->pending_bh && !port->bh_running &&
44102 !port->bh_requested) {
44103 DBGISR(("%s bh queued\n", port->device_name));
44104@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44105 spin_lock_irqsave(&info->lock, flags);
44106 if (!tty_hung_up_p(filp)) {
44107 extra_count = true;
44108- port->count--;
44109+ atomic_dec(&port->count);
44110 }
44111 spin_unlock_irqrestore(&info->lock, flags);
44112 port->blocked_open++;
44113@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44114 remove_wait_queue(&port->open_wait, &wait);
44115
44116 if (extra_count)
44117- port->count++;
44118+ atomic_inc(&port->count);
44119 port->blocked_open--;
44120
44121 if (!retval)
44122diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44123index ff17138..e38b41e 100644
44124--- a/drivers/tty/synclinkmp.c
44125+++ b/drivers/tty/synclinkmp.c
44126@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44127
44128 if (debug_level >= DEBUG_LEVEL_INFO)
44129 printk("%s(%d):%s open(), old ref count = %d\n",
44130- __FILE__,__LINE__,tty->driver->name, info->port.count);
44131+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44132
44133 /* If port is closing, signal caller to try again */
44134 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44135@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44136 spin_unlock_irqrestore(&info->netlock, flags);
44137 goto cleanup;
44138 }
44139- info->port.count++;
44140+ atomic_inc(&info->port.count);
44141 spin_unlock_irqrestore(&info->netlock, flags);
44142
44143- if (info->port.count == 1) {
44144+ if (atomic_read(&info->port.count) == 1) {
44145 /* 1st open on this device, init hardware */
44146 retval = startup(info);
44147 if (retval < 0)
44148@@ -796,8 +796,8 @@ cleanup:
44149 if (retval) {
44150 if (tty->count == 1)
44151 info->port.tty = NULL; /* tty layer will release tty struct */
44152- if(info->port.count)
44153- info->port.count--;
44154+ if(atomic_read(&info->port.count))
44155+ atomic_dec(&info->port.count);
44156 }
44157
44158 return retval;
44159@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44160
44161 if (debug_level >= DEBUG_LEVEL_INFO)
44162 printk("%s(%d):%s close() entry, count=%d\n",
44163- __FILE__,__LINE__, info->device_name, info->port.count);
44164+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44165
44166 if (tty_port_close_start(&info->port, tty, filp) == 0)
44167 goto cleanup;
44168@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44169 cleanup:
44170 if (debug_level >= DEBUG_LEVEL_INFO)
44171 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44172- tty->driver->name, info->port.count);
44173+ tty->driver->name, atomic_read(&info->port.count));
44174 }
44175
44176 /* Called by tty_hangup() when a hangup is signaled.
44177@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
44178 shutdown(info);
44179
44180 spin_lock_irqsave(&info->port.lock, flags);
44181- info->port.count = 0;
44182+ atomic_set(&info->port.count, 0);
44183 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44184 info->port.tty = NULL;
44185 spin_unlock_irqrestore(&info->port.lock, flags);
44186@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44187 unsigned short new_crctype;
44188
44189 /* return error if TTY interface open */
44190- if (info->port.count)
44191+ if (atomic_read(&info->port.count))
44192 return -EBUSY;
44193
44194 switch (encoding)
44195@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
44196
44197 /* arbitrate between network and tty opens */
44198 spin_lock_irqsave(&info->netlock, flags);
44199- if (info->port.count != 0 || info->netcount != 0) {
44200+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44201 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44202 spin_unlock_irqrestore(&info->netlock, flags);
44203 return -EBUSY;
44204@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44205 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44206
44207 /* return error if TTY interface open */
44208- if (info->port.count)
44209+ if (atomic_read(&info->port.count))
44210 return -EBUSY;
44211
44212 if (cmd != SIOCWANDEV)
44213@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44214 * do not request bottom half processing if the
44215 * device is not open in a normal mode.
44216 */
44217- if ( port && (port->port.count || port->netcount) &&
44218+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44219 port->pending_bh && !port->bh_running &&
44220 !port->bh_requested ) {
44221 if ( debug_level >= DEBUG_LEVEL_ISR )
44222@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44223
44224 if (debug_level >= DEBUG_LEVEL_INFO)
44225 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44226- __FILE__,__LINE__, tty->driver->name, port->count );
44227+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44228
44229 spin_lock_irqsave(&info->lock, flags);
44230 if (!tty_hung_up_p(filp)) {
44231 extra_count = true;
44232- port->count--;
44233+ atomic_dec(&port->count);
44234 }
44235 spin_unlock_irqrestore(&info->lock, flags);
44236 port->blocked_open++;
44237@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44238
44239 if (debug_level >= DEBUG_LEVEL_INFO)
44240 printk("%s(%d):%s block_til_ready() count=%d\n",
44241- __FILE__,__LINE__, tty->driver->name, port->count );
44242+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44243
44244 tty_unlock(tty);
44245 schedule();
44246@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44247 remove_wait_queue(&port->open_wait, &wait);
44248
44249 if (extra_count)
44250- port->count++;
44251+ atomic_inc(&port->count);
44252 port->blocked_open--;
44253
44254 if (debug_level >= DEBUG_LEVEL_INFO)
44255 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44256- __FILE__,__LINE__, tty->driver->name, port->count );
44257+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44258
44259 if (!retval)
44260 port->flags |= ASYNC_NORMAL_ACTIVE;
44261diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44262index b51c154..17d55d1 100644
44263--- a/drivers/tty/sysrq.c
44264+++ b/drivers/tty/sysrq.c
44265@@ -1022,7 +1022,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44266 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44267 size_t count, loff_t *ppos)
44268 {
44269- if (count) {
44270+ if (count && capable(CAP_SYS_ADMIN)) {
44271 char c;
44272
44273 if (get_user(c, buf))
44274diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44275index 4476682..d77e748 100644
44276--- a/drivers/tty/tty_io.c
44277+++ b/drivers/tty/tty_io.c
44278@@ -3466,7 +3466,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44279
44280 void tty_default_fops(struct file_operations *fops)
44281 {
44282- *fops = tty_fops;
44283+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44284 }
44285
44286 /*
44287diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44288index 1afe192..73d2c20 100644
44289--- a/drivers/tty/tty_ldisc.c
44290+++ b/drivers/tty/tty_ldisc.c
44291@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44292 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44293 tty_ldiscs[disc] = new_ldisc;
44294 new_ldisc->num = disc;
44295- new_ldisc->refcount = 0;
44296+ atomic_set(&new_ldisc->refcount, 0);
44297 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44298
44299 return ret;
44300@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
44301 return -EINVAL;
44302
44303 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44304- if (tty_ldiscs[disc]->refcount)
44305+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44306 ret = -EBUSY;
44307 else
44308 tty_ldiscs[disc] = NULL;
44309@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44310 if (ldops) {
44311 ret = ERR_PTR(-EAGAIN);
44312 if (try_module_get(ldops->owner)) {
44313- ldops->refcount++;
44314+ atomic_inc(&ldops->refcount);
44315 ret = ldops;
44316 }
44317 }
44318@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44319 unsigned long flags;
44320
44321 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44322- ldops->refcount--;
44323+ atomic_dec(&ldops->refcount);
44324 module_put(ldops->owner);
44325 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44326 }
44327@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
44328 /* unreleased reader reference(s) will cause this WARN */
44329 WARN_ON(!atomic_dec_and_test(&ld->users));
44330
44331- ld->ops->refcount--;
44332+ atomic_dec(&ld->ops->refcount);
44333 module_put(ld->ops->owner);
44334 kfree(ld);
44335 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44336diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44337index 121aeb9..0d2c4b9 100644
44338--- a/drivers/tty/tty_port.c
44339+++ b/drivers/tty/tty_port.c
44340@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
44341 unsigned long flags;
44342
44343 spin_lock_irqsave(&port->lock, flags);
44344- port->count = 0;
44345+ atomic_set(&port->count, 0);
44346 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44347 tty = port->tty;
44348 if (tty)
44349@@ -391,7 +391,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44350 /* The port lock protects the port counts */
44351 spin_lock_irqsave(&port->lock, flags);
44352 if (!tty_hung_up_p(filp))
44353- port->count--;
44354+ atomic_dec(&port->count);
44355 port->blocked_open++;
44356 spin_unlock_irqrestore(&port->lock, flags);
44357
44358@@ -433,7 +433,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44359 we must not mess that up further */
44360 spin_lock_irqsave(&port->lock, flags);
44361 if (!tty_hung_up_p(filp))
44362- port->count++;
44363+ atomic_inc(&port->count);
44364 port->blocked_open--;
44365 if (retval == 0)
44366 port->flags |= ASYNC_NORMAL_ACTIVE;
44367@@ -467,19 +467,19 @@ int tty_port_close_start(struct tty_port *port,
44368 return 0;
44369 }
44370
44371- if (tty->count == 1 && port->count != 1) {
44372+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44373 printk(KERN_WARNING
44374 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44375- port->count);
44376- port->count = 1;
44377+ atomic_read(&port->count));
44378+ atomic_set(&port->count, 1);
44379 }
44380- if (--port->count < 0) {
44381+ if (atomic_dec_return(&port->count) < 0) {
44382 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44383- port->count);
44384- port->count = 0;
44385+ atomic_read(&port->count));
44386+ atomic_set(&port->count, 0);
44387 }
44388
44389- if (port->count) {
44390+ if (atomic_read(&port->count)) {
44391 spin_unlock_irqrestore(&port->lock, flags);
44392 if (port->ops->drop)
44393 port->ops->drop(port);
44394@@ -565,7 +565,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44395 {
44396 spin_lock_irq(&port->lock);
44397 if (!tty_hung_up_p(filp))
44398- ++port->count;
44399+ atomic_inc(&port->count);
44400 spin_unlock_irq(&port->lock);
44401 tty_port_tty_set(port, tty);
44402
44403diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44404index a9af1b9a..1e08e7f 100644
44405--- a/drivers/tty/vt/keyboard.c
44406+++ b/drivers/tty/vt/keyboard.c
44407@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44408 kbd->kbdmode == VC_OFF) &&
44409 value != KVAL(K_SAK))
44410 return; /* SAK is allowed even in raw mode */
44411+
44412+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44413+ {
44414+ void *func = fn_handler[value];
44415+ if (func == fn_show_state || func == fn_show_ptregs ||
44416+ func == fn_show_mem)
44417+ return;
44418+ }
44419+#endif
44420+
44421 fn_handler[value](vc);
44422 }
44423
44424@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44425 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44426 return -EFAULT;
44427
44428- if (!capable(CAP_SYS_TTY_CONFIG))
44429- perm = 0;
44430-
44431 switch (cmd) {
44432 case KDGKBENT:
44433 /* Ensure another thread doesn't free it under us */
44434@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44435 spin_unlock_irqrestore(&kbd_event_lock, flags);
44436 return put_user(val, &user_kbe->kb_value);
44437 case KDSKBENT:
44438+ if (!capable(CAP_SYS_TTY_CONFIG))
44439+ perm = 0;
44440+
44441 if (!perm)
44442 return -EPERM;
44443 if (!i && v == K_NOSUCHMAP) {
44444@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44445 int i, j, k;
44446 int ret;
44447
44448- if (!capable(CAP_SYS_TTY_CONFIG))
44449- perm = 0;
44450-
44451 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44452 if (!kbs) {
44453 ret = -ENOMEM;
44454@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44455 kfree(kbs);
44456 return ((p && *p) ? -EOVERFLOW : 0);
44457 case KDSKBSENT:
44458+ if (!capable(CAP_SYS_TTY_CONFIG))
44459+ perm = 0;
44460+
44461 if (!perm) {
44462 ret = -EPERM;
44463 goto reterr;
44464diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44465index b645c47..a55c182 100644
44466--- a/drivers/uio/uio.c
44467+++ b/drivers/uio/uio.c
44468@@ -25,6 +25,7 @@
44469 #include <linux/kobject.h>
44470 #include <linux/cdev.h>
44471 #include <linux/uio_driver.h>
44472+#include <asm/local.h>
44473
44474 #define UIO_MAX_DEVICES (1U << MINORBITS)
44475
44476@@ -32,10 +33,10 @@ struct uio_device {
44477 struct module *owner;
44478 struct device *dev;
44479 int minor;
44480- atomic_t event;
44481+ atomic_unchecked_t event;
44482 struct fasync_struct *async_queue;
44483 wait_queue_head_t wait;
44484- int vma_count;
44485+ local_t vma_count;
44486 struct uio_info *info;
44487 struct kobject *map_dir;
44488 struct kobject *portio_dir;
44489@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44490 struct device_attribute *attr, char *buf)
44491 {
44492 struct uio_device *idev = dev_get_drvdata(dev);
44493- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44494+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44495 }
44496
44497 static struct device_attribute uio_class_attributes[] = {
44498@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
44499 {
44500 struct uio_device *idev = info->uio_dev;
44501
44502- atomic_inc(&idev->event);
44503+ atomic_inc_unchecked(&idev->event);
44504 wake_up_interruptible(&idev->wait);
44505 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44506 }
44507@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44508 }
44509
44510 listener->dev = idev;
44511- listener->event_count = atomic_read(&idev->event);
44512+ listener->event_count = atomic_read_unchecked(&idev->event);
44513 filep->private_data = listener;
44514
44515 if (idev->info->open) {
44516@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44517 return -EIO;
44518
44519 poll_wait(filep, &idev->wait, wait);
44520- if (listener->event_count != atomic_read(&idev->event))
44521+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44522 return POLLIN | POLLRDNORM;
44523 return 0;
44524 }
44525@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44526 do {
44527 set_current_state(TASK_INTERRUPTIBLE);
44528
44529- event_count = atomic_read(&idev->event);
44530+ event_count = atomic_read_unchecked(&idev->event);
44531 if (event_count != listener->event_count) {
44532 if (copy_to_user(buf, &event_count, count))
44533 retval = -EFAULT;
44534@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44535 static void uio_vma_open(struct vm_area_struct *vma)
44536 {
44537 struct uio_device *idev = vma->vm_private_data;
44538- idev->vma_count++;
44539+ local_inc(&idev->vma_count);
44540 }
44541
44542 static void uio_vma_close(struct vm_area_struct *vma)
44543 {
44544 struct uio_device *idev = vma->vm_private_data;
44545- idev->vma_count--;
44546+ local_dec(&idev->vma_count);
44547 }
44548
44549 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44550@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
44551 idev->owner = owner;
44552 idev->info = info;
44553 init_waitqueue_head(&idev->wait);
44554- atomic_set(&idev->event, 0);
44555+ atomic_set_unchecked(&idev->event, 0);
44556
44557 ret = uio_get_minor(idev);
44558 if (ret)
44559diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44560index 8a7eb77..c00402f 100644
44561--- a/drivers/usb/atm/cxacru.c
44562+++ b/drivers/usb/atm/cxacru.c
44563@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44564 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44565 if (ret < 2)
44566 return -EINVAL;
44567- if (index < 0 || index > 0x7f)
44568+ if (index > 0x7f)
44569 return -EINVAL;
44570 pos += tmp;
44571
44572diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44573index d3527dd..26effa2 100644
44574--- a/drivers/usb/atm/usbatm.c
44575+++ b/drivers/usb/atm/usbatm.c
44576@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44577 if (printk_ratelimit())
44578 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44579 __func__, vpi, vci);
44580- atomic_inc(&vcc->stats->rx_err);
44581+ atomic_inc_unchecked(&vcc->stats->rx_err);
44582 return;
44583 }
44584
44585@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44586 if (length > ATM_MAX_AAL5_PDU) {
44587 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44588 __func__, length, vcc);
44589- atomic_inc(&vcc->stats->rx_err);
44590+ atomic_inc_unchecked(&vcc->stats->rx_err);
44591 goto out;
44592 }
44593
44594@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44595 if (sarb->len < pdu_length) {
44596 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44597 __func__, pdu_length, sarb->len, vcc);
44598- atomic_inc(&vcc->stats->rx_err);
44599+ atomic_inc_unchecked(&vcc->stats->rx_err);
44600 goto out;
44601 }
44602
44603 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44604 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44605 __func__, vcc);
44606- atomic_inc(&vcc->stats->rx_err);
44607+ atomic_inc_unchecked(&vcc->stats->rx_err);
44608 goto out;
44609 }
44610
44611@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44612 if (printk_ratelimit())
44613 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44614 __func__, length);
44615- atomic_inc(&vcc->stats->rx_drop);
44616+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44617 goto out;
44618 }
44619
44620@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44621
44622 vcc->push(vcc, skb);
44623
44624- atomic_inc(&vcc->stats->rx);
44625+ atomic_inc_unchecked(&vcc->stats->rx);
44626 out:
44627 skb_trim(sarb, 0);
44628 }
44629@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44630 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44631
44632 usbatm_pop(vcc, skb);
44633- atomic_inc(&vcc->stats->tx);
44634+ atomic_inc_unchecked(&vcc->stats->tx);
44635
44636 skb = skb_dequeue(&instance->sndqueue);
44637 }
44638@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44639 if (!left--)
44640 return sprintf(page,
44641 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44642- atomic_read(&atm_dev->stats.aal5.tx),
44643- atomic_read(&atm_dev->stats.aal5.tx_err),
44644- atomic_read(&atm_dev->stats.aal5.rx),
44645- atomic_read(&atm_dev->stats.aal5.rx_err),
44646- atomic_read(&atm_dev->stats.aal5.rx_drop));
44647+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44648+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44649+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44650+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44651+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44652
44653 if (!left--) {
44654 if (instance->disconnected)
44655diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44656index 2a3bbdf..91d72cf 100644
44657--- a/drivers/usb/core/devices.c
44658+++ b/drivers/usb/core/devices.c
44659@@ -126,7 +126,7 @@ static const char format_endpt[] =
44660 * time it gets called.
44661 */
44662 static struct device_connect_event {
44663- atomic_t count;
44664+ atomic_unchecked_t count;
44665 wait_queue_head_t wait;
44666 } device_event = {
44667 .count = ATOMIC_INIT(1),
44668@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44669
44670 void usbfs_conn_disc_event(void)
44671 {
44672- atomic_add(2, &device_event.count);
44673+ atomic_add_unchecked(2, &device_event.count);
44674 wake_up(&device_event.wait);
44675 }
44676
44677@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
44678
44679 poll_wait(file, &device_event.wait, wait);
44680
44681- event_count = atomic_read(&device_event.count);
44682+ event_count = atomic_read_unchecked(&device_event.count);
44683 if (file->f_version != event_count) {
44684 file->f_version = event_count;
44685 return POLLIN | POLLRDNORM;
44686diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44687index d53547d..6a22d02 100644
44688--- a/drivers/usb/core/hcd.c
44689+++ b/drivers/usb/core/hcd.c
44690@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44691 */
44692 usb_get_urb(urb);
44693 atomic_inc(&urb->use_count);
44694- atomic_inc(&urb->dev->urbnum);
44695+ atomic_inc_unchecked(&urb->dev->urbnum);
44696 usbmon_urb_submit(&hcd->self, urb);
44697
44698 /* NOTE requirements on root-hub callers (usbfs and the hub
44699@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44700 urb->hcpriv = NULL;
44701 INIT_LIST_HEAD(&urb->urb_list);
44702 atomic_dec(&urb->use_count);
44703- atomic_dec(&urb->dev->urbnum);
44704+ atomic_dec_unchecked(&urb->dev->urbnum);
44705 if (atomic_read(&urb->reject))
44706 wake_up(&usb_kill_urb_queue);
44707 usb_put_urb(urb);
44708diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44709index 444d30e..f15c850 100644
44710--- a/drivers/usb/core/message.c
44711+++ b/drivers/usb/core/message.c
44712@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44713 * method can wait for it to complete. Since you don't have a handle on the
44714 * URB used, you can't cancel the request.
44715 */
44716-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44717+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44718 __u8 requesttype, __u16 value, __u16 index, void *data,
44719 __u16 size, int timeout)
44720 {
44721diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44722index aa38db4..0a08682 100644
44723--- a/drivers/usb/core/sysfs.c
44724+++ b/drivers/usb/core/sysfs.c
44725@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44726 struct usb_device *udev;
44727
44728 udev = to_usb_device(dev);
44729- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44730+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44731 }
44732 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44733
44734diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44735index b10da72..43aa0b2 100644
44736--- a/drivers/usb/core/usb.c
44737+++ b/drivers/usb/core/usb.c
44738@@ -389,7 +389,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44739 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44740 dev->state = USB_STATE_ATTACHED;
44741 dev->lpm_disable_count = 1;
44742- atomic_set(&dev->urbnum, 0);
44743+ atomic_set_unchecked(&dev->urbnum, 0);
44744
44745 INIT_LIST_HEAD(&dev->ep0.urb_list);
44746 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44747diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44748index 5e29dde..eca992f 100644
44749--- a/drivers/usb/early/ehci-dbgp.c
44750+++ b/drivers/usb/early/ehci-dbgp.c
44751@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44752
44753 #ifdef CONFIG_KGDB
44754 static struct kgdb_io kgdbdbgp_io_ops;
44755-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44756+static struct kgdb_io kgdbdbgp_io_ops_console;
44757+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44758 #else
44759 #define dbgp_kgdb_mode (0)
44760 #endif
44761@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44762 .write_char = kgdbdbgp_write_char,
44763 };
44764
44765+static struct kgdb_io kgdbdbgp_io_ops_console = {
44766+ .name = "kgdbdbgp",
44767+ .read_char = kgdbdbgp_read_char,
44768+ .write_char = kgdbdbgp_write_char,
44769+ .is_console = 1
44770+};
44771+
44772 static int kgdbdbgp_wait_time;
44773
44774 static int __init kgdbdbgp_parse_config(char *str)
44775@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44776 ptr++;
44777 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44778 }
44779- kgdb_register_io_module(&kgdbdbgp_io_ops);
44780- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44781+ if (early_dbgp_console.index != -1)
44782+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44783+ else
44784+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44785
44786 return 0;
44787 }
44788diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44789index b369292..9f3ba40 100644
44790--- a/drivers/usb/gadget/u_serial.c
44791+++ b/drivers/usb/gadget/u_serial.c
44792@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44793 spin_lock_irq(&port->port_lock);
44794
44795 /* already open? Great. */
44796- if (port->port.count) {
44797+ if (atomic_read(&port->port.count)) {
44798 status = 0;
44799- port->port.count++;
44800+ atomic_inc(&port->port.count);
44801
44802 /* currently opening/closing? wait ... */
44803 } else if (port->openclose) {
44804@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44805 tty->driver_data = port;
44806 port->port.tty = tty;
44807
44808- port->port.count = 1;
44809+ atomic_set(&port->port.count, 1);
44810 port->openclose = false;
44811
44812 /* if connected, start the I/O stream */
44813@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44814
44815 spin_lock_irq(&port->port_lock);
44816
44817- if (port->port.count != 1) {
44818- if (port->port.count == 0)
44819+ if (atomic_read(&port->port.count) != 1) {
44820+ if (atomic_read(&port->port.count) == 0)
44821 WARN_ON(1);
44822 else
44823- --port->port.count;
44824+ atomic_dec(&port->port.count);
44825 goto exit;
44826 }
44827
44828@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44829 * and sleep if necessary
44830 */
44831 port->openclose = true;
44832- port->port.count = 0;
44833+ atomic_set(&port->port.count, 0);
44834
44835 gser = port->port_usb;
44836 if (gser && gser->disconnect)
44837@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
44838 int cond;
44839
44840 spin_lock_irq(&port->port_lock);
44841- cond = (port->port.count == 0) && !port->openclose;
44842+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44843 spin_unlock_irq(&port->port_lock);
44844 return cond;
44845 }
44846@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44847 /* if it's already open, start I/O ... and notify the serial
44848 * protocol about open/close status (connect/disconnect).
44849 */
44850- if (port->port.count) {
44851+ if (atomic_read(&port->port.count)) {
44852 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44853 gs_start_io(port);
44854 if (gser->connect)
44855@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
44856
44857 port->port_usb = NULL;
44858 gser->ioport = NULL;
44859- if (port->port.count > 0 || port->openclose) {
44860+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44861 wake_up_interruptible(&port->drain_wait);
44862 if (port->port.tty)
44863 tty_hangup(port->port.tty);
44864@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
44865
44866 /* finally, free any unused/unusable I/O buffers */
44867 spin_lock_irqsave(&port->port_lock, flags);
44868- if (port->port.count == 0 && !port->openclose)
44869+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44870 gs_buf_free(&port->port_write_buf);
44871 gs_free_requests(gser->out, &port->read_pool, NULL);
44872 gs_free_requests(gser->out, &port->read_queue, NULL);
44873diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44874index 5f3bcd3..bfca43f 100644
44875--- a/drivers/usb/serial/console.c
44876+++ b/drivers/usb/serial/console.c
44877@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44878
44879 info->port = port;
44880
44881- ++port->port.count;
44882+ atomic_inc(&port->port.count);
44883 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44884 if (serial->type->set_termios) {
44885 /*
44886@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44887 }
44888 /* Now that any required fake tty operations are completed restore
44889 * the tty port count */
44890- --port->port.count;
44891+ atomic_dec(&port->port.count);
44892 /* The console is special in terms of closing the device so
44893 * indicate this port is now acting as a system console. */
44894 port->port.console = 1;
44895@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44896 free_tty:
44897 kfree(tty);
44898 reset_open_count:
44899- port->port.count = 0;
44900+ atomic_set(&port->port.count, 0);
44901 usb_autopm_put_interface(serial->interface);
44902 error_get_interface:
44903 usb_serial_put(serial);
44904diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44905index 75f70f0..d467e1a 100644
44906--- a/drivers/usb/storage/usb.h
44907+++ b/drivers/usb/storage/usb.h
44908@@ -63,7 +63,7 @@ struct us_unusual_dev {
44909 __u8 useProtocol;
44910 __u8 useTransport;
44911 int (*initFunction)(struct us_data *);
44912-};
44913+} __do_const;
44914
44915
44916 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44917diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44918index d6bea3e..60b250e 100644
44919--- a/drivers/usb/wusbcore/wa-hc.h
44920+++ b/drivers/usb/wusbcore/wa-hc.h
44921@@ -192,7 +192,7 @@ struct wahc {
44922 struct list_head xfer_delayed_list;
44923 spinlock_t xfer_list_lock;
44924 struct work_struct xfer_work;
44925- atomic_t xfer_id_count;
44926+ atomic_unchecked_t xfer_id_count;
44927 };
44928
44929
44930@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44931 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44932 spin_lock_init(&wa->xfer_list_lock);
44933 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44934- atomic_set(&wa->xfer_id_count, 1);
44935+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44936 }
44937
44938 /**
44939diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44940index 6ef94bc..1b41265 100644
44941--- a/drivers/usb/wusbcore/wa-xfer.c
44942+++ b/drivers/usb/wusbcore/wa-xfer.c
44943@@ -296,7 +296,7 @@ out:
44944 */
44945 static void wa_xfer_id_init(struct wa_xfer *xfer)
44946 {
44947- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44948+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44949 }
44950
44951 /*
44952diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
44953index f80d3dd..8ca5ac7 100644
44954--- a/drivers/vhost/net.c
44955+++ b/drivers/vhost/net.c
44956@@ -150,6 +150,11 @@ static void vhost_net_ubuf_put_and_wait(struct vhost_net_ubuf_ref *ubufs)
44957 {
44958 kref_put(&ubufs->kref, vhost_net_zerocopy_done_signal);
44959 wait_event(ubufs->wait, !atomic_read(&ubufs->kref.refcount));
44960+}
44961+
44962+static void vhost_net_ubuf_put_wait_and_free(struct vhost_net_ubuf_ref *ubufs)
44963+{
44964+ vhost_net_ubuf_put_and_wait(ubufs);
44965 kfree(ubufs);
44966 }
44967
44968@@ -948,7 +953,7 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd)
44969 mutex_unlock(&vq->mutex);
44970
44971 if (oldubufs) {
44972- vhost_net_ubuf_put_and_wait(oldubufs);
44973+ vhost_net_ubuf_put_wait_and_free(oldubufs);
44974 mutex_lock(&vq->mutex);
44975 vhost_zerocopy_signal_used(n, vq);
44976 mutex_unlock(&vq->mutex);
44977@@ -966,7 +971,7 @@ err_used:
44978 rcu_assign_pointer(vq->private_data, oldsock);
44979 vhost_net_enable_vq(n, vq);
44980 if (ubufs)
44981- vhost_net_ubuf_put_and_wait(ubufs);
44982+ vhost_net_ubuf_put_wait_and_free(ubufs);
44983 err_ubufs:
44984 fput(sock->file);
44985 err_vq:
44986diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
44987index 5174eba..86e764a 100644
44988--- a/drivers/vhost/vringh.c
44989+++ b/drivers/vhost/vringh.c
44990@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
44991
44992 static inline int putu16_kern(u16 *p, u16 val)
44993 {
44994- ACCESS_ONCE(*p) = val;
44995+ ACCESS_ONCE_RW(*p) = val;
44996 return 0;
44997 }
44998
44999diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
45000index 8c55011..eed4ae1a 100644
45001--- a/drivers/video/aty/aty128fb.c
45002+++ b/drivers/video/aty/aty128fb.c
45003@@ -149,7 +149,7 @@ enum {
45004 };
45005
45006 /* Must match above enum */
45007-static char * const r128_family[] = {
45008+static const char * const r128_family[] = {
45009 "AGP",
45010 "PCI",
45011 "PRO AGP",
45012diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
45013index 4f27fdc..d3537e6 100644
45014--- a/drivers/video/aty/atyfb_base.c
45015+++ b/drivers/video/aty/atyfb_base.c
45016@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
45017 par->accel_flags = var->accel_flags; /* hack */
45018
45019 if (var->accel_flags) {
45020- info->fbops->fb_sync = atyfb_sync;
45021+ pax_open_kernel();
45022+ *(void **)&info->fbops->fb_sync = atyfb_sync;
45023+ pax_close_kernel();
45024 info->flags &= ~FBINFO_HWACCEL_DISABLED;
45025 } else {
45026- info->fbops->fb_sync = NULL;
45027+ pax_open_kernel();
45028+ *(void **)&info->fbops->fb_sync = NULL;
45029+ pax_close_kernel();
45030 info->flags |= FBINFO_HWACCEL_DISABLED;
45031 }
45032
45033diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
45034index 95ec042..e6affdd 100644
45035--- a/drivers/video/aty/mach64_cursor.c
45036+++ b/drivers/video/aty/mach64_cursor.c
45037@@ -7,6 +7,7 @@
45038 #include <linux/string.h>
45039
45040 #include <asm/io.h>
45041+#include <asm/pgtable.h>
45042
45043 #ifdef __sparc__
45044 #include <asm/fbio.h>
45045@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
45046 info->sprite.buf_align = 16; /* and 64 lines tall. */
45047 info->sprite.flags = FB_PIXMAP_IO;
45048
45049- info->fbops->fb_cursor = atyfb_cursor;
45050+ pax_open_kernel();
45051+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
45052+ pax_close_kernel();
45053
45054 return 0;
45055 }
45056diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
45057index bca6ccc..252107e 100644
45058--- a/drivers/video/backlight/kb3886_bl.c
45059+++ b/drivers/video/backlight/kb3886_bl.c
45060@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
45061 static unsigned long kb3886bl_flags;
45062 #define KB3886BL_SUSPENDED 0x01
45063
45064-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
45065+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
45066 {
45067 .ident = "Sahara Touch-iT",
45068 .matches = {
45069diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
45070index 900aa4e..6d49418 100644
45071--- a/drivers/video/fb_defio.c
45072+++ b/drivers/video/fb_defio.c
45073@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
45074
45075 BUG_ON(!fbdefio);
45076 mutex_init(&fbdefio->lock);
45077- info->fbops->fb_mmap = fb_deferred_io_mmap;
45078+ pax_open_kernel();
45079+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
45080+ pax_close_kernel();
45081 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
45082 INIT_LIST_HEAD(&fbdefio->pagelist);
45083 if (fbdefio->delay == 0) /* set a default of 1 s */
45084@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
45085 page->mapping = NULL;
45086 }
45087
45088- info->fbops->fb_mmap = NULL;
45089+ *(void **)&info->fbops->fb_mmap = NULL;
45090 mutex_destroy(&fbdefio->lock);
45091 }
45092 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
45093diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
45094index 5c3960d..15cf8fc 100644
45095--- a/drivers/video/fbcmap.c
45096+++ b/drivers/video/fbcmap.c
45097@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
45098 rc = -ENODEV;
45099 goto out;
45100 }
45101- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
45102- !info->fbops->fb_setcmap)) {
45103+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
45104 rc = -EINVAL;
45105 goto out1;
45106 }
45107diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
45108index 098bfc6..796841d 100644
45109--- a/drivers/video/fbmem.c
45110+++ b/drivers/video/fbmem.c
45111@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45112 image->dx += image->width + 8;
45113 }
45114 } else if (rotate == FB_ROTATE_UD) {
45115- for (x = 0; x < num && image->dx >= 0; x++) {
45116+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
45117 info->fbops->fb_imageblit(info, image);
45118 image->dx -= image->width + 8;
45119 }
45120@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
45121 image->dy += image->height + 8;
45122 }
45123 } else if (rotate == FB_ROTATE_CCW) {
45124- for (x = 0; x < num && image->dy >= 0; x++) {
45125+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
45126 info->fbops->fb_imageblit(info, image);
45127 image->dy -= image->height + 8;
45128 }
45129@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
45130 return -EFAULT;
45131 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
45132 return -EINVAL;
45133- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
45134+ if (con2fb.framebuffer >= FB_MAX)
45135 return -EINVAL;
45136 if (!registered_fb[con2fb.framebuffer])
45137 request_module("fb%d", con2fb.framebuffer);
45138diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
45139index 7672d2e..b56437f 100644
45140--- a/drivers/video/i810/i810_accel.c
45141+++ b/drivers/video/i810/i810_accel.c
45142@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45143 }
45144 }
45145 printk("ringbuffer lockup!!!\n");
45146+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45147 i810_report_error(mmio);
45148 par->dev_flags |= LOCKUP;
45149 info->pixmap.scan_align = 1;
45150diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45151index 3c14e43..eafa544 100644
45152--- a/drivers/video/logo/logo_linux_clut224.ppm
45153+++ b/drivers/video/logo/logo_linux_clut224.ppm
45154@@ -1,1604 +1,1123 @@
45155 P3
45156-# Standard 224-color Linux logo
45157 80 80
45158 255
45159- 0 0 0 0 0 0 0 0 0 0 0 0
45160- 0 0 0 0 0 0 0 0 0 0 0 0
45161- 0 0 0 0 0 0 0 0 0 0 0 0
45162- 0 0 0 0 0 0 0 0 0 0 0 0
45163- 0 0 0 0 0 0 0 0 0 0 0 0
45164- 0 0 0 0 0 0 0 0 0 0 0 0
45165- 0 0 0 0 0 0 0 0 0 0 0 0
45166- 0 0 0 0 0 0 0 0 0 0 0 0
45167- 0 0 0 0 0 0 0 0 0 0 0 0
45168- 6 6 6 6 6 6 10 10 10 10 10 10
45169- 10 10 10 6 6 6 6 6 6 6 6 6
45170- 0 0 0 0 0 0 0 0 0 0 0 0
45171- 0 0 0 0 0 0 0 0 0 0 0 0
45172- 0 0 0 0 0 0 0 0 0 0 0 0
45173- 0 0 0 0 0 0 0 0 0 0 0 0
45174- 0 0 0 0 0 0 0 0 0 0 0 0
45175- 0 0 0 0 0 0 0 0 0 0 0 0
45176- 0 0 0 0 0 0 0 0 0 0 0 0
45177- 0 0 0 0 0 0 0 0 0 0 0 0
45178- 0 0 0 0 0 0 0 0 0 0 0 0
45179- 0 0 0 0 0 0 0 0 0 0 0 0
45180- 0 0 0 0 0 0 0 0 0 0 0 0
45181- 0 0 0 0 0 0 0 0 0 0 0 0
45182- 0 0 0 0 0 0 0 0 0 0 0 0
45183- 0 0 0 0 0 0 0 0 0 0 0 0
45184- 0 0 0 0 0 0 0 0 0 0 0 0
45185- 0 0 0 0 0 0 0 0 0 0 0 0
45186- 0 0 0 0 0 0 0 0 0 0 0 0
45187- 0 0 0 6 6 6 10 10 10 14 14 14
45188- 22 22 22 26 26 26 30 30 30 34 34 34
45189- 30 30 30 30 30 30 26 26 26 18 18 18
45190- 14 14 14 10 10 10 6 6 6 0 0 0
45191- 0 0 0 0 0 0 0 0 0 0 0 0
45192- 0 0 0 0 0 0 0 0 0 0 0 0
45193- 0 0 0 0 0 0 0 0 0 0 0 0
45194- 0 0 0 0 0 0 0 0 0 0 0 0
45195- 0 0 0 0 0 0 0 0 0 0 0 0
45196- 0 0 0 0 0 0 0 0 0 0 0 0
45197- 0 0 0 0 0 0 0 0 0 0 0 0
45198- 0 0 0 0 0 0 0 0 0 0 0 0
45199- 0 0 0 0 0 0 0 0 0 0 0 0
45200- 0 0 0 0 0 1 0 0 1 0 0 0
45201- 0 0 0 0 0 0 0 0 0 0 0 0
45202- 0 0 0 0 0 0 0 0 0 0 0 0
45203- 0 0 0 0 0 0 0 0 0 0 0 0
45204- 0 0 0 0 0 0 0 0 0 0 0 0
45205- 0 0 0 0 0 0 0 0 0 0 0 0
45206- 0 0 0 0 0 0 0 0 0 0 0 0
45207- 6 6 6 14 14 14 26 26 26 42 42 42
45208- 54 54 54 66 66 66 78 78 78 78 78 78
45209- 78 78 78 74 74 74 66 66 66 54 54 54
45210- 42 42 42 26 26 26 18 18 18 10 10 10
45211- 6 6 6 0 0 0 0 0 0 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 0 0 0
45216- 0 0 0 0 0 0 0 0 0 0 0 0
45217- 0 0 0 0 0 0 0 0 0 0 0 0
45218- 0 0 0 0 0 0 0 0 0 0 0 0
45219- 0 0 0 0 0 0 0 0 0 0 0 0
45220- 0 0 1 0 0 0 0 0 0 0 0 0
45221- 0 0 0 0 0 0 0 0 0 0 0 0
45222- 0 0 0 0 0 0 0 0 0 0 0 0
45223- 0 0 0 0 0 0 0 0 0 0 0 0
45224- 0 0 0 0 0 0 0 0 0 0 0 0
45225- 0 0 0 0 0 0 0 0 0 0 0 0
45226- 0 0 0 0 0 0 0 0 0 10 10 10
45227- 22 22 22 42 42 42 66 66 66 86 86 86
45228- 66 66 66 38 38 38 38 38 38 22 22 22
45229- 26 26 26 34 34 34 54 54 54 66 66 66
45230- 86 86 86 70 70 70 46 46 46 26 26 26
45231- 14 14 14 6 6 6 0 0 0 0 0 0
45232- 0 0 0 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 0 0 0
45236- 0 0 0 0 0 0 0 0 0 0 0 0
45237- 0 0 0 0 0 0 0 0 0 0 0 0
45238- 0 0 0 0 0 0 0 0 0 0 0 0
45239- 0 0 0 0 0 0 0 0 0 0 0 0
45240- 0 0 1 0 0 1 0 0 1 0 0 0
45241- 0 0 0 0 0 0 0 0 0 0 0 0
45242- 0 0 0 0 0 0 0 0 0 0 0 0
45243- 0 0 0 0 0 0 0 0 0 0 0 0
45244- 0 0 0 0 0 0 0 0 0 0 0 0
45245- 0 0 0 0 0 0 0 0 0 0 0 0
45246- 0 0 0 0 0 0 10 10 10 26 26 26
45247- 50 50 50 82 82 82 58 58 58 6 6 6
45248- 2 2 6 2 2 6 2 2 6 2 2 6
45249- 2 2 6 2 2 6 2 2 6 2 2 6
45250- 6 6 6 54 54 54 86 86 86 66 66 66
45251- 38 38 38 18 18 18 6 6 6 0 0 0
45252- 0 0 0 0 0 0 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 0 0 0 0 0 0
45256- 0 0 0 0 0 0 0 0 0 0 0 0
45257- 0 0 0 0 0 0 0 0 0 0 0 0
45258- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
45267- 78 78 78 34 34 34 2 2 6 2 2 6
45268- 2 2 6 2 2 6 2 2 6 2 2 6
45269- 2 2 6 2 2 6 2 2 6 2 2 6
45270- 2 2 6 2 2 6 6 6 6 70 70 70
45271- 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
45287- 26 26 26 2 2 6 2 2 6 2 2 6
45288- 2 2 6 2 2 6 2 2 6 2 2 6
45289- 2 2 6 2 2 6 2 2 6 14 14 14
45290- 46 46 46 34 34 34 6 6 6 2 2 6
45291- 42 42 42 78 78 78 42 42 42 18 18 18
45292- 6 6 6 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 0 0 0 0 0 0 0
45300- 0 0 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
45307- 2 2 6 2 2 6 2 2 6 2 2 6
45308- 2 2 6 2 2 6 2 2 6 2 2 6
45309- 2 2 6 2 2 6 2 2 6 26 26 26
45310- 86 86 86 101 101 101 46 46 46 10 10 10
45311- 2 2 6 58 58 58 70 70 70 34 34 34
45312- 10 10 10 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 0 0 0 0 0 0 0 0 0 0
45320- 0 0 1 0 0 1 0 0 1 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 0 0 0
45326- 14 14 14 42 42 42 86 86 86 10 10 10
45327- 2 2 6 2 2 6 2 2 6 2 2 6
45328- 2 2 6 2 2 6 2 2 6 2 2 6
45329- 2 2 6 2 2 6 2 2 6 30 30 30
45330- 94 94 94 94 94 94 58 58 58 26 26 26
45331- 2 2 6 6 6 6 78 78 78 54 54 54
45332- 22 22 22 6 6 6 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 0 0 0 0 0 0 0 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 0 0 0 6 6 6
45346- 22 22 22 62 62 62 62 62 62 2 2 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- 2 2 6 2 2 6 2 2 6 26 26 26
45350- 54 54 54 38 38 38 18 18 18 10 10 10
45351- 2 2 6 2 2 6 34 34 34 82 82 82
45352- 38 38 38 14 14 14 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 1 0 0 1 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 0 0 0 0 0 0 6 6 6
45366- 30 30 30 78 78 78 30 30 30 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 2 2 6 10 10 10
45370- 10 10 10 2 2 6 2 2 6 2 2 6
45371- 2 2 6 2 2 6 2 2 6 78 78 78
45372- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
45380- 0 0 1 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- 0 0 0 0 0 0 0 0 0 10 10 10
45386- 38 38 38 86 86 86 14 14 14 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 2 2 6
45389- 2 2 6 2 2 6 2 2 6 2 2 6
45390- 2 2 6 2 2 6 2 2 6 2 2 6
45391- 2 2 6 2 2 6 2 2 6 54 54 54
45392- 66 66 66 26 26 26 6 6 6 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 0 0 0 0 0 0 0 0 0 0
45400- 0 0 0 0 0 1 0 0 1 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- 0 0 0 0 0 0 0 0 0 14 14 14
45406- 42 42 42 82 82 82 2 2 6 2 2 6
45407- 2 2 6 6 6 6 10 10 10 2 2 6
45408- 2 2 6 2 2 6 2 2 6 2 2 6
45409- 2 2 6 2 2 6 2 2 6 6 6 6
45410- 14 14 14 10 10 10 2 2 6 2 2 6
45411- 2 2 6 2 2 6 2 2 6 18 18 18
45412- 82 82 82 34 34 34 10 10 10 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 0 0 0 0 0 0 0 0 0 0
45420- 0 0 1 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- 0 0 0 0 0 0 0 0 0 14 14 14
45426- 46 46 46 86 86 86 2 2 6 2 2 6
45427- 6 6 6 6 6 6 22 22 22 34 34 34
45428- 6 6 6 2 2 6 2 2 6 2 2 6
45429- 2 2 6 2 2 6 18 18 18 34 34 34
45430- 10 10 10 50 50 50 22 22 22 2 2 6
45431- 2 2 6 2 2 6 2 2 6 10 10 10
45432- 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 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 0 0 0
45445- 0 0 0 0 0 0 0 0 0 14 14 14
45446- 46 46 46 86 86 86 2 2 6 2 2 6
45447- 38 38 38 116 116 116 94 94 94 22 22 22
45448- 22 22 22 2 2 6 2 2 6 2 2 6
45449- 14 14 14 86 86 86 138 138 138 162 162 162
45450-154 154 154 38 38 38 26 26 26 6 6 6
45451- 2 2 6 2 2 6 2 2 6 2 2 6
45452- 86 86 86 46 46 46 14 14 14 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 0 0 0 0 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 0 0 0
45465- 0 0 0 0 0 0 0 0 0 14 14 14
45466- 46 46 46 86 86 86 2 2 6 14 14 14
45467-134 134 134 198 198 198 195 195 195 116 116 116
45468- 10 10 10 2 2 6 2 2 6 6 6 6
45469-101 98 89 187 187 187 210 210 210 218 218 218
45470-214 214 214 134 134 134 14 14 14 6 6 6
45471- 2 2 6 2 2 6 2 2 6 2 2 6
45472- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0 0 0 1 0 0 0
45480- 0 0 1 0 0 1 0 0 1 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 0 0 0
45485- 0 0 0 0 0 0 0 0 0 14 14 14
45486- 46 46 46 86 86 86 2 2 6 54 54 54
45487-218 218 218 195 195 195 226 226 226 246 246 246
45488- 58 58 58 2 2 6 2 2 6 30 30 30
45489-210 210 210 253 253 253 174 174 174 123 123 123
45490-221 221 221 234 234 234 74 74 74 2 2 6
45491- 2 2 6 2 2 6 2 2 6 2 2 6
45492- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 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 0 0 0
45505- 0 0 0 0 0 0 0 0 0 14 14 14
45506- 46 46 46 82 82 82 2 2 6 106 106 106
45507-170 170 170 26 26 26 86 86 86 226 226 226
45508-123 123 123 10 10 10 14 14 14 46 46 46
45509-231 231 231 190 190 190 6 6 6 70 70 70
45510- 90 90 90 238 238 238 158 158 158 2 2 6
45511- 2 2 6 2 2 6 2 2 6 2 2 6
45512- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 1 0 0 0
45520- 0 0 1 0 0 1 0 0 1 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 0 0 0
45525- 0 0 0 0 0 0 0 0 0 14 14 14
45526- 42 42 42 86 86 86 6 6 6 116 116 116
45527-106 106 106 6 6 6 70 70 70 149 149 149
45528-128 128 128 18 18 18 38 38 38 54 54 54
45529-221 221 221 106 106 106 2 2 6 14 14 14
45530- 46 46 46 190 190 190 198 198 198 2 2 6
45531- 2 2 6 2 2 6 2 2 6 2 2 6
45532- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0 0 0 0 1 0 0 0
45540- 0 0 1 0 0 0 0 0 1 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 0 0 0
45545- 0 0 0 0 0 0 0 0 0 14 14 14
45546- 42 42 42 94 94 94 14 14 14 101 101 101
45547-128 128 128 2 2 6 18 18 18 116 116 116
45548-118 98 46 121 92 8 121 92 8 98 78 10
45549-162 162 162 106 106 106 2 2 6 2 2 6
45550- 2 2 6 195 195 195 195 195 195 6 6 6
45551- 2 2 6 2 2 6 2 2 6 2 2 6
45552- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
45560- 0 0 1 0 0 0 0 0 1 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 0 0 0
45565- 0 0 0 0 0 0 0 0 0 10 10 10
45566- 38 38 38 90 90 90 14 14 14 58 58 58
45567-210 210 210 26 26 26 54 38 6 154 114 10
45568-226 170 11 236 186 11 225 175 15 184 144 12
45569-215 174 15 175 146 61 37 26 9 2 2 6
45570- 70 70 70 246 246 246 138 138 138 2 2 6
45571- 2 2 6 2 2 6 2 2 6 2 2 6
45572- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0 0
45579- 0 0 0 0 0 0 0 0 0 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 0 0 0
45585- 0 0 0 0 0 0 0 0 0 10 10 10
45586- 38 38 38 86 86 86 14 14 14 10 10 10
45587-195 195 195 188 164 115 192 133 9 225 175 15
45588-239 182 13 234 190 10 232 195 16 232 200 30
45589-245 207 45 241 208 19 232 195 16 184 144 12
45590-218 194 134 211 206 186 42 42 42 2 2 6
45591- 2 2 6 2 2 6 2 2 6 2 2 6
45592- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
45605- 0 0 0 0 0 0 0 0 0 10 10 10
45606- 34 34 34 86 86 86 14 14 14 2 2 6
45607-121 87 25 192 133 9 219 162 10 239 182 13
45608-236 186 11 232 195 16 241 208 19 244 214 54
45609-246 218 60 246 218 38 246 215 20 241 208 19
45610-241 208 19 226 184 13 121 87 25 2 2 6
45611- 2 2 6 2 2 6 2 2 6 2 2 6
45612- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0 0
45619- 0 0 0 0 0 0 0 0 0 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 0 0 0
45625- 0 0 0 0 0 0 0 0 0 10 10 10
45626- 34 34 34 82 82 82 30 30 30 61 42 6
45627-180 123 7 206 145 10 230 174 11 239 182 13
45628-234 190 10 238 202 15 241 208 19 246 218 74
45629-246 218 38 246 215 20 246 215 20 246 215 20
45630-226 184 13 215 174 15 184 144 12 6 6 6
45631- 2 2 6 2 2 6 2 2 6 2 2 6
45632- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0 0
45639- 0 0 0 0 0 0 0 0 0 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 0 0 0
45645- 0 0 0 0 0 0 0 0 0 10 10 10
45646- 30 30 30 78 78 78 50 50 50 104 69 6
45647-192 133 9 216 158 10 236 178 12 236 186 11
45648-232 195 16 241 208 19 244 214 54 245 215 43
45649-246 215 20 246 215 20 241 208 19 198 155 10
45650-200 144 11 216 158 10 156 118 10 2 2 6
45651- 2 2 6 2 2 6 2 2 6 2 2 6
45652- 6 6 6 90 90 90 54 54 54 18 18 18
45653- 6 6 6 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 0 0 0 0
45659- 0 0 0 0 0 0 0 0 0 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 0 0 0
45665- 0 0 0 0 0 0 0 0 0 10 10 10
45666- 30 30 30 78 78 78 46 46 46 22 22 22
45667-137 92 6 210 162 10 239 182 13 238 190 10
45668-238 202 15 241 208 19 246 215 20 246 215 20
45669-241 208 19 203 166 17 185 133 11 210 150 10
45670-216 158 10 210 150 10 102 78 10 2 2 6
45671- 6 6 6 54 54 54 14 14 14 2 2 6
45672- 2 2 6 62 62 62 74 74 74 30 30 30
45673- 10 10 10 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 0 0 0
45685- 0 0 0 0 0 0 0 0 0 10 10 10
45686- 34 34 34 78 78 78 50 50 50 6 6 6
45687- 94 70 30 139 102 15 190 146 13 226 184 13
45688-232 200 30 232 195 16 215 174 15 190 146 13
45689-168 122 10 192 133 9 210 150 10 213 154 11
45690-202 150 34 182 157 106 101 98 89 2 2 6
45691- 2 2 6 78 78 78 116 116 116 58 58 58
45692- 2 2 6 22 22 22 90 90 90 46 46 46
45693- 18 18 18 6 6 6 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 0 0 0
45705- 0 0 0 0 0 0 0 0 0 10 10 10
45706- 38 38 38 86 86 86 50 50 50 6 6 6
45707-128 128 128 174 154 114 156 107 11 168 122 10
45708-198 155 10 184 144 12 197 138 11 200 144 11
45709-206 145 10 206 145 10 197 138 11 188 164 115
45710-195 195 195 198 198 198 174 174 174 14 14 14
45711- 2 2 6 22 22 22 116 116 116 116 116 116
45712- 22 22 22 2 2 6 74 74 74 70 70 70
45713- 30 30 30 10 10 10 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 0 0 0
45725- 0 0 0 0 0 0 6 6 6 18 18 18
45726- 50 50 50 101 101 101 26 26 26 10 10 10
45727-138 138 138 190 190 190 174 154 114 156 107 11
45728-197 138 11 200 144 11 197 138 11 192 133 9
45729-180 123 7 190 142 34 190 178 144 187 187 187
45730-202 202 202 221 221 221 214 214 214 66 66 66
45731- 2 2 6 2 2 6 50 50 50 62 62 62
45732- 6 6 6 2 2 6 10 10 10 90 90 90
45733- 50 50 50 18 18 18 6 6 6 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 0 0 0
45745- 0 0 0 0 0 0 10 10 10 34 34 34
45746- 74 74 74 74 74 74 2 2 6 6 6 6
45747-144 144 144 198 198 198 190 190 190 178 166 146
45748-154 121 60 156 107 11 156 107 11 168 124 44
45749-174 154 114 187 187 187 190 190 190 210 210 210
45750-246 246 246 253 253 253 253 253 253 182 182 182
45751- 6 6 6 2 2 6 2 2 6 2 2 6
45752- 2 2 6 2 2 6 2 2 6 62 62 62
45753- 74 74 74 34 34 34 14 14 14 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 0 0 0
45765- 0 0 0 10 10 10 22 22 22 54 54 54
45766- 94 94 94 18 18 18 2 2 6 46 46 46
45767-234 234 234 221 221 221 190 190 190 190 190 190
45768-190 190 190 187 187 187 187 187 187 190 190 190
45769-190 190 190 195 195 195 214 214 214 242 242 242
45770-253 253 253 253 253 253 253 253 253 253 253 253
45771- 82 82 82 2 2 6 2 2 6 2 2 6
45772- 2 2 6 2 2 6 2 2 6 14 14 14
45773- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0
45785- 6 6 6 18 18 18 46 46 46 90 90 90
45786- 46 46 46 18 18 18 6 6 6 182 182 182
45787-253 253 253 246 246 246 206 206 206 190 190 190
45788-190 190 190 190 190 190 190 190 190 190 190 190
45789-206 206 206 231 231 231 250 250 250 253 253 253
45790-253 253 253 253 253 253 253 253 253 253 253 253
45791-202 202 202 14 14 14 2 2 6 2 2 6
45792- 2 2 6 2 2 6 2 2 6 2 2 6
45793- 42 42 42 86 86 86 42 42 42 18 18 18
45794- 6 6 6 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 6 6 6
45805- 14 14 14 38 38 38 74 74 74 66 66 66
45806- 2 2 6 6 6 6 90 90 90 250 250 250
45807-253 253 253 253 253 253 238 238 238 198 198 198
45808-190 190 190 190 190 190 195 195 195 221 221 221
45809-246 246 246 253 253 253 253 253 253 253 253 253
45810-253 253 253 253 253 253 253 253 253 253 253 253
45811-253 253 253 82 82 82 2 2 6 2 2 6
45812- 2 2 6 2 2 6 2 2 6 2 2 6
45813- 2 2 6 78 78 78 70 70 70 34 34 34
45814- 14 14 14 6 6 6 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 0 0 0 14 14 14
45825- 34 34 34 66 66 66 78 78 78 6 6 6
45826- 2 2 6 18 18 18 218 218 218 253 253 253
45827-253 253 253 253 253 253 253 253 253 246 246 246
45828-226 226 226 231 231 231 246 246 246 253 253 253
45829-253 253 253 253 253 253 253 253 253 253 253 253
45830-253 253 253 253 253 253 253 253 253 253 253 253
45831-253 253 253 178 178 178 2 2 6 2 2 6
45832- 2 2 6 2 2 6 2 2 6 2 2 6
45833- 2 2 6 18 18 18 90 90 90 62 62 62
45834- 30 30 30 10 10 10 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 26 26 26
45845- 58 58 58 90 90 90 18 18 18 2 2 6
45846- 2 2 6 110 110 110 253 253 253 253 253 253
45847-253 253 253 253 253 253 253 253 253 253 253 253
45848-250 250 250 253 253 253 253 253 253 253 253 253
45849-253 253 253 253 253 253 253 253 253 253 253 253
45850-253 253 253 253 253 253 253 253 253 253 253 253
45851-253 253 253 231 231 231 18 18 18 2 2 6
45852- 2 2 6 2 2 6 2 2 6 2 2 6
45853- 2 2 6 2 2 6 18 18 18 94 94 94
45854- 54 54 54 26 26 26 10 10 10 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 6 6 6 22 22 22 50 50 50
45865- 90 90 90 26 26 26 2 2 6 2 2 6
45866- 14 14 14 195 195 195 250 250 250 253 253 253
45867-253 253 253 253 253 253 253 253 253 253 253 253
45868-253 253 253 253 253 253 253 253 253 253 253 253
45869-253 253 253 253 253 253 253 253 253 253 253 253
45870-253 253 253 253 253 253 253 253 253 253 253 253
45871-250 250 250 242 242 242 54 54 54 2 2 6
45872- 2 2 6 2 2 6 2 2 6 2 2 6
45873- 2 2 6 2 2 6 2 2 6 38 38 38
45874- 86 86 86 50 50 50 22 22 22 6 6 6
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 14 14 14 38 38 38 82 82 82
45885- 34 34 34 2 2 6 2 2 6 2 2 6
45886- 42 42 42 195 195 195 246 246 246 253 253 253
45887-253 253 253 253 253 253 253 253 253 250 250 250
45888-242 242 242 242 242 242 250 250 250 253 253 253
45889-253 253 253 253 253 253 253 253 253 253 253 253
45890-253 253 253 250 250 250 246 246 246 238 238 238
45891-226 226 226 231 231 231 101 101 101 6 6 6
45892- 2 2 6 2 2 6 2 2 6 2 2 6
45893- 2 2 6 2 2 6 2 2 6 2 2 6
45894- 38 38 38 82 82 82 42 42 42 14 14 14
45895- 6 6 6 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 0 0 0
45904- 10 10 10 26 26 26 62 62 62 66 66 66
45905- 2 2 6 2 2 6 2 2 6 6 6 6
45906- 70 70 70 170 170 170 206 206 206 234 234 234
45907-246 246 246 250 250 250 250 250 250 238 238 238
45908-226 226 226 231 231 231 238 238 238 250 250 250
45909-250 250 250 250 250 250 246 246 246 231 231 231
45910-214 214 214 206 206 206 202 202 202 202 202 202
45911-198 198 198 202 202 202 182 182 182 18 18 18
45912- 2 2 6 2 2 6 2 2 6 2 2 6
45913- 2 2 6 2 2 6 2 2 6 2 2 6
45914- 2 2 6 62 62 62 66 66 66 30 30 30
45915- 10 10 10 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 0 0 0
45924- 14 14 14 42 42 42 82 82 82 18 18 18
45925- 2 2 6 2 2 6 2 2 6 10 10 10
45926- 94 94 94 182 182 182 218 218 218 242 242 242
45927-250 250 250 253 253 253 253 253 253 250 250 250
45928-234 234 234 253 253 253 253 253 253 253 253 253
45929-253 253 253 253 253 253 253 253 253 246 246 246
45930-238 238 238 226 226 226 210 210 210 202 202 202
45931-195 195 195 195 195 195 210 210 210 158 158 158
45932- 6 6 6 14 14 14 50 50 50 14 14 14
45933- 2 2 6 2 2 6 2 2 6 2 2 6
45934- 2 2 6 6 6 6 86 86 86 46 46 46
45935- 18 18 18 6 6 6 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 0 0 0 6 6 6
45944- 22 22 22 54 54 54 70 70 70 2 2 6
45945- 2 2 6 10 10 10 2 2 6 22 22 22
45946-166 166 166 231 231 231 250 250 250 253 253 253
45947-253 253 253 253 253 253 253 253 253 250 250 250
45948-242 242 242 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 253 253 253 253 253 253 246 246 246
45951-231 231 231 206 206 206 198 198 198 226 226 226
45952- 94 94 94 2 2 6 6 6 6 38 38 38
45953- 30 30 30 2 2 6 2 2 6 2 2 6
45954- 2 2 6 2 2 6 62 62 62 66 66 66
45955- 26 26 26 10 10 10 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 0 0 0 0 0 0 10 10 10
45964- 30 30 30 74 74 74 50 50 50 2 2 6
45965- 26 26 26 26 26 26 2 2 6 106 106 106
45966-238 238 238 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-253 253 253 253 253 253 253 253 253 253 253 253
45971-253 253 253 246 246 246 218 218 218 202 202 202
45972-210 210 210 14 14 14 2 2 6 2 2 6
45973- 30 30 30 22 22 22 2 2 6 2 2 6
45974- 2 2 6 2 2 6 18 18 18 86 86 86
45975- 42 42 42 14 14 14 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- 0 0 0 0 0 0 0 0 0 14 14 14
45984- 42 42 42 90 90 90 22 22 22 2 2 6
45985- 42 42 42 2 2 6 18 18 18 218 218 218
45986-253 253 253 253 253 253 253 253 253 253 253 253
45987-253 253 253 253 253 253 253 253 253 253 253 253
45988-253 253 253 253 253 253 253 253 253 253 253 253
45989-253 253 253 253 253 253 253 253 253 253 253 253
45990-253 253 253 253 253 253 253 253 253 253 253 253
45991-253 253 253 253 253 253 250 250 250 221 221 221
45992-218 218 218 101 101 101 2 2 6 14 14 14
45993- 18 18 18 38 38 38 10 10 10 2 2 6
45994- 2 2 6 2 2 6 2 2 6 78 78 78
45995- 58 58 58 22 22 22 6 6 6 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- 0 0 0 0 0 0 6 6 6 18 18 18
46004- 54 54 54 82 82 82 2 2 6 26 26 26
46005- 22 22 22 2 2 6 123 123 123 253 253 253
46006-253 253 253 253 253 253 253 253 253 253 253 253
46007-253 253 253 253 253 253 253 253 253 253 253 253
46008-253 253 253 253 253 253 253 253 253 253 253 253
46009-253 253 253 253 253 253 253 253 253 253 253 253
46010-253 253 253 253 253 253 253 253 253 253 253 253
46011-253 253 253 253 253 253 253 253 253 250 250 250
46012-238 238 238 198 198 198 6 6 6 38 38 38
46013- 58 58 58 26 26 26 38 38 38 2 2 6
46014- 2 2 6 2 2 6 2 2 6 46 46 46
46015- 78 78 78 30 30 30 10 10 10 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- 0 0 0 0 0 0 10 10 10 30 30 30
46024- 74 74 74 58 58 58 2 2 6 42 42 42
46025- 2 2 6 22 22 22 231 231 231 253 253 253
46026-253 253 253 253 253 253 253 253 253 253 253 253
46027-253 253 253 253 253 253 253 253 253 250 250 250
46028-253 253 253 253 253 253 253 253 253 253 253 253
46029-253 253 253 253 253 253 253 253 253 253 253 253
46030-253 253 253 253 253 253 253 253 253 253 253 253
46031-253 253 253 253 253 253 253 253 253 253 253 253
46032-253 253 253 246 246 246 46 46 46 38 38 38
46033- 42 42 42 14 14 14 38 38 38 14 14 14
46034- 2 2 6 2 2 6 2 2 6 6 6 6
46035- 86 86 86 46 46 46 14 14 14 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 0 0 0
46043- 0 0 0 6 6 6 14 14 14 42 42 42
46044- 90 90 90 18 18 18 18 18 18 26 26 26
46045- 2 2 6 116 116 116 253 253 253 253 253 253
46046-253 253 253 253 253 253 253 253 253 253 253 253
46047-253 253 253 253 253 253 250 250 250 238 238 238
46048-253 253 253 253 253 253 253 253 253 253 253 253
46049-253 253 253 253 253 253 253 253 253 253 253 253
46050-253 253 253 253 253 253 253 253 253 253 253 253
46051-253 253 253 253 253 253 253 253 253 253 253 253
46052-253 253 253 253 253 253 94 94 94 6 6 6
46053- 2 2 6 2 2 6 10 10 10 34 34 34
46054- 2 2 6 2 2 6 2 2 6 2 2 6
46055- 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
46063- 0 0 0 10 10 10 26 26 26 66 66 66
46064- 82 82 82 2 2 6 38 38 38 6 6 6
46065- 14 14 14 210 210 210 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 246 246 246 242 242 242
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 253 253 253 253 253 253 253 253 253
46071-253 253 253 253 253 253 253 253 253 253 253 253
46072-253 253 253 253 253 253 144 144 144 2 2 6
46073- 2 2 6 2 2 6 2 2 6 46 46 46
46074- 2 2 6 2 2 6 2 2 6 2 2 6
46075- 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
46083- 6 6 6 14 14 14 42 42 42 90 90 90
46084- 26 26 26 6 6 6 42 42 42 2 2 6
46085- 74 74 74 250 250 250 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 242 242 242 242 242 242
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 253 253 253 253 253 253
46091-253 253 253 253 253 253 253 253 253 253 253 253
46092-253 253 253 253 253 253 182 182 182 2 2 6
46093- 2 2 6 2 2 6 2 2 6 46 46 46
46094- 2 2 6 2 2 6 2 2 6 2 2 6
46095- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0
46103- 10 10 10 26 26 26 66 66 66 82 82 82
46104- 2 2 6 22 22 22 18 18 18 2 2 6
46105-149 149 149 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 234 234 234 242 242 242
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 253 253 253
46111-253 253 253 253 253 253 253 253 253 253 253 253
46112-253 253 253 253 253 253 206 206 206 2 2 6
46113- 2 2 6 2 2 6 2 2 6 38 38 38
46114- 2 2 6 2 2 6 2 2 6 2 2 6
46115- 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 6 6 6
46123- 18 18 18 46 46 46 86 86 86 18 18 18
46124- 2 2 6 34 34 34 10 10 10 6 6 6
46125-210 210 210 253 253 253 253 253 253 253 253 253
46126-253 253 253 253 253 253 253 253 253 253 253 253
46127-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253 253 253 253
46132-253 253 253 253 253 253 221 221 221 6 6 6
46133- 2 2 6 2 2 6 6 6 6 30 30 30
46134- 2 2 6 2 2 6 2 2 6 2 2 6
46135- 2 2 6 82 82 82 54 54 54 18 18 18
46136- 6 6 6 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 0 0 0 0 0 0 10 10 10
46143- 26 26 26 66 66 66 62 62 62 2 2 6
46144- 2 2 6 38 38 38 10 10 10 26 26 26
46145-238 238 238 253 253 253 253 253 253 253 253 253
46146-253 253 253 253 253 253 253 253 253 253 253 253
46147-253 253 253 253 253 253 231 231 231 238 238 238
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 253 253 253 253 253 253
46152-253 253 253 253 253 253 231 231 231 6 6 6
46153- 2 2 6 2 2 6 10 10 10 30 30 30
46154- 2 2 6 2 2 6 2 2 6 2 2 6
46155- 2 2 6 66 66 66 58 58 58 22 22 22
46156- 6 6 6 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 0 0 0 0 0 0 10 10 10
46163- 38 38 38 78 78 78 6 6 6 2 2 6
46164- 2 2 6 46 46 46 14 14 14 42 42 42
46165-246 246 246 253 253 253 253 253 253 253 253 253
46166-253 253 253 253 253 253 253 253 253 253 253 253
46167-253 253 253 253 253 253 231 231 231 242 242 242
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 253 253 253 253 253 253
46172-253 253 253 253 253 253 234 234 234 10 10 10
46173- 2 2 6 2 2 6 22 22 22 14 14 14
46174- 2 2 6 2 2 6 2 2 6 2 2 6
46175- 2 2 6 66 66 66 62 62 62 22 22 22
46176- 6 6 6 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- 0 0 0 0 0 0 6 6 6 18 18 18
46183- 50 50 50 74 74 74 2 2 6 2 2 6
46184- 14 14 14 70 70 70 34 34 34 62 62 62
46185-250 250 250 253 253 253 253 253 253 253 253 253
46186-253 253 253 253 253 253 253 253 253 253 253 253
46187-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
46192-253 253 253 253 253 253 234 234 234 14 14 14
46193- 2 2 6 2 2 6 30 30 30 2 2 6
46194- 2 2 6 2 2 6 2 2 6 2 2 6
46195- 2 2 6 66 66 66 62 62 62 22 22 22
46196- 6 6 6 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- 0 0 0 0 0 0 6 6 6 18 18 18
46203- 54 54 54 62 62 62 2 2 6 2 2 6
46204- 2 2 6 30 30 30 46 46 46 70 70 70
46205-250 250 250 253 253 253 253 253 253 253 253 253
46206-253 253 253 253 253 253 253 253 253 253 253 253
46207-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
46212-253 253 253 253 253 253 226 226 226 10 10 10
46213- 2 2 6 6 6 6 30 30 30 2 2 6
46214- 2 2 6 2 2 6 2 2 6 2 2 6
46215- 2 2 6 66 66 66 58 58 58 22 22 22
46216- 6 6 6 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 0 0 0
46222- 0 0 0 0 0 0 6 6 6 22 22 22
46223- 58 58 58 62 62 62 2 2 6 2 2 6
46224- 2 2 6 2 2 6 30 30 30 78 78 78
46225-250 250 250 253 253 253 253 253 253 253 253 253
46226-253 253 253 253 253 253 253 253 253 253 253 253
46227-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
46232-253 253 253 253 253 253 206 206 206 2 2 6
46233- 22 22 22 34 34 34 18 14 6 22 22 22
46234- 26 26 26 18 18 18 6 6 6 2 2 6
46235- 2 2 6 82 82 82 54 54 54 18 18 18
46236- 6 6 6 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 0 0 0
46242- 0 0 0 0 0 0 6 6 6 26 26 26
46243- 62 62 62 106 106 106 74 54 14 185 133 11
46244-210 162 10 121 92 8 6 6 6 62 62 62
46245-238 238 238 253 253 253 253 253 253 253 253 253
46246-253 253 253 253 253 253 253 253 253 253 253 253
46247-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
46252-253 253 253 253 253 253 158 158 158 18 18 18
46253- 14 14 14 2 2 6 2 2 6 2 2 6
46254- 6 6 6 18 18 18 66 66 66 38 38 38
46255- 6 6 6 94 94 94 50 50 50 18 18 18
46256- 6 6 6 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 6 6 6
46262- 10 10 10 10 10 10 18 18 18 38 38 38
46263- 78 78 78 142 134 106 216 158 10 242 186 14
46264-246 190 14 246 190 14 156 118 10 10 10 10
46265- 90 90 90 238 238 238 253 253 253 253 253 253
46266-253 253 253 253 253 253 253 253 253 253 253 253
46267-253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253 246 230 190
46272-238 204 91 238 204 91 181 142 44 37 26 9
46273- 2 2 6 2 2 6 2 2 6 2 2 6
46274- 2 2 6 2 2 6 38 38 38 46 46 46
46275- 26 26 26 106 106 106 54 54 54 18 18 18
46276- 6 6 6 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 6 6 6 14 14 14 22 22 22
46282- 30 30 30 38 38 38 50 50 50 70 70 70
46283-106 106 106 190 142 34 226 170 11 242 186 14
46284-246 190 14 246 190 14 246 190 14 154 114 10
46285- 6 6 6 74 74 74 226 226 226 253 253 253
46286-253 253 253 253 253 253 253 253 253 253 253 253
46287-253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253 228 184 62
46292-241 196 14 241 208 19 232 195 16 38 30 10
46293- 2 2 6 2 2 6 2 2 6 2 2 6
46294- 2 2 6 6 6 6 30 30 30 26 26 26
46295-203 166 17 154 142 90 66 66 66 26 26 26
46296- 6 6 6 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- 6 6 6 18 18 18 38 38 38 58 58 58
46302- 78 78 78 86 86 86 101 101 101 123 123 123
46303-175 146 61 210 150 10 234 174 13 246 186 14
46304-246 190 14 246 190 14 246 190 14 238 190 10
46305-102 78 10 2 2 6 46 46 46 198 198 198
46306-253 253 253 253 253 253 253 253 253 253 253 253
46307-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 224 178 62
46312-242 186 14 241 196 14 210 166 10 22 18 6
46313- 2 2 6 2 2 6 2 2 6 2 2 6
46314- 2 2 6 2 2 6 6 6 6 121 92 8
46315-238 202 15 232 195 16 82 82 82 34 34 34
46316- 10 10 10 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- 14 14 14 38 38 38 70 70 70 154 122 46
46322-190 142 34 200 144 11 197 138 11 197 138 11
46323-213 154 11 226 170 11 242 186 14 246 190 14
46324-246 190 14 246 190 14 246 190 14 246 190 14
46325-225 175 15 46 32 6 2 2 6 22 22 22
46326-158 158 158 250 250 250 253 253 253 253 253 253
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 250 250 250 242 242 242 224 178 62
46332-239 182 13 236 186 11 213 154 11 46 32 6
46333- 2 2 6 2 2 6 2 2 6 2 2 6
46334- 2 2 6 2 2 6 61 42 6 225 175 15
46335-238 190 10 236 186 11 112 100 78 42 42 42
46336- 14 14 14 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 6 6 6
46341- 22 22 22 54 54 54 154 122 46 213 154 11
46342-226 170 11 230 174 11 226 170 11 226 170 11
46343-236 178 12 242 186 14 246 190 14 246 190 14
46344-246 190 14 246 190 14 246 190 14 246 190 14
46345-241 196 14 184 144 12 10 10 10 2 2 6
46346- 6 6 6 116 116 116 242 242 242 253 253 253
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 231 231 231 198 198 198 214 170 54
46352-236 178 12 236 178 12 210 150 10 137 92 6
46353- 18 14 6 2 2 6 2 2 6 2 2 6
46354- 6 6 6 70 47 6 200 144 11 236 178 12
46355-239 182 13 239 182 13 124 112 88 58 58 58
46356- 22 22 22 6 6 6 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 10 10 10
46361- 30 30 30 70 70 70 180 133 36 226 170 11
46362-239 182 13 242 186 14 242 186 14 246 186 14
46363-246 190 14 246 190 14 246 190 14 246 190 14
46364-246 190 14 246 190 14 246 190 14 246 190 14
46365-246 190 14 232 195 16 98 70 6 2 2 6
46366- 2 2 6 2 2 6 66 66 66 221 221 221
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 253 253 253
46371-253 253 253 206 206 206 198 198 198 214 166 58
46372-230 174 11 230 174 11 216 158 10 192 133 9
46373-163 110 8 116 81 8 102 78 10 116 81 8
46374-167 114 7 197 138 11 226 170 11 239 182 13
46375-242 186 14 242 186 14 162 146 94 78 78 78
46376- 34 34 34 14 14 14 6 6 6 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 0 0 0 0 0 0 6 6 6
46381- 30 30 30 78 78 78 190 142 34 226 170 11
46382-239 182 13 246 190 14 246 190 14 246 190 14
46383-246 190 14 246 190 14 246 190 14 246 190 14
46384-246 190 14 246 190 14 246 190 14 246 190 14
46385-246 190 14 241 196 14 203 166 17 22 18 6
46386- 2 2 6 2 2 6 2 2 6 38 38 38
46387-218 218 218 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 253 253 253
46391-250 250 250 206 206 206 198 198 198 202 162 69
46392-226 170 11 236 178 12 224 166 10 210 150 10
46393-200 144 11 197 138 11 192 133 9 197 138 11
46394-210 150 10 226 170 11 242 186 14 246 190 14
46395-246 190 14 246 186 14 225 175 15 124 112 88
46396- 62 62 62 30 30 30 14 14 14 6 6 6
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- 0 0 0 0 0 0 0 0 0 10 10 10
46401- 30 30 30 78 78 78 174 135 50 224 166 10
46402-239 182 13 246 190 14 246 190 14 246 190 14
46403-246 190 14 246 190 14 246 190 14 246 190 14
46404-246 190 14 246 190 14 246 190 14 246 190 14
46405-246 190 14 246 190 14 241 196 14 139 102 15
46406- 2 2 6 2 2 6 2 2 6 2 2 6
46407- 78 78 78 250 250 250 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 253 253 253
46411-250 250 250 214 214 214 198 198 198 190 150 46
46412-219 162 10 236 178 12 234 174 13 224 166 10
46413-216 158 10 213 154 11 213 154 11 216 158 10
46414-226 170 11 239 182 13 246 190 14 246 190 14
46415-246 190 14 246 190 14 242 186 14 206 162 42
46416-101 101 101 58 58 58 30 30 30 14 14 14
46417- 6 6 6 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- 0 0 0 0 0 0 0 0 0 10 10 10
46421- 30 30 30 74 74 74 174 135 50 216 158 10
46422-236 178 12 246 190 14 246 190 14 246 190 14
46423-246 190 14 246 190 14 246 190 14 246 190 14
46424-246 190 14 246 190 14 246 190 14 246 190 14
46425-246 190 14 246 190 14 241 196 14 226 184 13
46426- 61 42 6 2 2 6 2 2 6 2 2 6
46427- 22 22 22 238 238 238 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 253 253 253 253 253 253 253 253 253
46431-253 253 253 226 226 226 187 187 187 180 133 36
46432-216 158 10 236 178 12 239 182 13 236 178 12
46433-230 174 11 226 170 11 226 170 11 230 174 11
46434-236 178 12 242 186 14 246 190 14 246 190 14
46435-246 190 14 246 190 14 246 186 14 239 182 13
46436-206 162 42 106 106 106 66 66 66 34 34 34
46437- 14 14 14 6 6 6 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 0 0 0
46440- 0 0 0 0 0 0 0 0 0 6 6 6
46441- 26 26 26 70 70 70 163 133 67 213 154 11
46442-236 178 12 246 190 14 246 190 14 246 190 14
46443-246 190 14 246 190 14 246 190 14 246 190 14
46444-246 190 14 246 190 14 246 190 14 246 190 14
46445-246 190 14 246 190 14 246 190 14 241 196 14
46446-190 146 13 18 14 6 2 2 6 2 2 6
46447- 46 46 46 246 246 246 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 253 253 253 253 253 253 253 253 253
46451-253 253 253 221 221 221 86 86 86 156 107 11
46452-216 158 10 236 178 12 242 186 14 246 186 14
46453-242 186 14 239 182 13 239 182 13 242 186 14
46454-242 186 14 246 186 14 246 190 14 246 190 14
46455-246 190 14 246 190 14 246 190 14 246 190 14
46456-242 186 14 225 175 15 142 122 72 66 66 66
46457- 30 30 30 10 10 10 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 0 0 0
46460- 0 0 0 0 0 0 0 0 0 6 6 6
46461- 26 26 26 70 70 70 163 133 67 210 150 10
46462-236 178 12 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 246 190 14 246 190 14 246 190 14
46465-246 190 14 246 190 14 246 190 14 246 190 14
46466-232 195 16 121 92 8 34 34 34 106 106 106
46467-221 221 221 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 253 253 253 253 253 253 253 253 253
46471-242 242 242 82 82 82 18 14 6 163 110 8
46472-216 158 10 236 178 12 242 186 14 246 190 14
46473-246 190 14 246 190 14 246 190 14 246 190 14
46474-246 190 14 246 190 14 246 190 14 246 190 14
46475-246 190 14 246 190 14 246 190 14 246 190 14
46476-246 190 14 246 190 14 242 186 14 163 133 67
46477- 46 46 46 18 18 18 6 6 6 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 0 0 0
46480- 0 0 0 0 0 0 0 0 0 10 10 10
46481- 30 30 30 78 78 78 163 133 67 210 150 10
46482-236 178 12 246 186 14 246 190 14 246 190 14
46483-246 190 14 246 190 14 246 190 14 246 190 14
46484-246 190 14 246 190 14 246 190 14 246 190 14
46485-246 190 14 246 190 14 246 190 14 246 190 14
46486-241 196 14 215 174 15 190 178 144 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-253 253 253 253 253 253 253 253 253 218 218 218
46491- 58 58 58 2 2 6 22 18 6 167 114 7
46492-216 158 10 236 178 12 246 186 14 246 190 14
46493-246 190 14 246 190 14 246 190 14 246 190 14
46494-246 190 14 246 190 14 246 190 14 246 190 14
46495-246 190 14 246 190 14 246 190 14 246 190 14
46496-246 190 14 246 186 14 242 186 14 190 150 46
46497- 54 54 54 22 22 22 6 6 6 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 0 0 0
46500- 0 0 0 0 0 0 0 0 0 14 14 14
46501- 38 38 38 86 86 86 180 133 36 213 154 11
46502-236 178 12 246 186 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 246 190 14 246 190 14
46505-246 190 14 246 190 14 246 190 14 246 190 14
46506-246 190 14 232 195 16 190 146 13 214 214 214
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-253 253 253 250 250 250 170 170 170 26 26 26
46511- 2 2 6 2 2 6 37 26 9 163 110 8
46512-219 162 10 239 182 13 246 186 14 246 190 14
46513-246 190 14 246 190 14 246 190 14 246 190 14
46514-246 190 14 246 190 14 246 190 14 246 190 14
46515-246 190 14 246 190 14 246 190 14 246 190 14
46516-246 186 14 236 178 12 224 166 10 142 122 72
46517- 46 46 46 18 18 18 6 6 6 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 0 0 0
46520- 0 0 0 0 0 0 6 6 6 18 18 18
46521- 50 50 50 109 106 95 192 133 9 224 166 10
46522-242 186 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 246 190 14 246 190 14
46525-246 190 14 246 190 14 246 190 14 246 190 14
46526-242 186 14 226 184 13 210 162 10 142 110 46
46527-226 226 226 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-198 198 198 66 66 66 2 2 6 2 2 6
46531- 2 2 6 2 2 6 50 34 6 156 107 11
46532-219 162 10 239 182 13 246 186 14 246 190 14
46533-246 190 14 246 190 14 246 190 14 246 190 14
46534-246 190 14 246 190 14 246 190 14 246 190 14
46535-246 190 14 246 190 14 246 190 14 242 186 14
46536-234 174 13 213 154 11 154 122 46 66 66 66
46537- 30 30 30 10 10 10 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 0 0 0
46540- 0 0 0 0 0 0 6 6 6 22 22 22
46541- 58 58 58 154 121 60 206 145 10 234 174 13
46542-242 186 14 246 186 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 246 190 14
46545-246 190 14 246 190 14 246 190 14 246 190 14
46546-246 186 14 236 178 12 210 162 10 163 110 8
46547- 61 42 6 138 138 138 218 218 218 250 250 250
46548-253 253 253 253 253 253 253 253 253 250 250 250
46549-242 242 242 210 210 210 144 144 144 66 66 66
46550- 6 6 6 2 2 6 2 2 6 2 2 6
46551- 2 2 6 2 2 6 61 42 6 163 110 8
46552-216 158 10 236 178 12 246 190 14 246 190 14
46553-246 190 14 246 190 14 246 190 14 246 190 14
46554-246 190 14 246 190 14 246 190 14 246 190 14
46555-246 190 14 239 182 13 230 174 11 216 158 10
46556-190 142 34 124 112 88 70 70 70 38 38 38
46557- 18 18 18 6 6 6 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 0 0 0
46560- 0 0 0 0 0 0 6 6 6 22 22 22
46561- 62 62 62 168 124 44 206 145 10 224 166 10
46562-236 178 12 239 182 13 242 186 14 242 186 14
46563-246 186 14 246 190 14 246 190 14 246 190 14
46564-246 190 14 246 190 14 246 190 14 246 190 14
46565-246 190 14 246 190 14 246 190 14 246 190 14
46566-246 190 14 236 178 12 216 158 10 175 118 6
46567- 80 54 7 2 2 6 6 6 6 30 30 30
46568- 54 54 54 62 62 62 50 50 50 38 38 38
46569- 14 14 14 2 2 6 2 2 6 2 2 6
46570- 2 2 6 2 2 6 2 2 6 2 2 6
46571- 2 2 6 6 6 6 80 54 7 167 114 7
46572-213 154 11 236 178 12 246 190 14 246 190 14
46573-246 190 14 246 190 14 246 190 14 246 190 14
46574-246 190 14 242 186 14 239 182 13 239 182 13
46575-230 174 11 210 150 10 174 135 50 124 112 88
46576- 82 82 82 54 54 54 34 34 34 18 18 18
46577- 6 6 6 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 0 0 0
46580- 0 0 0 0 0 0 6 6 6 18 18 18
46581- 50 50 50 158 118 36 192 133 9 200 144 11
46582-216 158 10 219 162 10 224 166 10 226 170 11
46583-230 174 11 236 178 12 239 182 13 239 182 13
46584-242 186 14 246 186 14 246 190 14 246 190 14
46585-246 190 14 246 190 14 246 190 14 246 190 14
46586-246 186 14 230 174 11 210 150 10 163 110 8
46587-104 69 6 10 10 10 2 2 6 2 2 6
46588- 2 2 6 2 2 6 2 2 6 2 2 6
46589- 2 2 6 2 2 6 2 2 6 2 2 6
46590- 2 2 6 2 2 6 2 2 6 2 2 6
46591- 2 2 6 6 6 6 91 60 6 167 114 7
46592-206 145 10 230 174 11 242 186 14 246 190 14
46593-246 190 14 246 190 14 246 186 14 242 186 14
46594-239 182 13 230 174 11 224 166 10 213 154 11
46595-180 133 36 124 112 88 86 86 86 58 58 58
46596- 38 38 38 22 22 22 10 10 10 6 6 6
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 0 0 0
46600- 0 0 0 0 0 0 0 0 0 14 14 14
46601- 34 34 34 70 70 70 138 110 50 158 118 36
46602-167 114 7 180 123 7 192 133 9 197 138 11
46603-200 144 11 206 145 10 213 154 11 219 162 10
46604-224 166 10 230 174 11 239 182 13 242 186 14
46605-246 186 14 246 186 14 246 186 14 246 186 14
46606-239 182 13 216 158 10 185 133 11 152 99 6
46607-104 69 6 18 14 6 2 2 6 2 2 6
46608- 2 2 6 2 2 6 2 2 6 2 2 6
46609- 2 2 6 2 2 6 2 2 6 2 2 6
46610- 2 2 6 2 2 6 2 2 6 2 2 6
46611- 2 2 6 6 6 6 80 54 7 152 99 6
46612-192 133 9 219 162 10 236 178 12 239 182 13
46613-246 186 14 242 186 14 239 182 13 236 178 12
46614-224 166 10 206 145 10 192 133 9 154 121 60
46615- 94 94 94 62 62 62 42 42 42 22 22 22
46616- 14 14 14 6 6 6 0 0 0 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 0 0 0 0 0 0
46620- 0 0 0 0 0 0 0 0 0 6 6 6
46621- 18 18 18 34 34 34 58 58 58 78 78 78
46622-101 98 89 124 112 88 142 110 46 156 107 11
46623-163 110 8 167 114 7 175 118 6 180 123 7
46624-185 133 11 197 138 11 210 150 10 219 162 10
46625-226 170 11 236 178 12 236 178 12 234 174 13
46626-219 162 10 197 138 11 163 110 8 130 83 6
46627- 91 60 6 10 10 10 2 2 6 2 2 6
46628- 18 18 18 38 38 38 38 38 38 38 38 38
46629- 38 38 38 38 38 38 38 38 38 38 38 38
46630- 38 38 38 38 38 38 26 26 26 2 2 6
46631- 2 2 6 6 6 6 70 47 6 137 92 6
46632-175 118 6 200 144 11 219 162 10 230 174 11
46633-234 174 13 230 174 11 219 162 10 210 150 10
46634-192 133 9 163 110 8 124 112 88 82 82 82
46635- 50 50 50 30 30 30 14 14 14 6 6 6
46636- 0 0 0 0 0 0 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 0 0 0 0 0 0
46640- 0 0 0 0 0 0 0 0 0 0 0 0
46641- 6 6 6 14 14 14 22 22 22 34 34 34
46642- 42 42 42 58 58 58 74 74 74 86 86 86
46643-101 98 89 122 102 70 130 98 46 121 87 25
46644-137 92 6 152 99 6 163 110 8 180 123 7
46645-185 133 11 197 138 11 206 145 10 200 144 11
46646-180 123 7 156 107 11 130 83 6 104 69 6
46647- 50 34 6 54 54 54 110 110 110 101 98 89
46648- 86 86 86 82 82 82 78 78 78 78 78 78
46649- 78 78 78 78 78 78 78 78 78 78 78 78
46650- 78 78 78 82 82 82 86 86 86 94 94 94
46651-106 106 106 101 101 101 86 66 34 124 80 6
46652-156 107 11 180 123 7 192 133 9 200 144 11
46653-206 145 10 200 144 11 192 133 9 175 118 6
46654-139 102 15 109 106 95 70 70 70 42 42 42
46655- 22 22 22 10 10 10 0 0 0 0 0 0
46656- 0 0 0 0 0 0 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 0 0 0 0 0 0
46660- 0 0 0 0 0 0 0 0 0 0 0 0
46661- 0 0 0 0 0 0 6 6 6 10 10 10
46662- 14 14 14 22 22 22 30 30 30 38 38 38
46663- 50 50 50 62 62 62 74 74 74 90 90 90
46664-101 98 89 112 100 78 121 87 25 124 80 6
46665-137 92 6 152 99 6 152 99 6 152 99 6
46666-138 86 6 124 80 6 98 70 6 86 66 30
46667-101 98 89 82 82 82 58 58 58 46 46 46
46668- 38 38 38 34 34 34 34 34 34 34 34 34
46669- 34 34 34 34 34 34 34 34 34 34 34 34
46670- 34 34 34 34 34 34 38 38 38 42 42 42
46671- 54 54 54 82 82 82 94 86 76 91 60 6
46672-134 86 6 156 107 11 167 114 7 175 118 6
46673-175 118 6 167 114 7 152 99 6 121 87 25
46674-101 98 89 62 62 62 34 34 34 18 18 18
46675- 6 6 6 0 0 0 0 0 0 0 0 0
46676- 0 0 0 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 0 0 0 0 0 0
46680- 0 0 0 0 0 0 0 0 0 0 0 0
46681- 0 0 0 0 0 0 0 0 0 0 0 0
46682- 0 0 0 6 6 6 6 6 6 10 10 10
46683- 18 18 18 22 22 22 30 30 30 42 42 42
46684- 50 50 50 66 66 66 86 86 86 101 98 89
46685-106 86 58 98 70 6 104 69 6 104 69 6
46686-104 69 6 91 60 6 82 62 34 90 90 90
46687- 62 62 62 38 38 38 22 22 22 14 14 14
46688- 10 10 10 10 10 10 10 10 10 10 10 10
46689- 10 10 10 10 10 10 6 6 6 10 10 10
46690- 10 10 10 10 10 10 10 10 10 14 14 14
46691- 22 22 22 42 42 42 70 70 70 89 81 66
46692- 80 54 7 104 69 6 124 80 6 137 92 6
46693-134 86 6 116 81 8 100 82 52 86 86 86
46694- 58 58 58 30 30 30 14 14 14 6 6 6
46695- 0 0 0 0 0 0 0 0 0 0 0 0
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 0 0 0
46700- 0 0 0 0 0 0 0 0 0 0 0 0
46701- 0 0 0 0 0 0 0 0 0 0 0 0
46702- 0 0 0 0 0 0 0 0 0 0 0 0
46703- 0 0 0 6 6 6 10 10 10 14 14 14
46704- 18 18 18 26 26 26 38 38 38 54 54 54
46705- 70 70 70 86 86 86 94 86 76 89 81 66
46706- 89 81 66 86 86 86 74 74 74 50 50 50
46707- 30 30 30 14 14 14 6 6 6 0 0 0
46708- 0 0 0 0 0 0 0 0 0 0 0 0
46709- 0 0 0 0 0 0 0 0 0 0 0 0
46710- 0 0 0 0 0 0 0 0 0 0 0 0
46711- 6 6 6 18 18 18 34 34 34 58 58 58
46712- 82 82 82 89 81 66 89 81 66 89 81 66
46713- 94 86 66 94 86 76 74 74 74 50 50 50
46714- 26 26 26 14 14 14 6 6 6 0 0 0
46715- 0 0 0 0 0 0 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 0 0 0
46720- 0 0 0 0 0 0 0 0 0 0 0 0
46721- 0 0 0 0 0 0 0 0 0 0 0 0
46722- 0 0 0 0 0 0 0 0 0 0 0 0
46723- 0 0 0 0 0 0 0 0 0 0 0 0
46724- 6 6 6 6 6 6 14 14 14 18 18 18
46725- 30 30 30 38 38 38 46 46 46 54 54 54
46726- 50 50 50 42 42 42 30 30 30 18 18 18
46727- 10 10 10 0 0 0 0 0 0 0 0 0
46728- 0 0 0 0 0 0 0 0 0 0 0 0
46729- 0 0 0 0 0 0 0 0 0 0 0 0
46730- 0 0 0 0 0 0 0 0 0 0 0 0
46731- 0 0 0 6 6 6 14 14 14 26 26 26
46732- 38 38 38 50 50 50 58 58 58 58 58 58
46733- 54 54 54 42 42 42 30 30 30 18 18 18
46734- 10 10 10 0 0 0 0 0 0 0 0 0
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- 0 0 0 0 0 0 0 0 0 0 0 0
46741- 0 0 0 0 0 0 0 0 0 0 0 0
46742- 0 0 0 0 0 0 0 0 0 0 0 0
46743- 0 0 0 0 0 0 0 0 0 0 0 0
46744- 0 0 0 0 0 0 0 0 0 6 6 6
46745- 6 6 6 10 10 10 14 14 14 18 18 18
46746- 18 18 18 14 14 14 10 10 10 6 6 6
46747- 0 0 0 0 0 0 0 0 0 0 0 0
46748- 0 0 0 0 0 0 0 0 0 0 0 0
46749- 0 0 0 0 0 0 0 0 0 0 0 0
46750- 0 0 0 0 0 0 0 0 0 0 0 0
46751- 0 0 0 0 0 0 0 0 0 6 6 6
46752- 14 14 14 18 18 18 22 22 22 22 22 22
46753- 18 18 18 14 14 14 10 10 10 6 6 6
46754- 0 0 0 0 0 0 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46772+4 4 4 4 4 4
46773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46786+4 4 4 4 4 4
46787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46800+4 4 4 4 4 4
46801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46814+4 4 4 4 4 4
46815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46828+4 4 4 4 4 4
46829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46831+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46842+4 4 4 4 4 4
46843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46845+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46847+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46848+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46852+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46853+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46854+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46856+4 4 4 4 4 4
46857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46859+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46861+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46862+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46863+5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
46867+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46868+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46869+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46870+4 4 4 4 4 4
46871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46873+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46875+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46876+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46877+0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
46881+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46882+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46883+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46884+4 4 4 4 4 4
46885+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46886+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46887+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46888+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46889+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46890+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46891+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
46894+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46895+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46896+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46897+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46898+4 4 4 4 4 4
46899+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46900+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46901+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46902+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46903+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46904+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46905+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46906+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46907+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46908+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46909+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46910+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46911+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46912+4 4 4 4 4 4
46913+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46914+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46915+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46916+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46917+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46918+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46919+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46920+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46921+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46922+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46923+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46924+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46925+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46926+4 4 4 4 4 4
46927+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46928+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46929+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
46930+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46931+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46932+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46933+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46934+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46935+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46936+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46937+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46938+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46939+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46940+4 4 4 4 4 4
46941+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46942+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46943+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
46944+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46945+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46946+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46947+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46948+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46949+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46950+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46951+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46952+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46953+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46954+4 4 4 4 4 4
46955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46956+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46957+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46958+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46959+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46960+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46961+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46962+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46963+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46964+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46965+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46966+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46967+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46968+4 4 4 4 4 4
46969+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46970+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46971+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46972+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46973+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46974+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46975+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46976+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46977+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46978+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46979+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46980+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46981+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46982+4 4 4 4 4 4
46983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46984+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
46985+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46986+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46987+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46988+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46989+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46990+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46991+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46992+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46993+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46994+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46995+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46996+4 4 4 4 4 4
46997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46998+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46999+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
47000+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
47001+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47002+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
47003+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
47004+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
47005+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
47006+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
47007+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
47008+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
47009+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
47010+0 0 0 4 4 4
47011+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
47012+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
47013+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
47014+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
47015+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
47016+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
47017+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
47018+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
47019+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
47020+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
47021+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
47022+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
47023+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
47024+2 0 0 0 0 0
47025+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
47026+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
47027+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
47028+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
47029+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
47030+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
47031+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
47032+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
47033+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
47034+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
47035+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
47036+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
47037+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
47038+37 38 37 0 0 0
47039+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47040+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
47041+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
47042+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
47043+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
47044+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
47045+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
47046+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
47047+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
47048+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
47049+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
47050+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
47051+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
47052+85 115 134 4 0 0
47053+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
47054+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
47055+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
47056+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
47057+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
47058+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
47059+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
47060+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
47061+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
47062+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
47063+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
47064+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
47065+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
47066+60 73 81 4 0 0
47067+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
47068+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
47069+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
47070+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
47071+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
47072+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
47073+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
47074+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
47075+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
47076+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
47077+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
47078+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
47079+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
47080+16 19 21 4 0 0
47081+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
47082+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
47083+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
47084+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
47085+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
47086+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
47087+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
47088+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
47089+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
47090+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
47091+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
47092+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
47093+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
47094+4 0 0 4 3 3
47095+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
47096+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
47097+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
47098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
47099+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
47100+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
47101+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
47102+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
47103+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
47104+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
47105+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
47106+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
47107+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
47108+3 2 2 4 4 4
47109+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
47110+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
47111+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
47112+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
47113+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
47114+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
47115+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
47116+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
47117+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
47118+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
47119+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
47120+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
47121+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
47122+4 4 4 4 4 4
47123+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
47124+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
47125+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
47126+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
47127+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
47128+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
47129+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
47130+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
47131+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
47132+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
47133+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
47134+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
47135+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
47136+4 4 4 4 4 4
47137+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
47138+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
47139+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
47140+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
47141+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
47142+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47143+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47144+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47145+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47146+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47147+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47148+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47149+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47150+5 5 5 5 5 5
47151+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47152+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47153+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47154+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47155+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47156+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47157+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47158+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47159+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47160+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47161+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47162+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47163+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47164+5 5 5 4 4 4
47165+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47166+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47167+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47168+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47169+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47170+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47171+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47172+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47173+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47174+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47175+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47176+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47178+4 4 4 4 4 4
47179+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47180+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47181+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47182+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47183+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47184+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47185+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47186+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47187+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47188+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47189+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47190+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47192+4 4 4 4 4 4
47193+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47194+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47195+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47196+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47197+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47198+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47199+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47200+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47201+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47202+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47203+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47204+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47206+4 4 4 4 4 4
47207+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47208+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47209+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47210+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47211+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47212+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47213+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47214+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47215+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47216+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47217+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47218+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47220+4 4 4 4 4 4
47221+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47222+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47223+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47224+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47225+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47226+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47227+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47228+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47229+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47230+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47231+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47232+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47234+4 4 4 4 4 4
47235+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47236+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47237+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47238+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47239+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47240+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47241+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47242+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47243+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47244+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47245+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47246+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47248+4 4 4 4 4 4
47249+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47250+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47251+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47252+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47253+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47254+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47255+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47256+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47257+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47258+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47259+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47260+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47262+4 4 4 4 4 4
47263+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47264+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47265+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47266+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47267+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47268+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47269+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47270+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47271+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47272+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47273+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47274+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47276+4 4 4 4 4 4
47277+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47278+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47279+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47280+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47281+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47282+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47283+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47284+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47285+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47286+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47287+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47290+4 4 4 4 4 4
47291+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47292+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47293+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47294+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47295+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47296+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47297+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47298+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47299+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47300+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47301+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47304+4 4 4 4 4 4
47305+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47306+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47307+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47308+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47309+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47310+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47311+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47312+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47313+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47314+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47315+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47318+4 4 4 4 4 4
47319+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47320+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47321+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47322+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47323+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47324+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47325+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47326+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47327+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47328+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47329+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47332+4 4 4 4 4 4
47333+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47334+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47335+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47336+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47337+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47338+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47339+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47340+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47341+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47342+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47343+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47346+4 4 4 4 4 4
47347+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47348+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47349+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47350+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47351+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47352+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47353+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47354+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47355+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47356+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47357+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47358+4 4 4 4 4 4 4 4 4 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
47361+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47362+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47363+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47364+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47365+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47366+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47367+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47368+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47369+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47370+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47371+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47372+4 4 4 4 4 4 4 4 4 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
47375+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47376+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47377+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47378+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47379+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47380+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47381+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47382+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47383+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47384+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47385+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47386+4 4 4 4 4 4 4 4 4 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
47389+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47390+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47391+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47392+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47393+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47394+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47395+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47396+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47397+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47398+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47399+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47400+4 4 4 4 4 4 4 4 4 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
47403+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47404+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47405+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47406+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47407+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47408+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47409+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47410+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47411+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47412+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47413+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47414+4 4 4 4 4 4 4 4 4 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
47417+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47418+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47419+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47420+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47421+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47422+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47423+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47424+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47425+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47426+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47427+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47428+4 4 4 4 4 4 4 4 4 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
47431+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47432+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47433+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47434+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47435+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47436+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47437+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47438+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47439+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47440+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47441+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47442+4 4 4 4 4 4 4 4 4 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
47445+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47446+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47447+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47448+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47449+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47450+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47451+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47452+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47453+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47454+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47455+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47456+4 4 4 4 4 4 4 4 4 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
47459+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47460+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47461+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47462+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47463+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47464+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47465+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47466+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47467+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47468+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47469+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47470+4 4 4 4 4 4 4 4 4 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
47473+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47474+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47475+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47476+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47477+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47478+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47479+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47480+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47481+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47482+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47483+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47484+4 4 4 4 4 4 4 4 4 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
47487+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47488+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47489+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47490+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47491+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47492+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47493+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47494+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47495+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47496+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47497+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47498+4 4 4 4 4 4 4 4 4 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
47501+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47502+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47503+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47504+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47505+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47506+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47507+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47508+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47509+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47510+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47511+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47512+4 4 4 4 4 4 4 4 4 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
47515+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47516+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47517+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47518+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47519+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47520+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47521+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47522+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47523+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47524+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47525+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47526+4 4 4 4 4 4 4 4 4 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
47529+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47530+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47531+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47532+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47533+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47534+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47535+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47536+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47537+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47538+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47539+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47540+4 4 4 4 4 4 4 4 4 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
47543+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47544+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47545+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47546+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47547+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47548+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47549+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47550+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47551+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47552+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47553+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47554+4 4 4 4 4 4 4 4 4 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
47557+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47558+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47559+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47560+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47561+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47562+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47563+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47564+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47565+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47566+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47567+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47568+4 4 4 4 4 4 4 4 4 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
47571+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47572+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47573+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47574+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47575+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47576+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47577+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47578+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47579+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47580+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47582+4 4 4 4 4 4 4 4 4 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
47585+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47586+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47587+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47588+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47589+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47590+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47591+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47592+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47593+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47594+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47596+4 4 4 4 4 4 4 4 4 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
47599+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47600+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47601+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47602+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47603+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47604+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47605+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47606+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47607+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47608+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47610+4 4 4 4 4 4 4 4 4 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
47613+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47614+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47615+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47616+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47617+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47618+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47619+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47620+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47621+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47622+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47624+4 4 4 4 4 4 4 4 4 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
47627+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47628+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47629+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47630+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47631+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47632+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47633+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47634+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47635+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47638+4 4 4 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
47641+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47642+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47643+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47644+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47645+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47646+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47647+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47648+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47649+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47652+4 4 4 4 4 4 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
47655+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47656+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47657+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47658+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47659+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47660+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47661+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47662+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47663+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47666+4 4 4 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
47669+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47670+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47671+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47672+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47673+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47674+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47675+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47676+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
47683+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47684+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47685+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47686+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47687+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47688+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47689+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47690+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47693+4 4 4 4 4 4 4 4 4 4 4 4 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
47697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47698+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47699+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47700+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47701+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47702+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47703+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47704+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47707+4 4 4 4 4 4 4 4 4 4 4 4 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
47711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47712+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47713+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47714+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47715+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47716+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47717+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47718+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47721+4 4 4 4 4 4 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
47725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47726+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47727+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47728+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47729+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47730+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47731+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47732+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
47739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47741+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47742+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47743+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47744+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47745+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47746+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47748+4 4 4 4 4 4 4 4 4 4 4 4 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
47753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47756+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47757+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47758+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47759+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47762+4 4 4 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
47767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47770+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47771+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47772+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47773+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
47781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47784+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47785+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47786+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47787+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47789+4 4 4 4 4 4 4 4 4 4 4 4 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
47795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47798+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47799+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47800+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47801+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47803+4 4 4 4 4 4 4 4 4 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
47809+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47813+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47814+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47815+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47817+4 4 4 4 4 4 4 4 4 4 4 4 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
47823+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
47826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47827+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47828+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47829+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47831+4 4 4 4 4 4 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
47837+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47841+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47842+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47843+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47845+4 4 4 4 4 4 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
47851+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
47855+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47856+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47857+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47858+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
47865+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47870+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47871+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47872+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
47879diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47880index fe92eed..106e085 100644
47881--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47882+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47883@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47884 struct mb862xxfb_par *par = info->par;
47885
47886 if (info->var.bits_per_pixel == 32) {
47887- info->fbops->fb_fillrect = cfb_fillrect;
47888- info->fbops->fb_copyarea = cfb_copyarea;
47889- info->fbops->fb_imageblit = cfb_imageblit;
47890+ pax_open_kernel();
47891+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47892+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47893+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47894+ pax_close_kernel();
47895 } else {
47896 outreg(disp, GC_L0EM, 3);
47897- info->fbops->fb_fillrect = mb86290fb_fillrect;
47898- info->fbops->fb_copyarea = mb86290fb_copyarea;
47899- info->fbops->fb_imageblit = mb86290fb_imageblit;
47900+ pax_open_kernel();
47901+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47902+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47903+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47904+ pax_close_kernel();
47905 }
47906 outreg(draw, GDC_REG_DRAW_BASE, 0);
47907 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47908diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47909index ff22871..b129bed 100644
47910--- a/drivers/video/nvidia/nvidia.c
47911+++ b/drivers/video/nvidia/nvidia.c
47912@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47913 info->fix.line_length = (info->var.xres_virtual *
47914 info->var.bits_per_pixel) >> 3;
47915 if (info->var.accel_flags) {
47916- info->fbops->fb_imageblit = nvidiafb_imageblit;
47917- info->fbops->fb_fillrect = nvidiafb_fillrect;
47918- info->fbops->fb_copyarea = nvidiafb_copyarea;
47919- info->fbops->fb_sync = nvidiafb_sync;
47920+ pax_open_kernel();
47921+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47922+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47923+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47924+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47925+ pax_close_kernel();
47926 info->pixmap.scan_align = 4;
47927 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47928 info->flags |= FBINFO_READS_FAST;
47929 NVResetGraphics(info);
47930 } else {
47931- info->fbops->fb_imageblit = cfb_imageblit;
47932- info->fbops->fb_fillrect = cfb_fillrect;
47933- info->fbops->fb_copyarea = cfb_copyarea;
47934- info->fbops->fb_sync = NULL;
47935+ pax_open_kernel();
47936+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47937+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47938+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47939+ *(void **)&info->fbops->fb_sync = NULL;
47940+ pax_close_kernel();
47941 info->pixmap.scan_align = 1;
47942 info->flags |= FBINFO_HWACCEL_DISABLED;
47943 info->flags &= ~FBINFO_READS_FAST;
47944@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47945 info->pixmap.size = 8 * 1024;
47946 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47947
47948- if (!hwcur)
47949- info->fbops->fb_cursor = NULL;
47950+ if (!hwcur) {
47951+ pax_open_kernel();
47952+ *(void **)&info->fbops->fb_cursor = NULL;
47953+ pax_close_kernel();
47954+ }
47955
47956 info->var.accel_flags = (!noaccel);
47957
47958diff --git a/drivers/video/output.c b/drivers/video/output.c
47959index 0d6f2cd..6285b97 100644
47960--- a/drivers/video/output.c
47961+++ b/drivers/video/output.c
47962@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
47963 new_dev->props = op;
47964 new_dev->dev.class = &video_output_class;
47965 new_dev->dev.parent = dev;
47966- dev_set_name(&new_dev->dev, name);
47967+ dev_set_name(&new_dev->dev, "%s", name);
47968 dev_set_drvdata(&new_dev->dev, devdata);
47969 ret_code = device_register(&new_dev->dev);
47970 if (ret_code) {
47971diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47972index 05c2dc3..ea1f391 100644
47973--- a/drivers/video/s1d13xxxfb.c
47974+++ b/drivers/video/s1d13xxxfb.c
47975@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47976
47977 switch(prod_id) {
47978 case S1D13506_PROD_ID: /* activate acceleration */
47979- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47980- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47981+ pax_open_kernel();
47982+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47983+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47984+ pax_close_kernel();
47985 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47986 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47987 break;
47988diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47989index b2b33fc..f9f4658 100644
47990--- a/drivers/video/smscufx.c
47991+++ b/drivers/video/smscufx.c
47992@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47993 fb_deferred_io_cleanup(info);
47994 kfree(info->fbdefio);
47995 info->fbdefio = NULL;
47996- info->fbops->fb_mmap = ufx_ops_mmap;
47997+ pax_open_kernel();
47998+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47999+ pax_close_kernel();
48000 }
48001
48002 pr_debug("released /dev/fb%d user=%d count=%d",
48003diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
48004index ec03e72..f578436 100644
48005--- a/drivers/video/udlfb.c
48006+++ b/drivers/video/udlfb.c
48007@@ -623,11 +623,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
48008 dlfb_urb_completion(urb);
48009
48010 error:
48011- atomic_add(bytes_sent, &dev->bytes_sent);
48012- atomic_add(bytes_identical, &dev->bytes_identical);
48013- atomic_add(width*height*2, &dev->bytes_rendered);
48014+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48015+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48016+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
48017 end_cycles = get_cycles();
48018- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48019+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48020 >> 10)), /* Kcycles */
48021 &dev->cpu_kcycles_used);
48022
48023@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
48024 dlfb_urb_completion(urb);
48025
48026 error:
48027- atomic_add(bytes_sent, &dev->bytes_sent);
48028- atomic_add(bytes_identical, &dev->bytes_identical);
48029- atomic_add(bytes_rendered, &dev->bytes_rendered);
48030+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
48031+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
48032+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
48033 end_cycles = get_cycles();
48034- atomic_add(((unsigned int) ((end_cycles - start_cycles)
48035+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
48036 >> 10)), /* Kcycles */
48037 &dev->cpu_kcycles_used);
48038 }
48039@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
48040 fb_deferred_io_cleanup(info);
48041 kfree(info->fbdefio);
48042 info->fbdefio = NULL;
48043- info->fbops->fb_mmap = dlfb_ops_mmap;
48044+ pax_open_kernel();
48045+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
48046+ pax_close_kernel();
48047 }
48048
48049 pr_warn("released /dev/fb%d user=%d count=%d\n",
48050@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
48051 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48052 struct dlfb_data *dev = fb_info->par;
48053 return snprintf(buf, PAGE_SIZE, "%u\n",
48054- atomic_read(&dev->bytes_rendered));
48055+ atomic_read_unchecked(&dev->bytes_rendered));
48056 }
48057
48058 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48059@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
48060 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48061 struct dlfb_data *dev = fb_info->par;
48062 return snprintf(buf, PAGE_SIZE, "%u\n",
48063- atomic_read(&dev->bytes_identical));
48064+ atomic_read_unchecked(&dev->bytes_identical));
48065 }
48066
48067 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48068@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
48069 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48070 struct dlfb_data *dev = fb_info->par;
48071 return snprintf(buf, PAGE_SIZE, "%u\n",
48072- atomic_read(&dev->bytes_sent));
48073+ atomic_read_unchecked(&dev->bytes_sent));
48074 }
48075
48076 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48077@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
48078 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48079 struct dlfb_data *dev = fb_info->par;
48080 return snprintf(buf, PAGE_SIZE, "%u\n",
48081- atomic_read(&dev->cpu_kcycles_used));
48082+ atomic_read_unchecked(&dev->cpu_kcycles_used));
48083 }
48084
48085 static ssize_t edid_show(
48086@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
48087 struct fb_info *fb_info = dev_get_drvdata(fbdev);
48088 struct dlfb_data *dev = fb_info->par;
48089
48090- atomic_set(&dev->bytes_rendered, 0);
48091- atomic_set(&dev->bytes_identical, 0);
48092- atomic_set(&dev->bytes_sent, 0);
48093- atomic_set(&dev->cpu_kcycles_used, 0);
48094+ atomic_set_unchecked(&dev->bytes_rendered, 0);
48095+ atomic_set_unchecked(&dev->bytes_identical, 0);
48096+ atomic_set_unchecked(&dev->bytes_sent, 0);
48097+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
48098
48099 return count;
48100 }
48101diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
48102index e328a61..1b08ecb 100644
48103--- a/drivers/video/uvesafb.c
48104+++ b/drivers/video/uvesafb.c
48105@@ -19,6 +19,7 @@
48106 #include <linux/io.h>
48107 #include <linux/mutex.h>
48108 #include <linux/slab.h>
48109+#include <linux/moduleloader.h>
48110 #include <video/edid.h>
48111 #include <video/uvesafb.h>
48112 #ifdef CONFIG_X86
48113@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
48114 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
48115 par->pmi_setpal = par->ypan = 0;
48116 } else {
48117+
48118+#ifdef CONFIG_PAX_KERNEXEC
48119+#ifdef CONFIG_MODULES
48120+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
48121+#endif
48122+ if (!par->pmi_code) {
48123+ par->pmi_setpal = par->ypan = 0;
48124+ return 0;
48125+ }
48126+#endif
48127+
48128 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
48129 + task->t.regs.edi);
48130+
48131+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48132+ pax_open_kernel();
48133+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
48134+ pax_close_kernel();
48135+
48136+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
48137+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
48138+#else
48139 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
48140 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
48141+#endif
48142+
48143 printk(KERN_INFO "uvesafb: protected mode interface info at "
48144 "%04x:%04x\n",
48145 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48146@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48147 par->ypan = ypan;
48148
48149 if (par->pmi_setpal || par->ypan) {
48150+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48151 if (__supported_pte_mask & _PAGE_NX) {
48152 par->pmi_setpal = par->ypan = 0;
48153 printk(KERN_WARNING "uvesafb: NX protection is actively."
48154 "We have better not to use the PMI.\n");
48155- } else {
48156+ } else
48157+#endif
48158 uvesafb_vbe_getpmi(task, par);
48159- }
48160 }
48161 #else
48162 /* The protected mode interface is not available on non-x86. */
48163@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48164 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48165
48166 /* Disable blanking if the user requested so. */
48167- if (!blank)
48168- info->fbops->fb_blank = NULL;
48169+ if (!blank) {
48170+ pax_open_kernel();
48171+ *(void **)&info->fbops->fb_blank = NULL;
48172+ pax_close_kernel();
48173+ }
48174
48175 /*
48176 * Find out how much IO memory is required for the mode with
48177@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48178 info->flags = FBINFO_FLAG_DEFAULT |
48179 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48180
48181- if (!par->ypan)
48182- info->fbops->fb_pan_display = NULL;
48183+ if (!par->ypan) {
48184+ pax_open_kernel();
48185+ *(void **)&info->fbops->fb_pan_display = NULL;
48186+ pax_close_kernel();
48187+ }
48188 }
48189
48190 static void uvesafb_init_mtrr(struct fb_info *info)
48191@@ -1836,6 +1866,11 @@ out:
48192 if (par->vbe_modes)
48193 kfree(par->vbe_modes);
48194
48195+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48196+ if (par->pmi_code)
48197+ module_free_exec(NULL, par->pmi_code);
48198+#endif
48199+
48200 framebuffer_release(info);
48201 return err;
48202 }
48203@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48204 kfree(par->vbe_state_orig);
48205 if (par->vbe_state_saved)
48206 kfree(par->vbe_state_saved);
48207+
48208+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48209+ if (par->pmi_code)
48210+ module_free_exec(NULL, par->pmi_code);
48211+#endif
48212+
48213 }
48214
48215 framebuffer_release(info);
48216diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48217index 501b340..d80aa17 100644
48218--- a/drivers/video/vesafb.c
48219+++ b/drivers/video/vesafb.c
48220@@ -9,6 +9,7 @@
48221 */
48222
48223 #include <linux/module.h>
48224+#include <linux/moduleloader.h>
48225 #include <linux/kernel.h>
48226 #include <linux/errno.h>
48227 #include <linux/string.h>
48228@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48229 static int vram_total __initdata; /* Set total amount of memory */
48230 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48231 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48232-static void (*pmi_start)(void) __read_mostly;
48233-static void (*pmi_pal) (void) __read_mostly;
48234+static void (*pmi_start)(void) __read_only;
48235+static void (*pmi_pal) (void) __read_only;
48236 static int depth __read_mostly;
48237 static int vga_compat __read_mostly;
48238 /* --------------------------------------------------------------------- */
48239@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48240 unsigned int size_vmode;
48241 unsigned int size_remap;
48242 unsigned int size_total;
48243+ void *pmi_code = NULL;
48244
48245 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48246 return -ENODEV;
48247@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48248 size_remap = size_total;
48249 vesafb_fix.smem_len = size_remap;
48250
48251-#ifndef __i386__
48252- screen_info.vesapm_seg = 0;
48253-#endif
48254-
48255 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48256 printk(KERN_WARNING
48257 "vesafb: cannot reserve video memory at 0x%lx\n",
48258@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48259 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48260 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48261
48262+#ifdef __i386__
48263+
48264+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48265+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48266+ if (!pmi_code)
48267+#elif !defined(CONFIG_PAX_KERNEXEC)
48268+ if (0)
48269+#endif
48270+
48271+#endif
48272+ screen_info.vesapm_seg = 0;
48273+
48274 if (screen_info.vesapm_seg) {
48275- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48276- screen_info.vesapm_seg,screen_info.vesapm_off);
48277+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48278+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48279 }
48280
48281 if (screen_info.vesapm_seg < 0xc000)
48282@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48283
48284 if (ypan || pmi_setpal) {
48285 unsigned short *pmi_base;
48286+
48287 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48288- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48289- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48290+
48291+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48292+ pax_open_kernel();
48293+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48294+#else
48295+ pmi_code = pmi_base;
48296+#endif
48297+
48298+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48299+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48300+
48301+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48302+ pmi_start = ktva_ktla(pmi_start);
48303+ pmi_pal = ktva_ktla(pmi_pal);
48304+ pax_close_kernel();
48305+#endif
48306+
48307 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48308 if (pmi_base[3]) {
48309 printk(KERN_INFO "vesafb: pmi: ports = ");
48310@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48311 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48312 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48313
48314- if (!ypan)
48315- info->fbops->fb_pan_display = NULL;
48316+ if (!ypan) {
48317+ pax_open_kernel();
48318+ *(void **)&info->fbops->fb_pan_display = NULL;
48319+ pax_close_kernel();
48320+ }
48321
48322 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48323 err = -ENOMEM;
48324@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48325 info->node, info->fix.id);
48326 return 0;
48327 err:
48328+
48329+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48330+ module_free_exec(NULL, pmi_code);
48331+#endif
48332+
48333 if (info->screen_base)
48334 iounmap(info->screen_base);
48335 framebuffer_release(info);
48336diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48337index 88714ae..16c2e11 100644
48338--- a/drivers/video/via/via_clock.h
48339+++ b/drivers/video/via/via_clock.h
48340@@ -56,7 +56,7 @@ struct via_clock {
48341
48342 void (*set_engine_pll_state)(u8 state);
48343 void (*set_engine_pll)(struct via_pll_config config);
48344-};
48345+} __no_const;
48346
48347
48348 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48349diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48350index fef20db..d28b1ab 100644
48351--- a/drivers/xen/xenfs/xenstored.c
48352+++ b/drivers/xen/xenfs/xenstored.c
48353@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48354 static int xsd_kva_open(struct inode *inode, struct file *file)
48355 {
48356 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48357+#ifdef CONFIG_GRKERNSEC_HIDESYM
48358+ NULL);
48359+#else
48360 xen_store_interface);
48361+#endif
48362+
48363 if (!file->private_data)
48364 return -ENOMEM;
48365 return 0;
48366diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
48367index 055562c..fdfb10d 100644
48368--- a/fs/9p/vfs_addr.c
48369+++ b/fs/9p/vfs_addr.c
48370@@ -186,7 +186,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
48371
48372 retval = v9fs_file_write_internal(inode,
48373 v9inode->writeback_fid,
48374- (__force const char __user *)buffer,
48375+ (const char __force_user *)buffer,
48376 len, &offset, 0);
48377 if (retval > 0)
48378 retval = 0;
48379diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48380index d86edc8..40ff2fb 100644
48381--- a/fs/9p/vfs_inode.c
48382+++ b/fs/9p/vfs_inode.c
48383@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48384 void
48385 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48386 {
48387- char *s = nd_get_link(nd);
48388+ const char *s = nd_get_link(nd);
48389
48390 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48391 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48392diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48393index 370b24c..ff0be7b 100644
48394--- a/fs/Kconfig.binfmt
48395+++ b/fs/Kconfig.binfmt
48396@@ -103,7 +103,7 @@ config HAVE_AOUT
48397
48398 config BINFMT_AOUT
48399 tristate "Kernel support for a.out and ECOFF binaries"
48400- depends on HAVE_AOUT
48401+ depends on HAVE_AOUT && BROKEN
48402 ---help---
48403 A.out (Assembler.OUTput) is a set of formats for libraries and
48404 executables used in the earliest versions of UNIX. Linux used
48405diff --git a/fs/aio.c b/fs/aio.c
48406index 2bbcacf..8614116 100644
48407--- a/fs/aio.c
48408+++ b/fs/aio.c
48409@@ -160,7 +160,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48410 size += sizeof(struct io_event) * nr_events;
48411 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48412
48413- if (nr_pages < 0)
48414+ if (nr_pages <= 0)
48415 return -EINVAL;
48416
48417 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48418@@ -950,6 +950,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
48419 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
48420 {
48421 ssize_t ret;
48422+ struct iovec iovstack;
48423
48424 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48425
48426@@ -957,17 +958,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
48427 if (compat)
48428 ret = compat_rw_copy_check_uvector(rw,
48429 (struct compat_iovec __user *)kiocb->ki_buf,
48430- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
48431+ kiocb->ki_nr_segs, 1, &iovstack,
48432 &kiocb->ki_iovec);
48433 else
48434 #endif
48435 ret = rw_copy_check_uvector(rw,
48436 (struct iovec __user *)kiocb->ki_buf,
48437- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
48438+ kiocb->ki_nr_segs, 1, &iovstack,
48439 &kiocb->ki_iovec);
48440 if (ret < 0)
48441 return ret;
48442
48443+ if (kiocb->ki_iovec == &iovstack) {
48444+ kiocb->ki_inline_vec = iovstack;
48445+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48446+ }
48447+
48448 /* ki_nbytes now reflect bytes instead of segs */
48449 kiocb->ki_nbytes = ret;
48450 return 0;
48451diff --git a/fs/attr.c b/fs/attr.c
48452index 1449adb..a2038c2 100644
48453--- a/fs/attr.c
48454+++ b/fs/attr.c
48455@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48456 unsigned long limit;
48457
48458 limit = rlimit(RLIMIT_FSIZE);
48459+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48460 if (limit != RLIM_INFINITY && offset > limit)
48461 goto out_sig;
48462 if (offset > inode->i_sb->s_maxbytes)
48463diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48464index 3db70da..7aeec5b 100644
48465--- a/fs/autofs4/waitq.c
48466+++ b/fs/autofs4/waitq.c
48467@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48468 {
48469 unsigned long sigpipe, flags;
48470 mm_segment_t fs;
48471- const char *data = (const char *)addr;
48472+ const char __user *data = (const char __force_user *)addr;
48473 ssize_t wr = 0;
48474
48475 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48476@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48477 return 1;
48478 }
48479
48480+#ifdef CONFIG_GRKERNSEC_HIDESYM
48481+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48482+#endif
48483+
48484 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48485 enum autofs_notify notify)
48486 {
48487@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48488
48489 /* If this is a direct mount request create a dummy name */
48490 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48491+#ifdef CONFIG_GRKERNSEC_HIDESYM
48492+ /* this name does get written to userland via autofs4_write() */
48493+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48494+#else
48495 qstr.len = sprintf(name, "%p", dentry);
48496+#endif
48497 else {
48498 qstr.len = autofs4_getpath(sbi, dentry, &name);
48499 if (!qstr.len) {
48500diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48501index 2722387..c8dd2a7 100644
48502--- a/fs/befs/endian.h
48503+++ b/fs/befs/endian.h
48504@@ -11,7 +11,7 @@
48505
48506 #include <asm/byteorder.h>
48507
48508-static inline u64
48509+static inline u64 __intentional_overflow(-1)
48510 fs64_to_cpu(const struct super_block *sb, fs64 n)
48511 {
48512 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48513@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48514 return (__force fs64)cpu_to_be64(n);
48515 }
48516
48517-static inline u32
48518+static inline u32 __intentional_overflow(-1)
48519 fs32_to_cpu(const struct super_block *sb, fs32 n)
48520 {
48521 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48522diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48523index f95dddc..b1e2c1c 100644
48524--- a/fs/befs/linuxvfs.c
48525+++ b/fs/befs/linuxvfs.c
48526@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48527 {
48528 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48529 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48530- char *link = nd_get_link(nd);
48531+ const char *link = nd_get_link(nd);
48532 if (!IS_ERR(link))
48533 kfree(link);
48534 }
48535diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48536index bce8769..7fc7544 100644
48537--- a/fs/binfmt_aout.c
48538+++ b/fs/binfmt_aout.c
48539@@ -16,6 +16,7 @@
48540 #include <linux/string.h>
48541 #include <linux/fs.h>
48542 #include <linux/file.h>
48543+#include <linux/security.h>
48544 #include <linux/stat.h>
48545 #include <linux/fcntl.h>
48546 #include <linux/ptrace.h>
48547@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48548 #endif
48549 # define START_STACK(u) ((void __user *)u.start_stack)
48550
48551+ memset(&dump, 0, sizeof(dump));
48552+
48553 fs = get_fs();
48554 set_fs(KERNEL_DS);
48555 has_dumped = 1;
48556@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48557
48558 /* If the size of the dump file exceeds the rlimit, then see what would happen
48559 if we wrote the stack, but not the data area. */
48560+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48561 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48562 dump.u_dsize = 0;
48563
48564 /* Make sure we have enough room to write the stack and data areas. */
48565+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48566 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48567 dump.u_ssize = 0;
48568
48569@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48570 rlim = rlimit(RLIMIT_DATA);
48571 if (rlim >= RLIM_INFINITY)
48572 rlim = ~0;
48573+
48574+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48575 if (ex.a_data + ex.a_bss > rlim)
48576 return -ENOMEM;
48577
48578@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48579
48580 install_exec_creds(bprm);
48581
48582+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48583+ current->mm->pax_flags = 0UL;
48584+#endif
48585+
48586+#ifdef CONFIG_PAX_PAGEEXEC
48587+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48588+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48589+
48590+#ifdef CONFIG_PAX_EMUTRAMP
48591+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48592+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48593+#endif
48594+
48595+#ifdef CONFIG_PAX_MPROTECT
48596+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48597+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48598+#endif
48599+
48600+ }
48601+#endif
48602+
48603 if (N_MAGIC(ex) == OMAGIC) {
48604 unsigned long text_addr, map_size;
48605 loff_t pos;
48606@@ -324,7 +352,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48607 }
48608
48609 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48610- PROT_READ | PROT_WRITE | PROT_EXEC,
48611+ PROT_READ | PROT_WRITE,
48612 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48613 fd_offset + ex.a_text);
48614 if (error != N_DATADDR(ex)) {
48615diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48616index f8a0b0e..8186af0 100644
48617--- a/fs/binfmt_elf.c
48618+++ b/fs/binfmt_elf.c
48619@@ -34,6 +34,7 @@
48620 #include <linux/utsname.h>
48621 #include <linux/coredump.h>
48622 #include <linux/sched.h>
48623+#include <linux/xattr.h>
48624 #include <asm/uaccess.h>
48625 #include <asm/param.h>
48626 #include <asm/page.h>
48627@@ -60,6 +61,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48628 #define elf_core_dump NULL
48629 #endif
48630
48631+#ifdef CONFIG_PAX_MPROTECT
48632+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48633+#endif
48634+
48635 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48636 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48637 #else
48638@@ -79,6 +84,11 @@ static struct linux_binfmt elf_format = {
48639 .load_binary = load_elf_binary,
48640 .load_shlib = load_elf_library,
48641 .core_dump = elf_core_dump,
48642+
48643+#ifdef CONFIG_PAX_MPROTECT
48644+ .handle_mprotect= elf_handle_mprotect,
48645+#endif
48646+
48647 .min_coredump = ELF_EXEC_PAGESIZE,
48648 };
48649
48650@@ -86,6 +96,8 @@ static struct linux_binfmt elf_format = {
48651
48652 static int set_brk(unsigned long start, unsigned long end)
48653 {
48654+ unsigned long e = end;
48655+
48656 start = ELF_PAGEALIGN(start);
48657 end = ELF_PAGEALIGN(end);
48658 if (end > start) {
48659@@ -94,7 +106,7 @@ static int set_brk(unsigned long start, unsigned long end)
48660 if (BAD_ADDR(addr))
48661 return addr;
48662 }
48663- current->mm->start_brk = current->mm->brk = end;
48664+ current->mm->start_brk = current->mm->brk = e;
48665 return 0;
48666 }
48667
48668@@ -155,12 +167,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48669 elf_addr_t __user *u_rand_bytes;
48670 const char *k_platform = ELF_PLATFORM;
48671 const char *k_base_platform = ELF_BASE_PLATFORM;
48672- unsigned char k_rand_bytes[16];
48673+ u32 k_rand_bytes[4];
48674 int items;
48675 elf_addr_t *elf_info;
48676 int ei_index = 0;
48677 const struct cred *cred = current_cred();
48678 struct vm_area_struct *vma;
48679+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48680
48681 /*
48682 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48683@@ -202,8 +215,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48684 * Generate 16 random bytes for userspace PRNG seeding.
48685 */
48686 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48687- u_rand_bytes = (elf_addr_t __user *)
48688- STACK_ALLOC(p, sizeof(k_rand_bytes));
48689+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
48690+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
48691+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
48692+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
48693+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48694+ u_rand_bytes = (elf_addr_t __user *) p;
48695 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48696 return -EFAULT;
48697
48698@@ -318,9 +335,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48699 return -EFAULT;
48700 current->mm->env_end = p;
48701
48702+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48703+
48704 /* Put the elf_info on the stack in the right place. */
48705 sp = (elf_addr_t __user *)envp + 1;
48706- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48707+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48708 return -EFAULT;
48709 return 0;
48710 }
48711@@ -388,15 +407,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48712 an ELF header */
48713
48714 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48715- struct file *interpreter, unsigned long *interp_map_addr,
48716- unsigned long no_base)
48717+ struct file *interpreter, unsigned long no_base)
48718 {
48719 struct elf_phdr *elf_phdata;
48720 struct elf_phdr *eppnt;
48721- unsigned long load_addr = 0;
48722+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48723 int load_addr_set = 0;
48724 unsigned long last_bss = 0, elf_bss = 0;
48725- unsigned long error = ~0UL;
48726+ unsigned long error = -EINVAL;
48727 unsigned long total_size;
48728 int retval, i, size;
48729
48730@@ -442,6 +460,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48731 goto out_close;
48732 }
48733
48734+#ifdef CONFIG_PAX_SEGMEXEC
48735+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48736+ pax_task_size = SEGMEXEC_TASK_SIZE;
48737+#endif
48738+
48739 eppnt = elf_phdata;
48740 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48741 if (eppnt->p_type == PT_LOAD) {
48742@@ -465,8 +488,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48743 map_addr = elf_map(interpreter, load_addr + vaddr,
48744 eppnt, elf_prot, elf_type, total_size);
48745 total_size = 0;
48746- if (!*interp_map_addr)
48747- *interp_map_addr = map_addr;
48748 error = map_addr;
48749 if (BAD_ADDR(map_addr))
48750 goto out_close;
48751@@ -485,8 +506,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48752 k = load_addr + eppnt->p_vaddr;
48753 if (BAD_ADDR(k) ||
48754 eppnt->p_filesz > eppnt->p_memsz ||
48755- eppnt->p_memsz > TASK_SIZE ||
48756- TASK_SIZE - eppnt->p_memsz < k) {
48757+ eppnt->p_memsz > pax_task_size ||
48758+ pax_task_size - eppnt->p_memsz < k) {
48759 error = -ENOMEM;
48760 goto out_close;
48761 }
48762@@ -538,6 +559,315 @@ out:
48763 return error;
48764 }
48765
48766+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48767+#ifdef CONFIG_PAX_SOFTMODE
48768+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48769+{
48770+ unsigned long pax_flags = 0UL;
48771+
48772+#ifdef CONFIG_PAX_PAGEEXEC
48773+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48774+ pax_flags |= MF_PAX_PAGEEXEC;
48775+#endif
48776+
48777+#ifdef CONFIG_PAX_SEGMEXEC
48778+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48779+ pax_flags |= MF_PAX_SEGMEXEC;
48780+#endif
48781+
48782+#ifdef CONFIG_PAX_EMUTRAMP
48783+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48784+ pax_flags |= MF_PAX_EMUTRAMP;
48785+#endif
48786+
48787+#ifdef CONFIG_PAX_MPROTECT
48788+ if (elf_phdata->p_flags & PF_MPROTECT)
48789+ pax_flags |= MF_PAX_MPROTECT;
48790+#endif
48791+
48792+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48793+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48794+ pax_flags |= MF_PAX_RANDMMAP;
48795+#endif
48796+
48797+ return pax_flags;
48798+}
48799+#endif
48800+
48801+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48802+{
48803+ unsigned long pax_flags = 0UL;
48804+
48805+#ifdef CONFIG_PAX_PAGEEXEC
48806+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48807+ pax_flags |= MF_PAX_PAGEEXEC;
48808+#endif
48809+
48810+#ifdef CONFIG_PAX_SEGMEXEC
48811+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48812+ pax_flags |= MF_PAX_SEGMEXEC;
48813+#endif
48814+
48815+#ifdef CONFIG_PAX_EMUTRAMP
48816+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48817+ pax_flags |= MF_PAX_EMUTRAMP;
48818+#endif
48819+
48820+#ifdef CONFIG_PAX_MPROTECT
48821+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48822+ pax_flags |= MF_PAX_MPROTECT;
48823+#endif
48824+
48825+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48826+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48827+ pax_flags |= MF_PAX_RANDMMAP;
48828+#endif
48829+
48830+ return pax_flags;
48831+}
48832+#endif
48833+
48834+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48835+#ifdef CONFIG_PAX_SOFTMODE
48836+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48837+{
48838+ unsigned long pax_flags = 0UL;
48839+
48840+#ifdef CONFIG_PAX_PAGEEXEC
48841+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48842+ pax_flags |= MF_PAX_PAGEEXEC;
48843+#endif
48844+
48845+#ifdef CONFIG_PAX_SEGMEXEC
48846+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48847+ pax_flags |= MF_PAX_SEGMEXEC;
48848+#endif
48849+
48850+#ifdef CONFIG_PAX_EMUTRAMP
48851+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48852+ pax_flags |= MF_PAX_EMUTRAMP;
48853+#endif
48854+
48855+#ifdef CONFIG_PAX_MPROTECT
48856+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48857+ pax_flags |= MF_PAX_MPROTECT;
48858+#endif
48859+
48860+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48861+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48862+ pax_flags |= MF_PAX_RANDMMAP;
48863+#endif
48864+
48865+ return pax_flags;
48866+}
48867+#endif
48868+
48869+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48870+{
48871+ unsigned long pax_flags = 0UL;
48872+
48873+#ifdef CONFIG_PAX_PAGEEXEC
48874+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48875+ pax_flags |= MF_PAX_PAGEEXEC;
48876+#endif
48877+
48878+#ifdef CONFIG_PAX_SEGMEXEC
48879+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48880+ pax_flags |= MF_PAX_SEGMEXEC;
48881+#endif
48882+
48883+#ifdef CONFIG_PAX_EMUTRAMP
48884+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48885+ pax_flags |= MF_PAX_EMUTRAMP;
48886+#endif
48887+
48888+#ifdef CONFIG_PAX_MPROTECT
48889+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48890+ pax_flags |= MF_PAX_MPROTECT;
48891+#endif
48892+
48893+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48894+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48895+ pax_flags |= MF_PAX_RANDMMAP;
48896+#endif
48897+
48898+ return pax_flags;
48899+}
48900+#endif
48901+
48902+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48903+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48904+{
48905+ unsigned long pax_flags = 0UL;
48906+
48907+#ifdef CONFIG_PAX_EI_PAX
48908+
48909+#ifdef CONFIG_PAX_PAGEEXEC
48910+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48911+ pax_flags |= MF_PAX_PAGEEXEC;
48912+#endif
48913+
48914+#ifdef CONFIG_PAX_SEGMEXEC
48915+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48916+ pax_flags |= MF_PAX_SEGMEXEC;
48917+#endif
48918+
48919+#ifdef CONFIG_PAX_EMUTRAMP
48920+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48921+ pax_flags |= MF_PAX_EMUTRAMP;
48922+#endif
48923+
48924+#ifdef CONFIG_PAX_MPROTECT
48925+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48926+ pax_flags |= MF_PAX_MPROTECT;
48927+#endif
48928+
48929+#ifdef CONFIG_PAX_ASLR
48930+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48931+ pax_flags |= MF_PAX_RANDMMAP;
48932+#endif
48933+
48934+#else
48935+
48936+#ifdef CONFIG_PAX_PAGEEXEC
48937+ pax_flags |= MF_PAX_PAGEEXEC;
48938+#endif
48939+
48940+#ifdef CONFIG_PAX_SEGMEXEC
48941+ pax_flags |= MF_PAX_SEGMEXEC;
48942+#endif
48943+
48944+#ifdef CONFIG_PAX_MPROTECT
48945+ pax_flags |= MF_PAX_MPROTECT;
48946+#endif
48947+
48948+#ifdef CONFIG_PAX_RANDMMAP
48949+ if (randomize_va_space)
48950+ pax_flags |= MF_PAX_RANDMMAP;
48951+#endif
48952+
48953+#endif
48954+
48955+ return pax_flags;
48956+}
48957+
48958+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48959+{
48960+
48961+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48962+ unsigned long i;
48963+
48964+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48965+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48966+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48967+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48968+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48969+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48970+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48971+ return ~0UL;
48972+
48973+#ifdef CONFIG_PAX_SOFTMODE
48974+ if (pax_softmode)
48975+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48976+ else
48977+#endif
48978+
48979+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48980+ break;
48981+ }
48982+#endif
48983+
48984+ return ~0UL;
48985+}
48986+
48987+static unsigned long pax_parse_xattr_pax(struct file * const file)
48988+{
48989+
48990+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48991+ ssize_t xattr_size, i;
48992+ unsigned char xattr_value[sizeof("pemrs") - 1];
48993+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48994+
48995+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
48996+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
48997+ return ~0UL;
48998+
48999+ for (i = 0; i < xattr_size; i++)
49000+ switch (xattr_value[i]) {
49001+ default:
49002+ return ~0UL;
49003+
49004+#define parse_flag(option1, option2, flag) \
49005+ case option1: \
49006+ if (pax_flags_hardmode & MF_PAX_##flag) \
49007+ return ~0UL; \
49008+ pax_flags_hardmode |= MF_PAX_##flag; \
49009+ break; \
49010+ case option2: \
49011+ if (pax_flags_softmode & MF_PAX_##flag) \
49012+ return ~0UL; \
49013+ pax_flags_softmode |= MF_PAX_##flag; \
49014+ break;
49015+
49016+ parse_flag('p', 'P', PAGEEXEC);
49017+ parse_flag('e', 'E', EMUTRAMP);
49018+ parse_flag('m', 'M', MPROTECT);
49019+ parse_flag('r', 'R', RANDMMAP);
49020+ parse_flag('s', 'S', SEGMEXEC);
49021+
49022+#undef parse_flag
49023+ }
49024+
49025+ if (pax_flags_hardmode & pax_flags_softmode)
49026+ return ~0UL;
49027+
49028+#ifdef CONFIG_PAX_SOFTMODE
49029+ if (pax_softmode)
49030+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
49031+ else
49032+#endif
49033+
49034+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
49035+#else
49036+ return ~0UL;
49037+#endif
49038+
49039+}
49040+
49041+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
49042+{
49043+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
49044+
49045+ pax_flags = pax_parse_ei_pax(elf_ex);
49046+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
49047+ xattr_pax_flags = pax_parse_xattr_pax(file);
49048+
49049+ if (pt_pax_flags == ~0UL)
49050+ pt_pax_flags = xattr_pax_flags;
49051+ else if (xattr_pax_flags == ~0UL)
49052+ xattr_pax_flags = pt_pax_flags;
49053+ if (pt_pax_flags != xattr_pax_flags)
49054+ return -EINVAL;
49055+ if (pt_pax_flags != ~0UL)
49056+ pax_flags = pt_pax_flags;
49057+
49058+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
49059+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49060+ if ((__supported_pte_mask & _PAGE_NX))
49061+ pax_flags &= ~MF_PAX_SEGMEXEC;
49062+ else
49063+ pax_flags &= ~MF_PAX_PAGEEXEC;
49064+ }
49065+#endif
49066+
49067+ if (0 > pax_check_flags(&pax_flags))
49068+ return -EINVAL;
49069+
49070+ current->mm->pax_flags = pax_flags;
49071+ return 0;
49072+}
49073+#endif
49074+
49075 /*
49076 * These are the functions used to load ELF style executables and shared
49077 * libraries. There is no binary dependent code anywhere else.
49078@@ -554,6 +884,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
49079 {
49080 unsigned int random_variable = 0;
49081
49082+#ifdef CONFIG_PAX_RANDUSTACK
49083+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
49084+ return stack_top - current->mm->delta_stack;
49085+#endif
49086+
49087 if ((current->flags & PF_RANDOMIZE) &&
49088 !(current->personality & ADDR_NO_RANDOMIZE)) {
49089 random_variable = get_random_int() & STACK_RND_MASK;
49090@@ -572,7 +907,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
49091 unsigned long load_addr = 0, load_bias = 0;
49092 int load_addr_set = 0;
49093 char * elf_interpreter = NULL;
49094- unsigned long error;
49095+ unsigned long error = 0;
49096 struct elf_phdr *elf_ppnt, *elf_phdata;
49097 unsigned long elf_bss, elf_brk;
49098 int retval, i;
49099@@ -582,12 +917,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
49100 unsigned long start_code, end_code, start_data, end_data;
49101 unsigned long reloc_func_desc __maybe_unused = 0;
49102 int executable_stack = EXSTACK_DEFAULT;
49103- unsigned long def_flags = 0;
49104 struct pt_regs *regs = current_pt_regs();
49105 struct {
49106 struct elfhdr elf_ex;
49107 struct elfhdr interp_elf_ex;
49108 } *loc;
49109+ unsigned long pax_task_size = TASK_SIZE;
49110
49111 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
49112 if (!loc) {
49113@@ -723,11 +1058,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
49114 goto out_free_dentry;
49115
49116 /* OK, This is the point of no return */
49117- current->mm->def_flags = def_flags;
49118+
49119+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49120+ current->mm->pax_flags = 0UL;
49121+#endif
49122+
49123+#ifdef CONFIG_PAX_DLRESOLVE
49124+ current->mm->call_dl_resolve = 0UL;
49125+#endif
49126+
49127+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
49128+ current->mm->call_syscall = 0UL;
49129+#endif
49130+
49131+#ifdef CONFIG_PAX_ASLR
49132+ current->mm->delta_mmap = 0UL;
49133+ current->mm->delta_stack = 0UL;
49134+#endif
49135+
49136+ current->mm->def_flags = 0;
49137+
49138+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
49139+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
49140+ send_sig(SIGKILL, current, 0);
49141+ goto out_free_dentry;
49142+ }
49143+#endif
49144+
49145+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49146+ pax_set_initial_flags(bprm);
49147+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49148+ if (pax_set_initial_flags_func)
49149+ (pax_set_initial_flags_func)(bprm);
49150+#endif
49151+
49152+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49153+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49154+ current->mm->context.user_cs_limit = PAGE_SIZE;
49155+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49156+ }
49157+#endif
49158+
49159+#ifdef CONFIG_PAX_SEGMEXEC
49160+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49161+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49162+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49163+ pax_task_size = SEGMEXEC_TASK_SIZE;
49164+ current->mm->def_flags |= VM_NOHUGEPAGE;
49165+ }
49166+#endif
49167+
49168+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49169+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49170+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49171+ put_cpu();
49172+ }
49173+#endif
49174
49175 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49176 may depend on the personality. */
49177 SET_PERSONALITY(loc->elf_ex);
49178+
49179+#ifdef CONFIG_PAX_ASLR
49180+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49181+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49182+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49183+ }
49184+#endif
49185+
49186+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49187+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49188+ executable_stack = EXSTACK_DISABLE_X;
49189+ current->personality &= ~READ_IMPLIES_EXEC;
49190+ } else
49191+#endif
49192+
49193 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49194 current->personality |= READ_IMPLIES_EXEC;
49195
49196@@ -819,6 +1224,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49197 #else
49198 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49199 #endif
49200+
49201+#ifdef CONFIG_PAX_RANDMMAP
49202+ /* PaX: randomize base address at the default exe base if requested */
49203+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49204+#ifdef CONFIG_SPARC64
49205+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49206+#else
49207+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49208+#endif
49209+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49210+ elf_flags |= MAP_FIXED;
49211+ }
49212+#endif
49213+
49214 }
49215
49216 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49217@@ -851,9 +1270,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49218 * allowed task size. Note that p_filesz must always be
49219 * <= p_memsz so it is only necessary to check p_memsz.
49220 */
49221- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49222- elf_ppnt->p_memsz > TASK_SIZE ||
49223- TASK_SIZE - elf_ppnt->p_memsz < k) {
49224+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49225+ elf_ppnt->p_memsz > pax_task_size ||
49226+ pax_task_size - elf_ppnt->p_memsz < k) {
49227 /* set_brk can never work. Avoid overflows. */
49228 send_sig(SIGKILL, current, 0);
49229 retval = -EINVAL;
49230@@ -892,17 +1311,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
49231 goto out_free_dentry;
49232 }
49233 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49234- send_sig(SIGSEGV, current, 0);
49235- retval = -EFAULT; /* Nobody gets to see this, but.. */
49236- goto out_free_dentry;
49237+ /*
49238+ * This bss-zeroing can fail if the ELF
49239+ * file specifies odd protections. So
49240+ * we don't check the return value
49241+ */
49242 }
49243
49244+#ifdef CONFIG_PAX_RANDMMAP
49245+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49246+ unsigned long start, size, flags;
49247+ vm_flags_t vm_flags;
49248+
49249+ start = ELF_PAGEALIGN(elf_brk);
49250+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49251+ flags = MAP_FIXED | MAP_PRIVATE;
49252+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49253+
49254+ down_write(&current->mm->mmap_sem);
49255+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49256+ retval = -ENOMEM;
49257+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49258+// if (current->personality & ADDR_NO_RANDOMIZE)
49259+// vm_flags |= VM_READ | VM_MAYREAD;
49260+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
49261+ retval = IS_ERR_VALUE(start) ? start : 0;
49262+ }
49263+ up_write(&current->mm->mmap_sem);
49264+ if (retval == 0)
49265+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49266+ if (retval < 0) {
49267+ send_sig(SIGKILL, current, 0);
49268+ goto out_free_dentry;
49269+ }
49270+ }
49271+#endif
49272+
49273 if (elf_interpreter) {
49274- unsigned long interp_map_addr = 0;
49275-
49276 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49277 interpreter,
49278- &interp_map_addr,
49279 load_bias);
49280 if (!IS_ERR((void *)elf_entry)) {
49281 /*
49282@@ -1124,7 +1571,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49283 * Decide what to dump of a segment, part, all or none.
49284 */
49285 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49286- unsigned long mm_flags)
49287+ unsigned long mm_flags, long signr)
49288 {
49289 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49290
49291@@ -1162,7 +1609,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49292 if (vma->vm_file == NULL)
49293 return 0;
49294
49295- if (FILTER(MAPPED_PRIVATE))
49296+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49297 goto whole;
49298
49299 /*
49300@@ -1387,9 +1834,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49301 {
49302 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49303 int i = 0;
49304- do
49305+ do {
49306 i += 2;
49307- while (auxv[i - 2] != AT_NULL);
49308+ } while (auxv[i - 2] != AT_NULL);
49309 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49310 }
49311
49312@@ -1398,7 +1845,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
49313 {
49314 mm_segment_t old_fs = get_fs();
49315 set_fs(KERNEL_DS);
49316- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
49317+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
49318 set_fs(old_fs);
49319 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
49320 }
49321@@ -2019,14 +2466,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49322 }
49323
49324 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49325- unsigned long mm_flags)
49326+ struct coredump_params *cprm)
49327 {
49328 struct vm_area_struct *vma;
49329 size_t size = 0;
49330
49331 for (vma = first_vma(current, gate_vma); vma != NULL;
49332 vma = next_vma(vma, gate_vma))
49333- size += vma_dump_size(vma, mm_flags);
49334+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49335 return size;
49336 }
49337
49338@@ -2119,7 +2566,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49339
49340 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49341
49342- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49343+ offset += elf_core_vma_data_size(gate_vma, cprm);
49344 offset += elf_core_extra_data_size();
49345 e_shoff = offset;
49346
49347@@ -2133,10 +2580,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49348 offset = dataoff;
49349
49350 size += sizeof(*elf);
49351+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49352 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49353 goto end_coredump;
49354
49355 size += sizeof(*phdr4note);
49356+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49357 if (size > cprm->limit
49358 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49359 goto end_coredump;
49360@@ -2150,7 +2599,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49361 phdr.p_offset = offset;
49362 phdr.p_vaddr = vma->vm_start;
49363 phdr.p_paddr = 0;
49364- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49365+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49366 phdr.p_memsz = vma->vm_end - vma->vm_start;
49367 offset += phdr.p_filesz;
49368 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49369@@ -2161,6 +2610,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49370 phdr.p_align = ELF_EXEC_PAGESIZE;
49371
49372 size += sizeof(phdr);
49373+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49374 if (size > cprm->limit
49375 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49376 goto end_coredump;
49377@@ -2185,7 +2635,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49378 unsigned long addr;
49379 unsigned long end;
49380
49381- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49382+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49383
49384 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49385 struct page *page;
49386@@ -2194,6 +2644,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49387 page = get_dump_page(addr);
49388 if (page) {
49389 void *kaddr = kmap(page);
49390+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49391 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49392 !dump_write(cprm->file, kaddr,
49393 PAGE_SIZE);
49394@@ -2211,6 +2662,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49395
49396 if (e_phnum == PN_XNUM) {
49397 size += sizeof(*shdr4extnum);
49398+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49399 if (size > cprm->limit
49400 || !dump_write(cprm->file, shdr4extnum,
49401 sizeof(*shdr4extnum)))
49402@@ -2231,6 +2683,97 @@ out:
49403
49404 #endif /* CONFIG_ELF_CORE */
49405
49406+#ifdef CONFIG_PAX_MPROTECT
49407+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49408+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49409+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49410+ *
49411+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49412+ * basis because we want to allow the common case and not the special ones.
49413+ */
49414+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49415+{
49416+ struct elfhdr elf_h;
49417+ struct elf_phdr elf_p;
49418+ unsigned long i;
49419+ unsigned long oldflags;
49420+ bool is_textrel_rw, is_textrel_rx, is_relro;
49421+
49422+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49423+ return;
49424+
49425+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49426+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49427+
49428+#ifdef CONFIG_PAX_ELFRELOCS
49429+ /* possible TEXTREL */
49430+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49431+ is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
49432+#else
49433+ is_textrel_rw = false;
49434+ is_textrel_rx = false;
49435+#endif
49436+
49437+ /* possible RELRO */
49438+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49439+
49440+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49441+ return;
49442+
49443+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49444+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49445+
49446+#ifdef CONFIG_PAX_ETEXECRELOCS
49447+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49448+#else
49449+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49450+#endif
49451+
49452+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49453+ !elf_check_arch(&elf_h) ||
49454+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49455+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49456+ return;
49457+
49458+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49459+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49460+ return;
49461+ switch (elf_p.p_type) {
49462+ case PT_DYNAMIC:
49463+ if (!is_textrel_rw && !is_textrel_rx)
49464+ continue;
49465+ i = 0UL;
49466+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49467+ elf_dyn dyn;
49468+
49469+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49470+ return;
49471+ if (dyn.d_tag == DT_NULL)
49472+ return;
49473+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49474+ gr_log_textrel(vma);
49475+ if (is_textrel_rw)
49476+ vma->vm_flags |= VM_MAYWRITE;
49477+ else
49478+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49479+ vma->vm_flags &= ~VM_MAYWRITE;
49480+ return;
49481+ }
49482+ i++;
49483+ }
49484+ return;
49485+
49486+ case PT_GNU_RELRO:
49487+ if (!is_relro)
49488+ continue;
49489+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49490+ vma->vm_flags &= ~VM_MAYWRITE;
49491+ return;
49492+ }
49493+ }
49494+}
49495+#endif
49496+
49497 static int __init init_elf_binfmt(void)
49498 {
49499 register_binfmt(&elf_format);
49500diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49501index d50bbe5..af3b649 100644
49502--- a/fs/binfmt_flat.c
49503+++ b/fs/binfmt_flat.c
49504@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49505 realdatastart = (unsigned long) -ENOMEM;
49506 printk("Unable to allocate RAM for process data, errno %d\n",
49507 (int)-realdatastart);
49508+ down_write(&current->mm->mmap_sem);
49509 vm_munmap(textpos, text_len);
49510+ up_write(&current->mm->mmap_sem);
49511 ret = realdatastart;
49512 goto err;
49513 }
49514@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49515 }
49516 if (IS_ERR_VALUE(result)) {
49517 printk("Unable to read data+bss, errno %d\n", (int)-result);
49518+ down_write(&current->mm->mmap_sem);
49519 vm_munmap(textpos, text_len);
49520 vm_munmap(realdatastart, len);
49521+ up_write(&current->mm->mmap_sem);
49522 ret = result;
49523 goto err;
49524 }
49525@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49526 }
49527 if (IS_ERR_VALUE(result)) {
49528 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49529+ down_write(&current->mm->mmap_sem);
49530 vm_munmap(textpos, text_len + data_len + extra +
49531 MAX_SHARED_LIBS * sizeof(unsigned long));
49532+ up_write(&current->mm->mmap_sem);
49533 ret = result;
49534 goto err;
49535 }
49536diff --git a/fs/bio.c b/fs/bio.c
49537index 94bbc04..6fe78a4 100644
49538--- a/fs/bio.c
49539+++ b/fs/bio.c
49540@@ -1096,7 +1096,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49541 /*
49542 * Overflow, abort
49543 */
49544- if (end < start)
49545+ if (end < start || end - start > INT_MAX - nr_pages)
49546 return ERR_PTR(-EINVAL);
49547
49548 nr_pages += end - start;
49549@@ -1230,7 +1230,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49550 /*
49551 * Overflow, abort
49552 */
49553- if (end < start)
49554+ if (end < start || end - start > INT_MAX - nr_pages)
49555 return ERR_PTR(-EINVAL);
49556
49557 nr_pages += end - start;
49558@@ -1492,7 +1492,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49559 const int read = bio_data_dir(bio) == READ;
49560 struct bio_map_data *bmd = bio->bi_private;
49561 int i;
49562- char *p = bmd->sgvecs[0].iov_base;
49563+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49564
49565 bio_for_each_segment_all(bvec, bio, i) {
49566 char *addr = page_address(bvec->bv_page);
49567diff --git a/fs/block_dev.c b/fs/block_dev.c
49568index 2091db8..81dafe9 100644
49569--- a/fs/block_dev.c
49570+++ b/fs/block_dev.c
49571@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49572 else if (bdev->bd_contains == bdev)
49573 return true; /* is a whole device which isn't held */
49574
49575- else if (whole->bd_holder == bd_may_claim)
49576+ else if (whole->bd_holder == (void *)bd_may_claim)
49577 return true; /* is a partition of a device that is being partitioned */
49578 else if (whole->bd_holder != NULL)
49579 return false; /* is a partition of a held device */
49580diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49581index 02fae7f..48da375 100644
49582--- a/fs/btrfs/ctree.c
49583+++ b/fs/btrfs/ctree.c
49584@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49585 free_extent_buffer(buf);
49586 add_root_to_dirty_list(root);
49587 } else {
49588- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49589- parent_start = parent->start;
49590- else
49591+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49592+ if (parent)
49593+ parent_start = parent->start;
49594+ else
49595+ parent_start = 0;
49596+ } else
49597 parent_start = 0;
49598
49599 WARN_ON(trans->transid != btrfs_header_generation(parent));
49600diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49601index 0f81d67..0ad55fe 100644
49602--- a/fs/btrfs/ioctl.c
49603+++ b/fs/btrfs/ioctl.c
49604@@ -3084,9 +3084,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49605 for (i = 0; i < num_types; i++) {
49606 struct btrfs_space_info *tmp;
49607
49608+ /* Don't copy in more than we allocated */
49609 if (!slot_count)
49610 break;
49611
49612+ slot_count--;
49613+
49614 info = NULL;
49615 rcu_read_lock();
49616 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49617@@ -3108,10 +3111,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49618 memcpy(dest, &space, sizeof(space));
49619 dest++;
49620 space_args.total_spaces++;
49621- slot_count--;
49622 }
49623- if (!slot_count)
49624- break;
49625 }
49626 up_read(&info->groups_sem);
49627 }
49628diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49629index f0857e0..e7023c5 100644
49630--- a/fs/btrfs/super.c
49631+++ b/fs/btrfs/super.c
49632@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49633 function, line, errstr);
49634 return;
49635 }
49636- ACCESS_ONCE(trans->transaction->aborted) = errno;
49637+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49638 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49639 }
49640 /*
49641diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49642index 622f469..e8d2d55 100644
49643--- a/fs/cachefiles/bind.c
49644+++ b/fs/cachefiles/bind.c
49645@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49646 args);
49647
49648 /* start by checking things over */
49649- ASSERT(cache->fstop_percent >= 0 &&
49650- cache->fstop_percent < cache->fcull_percent &&
49651+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49652 cache->fcull_percent < cache->frun_percent &&
49653 cache->frun_percent < 100);
49654
49655- ASSERT(cache->bstop_percent >= 0 &&
49656- cache->bstop_percent < cache->bcull_percent &&
49657+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49658 cache->bcull_percent < cache->brun_percent &&
49659 cache->brun_percent < 100);
49660
49661diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49662index 0a1467b..6a53245 100644
49663--- a/fs/cachefiles/daemon.c
49664+++ b/fs/cachefiles/daemon.c
49665@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49666 if (n > buflen)
49667 return -EMSGSIZE;
49668
49669- if (copy_to_user(_buffer, buffer, n) != 0)
49670+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49671 return -EFAULT;
49672
49673 return n;
49674@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49675 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49676 return -EIO;
49677
49678- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49679+ if (datalen > PAGE_SIZE - 1)
49680 return -EOPNOTSUPP;
49681
49682 /* drag the command string into the kernel so we can parse it */
49683@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49684 if (args[0] != '%' || args[1] != '\0')
49685 return -EINVAL;
49686
49687- if (fstop < 0 || fstop >= cache->fcull_percent)
49688+ if (fstop >= cache->fcull_percent)
49689 return cachefiles_daemon_range_error(cache, args);
49690
49691 cache->fstop_percent = fstop;
49692@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49693 if (args[0] != '%' || args[1] != '\0')
49694 return -EINVAL;
49695
49696- if (bstop < 0 || bstop >= cache->bcull_percent)
49697+ if (bstop >= cache->bcull_percent)
49698 return cachefiles_daemon_range_error(cache, args);
49699
49700 cache->bstop_percent = bstop;
49701diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49702index 4938251..7e01445 100644
49703--- a/fs/cachefiles/internal.h
49704+++ b/fs/cachefiles/internal.h
49705@@ -59,7 +59,7 @@ struct cachefiles_cache {
49706 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49707 struct rb_root active_nodes; /* active nodes (can't be culled) */
49708 rwlock_t active_lock; /* lock for active_nodes */
49709- atomic_t gravecounter; /* graveyard uniquifier */
49710+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49711 unsigned frun_percent; /* when to stop culling (% files) */
49712 unsigned fcull_percent; /* when to start culling (% files) */
49713 unsigned fstop_percent; /* when to stop allocating (% files) */
49714@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49715 * proc.c
49716 */
49717 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49718-extern atomic_t cachefiles_lookup_histogram[HZ];
49719-extern atomic_t cachefiles_mkdir_histogram[HZ];
49720-extern atomic_t cachefiles_create_histogram[HZ];
49721+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49722+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49723+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49724
49725 extern int __init cachefiles_proc_init(void);
49726 extern void cachefiles_proc_cleanup(void);
49727 static inline
49728-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49729+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49730 {
49731 unsigned long jif = jiffies - start_jif;
49732 if (jif >= HZ)
49733 jif = HZ - 1;
49734- atomic_inc(&histogram[jif]);
49735+ atomic_inc_unchecked(&histogram[jif]);
49736 }
49737
49738 #else
49739diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49740index 8c01c5fc..15f982e 100644
49741--- a/fs/cachefiles/namei.c
49742+++ b/fs/cachefiles/namei.c
49743@@ -317,7 +317,7 @@ try_again:
49744 /* first step is to make up a grave dentry in the graveyard */
49745 sprintf(nbuffer, "%08x%08x",
49746 (uint32_t) get_seconds(),
49747- (uint32_t) atomic_inc_return(&cache->gravecounter));
49748+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49749
49750 /* do the multiway lock magic */
49751 trap = lock_rename(cache->graveyard, dir);
49752diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49753index eccd339..4c1d995 100644
49754--- a/fs/cachefiles/proc.c
49755+++ b/fs/cachefiles/proc.c
49756@@ -14,9 +14,9 @@
49757 #include <linux/seq_file.h>
49758 #include "internal.h"
49759
49760-atomic_t cachefiles_lookup_histogram[HZ];
49761-atomic_t cachefiles_mkdir_histogram[HZ];
49762-atomic_t cachefiles_create_histogram[HZ];
49763+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49764+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49765+atomic_unchecked_t cachefiles_create_histogram[HZ];
49766
49767 /*
49768 * display the latency histogram
49769@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49770 return 0;
49771 default:
49772 index = (unsigned long) v - 3;
49773- x = atomic_read(&cachefiles_lookup_histogram[index]);
49774- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49775- z = atomic_read(&cachefiles_create_histogram[index]);
49776+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49777+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49778+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49779 if (x == 0 && y == 0 && z == 0)
49780 return 0;
49781
49782diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49783index 317f9ee..3d24511 100644
49784--- a/fs/cachefiles/rdwr.c
49785+++ b/fs/cachefiles/rdwr.c
49786@@ -966,7 +966,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49787 old_fs = get_fs();
49788 set_fs(KERNEL_DS);
49789 ret = file->f_op->write(
49790- file, (const void __user *) data, len, &pos);
49791+ file, (const void __force_user *) data, len, &pos);
49792 set_fs(old_fs);
49793 kunmap(page);
49794 file_end_write(file);
49795diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49796index f02d82b..2632cf86 100644
49797--- a/fs/ceph/dir.c
49798+++ b/fs/ceph/dir.c
49799@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49800 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49801 struct ceph_mds_client *mdsc = fsc->mdsc;
49802 unsigned frag = fpos_frag(filp->f_pos);
49803- int off = fpos_off(filp->f_pos);
49804+ unsigned int off = fpos_off(filp->f_pos);
49805 int err;
49806 u32 ftype;
49807 struct ceph_mds_reply_info_parsed *rinfo;
49808diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49809index d597483..747901b 100644
49810--- a/fs/cifs/cifs_debug.c
49811+++ b/fs/cifs/cifs_debug.c
49812@@ -284,8 +284,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49813
49814 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49815 #ifdef CONFIG_CIFS_STATS2
49816- atomic_set(&totBufAllocCount, 0);
49817- atomic_set(&totSmBufAllocCount, 0);
49818+ atomic_set_unchecked(&totBufAllocCount, 0);
49819+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49820 #endif /* CONFIG_CIFS_STATS2 */
49821 spin_lock(&cifs_tcp_ses_lock);
49822 list_for_each(tmp1, &cifs_tcp_ses_list) {
49823@@ -298,7 +298,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49824 tcon = list_entry(tmp3,
49825 struct cifs_tcon,
49826 tcon_list);
49827- atomic_set(&tcon->num_smbs_sent, 0);
49828+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49829 if (server->ops->clear_stats)
49830 server->ops->clear_stats(tcon);
49831 }
49832@@ -330,8 +330,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49833 smBufAllocCount.counter, cifs_min_small);
49834 #ifdef CONFIG_CIFS_STATS2
49835 seq_printf(m, "Total Large %d Small %d Allocations\n",
49836- atomic_read(&totBufAllocCount),
49837- atomic_read(&totSmBufAllocCount));
49838+ atomic_read_unchecked(&totBufAllocCount),
49839+ atomic_read_unchecked(&totSmBufAllocCount));
49840 #endif /* CONFIG_CIFS_STATS2 */
49841
49842 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49843@@ -360,7 +360,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49844 if (tcon->need_reconnect)
49845 seq_puts(m, "\tDISCONNECTED ");
49846 seq_printf(m, "\nSMBs: %d",
49847- atomic_read(&tcon->num_smbs_sent));
49848+ atomic_read_unchecked(&tcon->num_smbs_sent));
49849 if (server->ops->print_stats)
49850 server->ops->print_stats(m, tcon);
49851 }
49852diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49853index 3752b9f..8db5569 100644
49854--- a/fs/cifs/cifsfs.c
49855+++ b/fs/cifs/cifsfs.c
49856@@ -1035,7 +1035,7 @@ cifs_init_request_bufs(void)
49857 */
49858 cifs_req_cachep = kmem_cache_create("cifs_request",
49859 CIFSMaxBufSize + max_hdr_size, 0,
49860- SLAB_HWCACHE_ALIGN, NULL);
49861+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49862 if (cifs_req_cachep == NULL)
49863 return -ENOMEM;
49864
49865@@ -1062,7 +1062,7 @@ cifs_init_request_bufs(void)
49866 efficient to alloc 1 per page off the slab compared to 17K (5page)
49867 alloc of large cifs buffers even when page debugging is on */
49868 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49869- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49870+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49871 NULL);
49872 if (cifs_sm_req_cachep == NULL) {
49873 mempool_destroy(cifs_req_poolp);
49874@@ -1147,8 +1147,8 @@ init_cifs(void)
49875 atomic_set(&bufAllocCount, 0);
49876 atomic_set(&smBufAllocCount, 0);
49877 #ifdef CONFIG_CIFS_STATS2
49878- atomic_set(&totBufAllocCount, 0);
49879- atomic_set(&totSmBufAllocCount, 0);
49880+ atomic_set_unchecked(&totBufAllocCount, 0);
49881+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49882 #endif /* CONFIG_CIFS_STATS2 */
49883
49884 atomic_set(&midCount, 0);
49885diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49886index 4f07f6f..55de8ce 100644
49887--- a/fs/cifs/cifsglob.h
49888+++ b/fs/cifs/cifsglob.h
49889@@ -751,35 +751,35 @@ struct cifs_tcon {
49890 __u16 Flags; /* optional support bits */
49891 enum statusEnum tidStatus;
49892 #ifdef CONFIG_CIFS_STATS
49893- atomic_t num_smbs_sent;
49894+ atomic_unchecked_t num_smbs_sent;
49895 union {
49896 struct {
49897- atomic_t num_writes;
49898- atomic_t num_reads;
49899- atomic_t num_flushes;
49900- atomic_t num_oplock_brks;
49901- atomic_t num_opens;
49902- atomic_t num_closes;
49903- atomic_t num_deletes;
49904- atomic_t num_mkdirs;
49905- atomic_t num_posixopens;
49906- atomic_t num_posixmkdirs;
49907- atomic_t num_rmdirs;
49908- atomic_t num_renames;
49909- atomic_t num_t2renames;
49910- atomic_t num_ffirst;
49911- atomic_t num_fnext;
49912- atomic_t num_fclose;
49913- atomic_t num_hardlinks;
49914- atomic_t num_symlinks;
49915- atomic_t num_locks;
49916- atomic_t num_acl_get;
49917- atomic_t num_acl_set;
49918+ atomic_unchecked_t num_writes;
49919+ atomic_unchecked_t num_reads;
49920+ atomic_unchecked_t num_flushes;
49921+ atomic_unchecked_t num_oplock_brks;
49922+ atomic_unchecked_t num_opens;
49923+ atomic_unchecked_t num_closes;
49924+ atomic_unchecked_t num_deletes;
49925+ atomic_unchecked_t num_mkdirs;
49926+ atomic_unchecked_t num_posixopens;
49927+ atomic_unchecked_t num_posixmkdirs;
49928+ atomic_unchecked_t num_rmdirs;
49929+ atomic_unchecked_t num_renames;
49930+ atomic_unchecked_t num_t2renames;
49931+ atomic_unchecked_t num_ffirst;
49932+ atomic_unchecked_t num_fnext;
49933+ atomic_unchecked_t num_fclose;
49934+ atomic_unchecked_t num_hardlinks;
49935+ atomic_unchecked_t num_symlinks;
49936+ atomic_unchecked_t num_locks;
49937+ atomic_unchecked_t num_acl_get;
49938+ atomic_unchecked_t num_acl_set;
49939 } cifs_stats;
49940 #ifdef CONFIG_CIFS_SMB2
49941 struct {
49942- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49943- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49944+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49945+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49946 } smb2_stats;
49947 #endif /* CONFIG_CIFS_SMB2 */
49948 } stats;
49949@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49950 }
49951
49952 #ifdef CONFIG_CIFS_STATS
49953-#define cifs_stats_inc atomic_inc
49954+#define cifs_stats_inc atomic_inc_unchecked
49955
49956 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49957 unsigned int bytes)
49958@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49959 /* Various Debug counters */
49960 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49961 #ifdef CONFIG_CIFS_STATS2
49962-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49963-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49964+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49965+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49966 #endif
49967 GLOBAL_EXTERN atomic_t smBufAllocCount;
49968 GLOBAL_EXTERN atomic_t midCount;
49969diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49970index b83c3f5..6437caa 100644
49971--- a/fs/cifs/link.c
49972+++ b/fs/cifs/link.c
49973@@ -616,7 +616,7 @@ symlink_exit:
49974
49975 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49976 {
49977- char *p = nd_get_link(nd);
49978+ const char *p = nd_get_link(nd);
49979 if (!IS_ERR(p))
49980 kfree(p);
49981 }
49982diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49983index 1bec014..f329411 100644
49984--- a/fs/cifs/misc.c
49985+++ b/fs/cifs/misc.c
49986@@ -169,7 +169,7 @@ cifs_buf_get(void)
49987 memset(ret_buf, 0, buf_size + 3);
49988 atomic_inc(&bufAllocCount);
49989 #ifdef CONFIG_CIFS_STATS2
49990- atomic_inc(&totBufAllocCount);
49991+ atomic_inc_unchecked(&totBufAllocCount);
49992 #endif /* CONFIG_CIFS_STATS2 */
49993 }
49994
49995@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49996 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49997 atomic_inc(&smBufAllocCount);
49998 #ifdef CONFIG_CIFS_STATS2
49999- atomic_inc(&totSmBufAllocCount);
50000+ atomic_inc_unchecked(&totSmBufAllocCount);
50001 #endif /* CONFIG_CIFS_STATS2 */
50002
50003 }
50004diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
50005index 3efdb9d..e845a5e 100644
50006--- a/fs/cifs/smb1ops.c
50007+++ b/fs/cifs/smb1ops.c
50008@@ -591,27 +591,27 @@ static void
50009 cifs_clear_stats(struct cifs_tcon *tcon)
50010 {
50011 #ifdef CONFIG_CIFS_STATS
50012- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
50013- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
50014- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
50015- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50016- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
50017- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
50018- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50019- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
50020- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
50021- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
50022- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
50023- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
50024- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
50025- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
50026- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
50027- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
50028- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
50029- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
50030- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
50031- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
50032- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
50033+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
50034+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
50035+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
50036+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
50037+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
50038+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
50039+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
50040+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
50041+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
50042+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
50043+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
50044+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
50045+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
50046+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
50047+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
50048+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
50049+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
50050+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
50051+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
50052+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
50053+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
50054 #endif
50055 }
50056
50057@@ -620,36 +620,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50058 {
50059 #ifdef CONFIG_CIFS_STATS
50060 seq_printf(m, " Oplocks breaks: %d",
50061- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
50062+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
50063 seq_printf(m, "\nReads: %d Bytes: %llu",
50064- atomic_read(&tcon->stats.cifs_stats.num_reads),
50065+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
50066 (long long)(tcon->bytes_read));
50067 seq_printf(m, "\nWrites: %d Bytes: %llu",
50068- atomic_read(&tcon->stats.cifs_stats.num_writes),
50069+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
50070 (long long)(tcon->bytes_written));
50071 seq_printf(m, "\nFlushes: %d",
50072- atomic_read(&tcon->stats.cifs_stats.num_flushes));
50073+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
50074 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
50075- atomic_read(&tcon->stats.cifs_stats.num_locks),
50076- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
50077- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
50078+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
50079+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
50080+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
50081 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
50082- atomic_read(&tcon->stats.cifs_stats.num_opens),
50083- atomic_read(&tcon->stats.cifs_stats.num_closes),
50084- atomic_read(&tcon->stats.cifs_stats.num_deletes));
50085+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
50086+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
50087+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
50088 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
50089- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
50090- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
50091+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
50092+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
50093 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
50094- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
50095- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
50096+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
50097+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
50098 seq_printf(m, "\nRenames: %d T2 Renames %d",
50099- atomic_read(&tcon->stats.cifs_stats.num_renames),
50100- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
50101+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
50102+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
50103 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
50104- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
50105- atomic_read(&tcon->stats.cifs_stats.num_fnext),
50106- atomic_read(&tcon->stats.cifs_stats.num_fclose));
50107+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
50108+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
50109+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
50110 #endif
50111 }
50112
50113diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
50114index f2e76f3..c44fac7 100644
50115--- a/fs/cifs/smb2ops.c
50116+++ b/fs/cifs/smb2ops.c
50117@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
50118 #ifdef CONFIG_CIFS_STATS
50119 int i;
50120 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
50121- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50122- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50123+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
50124+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
50125 }
50126 #endif
50127 }
50128@@ -284,66 +284,66 @@ static void
50129 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
50130 {
50131 #ifdef CONFIG_CIFS_STATS
50132- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50133- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50134+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
50135+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
50136 seq_printf(m, "\nNegotiates: %d sent %d failed",
50137- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
50138- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
50139+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
50140+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
50141 seq_printf(m, "\nSessionSetups: %d sent %d failed",
50142- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50143- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50144+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50145+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50146 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50147 seq_printf(m, "\nLogoffs: %d sent %d failed",
50148- atomic_read(&sent[SMB2_LOGOFF_HE]),
50149- atomic_read(&failed[SMB2_LOGOFF_HE]));
50150+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50151+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50152 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50153- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50154- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50155+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50156+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50157 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50158- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50159- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50160+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50161+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50162 seq_printf(m, "\nCreates: %d sent %d failed",
50163- atomic_read(&sent[SMB2_CREATE_HE]),
50164- atomic_read(&failed[SMB2_CREATE_HE]));
50165+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50166+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50167 seq_printf(m, "\nCloses: %d sent %d failed",
50168- atomic_read(&sent[SMB2_CLOSE_HE]),
50169- atomic_read(&failed[SMB2_CLOSE_HE]));
50170+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50171+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50172 seq_printf(m, "\nFlushes: %d sent %d failed",
50173- atomic_read(&sent[SMB2_FLUSH_HE]),
50174- atomic_read(&failed[SMB2_FLUSH_HE]));
50175+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50176+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50177 seq_printf(m, "\nReads: %d sent %d failed",
50178- atomic_read(&sent[SMB2_READ_HE]),
50179- atomic_read(&failed[SMB2_READ_HE]));
50180+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50181+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50182 seq_printf(m, "\nWrites: %d sent %d failed",
50183- atomic_read(&sent[SMB2_WRITE_HE]),
50184- atomic_read(&failed[SMB2_WRITE_HE]));
50185+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50186+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50187 seq_printf(m, "\nLocks: %d sent %d failed",
50188- atomic_read(&sent[SMB2_LOCK_HE]),
50189- atomic_read(&failed[SMB2_LOCK_HE]));
50190+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50191+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50192 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50193- atomic_read(&sent[SMB2_IOCTL_HE]),
50194- atomic_read(&failed[SMB2_IOCTL_HE]));
50195+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50196+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50197 seq_printf(m, "\nCancels: %d sent %d failed",
50198- atomic_read(&sent[SMB2_CANCEL_HE]),
50199- atomic_read(&failed[SMB2_CANCEL_HE]));
50200+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50201+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50202 seq_printf(m, "\nEchos: %d sent %d failed",
50203- atomic_read(&sent[SMB2_ECHO_HE]),
50204- atomic_read(&failed[SMB2_ECHO_HE]));
50205+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50206+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50207 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50208- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50209- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50210+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50211+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50212 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50213- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50214- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50215+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50216+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50217 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50218- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50219- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50220+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50221+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50222 seq_printf(m, "\nSetInfos: %d sent %d failed",
50223- atomic_read(&sent[SMB2_SET_INFO_HE]),
50224- atomic_read(&failed[SMB2_SET_INFO_HE]));
50225+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50226+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50227 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50228- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50229- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50230+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50231+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50232 #endif
50233 }
50234
50235diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50236index 2b95ce2..d079d75 100644
50237--- a/fs/cifs/smb2pdu.c
50238+++ b/fs/cifs/smb2pdu.c
50239@@ -1760,8 +1760,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50240 default:
50241 cifs_dbg(VFS, "info level %u isn't supported\n",
50242 srch_inf->info_level);
50243- rc = -EINVAL;
50244- goto qdir_exit;
50245+ return -EINVAL;
50246 }
50247
50248 req->FileIndex = cpu_to_le32(index);
50249diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50250index 1da168c..8bc7ff6 100644
50251--- a/fs/coda/cache.c
50252+++ b/fs/coda/cache.c
50253@@ -24,7 +24,7 @@
50254 #include "coda_linux.h"
50255 #include "coda_cache.h"
50256
50257-static atomic_t permission_epoch = ATOMIC_INIT(0);
50258+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50259
50260 /* replace or extend an acl cache hit */
50261 void coda_cache_enter(struct inode *inode, int mask)
50262@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50263 struct coda_inode_info *cii = ITOC(inode);
50264
50265 spin_lock(&cii->c_lock);
50266- cii->c_cached_epoch = atomic_read(&permission_epoch);
50267+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50268 if (!uid_eq(cii->c_uid, current_fsuid())) {
50269 cii->c_uid = current_fsuid();
50270 cii->c_cached_perm = mask;
50271@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50272 {
50273 struct coda_inode_info *cii = ITOC(inode);
50274 spin_lock(&cii->c_lock);
50275- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50276+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50277 spin_unlock(&cii->c_lock);
50278 }
50279
50280 /* remove all acl caches */
50281 void coda_cache_clear_all(struct super_block *sb)
50282 {
50283- atomic_inc(&permission_epoch);
50284+ atomic_inc_unchecked(&permission_epoch);
50285 }
50286
50287
50288@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50289 spin_lock(&cii->c_lock);
50290 hit = (mask & cii->c_cached_perm) == mask &&
50291 uid_eq(cii->c_uid, current_fsuid()) &&
50292- cii->c_cached_epoch == atomic_read(&permission_epoch);
50293+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50294 spin_unlock(&cii->c_lock);
50295
50296 return hit;
50297diff --git a/fs/compat.c b/fs/compat.c
50298index fc3b55d..7b568ae 100644
50299--- a/fs/compat.c
50300+++ b/fs/compat.c
50301@@ -54,7 +54,7 @@
50302 #include <asm/ioctls.h>
50303 #include "internal.h"
50304
50305-int compat_log = 1;
50306+int compat_log = 0;
50307
50308 int compat_printk(const char *fmt, ...)
50309 {
50310@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50311
50312 set_fs(KERNEL_DS);
50313 /* The __user pointer cast is valid because of the set_fs() */
50314- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50315+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50316 set_fs(oldfs);
50317 /* truncating is ok because it's a user address */
50318 if (!ret)
50319@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50320 goto out;
50321
50322 ret = -EINVAL;
50323- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50324+ if (nr_segs > UIO_MAXIOV)
50325 goto out;
50326 if (nr_segs > fast_segs) {
50327 ret = -ENOMEM;
50328@@ -833,6 +833,7 @@ struct compat_old_linux_dirent {
50329
50330 struct compat_readdir_callback {
50331 struct compat_old_linux_dirent __user *dirent;
50332+ struct file * file;
50333 int result;
50334 };
50335
50336@@ -850,6 +851,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50337 buf->result = -EOVERFLOW;
50338 return -EOVERFLOW;
50339 }
50340+
50341+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50342+ return 0;
50343+
50344 buf->result++;
50345 dirent = buf->dirent;
50346 if (!access_ok(VERIFY_WRITE, dirent,
50347@@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50348
50349 buf.result = 0;
50350 buf.dirent = dirent;
50351+ buf.file = f.file;
50352
50353 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50354 if (buf.result)
50355@@ -899,6 +905,7 @@ struct compat_linux_dirent {
50356 struct compat_getdents_callback {
50357 struct compat_linux_dirent __user *current_dir;
50358 struct compat_linux_dirent __user *previous;
50359+ struct file * file;
50360 int count;
50361 int error;
50362 };
50363@@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50364 buf->error = -EOVERFLOW;
50365 return -EOVERFLOW;
50366 }
50367+
50368+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50369+ return 0;
50370+
50371 dirent = buf->previous;
50372 if (dirent) {
50373 if (__put_user(offset, &dirent->d_off))
50374@@ -965,6 +976,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50375 buf.previous = NULL;
50376 buf.count = count;
50377 buf.error = 0;
50378+ buf.file = f.file;
50379
50380 error = vfs_readdir(f.file, compat_filldir, &buf);
50381 if (error >= 0)
50382@@ -985,6 +997,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50383 struct compat_getdents_callback64 {
50384 struct linux_dirent64 __user *current_dir;
50385 struct linux_dirent64 __user *previous;
50386+ struct file * file;
50387 int count;
50388 int error;
50389 };
50390@@ -1001,6 +1014,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50391 buf->error = -EINVAL; /* only used if we fail.. */
50392 if (reclen > buf->count)
50393 return -EINVAL;
50394+
50395+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50396+ return 0;
50397+
50398 dirent = buf->previous;
50399
50400 if (dirent) {
50401@@ -1050,13 +1067,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50402 buf.previous = NULL;
50403 buf.count = count;
50404 buf.error = 0;
50405+ buf.file = f.file;
50406
50407 error = vfs_readdir(f.file, compat_filldir64, &buf);
50408 if (error >= 0)
50409 error = buf.error;
50410 lastdirent = buf.previous;
50411 if (lastdirent) {
50412- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50413+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50414 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50415 error = -EFAULT;
50416 else
50417diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50418index a81147e..20bf2b5 100644
50419--- a/fs/compat_binfmt_elf.c
50420+++ b/fs/compat_binfmt_elf.c
50421@@ -30,11 +30,13 @@
50422 #undef elf_phdr
50423 #undef elf_shdr
50424 #undef elf_note
50425+#undef elf_dyn
50426 #undef elf_addr_t
50427 #define elfhdr elf32_hdr
50428 #define elf_phdr elf32_phdr
50429 #define elf_shdr elf32_shdr
50430 #define elf_note elf32_note
50431+#define elf_dyn Elf32_Dyn
50432 #define elf_addr_t Elf32_Addr
50433
50434 /*
50435diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50436index 996cdc5..15e2f33 100644
50437--- a/fs/compat_ioctl.c
50438+++ b/fs/compat_ioctl.c
50439@@ -622,7 +622,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50440 return -EFAULT;
50441 if (__get_user(udata, &ss32->iomem_base))
50442 return -EFAULT;
50443- ss.iomem_base = compat_ptr(udata);
50444+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50445 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50446 __get_user(ss.port_high, &ss32->port_high))
50447 return -EFAULT;
50448@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
50449 for (i = 0; i < nmsgs; i++) {
50450 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
50451 return -EFAULT;
50452- if (get_user(datap, &umsgs[i].buf) ||
50453- put_user(compat_ptr(datap), &tmsgs[i].buf))
50454+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
50455+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
50456 return -EFAULT;
50457 }
50458 return sys_ioctl(fd, cmd, (unsigned long)tdata);
50459@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
50460 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50461 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50462 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50463- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50464+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50465 return -EFAULT;
50466
50467 return ioctl_preallocate(file, p);
50468@@ -1619,8 +1619,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50469 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50470 {
50471 unsigned int a, b;
50472- a = *(unsigned int *)p;
50473- b = *(unsigned int *)q;
50474+ a = *(const unsigned int *)p;
50475+ b = *(const unsigned int *)q;
50476 if (a > b)
50477 return 1;
50478 if (a < b)
50479diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50480index 7aabc6a..34c1197 100644
50481--- a/fs/configfs/dir.c
50482+++ b/fs/configfs/dir.c
50483@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50484 }
50485 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50486 struct configfs_dirent *next;
50487- const char * name;
50488+ const unsigned char * name;
50489+ char d_name[sizeof(next->s_dentry->d_iname)];
50490 int len;
50491 struct inode *inode = NULL;
50492
50493@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50494 continue;
50495
50496 name = configfs_get_name(next);
50497- len = strlen(name);
50498+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50499+ len = next->s_dentry->d_name.len;
50500+ memcpy(d_name, name, len);
50501+ name = d_name;
50502+ } else
50503+ len = strlen(name);
50504
50505 /*
50506 * We'll have a dentry and an inode for
50507diff --git a/fs/coredump.c b/fs/coredump.c
50508index dafafba..10b3b27 100644
50509--- a/fs/coredump.c
50510+++ b/fs/coredump.c
50511@@ -52,7 +52,7 @@ struct core_name {
50512 char *corename;
50513 int used, size;
50514 };
50515-static atomic_t call_count = ATOMIC_INIT(1);
50516+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50517
50518 /* The maximal length of core_pattern is also specified in sysctl.c */
50519
50520@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50521 {
50522 char *old_corename = cn->corename;
50523
50524- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50525+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50526 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50527
50528 if (!cn->corename) {
50529@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50530 int pid_in_pattern = 0;
50531 int err = 0;
50532
50533- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50534+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50535 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50536 cn->used = 0;
50537
50538@@ -435,8 +435,8 @@ static void wait_for_dump_helpers(struct file *file)
50539 struct pipe_inode_info *pipe = file->private_data;
50540
50541 pipe_lock(pipe);
50542- pipe->readers++;
50543- pipe->writers--;
50544+ atomic_inc(&pipe->readers);
50545+ atomic_dec(&pipe->writers);
50546 wake_up_interruptible_sync(&pipe->wait);
50547 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50548 pipe_unlock(pipe);
50549@@ -445,11 +445,11 @@ static void wait_for_dump_helpers(struct file *file)
50550 * We actually want wait_event_freezable() but then we need
50551 * to clear TIF_SIGPENDING and improve dump_interrupted().
50552 */
50553- wait_event_interruptible(pipe->wait, pipe->readers == 1);
50554+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
50555
50556 pipe_lock(pipe);
50557- pipe->readers--;
50558- pipe->writers++;
50559+ atomic_dec(&pipe->readers);
50560+ atomic_inc(&pipe->writers);
50561 pipe_unlock(pipe);
50562 }
50563
50564@@ -496,7 +496,8 @@ void do_coredump(siginfo_t *siginfo)
50565 struct files_struct *displaced;
50566 bool need_nonrelative = false;
50567 bool core_dumped = false;
50568- static atomic_t core_dump_count = ATOMIC_INIT(0);
50569+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50570+ long signr = siginfo->si_signo;
50571 struct coredump_params cprm = {
50572 .siginfo = siginfo,
50573 .regs = signal_pt_regs(),
50574@@ -509,7 +510,10 @@ void do_coredump(siginfo_t *siginfo)
50575 .mm_flags = mm->flags,
50576 };
50577
50578- audit_core_dumps(siginfo->si_signo);
50579+ audit_core_dumps(signr);
50580+
50581+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50582+ gr_handle_brute_attach(cprm.mm_flags);
50583
50584 binfmt = mm->binfmt;
50585 if (!binfmt || !binfmt->core_dump)
50586@@ -533,7 +537,7 @@ void do_coredump(siginfo_t *siginfo)
50587 need_nonrelative = true;
50588 }
50589
50590- retval = coredump_wait(siginfo->si_signo, &core_state);
50591+ retval = coredump_wait(signr, &core_state);
50592 if (retval < 0)
50593 goto fail_creds;
50594
50595@@ -576,7 +580,7 @@ void do_coredump(siginfo_t *siginfo)
50596 }
50597 cprm.limit = RLIM_INFINITY;
50598
50599- dump_count = atomic_inc_return(&core_dump_count);
50600+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50601 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50602 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50603 task_tgid_vnr(current), current->comm);
50604@@ -608,6 +612,8 @@ void do_coredump(siginfo_t *siginfo)
50605 } else {
50606 struct inode *inode;
50607
50608+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50609+
50610 if (cprm.limit < binfmt->min_coredump)
50611 goto fail_unlock;
50612
50613@@ -666,7 +672,7 @@ close_fail:
50614 filp_close(cprm.file, NULL);
50615 fail_dropcount:
50616 if (ispipe)
50617- atomic_dec(&core_dump_count);
50618+ atomic_dec_unchecked(&core_dump_count);
50619 fail_unlock:
50620 kfree(cn.corename);
50621 fail_corename:
50622@@ -687,7 +693,7 @@ int dump_write(struct file *file, const void *addr, int nr)
50623 {
50624 return !dump_interrupted() &&
50625 access_ok(VERIFY_READ, addr, nr) &&
50626- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50627+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50628 }
50629 EXPORT_SYMBOL(dump_write);
50630
50631diff --git a/fs/dcache.c b/fs/dcache.c
50632index f09b908..4dd10d8 100644
50633--- a/fs/dcache.c
50634+++ b/fs/dcache.c
50635@@ -3086,7 +3086,7 @@ void __init vfs_caches_init(unsigned long mempages)
50636 mempages -= reserve;
50637
50638 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50639- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50640+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50641
50642 dcache_init();
50643 inode_init();
50644diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50645index 4888cb3..e0f7cf8 100644
50646--- a/fs/debugfs/inode.c
50647+++ b/fs/debugfs/inode.c
50648@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50649 */
50650 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50651 {
50652+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50653+ return __create_file(name, S_IFDIR | S_IRWXU,
50654+#else
50655 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50656+#endif
50657 parent, NULL, NULL);
50658 }
50659 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50660diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50661index 5eab400..810a3f5 100644
50662--- a/fs/ecryptfs/inode.c
50663+++ b/fs/ecryptfs/inode.c
50664@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50665 old_fs = get_fs();
50666 set_fs(get_ds());
50667 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50668- (char __user *)lower_buf,
50669+ (char __force_user *)lower_buf,
50670 PATH_MAX);
50671 set_fs(old_fs);
50672 if (rc < 0)
50673@@ -706,7 +706,7 @@ out:
50674 static void
50675 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50676 {
50677- char *buf = nd_get_link(nd);
50678+ const char *buf = nd_get_link(nd);
50679 if (!IS_ERR(buf)) {
50680 /* Free the char* */
50681 kfree(buf);
50682diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50683index e4141f2..d8263e8 100644
50684--- a/fs/ecryptfs/miscdev.c
50685+++ b/fs/ecryptfs/miscdev.c
50686@@ -304,7 +304,7 @@ check_list:
50687 goto out_unlock_msg_ctx;
50688 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50689 if (msg_ctx->msg) {
50690- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50691+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50692 goto out_unlock_msg_ctx;
50693 i += packet_length_size;
50694 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50695diff --git a/fs/exec.c b/fs/exec.c
50696index ffd7a81..e38107f 100644
50697--- a/fs/exec.c
50698+++ b/fs/exec.c
50699@@ -55,8 +55,20 @@
50700 #include <linux/pipe_fs_i.h>
50701 #include <linux/oom.h>
50702 #include <linux/compat.h>
50703+#include <linux/random.h>
50704+#include <linux/seq_file.h>
50705+#include <linux/coredump.h>
50706+#include <linux/mman.h>
50707+
50708+#ifdef CONFIG_PAX_REFCOUNT
50709+#include <linux/kallsyms.h>
50710+#include <linux/kdebug.h>
50711+#endif
50712+
50713+#include <trace/events/fs.h>
50714
50715 #include <asm/uaccess.h>
50716+#include <asm/sections.h>
50717 #include <asm/mmu_context.h>
50718 #include <asm/tlb.h>
50719
50720@@ -66,17 +78,32 @@
50721
50722 #include <trace/events/sched.h>
50723
50724+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50725+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50726+{
50727+ 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");
50728+}
50729+#endif
50730+
50731+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50732+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50733+EXPORT_SYMBOL(pax_set_initial_flags_func);
50734+#endif
50735+
50736 int suid_dumpable = 0;
50737
50738 static LIST_HEAD(formats);
50739 static DEFINE_RWLOCK(binfmt_lock);
50740
50741+extern int gr_process_kernel_exec_ban(void);
50742+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
50743+
50744 void __register_binfmt(struct linux_binfmt * fmt, int insert)
50745 {
50746 BUG_ON(!fmt);
50747 write_lock(&binfmt_lock);
50748- insert ? list_add(&fmt->lh, &formats) :
50749- list_add_tail(&fmt->lh, &formats);
50750+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50751+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50752 write_unlock(&binfmt_lock);
50753 }
50754
50755@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
50756 void unregister_binfmt(struct linux_binfmt * fmt)
50757 {
50758 write_lock(&binfmt_lock);
50759- list_del(&fmt->lh);
50760+ pax_list_del((struct list_head *)&fmt->lh);
50761 write_unlock(&binfmt_lock);
50762 }
50763
50764@@ -180,18 +207,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50765 int write)
50766 {
50767 struct page *page;
50768- int ret;
50769
50770-#ifdef CONFIG_STACK_GROWSUP
50771- if (write) {
50772- ret = expand_downwards(bprm->vma, pos);
50773- if (ret < 0)
50774- return NULL;
50775- }
50776-#endif
50777- ret = get_user_pages(current, bprm->mm, pos,
50778- 1, write, 1, &page, NULL);
50779- if (ret <= 0)
50780+ if (0 > expand_downwards(bprm->vma, pos))
50781+ return NULL;
50782+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50783 return NULL;
50784
50785 if (write) {
50786@@ -207,6 +226,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50787 if (size <= ARG_MAX)
50788 return page;
50789
50790+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50791+ // only allow 512KB for argv+env on suid/sgid binaries
50792+ // to prevent easy ASLR exhaustion
50793+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50794+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50795+ (size > (512 * 1024))) {
50796+ put_page(page);
50797+ return NULL;
50798+ }
50799+#endif
50800+
50801 /*
50802 * Limit to 1/4-th the stack size for the argv+env strings.
50803 * This ensures that:
50804@@ -266,6 +296,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50805 vma->vm_end = STACK_TOP_MAX;
50806 vma->vm_start = vma->vm_end - PAGE_SIZE;
50807 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50808+
50809+#ifdef CONFIG_PAX_SEGMEXEC
50810+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50811+#endif
50812+
50813 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50814 INIT_LIST_HEAD(&vma->anon_vma_chain);
50815
50816@@ -276,6 +311,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50817 mm->stack_vm = mm->total_vm = 1;
50818 up_write(&mm->mmap_sem);
50819 bprm->p = vma->vm_end - sizeof(void *);
50820+
50821+#ifdef CONFIG_PAX_RANDUSTACK
50822+ if (randomize_va_space)
50823+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
50824+#endif
50825+
50826 return 0;
50827 err:
50828 up_write(&mm->mmap_sem);
50829@@ -396,7 +437,7 @@ struct user_arg_ptr {
50830 } ptr;
50831 };
50832
50833-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50834+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50835 {
50836 const char __user *native;
50837
50838@@ -405,14 +446,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50839 compat_uptr_t compat;
50840
50841 if (get_user(compat, argv.ptr.compat + nr))
50842- return ERR_PTR(-EFAULT);
50843+ return (const char __force_user *)ERR_PTR(-EFAULT);
50844
50845 return compat_ptr(compat);
50846 }
50847 #endif
50848
50849 if (get_user(native, argv.ptr.native + nr))
50850- return ERR_PTR(-EFAULT);
50851+ return (const char __force_user *)ERR_PTR(-EFAULT);
50852
50853 return native;
50854 }
50855@@ -431,7 +472,7 @@ static int count(struct user_arg_ptr argv, int max)
50856 if (!p)
50857 break;
50858
50859- if (IS_ERR(p))
50860+ if (IS_ERR((const char __force_kernel *)p))
50861 return -EFAULT;
50862
50863 if (i >= max)
50864@@ -466,7 +507,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50865
50866 ret = -EFAULT;
50867 str = get_user_arg_ptr(argv, argc);
50868- if (IS_ERR(str))
50869+ if (IS_ERR((const char __force_kernel *)str))
50870 goto out;
50871
50872 len = strnlen_user(str, MAX_ARG_STRLEN);
50873@@ -548,7 +589,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50874 int r;
50875 mm_segment_t oldfs = get_fs();
50876 struct user_arg_ptr argv = {
50877- .ptr.native = (const char __user *const __user *)__argv,
50878+ .ptr.native = (const char __force_user * const __force_user *)__argv,
50879 };
50880
50881 set_fs(KERNEL_DS);
50882@@ -583,7 +624,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50883 unsigned long new_end = old_end - shift;
50884 struct mmu_gather tlb;
50885
50886- BUG_ON(new_start > new_end);
50887+ if (new_start >= new_end || new_start < mmap_min_addr)
50888+ return -ENOMEM;
50889
50890 /*
50891 * ensure there are no vmas between where we want to go
50892@@ -592,6 +634,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50893 if (vma != find_vma(mm, new_start))
50894 return -EFAULT;
50895
50896+#ifdef CONFIG_PAX_SEGMEXEC
50897+ BUG_ON(pax_find_mirror_vma(vma));
50898+#endif
50899+
50900 /*
50901 * cover the whole range: [new_start, old_end)
50902 */
50903@@ -672,10 +718,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50904 stack_top = arch_align_stack(stack_top);
50905 stack_top = PAGE_ALIGN(stack_top);
50906
50907- if (unlikely(stack_top < mmap_min_addr) ||
50908- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50909- return -ENOMEM;
50910-
50911 stack_shift = vma->vm_end - stack_top;
50912
50913 bprm->p -= stack_shift;
50914@@ -687,8 +729,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50915 bprm->exec -= stack_shift;
50916
50917 down_write(&mm->mmap_sem);
50918+
50919+ /* Move stack pages down in memory. */
50920+ if (stack_shift) {
50921+ ret = shift_arg_pages(vma, stack_shift);
50922+ if (ret)
50923+ goto out_unlock;
50924+ }
50925+
50926 vm_flags = VM_STACK_FLAGS;
50927
50928+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50929+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50930+ vm_flags &= ~VM_EXEC;
50931+
50932+#ifdef CONFIG_PAX_MPROTECT
50933+ if (mm->pax_flags & MF_PAX_MPROTECT)
50934+ vm_flags &= ~VM_MAYEXEC;
50935+#endif
50936+
50937+ }
50938+#endif
50939+
50940 /*
50941 * Adjust stack execute permissions; explicitly enable for
50942 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50943@@ -707,13 +769,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50944 goto out_unlock;
50945 BUG_ON(prev != vma);
50946
50947- /* Move stack pages down in memory. */
50948- if (stack_shift) {
50949- ret = shift_arg_pages(vma, stack_shift);
50950- if (ret)
50951- goto out_unlock;
50952- }
50953-
50954 /* mprotect_fixup is overkill to remove the temporary stack flags */
50955 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50956
50957@@ -737,6 +792,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50958 #endif
50959 current->mm->start_stack = bprm->p;
50960 ret = expand_stack(vma, stack_base);
50961+
50962+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50963+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50964+ unsigned long size;
50965+ vm_flags_t vm_flags;
50966+
50967+ size = STACK_TOP - vma->vm_end;
50968+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50969+
50970+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
50971+
50972+#ifdef CONFIG_X86
50973+ if (!ret) {
50974+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50975+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
50976+ }
50977+#endif
50978+
50979+ }
50980+#endif
50981+
50982 if (ret)
50983 ret = -EFAULT;
50984
50985@@ -772,6 +848,8 @@ struct file *open_exec(const char *name)
50986
50987 fsnotify_open(file);
50988
50989+ trace_open_exec(name);
50990+
50991 err = deny_write_access(file);
50992 if (err)
50993 goto exit;
50994@@ -795,7 +873,7 @@ int kernel_read(struct file *file, loff_t offset,
50995 old_fs = get_fs();
50996 set_fs(get_ds());
50997 /* The cast to a user pointer is valid due to the set_fs() */
50998- result = vfs_read(file, (void __user *)addr, count, &pos);
50999+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
51000 set_fs(old_fs);
51001 return result;
51002 }
51003@@ -1251,7 +1329,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
51004 }
51005 rcu_read_unlock();
51006
51007- if (p->fs->users > n_fs) {
51008+ if (atomic_read(&p->fs->users) > n_fs) {
51009 bprm->unsafe |= LSM_UNSAFE_SHARE;
51010 } else {
51011 res = -EAGAIN;
51012@@ -1451,6 +1529,31 @@ int search_binary_handler(struct linux_binprm *bprm)
51013
51014 EXPORT_SYMBOL(search_binary_handler);
51015
51016+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51017+static DEFINE_PER_CPU(u64, exec_counter);
51018+static int __init init_exec_counters(void)
51019+{
51020+ unsigned int cpu;
51021+
51022+ for_each_possible_cpu(cpu) {
51023+ per_cpu(exec_counter, cpu) = (u64)cpu;
51024+ }
51025+
51026+ return 0;
51027+}
51028+early_initcall(init_exec_counters);
51029+static inline void increment_exec_counter(void)
51030+{
51031+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
51032+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
51033+}
51034+#else
51035+static inline void increment_exec_counter(void) {}
51036+#endif
51037+
51038+extern void gr_handle_exec_args(struct linux_binprm *bprm,
51039+ struct user_arg_ptr argv);
51040+
51041 /*
51042 * sys_execve() executes a new program.
51043 */
51044@@ -1458,6 +1561,11 @@ static int do_execve_common(const char *filename,
51045 struct user_arg_ptr argv,
51046 struct user_arg_ptr envp)
51047 {
51048+#ifdef CONFIG_GRKERNSEC
51049+ struct file *old_exec_file;
51050+ struct acl_subject_label *old_acl;
51051+ struct rlimit old_rlim[RLIM_NLIMITS];
51052+#endif
51053 struct linux_binprm *bprm;
51054 struct file *file;
51055 struct files_struct *displaced;
51056@@ -1465,6 +1573,8 @@ static int do_execve_common(const char *filename,
51057 int retval;
51058 const struct cred *cred = current_cred();
51059
51060+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
51061+
51062 /*
51063 * We move the actual failure in case of RLIMIT_NPROC excess from
51064 * set*uid() to execve() because too many poorly written programs
51065@@ -1505,12 +1615,22 @@ static int do_execve_common(const char *filename,
51066 if (IS_ERR(file))
51067 goto out_unmark;
51068
51069+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
51070+ retval = -EPERM;
51071+ goto out_file;
51072+ }
51073+
51074 sched_exec();
51075
51076 bprm->file = file;
51077 bprm->filename = filename;
51078 bprm->interp = filename;
51079
51080+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
51081+ retval = -EACCES;
51082+ goto out_file;
51083+ }
51084+
51085 retval = bprm_mm_init(bprm);
51086 if (retval)
51087 goto out_file;
51088@@ -1527,24 +1647,70 @@ static int do_execve_common(const char *filename,
51089 if (retval < 0)
51090 goto out;
51091
51092+#ifdef CONFIG_GRKERNSEC
51093+ old_acl = current->acl;
51094+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
51095+ old_exec_file = current->exec_file;
51096+ get_file(file);
51097+ current->exec_file = file;
51098+#endif
51099+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51100+ /* limit suid stack to 8MB
51101+ * we saved the old limits above and will restore them if this exec fails
51102+ */
51103+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51104+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51105+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51106+#endif
51107+
51108+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
51109+ retval = -EPERM;
51110+ goto out_fail;
51111+ }
51112+
51113+ if (!gr_tpe_allow(file)) {
51114+ retval = -EACCES;
51115+ goto out_fail;
51116+ }
51117+
51118+ if (gr_check_crash_exec(file)) {
51119+ retval = -EACCES;
51120+ goto out_fail;
51121+ }
51122+
51123+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
51124+ bprm->unsafe);
51125+ if (retval < 0)
51126+ goto out_fail;
51127+
51128 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51129 if (retval < 0)
51130- goto out;
51131+ goto out_fail;
51132
51133 bprm->exec = bprm->p;
51134 retval = copy_strings(bprm->envc, envp, bprm);
51135 if (retval < 0)
51136- goto out;
51137+ goto out_fail;
51138
51139 retval = copy_strings(bprm->argc, argv, bprm);
51140 if (retval < 0)
51141- goto out;
51142+ goto out_fail;
51143+
51144+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
51145+
51146+ gr_handle_exec_args(bprm, argv);
51147
51148 retval = search_binary_handler(bprm);
51149 if (retval < 0)
51150- goto out;
51151+ goto out_fail;
51152+#ifdef CONFIG_GRKERNSEC
51153+ if (old_exec_file)
51154+ fput(old_exec_file);
51155+#endif
51156
51157 /* execve succeeded */
51158+
51159+ increment_exec_counter();
51160 current->fs->in_exec = 0;
51161 current->in_execve = 0;
51162 acct_update_integrals(current);
51163@@ -1553,6 +1719,14 @@ static int do_execve_common(const char *filename,
51164 put_files_struct(displaced);
51165 return retval;
51166
51167+out_fail:
51168+#ifdef CONFIG_GRKERNSEC
51169+ current->acl = old_acl;
51170+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51171+ fput(current->exec_file);
51172+ current->exec_file = old_exec_file;
51173+#endif
51174+
51175 out:
51176 if (bprm->mm) {
51177 acct_arg_size(bprm, 0);
51178@@ -1701,3 +1875,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51179 return error;
51180 }
51181 #endif
51182+
51183+int pax_check_flags(unsigned long *flags)
51184+{
51185+ int retval = 0;
51186+
51187+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51188+ if (*flags & MF_PAX_SEGMEXEC)
51189+ {
51190+ *flags &= ~MF_PAX_SEGMEXEC;
51191+ retval = -EINVAL;
51192+ }
51193+#endif
51194+
51195+ if ((*flags & MF_PAX_PAGEEXEC)
51196+
51197+#ifdef CONFIG_PAX_PAGEEXEC
51198+ && (*flags & MF_PAX_SEGMEXEC)
51199+#endif
51200+
51201+ )
51202+ {
51203+ *flags &= ~MF_PAX_PAGEEXEC;
51204+ retval = -EINVAL;
51205+ }
51206+
51207+ if ((*flags & MF_PAX_MPROTECT)
51208+
51209+#ifdef CONFIG_PAX_MPROTECT
51210+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51211+#endif
51212+
51213+ )
51214+ {
51215+ *flags &= ~MF_PAX_MPROTECT;
51216+ retval = -EINVAL;
51217+ }
51218+
51219+ if ((*flags & MF_PAX_EMUTRAMP)
51220+
51221+#ifdef CONFIG_PAX_EMUTRAMP
51222+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51223+#endif
51224+
51225+ )
51226+ {
51227+ *flags &= ~MF_PAX_EMUTRAMP;
51228+ retval = -EINVAL;
51229+ }
51230+
51231+ return retval;
51232+}
51233+
51234+EXPORT_SYMBOL(pax_check_flags);
51235+
51236+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51237+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51238+{
51239+ struct task_struct *tsk = current;
51240+ struct mm_struct *mm = current->mm;
51241+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51242+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51243+ char *path_exec = NULL;
51244+ char *path_fault = NULL;
51245+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51246+ siginfo_t info = { };
51247+
51248+ if (buffer_exec && buffer_fault) {
51249+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51250+
51251+ down_read(&mm->mmap_sem);
51252+ vma = mm->mmap;
51253+ while (vma && (!vma_exec || !vma_fault)) {
51254+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51255+ vma_exec = vma;
51256+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51257+ vma_fault = vma;
51258+ vma = vma->vm_next;
51259+ }
51260+ if (vma_exec) {
51261+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51262+ if (IS_ERR(path_exec))
51263+ path_exec = "<path too long>";
51264+ else {
51265+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51266+ if (path_exec) {
51267+ *path_exec = 0;
51268+ path_exec = buffer_exec;
51269+ } else
51270+ path_exec = "<path too long>";
51271+ }
51272+ }
51273+ if (vma_fault) {
51274+ start = vma_fault->vm_start;
51275+ end = vma_fault->vm_end;
51276+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51277+ if (vma_fault->vm_file) {
51278+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51279+ if (IS_ERR(path_fault))
51280+ path_fault = "<path too long>";
51281+ else {
51282+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51283+ if (path_fault) {
51284+ *path_fault = 0;
51285+ path_fault = buffer_fault;
51286+ } else
51287+ path_fault = "<path too long>";
51288+ }
51289+ } else
51290+ path_fault = "<anonymous mapping>";
51291+ }
51292+ up_read(&mm->mmap_sem);
51293+ }
51294+ if (tsk->signal->curr_ip)
51295+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51296+ else
51297+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51298+ 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),
51299+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51300+ free_page((unsigned long)buffer_exec);
51301+ free_page((unsigned long)buffer_fault);
51302+ pax_report_insns(regs, pc, sp);
51303+ info.si_signo = SIGKILL;
51304+ info.si_errno = 0;
51305+ info.si_code = SI_KERNEL;
51306+ info.si_pid = 0;
51307+ info.si_uid = 0;
51308+ do_coredump(&info);
51309+}
51310+#endif
51311+
51312+#ifdef CONFIG_PAX_REFCOUNT
51313+void pax_report_refcount_overflow(struct pt_regs *regs)
51314+{
51315+ if (current->signal->curr_ip)
51316+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51317+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51318+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51319+ else
51320+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51321+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51322+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51323+ show_regs(regs);
51324+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51325+}
51326+#endif
51327+
51328+#ifdef CONFIG_PAX_USERCOPY
51329+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51330+static noinline int check_stack_object(const void *obj, unsigned long len)
51331+{
51332+ const void * const stack = task_stack_page(current);
51333+ const void * const stackend = stack + THREAD_SIZE;
51334+
51335+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51336+ const void *frame = NULL;
51337+ const void *oldframe;
51338+#endif
51339+
51340+ if (obj + len < obj)
51341+ return -1;
51342+
51343+ if (obj + len <= stack || stackend <= obj)
51344+ return 0;
51345+
51346+ if (obj < stack || stackend < obj + len)
51347+ return -1;
51348+
51349+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51350+ oldframe = __builtin_frame_address(1);
51351+ if (oldframe)
51352+ frame = __builtin_frame_address(2);
51353+ /*
51354+ low ----------------------------------------------> high
51355+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51356+ ^----------------^
51357+ allow copies only within here
51358+ */
51359+ while (stack <= frame && frame < stackend) {
51360+ /* if obj + len extends past the last frame, this
51361+ check won't pass and the next frame will be 0,
51362+ causing us to bail out and correctly report
51363+ the copy as invalid
51364+ */
51365+ if (obj + len <= frame)
51366+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51367+ oldframe = frame;
51368+ frame = *(const void * const *)frame;
51369+ }
51370+ return -1;
51371+#else
51372+ return 1;
51373+#endif
51374+}
51375+
51376+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51377+{
51378+ if (current->signal->curr_ip)
51379+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51380+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51381+ else
51382+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51383+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51384+ dump_stack();
51385+ gr_handle_kernel_exploit();
51386+ do_group_exit(SIGKILL);
51387+}
51388+#endif
51389+
51390+#ifdef CONFIG_PAX_USERCOPY
51391+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51392+{
51393+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51394+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51395+#ifdef CONFIG_MODULES
51396+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
51397+#else
51398+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51399+#endif
51400+
51401+#else
51402+ unsigned long textlow = (unsigned long)_stext;
51403+ unsigned long texthigh = (unsigned long)_etext;
51404+#endif
51405+
51406+ if (high <= textlow || low > texthigh)
51407+ return false;
51408+ else
51409+ return true;
51410+}
51411+#endif
51412+
51413+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51414+{
51415+
51416+#ifdef CONFIG_PAX_USERCOPY
51417+ const char *type;
51418+
51419+ if (!n)
51420+ return;
51421+
51422+ type = check_heap_object(ptr, n);
51423+ if (!type) {
51424+ int ret = check_stack_object(ptr, n);
51425+ if (ret == 1 || ret == 2)
51426+ return;
51427+ if (ret == 0) {
51428+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51429+ type = "<kernel text>";
51430+ else
51431+ return;
51432+ } else
51433+ type = "<process stack>";
51434+ }
51435+
51436+ pax_report_usercopy(ptr, n, to_user, type);
51437+#endif
51438+
51439+}
51440+EXPORT_SYMBOL(__check_object_size);
51441+
51442+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51443+void pax_track_stack(void)
51444+{
51445+ unsigned long sp = (unsigned long)&sp;
51446+ if (sp < current_thread_info()->lowest_stack &&
51447+ sp > (unsigned long)task_stack_page(current))
51448+ current_thread_info()->lowest_stack = sp;
51449+}
51450+EXPORT_SYMBOL(pax_track_stack);
51451+#endif
51452+
51453+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51454+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51455+{
51456+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51457+ dump_stack();
51458+ do_group_exit(SIGKILL);
51459+}
51460+EXPORT_SYMBOL(report_size_overflow);
51461+#endif
51462diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51463index 9f9992b..8b59411 100644
51464--- a/fs/ext2/balloc.c
51465+++ b/fs/ext2/balloc.c
51466@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51467
51468 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51469 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51470- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51471+ if (free_blocks < root_blocks + 1 &&
51472 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51473 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51474- !in_group_p (sbi->s_resgid))) {
51475+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51476 return 0;
51477 }
51478 return 1;
51479diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51480index 22548f5..41521d8 100644
51481--- a/fs/ext3/balloc.c
51482+++ b/fs/ext3/balloc.c
51483@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51484
51485 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51486 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51487- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51488+ if (free_blocks < root_blocks + 1 &&
51489 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51490 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51491- !in_group_p (sbi->s_resgid))) {
51492+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51493 return 0;
51494 }
51495 return 1;
51496diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51497index d0f13ea..4b2dadd 100644
51498--- a/fs/ext4/balloc.c
51499+++ b/fs/ext4/balloc.c
51500@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51501 /* Hm, nope. Are (enough) root reserved clusters available? */
51502 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51503 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51504- capable(CAP_SYS_RESOURCE) ||
51505- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51506+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51507+ capable_nolog(CAP_SYS_RESOURCE)) {
51508
51509 if (free_clusters >= (nclusters + dirty_clusters +
51510 resv_clusters))
51511diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51512index 5aae3d1..b5da7f8 100644
51513--- a/fs/ext4/ext4.h
51514+++ b/fs/ext4/ext4.h
51515@@ -1252,19 +1252,19 @@ struct ext4_sb_info {
51516 unsigned long s_mb_last_start;
51517
51518 /* stats for buddy allocator */
51519- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51520- atomic_t s_bal_success; /* we found long enough chunks */
51521- atomic_t s_bal_allocated; /* in blocks */
51522- atomic_t s_bal_ex_scanned; /* total extents scanned */
51523- atomic_t s_bal_goals; /* goal hits */
51524- atomic_t s_bal_breaks; /* too long searches */
51525- atomic_t s_bal_2orders; /* 2^order hits */
51526+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51527+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51528+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51529+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51530+ atomic_unchecked_t s_bal_goals; /* goal hits */
51531+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51532+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51533 spinlock_t s_bal_lock;
51534 unsigned long s_mb_buddies_generated;
51535 unsigned long long s_mb_generation_time;
51536- atomic_t s_mb_lost_chunks;
51537- atomic_t s_mb_preallocated;
51538- atomic_t s_mb_discarded;
51539+ atomic_unchecked_t s_mb_lost_chunks;
51540+ atomic_unchecked_t s_mb_preallocated;
51541+ atomic_unchecked_t s_mb_discarded;
51542 atomic_t s_lock_busy;
51543
51544 /* locality groups */
51545diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51546index def8408..8253d11 100644
51547--- a/fs/ext4/mballoc.c
51548+++ b/fs/ext4/mballoc.c
51549@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51550 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51551
51552 if (EXT4_SB(sb)->s_mb_stats)
51553- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51554+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51555
51556 break;
51557 }
51558@@ -2170,7 +2170,7 @@ repeat:
51559 ac->ac_status = AC_STATUS_CONTINUE;
51560 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51561 cr = 3;
51562- atomic_inc(&sbi->s_mb_lost_chunks);
51563+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51564 goto repeat;
51565 }
51566 }
51567@@ -2678,25 +2678,25 @@ int ext4_mb_release(struct super_block *sb)
51568 if (sbi->s_mb_stats) {
51569 ext4_msg(sb, KERN_INFO,
51570 "mballoc: %u blocks %u reqs (%u success)",
51571- atomic_read(&sbi->s_bal_allocated),
51572- atomic_read(&sbi->s_bal_reqs),
51573- atomic_read(&sbi->s_bal_success));
51574+ atomic_read_unchecked(&sbi->s_bal_allocated),
51575+ atomic_read_unchecked(&sbi->s_bal_reqs),
51576+ atomic_read_unchecked(&sbi->s_bal_success));
51577 ext4_msg(sb, KERN_INFO,
51578 "mballoc: %u extents scanned, %u goal hits, "
51579 "%u 2^N hits, %u breaks, %u lost",
51580- atomic_read(&sbi->s_bal_ex_scanned),
51581- atomic_read(&sbi->s_bal_goals),
51582- atomic_read(&sbi->s_bal_2orders),
51583- atomic_read(&sbi->s_bal_breaks),
51584- atomic_read(&sbi->s_mb_lost_chunks));
51585+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51586+ atomic_read_unchecked(&sbi->s_bal_goals),
51587+ atomic_read_unchecked(&sbi->s_bal_2orders),
51588+ atomic_read_unchecked(&sbi->s_bal_breaks),
51589+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51590 ext4_msg(sb, KERN_INFO,
51591 "mballoc: %lu generated and it took %Lu",
51592 sbi->s_mb_buddies_generated,
51593 sbi->s_mb_generation_time);
51594 ext4_msg(sb, KERN_INFO,
51595 "mballoc: %u preallocated, %u discarded",
51596- atomic_read(&sbi->s_mb_preallocated),
51597- atomic_read(&sbi->s_mb_discarded));
51598+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51599+ atomic_read_unchecked(&sbi->s_mb_discarded));
51600 }
51601
51602 free_percpu(sbi->s_locality_groups);
51603@@ -3150,16 +3150,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51604 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51605
51606 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51607- atomic_inc(&sbi->s_bal_reqs);
51608- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51609+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51610+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51611 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51612- atomic_inc(&sbi->s_bal_success);
51613- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51614+ atomic_inc_unchecked(&sbi->s_bal_success);
51615+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51616 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51617 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51618- atomic_inc(&sbi->s_bal_goals);
51619+ atomic_inc_unchecked(&sbi->s_bal_goals);
51620 if (ac->ac_found > sbi->s_mb_max_to_scan)
51621- atomic_inc(&sbi->s_bal_breaks);
51622+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51623 }
51624
51625 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51626@@ -3559,7 +3559,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51627 trace_ext4_mb_new_inode_pa(ac, pa);
51628
51629 ext4_mb_use_inode_pa(ac, pa);
51630- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51631+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51632
51633 ei = EXT4_I(ac->ac_inode);
51634 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51635@@ -3619,7 +3619,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51636 trace_ext4_mb_new_group_pa(ac, pa);
51637
51638 ext4_mb_use_group_pa(ac, pa);
51639- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51640+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51641
51642 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51643 lg = ac->ac_lg;
51644@@ -3708,7 +3708,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51645 * from the bitmap and continue.
51646 */
51647 }
51648- atomic_add(free, &sbi->s_mb_discarded);
51649+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51650
51651 return err;
51652 }
51653@@ -3726,7 +3726,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51654 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51655 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51656 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51657- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51658+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51659 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51660
51661 return 0;
51662diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
51663index 214461e..3614c89 100644
51664--- a/fs/ext4/mmp.c
51665+++ b/fs/ext4/mmp.c
51666@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
51667 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
51668 const char *function, unsigned int line, const char *msg)
51669 {
51670- __ext4_warning(sb, function, line, msg);
51671+ __ext4_warning(sb, function, line, "%s", msg);
51672 __ext4_warning(sb, function, line,
51673 "MMP failure info: last update time: %llu, last update "
51674 "node: %s, last update device: %s\n",
51675diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
51676index b27c96d..6ed4df2 100644
51677--- a/fs/ext4/resize.c
51678+++ b/fs/ext4/resize.c
51679@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
51680 ext4_fsblk_t end = start + input->blocks_count;
51681 ext4_group_t group = input->group;
51682 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
51683- unsigned overhead = ext4_group_overhead_blocks(sb, group);
51684- ext4_fsblk_t metaend = start + overhead;
51685+ unsigned overhead;
51686+ ext4_fsblk_t metaend;
51687 struct buffer_head *bh = NULL;
51688 ext4_grpblk_t free_blocks_count, offset;
51689 int err = -EINVAL;
51690
51691+ if (group != sbi->s_groups_count) {
51692+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51693+ input->group, sbi->s_groups_count);
51694+ return -EINVAL;
51695+ }
51696+
51697+ overhead = ext4_group_overhead_blocks(sb, group);
51698+ metaend = start + overhead;
51699 input->free_blocks_count = free_blocks_count =
51700 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
51701
51702@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
51703 free_blocks_count, input->reserved_blocks);
51704
51705 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
51706- if (group != sbi->s_groups_count)
51707- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51708- input->group, sbi->s_groups_count);
51709- else if (offset != 0)
51710+ if (offset != 0)
51711 ext4_warning(sb, "Last group not full");
51712 else if (input->reserved_blocks > input->blocks_count / 5)
51713 ext4_warning(sb, "Reserved blocks too high (%u)",
51714diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51715index 94cc84d..2490974 100644
51716--- a/fs/ext4/super.c
51717+++ b/fs/ext4/super.c
51718@@ -1236,7 +1236,7 @@ static ext4_fsblk_t get_sb_block(void **data)
51719 }
51720
51721 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
51722-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51723+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51724 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
51725
51726 #ifdef CONFIG_QUOTA
51727@@ -2378,7 +2378,7 @@ struct ext4_attr {
51728 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51729 const char *, size_t);
51730 int offset;
51731-};
51732+} __do_const;
51733
51734 static int parse_strtoull(const char *buf,
51735 unsigned long long max, unsigned long long *value)
51736diff --git a/fs/fcntl.c b/fs/fcntl.c
51737index 6599222..e7bf0de 100644
51738--- a/fs/fcntl.c
51739+++ b/fs/fcntl.c
51740@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51741 if (err)
51742 return err;
51743
51744+ if (gr_handle_chroot_fowner(pid, type))
51745+ return -ENOENT;
51746+ if (gr_check_protected_task_fowner(pid, type))
51747+ return -EACCES;
51748+
51749 f_modown(filp, pid, type, force);
51750 return 0;
51751 }
51752diff --git a/fs/fhandle.c b/fs/fhandle.c
51753index 999ff5c..41f4109 100644
51754--- a/fs/fhandle.c
51755+++ b/fs/fhandle.c
51756@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51757 } else
51758 retval = 0;
51759 /* copy the mount id */
51760- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51761- sizeof(*mnt_id)) ||
51762+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51763 copy_to_user(ufh, handle,
51764 sizeof(struct file_handle) + handle_bytes))
51765 retval = -EFAULT;
51766diff --git a/fs/file.c b/fs/file.c
51767index 4a78f98..9447397 100644
51768--- a/fs/file.c
51769+++ b/fs/file.c
51770@@ -16,6 +16,7 @@
51771 #include <linux/slab.h>
51772 #include <linux/vmalloc.h>
51773 #include <linux/file.h>
51774+#include <linux/security.h>
51775 #include <linux/fdtable.h>
51776 #include <linux/bitops.h>
51777 #include <linux/interrupt.h>
51778@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51779 if (!file)
51780 return __close_fd(files, fd);
51781
51782+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51783 if (fd >= rlimit(RLIMIT_NOFILE))
51784 return -EBADF;
51785
51786@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51787 if (unlikely(oldfd == newfd))
51788 return -EINVAL;
51789
51790+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51791 if (newfd >= rlimit(RLIMIT_NOFILE))
51792 return -EBADF;
51793
51794@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51795 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51796 {
51797 int err;
51798+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51799 if (from >= rlimit(RLIMIT_NOFILE))
51800 return -EINVAL;
51801 err = alloc_fd(from, flags);
51802diff --git a/fs/filesystems.c b/fs/filesystems.c
51803index 92567d9..fcd8cbf 100644
51804--- a/fs/filesystems.c
51805+++ b/fs/filesystems.c
51806@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
51807 int len = dot ? dot - name : strlen(name);
51808
51809 fs = __get_fs_type(name, len);
51810+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51811+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
51812+#else
51813 if (!fs && (request_module("fs-%.*s", len, name) == 0))
51814+#endif
51815 fs = __get_fs_type(name, len);
51816
51817 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51818diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51819index d8ac61d..79a36f0 100644
51820--- a/fs/fs_struct.c
51821+++ b/fs/fs_struct.c
51822@@ -4,6 +4,7 @@
51823 #include <linux/path.h>
51824 #include <linux/slab.h>
51825 #include <linux/fs_struct.h>
51826+#include <linux/grsecurity.h>
51827 #include "internal.h"
51828
51829 /*
51830@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
51831 write_seqcount_begin(&fs->seq);
51832 old_root = fs->root;
51833 fs->root = *path;
51834+ gr_set_chroot_entries(current, path);
51835 write_seqcount_end(&fs->seq);
51836 spin_unlock(&fs->lock);
51837 if (old_root.dentry)
51838@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
51839 int hits = 0;
51840 spin_lock(&fs->lock);
51841 write_seqcount_begin(&fs->seq);
51842+ /* this root replacement is only done by pivot_root,
51843+ leave grsec's chroot tagging alone for this task
51844+ so that a pivoted root isn't treated as a chroot
51845+ */
51846 hits += replace_path(&fs->root, old_root, new_root);
51847 hits += replace_path(&fs->pwd, old_root, new_root);
51848 write_seqcount_end(&fs->seq);
51849@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
51850 task_lock(tsk);
51851 spin_lock(&fs->lock);
51852 tsk->fs = NULL;
51853- kill = !--fs->users;
51854+ gr_clear_chroot_entries(tsk);
51855+ kill = !atomic_dec_return(&fs->users);
51856 spin_unlock(&fs->lock);
51857 task_unlock(tsk);
51858 if (kill)
51859@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51860 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51861 /* We don't need to lock fs - think why ;-) */
51862 if (fs) {
51863- fs->users = 1;
51864+ atomic_set(&fs->users, 1);
51865 fs->in_exec = 0;
51866 spin_lock_init(&fs->lock);
51867 seqcount_init(&fs->seq);
51868@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51869 spin_lock(&old->lock);
51870 fs->root = old->root;
51871 path_get(&fs->root);
51872+ /* instead of calling gr_set_chroot_entries here,
51873+ we call it from every caller of this function
51874+ */
51875 fs->pwd = old->pwd;
51876 path_get(&fs->pwd);
51877 spin_unlock(&old->lock);
51878@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
51879
51880 task_lock(current);
51881 spin_lock(&fs->lock);
51882- kill = !--fs->users;
51883+ kill = !atomic_dec_return(&fs->users);
51884 current->fs = new_fs;
51885+ gr_set_chroot_entries(current, &new_fs->root);
51886 spin_unlock(&fs->lock);
51887 task_unlock(current);
51888
51889@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51890
51891 int current_umask(void)
51892 {
51893- return current->fs->umask;
51894+ return current->fs->umask | gr_acl_umask();
51895 }
51896 EXPORT_SYMBOL(current_umask);
51897
51898 /* to be mentioned only in INIT_TASK */
51899 struct fs_struct init_fs = {
51900- .users = 1,
51901+ .users = ATOMIC_INIT(1),
51902 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51903 .seq = SEQCNT_ZERO,
51904 .umask = 0022,
51905diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51906index e2cba1f..17a25bb 100644
51907--- a/fs/fscache/cookie.c
51908+++ b/fs/fscache/cookie.c
51909@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51910 parent ? (char *) parent->def->name : "<no-parent>",
51911 def->name, netfs_data);
51912
51913- fscache_stat(&fscache_n_acquires);
51914+ fscache_stat_unchecked(&fscache_n_acquires);
51915
51916 /* if there's no parent cookie, then we don't create one here either */
51917 if (!parent) {
51918- fscache_stat(&fscache_n_acquires_null);
51919+ fscache_stat_unchecked(&fscache_n_acquires_null);
51920 _leave(" [no parent]");
51921 return NULL;
51922 }
51923@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51924 /* allocate and initialise a cookie */
51925 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51926 if (!cookie) {
51927- fscache_stat(&fscache_n_acquires_oom);
51928+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51929 _leave(" [ENOMEM]");
51930 return NULL;
51931 }
51932@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51933
51934 switch (cookie->def->type) {
51935 case FSCACHE_COOKIE_TYPE_INDEX:
51936- fscache_stat(&fscache_n_cookie_index);
51937+ fscache_stat_unchecked(&fscache_n_cookie_index);
51938 break;
51939 case FSCACHE_COOKIE_TYPE_DATAFILE:
51940- fscache_stat(&fscache_n_cookie_data);
51941+ fscache_stat_unchecked(&fscache_n_cookie_data);
51942 break;
51943 default:
51944- fscache_stat(&fscache_n_cookie_special);
51945+ fscache_stat_unchecked(&fscache_n_cookie_special);
51946 break;
51947 }
51948
51949@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51950 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51951 atomic_dec(&parent->n_children);
51952 __fscache_cookie_put(cookie);
51953- fscache_stat(&fscache_n_acquires_nobufs);
51954+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51955 _leave(" = NULL");
51956 return NULL;
51957 }
51958 }
51959
51960- fscache_stat(&fscache_n_acquires_ok);
51961+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51962 _leave(" = %p", cookie);
51963 return cookie;
51964 }
51965@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51966 cache = fscache_select_cache_for_object(cookie->parent);
51967 if (!cache) {
51968 up_read(&fscache_addremove_sem);
51969- fscache_stat(&fscache_n_acquires_no_cache);
51970+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51971 _leave(" = -ENOMEDIUM [no cache]");
51972 return -ENOMEDIUM;
51973 }
51974@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51975 object = cache->ops->alloc_object(cache, cookie);
51976 fscache_stat_d(&fscache_n_cop_alloc_object);
51977 if (IS_ERR(object)) {
51978- fscache_stat(&fscache_n_object_no_alloc);
51979+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51980 ret = PTR_ERR(object);
51981 goto error;
51982 }
51983
51984- fscache_stat(&fscache_n_object_alloc);
51985+ fscache_stat_unchecked(&fscache_n_object_alloc);
51986
51987 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51988
51989@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51990
51991 _enter("{%s}", cookie->def->name);
51992
51993- fscache_stat(&fscache_n_invalidates);
51994+ fscache_stat_unchecked(&fscache_n_invalidates);
51995
51996 /* Only permit invalidation of data files. Invalidating an index will
51997 * require the caller to release all its attachments to the tree rooted
51998@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51999 {
52000 struct fscache_object *object;
52001
52002- fscache_stat(&fscache_n_updates);
52003+ fscache_stat_unchecked(&fscache_n_updates);
52004
52005 if (!cookie) {
52006- fscache_stat(&fscache_n_updates_null);
52007+ fscache_stat_unchecked(&fscache_n_updates_null);
52008 _leave(" [no cookie]");
52009 return;
52010 }
52011@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52012 struct fscache_object *object;
52013 unsigned long event;
52014
52015- fscache_stat(&fscache_n_relinquishes);
52016+ fscache_stat_unchecked(&fscache_n_relinquishes);
52017 if (retire)
52018- fscache_stat(&fscache_n_relinquishes_retire);
52019+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
52020
52021 if (!cookie) {
52022- fscache_stat(&fscache_n_relinquishes_null);
52023+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
52024 _leave(" [no cookie]");
52025 return;
52026 }
52027@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
52028
52029 /* wait for the cookie to finish being instantiated (or to fail) */
52030 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
52031- fscache_stat(&fscache_n_relinquishes_waitcrt);
52032+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
52033 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52034 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52035 }
52036diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52037index ee38fef..0a326d4 100644
52038--- a/fs/fscache/internal.h
52039+++ b/fs/fscache/internal.h
52040@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52041 * stats.c
52042 */
52043 #ifdef CONFIG_FSCACHE_STATS
52044-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52045-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52046+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52047+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52048
52049-extern atomic_t fscache_n_op_pend;
52050-extern atomic_t fscache_n_op_run;
52051-extern atomic_t fscache_n_op_enqueue;
52052-extern atomic_t fscache_n_op_deferred_release;
52053-extern atomic_t fscache_n_op_release;
52054-extern atomic_t fscache_n_op_gc;
52055-extern atomic_t fscache_n_op_cancelled;
52056-extern atomic_t fscache_n_op_rejected;
52057+extern atomic_unchecked_t fscache_n_op_pend;
52058+extern atomic_unchecked_t fscache_n_op_run;
52059+extern atomic_unchecked_t fscache_n_op_enqueue;
52060+extern atomic_unchecked_t fscache_n_op_deferred_release;
52061+extern atomic_unchecked_t fscache_n_op_release;
52062+extern atomic_unchecked_t fscache_n_op_gc;
52063+extern atomic_unchecked_t fscache_n_op_cancelled;
52064+extern atomic_unchecked_t fscache_n_op_rejected;
52065
52066-extern atomic_t fscache_n_attr_changed;
52067-extern atomic_t fscache_n_attr_changed_ok;
52068-extern atomic_t fscache_n_attr_changed_nobufs;
52069-extern atomic_t fscache_n_attr_changed_nomem;
52070-extern atomic_t fscache_n_attr_changed_calls;
52071+extern atomic_unchecked_t fscache_n_attr_changed;
52072+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52073+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52074+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52075+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52076
52077-extern atomic_t fscache_n_allocs;
52078-extern atomic_t fscache_n_allocs_ok;
52079-extern atomic_t fscache_n_allocs_wait;
52080-extern atomic_t fscache_n_allocs_nobufs;
52081-extern atomic_t fscache_n_allocs_intr;
52082-extern atomic_t fscache_n_allocs_object_dead;
52083-extern atomic_t fscache_n_alloc_ops;
52084-extern atomic_t fscache_n_alloc_op_waits;
52085+extern atomic_unchecked_t fscache_n_allocs;
52086+extern atomic_unchecked_t fscache_n_allocs_ok;
52087+extern atomic_unchecked_t fscache_n_allocs_wait;
52088+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52089+extern atomic_unchecked_t fscache_n_allocs_intr;
52090+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52091+extern atomic_unchecked_t fscache_n_alloc_ops;
52092+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52093
52094-extern atomic_t fscache_n_retrievals;
52095-extern atomic_t fscache_n_retrievals_ok;
52096-extern atomic_t fscache_n_retrievals_wait;
52097-extern atomic_t fscache_n_retrievals_nodata;
52098-extern atomic_t fscache_n_retrievals_nobufs;
52099-extern atomic_t fscache_n_retrievals_intr;
52100-extern atomic_t fscache_n_retrievals_nomem;
52101-extern atomic_t fscache_n_retrievals_object_dead;
52102-extern atomic_t fscache_n_retrieval_ops;
52103-extern atomic_t fscache_n_retrieval_op_waits;
52104+extern atomic_unchecked_t fscache_n_retrievals;
52105+extern atomic_unchecked_t fscache_n_retrievals_ok;
52106+extern atomic_unchecked_t fscache_n_retrievals_wait;
52107+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52108+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52109+extern atomic_unchecked_t fscache_n_retrievals_intr;
52110+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52111+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52112+extern atomic_unchecked_t fscache_n_retrieval_ops;
52113+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52114
52115-extern atomic_t fscache_n_stores;
52116-extern atomic_t fscache_n_stores_ok;
52117-extern atomic_t fscache_n_stores_again;
52118-extern atomic_t fscache_n_stores_nobufs;
52119-extern atomic_t fscache_n_stores_oom;
52120-extern atomic_t fscache_n_store_ops;
52121-extern atomic_t fscache_n_store_calls;
52122-extern atomic_t fscache_n_store_pages;
52123-extern atomic_t fscache_n_store_radix_deletes;
52124-extern atomic_t fscache_n_store_pages_over_limit;
52125+extern atomic_unchecked_t fscache_n_stores;
52126+extern atomic_unchecked_t fscache_n_stores_ok;
52127+extern atomic_unchecked_t fscache_n_stores_again;
52128+extern atomic_unchecked_t fscache_n_stores_nobufs;
52129+extern atomic_unchecked_t fscache_n_stores_oom;
52130+extern atomic_unchecked_t fscache_n_store_ops;
52131+extern atomic_unchecked_t fscache_n_store_calls;
52132+extern atomic_unchecked_t fscache_n_store_pages;
52133+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52134+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52135
52136-extern atomic_t fscache_n_store_vmscan_not_storing;
52137-extern atomic_t fscache_n_store_vmscan_gone;
52138-extern atomic_t fscache_n_store_vmscan_busy;
52139-extern atomic_t fscache_n_store_vmscan_cancelled;
52140-extern atomic_t fscache_n_store_vmscan_wait;
52141+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52142+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52143+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52144+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52145+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52146
52147-extern atomic_t fscache_n_marks;
52148-extern atomic_t fscache_n_uncaches;
52149+extern atomic_unchecked_t fscache_n_marks;
52150+extern atomic_unchecked_t fscache_n_uncaches;
52151
52152-extern atomic_t fscache_n_acquires;
52153-extern atomic_t fscache_n_acquires_null;
52154-extern atomic_t fscache_n_acquires_no_cache;
52155-extern atomic_t fscache_n_acquires_ok;
52156-extern atomic_t fscache_n_acquires_nobufs;
52157-extern atomic_t fscache_n_acquires_oom;
52158+extern atomic_unchecked_t fscache_n_acquires;
52159+extern atomic_unchecked_t fscache_n_acquires_null;
52160+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52161+extern atomic_unchecked_t fscache_n_acquires_ok;
52162+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52163+extern atomic_unchecked_t fscache_n_acquires_oom;
52164
52165-extern atomic_t fscache_n_invalidates;
52166-extern atomic_t fscache_n_invalidates_run;
52167+extern atomic_unchecked_t fscache_n_invalidates;
52168+extern atomic_unchecked_t fscache_n_invalidates_run;
52169
52170-extern atomic_t fscache_n_updates;
52171-extern atomic_t fscache_n_updates_null;
52172-extern atomic_t fscache_n_updates_run;
52173+extern atomic_unchecked_t fscache_n_updates;
52174+extern atomic_unchecked_t fscache_n_updates_null;
52175+extern atomic_unchecked_t fscache_n_updates_run;
52176
52177-extern atomic_t fscache_n_relinquishes;
52178-extern atomic_t fscache_n_relinquishes_null;
52179-extern atomic_t fscache_n_relinquishes_waitcrt;
52180-extern atomic_t fscache_n_relinquishes_retire;
52181+extern atomic_unchecked_t fscache_n_relinquishes;
52182+extern atomic_unchecked_t fscache_n_relinquishes_null;
52183+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52184+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52185
52186-extern atomic_t fscache_n_cookie_index;
52187-extern atomic_t fscache_n_cookie_data;
52188-extern atomic_t fscache_n_cookie_special;
52189+extern atomic_unchecked_t fscache_n_cookie_index;
52190+extern atomic_unchecked_t fscache_n_cookie_data;
52191+extern atomic_unchecked_t fscache_n_cookie_special;
52192
52193-extern atomic_t fscache_n_object_alloc;
52194-extern atomic_t fscache_n_object_no_alloc;
52195-extern atomic_t fscache_n_object_lookups;
52196-extern atomic_t fscache_n_object_lookups_negative;
52197-extern atomic_t fscache_n_object_lookups_positive;
52198-extern atomic_t fscache_n_object_lookups_timed_out;
52199-extern atomic_t fscache_n_object_created;
52200-extern atomic_t fscache_n_object_avail;
52201-extern atomic_t fscache_n_object_dead;
52202+extern atomic_unchecked_t fscache_n_object_alloc;
52203+extern atomic_unchecked_t fscache_n_object_no_alloc;
52204+extern atomic_unchecked_t fscache_n_object_lookups;
52205+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52206+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52207+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52208+extern atomic_unchecked_t fscache_n_object_created;
52209+extern atomic_unchecked_t fscache_n_object_avail;
52210+extern atomic_unchecked_t fscache_n_object_dead;
52211
52212-extern atomic_t fscache_n_checkaux_none;
52213-extern atomic_t fscache_n_checkaux_okay;
52214-extern atomic_t fscache_n_checkaux_update;
52215-extern atomic_t fscache_n_checkaux_obsolete;
52216+extern atomic_unchecked_t fscache_n_checkaux_none;
52217+extern atomic_unchecked_t fscache_n_checkaux_okay;
52218+extern atomic_unchecked_t fscache_n_checkaux_update;
52219+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52220
52221 extern atomic_t fscache_n_cop_alloc_object;
52222 extern atomic_t fscache_n_cop_lookup_object;
52223@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52224 atomic_inc(stat);
52225 }
52226
52227+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52228+{
52229+ atomic_inc_unchecked(stat);
52230+}
52231+
52232 static inline void fscache_stat_d(atomic_t *stat)
52233 {
52234 atomic_dec(stat);
52235@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52236
52237 #define __fscache_stat(stat) (NULL)
52238 #define fscache_stat(stat) do {} while (0)
52239+#define fscache_stat_unchecked(stat) do {} while (0)
52240 #define fscache_stat_d(stat) do {} while (0)
52241 #endif
52242
52243diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52244index 50d41c1..10ee117 100644
52245--- a/fs/fscache/object.c
52246+++ b/fs/fscache/object.c
52247@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52248 /* Invalidate an object on disk */
52249 case FSCACHE_OBJECT_INVALIDATING:
52250 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52251- fscache_stat(&fscache_n_invalidates_run);
52252+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52253 fscache_stat(&fscache_n_cop_invalidate_object);
52254 fscache_invalidate_object(object);
52255 fscache_stat_d(&fscache_n_cop_invalidate_object);
52256@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52257 /* update the object metadata on disk */
52258 case FSCACHE_OBJECT_UPDATING:
52259 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52260- fscache_stat(&fscache_n_updates_run);
52261+ fscache_stat_unchecked(&fscache_n_updates_run);
52262 fscache_stat(&fscache_n_cop_update_object);
52263 object->cache->ops->update_object(object);
52264 fscache_stat_d(&fscache_n_cop_update_object);
52265@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52266 spin_lock(&object->lock);
52267 object->state = FSCACHE_OBJECT_DEAD;
52268 spin_unlock(&object->lock);
52269- fscache_stat(&fscache_n_object_dead);
52270+ fscache_stat_unchecked(&fscache_n_object_dead);
52271 goto terminal_transit;
52272
52273 /* handle the parent cache of this object being withdrawn from
52274@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52275 spin_lock(&object->lock);
52276 object->state = FSCACHE_OBJECT_DEAD;
52277 spin_unlock(&object->lock);
52278- fscache_stat(&fscache_n_object_dead);
52279+ fscache_stat_unchecked(&fscache_n_object_dead);
52280 goto terminal_transit;
52281
52282 /* complain about the object being woken up once it is
52283@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52284 parent->cookie->def->name, cookie->def->name,
52285 object->cache->tag->name);
52286
52287- fscache_stat(&fscache_n_object_lookups);
52288+ fscache_stat_unchecked(&fscache_n_object_lookups);
52289 fscache_stat(&fscache_n_cop_lookup_object);
52290 ret = object->cache->ops->lookup_object(object);
52291 fscache_stat_d(&fscache_n_cop_lookup_object);
52292@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52293 if (ret == -ETIMEDOUT) {
52294 /* probably stuck behind another object, so move this one to
52295 * the back of the queue */
52296- fscache_stat(&fscache_n_object_lookups_timed_out);
52297+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52298 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52299 }
52300
52301@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52302
52303 spin_lock(&object->lock);
52304 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52305- fscache_stat(&fscache_n_object_lookups_negative);
52306+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52307
52308 /* transit here to allow write requests to begin stacking up
52309 * and read requests to begin returning ENODATA */
52310@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52311 * result, in which case there may be data available */
52312 spin_lock(&object->lock);
52313 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52314- fscache_stat(&fscache_n_object_lookups_positive);
52315+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52316
52317 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52318
52319@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52320 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52321 } else {
52322 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52323- fscache_stat(&fscache_n_object_created);
52324+ fscache_stat_unchecked(&fscache_n_object_created);
52325
52326 object->state = FSCACHE_OBJECT_AVAILABLE;
52327 spin_unlock(&object->lock);
52328@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52329 fscache_enqueue_dependents(object);
52330
52331 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52332- fscache_stat(&fscache_n_object_avail);
52333+ fscache_stat_unchecked(&fscache_n_object_avail);
52334
52335 _leave("");
52336 }
52337@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52338 enum fscache_checkaux result;
52339
52340 if (!object->cookie->def->check_aux) {
52341- fscache_stat(&fscache_n_checkaux_none);
52342+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52343 return FSCACHE_CHECKAUX_OKAY;
52344 }
52345
52346@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52347 switch (result) {
52348 /* entry okay as is */
52349 case FSCACHE_CHECKAUX_OKAY:
52350- fscache_stat(&fscache_n_checkaux_okay);
52351+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52352 break;
52353
52354 /* entry requires update */
52355 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52356- fscache_stat(&fscache_n_checkaux_update);
52357+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52358 break;
52359
52360 /* entry requires deletion */
52361 case FSCACHE_CHECKAUX_OBSOLETE:
52362- fscache_stat(&fscache_n_checkaux_obsolete);
52363+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52364 break;
52365
52366 default:
52367diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52368index 762a9ec..2023284 100644
52369--- a/fs/fscache/operation.c
52370+++ b/fs/fscache/operation.c
52371@@ -17,7 +17,7 @@
52372 #include <linux/slab.h>
52373 #include "internal.h"
52374
52375-atomic_t fscache_op_debug_id;
52376+atomic_unchecked_t fscache_op_debug_id;
52377 EXPORT_SYMBOL(fscache_op_debug_id);
52378
52379 /**
52380@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52381 ASSERTCMP(atomic_read(&op->usage), >, 0);
52382 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52383
52384- fscache_stat(&fscache_n_op_enqueue);
52385+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52386 switch (op->flags & FSCACHE_OP_TYPE) {
52387 case FSCACHE_OP_ASYNC:
52388 _debug("queue async");
52389@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52390 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52391 if (op->processor)
52392 fscache_enqueue_operation(op);
52393- fscache_stat(&fscache_n_op_run);
52394+ fscache_stat_unchecked(&fscache_n_op_run);
52395 }
52396
52397 /*
52398@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52399 if (object->n_in_progress > 0) {
52400 atomic_inc(&op->usage);
52401 list_add_tail(&op->pend_link, &object->pending_ops);
52402- fscache_stat(&fscache_n_op_pend);
52403+ fscache_stat_unchecked(&fscache_n_op_pend);
52404 } else if (!list_empty(&object->pending_ops)) {
52405 atomic_inc(&op->usage);
52406 list_add_tail(&op->pend_link, &object->pending_ops);
52407- fscache_stat(&fscache_n_op_pend);
52408+ fscache_stat_unchecked(&fscache_n_op_pend);
52409 fscache_start_operations(object);
52410 } else {
52411 ASSERTCMP(object->n_in_progress, ==, 0);
52412@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52413 object->n_exclusive++; /* reads and writes must wait */
52414 atomic_inc(&op->usage);
52415 list_add_tail(&op->pend_link, &object->pending_ops);
52416- fscache_stat(&fscache_n_op_pend);
52417+ fscache_stat_unchecked(&fscache_n_op_pend);
52418 ret = 0;
52419 } else {
52420 /* If we're in any other state, there must have been an I/O
52421@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52422 if (object->n_exclusive > 0) {
52423 atomic_inc(&op->usage);
52424 list_add_tail(&op->pend_link, &object->pending_ops);
52425- fscache_stat(&fscache_n_op_pend);
52426+ fscache_stat_unchecked(&fscache_n_op_pend);
52427 } else if (!list_empty(&object->pending_ops)) {
52428 atomic_inc(&op->usage);
52429 list_add_tail(&op->pend_link, &object->pending_ops);
52430- fscache_stat(&fscache_n_op_pend);
52431+ fscache_stat_unchecked(&fscache_n_op_pend);
52432 fscache_start_operations(object);
52433 } else {
52434 ASSERTCMP(object->n_exclusive, ==, 0);
52435@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52436 object->n_ops++;
52437 atomic_inc(&op->usage);
52438 list_add_tail(&op->pend_link, &object->pending_ops);
52439- fscache_stat(&fscache_n_op_pend);
52440+ fscache_stat_unchecked(&fscache_n_op_pend);
52441 ret = 0;
52442 } else if (object->state == FSCACHE_OBJECT_DYING ||
52443 object->state == FSCACHE_OBJECT_LC_DYING ||
52444 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52445- fscache_stat(&fscache_n_op_rejected);
52446+ fscache_stat_unchecked(&fscache_n_op_rejected);
52447 op->state = FSCACHE_OP_ST_CANCELLED;
52448 ret = -ENOBUFS;
52449 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52450@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52451 ret = -EBUSY;
52452 if (op->state == FSCACHE_OP_ST_PENDING) {
52453 ASSERT(!list_empty(&op->pend_link));
52454- fscache_stat(&fscache_n_op_cancelled);
52455+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52456 list_del_init(&op->pend_link);
52457 if (do_cancel)
52458 do_cancel(op);
52459@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52460 while (!list_empty(&object->pending_ops)) {
52461 op = list_entry(object->pending_ops.next,
52462 struct fscache_operation, pend_link);
52463- fscache_stat(&fscache_n_op_cancelled);
52464+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52465 list_del_init(&op->pend_link);
52466
52467 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52468@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52469 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52470 op->state = FSCACHE_OP_ST_DEAD;
52471
52472- fscache_stat(&fscache_n_op_release);
52473+ fscache_stat_unchecked(&fscache_n_op_release);
52474
52475 if (op->release) {
52476 op->release(op);
52477@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52478 * lock, and defer it otherwise */
52479 if (!spin_trylock(&object->lock)) {
52480 _debug("defer put");
52481- fscache_stat(&fscache_n_op_deferred_release);
52482+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52483
52484 cache = object->cache;
52485 spin_lock(&cache->op_gc_list_lock);
52486@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52487
52488 _debug("GC DEFERRED REL OBJ%x OP%x",
52489 object->debug_id, op->debug_id);
52490- fscache_stat(&fscache_n_op_gc);
52491+ fscache_stat_unchecked(&fscache_n_op_gc);
52492
52493 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52494 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52495diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52496index ff000e5..c44ec6d 100644
52497--- a/fs/fscache/page.c
52498+++ b/fs/fscache/page.c
52499@@ -61,7 +61,7 @@ try_again:
52500 val = radix_tree_lookup(&cookie->stores, page->index);
52501 if (!val) {
52502 rcu_read_unlock();
52503- fscache_stat(&fscache_n_store_vmscan_not_storing);
52504+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52505 __fscache_uncache_page(cookie, page);
52506 return true;
52507 }
52508@@ -91,11 +91,11 @@ try_again:
52509 spin_unlock(&cookie->stores_lock);
52510
52511 if (xpage) {
52512- fscache_stat(&fscache_n_store_vmscan_cancelled);
52513- fscache_stat(&fscache_n_store_radix_deletes);
52514+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52515+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52516 ASSERTCMP(xpage, ==, page);
52517 } else {
52518- fscache_stat(&fscache_n_store_vmscan_gone);
52519+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52520 }
52521
52522 wake_up_bit(&cookie->flags, 0);
52523@@ -110,11 +110,11 @@ page_busy:
52524 * sleeping on memory allocation, so we may need to impose a timeout
52525 * too. */
52526 if (!(gfp & __GFP_WAIT)) {
52527- fscache_stat(&fscache_n_store_vmscan_busy);
52528+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52529 return false;
52530 }
52531
52532- fscache_stat(&fscache_n_store_vmscan_wait);
52533+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52534 __fscache_wait_on_page_write(cookie, page);
52535 gfp &= ~__GFP_WAIT;
52536 goto try_again;
52537@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52538 FSCACHE_COOKIE_STORING_TAG);
52539 if (!radix_tree_tag_get(&cookie->stores, page->index,
52540 FSCACHE_COOKIE_PENDING_TAG)) {
52541- fscache_stat(&fscache_n_store_radix_deletes);
52542+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52543 xpage = radix_tree_delete(&cookie->stores, page->index);
52544 }
52545 spin_unlock(&cookie->stores_lock);
52546@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52547
52548 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52549
52550- fscache_stat(&fscache_n_attr_changed_calls);
52551+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52552
52553 if (fscache_object_is_active(object)) {
52554 fscache_stat(&fscache_n_cop_attr_changed);
52555@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52556
52557 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52558
52559- fscache_stat(&fscache_n_attr_changed);
52560+ fscache_stat_unchecked(&fscache_n_attr_changed);
52561
52562 op = kzalloc(sizeof(*op), GFP_KERNEL);
52563 if (!op) {
52564- fscache_stat(&fscache_n_attr_changed_nomem);
52565+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52566 _leave(" = -ENOMEM");
52567 return -ENOMEM;
52568 }
52569@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52570 if (fscache_submit_exclusive_op(object, op) < 0)
52571 goto nobufs;
52572 spin_unlock(&cookie->lock);
52573- fscache_stat(&fscache_n_attr_changed_ok);
52574+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52575 fscache_put_operation(op);
52576 _leave(" = 0");
52577 return 0;
52578@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52579 nobufs:
52580 spin_unlock(&cookie->lock);
52581 kfree(op);
52582- fscache_stat(&fscache_n_attr_changed_nobufs);
52583+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52584 _leave(" = %d", -ENOBUFS);
52585 return -ENOBUFS;
52586 }
52587@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52588 /* allocate a retrieval operation and attempt to submit it */
52589 op = kzalloc(sizeof(*op), GFP_NOIO);
52590 if (!op) {
52591- fscache_stat(&fscache_n_retrievals_nomem);
52592+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52593 return NULL;
52594 }
52595
52596@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52597 return 0;
52598 }
52599
52600- fscache_stat(&fscache_n_retrievals_wait);
52601+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52602
52603 jif = jiffies;
52604 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52605 fscache_wait_bit_interruptible,
52606 TASK_INTERRUPTIBLE) != 0) {
52607- fscache_stat(&fscache_n_retrievals_intr);
52608+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52609 _leave(" = -ERESTARTSYS");
52610 return -ERESTARTSYS;
52611 }
52612@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52613 */
52614 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52615 struct fscache_retrieval *op,
52616- atomic_t *stat_op_waits,
52617- atomic_t *stat_object_dead)
52618+ atomic_unchecked_t *stat_op_waits,
52619+ atomic_unchecked_t *stat_object_dead)
52620 {
52621 int ret;
52622
52623@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52624 goto check_if_dead;
52625
52626 _debug(">>> WT");
52627- fscache_stat(stat_op_waits);
52628+ fscache_stat_unchecked(stat_op_waits);
52629 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52630 fscache_wait_bit_interruptible,
52631 TASK_INTERRUPTIBLE) != 0) {
52632@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52633
52634 check_if_dead:
52635 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52636- fscache_stat(stat_object_dead);
52637+ fscache_stat_unchecked(stat_object_dead);
52638 _leave(" = -ENOBUFS [cancelled]");
52639 return -ENOBUFS;
52640 }
52641 if (unlikely(fscache_object_is_dead(object))) {
52642 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52643 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52644- fscache_stat(stat_object_dead);
52645+ fscache_stat_unchecked(stat_object_dead);
52646 return -ENOBUFS;
52647 }
52648 return 0;
52649@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52650
52651 _enter("%p,%p,,,", cookie, page);
52652
52653- fscache_stat(&fscache_n_retrievals);
52654+ fscache_stat_unchecked(&fscache_n_retrievals);
52655
52656 if (hlist_empty(&cookie->backing_objects))
52657 goto nobufs;
52658@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52659 goto nobufs_unlock_dec;
52660 spin_unlock(&cookie->lock);
52661
52662- fscache_stat(&fscache_n_retrieval_ops);
52663+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52664
52665 /* pin the netfs read context in case we need to do the actual netfs
52666 * read because we've encountered a cache read failure */
52667@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52668
52669 error:
52670 if (ret == -ENOMEM)
52671- fscache_stat(&fscache_n_retrievals_nomem);
52672+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52673 else if (ret == -ERESTARTSYS)
52674- fscache_stat(&fscache_n_retrievals_intr);
52675+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52676 else if (ret == -ENODATA)
52677- fscache_stat(&fscache_n_retrievals_nodata);
52678+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52679 else if (ret < 0)
52680- fscache_stat(&fscache_n_retrievals_nobufs);
52681+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52682 else
52683- fscache_stat(&fscache_n_retrievals_ok);
52684+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52685
52686 fscache_put_retrieval(op);
52687 _leave(" = %d", ret);
52688@@ -467,7 +467,7 @@ nobufs_unlock:
52689 spin_unlock(&cookie->lock);
52690 kfree(op);
52691 nobufs:
52692- fscache_stat(&fscache_n_retrievals_nobufs);
52693+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52694 _leave(" = -ENOBUFS");
52695 return -ENOBUFS;
52696 }
52697@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52698
52699 _enter("%p,,%d,,,", cookie, *nr_pages);
52700
52701- fscache_stat(&fscache_n_retrievals);
52702+ fscache_stat_unchecked(&fscache_n_retrievals);
52703
52704 if (hlist_empty(&cookie->backing_objects))
52705 goto nobufs;
52706@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52707 goto nobufs_unlock_dec;
52708 spin_unlock(&cookie->lock);
52709
52710- fscache_stat(&fscache_n_retrieval_ops);
52711+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52712
52713 /* pin the netfs read context in case we need to do the actual netfs
52714 * read because we've encountered a cache read failure */
52715@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52716
52717 error:
52718 if (ret == -ENOMEM)
52719- fscache_stat(&fscache_n_retrievals_nomem);
52720+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52721 else if (ret == -ERESTARTSYS)
52722- fscache_stat(&fscache_n_retrievals_intr);
52723+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52724 else if (ret == -ENODATA)
52725- fscache_stat(&fscache_n_retrievals_nodata);
52726+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52727 else if (ret < 0)
52728- fscache_stat(&fscache_n_retrievals_nobufs);
52729+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52730 else
52731- fscache_stat(&fscache_n_retrievals_ok);
52732+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52733
52734 fscache_put_retrieval(op);
52735 _leave(" = %d", ret);
52736@@ -591,7 +591,7 @@ nobufs_unlock:
52737 spin_unlock(&cookie->lock);
52738 kfree(op);
52739 nobufs:
52740- fscache_stat(&fscache_n_retrievals_nobufs);
52741+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52742 _leave(" = -ENOBUFS");
52743 return -ENOBUFS;
52744 }
52745@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52746
52747 _enter("%p,%p,,,", cookie, page);
52748
52749- fscache_stat(&fscache_n_allocs);
52750+ fscache_stat_unchecked(&fscache_n_allocs);
52751
52752 if (hlist_empty(&cookie->backing_objects))
52753 goto nobufs;
52754@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52755 goto nobufs_unlock;
52756 spin_unlock(&cookie->lock);
52757
52758- fscache_stat(&fscache_n_alloc_ops);
52759+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52760
52761 ret = fscache_wait_for_retrieval_activation(
52762 object, op,
52763@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52764
52765 error:
52766 if (ret == -ERESTARTSYS)
52767- fscache_stat(&fscache_n_allocs_intr);
52768+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52769 else if (ret < 0)
52770- fscache_stat(&fscache_n_allocs_nobufs);
52771+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52772 else
52773- fscache_stat(&fscache_n_allocs_ok);
52774+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52775
52776 fscache_put_retrieval(op);
52777 _leave(" = %d", ret);
52778@@ -677,7 +677,7 @@ nobufs_unlock:
52779 spin_unlock(&cookie->lock);
52780 kfree(op);
52781 nobufs:
52782- fscache_stat(&fscache_n_allocs_nobufs);
52783+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52784 _leave(" = -ENOBUFS");
52785 return -ENOBUFS;
52786 }
52787@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52788
52789 spin_lock(&cookie->stores_lock);
52790
52791- fscache_stat(&fscache_n_store_calls);
52792+ fscache_stat_unchecked(&fscache_n_store_calls);
52793
52794 /* find a page to store */
52795 page = NULL;
52796@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52797 page = results[0];
52798 _debug("gang %d [%lx]", n, page->index);
52799 if (page->index > op->store_limit) {
52800- fscache_stat(&fscache_n_store_pages_over_limit);
52801+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52802 goto superseded;
52803 }
52804
52805@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52806 spin_unlock(&cookie->stores_lock);
52807 spin_unlock(&object->lock);
52808
52809- fscache_stat(&fscache_n_store_pages);
52810+ fscache_stat_unchecked(&fscache_n_store_pages);
52811 fscache_stat(&fscache_n_cop_write_page);
52812 ret = object->cache->ops->write_page(op, page);
52813 fscache_stat_d(&fscache_n_cop_write_page);
52814@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52815 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52816 ASSERT(PageFsCache(page));
52817
52818- fscache_stat(&fscache_n_stores);
52819+ fscache_stat_unchecked(&fscache_n_stores);
52820
52821 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52822 _leave(" = -ENOBUFS [invalidating]");
52823@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52824 spin_unlock(&cookie->stores_lock);
52825 spin_unlock(&object->lock);
52826
52827- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52828+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52829 op->store_limit = object->store_limit;
52830
52831 if (fscache_submit_op(object, &op->op) < 0)
52832@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52833
52834 spin_unlock(&cookie->lock);
52835 radix_tree_preload_end();
52836- fscache_stat(&fscache_n_store_ops);
52837- fscache_stat(&fscache_n_stores_ok);
52838+ fscache_stat_unchecked(&fscache_n_store_ops);
52839+ fscache_stat_unchecked(&fscache_n_stores_ok);
52840
52841 /* the work queue now carries its own ref on the object */
52842 fscache_put_operation(&op->op);
52843@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52844 return 0;
52845
52846 already_queued:
52847- fscache_stat(&fscache_n_stores_again);
52848+ fscache_stat_unchecked(&fscache_n_stores_again);
52849 already_pending:
52850 spin_unlock(&cookie->stores_lock);
52851 spin_unlock(&object->lock);
52852 spin_unlock(&cookie->lock);
52853 radix_tree_preload_end();
52854 kfree(op);
52855- fscache_stat(&fscache_n_stores_ok);
52856+ fscache_stat_unchecked(&fscache_n_stores_ok);
52857 _leave(" = 0");
52858 return 0;
52859
52860@@ -959,14 +959,14 @@ nobufs:
52861 spin_unlock(&cookie->lock);
52862 radix_tree_preload_end();
52863 kfree(op);
52864- fscache_stat(&fscache_n_stores_nobufs);
52865+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52866 _leave(" = -ENOBUFS");
52867 return -ENOBUFS;
52868
52869 nomem_free:
52870 kfree(op);
52871 nomem:
52872- fscache_stat(&fscache_n_stores_oom);
52873+ fscache_stat_unchecked(&fscache_n_stores_oom);
52874 _leave(" = -ENOMEM");
52875 return -ENOMEM;
52876 }
52877@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52878 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52879 ASSERTCMP(page, !=, NULL);
52880
52881- fscache_stat(&fscache_n_uncaches);
52882+ fscache_stat_unchecked(&fscache_n_uncaches);
52883
52884 /* cache withdrawal may beat us to it */
52885 if (!PageFsCache(page))
52886@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52887 struct fscache_cookie *cookie = op->op.object->cookie;
52888
52889 #ifdef CONFIG_FSCACHE_STATS
52890- atomic_inc(&fscache_n_marks);
52891+ atomic_inc_unchecked(&fscache_n_marks);
52892 #endif
52893
52894 _debug("- mark %p{%lx}", page, page->index);
52895diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52896index 40d13c7..ddf52b9 100644
52897--- a/fs/fscache/stats.c
52898+++ b/fs/fscache/stats.c
52899@@ -18,99 +18,99 @@
52900 /*
52901 * operation counters
52902 */
52903-atomic_t fscache_n_op_pend;
52904-atomic_t fscache_n_op_run;
52905-atomic_t fscache_n_op_enqueue;
52906-atomic_t fscache_n_op_requeue;
52907-atomic_t fscache_n_op_deferred_release;
52908-atomic_t fscache_n_op_release;
52909-atomic_t fscache_n_op_gc;
52910-atomic_t fscache_n_op_cancelled;
52911-atomic_t fscache_n_op_rejected;
52912+atomic_unchecked_t fscache_n_op_pend;
52913+atomic_unchecked_t fscache_n_op_run;
52914+atomic_unchecked_t fscache_n_op_enqueue;
52915+atomic_unchecked_t fscache_n_op_requeue;
52916+atomic_unchecked_t fscache_n_op_deferred_release;
52917+atomic_unchecked_t fscache_n_op_release;
52918+atomic_unchecked_t fscache_n_op_gc;
52919+atomic_unchecked_t fscache_n_op_cancelled;
52920+atomic_unchecked_t fscache_n_op_rejected;
52921
52922-atomic_t fscache_n_attr_changed;
52923-atomic_t fscache_n_attr_changed_ok;
52924-atomic_t fscache_n_attr_changed_nobufs;
52925-atomic_t fscache_n_attr_changed_nomem;
52926-atomic_t fscache_n_attr_changed_calls;
52927+atomic_unchecked_t fscache_n_attr_changed;
52928+atomic_unchecked_t fscache_n_attr_changed_ok;
52929+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52930+atomic_unchecked_t fscache_n_attr_changed_nomem;
52931+atomic_unchecked_t fscache_n_attr_changed_calls;
52932
52933-atomic_t fscache_n_allocs;
52934-atomic_t fscache_n_allocs_ok;
52935-atomic_t fscache_n_allocs_wait;
52936-atomic_t fscache_n_allocs_nobufs;
52937-atomic_t fscache_n_allocs_intr;
52938-atomic_t fscache_n_allocs_object_dead;
52939-atomic_t fscache_n_alloc_ops;
52940-atomic_t fscache_n_alloc_op_waits;
52941+atomic_unchecked_t fscache_n_allocs;
52942+atomic_unchecked_t fscache_n_allocs_ok;
52943+atomic_unchecked_t fscache_n_allocs_wait;
52944+atomic_unchecked_t fscache_n_allocs_nobufs;
52945+atomic_unchecked_t fscache_n_allocs_intr;
52946+atomic_unchecked_t fscache_n_allocs_object_dead;
52947+atomic_unchecked_t fscache_n_alloc_ops;
52948+atomic_unchecked_t fscache_n_alloc_op_waits;
52949
52950-atomic_t fscache_n_retrievals;
52951-atomic_t fscache_n_retrievals_ok;
52952-atomic_t fscache_n_retrievals_wait;
52953-atomic_t fscache_n_retrievals_nodata;
52954-atomic_t fscache_n_retrievals_nobufs;
52955-atomic_t fscache_n_retrievals_intr;
52956-atomic_t fscache_n_retrievals_nomem;
52957-atomic_t fscache_n_retrievals_object_dead;
52958-atomic_t fscache_n_retrieval_ops;
52959-atomic_t fscache_n_retrieval_op_waits;
52960+atomic_unchecked_t fscache_n_retrievals;
52961+atomic_unchecked_t fscache_n_retrievals_ok;
52962+atomic_unchecked_t fscache_n_retrievals_wait;
52963+atomic_unchecked_t fscache_n_retrievals_nodata;
52964+atomic_unchecked_t fscache_n_retrievals_nobufs;
52965+atomic_unchecked_t fscache_n_retrievals_intr;
52966+atomic_unchecked_t fscache_n_retrievals_nomem;
52967+atomic_unchecked_t fscache_n_retrievals_object_dead;
52968+atomic_unchecked_t fscache_n_retrieval_ops;
52969+atomic_unchecked_t fscache_n_retrieval_op_waits;
52970
52971-atomic_t fscache_n_stores;
52972-atomic_t fscache_n_stores_ok;
52973-atomic_t fscache_n_stores_again;
52974-atomic_t fscache_n_stores_nobufs;
52975-atomic_t fscache_n_stores_oom;
52976-atomic_t fscache_n_store_ops;
52977-atomic_t fscache_n_store_calls;
52978-atomic_t fscache_n_store_pages;
52979-atomic_t fscache_n_store_radix_deletes;
52980-atomic_t fscache_n_store_pages_over_limit;
52981+atomic_unchecked_t fscache_n_stores;
52982+atomic_unchecked_t fscache_n_stores_ok;
52983+atomic_unchecked_t fscache_n_stores_again;
52984+atomic_unchecked_t fscache_n_stores_nobufs;
52985+atomic_unchecked_t fscache_n_stores_oom;
52986+atomic_unchecked_t fscache_n_store_ops;
52987+atomic_unchecked_t fscache_n_store_calls;
52988+atomic_unchecked_t fscache_n_store_pages;
52989+atomic_unchecked_t fscache_n_store_radix_deletes;
52990+atomic_unchecked_t fscache_n_store_pages_over_limit;
52991
52992-atomic_t fscache_n_store_vmscan_not_storing;
52993-atomic_t fscache_n_store_vmscan_gone;
52994-atomic_t fscache_n_store_vmscan_busy;
52995-atomic_t fscache_n_store_vmscan_cancelled;
52996-atomic_t fscache_n_store_vmscan_wait;
52997+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52998+atomic_unchecked_t fscache_n_store_vmscan_gone;
52999+atomic_unchecked_t fscache_n_store_vmscan_busy;
53000+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
53001+atomic_unchecked_t fscache_n_store_vmscan_wait;
53002
53003-atomic_t fscache_n_marks;
53004-atomic_t fscache_n_uncaches;
53005+atomic_unchecked_t fscache_n_marks;
53006+atomic_unchecked_t fscache_n_uncaches;
53007
53008-atomic_t fscache_n_acquires;
53009-atomic_t fscache_n_acquires_null;
53010-atomic_t fscache_n_acquires_no_cache;
53011-atomic_t fscache_n_acquires_ok;
53012-atomic_t fscache_n_acquires_nobufs;
53013-atomic_t fscache_n_acquires_oom;
53014+atomic_unchecked_t fscache_n_acquires;
53015+atomic_unchecked_t fscache_n_acquires_null;
53016+atomic_unchecked_t fscache_n_acquires_no_cache;
53017+atomic_unchecked_t fscache_n_acquires_ok;
53018+atomic_unchecked_t fscache_n_acquires_nobufs;
53019+atomic_unchecked_t fscache_n_acquires_oom;
53020
53021-atomic_t fscache_n_invalidates;
53022-atomic_t fscache_n_invalidates_run;
53023+atomic_unchecked_t fscache_n_invalidates;
53024+atomic_unchecked_t fscache_n_invalidates_run;
53025
53026-atomic_t fscache_n_updates;
53027-atomic_t fscache_n_updates_null;
53028-atomic_t fscache_n_updates_run;
53029+atomic_unchecked_t fscache_n_updates;
53030+atomic_unchecked_t fscache_n_updates_null;
53031+atomic_unchecked_t fscache_n_updates_run;
53032
53033-atomic_t fscache_n_relinquishes;
53034-atomic_t fscache_n_relinquishes_null;
53035-atomic_t fscache_n_relinquishes_waitcrt;
53036-atomic_t fscache_n_relinquishes_retire;
53037+atomic_unchecked_t fscache_n_relinquishes;
53038+atomic_unchecked_t fscache_n_relinquishes_null;
53039+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53040+atomic_unchecked_t fscache_n_relinquishes_retire;
53041
53042-atomic_t fscache_n_cookie_index;
53043-atomic_t fscache_n_cookie_data;
53044-atomic_t fscache_n_cookie_special;
53045+atomic_unchecked_t fscache_n_cookie_index;
53046+atomic_unchecked_t fscache_n_cookie_data;
53047+atomic_unchecked_t fscache_n_cookie_special;
53048
53049-atomic_t fscache_n_object_alloc;
53050-atomic_t fscache_n_object_no_alloc;
53051-atomic_t fscache_n_object_lookups;
53052-atomic_t fscache_n_object_lookups_negative;
53053-atomic_t fscache_n_object_lookups_positive;
53054-atomic_t fscache_n_object_lookups_timed_out;
53055-atomic_t fscache_n_object_created;
53056-atomic_t fscache_n_object_avail;
53057-atomic_t fscache_n_object_dead;
53058+atomic_unchecked_t fscache_n_object_alloc;
53059+atomic_unchecked_t fscache_n_object_no_alloc;
53060+atomic_unchecked_t fscache_n_object_lookups;
53061+atomic_unchecked_t fscache_n_object_lookups_negative;
53062+atomic_unchecked_t fscache_n_object_lookups_positive;
53063+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53064+atomic_unchecked_t fscache_n_object_created;
53065+atomic_unchecked_t fscache_n_object_avail;
53066+atomic_unchecked_t fscache_n_object_dead;
53067
53068-atomic_t fscache_n_checkaux_none;
53069-atomic_t fscache_n_checkaux_okay;
53070-atomic_t fscache_n_checkaux_update;
53071-atomic_t fscache_n_checkaux_obsolete;
53072+atomic_unchecked_t fscache_n_checkaux_none;
53073+atomic_unchecked_t fscache_n_checkaux_okay;
53074+atomic_unchecked_t fscache_n_checkaux_update;
53075+atomic_unchecked_t fscache_n_checkaux_obsolete;
53076
53077 atomic_t fscache_n_cop_alloc_object;
53078 atomic_t fscache_n_cop_lookup_object;
53079@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53080 seq_puts(m, "FS-Cache statistics\n");
53081
53082 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53083- atomic_read(&fscache_n_cookie_index),
53084- atomic_read(&fscache_n_cookie_data),
53085- atomic_read(&fscache_n_cookie_special));
53086+ atomic_read_unchecked(&fscache_n_cookie_index),
53087+ atomic_read_unchecked(&fscache_n_cookie_data),
53088+ atomic_read_unchecked(&fscache_n_cookie_special));
53089
53090 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53091- atomic_read(&fscache_n_object_alloc),
53092- atomic_read(&fscache_n_object_no_alloc),
53093- atomic_read(&fscache_n_object_avail),
53094- atomic_read(&fscache_n_object_dead));
53095+ atomic_read_unchecked(&fscache_n_object_alloc),
53096+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53097+ atomic_read_unchecked(&fscache_n_object_avail),
53098+ atomic_read_unchecked(&fscache_n_object_dead));
53099 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53100- atomic_read(&fscache_n_checkaux_none),
53101- atomic_read(&fscache_n_checkaux_okay),
53102- atomic_read(&fscache_n_checkaux_update),
53103- atomic_read(&fscache_n_checkaux_obsolete));
53104+ atomic_read_unchecked(&fscache_n_checkaux_none),
53105+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53106+ atomic_read_unchecked(&fscache_n_checkaux_update),
53107+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53108
53109 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53110- atomic_read(&fscache_n_marks),
53111- atomic_read(&fscache_n_uncaches));
53112+ atomic_read_unchecked(&fscache_n_marks),
53113+ atomic_read_unchecked(&fscache_n_uncaches));
53114
53115 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53116 " oom=%u\n",
53117- atomic_read(&fscache_n_acquires),
53118- atomic_read(&fscache_n_acquires_null),
53119- atomic_read(&fscache_n_acquires_no_cache),
53120- atomic_read(&fscache_n_acquires_ok),
53121- atomic_read(&fscache_n_acquires_nobufs),
53122- atomic_read(&fscache_n_acquires_oom));
53123+ atomic_read_unchecked(&fscache_n_acquires),
53124+ atomic_read_unchecked(&fscache_n_acquires_null),
53125+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53126+ atomic_read_unchecked(&fscache_n_acquires_ok),
53127+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53128+ atomic_read_unchecked(&fscache_n_acquires_oom));
53129
53130 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53131- atomic_read(&fscache_n_object_lookups),
53132- atomic_read(&fscache_n_object_lookups_negative),
53133- atomic_read(&fscache_n_object_lookups_positive),
53134- atomic_read(&fscache_n_object_created),
53135- atomic_read(&fscache_n_object_lookups_timed_out));
53136+ atomic_read_unchecked(&fscache_n_object_lookups),
53137+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53138+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53139+ atomic_read_unchecked(&fscache_n_object_created),
53140+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53141
53142 seq_printf(m, "Invals : n=%u run=%u\n",
53143- atomic_read(&fscache_n_invalidates),
53144- atomic_read(&fscache_n_invalidates_run));
53145+ atomic_read_unchecked(&fscache_n_invalidates),
53146+ atomic_read_unchecked(&fscache_n_invalidates_run));
53147
53148 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53149- atomic_read(&fscache_n_updates),
53150- atomic_read(&fscache_n_updates_null),
53151- atomic_read(&fscache_n_updates_run));
53152+ atomic_read_unchecked(&fscache_n_updates),
53153+ atomic_read_unchecked(&fscache_n_updates_null),
53154+ atomic_read_unchecked(&fscache_n_updates_run));
53155
53156 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53157- atomic_read(&fscache_n_relinquishes),
53158- atomic_read(&fscache_n_relinquishes_null),
53159- atomic_read(&fscache_n_relinquishes_waitcrt),
53160- atomic_read(&fscache_n_relinquishes_retire));
53161+ atomic_read_unchecked(&fscache_n_relinquishes),
53162+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53163+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53164+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53165
53166 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53167- atomic_read(&fscache_n_attr_changed),
53168- atomic_read(&fscache_n_attr_changed_ok),
53169- atomic_read(&fscache_n_attr_changed_nobufs),
53170- atomic_read(&fscache_n_attr_changed_nomem),
53171- atomic_read(&fscache_n_attr_changed_calls));
53172+ atomic_read_unchecked(&fscache_n_attr_changed),
53173+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53174+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53175+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53176+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53177
53178 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53179- atomic_read(&fscache_n_allocs),
53180- atomic_read(&fscache_n_allocs_ok),
53181- atomic_read(&fscache_n_allocs_wait),
53182- atomic_read(&fscache_n_allocs_nobufs),
53183- atomic_read(&fscache_n_allocs_intr));
53184+ atomic_read_unchecked(&fscache_n_allocs),
53185+ atomic_read_unchecked(&fscache_n_allocs_ok),
53186+ atomic_read_unchecked(&fscache_n_allocs_wait),
53187+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53188+ atomic_read_unchecked(&fscache_n_allocs_intr));
53189 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53190- atomic_read(&fscache_n_alloc_ops),
53191- atomic_read(&fscache_n_alloc_op_waits),
53192- atomic_read(&fscache_n_allocs_object_dead));
53193+ atomic_read_unchecked(&fscache_n_alloc_ops),
53194+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53195+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53196
53197 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53198 " int=%u oom=%u\n",
53199- atomic_read(&fscache_n_retrievals),
53200- atomic_read(&fscache_n_retrievals_ok),
53201- atomic_read(&fscache_n_retrievals_wait),
53202- atomic_read(&fscache_n_retrievals_nodata),
53203- atomic_read(&fscache_n_retrievals_nobufs),
53204- atomic_read(&fscache_n_retrievals_intr),
53205- atomic_read(&fscache_n_retrievals_nomem));
53206+ atomic_read_unchecked(&fscache_n_retrievals),
53207+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53208+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53209+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53210+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53211+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53212+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53213 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53214- atomic_read(&fscache_n_retrieval_ops),
53215- atomic_read(&fscache_n_retrieval_op_waits),
53216- atomic_read(&fscache_n_retrievals_object_dead));
53217+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53218+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53219+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53220
53221 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53222- atomic_read(&fscache_n_stores),
53223- atomic_read(&fscache_n_stores_ok),
53224- atomic_read(&fscache_n_stores_again),
53225- atomic_read(&fscache_n_stores_nobufs),
53226- atomic_read(&fscache_n_stores_oom));
53227+ atomic_read_unchecked(&fscache_n_stores),
53228+ atomic_read_unchecked(&fscache_n_stores_ok),
53229+ atomic_read_unchecked(&fscache_n_stores_again),
53230+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53231+ atomic_read_unchecked(&fscache_n_stores_oom));
53232 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53233- atomic_read(&fscache_n_store_ops),
53234- atomic_read(&fscache_n_store_calls),
53235- atomic_read(&fscache_n_store_pages),
53236- atomic_read(&fscache_n_store_radix_deletes),
53237- atomic_read(&fscache_n_store_pages_over_limit));
53238+ atomic_read_unchecked(&fscache_n_store_ops),
53239+ atomic_read_unchecked(&fscache_n_store_calls),
53240+ atomic_read_unchecked(&fscache_n_store_pages),
53241+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53242+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53243
53244 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53245- atomic_read(&fscache_n_store_vmscan_not_storing),
53246- atomic_read(&fscache_n_store_vmscan_gone),
53247- atomic_read(&fscache_n_store_vmscan_busy),
53248- atomic_read(&fscache_n_store_vmscan_cancelled),
53249- atomic_read(&fscache_n_store_vmscan_wait));
53250+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53251+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53252+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53253+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53254+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53255
53256 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53257- atomic_read(&fscache_n_op_pend),
53258- atomic_read(&fscache_n_op_run),
53259- atomic_read(&fscache_n_op_enqueue),
53260- atomic_read(&fscache_n_op_cancelled),
53261- atomic_read(&fscache_n_op_rejected));
53262+ atomic_read_unchecked(&fscache_n_op_pend),
53263+ atomic_read_unchecked(&fscache_n_op_run),
53264+ atomic_read_unchecked(&fscache_n_op_enqueue),
53265+ atomic_read_unchecked(&fscache_n_op_cancelled),
53266+ atomic_read_unchecked(&fscache_n_op_rejected));
53267 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53268- atomic_read(&fscache_n_op_deferred_release),
53269- atomic_read(&fscache_n_op_release),
53270- atomic_read(&fscache_n_op_gc));
53271+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53272+ atomic_read_unchecked(&fscache_n_op_release),
53273+ atomic_read_unchecked(&fscache_n_op_gc));
53274
53275 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53276 atomic_read(&fscache_n_cop_alloc_object),
53277diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53278index aef34b1..59bfd7b 100644
53279--- a/fs/fuse/cuse.c
53280+++ b/fs/fuse/cuse.c
53281@@ -600,10 +600,12 @@ static int __init cuse_init(void)
53282 INIT_LIST_HEAD(&cuse_conntbl[i]);
53283
53284 /* inherit and extend fuse_dev_operations */
53285- cuse_channel_fops = fuse_dev_operations;
53286- cuse_channel_fops.owner = THIS_MODULE;
53287- cuse_channel_fops.open = cuse_channel_open;
53288- cuse_channel_fops.release = cuse_channel_release;
53289+ pax_open_kernel();
53290+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53291+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53292+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53293+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53294+ pax_close_kernel();
53295
53296 cuse_class = class_create(THIS_MODULE, "cuse");
53297 if (IS_ERR(cuse_class))
53298diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53299index 1d55f94..088da65 100644
53300--- a/fs/fuse/dev.c
53301+++ b/fs/fuse/dev.c
53302@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53303 ret = 0;
53304 pipe_lock(pipe);
53305
53306- if (!pipe->readers) {
53307+ if (!atomic_read(&pipe->readers)) {
53308 send_sig(SIGPIPE, current, 0);
53309 if (!ret)
53310 ret = -EPIPE;
53311@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53312 page_nr++;
53313 ret += buf->len;
53314
53315- if (pipe->files)
53316+ if (atomic_read(&pipe->files))
53317 do_wakeup = 1;
53318 }
53319
53320diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53321index f3f783d..bf11a8e 100644
53322--- a/fs/fuse/dir.c
53323+++ b/fs/fuse/dir.c
53324@@ -1415,7 +1415,7 @@ static char *read_link(struct dentry *dentry)
53325 return link;
53326 }
53327
53328-static void free_link(char *link)
53329+static void free_link(const char *link)
53330 {
53331 if (!IS_ERR(link))
53332 free_page((unsigned long) link);
53333diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53334index 62b484e..0f9a140 100644
53335--- a/fs/gfs2/inode.c
53336+++ b/fs/gfs2/inode.c
53337@@ -1441,7 +1441,7 @@ out:
53338
53339 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53340 {
53341- char *s = nd_get_link(nd);
53342+ const char *s = nd_get_link(nd);
53343 if (!IS_ERR(s))
53344 kfree(s);
53345 }
53346diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53347index a3f868a..bb308ae 100644
53348--- a/fs/hugetlbfs/inode.c
53349+++ b/fs/hugetlbfs/inode.c
53350@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53351 struct mm_struct *mm = current->mm;
53352 struct vm_area_struct *vma;
53353 struct hstate *h = hstate_file(file);
53354+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53355 struct vm_unmapped_area_info info;
53356
53357 if (len & ~huge_page_mask(h))
53358@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53359 return addr;
53360 }
53361
53362+#ifdef CONFIG_PAX_RANDMMAP
53363+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53364+#endif
53365+
53366 if (addr) {
53367 addr = ALIGN(addr, huge_page_size(h));
53368 vma = find_vma(mm, addr);
53369- if (TASK_SIZE - len >= addr &&
53370- (!vma || addr + len <= vma->vm_start))
53371+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53372 return addr;
53373 }
53374
53375 info.flags = 0;
53376 info.length = len;
53377 info.low_limit = TASK_UNMAPPED_BASE;
53378+
53379+#ifdef CONFIG_PAX_RANDMMAP
53380+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53381+ info.low_limit += mm->delta_mmap;
53382+#endif
53383+
53384 info.high_limit = TASK_SIZE;
53385 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53386 info.align_offset = 0;
53387@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53388 };
53389 MODULE_ALIAS_FS("hugetlbfs");
53390
53391-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53392+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53393
53394 static int can_do_hugetlb_shm(void)
53395 {
53396diff --git a/fs/inode.c b/fs/inode.c
53397index 00d5fc3..98ce7d7 100644
53398--- a/fs/inode.c
53399+++ b/fs/inode.c
53400@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
53401
53402 #ifdef CONFIG_SMP
53403 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53404- static atomic_t shared_last_ino;
53405- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53406+ static atomic_unchecked_t shared_last_ino;
53407+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53408
53409 res = next - LAST_INO_BATCH;
53410 }
53411diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53412index 4a6cf28..d3a29d3 100644
53413--- a/fs/jffs2/erase.c
53414+++ b/fs/jffs2/erase.c
53415@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53416 struct jffs2_unknown_node marker = {
53417 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53418 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53419- .totlen = cpu_to_je32(c->cleanmarker_size)
53420+ .totlen = cpu_to_je32(c->cleanmarker_size),
53421+ .hdr_crc = cpu_to_je32(0)
53422 };
53423
53424 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53425diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53426index a6597d6..41b30ec 100644
53427--- a/fs/jffs2/wbuf.c
53428+++ b/fs/jffs2/wbuf.c
53429@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53430 {
53431 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53432 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53433- .totlen = constant_cpu_to_je32(8)
53434+ .totlen = constant_cpu_to_je32(8),
53435+ .hdr_crc = constant_cpu_to_je32(0)
53436 };
53437
53438 /*
53439diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53440index 788e0a9..8433098 100644
53441--- a/fs/jfs/super.c
53442+++ b/fs/jfs/super.c
53443@@ -878,7 +878,7 @@ static int __init init_jfs_fs(void)
53444
53445 jfs_inode_cachep =
53446 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53447- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53448+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53449 init_once);
53450 if (jfs_inode_cachep == NULL)
53451 return -ENOMEM;
53452diff --git a/fs/libfs.c b/fs/libfs.c
53453index 916da8c..1588998 100644
53454--- a/fs/libfs.c
53455+++ b/fs/libfs.c
53456@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53457
53458 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53459 struct dentry *next;
53460+ char d_name[sizeof(next->d_iname)];
53461+ const unsigned char *name;
53462+
53463 next = list_entry(p, struct dentry, d_u.d_child);
53464 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53465 if (!simple_positive(next)) {
53466@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53467
53468 spin_unlock(&next->d_lock);
53469 spin_unlock(&dentry->d_lock);
53470- if (filldir(dirent, next->d_name.name,
53471+ name = next->d_name.name;
53472+ if (name == next->d_iname) {
53473+ memcpy(d_name, name, next->d_name.len);
53474+ name = d_name;
53475+ }
53476+ if (filldir(dirent, name,
53477 next->d_name.len, filp->f_pos,
53478 next->d_inode->i_ino,
53479 dt_type(next->d_inode)) < 0)
53480diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53481index 9760ecb..9b838ef 100644
53482--- a/fs/lockd/clntproc.c
53483+++ b/fs/lockd/clntproc.c
53484@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53485 /*
53486 * Cookie counter for NLM requests
53487 */
53488-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53489+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53490
53491 void nlmclnt_next_cookie(struct nlm_cookie *c)
53492 {
53493- u32 cookie = atomic_inc_return(&nlm_cookie);
53494+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53495
53496 memcpy(c->data, &cookie, 4);
53497 c->len=4;
53498diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
53499index a2aa97d..10d6c41 100644
53500--- a/fs/lockd/svc.c
53501+++ b/fs/lockd/svc.c
53502@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
53503 svc_sock_update_bufs(serv);
53504 serv->sv_maxconn = nlm_max_connections;
53505
53506- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
53507+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
53508 if (IS_ERR(nlmsvc_task)) {
53509 error = PTR_ERR(nlmsvc_task);
53510 printk(KERN_WARNING
53511diff --git a/fs/locks.c b/fs/locks.c
53512index cb424a4..850e4dd 100644
53513--- a/fs/locks.c
53514+++ b/fs/locks.c
53515@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53516 return;
53517
53518 if (filp->f_op && filp->f_op->flock) {
53519- struct file_lock fl = {
53520+ struct file_lock flock = {
53521 .fl_pid = current->tgid,
53522 .fl_file = filp,
53523 .fl_flags = FL_FLOCK,
53524 .fl_type = F_UNLCK,
53525 .fl_end = OFFSET_MAX,
53526 };
53527- filp->f_op->flock(filp, F_SETLKW, &fl);
53528- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53529- fl.fl_ops->fl_release_private(&fl);
53530+ filp->f_op->flock(filp, F_SETLKW, &flock);
53531+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53532+ flock.fl_ops->fl_release_private(&flock);
53533 }
53534
53535 lock_flocks();
53536diff --git a/fs/namei.c b/fs/namei.c
53537index 9ed9361..2b72db1 100644
53538--- a/fs/namei.c
53539+++ b/fs/namei.c
53540@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53541 if (ret != -EACCES)
53542 return ret;
53543
53544+#ifdef CONFIG_GRKERNSEC
53545+ /* we'll block if we have to log due to a denied capability use */
53546+ if (mask & MAY_NOT_BLOCK)
53547+ return -ECHILD;
53548+#endif
53549+
53550 if (S_ISDIR(inode->i_mode)) {
53551 /* DACs are overridable for directories */
53552- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53553- return 0;
53554 if (!(mask & MAY_WRITE))
53555- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53556+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53557+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53558 return 0;
53559+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53560+ return 0;
53561 return -EACCES;
53562 }
53563 /*
53564+ * Searching includes executable on directories, else just read.
53565+ */
53566+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53567+ if (mask == MAY_READ)
53568+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53569+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53570+ return 0;
53571+
53572+ /*
53573 * Read/write DACs are always overridable.
53574 * Executable DACs are overridable when there is
53575 * at least one exec bit set.
53576@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53577 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53578 return 0;
53579
53580- /*
53581- * Searching includes executable on directories, else just read.
53582- */
53583- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53584- if (mask == MAY_READ)
53585- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53586- return 0;
53587-
53588 return -EACCES;
53589 }
53590
53591@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53592 {
53593 struct dentry *dentry = link->dentry;
53594 int error;
53595- char *s;
53596+ const char *s;
53597
53598 BUG_ON(nd->flags & LOOKUP_RCU);
53599
53600@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53601 if (error)
53602 goto out_put_nd_path;
53603
53604+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53605+ dentry->d_inode, dentry, nd->path.mnt)) {
53606+ error = -EACCES;
53607+ goto out_put_nd_path;
53608+ }
53609+
53610 nd->last_type = LAST_BIND;
53611 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53612 error = PTR_ERR(*p);
53613@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53614 if (res)
53615 break;
53616 res = walk_component(nd, path, LOOKUP_FOLLOW);
53617+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53618+ res = -EACCES;
53619 put_link(nd, &link, cookie);
53620 } while (res > 0);
53621
53622@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
53623 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53624 {
53625 unsigned long a, b, adata, bdata, mask, hash, len;
53626- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53627+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53628
53629 hash = a = 0;
53630 len = -sizeof(unsigned long);
53631@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
53632 if (err)
53633 break;
53634 err = lookup_last(nd, &path);
53635+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53636+ err = -EACCES;
53637 put_link(nd, &link, cookie);
53638 }
53639 }
53640@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
53641 if (!err)
53642 err = complete_walk(nd);
53643
53644+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53645+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53646+ path_put(&nd->path);
53647+ err = -ENOENT;
53648+ }
53649+ }
53650+
53651 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53652 if (!can_lookup(nd->inode)) {
53653 path_put(&nd->path);
53654@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
53655 retval = path_lookupat(dfd, name->name,
53656 flags | LOOKUP_REVAL, nd);
53657
53658- if (likely(!retval))
53659+ if (likely(!retval)) {
53660 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53661+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53662+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53663+ path_put(&nd->path);
53664+ return -ENOENT;
53665+ }
53666+ }
53667+ }
53668 return retval;
53669 }
53670
53671@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53672 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53673 return -EPERM;
53674
53675+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53676+ return -EPERM;
53677+ if (gr_handle_rawio(inode))
53678+ return -EPERM;
53679+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53680+ return -EACCES;
53681+
53682 return 0;
53683 }
53684
53685@@ -2602,7 +2641,7 @@ looked_up:
53686 * cleared otherwise prior to returning.
53687 */
53688 static int lookup_open(struct nameidata *nd, struct path *path,
53689- struct file *file,
53690+ struct path *link, struct file *file,
53691 const struct open_flags *op,
53692 bool got_write, int *opened)
53693 {
53694@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53695 /* Negative dentry, just create the file */
53696 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53697 umode_t mode = op->mode;
53698+
53699+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53700+ error = -EACCES;
53701+ goto out_dput;
53702+ }
53703+
53704+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53705+ error = -EACCES;
53706+ goto out_dput;
53707+ }
53708+
53709 if (!IS_POSIXACL(dir->d_inode))
53710 mode &= ~current_umask();
53711 /*
53712@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53713 nd->flags & LOOKUP_EXCL);
53714 if (error)
53715 goto out_dput;
53716+ else
53717+ gr_handle_create(dentry, nd->path.mnt);
53718 }
53719 out_no_open:
53720 path->dentry = dentry;
53721@@ -2672,7 +2724,7 @@ out_dput:
53722 /*
53723 * Handle the last step of open()
53724 */
53725-static int do_last(struct nameidata *nd, struct path *path,
53726+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53727 struct file *file, const struct open_flags *op,
53728 int *opened, struct filename *name)
53729 {
53730@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53731 error = complete_walk(nd);
53732 if (error)
53733 return error;
53734+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53735+ error = -ENOENT;
53736+ goto out;
53737+ }
53738 audit_inode(name, nd->path.dentry, 0);
53739 if (open_flag & O_CREAT) {
53740 error = -EISDIR;
53741 goto out;
53742 }
53743+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53744+ error = -EACCES;
53745+ goto out;
53746+ }
53747 goto finish_open;
53748 case LAST_BIND:
53749 error = complete_walk(nd);
53750 if (error)
53751 return error;
53752+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53753+ error = -ENOENT;
53754+ goto out;
53755+ }
53756+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53757+ error = -EACCES;
53758+ goto out;
53759+ }
53760 audit_inode(name, dir, 0);
53761 goto finish_open;
53762 }
53763@@ -2759,7 +2827,7 @@ retry_lookup:
53764 */
53765 }
53766 mutex_lock(&dir->d_inode->i_mutex);
53767- error = lookup_open(nd, path, file, op, got_write, opened);
53768+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53769 mutex_unlock(&dir->d_inode->i_mutex);
53770
53771 if (error <= 0) {
53772@@ -2783,11 +2851,28 @@ retry_lookup:
53773 goto finish_open_created;
53774 }
53775
53776+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53777+ error = -ENOENT;
53778+ goto exit_dput;
53779+ }
53780+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53781+ error = -EACCES;
53782+ goto exit_dput;
53783+ }
53784+
53785 /*
53786 * create/update audit record if it already exists.
53787 */
53788- if (path->dentry->d_inode)
53789+ if (path->dentry->d_inode) {
53790+ /* only check if O_CREAT is specified, all other checks need to go
53791+ into may_open */
53792+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53793+ error = -EACCES;
53794+ goto exit_dput;
53795+ }
53796+
53797 audit_inode(name, path->dentry, 0);
53798+ }
53799
53800 /*
53801 * If atomic_open() acquired write access it is dropped now due to
53802@@ -2828,6 +2913,11 @@ finish_lookup:
53803 }
53804 }
53805 BUG_ON(inode != path->dentry->d_inode);
53806+ /* if we're resolving a symlink to another symlink */
53807+ if (link && gr_handle_symlink_owner(link, inode)) {
53808+ error = -EACCES;
53809+ goto out;
53810+ }
53811 return 1;
53812 }
53813
53814@@ -2837,7 +2927,6 @@ finish_lookup:
53815 save_parent.dentry = nd->path.dentry;
53816 save_parent.mnt = mntget(path->mnt);
53817 nd->path.dentry = path->dentry;
53818-
53819 }
53820 nd->inode = inode;
53821 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53822@@ -2846,6 +2935,16 @@ finish_lookup:
53823 path_put(&save_parent);
53824 return error;
53825 }
53826+
53827+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53828+ error = -ENOENT;
53829+ goto out;
53830+ }
53831+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53832+ error = -EACCES;
53833+ goto out;
53834+ }
53835+
53836 error = -EISDIR;
53837 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53838 goto out;
53839@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53840 if (unlikely(error))
53841 goto out;
53842
53843- error = do_last(nd, &path, file, op, &opened, pathname);
53844+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53845 while (unlikely(error > 0)) { /* trailing symlink */
53846 struct path link = path;
53847 void *cookie;
53848@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53849 error = follow_link(&link, nd, &cookie);
53850 if (unlikely(error))
53851 break;
53852- error = do_last(nd, &path, file, op, &opened, pathname);
53853+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53854 put_link(nd, &link, cookie);
53855 }
53856 out:
53857@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53858 goto unlock;
53859
53860 error = -EEXIST;
53861- if (dentry->d_inode)
53862+ if (dentry->d_inode) {
53863+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53864+ error = -ENOENT;
53865+ }
53866 goto fail;
53867+ }
53868 /*
53869 * Special case - lookup gave negative, but... we had foo/bar/
53870 * From the vfs_mknod() POV we just have a negative dentry -
53871@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53872 }
53873 EXPORT_SYMBOL(user_path_create);
53874
53875+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53876+{
53877+ struct filename *tmp = getname(pathname);
53878+ struct dentry *res;
53879+ if (IS_ERR(tmp))
53880+ return ERR_CAST(tmp);
53881+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53882+ if (IS_ERR(res))
53883+ putname(tmp);
53884+ else
53885+ *to = tmp;
53886+ return res;
53887+}
53888+
53889 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53890 {
53891 int error = may_create(dir, dentry);
53892@@ -3177,6 +3294,17 @@ retry:
53893
53894 if (!IS_POSIXACL(path.dentry->d_inode))
53895 mode &= ~current_umask();
53896+
53897+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53898+ error = -EPERM;
53899+ goto out;
53900+ }
53901+
53902+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53903+ error = -EACCES;
53904+ goto out;
53905+ }
53906+
53907 error = security_path_mknod(&path, dentry, mode, dev);
53908 if (error)
53909 goto out;
53910@@ -3193,6 +3321,8 @@ retry:
53911 break;
53912 }
53913 out:
53914+ if (!error)
53915+ gr_handle_create(dentry, path.mnt);
53916 done_path_create(&path, dentry);
53917 if (retry_estale(error, lookup_flags)) {
53918 lookup_flags |= LOOKUP_REVAL;
53919@@ -3245,9 +3375,16 @@ retry:
53920
53921 if (!IS_POSIXACL(path.dentry->d_inode))
53922 mode &= ~current_umask();
53923+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53924+ error = -EACCES;
53925+ goto out;
53926+ }
53927 error = security_path_mkdir(&path, dentry, mode);
53928 if (!error)
53929 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53930+ if (!error)
53931+ gr_handle_create(dentry, path.mnt);
53932+out:
53933 done_path_create(&path, dentry);
53934 if (retry_estale(error, lookup_flags)) {
53935 lookup_flags |= LOOKUP_REVAL;
53936@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53937 struct filename *name;
53938 struct dentry *dentry;
53939 struct nameidata nd;
53940+ ino_t saved_ino = 0;
53941+ dev_t saved_dev = 0;
53942 unsigned int lookup_flags = 0;
53943 retry:
53944 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53945@@ -3360,10 +3499,21 @@ retry:
53946 error = -ENOENT;
53947 goto exit3;
53948 }
53949+
53950+ saved_ino = dentry->d_inode->i_ino;
53951+ saved_dev = gr_get_dev_from_dentry(dentry);
53952+
53953+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53954+ error = -EACCES;
53955+ goto exit3;
53956+ }
53957+
53958 error = security_path_rmdir(&nd.path, dentry);
53959 if (error)
53960 goto exit3;
53961 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53962+ if (!error && (saved_dev || saved_ino))
53963+ gr_handle_delete(saved_ino, saved_dev);
53964 exit3:
53965 dput(dentry);
53966 exit2:
53967@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53968 struct dentry *dentry;
53969 struct nameidata nd;
53970 struct inode *inode = NULL;
53971+ ino_t saved_ino = 0;
53972+ dev_t saved_dev = 0;
53973 unsigned int lookup_flags = 0;
53974 retry:
53975 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53976@@ -3455,10 +3607,22 @@ retry:
53977 if (!inode)
53978 goto slashes;
53979 ihold(inode);
53980+
53981+ if (inode->i_nlink <= 1) {
53982+ saved_ino = inode->i_ino;
53983+ saved_dev = gr_get_dev_from_dentry(dentry);
53984+ }
53985+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53986+ error = -EACCES;
53987+ goto exit2;
53988+ }
53989+
53990 error = security_path_unlink(&nd.path, dentry);
53991 if (error)
53992 goto exit2;
53993 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53994+ if (!error && (saved_ino || saved_dev))
53995+ gr_handle_delete(saved_ino, saved_dev);
53996 exit2:
53997 dput(dentry);
53998 }
53999@@ -3536,9 +3700,17 @@ retry:
54000 if (IS_ERR(dentry))
54001 goto out_putname;
54002
54003+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
54004+ error = -EACCES;
54005+ goto out;
54006+ }
54007+
54008 error = security_path_symlink(&path, dentry, from->name);
54009 if (!error)
54010 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
54011+ if (!error)
54012+ gr_handle_create(dentry, path.mnt);
54013+out:
54014 done_path_create(&path, dentry);
54015 if (retry_estale(error, lookup_flags)) {
54016 lookup_flags |= LOOKUP_REVAL;
54017@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
54018 {
54019 struct dentry *new_dentry;
54020 struct path old_path, new_path;
54021+ struct filename *to = NULL;
54022 int how = 0;
54023 int error;
54024
54025@@ -3635,7 +3808,7 @@ retry:
54026 if (error)
54027 return error;
54028
54029- new_dentry = user_path_create(newdfd, newname, &new_path,
54030+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
54031 (how & LOOKUP_REVAL));
54032 error = PTR_ERR(new_dentry);
54033 if (IS_ERR(new_dentry))
54034@@ -3647,11 +3820,28 @@ retry:
54035 error = may_linkat(&old_path);
54036 if (unlikely(error))
54037 goto out_dput;
54038+
54039+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
54040+ old_path.dentry->d_inode,
54041+ old_path.dentry->d_inode->i_mode, to)) {
54042+ error = -EACCES;
54043+ goto out_dput;
54044+ }
54045+
54046+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54047+ old_path.dentry, old_path.mnt, to)) {
54048+ error = -EACCES;
54049+ goto out_dput;
54050+ }
54051+
54052 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54053 if (error)
54054 goto out_dput;
54055 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54056+ if (!error)
54057+ gr_handle_create(new_dentry, new_path.mnt);
54058 out_dput:
54059+ putname(to);
54060 done_path_create(&new_path, new_dentry);
54061 if (retry_estale(error, how)) {
54062 how |= LOOKUP_REVAL;
54063@@ -3897,12 +4087,21 @@ retry:
54064 if (new_dentry == trap)
54065 goto exit5;
54066
54067+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54068+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54069+ to);
54070+ if (error)
54071+ goto exit5;
54072+
54073 error = security_path_rename(&oldnd.path, old_dentry,
54074 &newnd.path, new_dentry);
54075 if (error)
54076 goto exit5;
54077 error = vfs_rename(old_dir->d_inode, old_dentry,
54078 new_dir->d_inode, new_dentry);
54079+ if (!error)
54080+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54081+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54082 exit5:
54083 dput(new_dentry);
54084 exit4:
54085@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54086
54087 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54088 {
54089+ char tmpbuf[64];
54090+ const char *newlink;
54091 int len;
54092
54093 len = PTR_ERR(link);
54094@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54095 len = strlen(link);
54096 if (len > (unsigned) buflen)
54097 len = buflen;
54098- if (copy_to_user(buffer, link, len))
54099+
54100+ if (len < sizeof(tmpbuf)) {
54101+ memcpy(tmpbuf, link, len);
54102+ newlink = tmpbuf;
54103+ } else
54104+ newlink = link;
54105+
54106+ if (copy_to_user(buffer, newlink, len))
54107 len = -EFAULT;
54108 out:
54109 return len;
54110diff --git a/fs/namespace.c b/fs/namespace.c
54111index 7b1ca9b..6faeccf 100644
54112--- a/fs/namespace.c
54113+++ b/fs/namespace.c
54114@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
54115 if (!(sb->s_flags & MS_RDONLY))
54116 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54117 up_write(&sb->s_umount);
54118+
54119+ gr_log_remount(mnt->mnt_devname, retval);
54120+
54121 return retval;
54122 }
54123
54124@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
54125 }
54126 br_write_unlock(&vfsmount_lock);
54127 namespace_unlock();
54128+
54129+ gr_log_unmount(mnt->mnt_devname, retval);
54130+
54131 return retval;
54132 }
54133
54134@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
54135 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
54136 */
54137
54138-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
54139+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
54140 {
54141 struct path path;
54142 struct mount *mnt;
54143@@ -1342,7 +1348,7 @@ out:
54144 /*
54145 * The 2.0 compatible umount. No flags.
54146 */
54147-SYSCALL_DEFINE1(oldumount, char __user *, name)
54148+SYSCALL_DEFINE1(oldumount, const char __user *, name)
54149 {
54150 return sys_umount(name, 0);
54151 }
54152@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54153 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54154 MS_STRICTATIME);
54155
54156+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54157+ retval = -EPERM;
54158+ goto dput_out;
54159+ }
54160+
54161+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54162+ retval = -EPERM;
54163+ goto dput_out;
54164+ }
54165+
54166 if (flags & MS_REMOUNT)
54167 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54168 data_page);
54169@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54170 dev_name, data_page);
54171 dput_out:
54172 path_put(&path);
54173+
54174+ gr_log_mount(dev_name, dir_name, retval);
54175+
54176 return retval;
54177 }
54178
54179@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
54180 }
54181 EXPORT_SYMBOL(mount_subtree);
54182
54183-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
54184- char __user *, type, unsigned long, flags, void __user *, data)
54185+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
54186+ const char __user *, type, unsigned long, flags, void __user *, data)
54187 {
54188 int ret;
54189 char *kernel_type;
54190@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54191 if (error)
54192 goto out2;
54193
54194+ if (gr_handle_chroot_pivot()) {
54195+ error = -EPERM;
54196+ goto out2;
54197+ }
54198+
54199 get_fs_root(current->fs, &root);
54200 old_mp = lock_mount(&old);
54201 error = PTR_ERR(old_mp);
54202@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54203 !nsown_capable(CAP_SYS_ADMIN))
54204 return -EPERM;
54205
54206- if (fs->users != 1)
54207+ if (atomic_read(&fs->users) != 1)
54208 return -EINVAL;
54209
54210 get_mnt_ns(mnt_ns);
54211diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
54212index cff089a..4c3d57a 100644
54213--- a/fs/nfs/callback.c
54214+++ b/fs/nfs/callback.c
54215@@ -211,7 +211,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54216 struct svc_rqst *rqstp;
54217 int (*callback_svc)(void *vrqstp);
54218 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
54219- char svc_name[12];
54220 int ret;
54221
54222 nfs_callback_bc_serv(minorversion, xprt, serv);
54223@@ -235,10 +234,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54224
54225 svc_sock_update_bufs(serv);
54226
54227- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
54228 cb_info->serv = serv;
54229 cb_info->rqst = rqstp;
54230- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
54231+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
54232 if (IS_ERR(cb_info->task)) {
54233 ret = PTR_ERR(cb_info->task);
54234 svc_exit_thread(cb_info->rqst);
54235diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54236index a35582c..ebbdcd5 100644
54237--- a/fs/nfs/callback_xdr.c
54238+++ b/fs/nfs/callback_xdr.c
54239@@ -51,7 +51,7 @@ struct callback_op {
54240 callback_decode_arg_t decode_args;
54241 callback_encode_res_t encode_res;
54242 long res_maxsize;
54243-};
54244+} __do_const;
54245
54246 static struct callback_op callback_ops[];
54247
54248diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54249index c1c7a9d..7afa0b8 100644
54250--- a/fs/nfs/inode.c
54251+++ b/fs/nfs/inode.c
54252@@ -1043,16 +1043,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54253 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54254 }
54255
54256-static atomic_long_t nfs_attr_generation_counter;
54257+static atomic_long_unchecked_t nfs_attr_generation_counter;
54258
54259 static unsigned long nfs_read_attr_generation_counter(void)
54260 {
54261- return atomic_long_read(&nfs_attr_generation_counter);
54262+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54263 }
54264
54265 unsigned long nfs_inc_attr_generation_counter(void)
54266 {
54267- return atomic_long_inc_return(&nfs_attr_generation_counter);
54268+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54269 }
54270
54271 void nfs_fattr_init(struct nfs_fattr *fattr)
54272diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
54273index 2c37442..9b9538b 100644
54274--- a/fs/nfs/nfs4state.c
54275+++ b/fs/nfs/nfs4state.c
54276@@ -1193,7 +1193,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
54277 snprintf(buf, sizeof(buf), "%s-manager",
54278 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
54279 rcu_read_unlock();
54280- task = kthread_run(nfs4_run_state_manager, clp, buf);
54281+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
54282 if (IS_ERR(task)) {
54283 printk(KERN_ERR "%s: kthread_run: %ld\n",
54284 __func__, PTR_ERR(task));
54285diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54286index 27d74a2..c4c2a73 100644
54287--- a/fs/nfsd/nfs4proc.c
54288+++ b/fs/nfsd/nfs4proc.c
54289@@ -1126,7 +1126,7 @@ struct nfsd4_operation {
54290 nfsd4op_rsize op_rsize_bop;
54291 stateid_getter op_get_currentstateid;
54292 stateid_setter op_set_currentstateid;
54293-};
54294+} __do_const;
54295
54296 static struct nfsd4_operation nfsd4_ops[];
54297
54298diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54299index 582321a..0224663 100644
54300--- a/fs/nfsd/nfs4xdr.c
54301+++ b/fs/nfsd/nfs4xdr.c
54302@@ -1458,7 +1458,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54303
54304 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54305
54306-static nfsd4_dec nfsd4_dec_ops[] = {
54307+static const nfsd4_dec nfsd4_dec_ops[] = {
54308 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54309 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54310 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54311@@ -1498,7 +1498,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54312 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54313 };
54314
54315-static nfsd4_dec nfsd41_dec_ops[] = {
54316+static const nfsd4_dec nfsd41_dec_ops[] = {
54317 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54318 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54319 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54320@@ -1560,7 +1560,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54321 };
54322
54323 struct nfsd4_minorversion_ops {
54324- nfsd4_dec *decoders;
54325+ const nfsd4_dec *decoders;
54326 int nops;
54327 };
54328
54329diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54330index e76244e..9fe8f2f1 100644
54331--- a/fs/nfsd/nfscache.c
54332+++ b/fs/nfsd/nfscache.c
54333@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54334 {
54335 struct svc_cacherep *rp = rqstp->rq_cacherep;
54336 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
54337- int len;
54338+ long len;
54339 size_t bufsize = 0;
54340
54341 if (!rp)
54342 return;
54343
54344- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54345- len >>= 2;
54346+ if (statp) {
54347+ len = (char*)statp - (char*)resv->iov_base;
54348+ len = resv->iov_len - len;
54349+ len >>= 2;
54350+ }
54351
54352 /* Don't cache excessive amounts of data and XDR failures */
54353 if (!statp || len > (256 >> 2)) {
54354diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54355index 84ce601..633d226 100644
54356--- a/fs/nfsd/vfs.c
54357+++ b/fs/nfsd/vfs.c
54358@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54359 } else {
54360 oldfs = get_fs();
54361 set_fs(KERNEL_DS);
54362- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54363+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54364 set_fs(oldfs);
54365 }
54366
54367@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54368
54369 /* Write the data. */
54370 oldfs = get_fs(); set_fs(KERNEL_DS);
54371- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54372+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54373 set_fs(oldfs);
54374 if (host_err < 0)
54375 goto out_nfserr;
54376@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54377 */
54378
54379 oldfs = get_fs(); set_fs(KERNEL_DS);
54380- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54381+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54382 set_fs(oldfs);
54383
54384 if (host_err < 0)
54385diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54386index fea6bd5..8ee9d81 100644
54387--- a/fs/nls/nls_base.c
54388+++ b/fs/nls/nls_base.c
54389@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54390
54391 int register_nls(struct nls_table * nls)
54392 {
54393- struct nls_table ** tmp = &tables;
54394+ struct nls_table *tmp = tables;
54395
54396 if (nls->next)
54397 return -EBUSY;
54398
54399 spin_lock(&nls_lock);
54400- while (*tmp) {
54401- if (nls == *tmp) {
54402+ while (tmp) {
54403+ if (nls == tmp) {
54404 spin_unlock(&nls_lock);
54405 return -EBUSY;
54406 }
54407- tmp = &(*tmp)->next;
54408+ tmp = tmp->next;
54409 }
54410- nls->next = tables;
54411+ pax_open_kernel();
54412+ *(struct nls_table **)&nls->next = tables;
54413+ pax_close_kernel();
54414 tables = nls;
54415 spin_unlock(&nls_lock);
54416 return 0;
54417@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54418
54419 int unregister_nls(struct nls_table * nls)
54420 {
54421- struct nls_table ** tmp = &tables;
54422+ struct nls_table * const * tmp = &tables;
54423
54424 spin_lock(&nls_lock);
54425 while (*tmp) {
54426 if (nls == *tmp) {
54427- *tmp = nls->next;
54428+ pax_open_kernel();
54429+ *(struct nls_table **)tmp = nls->next;
54430+ pax_close_kernel();
54431 spin_unlock(&nls_lock);
54432 return 0;
54433 }
54434diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54435index 7424929..35f6be5 100644
54436--- a/fs/nls/nls_euc-jp.c
54437+++ b/fs/nls/nls_euc-jp.c
54438@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54439 p_nls = load_nls("cp932");
54440
54441 if (p_nls) {
54442- table.charset2upper = p_nls->charset2upper;
54443- table.charset2lower = p_nls->charset2lower;
54444+ pax_open_kernel();
54445+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54446+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54447+ pax_close_kernel();
54448 return register_nls(&table);
54449 }
54450
54451diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54452index e7bc1d7..06bd4bb 100644
54453--- a/fs/nls/nls_koi8-ru.c
54454+++ b/fs/nls/nls_koi8-ru.c
54455@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54456 p_nls = load_nls("koi8-u");
54457
54458 if (p_nls) {
54459- table.charset2upper = p_nls->charset2upper;
54460- table.charset2lower = p_nls->charset2lower;
54461+ pax_open_kernel();
54462+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54463+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54464+ pax_close_kernel();
54465 return register_nls(&table);
54466 }
54467
54468diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54469index 6c80083..a1e6299 100644
54470--- a/fs/notify/fanotify/fanotify_user.c
54471+++ b/fs/notify/fanotify/fanotify_user.c
54472@@ -122,6 +122,7 @@ static int fill_event_metadata(struct fsnotify_group *group,
54473 metadata->event_len = FAN_EVENT_METADATA_LEN;
54474 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
54475 metadata->vers = FANOTIFY_METADATA_VERSION;
54476+ metadata->reserved = 0;
54477 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
54478 metadata->pid = pid_vnr(event->tgid);
54479 if (unlikely(event->mask & FAN_Q_OVERFLOW))
54480@@ -252,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54481
54482 fd = fanotify_event_metadata.fd;
54483 ret = -EFAULT;
54484- if (copy_to_user(buf, &fanotify_event_metadata,
54485- fanotify_event_metadata.event_len))
54486+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54487+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54488 goto out_close_fd;
54489
54490 ret = prepare_for_access_response(group, event, fd);
54491diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54492index 7b51b05..5ea5ef6 100644
54493--- a/fs/notify/notification.c
54494+++ b/fs/notify/notification.c
54495@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54496 * get set to 0 so it will never get 'freed'
54497 */
54498 static struct fsnotify_event *q_overflow_event;
54499-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54500+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54501
54502 /**
54503 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54504@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54505 */
54506 u32 fsnotify_get_cookie(void)
54507 {
54508- return atomic_inc_return(&fsnotify_sync_cookie);
54509+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54510 }
54511 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54512
54513diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54514index aa411c3..c260a84 100644
54515--- a/fs/ntfs/dir.c
54516+++ b/fs/ntfs/dir.c
54517@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54518 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54519 ~(s64)(ndir->itype.index.block_size - 1)));
54520 /* Bounds checks. */
54521- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54522+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54523 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54524 "inode 0x%lx or driver bug.", vdir->i_ino);
54525 goto err_out;
54526diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54527index c5670b8..01a3656 100644
54528--- a/fs/ntfs/file.c
54529+++ b/fs/ntfs/file.c
54530@@ -2241,6 +2241,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54531 #endif /* NTFS_RW */
54532 };
54533
54534-const struct file_operations ntfs_empty_file_ops = {};
54535+const struct file_operations ntfs_empty_file_ops __read_only;
54536
54537-const struct inode_operations ntfs_empty_inode_ops = {};
54538+const struct inode_operations ntfs_empty_inode_ops __read_only;
54539diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54540index aebeacd..0dcdd26 100644
54541--- a/fs/ocfs2/localalloc.c
54542+++ b/fs/ocfs2/localalloc.c
54543@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54544 goto bail;
54545 }
54546
54547- atomic_inc(&osb->alloc_stats.moves);
54548+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54549
54550 bail:
54551 if (handle)
54552diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54553index d355e6e..578d905 100644
54554--- a/fs/ocfs2/ocfs2.h
54555+++ b/fs/ocfs2/ocfs2.h
54556@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54557
54558 struct ocfs2_alloc_stats
54559 {
54560- atomic_t moves;
54561- atomic_t local_data;
54562- atomic_t bitmap_data;
54563- atomic_t bg_allocs;
54564- atomic_t bg_extends;
54565+ atomic_unchecked_t moves;
54566+ atomic_unchecked_t local_data;
54567+ atomic_unchecked_t bitmap_data;
54568+ atomic_unchecked_t bg_allocs;
54569+ atomic_unchecked_t bg_extends;
54570 };
54571
54572 enum ocfs2_local_alloc_state
54573diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54574index b7e74b5..19c6536 100644
54575--- a/fs/ocfs2/suballoc.c
54576+++ b/fs/ocfs2/suballoc.c
54577@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54578 mlog_errno(status);
54579 goto bail;
54580 }
54581- atomic_inc(&osb->alloc_stats.bg_extends);
54582+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54583
54584 /* You should never ask for this much metadata */
54585 BUG_ON(bits_wanted >
54586@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54587 mlog_errno(status);
54588 goto bail;
54589 }
54590- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54591+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54592
54593 *suballoc_loc = res.sr_bg_blkno;
54594 *suballoc_bit_start = res.sr_bit_offset;
54595@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54596 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54597 res->sr_bits);
54598
54599- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54600+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54601
54602 BUG_ON(res->sr_bits != 1);
54603
54604@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54605 mlog_errno(status);
54606 goto bail;
54607 }
54608- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54609+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54610
54611 BUG_ON(res.sr_bits != 1);
54612
54613@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54614 cluster_start,
54615 num_clusters);
54616 if (!status)
54617- atomic_inc(&osb->alloc_stats.local_data);
54618+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54619 } else {
54620 if (min_clusters > (osb->bitmap_cpg - 1)) {
54621 /* The only paths asking for contiguousness
54622@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54623 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54624 res.sr_bg_blkno,
54625 res.sr_bit_offset);
54626- atomic_inc(&osb->alloc_stats.bitmap_data);
54627+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54628 *num_clusters = res.sr_bits;
54629 }
54630 }
54631diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54632index 01b8516..579c4df 100644
54633--- a/fs/ocfs2/super.c
54634+++ b/fs/ocfs2/super.c
54635@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54636 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54637 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54638 "Stats",
54639- atomic_read(&osb->alloc_stats.bitmap_data),
54640- atomic_read(&osb->alloc_stats.local_data),
54641- atomic_read(&osb->alloc_stats.bg_allocs),
54642- atomic_read(&osb->alloc_stats.moves),
54643- atomic_read(&osb->alloc_stats.bg_extends));
54644+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54645+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54646+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54647+ atomic_read_unchecked(&osb->alloc_stats.moves),
54648+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54649
54650 out += snprintf(buf + out, len - out,
54651 "%10s => State: %u Descriptor: %llu Size: %u bits "
54652@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54653 spin_lock_init(&osb->osb_xattr_lock);
54654 ocfs2_init_steal_slots(osb);
54655
54656- atomic_set(&osb->alloc_stats.moves, 0);
54657- atomic_set(&osb->alloc_stats.local_data, 0);
54658- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54659- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54660- atomic_set(&osb->alloc_stats.bg_extends, 0);
54661+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54662+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54663+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54664+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54665+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54666
54667 /* Copy the blockcheck stats from the superblock probe */
54668 osb->osb_ecc_stats = *stats;
54669diff --git a/fs/open.c b/fs/open.c
54670index 8c74100..4239c48 100644
54671--- a/fs/open.c
54672+++ b/fs/open.c
54673@@ -32,6 +32,8 @@
54674 #include <linux/dnotify.h>
54675 #include <linux/compat.h>
54676
54677+#define CREATE_TRACE_POINTS
54678+#include <trace/events/fs.h>
54679 #include "internal.h"
54680
54681 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54682@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
54683 error = locks_verify_truncate(inode, NULL, length);
54684 if (!error)
54685 error = security_path_truncate(path);
54686+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54687+ error = -EACCES;
54688 if (!error)
54689 error = do_truncate(path->dentry, length, 0, NULL);
54690
54691@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54692 error = locks_verify_truncate(inode, f.file, length);
54693 if (!error)
54694 error = security_path_truncate(&f.file->f_path);
54695+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54696+ error = -EACCES;
54697 if (!error)
54698 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54699 sb_end_write(inode->i_sb);
54700@@ -360,6 +366,9 @@ retry:
54701 if (__mnt_is_readonly(path.mnt))
54702 res = -EROFS;
54703
54704+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54705+ res = -EACCES;
54706+
54707 out_path_release:
54708 path_put(&path);
54709 if (retry_estale(res, lookup_flags)) {
54710@@ -391,6 +400,8 @@ retry:
54711 if (error)
54712 goto dput_and_out;
54713
54714+ gr_log_chdir(path.dentry, path.mnt);
54715+
54716 set_fs_pwd(current->fs, &path);
54717
54718 dput_and_out:
54719@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54720 goto out_putf;
54721
54722 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54723+
54724+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54725+ error = -EPERM;
54726+
54727+ if (!error)
54728+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54729+
54730 if (!error)
54731 set_fs_pwd(current->fs, &f.file->f_path);
54732 out_putf:
54733@@ -449,7 +467,13 @@ retry:
54734 if (error)
54735 goto dput_and_out;
54736
54737+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54738+ goto dput_and_out;
54739+
54740 set_fs_root(current->fs, &path);
54741+
54742+ gr_handle_chroot_chdir(&path);
54743+
54744 error = 0;
54745 dput_and_out:
54746 path_put(&path);
54747@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
54748 if (error)
54749 return error;
54750 mutex_lock(&inode->i_mutex);
54751+
54752+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54753+ error = -EACCES;
54754+ goto out_unlock;
54755+ }
54756+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54757+ error = -EACCES;
54758+ goto out_unlock;
54759+ }
54760+
54761 error = security_path_chmod(path, mode);
54762 if (error)
54763 goto out_unlock;
54764@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54765 uid = make_kuid(current_user_ns(), user);
54766 gid = make_kgid(current_user_ns(), group);
54767
54768+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54769+ return -EACCES;
54770+
54771 newattrs.ia_valid = ATTR_CTIME;
54772 if (user != (uid_t) -1) {
54773 if (!uid_valid(uid))
54774@@ -946,6 +983,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54775 } else {
54776 fsnotify_open(f);
54777 fd_install(fd, f);
54778+ trace_do_sys_open(tmp->name, flags, mode);
54779 }
54780 }
54781 putname(tmp);
54782diff --git a/fs/pipe.c b/fs/pipe.c
54783index d2c45e1..009fe1c 100644
54784--- a/fs/pipe.c
54785+++ b/fs/pipe.c
54786@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
54787
54788 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
54789 {
54790- if (pipe->files)
54791+ if (atomic_read(&pipe->files))
54792 mutex_lock_nested(&pipe->mutex, subclass);
54793 }
54794
54795@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
54796
54797 void pipe_unlock(struct pipe_inode_info *pipe)
54798 {
54799- if (pipe->files)
54800+ if (atomic_read(&pipe->files))
54801 mutex_unlock(&pipe->mutex);
54802 }
54803 EXPORT_SYMBOL(pipe_unlock);
54804@@ -449,9 +449,9 @@ redo:
54805 }
54806 if (bufs) /* More to do? */
54807 continue;
54808- if (!pipe->writers)
54809+ if (!atomic_read(&pipe->writers))
54810 break;
54811- if (!pipe->waiting_writers) {
54812+ if (!atomic_read(&pipe->waiting_writers)) {
54813 /* syscall merging: Usually we must not sleep
54814 * if O_NONBLOCK is set, or if we got some data.
54815 * But if a writer sleeps in kernel space, then
54816@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54817 ret = 0;
54818 __pipe_lock(pipe);
54819
54820- if (!pipe->readers) {
54821+ if (!atomic_read(&pipe->readers)) {
54822 send_sig(SIGPIPE, current, 0);
54823 ret = -EPIPE;
54824 goto out;
54825@@ -562,7 +562,7 @@ redo1:
54826 for (;;) {
54827 int bufs;
54828
54829- if (!pipe->readers) {
54830+ if (!atomic_read(&pipe->readers)) {
54831 send_sig(SIGPIPE, current, 0);
54832 if (!ret)
54833 ret = -EPIPE;
54834@@ -653,9 +653,9 @@ redo2:
54835 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54836 do_wakeup = 0;
54837 }
54838- pipe->waiting_writers++;
54839+ atomic_inc(&pipe->waiting_writers);
54840 pipe_wait(pipe);
54841- pipe->waiting_writers--;
54842+ atomic_dec(&pipe->waiting_writers);
54843 }
54844 out:
54845 __pipe_unlock(pipe);
54846@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54847 mask = 0;
54848 if (filp->f_mode & FMODE_READ) {
54849 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54850- if (!pipe->writers && filp->f_version != pipe->w_counter)
54851+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54852 mask |= POLLHUP;
54853 }
54854
54855@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54856 * Most Unices do not set POLLERR for FIFOs but on Linux they
54857 * behave exactly like pipes for poll().
54858 */
54859- if (!pipe->readers)
54860+ if (!atomic_read(&pipe->readers))
54861 mask |= POLLERR;
54862 }
54863
54864@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
54865
54866 __pipe_lock(pipe);
54867 if (file->f_mode & FMODE_READ)
54868- pipe->readers--;
54869+ atomic_dec(&pipe->readers);
54870 if (file->f_mode & FMODE_WRITE)
54871- pipe->writers--;
54872+ atomic_dec(&pipe->writers);
54873
54874- if (pipe->readers || pipe->writers) {
54875+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
54876 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54877 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54878 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
54879 }
54880 spin_lock(&inode->i_lock);
54881- if (!--pipe->files) {
54882+ if (atomic_dec_and_test(&pipe->files)) {
54883 inode->i_pipe = NULL;
54884 kill = 1;
54885 }
54886@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
54887 kfree(pipe);
54888 }
54889
54890-static struct vfsmount *pipe_mnt __read_mostly;
54891+struct vfsmount *pipe_mnt __read_mostly;
54892
54893 /*
54894 * pipefs_dname() is called from d_path().
54895@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
54896 goto fail_iput;
54897
54898 inode->i_pipe = pipe;
54899- pipe->files = 2;
54900- pipe->readers = pipe->writers = 1;
54901+ atomic_set(&pipe->files, 2);
54902+ atomic_set(&pipe->readers, 1);
54903+ atomic_set(&pipe->writers, 1);
54904 inode->i_fop = &pipefifo_fops;
54905
54906 /*
54907@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
54908 spin_lock(&inode->i_lock);
54909 if (inode->i_pipe) {
54910 pipe = inode->i_pipe;
54911- pipe->files++;
54912+ atomic_inc(&pipe->files);
54913 spin_unlock(&inode->i_lock);
54914 } else {
54915 spin_unlock(&inode->i_lock);
54916 pipe = alloc_pipe_info();
54917 if (!pipe)
54918 return -ENOMEM;
54919- pipe->files = 1;
54920+ atomic_set(&pipe->files, 1);
54921 spin_lock(&inode->i_lock);
54922 if (unlikely(inode->i_pipe)) {
54923- inode->i_pipe->files++;
54924+ atomic_inc(&inode->i_pipe->files);
54925 spin_unlock(&inode->i_lock);
54926 free_pipe_info(pipe);
54927 pipe = inode->i_pipe;
54928@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
54929 * opened, even when there is no process writing the FIFO.
54930 */
54931 pipe->r_counter++;
54932- if (pipe->readers++ == 0)
54933+ if (atomic_inc_return(&pipe->readers) == 1)
54934 wake_up_partner(pipe);
54935
54936- if (!is_pipe && !pipe->writers) {
54937+ if (!is_pipe && !atomic_read(&pipe->writers)) {
54938 if ((filp->f_flags & O_NONBLOCK)) {
54939 /* suppress POLLHUP until we have
54940 * seen a writer */
54941@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
54942 * errno=ENXIO when there is no process reading the FIFO.
54943 */
54944 ret = -ENXIO;
54945- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
54946+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
54947 goto err;
54948
54949 pipe->w_counter++;
54950- if (!pipe->writers++)
54951+ if (atomic_inc_return(&pipe->writers) == 1)
54952 wake_up_partner(pipe);
54953
54954- if (!is_pipe && !pipe->readers) {
54955+ if (!is_pipe && !atomic_read(&pipe->readers)) {
54956 if (wait_for_partner(pipe, &pipe->r_counter))
54957 goto err_wr;
54958 }
54959@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
54960 * the process can at least talk to itself.
54961 */
54962
54963- pipe->readers++;
54964- pipe->writers++;
54965+ atomic_inc(&pipe->readers);
54966+ atomic_inc(&pipe->writers);
54967 pipe->r_counter++;
54968 pipe->w_counter++;
54969- if (pipe->readers == 1 || pipe->writers == 1)
54970+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
54971 wake_up_partner(pipe);
54972 break;
54973
54974@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
54975 return 0;
54976
54977 err_rd:
54978- if (!--pipe->readers)
54979+ if (atomic_dec_and_test(&pipe->readers))
54980 wake_up_interruptible(&pipe->wait);
54981 ret = -ERESTARTSYS;
54982 goto err;
54983
54984 err_wr:
54985- if (!--pipe->writers)
54986+ if (atomic_dec_and_test(&pipe->writers))
54987 wake_up_interruptible(&pipe->wait);
54988 ret = -ERESTARTSYS;
54989 goto err;
54990
54991 err:
54992 spin_lock(&inode->i_lock);
54993- if (!--pipe->files) {
54994+ if (atomic_dec_and_test(&pipe->files)) {
54995 inode->i_pipe = NULL;
54996 kill = 1;
54997 }
54998diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54999index 15af622..0e9f4467 100644
55000--- a/fs/proc/Kconfig
55001+++ b/fs/proc/Kconfig
55002@@ -30,12 +30,12 @@ config PROC_FS
55003
55004 config PROC_KCORE
55005 bool "/proc/kcore support" if !ARM
55006- depends on PROC_FS && MMU
55007+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
55008
55009 config PROC_VMCORE
55010 bool "/proc/vmcore support"
55011- depends on PROC_FS && CRASH_DUMP
55012- default y
55013+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
55014+ default n
55015 help
55016 Exports the dump image of crashed kernel in ELF format.
55017
55018@@ -59,8 +59,8 @@ config PROC_SYSCTL
55019 limited in memory.
55020
55021 config PROC_PAGE_MONITOR
55022- default y
55023- depends on PROC_FS && MMU
55024+ default n
55025+ depends on PROC_FS && MMU && !GRKERNSEC
55026 bool "Enable /proc page monitoring" if EXPERT
55027 help
55028 Various /proc files exist to monitor process memory utilization:
55029diff --git a/fs/proc/array.c b/fs/proc/array.c
55030index cbd0f1b..adec3f0 100644
55031--- a/fs/proc/array.c
55032+++ b/fs/proc/array.c
55033@@ -60,6 +60,7 @@
55034 #include <linux/tty.h>
55035 #include <linux/string.h>
55036 #include <linux/mman.h>
55037+#include <linux/grsecurity.h>
55038 #include <linux/proc_fs.h>
55039 #include <linux/ioport.h>
55040 #include <linux/uaccess.h>
55041@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
55042 seq_putc(m, '\n');
55043 }
55044
55045+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55046+static inline void task_pax(struct seq_file *m, struct task_struct *p)
55047+{
55048+ if (p->mm)
55049+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
55050+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
55051+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
55052+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
55053+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
55054+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
55055+ else
55056+ seq_printf(m, "PaX:\t-----\n");
55057+}
55058+#endif
55059+
55060 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55061 struct pid *pid, struct task_struct *task)
55062 {
55063@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55064 task_cpus_allowed(m, task);
55065 cpuset_task_status_allowed(m, task);
55066 task_context_switch_counts(m, task);
55067+
55068+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55069+ task_pax(m, task);
55070+#endif
55071+
55072+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
55073+ task_grsec_rbac(m, task);
55074+#endif
55075+
55076 return 0;
55077 }
55078
55079+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55080+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55081+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55082+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55083+#endif
55084+
55085 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55086 struct pid *pid, struct task_struct *task, int whole)
55087 {
55088@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55089 char tcomm[sizeof(task->comm)];
55090 unsigned long flags;
55091
55092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55093+ if (current->exec_id != m->exec_id) {
55094+ gr_log_badprocpid("stat");
55095+ return 0;
55096+ }
55097+#endif
55098+
55099 state = *get_task_state(task);
55100 vsize = eip = esp = 0;
55101 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55102@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55103 gtime = task_gtime(task);
55104 }
55105
55106+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55107+ if (PAX_RAND_FLAGS(mm)) {
55108+ eip = 0;
55109+ esp = 0;
55110+ wchan = 0;
55111+ }
55112+#endif
55113+#ifdef CONFIG_GRKERNSEC_HIDESYM
55114+ wchan = 0;
55115+ eip =0;
55116+ esp =0;
55117+#endif
55118+
55119 /* scale priority and nice values from timeslices to -20..20 */
55120 /* to make it look like a "normal" Unix priority/nice value */
55121 priority = task_prio(task);
55122@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55123 seq_put_decimal_ull(m, ' ', vsize);
55124 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
55125 seq_put_decimal_ull(m, ' ', rsslim);
55126+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55127+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
55128+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
55129+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
55130+#else
55131 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
55132 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55133 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55134+#endif
55135 seq_put_decimal_ull(m, ' ', esp);
55136 seq_put_decimal_ull(m, ' ', eip);
55137 /* The signal information here is obsolete.
55138@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55139 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55140 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55141
55142- if (mm && permitted) {
55143+ if (mm && permitted
55144+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55145+ && !PAX_RAND_FLAGS(mm)
55146+#endif
55147+ ) {
55148 seq_put_decimal_ull(m, ' ', mm->start_data);
55149 seq_put_decimal_ull(m, ' ', mm->end_data);
55150 seq_put_decimal_ull(m, ' ', mm->start_brk);
55151@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55152 struct pid *pid, struct task_struct *task)
55153 {
55154 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55155- struct mm_struct *mm = get_task_mm(task);
55156+ struct mm_struct *mm;
55157
55158+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55159+ if (current->exec_id != m->exec_id) {
55160+ gr_log_badprocpid("statm");
55161+ return 0;
55162+ }
55163+#endif
55164+ mm = get_task_mm(task);
55165 if (mm) {
55166 size = task_statm(mm, &shared, &text, &data, &resident);
55167 mmput(mm);
55168@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55169 return 0;
55170 }
55171
55172+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55173+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55174+{
55175+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55176+}
55177+#endif
55178+
55179 #ifdef CONFIG_CHECKPOINT_RESTORE
55180 static struct pid *
55181 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55182diff --git a/fs/proc/base.c b/fs/proc/base.c
55183index c3834da..b402b2b 100644
55184--- a/fs/proc/base.c
55185+++ b/fs/proc/base.c
55186@@ -113,6 +113,14 @@ struct pid_entry {
55187 union proc_op op;
55188 };
55189
55190+struct getdents_callback {
55191+ struct linux_dirent __user * current_dir;
55192+ struct linux_dirent __user * previous;
55193+ struct file * file;
55194+ int count;
55195+ int error;
55196+};
55197+
55198 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55199 .name = (NAME), \
55200 .len = sizeof(NAME) - 1, \
55201@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55202 if (!mm->arg_end)
55203 goto out_mm; /* Shh! No looking before we're done */
55204
55205+ if (gr_acl_handle_procpidmem(task))
55206+ goto out_mm;
55207+
55208 len = mm->arg_end - mm->arg_start;
55209
55210 if (len > PAGE_SIZE)
55211@@ -237,12 +248,28 @@ out:
55212 return res;
55213 }
55214
55215+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55216+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55217+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55218+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55219+#endif
55220+
55221 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55222 {
55223 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55224 int res = PTR_ERR(mm);
55225 if (mm && !IS_ERR(mm)) {
55226 unsigned int nwords = 0;
55227+
55228+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55229+ /* allow if we're currently ptracing this task */
55230+ if (PAX_RAND_FLAGS(mm) &&
55231+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55232+ mmput(mm);
55233+ return 0;
55234+ }
55235+#endif
55236+
55237 do {
55238 nwords += 2;
55239 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55240@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55241 }
55242
55243
55244-#ifdef CONFIG_KALLSYMS
55245+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55246 /*
55247 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55248 * Returns the resolved symbol. If that fails, simply return the address.
55249@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
55250 mutex_unlock(&task->signal->cred_guard_mutex);
55251 }
55252
55253-#ifdef CONFIG_STACKTRACE
55254+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55255
55256 #define MAX_STACK_TRACE_DEPTH 64
55257
55258@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55259 return count;
55260 }
55261
55262-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55263+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55264 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55265 {
55266 long nr;
55267@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55268 /************************************************************************/
55269
55270 /* permission checks */
55271-static int proc_fd_access_allowed(struct inode *inode)
55272+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55273 {
55274 struct task_struct *task;
55275 int allowed = 0;
55276@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55277 */
55278 task = get_proc_task(inode);
55279 if (task) {
55280- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55281+ if (log)
55282+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55283+ else
55284+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55285 put_task_struct(task);
55286 }
55287 return allowed;
55288@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55289 struct task_struct *task,
55290 int hide_pid_min)
55291 {
55292+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55293+ return false;
55294+
55295+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55296+ rcu_read_lock();
55297+ {
55298+ const struct cred *tmpcred = current_cred();
55299+ const struct cred *cred = __task_cred(task);
55300+
55301+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55302+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55303+ || in_group_p(grsec_proc_gid)
55304+#endif
55305+ ) {
55306+ rcu_read_unlock();
55307+ return true;
55308+ }
55309+ }
55310+ rcu_read_unlock();
55311+
55312+ if (!pid->hide_pid)
55313+ return false;
55314+#endif
55315+
55316 if (pid->hide_pid < hide_pid_min)
55317 return true;
55318 if (in_group_p(pid->pid_gid))
55319 return true;
55320+
55321 return ptrace_may_access(task, PTRACE_MODE_READ);
55322 }
55323
55324@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55325 put_task_struct(task);
55326
55327 if (!has_perms) {
55328+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55329+ {
55330+#else
55331 if (pid->hide_pid == 2) {
55332+#endif
55333 /*
55334 * Let's make getdents(), stat(), and open()
55335 * consistent with each other. If a process
55336@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55337 if (!task)
55338 return -ESRCH;
55339
55340+ if (gr_acl_handle_procpidmem(task)) {
55341+ put_task_struct(task);
55342+ return -EPERM;
55343+ }
55344+
55345 mm = mm_access(task, mode);
55346 put_task_struct(task);
55347
55348@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55349
55350 file->private_data = mm;
55351
55352+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55353+ file->f_version = current->exec_id;
55354+#endif
55355+
55356 return 0;
55357 }
55358
55359@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55360 ssize_t copied;
55361 char *page;
55362
55363+#ifdef CONFIG_GRKERNSEC
55364+ if (write)
55365+ return -EPERM;
55366+#endif
55367+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55368+ if (file->f_version != current->exec_id) {
55369+ gr_log_badprocpid("mem");
55370+ return 0;
55371+ }
55372+#endif
55373+
55374 if (!mm)
55375 return 0;
55376
55377@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55378 goto free;
55379
55380 while (count > 0) {
55381- int this_len = min_t(int, count, PAGE_SIZE);
55382+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55383
55384 if (write && copy_from_user(page, buf, this_len)) {
55385 copied = -EFAULT;
55386@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55387 if (!mm)
55388 return 0;
55389
55390+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55391+ if (file->f_version != current->exec_id) {
55392+ gr_log_badprocpid("environ");
55393+ return 0;
55394+ }
55395+#endif
55396+
55397 page = (char *)__get_free_page(GFP_TEMPORARY);
55398 if (!page)
55399 return -ENOMEM;
55400@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55401 goto free;
55402 while (count > 0) {
55403 size_t this_len, max_len;
55404- int retval;
55405+ ssize_t retval;
55406
55407 if (src >= (mm->env_end - mm->env_start))
55408 break;
55409@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55410 int error = -EACCES;
55411
55412 /* Are we allowed to snoop on the tasks file descriptors? */
55413- if (!proc_fd_access_allowed(inode))
55414+ if (!proc_fd_access_allowed(inode, 0))
55415 goto out;
55416
55417 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55418@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55419 struct path path;
55420
55421 /* Are we allowed to snoop on the tasks file descriptors? */
55422- if (!proc_fd_access_allowed(inode))
55423- goto out;
55424+ /* logging this is needed for learning on chromium to work properly,
55425+ but we don't want to flood the logs from 'ps' which does a readlink
55426+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55427+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55428+ */
55429+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55430+ if (!proc_fd_access_allowed(inode,0))
55431+ goto out;
55432+ } else {
55433+ if (!proc_fd_access_allowed(inode,1))
55434+ goto out;
55435+ }
55436
55437 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55438 if (error)
55439@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55440 rcu_read_lock();
55441 cred = __task_cred(task);
55442 inode->i_uid = cred->euid;
55443+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55444+ inode->i_gid = grsec_proc_gid;
55445+#else
55446 inode->i_gid = cred->egid;
55447+#endif
55448 rcu_read_unlock();
55449 }
55450 security_task_to_inode(task, inode);
55451@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55452 return -ENOENT;
55453 }
55454 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55455+#ifdef CONFIG_GRKERNSEC_PROC_USER
55456+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55457+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55458+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55459+#endif
55460 task_dumpable(task)) {
55461 cred = __task_cred(task);
55462 stat->uid = cred->euid;
55463+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55464+ stat->gid = grsec_proc_gid;
55465+#else
55466 stat->gid = cred->egid;
55467+#endif
55468 }
55469 }
55470 rcu_read_unlock();
55471@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55472
55473 if (task) {
55474 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55475+#ifdef CONFIG_GRKERNSEC_PROC_USER
55476+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55477+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55478+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55479+#endif
55480 task_dumpable(task)) {
55481 rcu_read_lock();
55482 cred = __task_cred(task);
55483 inode->i_uid = cred->euid;
55484+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55485+ inode->i_gid = grsec_proc_gid;
55486+#else
55487 inode->i_gid = cred->egid;
55488+#endif
55489 rcu_read_unlock();
55490 } else {
55491 inode->i_uid = GLOBAL_ROOT_UID;
55492@@ -2196,6 +2314,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55493 if (!task)
55494 goto out_no_task;
55495
55496+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55497+ goto out;
55498+
55499 /*
55500 * Yes, it does not scale. And it should not. Don't add
55501 * new entries into /proc/<tgid>/ without very good reasons.
55502@@ -2240,6 +2361,9 @@ static int proc_pident_readdir(struct file *filp,
55503 if (!task)
55504 goto out_no_task;
55505
55506+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55507+ goto out;
55508+
55509 ret = 0;
55510 i = filp->f_pos;
55511 switch (i) {
55512@@ -2653,7 +2777,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55513 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55514 #endif
55515 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55516-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55517+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55518 INF("syscall", S_IRUGO, proc_pid_syscall),
55519 #endif
55520 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55521@@ -2678,10 +2802,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55522 #ifdef CONFIG_SECURITY
55523 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55524 #endif
55525-#ifdef CONFIG_KALLSYMS
55526+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55527 INF("wchan", S_IRUGO, proc_pid_wchan),
55528 #endif
55529-#ifdef CONFIG_STACKTRACE
55530+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55531 ONE("stack", S_IRUGO, proc_pid_stack),
55532 #endif
55533 #ifdef CONFIG_SCHEDSTATS
55534@@ -2715,6 +2839,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55535 #ifdef CONFIG_HARDWALL
55536 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55537 #endif
55538+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55539+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55540+#endif
55541 #ifdef CONFIG_USER_NS
55542 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55543 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55544@@ -2847,7 +2974,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55545 if (!inode)
55546 goto out;
55547
55548+#ifdef CONFIG_GRKERNSEC_PROC_USER
55549+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55550+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55551+ inode->i_gid = grsec_proc_gid;
55552+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55553+#else
55554 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55555+#endif
55556 inode->i_op = &proc_tgid_base_inode_operations;
55557 inode->i_fop = &proc_tgid_base_operations;
55558 inode->i_flags|=S_IMMUTABLE;
55559@@ -2885,7 +3019,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55560 if (!task)
55561 goto out;
55562
55563+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55564+ goto out_put_task;
55565+
55566 result = proc_pid_instantiate(dir, dentry, task, NULL);
55567+out_put_task:
55568 put_task_struct(task);
55569 out:
55570 return result;
55571@@ -2948,6 +3086,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55572 static int fake_filldir(void *buf, const char *name, int namelen,
55573 loff_t offset, u64 ino, unsigned d_type)
55574 {
55575+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55576+ __buf->error = -EINVAL;
55577 return 0;
55578 }
55579
55580@@ -3007,7 +3147,7 @@ static const struct pid_entry tid_base_stuff[] = {
55581 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55582 #endif
55583 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55584-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55585+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55586 INF("syscall", S_IRUGO, proc_pid_syscall),
55587 #endif
55588 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55589@@ -3034,10 +3174,10 @@ static const struct pid_entry tid_base_stuff[] = {
55590 #ifdef CONFIG_SECURITY
55591 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55592 #endif
55593-#ifdef CONFIG_KALLSYMS
55594+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55595 INF("wchan", S_IRUGO, proc_pid_wchan),
55596 #endif
55597-#ifdef CONFIG_STACKTRACE
55598+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55599 ONE("stack", S_IRUGO, proc_pid_stack),
55600 #endif
55601 #ifdef CONFIG_SCHEDSTATS
55602diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55603index 82676e3..5f8518a 100644
55604--- a/fs/proc/cmdline.c
55605+++ b/fs/proc/cmdline.c
55606@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55607
55608 static int __init proc_cmdline_init(void)
55609 {
55610+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55611+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55612+#else
55613 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55614+#endif
55615 return 0;
55616 }
55617 module_init(proc_cmdline_init);
55618diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55619index b143471..bb105e5 100644
55620--- a/fs/proc/devices.c
55621+++ b/fs/proc/devices.c
55622@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55623
55624 static int __init proc_devices_init(void)
55625 {
55626+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55627+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55628+#else
55629 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55630+#endif
55631 return 0;
55632 }
55633 module_init(proc_devices_init);
55634diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55635index d7a4a28..0201742 100644
55636--- a/fs/proc/fd.c
55637+++ b/fs/proc/fd.c
55638@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55639 if (!task)
55640 return -ENOENT;
55641
55642- files = get_files_struct(task);
55643+ if (!gr_acl_handle_procpidmem(task))
55644+ files = get_files_struct(task);
55645 put_task_struct(task);
55646
55647 if (files) {
55648@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55649 */
55650 int proc_fd_permission(struct inode *inode, int mask)
55651 {
55652+ struct task_struct *task;
55653 int rv = generic_permission(inode, mask);
55654- if (rv == 0)
55655- return 0;
55656+
55657 if (task_pid(current) == proc_pid(inode))
55658 rv = 0;
55659+
55660+ task = get_proc_task(inode);
55661+ if (task == NULL)
55662+ return rv;
55663+
55664+ if (gr_acl_handle_procpidmem(task))
55665+ rv = -EACCES;
55666+
55667+ put_task_struct(task);
55668+
55669 return rv;
55670 }
55671
55672diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55673index 073aea6..0630370 100644
55674--- a/fs/proc/inode.c
55675+++ b/fs/proc/inode.c
55676@@ -23,11 +23,17 @@
55677 #include <linux/slab.h>
55678 #include <linux/mount.h>
55679 #include <linux/magic.h>
55680+#include <linux/grsecurity.h>
55681
55682 #include <asm/uaccess.h>
55683
55684 #include "internal.h"
55685
55686+#ifdef CONFIG_PROC_SYSCTL
55687+extern const struct inode_operations proc_sys_inode_operations;
55688+extern const struct inode_operations proc_sys_dir_operations;
55689+#endif
55690+
55691 static void proc_evict_inode(struct inode *inode)
55692 {
55693 struct proc_dir_entry *de;
55694@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
55695 ns = PROC_I(inode)->ns.ns;
55696 if (ns_ops && ns)
55697 ns_ops->put(ns);
55698+
55699+#ifdef CONFIG_PROC_SYSCTL
55700+ if (inode->i_op == &proc_sys_inode_operations ||
55701+ inode->i_op == &proc_sys_dir_operations)
55702+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55703+#endif
55704+
55705 }
55706
55707 static struct kmem_cache * proc_inode_cachep;
55708@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55709 if (de->mode) {
55710 inode->i_mode = de->mode;
55711 inode->i_uid = de->uid;
55712+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55713+ inode->i_gid = grsec_proc_gid;
55714+#else
55715 inode->i_gid = de->gid;
55716+#endif
55717 }
55718 if (de->size)
55719 inode->i_size = de->size;
55720diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55721index d600fb0..3b495fe 100644
55722--- a/fs/proc/internal.h
55723+++ b/fs/proc/internal.h
55724@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
55725 struct pid *, struct task_struct *);
55726 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
55727 struct pid *, struct task_struct *);
55728+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55729+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55730+#endif
55731
55732 /*
55733 * base.c
55734diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55735index 0a22194..a9fc8c1 100644
55736--- a/fs/proc/kcore.c
55737+++ b/fs/proc/kcore.c
55738@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55739 * the addresses in the elf_phdr on our list.
55740 */
55741 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55742- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55743+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55744+ if (tsz > buflen)
55745 tsz = buflen;
55746-
55747+
55748 while (buflen) {
55749 struct kcore_list *m;
55750
55751@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55752 kfree(elf_buf);
55753 } else {
55754 if (kern_addr_valid(start)) {
55755- unsigned long n;
55756+ char *elf_buf;
55757+ mm_segment_t oldfs;
55758
55759- n = copy_to_user(buffer, (char *)start, tsz);
55760- /*
55761- * We cannot distinguish between fault on source
55762- * and fault on destination. When this happens
55763- * we clear too and hope it will trigger the
55764- * EFAULT again.
55765- */
55766- if (n) {
55767- if (clear_user(buffer + tsz - n,
55768- n))
55769+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55770+ if (!elf_buf)
55771+ return -ENOMEM;
55772+ oldfs = get_fs();
55773+ set_fs(KERNEL_DS);
55774+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55775+ set_fs(oldfs);
55776+ if (copy_to_user(buffer, elf_buf, tsz)) {
55777+ kfree(elf_buf);
55778 return -EFAULT;
55779+ }
55780 }
55781+ set_fs(oldfs);
55782+ kfree(elf_buf);
55783 } else {
55784 if (clear_user(buffer, tsz))
55785 return -EFAULT;
55786@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55787
55788 static int open_kcore(struct inode *inode, struct file *filp)
55789 {
55790+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55791+ return -EPERM;
55792+#endif
55793 if (!capable(CAP_SYS_RAWIO))
55794 return -EPERM;
55795 if (kcore_need_update)
55796diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55797index 5aa847a..f77c8d4 100644
55798--- a/fs/proc/meminfo.c
55799+++ b/fs/proc/meminfo.c
55800@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55801 vmi.used >> 10,
55802 vmi.largest_chunk >> 10
55803 #ifdef CONFIG_MEMORY_FAILURE
55804- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55805+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55806 #endif
55807 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55808 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55809diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55810index ccfd99b..1b7e255 100644
55811--- a/fs/proc/nommu.c
55812+++ b/fs/proc/nommu.c
55813@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55814 if (len < 1)
55815 len = 1;
55816 seq_printf(m, "%*c", len, ' ');
55817- seq_path(m, &file->f_path, "");
55818+ seq_path(m, &file->f_path, "\n\\");
55819 }
55820
55821 seq_putc(m, '\n');
55822diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55823index 986e832..6e8e859 100644
55824--- a/fs/proc/proc_net.c
55825+++ b/fs/proc/proc_net.c
55826@@ -23,6 +23,7 @@
55827 #include <linux/nsproxy.h>
55828 #include <net/net_namespace.h>
55829 #include <linux/seq_file.h>
55830+#include <linux/grsecurity.h>
55831
55832 #include "internal.h"
55833
55834@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55835 struct task_struct *task;
55836 struct nsproxy *ns;
55837 struct net *net = NULL;
55838+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55839+ const struct cred *cred = current_cred();
55840+#endif
55841+
55842+#ifdef CONFIG_GRKERNSEC_PROC_USER
55843+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55844+ return net;
55845+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55846+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55847+ return net;
55848+#endif
55849
55850 rcu_read_lock();
55851 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55852diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55853index ac05f33..1e6dc7e 100644
55854--- a/fs/proc/proc_sysctl.c
55855+++ b/fs/proc/proc_sysctl.c
55856@@ -13,11 +13,15 @@
55857 #include <linux/module.h>
55858 #include "internal.h"
55859
55860+extern int gr_handle_chroot_sysctl(const int op);
55861+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55862+ const int op);
55863+
55864 static const struct dentry_operations proc_sys_dentry_operations;
55865 static const struct file_operations proc_sys_file_operations;
55866-static const struct inode_operations proc_sys_inode_operations;
55867+const struct inode_operations proc_sys_inode_operations;
55868 static const struct file_operations proc_sys_dir_file_operations;
55869-static const struct inode_operations proc_sys_dir_operations;
55870+const struct inode_operations proc_sys_dir_operations;
55871
55872 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55873 {
55874@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55875
55876 err = NULL;
55877 d_set_d_op(dentry, &proc_sys_dentry_operations);
55878+
55879+ gr_handle_proc_create(dentry, inode);
55880+
55881 d_add(dentry, inode);
55882
55883 out:
55884@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55885 struct inode *inode = file_inode(filp);
55886 struct ctl_table_header *head = grab_header(inode);
55887 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55888+ int op = write ? MAY_WRITE : MAY_READ;
55889 ssize_t error;
55890 size_t res;
55891
55892@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55893 * and won't be until we finish.
55894 */
55895 error = -EPERM;
55896- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55897+ if (sysctl_perm(head, table, op))
55898 goto out;
55899
55900 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55901@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55902 if (!table->proc_handler)
55903 goto out;
55904
55905+#ifdef CONFIG_GRKERNSEC
55906+ error = -EPERM;
55907+ if (gr_handle_chroot_sysctl(op))
55908+ goto out;
55909+ dget(filp->f_path.dentry);
55910+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55911+ dput(filp->f_path.dentry);
55912+ goto out;
55913+ }
55914+ dput(filp->f_path.dentry);
55915+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55916+ goto out;
55917+ if (write && !capable(CAP_SYS_ADMIN))
55918+ goto out;
55919+#endif
55920+
55921 /* careful: calling conventions are nasty here */
55922 res = count;
55923 error = table->proc_handler(table, write, buf, &res, ppos);
55924@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55925 return -ENOMEM;
55926 } else {
55927 d_set_d_op(child, &proc_sys_dentry_operations);
55928+
55929+ gr_handle_proc_create(child, inode);
55930+
55931 d_add(child, inode);
55932 }
55933 } else {
55934@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55935 if ((*pos)++ < file->f_pos)
55936 return 0;
55937
55938+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55939+ return 0;
55940+
55941 if (unlikely(S_ISLNK(table->mode)))
55942 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55943 else
55944@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55945 if (IS_ERR(head))
55946 return PTR_ERR(head);
55947
55948+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55949+ return -ENOENT;
55950+
55951 generic_fillattr(inode, stat);
55952 if (table)
55953 stat->mode = (stat->mode & S_IFMT) | table->mode;
55954@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55955 .llseek = generic_file_llseek,
55956 };
55957
55958-static const struct inode_operations proc_sys_inode_operations = {
55959+const struct inode_operations proc_sys_inode_operations = {
55960 .permission = proc_sys_permission,
55961 .setattr = proc_sys_setattr,
55962 .getattr = proc_sys_getattr,
55963 };
55964
55965-static const struct inode_operations proc_sys_dir_operations = {
55966+const struct inode_operations proc_sys_dir_operations = {
55967 .lookup = proc_sys_lookup,
55968 .permission = proc_sys_permission,
55969 .setattr = proc_sys_setattr,
55970@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55971 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55972 const char *name, int namelen)
55973 {
55974- struct ctl_table *table;
55975+ ctl_table_no_const *table;
55976 struct ctl_dir *new;
55977 struct ctl_node *node;
55978 char *new_name;
55979@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55980 return NULL;
55981
55982 node = (struct ctl_node *)(new + 1);
55983- table = (struct ctl_table *)(node + 1);
55984+ table = (ctl_table_no_const *)(node + 1);
55985 new_name = (char *)(table + 2);
55986 memcpy(new_name, name, namelen);
55987 new_name[namelen] = '\0';
55988@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55989 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55990 struct ctl_table_root *link_root)
55991 {
55992- struct ctl_table *link_table, *entry, *link;
55993+ ctl_table_no_const *link_table, *link;
55994+ struct ctl_table *entry;
55995 struct ctl_table_header *links;
55996 struct ctl_node *node;
55997 char *link_name;
55998@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55999 return NULL;
56000
56001 node = (struct ctl_node *)(links + 1);
56002- link_table = (struct ctl_table *)(node + nr_entries);
56003+ link_table = (ctl_table_no_const *)(node + nr_entries);
56004 link_name = (char *)&link_table[nr_entries + 1];
56005
56006 for (link = link_table, entry = table; entry->procname; link++, entry++) {
56007@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56008 struct ctl_table_header ***subheader, struct ctl_table_set *set,
56009 struct ctl_table *table)
56010 {
56011- struct ctl_table *ctl_table_arg = NULL;
56012- struct ctl_table *entry, *files;
56013+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
56014+ struct ctl_table *entry;
56015 int nr_files = 0;
56016 int nr_dirs = 0;
56017 int err = -ENOMEM;
56018@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56019 nr_files++;
56020 }
56021
56022- files = table;
56023 /* If there are mixed files and directories we need a new table */
56024 if (nr_dirs && nr_files) {
56025- struct ctl_table *new;
56026+ ctl_table_no_const *new;
56027 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
56028 GFP_KERNEL);
56029 if (!files)
56030@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
56031 /* Register everything except a directory full of subdirectories */
56032 if (nr_files || !nr_dirs) {
56033 struct ctl_table_header *header;
56034- header = __register_sysctl_table(set, path, files);
56035+ header = __register_sysctl_table(set, path, files ? files : table);
56036 if (!header) {
56037 kfree(ctl_table_arg);
56038 goto out;
56039diff --git a/fs/proc/root.c b/fs/proc/root.c
56040index 41a6ea9..23eaa92 100644
56041--- a/fs/proc/root.c
56042+++ b/fs/proc/root.c
56043@@ -182,7 +182,15 @@ void __init proc_root_init(void)
56044 #ifdef CONFIG_PROC_DEVICETREE
56045 proc_device_tree_init();
56046 #endif
56047+#ifdef CONFIG_GRKERNSEC_PROC_ADD
56048+#ifdef CONFIG_GRKERNSEC_PROC_USER
56049+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
56050+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
56051+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
56052+#endif
56053+#else
56054 proc_mkdir("bus", NULL);
56055+#endif
56056 proc_sys_init();
56057 }
56058
56059diff --git a/fs/proc/self.c b/fs/proc/self.c
56060index 6b6a993..807cccc 100644
56061--- a/fs/proc/self.c
56062+++ b/fs/proc/self.c
56063@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
56064 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
56065 void *cookie)
56066 {
56067- char *s = nd_get_link(nd);
56068+ const char *s = nd_get_link(nd);
56069 if (!IS_ERR(s))
56070 kfree(s);
56071 }
56072diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
56073index 3e636d8..83e3b71 100644
56074--- a/fs/proc/task_mmu.c
56075+++ b/fs/proc/task_mmu.c
56076@@ -11,12 +11,19 @@
56077 #include <linux/rmap.h>
56078 #include <linux/swap.h>
56079 #include <linux/swapops.h>
56080+#include <linux/grsecurity.h>
56081
56082 #include <asm/elf.h>
56083 #include <asm/uaccess.h>
56084 #include <asm/tlbflush.h>
56085 #include "internal.h"
56086
56087+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56088+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
56089+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
56090+ _mm->pax_flags & MF_PAX_SEGMEXEC))
56091+#endif
56092+
56093 void task_mem(struct seq_file *m, struct mm_struct *mm)
56094 {
56095 unsigned long data, text, lib, swap;
56096@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56097 "VmExe:\t%8lu kB\n"
56098 "VmLib:\t%8lu kB\n"
56099 "VmPTE:\t%8lu kB\n"
56100- "VmSwap:\t%8lu kB\n",
56101- hiwater_vm << (PAGE_SHIFT-10),
56102+ "VmSwap:\t%8lu kB\n"
56103+
56104+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56105+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
56106+#endif
56107+
56108+ ,hiwater_vm << (PAGE_SHIFT-10),
56109 total_vm << (PAGE_SHIFT-10),
56110 mm->locked_vm << (PAGE_SHIFT-10),
56111 mm->pinned_vm << (PAGE_SHIFT-10),
56112@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56113 data << (PAGE_SHIFT-10),
56114 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
56115 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
56116- swap << (PAGE_SHIFT-10));
56117+ swap << (PAGE_SHIFT-10)
56118+
56119+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56120+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56121+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
56122+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
56123+#else
56124+ , mm->context.user_cs_base
56125+ , mm->context.user_cs_limit
56126+#endif
56127+#endif
56128+
56129+ );
56130 }
56131
56132 unsigned long task_vsize(struct mm_struct *mm)
56133@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56134 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56135 }
56136
56137- /* We don't show the stack guard page in /proc/maps */
56138+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56139+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56140+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56141+#else
56142 start = vma->vm_start;
56143- if (stack_guard_page_start(vma, start))
56144- start += PAGE_SIZE;
56145 end = vma->vm_end;
56146- if (stack_guard_page_end(vma, end))
56147- end -= PAGE_SIZE;
56148+#endif
56149
56150 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56151 start,
56152@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56153 flags & VM_WRITE ? 'w' : '-',
56154 flags & VM_EXEC ? 'x' : '-',
56155 flags & VM_MAYSHARE ? 's' : 'p',
56156+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56157+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56158+#else
56159 pgoff,
56160+#endif
56161 MAJOR(dev), MINOR(dev), ino, &len);
56162
56163 /*
56164@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56165 */
56166 if (file) {
56167 pad_len_spaces(m, len);
56168- seq_path(m, &file->f_path, "\n");
56169+ seq_path(m, &file->f_path, "\n\\");
56170 goto done;
56171 }
56172
56173@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56174 * Thread stack in /proc/PID/task/TID/maps or
56175 * the main process stack.
56176 */
56177- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56178- vma->vm_end >= mm->start_stack)) {
56179+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56180+ (vma->vm_start <= mm->start_stack &&
56181+ vma->vm_end >= mm->start_stack)) {
56182 name = "[stack]";
56183 } else {
56184 /* Thread stack in /proc/PID/maps */
56185@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56186 struct proc_maps_private *priv = m->private;
56187 struct task_struct *task = priv->task;
56188
56189+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56190+ if (current->exec_id != m->exec_id) {
56191+ gr_log_badprocpid("maps");
56192+ return 0;
56193+ }
56194+#endif
56195+
56196 show_map_vma(m, vma, is_pid);
56197
56198 if (m->count < m->size) /* vma is copied successfully */
56199@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56200 .private = &mss,
56201 };
56202
56203+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56204+ if (current->exec_id != m->exec_id) {
56205+ gr_log_badprocpid("smaps");
56206+ return 0;
56207+ }
56208+#endif
56209 memset(&mss, 0, sizeof mss);
56210- mss.vma = vma;
56211- /* mmap_sem is held in m_start */
56212- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56213- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56214-
56215+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56216+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56217+#endif
56218+ mss.vma = vma;
56219+ /* mmap_sem is held in m_start */
56220+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56221+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56222+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56223+ }
56224+#endif
56225 show_map_vma(m, vma, is_pid);
56226
56227 seq_printf(m,
56228@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56229 "KernelPageSize: %8lu kB\n"
56230 "MMUPageSize: %8lu kB\n"
56231 "Locked: %8lu kB\n",
56232+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56233+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56234+#else
56235 (vma->vm_end - vma->vm_start) >> 10,
56236+#endif
56237 mss.resident >> 10,
56238 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56239 mss.shared_clean >> 10,
56240@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56241 int n;
56242 char buffer[50];
56243
56244+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56245+ if (current->exec_id != m->exec_id) {
56246+ gr_log_badprocpid("numa_maps");
56247+ return 0;
56248+ }
56249+#endif
56250+
56251 if (!mm)
56252 return 0;
56253
56254@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56255 mpol_to_str(buffer, sizeof(buffer), pol);
56256 mpol_cond_put(pol);
56257
56258+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56259+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56260+#else
56261 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56262+#endif
56263
56264 if (file) {
56265 seq_printf(m, " file=");
56266- seq_path(m, &file->f_path, "\n\t= ");
56267+ seq_path(m, &file->f_path, "\n\t\\= ");
56268 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56269 seq_printf(m, " heap");
56270 } else {
56271diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56272index 56123a6..5a2f6ec 100644
56273--- a/fs/proc/task_nommu.c
56274+++ b/fs/proc/task_nommu.c
56275@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56276 else
56277 bytes += kobjsize(mm);
56278
56279- if (current->fs && current->fs->users > 1)
56280+ if (current->fs && atomic_read(&current->fs->users) > 1)
56281 sbytes += kobjsize(current->fs);
56282 else
56283 bytes += kobjsize(current->fs);
56284@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56285
56286 if (file) {
56287 pad_len_spaces(m, len);
56288- seq_path(m, &file->f_path, "");
56289+ seq_path(m, &file->f_path, "\n\\");
56290 } else if (mm) {
56291 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56292
56293diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
56294index 17f7e08..e4b1529 100644
56295--- a/fs/proc/vmcore.c
56296+++ b/fs/proc/vmcore.c
56297@@ -99,9 +99,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
56298 nr_bytes = count;
56299
56300 /* If pfn is not ram, return zeros for sparse dump files */
56301- if (pfn_is_ram(pfn) == 0)
56302- memset(buf, 0, nr_bytes);
56303- else {
56304+ if (pfn_is_ram(pfn) == 0) {
56305+ if (userbuf) {
56306+ if (clear_user((char __force_user *)buf, nr_bytes))
56307+ return -EFAULT;
56308+ } else
56309+ memset(buf, 0, nr_bytes);
56310+ } else {
56311 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
56312 offset, userbuf);
56313 if (tmp < 0)
56314@@ -186,7 +190,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
56315 if (tsz > nr_bytes)
56316 tsz = nr_bytes;
56317
56318- tmp = read_from_oldmem(buffer, tsz, &start, 1);
56319+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
56320 if (tmp < 0)
56321 return tmp;
56322 buflen -= tsz;
56323diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56324index b00fcc9..e0c6381 100644
56325--- a/fs/qnx6/qnx6.h
56326+++ b/fs/qnx6/qnx6.h
56327@@ -74,7 +74,7 @@ enum {
56328 BYTESEX_BE,
56329 };
56330
56331-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56332+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56333 {
56334 if (sbi->s_bytesex == BYTESEX_LE)
56335 return le64_to_cpu((__force __le64)n);
56336@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56337 return (__force __fs64)cpu_to_be64(n);
56338 }
56339
56340-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56341+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56342 {
56343 if (sbi->s_bytesex == BYTESEX_LE)
56344 return le32_to_cpu((__force __le32)n);
56345diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56346index 16e8abb..2dcf914 100644
56347--- a/fs/quota/netlink.c
56348+++ b/fs/quota/netlink.c
56349@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56350 void quota_send_warning(struct kqid qid, dev_t dev,
56351 const char warntype)
56352 {
56353- static atomic_t seq;
56354+ static atomic_unchecked_t seq;
56355 struct sk_buff *skb;
56356 void *msg_head;
56357 int ret;
56358@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56359 "VFS: Not enough memory to send quota warning.\n");
56360 return;
56361 }
56362- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56363+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56364 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56365 if (!msg_head) {
56366 printk(KERN_ERR
56367diff --git a/fs/read_write.c b/fs/read_write.c
56368index 2cefa41..c7e2fe0 100644
56369--- a/fs/read_write.c
56370+++ b/fs/read_write.c
56371@@ -411,7 +411,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
56372
56373 old_fs = get_fs();
56374 set_fs(get_ds());
56375- p = (__force const char __user *)buf;
56376+ p = (const char __force_user *)buf;
56377 if (count > MAX_RW_COUNT)
56378 count = MAX_RW_COUNT;
56379 if (file->f_op->write)
56380diff --git a/fs/readdir.c b/fs/readdir.c
56381index fee38e0..12fdf47 100644
56382--- a/fs/readdir.c
56383+++ b/fs/readdir.c
56384@@ -17,6 +17,7 @@
56385 #include <linux/security.h>
56386 #include <linux/syscalls.h>
56387 #include <linux/unistd.h>
56388+#include <linux/namei.h>
56389
56390 #include <asm/uaccess.h>
56391
56392@@ -67,6 +68,7 @@ struct old_linux_dirent {
56393
56394 struct readdir_callback {
56395 struct old_linux_dirent __user * dirent;
56396+ struct file * file;
56397 int result;
56398 };
56399
56400@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56401 buf->result = -EOVERFLOW;
56402 return -EOVERFLOW;
56403 }
56404+
56405+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56406+ return 0;
56407+
56408 buf->result++;
56409 dirent = buf->dirent;
56410 if (!access_ok(VERIFY_WRITE, dirent,
56411@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56412
56413 buf.result = 0;
56414 buf.dirent = dirent;
56415+ buf.file = f.file;
56416
56417 error = vfs_readdir(f.file, fillonedir, &buf);
56418 if (buf.result)
56419@@ -139,6 +146,7 @@ struct linux_dirent {
56420 struct getdents_callback {
56421 struct linux_dirent __user * current_dir;
56422 struct linux_dirent __user * previous;
56423+ struct file * file;
56424 int count;
56425 int error;
56426 };
56427@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56428 buf->error = -EOVERFLOW;
56429 return -EOVERFLOW;
56430 }
56431+
56432+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56433+ return 0;
56434+
56435 dirent = buf->previous;
56436 if (dirent) {
56437 if (__put_user(offset, &dirent->d_off))
56438@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56439 buf.previous = NULL;
56440 buf.count = count;
56441 buf.error = 0;
56442+ buf.file = f.file;
56443
56444 error = vfs_readdir(f.file, filldir, &buf);
56445 if (error >= 0)
56446@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56447 struct getdents_callback64 {
56448 struct linux_dirent64 __user * current_dir;
56449 struct linux_dirent64 __user * previous;
56450+ struct file *file;
56451 int count;
56452 int error;
56453 };
56454@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56455 buf->error = -EINVAL; /* only used if we fail.. */
56456 if (reclen > buf->count)
56457 return -EINVAL;
56458+
56459+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56460+ return 0;
56461+
56462 dirent = buf->previous;
56463 if (dirent) {
56464 if (__put_user(offset, &dirent->d_off))
56465@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56466
56467 buf.current_dir = dirent;
56468 buf.previous = NULL;
56469+ buf.file = f.file;
56470 buf.count = count;
56471 buf.error = 0;
56472
56473@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56474 error = buf.error;
56475 lastdirent = buf.previous;
56476 if (lastdirent) {
56477- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56478+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56479 if (__put_user(d_off, &lastdirent->d_off))
56480 error = -EFAULT;
56481 else
56482diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56483index 2b7882b..1c5ef48 100644
56484--- a/fs/reiserfs/do_balan.c
56485+++ b/fs/reiserfs/do_balan.c
56486@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56487 return;
56488 }
56489
56490- atomic_inc(&(fs_generation(tb->tb_sb)));
56491+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56492 do_balance_starts(tb);
56493
56494 /* balance leaf returns 0 except if combining L R and S into
56495diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56496index 33532f7..4846ade 100644
56497--- a/fs/reiserfs/procfs.c
56498+++ b/fs/reiserfs/procfs.c
56499@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56500 "SMALL_TAILS " : "NO_TAILS ",
56501 replay_only(sb) ? "REPLAY_ONLY " : "",
56502 convert_reiserfs(sb) ? "CONV " : "",
56503- atomic_read(&r->s_generation_counter),
56504+ atomic_read_unchecked(&r->s_generation_counter),
56505 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56506 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56507 SF(s_good_search_by_key_reada), SF(s_bmaps),
56508diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56509index 157e474..65a6114 100644
56510--- a/fs/reiserfs/reiserfs.h
56511+++ b/fs/reiserfs/reiserfs.h
56512@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56513 /* Comment? -Hans */
56514 wait_queue_head_t s_wait;
56515 /* To be obsoleted soon by per buffer seals.. -Hans */
56516- atomic_t s_generation_counter; // increased by one every time the
56517+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56518 // tree gets re-balanced
56519 unsigned long s_properties; /* File system properties. Currently holds
56520 on-disk FS format */
56521@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56522 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56523
56524 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56525-#define get_generation(s) atomic_read (&fs_generation(s))
56526+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56527 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56528 #define __fs_changed(gen,s) (gen != get_generation (s))
56529 #define fs_changed(gen,s) \
56530diff --git a/fs/select.c b/fs/select.c
56531index 8c1c96c..a0f9b6d 100644
56532--- a/fs/select.c
56533+++ b/fs/select.c
56534@@ -20,6 +20,7 @@
56535 #include <linux/export.h>
56536 #include <linux/slab.h>
56537 #include <linux/poll.h>
56538+#include <linux/security.h>
56539 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56540 #include <linux/file.h>
56541 #include <linux/fdtable.h>
56542@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56543 struct poll_list *walk = head;
56544 unsigned long todo = nfds;
56545
56546+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56547 if (nfds > rlimit(RLIMIT_NOFILE))
56548 return -EINVAL;
56549
56550diff --git a/fs/seq_file.c b/fs/seq_file.c
56551index 774c1eb..b67582a 100644
56552--- a/fs/seq_file.c
56553+++ b/fs/seq_file.c
56554@@ -10,6 +10,7 @@
56555 #include <linux/seq_file.h>
56556 #include <linux/slab.h>
56557 #include <linux/cred.h>
56558+#include <linux/sched.h>
56559
56560 #include <asm/uaccess.h>
56561 #include <asm/page.h>
56562@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56563 #ifdef CONFIG_USER_NS
56564 p->user_ns = file->f_cred->user_ns;
56565 #endif
56566+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56567+ p->exec_id = current->exec_id;
56568+#endif
56569
56570 /*
56571 * Wrappers around seq_open(e.g. swaps_open) need to be
56572@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56573 return 0;
56574 }
56575 if (!m->buf) {
56576- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56577+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56578 if (!m->buf)
56579 return -ENOMEM;
56580 }
56581@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56582 Eoverflow:
56583 m->op->stop(m, p);
56584 kfree(m->buf);
56585- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56586+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56587 return !m->buf ? -ENOMEM : -EAGAIN;
56588 }
56589
56590@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56591
56592 /* grab buffer if we didn't have one */
56593 if (!m->buf) {
56594- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56595+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56596 if (!m->buf)
56597 goto Enomem;
56598 }
56599@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56600 goto Fill;
56601 m->op->stop(m, p);
56602 kfree(m->buf);
56603- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56604+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56605 if (!m->buf)
56606 goto Enomem;
56607 m->count = 0;
56608@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56609 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56610 void *data)
56611 {
56612- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56613+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56614 int res = -ENOMEM;
56615
56616 if (op) {
56617diff --git a/fs/splice.c b/fs/splice.c
56618index d37431d..81c3044 100644
56619--- a/fs/splice.c
56620+++ b/fs/splice.c
56621@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56622 pipe_lock(pipe);
56623
56624 for (;;) {
56625- if (!pipe->readers) {
56626+ if (!atomic_read(&pipe->readers)) {
56627 send_sig(SIGPIPE, current, 0);
56628 if (!ret)
56629 ret = -EPIPE;
56630@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56631 page_nr++;
56632 ret += buf->len;
56633
56634- if (pipe->files)
56635+ if (atomic_read(&pipe->files))
56636 do_wakeup = 1;
56637
56638 if (!--spd->nr_pages)
56639@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56640 do_wakeup = 0;
56641 }
56642
56643- pipe->waiting_writers++;
56644+ atomic_inc(&pipe->waiting_writers);
56645 pipe_wait(pipe);
56646- pipe->waiting_writers--;
56647+ atomic_dec(&pipe->waiting_writers);
56648 }
56649
56650 pipe_unlock(pipe);
56651@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56652 old_fs = get_fs();
56653 set_fs(get_ds());
56654 /* The cast to a user pointer is valid due to the set_fs() */
56655- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56656+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56657 set_fs(old_fs);
56658
56659 return res;
56660@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56661 old_fs = get_fs();
56662 set_fs(get_ds());
56663 /* The cast to a user pointer is valid due to the set_fs() */
56664- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
56665+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56666 set_fs(old_fs);
56667
56668 return res;
56669@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56670 goto err;
56671
56672 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56673- vec[i].iov_base = (void __user *) page_address(page);
56674+ vec[i].iov_base = (void __force_user *) page_address(page);
56675 vec[i].iov_len = this_len;
56676 spd.pages[i] = page;
56677 spd.nr_pages++;
56678@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
56679 ops->release(pipe, buf);
56680 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
56681 pipe->nrbufs--;
56682- if (pipe->files)
56683+ if (atomic_read(&pipe->files))
56684 sd->need_wakeup = true;
56685 }
56686
56687@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56688 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56689 {
56690 while (!pipe->nrbufs) {
56691- if (!pipe->writers)
56692+ if (!atomic_read(&pipe->writers))
56693 return 0;
56694
56695- if (!pipe->waiting_writers && sd->num_spliced)
56696+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56697 return 0;
56698
56699 if (sd->flags & SPLICE_F_NONBLOCK)
56700@@ -1193,7 +1193,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56701 * out of the pipe right after the splice_to_pipe(). So set
56702 * PIPE_READERS appropriately.
56703 */
56704- pipe->readers = 1;
56705+ atomic_set(&pipe->readers, 1);
56706
56707 current->splice_pipe = pipe;
56708 }
56709@@ -1769,9 +1769,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56710 ret = -ERESTARTSYS;
56711 break;
56712 }
56713- if (!pipe->writers)
56714+ if (!atomic_read(&pipe->writers))
56715 break;
56716- if (!pipe->waiting_writers) {
56717+ if (!atomic_read(&pipe->waiting_writers)) {
56718 if (flags & SPLICE_F_NONBLOCK) {
56719 ret = -EAGAIN;
56720 break;
56721@@ -1803,7 +1803,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56722 pipe_lock(pipe);
56723
56724 while (pipe->nrbufs >= pipe->buffers) {
56725- if (!pipe->readers) {
56726+ if (!atomic_read(&pipe->readers)) {
56727 send_sig(SIGPIPE, current, 0);
56728 ret = -EPIPE;
56729 break;
56730@@ -1816,9 +1816,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56731 ret = -ERESTARTSYS;
56732 break;
56733 }
56734- pipe->waiting_writers++;
56735+ atomic_inc(&pipe->waiting_writers);
56736 pipe_wait(pipe);
56737- pipe->waiting_writers--;
56738+ atomic_dec(&pipe->waiting_writers);
56739 }
56740
56741 pipe_unlock(pipe);
56742@@ -1854,14 +1854,14 @@ retry:
56743 pipe_double_lock(ipipe, opipe);
56744
56745 do {
56746- if (!opipe->readers) {
56747+ if (!atomic_read(&opipe->readers)) {
56748 send_sig(SIGPIPE, current, 0);
56749 if (!ret)
56750 ret = -EPIPE;
56751 break;
56752 }
56753
56754- if (!ipipe->nrbufs && !ipipe->writers)
56755+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56756 break;
56757
56758 /*
56759@@ -1958,7 +1958,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56760 pipe_double_lock(ipipe, opipe);
56761
56762 do {
56763- if (!opipe->readers) {
56764+ if (!atomic_read(&opipe->readers)) {
56765 send_sig(SIGPIPE, current, 0);
56766 if (!ret)
56767 ret = -EPIPE;
56768@@ -2003,7 +2003,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56769 * return EAGAIN if we have the potential of some data in the
56770 * future, otherwise just return 0
56771 */
56772- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56773+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56774 ret = -EAGAIN;
56775
56776 pipe_unlock(ipipe);
56777diff --git a/fs/stat.c b/fs/stat.c
56778index 04ce1ac..a13dd1e 100644
56779--- a/fs/stat.c
56780+++ b/fs/stat.c
56781@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56782 stat->gid = inode->i_gid;
56783 stat->rdev = inode->i_rdev;
56784 stat->size = i_size_read(inode);
56785- stat->atime = inode->i_atime;
56786- stat->mtime = inode->i_mtime;
56787+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56788+ stat->atime = inode->i_ctime;
56789+ stat->mtime = inode->i_ctime;
56790+ } else {
56791+ stat->atime = inode->i_atime;
56792+ stat->mtime = inode->i_mtime;
56793+ }
56794 stat->ctime = inode->i_ctime;
56795 stat->blksize = (1 << inode->i_blkbits);
56796 stat->blocks = inode->i_blocks;
56797@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
56798 if (retval)
56799 return retval;
56800
56801- if (inode->i_op->getattr)
56802- return inode->i_op->getattr(path->mnt, path->dentry, stat);
56803+ if (inode->i_op->getattr) {
56804+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
56805+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56806+ stat->atime = stat->ctime;
56807+ stat->mtime = stat->ctime;
56808+ }
56809+ return retval;
56810+ }
56811
56812 generic_fillattr(inode, stat);
56813 return 0;
56814diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56815index 15c68f9..36a8b3e 100644
56816--- a/fs/sysfs/bin.c
56817+++ b/fs/sysfs/bin.c
56818@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56819 return ret;
56820 }
56821
56822-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56823- void *buf, int len, int write)
56824+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56825+ void *buf, size_t len, int write)
56826 {
56827 struct file *file = vma->vm_file;
56828 struct bin_buffer *bb = file->private_data;
56829 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56830- int ret;
56831+ ssize_t ret;
56832
56833 if (!bb->vm_ops)
56834 return -EINVAL;
56835diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56836index e8e0e71..3ca455a 100644
56837--- a/fs/sysfs/dir.c
56838+++ b/fs/sysfs/dir.c
56839@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56840 *
56841 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56842 */
56843-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56844+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56845 {
56846 unsigned long hash = init_name_hash();
56847 unsigned int len = strlen(name);
56848@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56849 struct sysfs_dirent *sd;
56850 int rc;
56851
56852+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56853+ const char *parent_name = parent_sd->s_name;
56854+
56855+ mode = S_IFDIR | S_IRWXU;
56856+
56857+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56858+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56859+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56860+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56861+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56862+#endif
56863+
56864 /* allocate */
56865 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56866 if (!sd)
56867diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56868index 602f56d..6853db8 100644
56869--- a/fs/sysfs/file.c
56870+++ b/fs/sysfs/file.c
56871@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56872
56873 struct sysfs_open_dirent {
56874 atomic_t refcnt;
56875- atomic_t event;
56876+ atomic_unchecked_t event;
56877 wait_queue_head_t poll;
56878 struct list_head buffers; /* goes through sysfs_buffer.list */
56879 };
56880@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56881 if (!sysfs_get_active(attr_sd))
56882 return -ENODEV;
56883
56884- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56885+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56886 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56887
56888 sysfs_put_active(attr_sd);
56889@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56890 return -ENOMEM;
56891
56892 atomic_set(&new_od->refcnt, 0);
56893- atomic_set(&new_od->event, 1);
56894+ atomic_set_unchecked(&new_od->event, 1);
56895 init_waitqueue_head(&new_od->poll);
56896 INIT_LIST_HEAD(&new_od->buffers);
56897 goto retry;
56898@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56899
56900 sysfs_put_active(attr_sd);
56901
56902- if (buffer->event != atomic_read(&od->event))
56903+ if (buffer->event != atomic_read_unchecked(&od->event))
56904 goto trigger;
56905
56906 return DEFAULT_POLLMASK;
56907@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56908
56909 od = sd->s_attr.open;
56910 if (od) {
56911- atomic_inc(&od->event);
56912+ atomic_inc_unchecked(&od->event);
56913 wake_up_interruptible(&od->poll);
56914 }
56915
56916diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56917index 8c940df..25b733e 100644
56918--- a/fs/sysfs/symlink.c
56919+++ b/fs/sysfs/symlink.c
56920@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56921
56922 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56923 {
56924- char *page = nd_get_link(nd);
56925+ const char *page = nd_get_link(nd);
56926 if (!IS_ERR(page))
56927 free_page((unsigned long)page);
56928 }
56929diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56930index 69d4889..a810bd4 100644
56931--- a/fs/sysv/sysv.h
56932+++ b/fs/sysv/sysv.h
56933@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56934 #endif
56935 }
56936
56937-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56938+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56939 {
56940 if (sbi->s_bytesex == BYTESEX_PDP)
56941 return PDP_swab((__force __u32)n);
56942diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56943index e18b988..f1d4ad0f 100644
56944--- a/fs/ubifs/io.c
56945+++ b/fs/ubifs/io.c
56946@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56947 return err;
56948 }
56949
56950-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56951+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56952 {
56953 int err;
56954
56955diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56956index c175b4d..8f36a16 100644
56957--- a/fs/udf/misc.c
56958+++ b/fs/udf/misc.c
56959@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56960
56961 u8 udf_tag_checksum(const struct tag *t)
56962 {
56963- u8 *data = (u8 *)t;
56964+ const u8 *data = (const u8 *)t;
56965 u8 checksum = 0;
56966 int i;
56967 for (i = 0; i < sizeof(struct tag); ++i)
56968diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56969index 8d974c4..b82f6ec 100644
56970--- a/fs/ufs/swab.h
56971+++ b/fs/ufs/swab.h
56972@@ -22,7 +22,7 @@ enum {
56973 BYTESEX_BE
56974 };
56975
56976-static inline u64
56977+static inline u64 __intentional_overflow(-1)
56978 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56979 {
56980 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56981@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56982 return (__force __fs64)cpu_to_be64(n);
56983 }
56984
56985-static inline u32
56986+static inline u32 __intentional_overflow(-1)
56987 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56988 {
56989 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56990diff --git a/fs/utimes.c b/fs/utimes.c
56991index f4fb7ec..3fe03c0 100644
56992--- a/fs/utimes.c
56993+++ b/fs/utimes.c
56994@@ -1,6 +1,7 @@
56995 #include <linux/compiler.h>
56996 #include <linux/file.h>
56997 #include <linux/fs.h>
56998+#include <linux/security.h>
56999 #include <linux/linkage.h>
57000 #include <linux/mount.h>
57001 #include <linux/namei.h>
57002@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
57003 goto mnt_drop_write_and_out;
57004 }
57005 }
57006+
57007+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
57008+ error = -EACCES;
57009+ goto mnt_drop_write_and_out;
57010+ }
57011+
57012 mutex_lock(&inode->i_mutex);
57013 error = notify_change(path->dentry, &newattrs);
57014 mutex_unlock(&inode->i_mutex);
57015diff --git a/fs/xattr.c b/fs/xattr.c
57016index 3377dff..4d074d9 100644
57017--- a/fs/xattr.c
57018+++ b/fs/xattr.c
57019@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
57020 return rc;
57021 }
57022
57023+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
57024+ssize_t
57025+pax_getxattr(struct dentry *dentry, void *value, size_t size)
57026+{
57027+ struct inode *inode = dentry->d_inode;
57028+ ssize_t error;
57029+
57030+ error = inode_permission(inode, MAY_EXEC);
57031+ if (error)
57032+ return error;
57033+
57034+ if (inode->i_op->getxattr)
57035+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
57036+ else
57037+ error = -EOPNOTSUPP;
57038+
57039+ return error;
57040+}
57041+EXPORT_SYMBOL(pax_getxattr);
57042+#endif
57043+
57044 ssize_t
57045 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
57046 {
57047@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
57048 * Extended attribute SET operations
57049 */
57050 static long
57051-setxattr(struct dentry *d, const char __user *name, const void __user *value,
57052+setxattr(struct path *path, const char __user *name, const void __user *value,
57053 size_t size, int flags)
57054 {
57055 int error;
57056@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
57057 posix_acl_fix_xattr_from_user(kvalue, size);
57058 }
57059
57060- error = vfs_setxattr(d, kname, kvalue, size, flags);
57061+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
57062+ error = -EACCES;
57063+ goto out;
57064+ }
57065+
57066+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
57067 out:
57068 if (vvalue)
57069 vfree(vvalue);
57070@@ -377,7 +403,7 @@ retry:
57071 return error;
57072 error = mnt_want_write(path.mnt);
57073 if (!error) {
57074- error = setxattr(path.dentry, name, value, size, flags);
57075+ error = setxattr(&path, name, value, size, flags);
57076 mnt_drop_write(path.mnt);
57077 }
57078 path_put(&path);
57079@@ -401,7 +427,7 @@ retry:
57080 return error;
57081 error = mnt_want_write(path.mnt);
57082 if (!error) {
57083- error = setxattr(path.dentry, name, value, size, flags);
57084+ error = setxattr(&path, name, value, size, flags);
57085 mnt_drop_write(path.mnt);
57086 }
57087 path_put(&path);
57088@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
57089 const void __user *,value, size_t, size, int, flags)
57090 {
57091 struct fd f = fdget(fd);
57092- struct dentry *dentry;
57093 int error = -EBADF;
57094
57095 if (!f.file)
57096 return error;
57097- dentry = f.file->f_path.dentry;
57098- audit_inode(NULL, dentry, 0);
57099+ audit_inode(NULL, f.file->f_path.dentry, 0);
57100 error = mnt_want_write_file(f.file);
57101 if (!error) {
57102- error = setxattr(dentry, name, value, size, flags);
57103+ error = setxattr(&f.file->f_path, name, value, size, flags);
57104 mnt_drop_write_file(f.file);
57105 }
57106 fdput(f);
57107diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
57108index 9fbea87..6b19972 100644
57109--- a/fs/xattr_acl.c
57110+++ b/fs/xattr_acl.c
57111@@ -76,8 +76,8 @@ struct posix_acl *
57112 posix_acl_from_xattr(struct user_namespace *user_ns,
57113 const void *value, size_t size)
57114 {
57115- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57116- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57117+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57118+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57119 int count;
57120 struct posix_acl *acl;
57121 struct posix_acl_entry *acl_e;
57122diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57123index 8904284..ee0e14b 100644
57124--- a/fs/xfs/xfs_bmap.c
57125+++ b/fs/xfs/xfs_bmap.c
57126@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
57127
57128 #else
57129 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
57130-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57131+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
57132 #endif /* DEBUG */
57133
57134 /*
57135diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57136index 6157424..ac98f6d 100644
57137--- a/fs/xfs/xfs_dir2_sf.c
57138+++ b/fs/xfs/xfs_dir2_sf.c
57139@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57140 }
57141
57142 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57143- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57144+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57145+ char name[sfep->namelen];
57146+ memcpy(name, sfep->name, sfep->namelen);
57147+ if (filldir(dirent, name, sfep->namelen,
57148+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57149+ *offset = off & 0x7fffffff;
57150+ return 0;
57151+ }
57152+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57153 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57154 *offset = off & 0x7fffffff;
57155 return 0;
57156diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57157index 5e99968..45bd327 100644
57158--- a/fs/xfs/xfs_ioctl.c
57159+++ b/fs/xfs/xfs_ioctl.c
57160@@ -127,7 +127,7 @@ xfs_find_handle(
57161 }
57162
57163 error = -EFAULT;
57164- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57165+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57166 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57167 goto out_put;
57168
57169diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57170index ca9ecaa..60100c7 100644
57171--- a/fs/xfs/xfs_iops.c
57172+++ b/fs/xfs/xfs_iops.c
57173@@ -395,7 +395,7 @@ xfs_vn_put_link(
57174 struct nameidata *nd,
57175 void *p)
57176 {
57177- char *s = nd_get_link(nd);
57178+ const char *s = nd_get_link(nd);
57179
57180 if (!IS_ERR(s))
57181 kfree(s);
57182diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57183new file mode 100644
57184index 0000000..c9c4ac3
57185--- /dev/null
57186+++ b/grsecurity/Kconfig
57187@@ -0,0 +1,1054 @@
57188+#
57189+# grecurity configuration
57190+#
57191+menu "Memory Protections"
57192+depends on GRKERNSEC
57193+
57194+config GRKERNSEC_KMEM
57195+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57196+ default y if GRKERNSEC_CONFIG_AUTO
57197+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57198+ help
57199+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57200+ be written to or read from to modify or leak the contents of the running
57201+ kernel. /dev/port will also not be allowed to be opened and support
57202+ for /dev/cpu/*/msr will be removed. If you have module
57203+ support disabled, enabling this will close up five ways that are
57204+ currently used to insert malicious code into the running kernel.
57205+
57206+ Even with all these features enabled, we still highly recommend that
57207+ you use the RBAC system, as it is still possible for an attacker to
57208+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57209+
57210+ If you are not using XFree86, you may be able to stop this additional
57211+ case by enabling the 'Disable privileged I/O' option. Though nothing
57212+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57213+ but only to video memory, which is the only writing we allow in this
57214+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57215+ not be allowed to mprotect it with PROT_WRITE later.
57216+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57217+ from working.
57218+
57219+ It is highly recommended that you say Y here if you meet all the
57220+ conditions above.
57221+
57222+config GRKERNSEC_VM86
57223+ bool "Restrict VM86 mode"
57224+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57225+ depends on X86_32
57226+
57227+ help
57228+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57229+ make use of a special execution mode on 32bit x86 processors called
57230+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57231+ video cards and will still work with this option enabled. The purpose
57232+ of the option is to prevent exploitation of emulation errors in
57233+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57234+ Nearly all users should be able to enable this option.
57235+
57236+config GRKERNSEC_IO
57237+ bool "Disable privileged I/O"
57238+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57239+ depends on X86
57240+ select RTC_CLASS
57241+ select RTC_INTF_DEV
57242+ select RTC_DRV_CMOS
57243+
57244+ help
57245+ If you say Y here, all ioperm and iopl calls will return an error.
57246+ Ioperm and iopl can be used to modify the running kernel.
57247+ Unfortunately, some programs need this access to operate properly,
57248+ the most notable of which are XFree86 and hwclock. hwclock can be
57249+ remedied by having RTC support in the kernel, so real-time
57250+ clock support is enabled if this option is enabled, to ensure
57251+ that hwclock operates correctly. XFree86 still will not
57252+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57253+ IF YOU USE XFree86. If you use XFree86 and you still want to
57254+ protect your kernel against modification, use the RBAC system.
57255+
57256+config GRKERNSEC_JIT_HARDEN
57257+ bool "Harden BPF JIT against spray attacks"
57258+ default y if GRKERNSEC_CONFIG_AUTO
57259+ depends on BPF_JIT
57260+ help
57261+ If you say Y here, the native code generated by the kernel's Berkeley
57262+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57263+ attacks that attempt to fit attacker-beneficial instructions in
57264+ 32bit immediate fields of JIT-generated native instructions. The
57265+ attacker will generally aim to cause an unintended instruction sequence
57266+ of JIT-generated native code to execute by jumping into the middle of
57267+ a generated instruction. This feature effectively randomizes the 32bit
57268+ immediate constants present in the generated code to thwart such attacks.
57269+
57270+ If you're using KERNEXEC, it's recommended that you enable this option
57271+ to supplement the hardening of the kernel.
57272+
57273+config GRKERNSEC_PERF_HARDEN
57274+ bool "Disable unprivileged PERF_EVENTS usage by default"
57275+ default y if GRKERNSEC_CONFIG_AUTO
57276+ depends on PERF_EVENTS
57277+ help
57278+ If you say Y here, the range of acceptable values for the
57279+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
57280+ default to a new value: 3. When the sysctl is set to this value, no
57281+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
57282+
57283+ Though PERF_EVENTS can be used legitimately for performance monitoring
57284+ and low-level application profiling, it is forced on regardless of
57285+ configuration, has been at fault for several vulnerabilities, and
57286+ creates new opportunities for side channels and other information leaks.
57287+
57288+ This feature puts PERF_EVENTS into a secure default state and permits
57289+ the administrator to change out of it temporarily if unprivileged
57290+ application profiling is needed.
57291+
57292+config GRKERNSEC_RAND_THREADSTACK
57293+ bool "Insert random gaps between thread stacks"
57294+ default y if GRKERNSEC_CONFIG_AUTO
57295+ depends on PAX_RANDMMAP && !PPC
57296+ help
57297+ If you say Y here, a random-sized gap will be enforced between allocated
57298+ thread stacks. Glibc's NPTL and other threading libraries that
57299+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57300+ The implementation currently provides 8 bits of entropy for the gap.
57301+
57302+ Many distributions do not compile threaded remote services with the
57303+ -fstack-check argument to GCC, causing the variable-sized stack-based
57304+ allocator, alloca(), to not probe the stack on allocation. This
57305+ permits an unbounded alloca() to skip over any guard page and potentially
57306+ modify another thread's stack reliably. An enforced random gap
57307+ reduces the reliability of such an attack and increases the chance
57308+ that such a read/write to another thread's stack instead lands in
57309+ an unmapped area, causing a crash and triggering grsecurity's
57310+ anti-bruteforcing logic.
57311+
57312+config GRKERNSEC_PROC_MEMMAP
57313+ bool "Harden ASLR against information leaks and entropy reduction"
57314+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57315+ depends on PAX_NOEXEC || PAX_ASLR
57316+ help
57317+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57318+ give no information about the addresses of its mappings if
57319+ PaX features that rely on random addresses are enabled on the task.
57320+ In addition to sanitizing this information and disabling other
57321+ dangerous sources of information, this option causes reads of sensitive
57322+ /proc/<pid> entries where the file descriptor was opened in a different
57323+ task than the one performing the read. Such attempts are logged.
57324+ This option also limits argv/env strings for suid/sgid binaries
57325+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57326+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57327+ binaries to prevent alternative mmap layouts from being abused.
57328+
57329+ If you use PaX it is essential that you say Y here as it closes up
57330+ several holes that make full ASLR useless locally.
57331+
57332+config GRKERNSEC_BRUTE
57333+ bool "Deter exploit bruteforcing"
57334+ default y if GRKERNSEC_CONFIG_AUTO
57335+ help
57336+ If you say Y here, attempts to bruteforce exploits against forking
57337+ daemons such as apache or sshd, as well as against suid/sgid binaries
57338+ will be deterred. When a child of a forking daemon is killed by PaX
57339+ or crashes due to an illegal instruction or other suspicious signal,
57340+ the parent process will be delayed 30 seconds upon every subsequent
57341+ fork until the administrator is able to assess the situation and
57342+ restart the daemon.
57343+ In the suid/sgid case, the attempt is logged, the user has all their
57344+ existing instances of the suid/sgid binary terminated and will
57345+ be unable to execute any suid/sgid binaries for 15 minutes.
57346+
57347+ It is recommended that you also enable signal logging in the auditing
57348+ section so that logs are generated when a process triggers a suspicious
57349+ signal.
57350+ If the sysctl option is enabled, a sysctl option with name
57351+ "deter_bruteforce" is created.
57352+
57353+
57354+config GRKERNSEC_MODHARDEN
57355+ bool "Harden module auto-loading"
57356+ default y if GRKERNSEC_CONFIG_AUTO
57357+ depends on MODULES
57358+ help
57359+ If you say Y here, module auto-loading in response to use of some
57360+ feature implemented by an unloaded module will be restricted to
57361+ root users. Enabling this option helps defend against attacks
57362+ by unprivileged users who abuse the auto-loading behavior to
57363+ cause a vulnerable module to load that is then exploited.
57364+
57365+ If this option prevents a legitimate use of auto-loading for a
57366+ non-root user, the administrator can execute modprobe manually
57367+ with the exact name of the module mentioned in the alert log.
57368+ Alternatively, the administrator can add the module to the list
57369+ of modules loaded at boot by modifying init scripts.
57370+
57371+ Modification of init scripts will most likely be needed on
57372+ Ubuntu servers with encrypted home directory support enabled,
57373+ as the first non-root user logging in will cause the ecb(aes),
57374+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57375+
57376+config GRKERNSEC_HIDESYM
57377+ bool "Hide kernel symbols"
57378+ default y if GRKERNSEC_CONFIG_AUTO
57379+ select PAX_USERCOPY_SLABS
57380+ help
57381+ If you say Y here, getting information on loaded modules, and
57382+ displaying all kernel symbols through a syscall will be restricted
57383+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57384+ /proc/kallsyms will be restricted to the root user. The RBAC
57385+ system can hide that entry even from root.
57386+
57387+ This option also prevents leaking of kernel addresses through
57388+ several /proc entries.
57389+
57390+ Note that this option is only effective provided the following
57391+ conditions are met:
57392+ 1) The kernel using grsecurity is not precompiled by some distribution
57393+ 2) You have also enabled GRKERNSEC_DMESG
57394+ 3) You are using the RBAC system and hiding other files such as your
57395+ kernel image and System.map. Alternatively, enabling this option
57396+ causes the permissions on /boot, /lib/modules, and the kernel
57397+ source directory to change at compile time to prevent
57398+ reading by non-root users.
57399+ If the above conditions are met, this option will aid in providing a
57400+ useful protection against local kernel exploitation of overflows
57401+ and arbitrary read/write vulnerabilities.
57402+
57403+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
57404+ in addition to this feature.
57405+
57406+config GRKERNSEC_KERN_LOCKOUT
57407+ bool "Active kernel exploit response"
57408+ default y if GRKERNSEC_CONFIG_AUTO
57409+ depends on X86 || ARM || PPC || SPARC
57410+ help
57411+ If you say Y here, when a PaX alert is triggered due to suspicious
57412+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57413+ or an OOPS occurs due to bad memory accesses, instead of just
57414+ terminating the offending process (and potentially allowing
57415+ a subsequent exploit from the same user), we will take one of two
57416+ actions:
57417+ If the user was root, we will panic the system
57418+ If the user was non-root, we will log the attempt, terminate
57419+ all processes owned by the user, then prevent them from creating
57420+ any new processes until the system is restarted
57421+ This deters repeated kernel exploitation/bruteforcing attempts
57422+ and is useful for later forensics.
57423+
57424+endmenu
57425+menu "Role Based Access Control Options"
57426+depends on GRKERNSEC
57427+
57428+config GRKERNSEC_RBAC_DEBUG
57429+ bool
57430+
57431+config GRKERNSEC_NO_RBAC
57432+ bool "Disable RBAC system"
57433+ help
57434+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57435+ preventing the RBAC system from being enabled. You should only say Y
57436+ here if you have no intention of using the RBAC system, so as to prevent
57437+ an attacker with root access from misusing the RBAC system to hide files
57438+ and processes when loadable module support and /dev/[k]mem have been
57439+ locked down.
57440+
57441+config GRKERNSEC_ACL_HIDEKERN
57442+ bool "Hide kernel processes"
57443+ help
57444+ If you say Y here, all kernel threads will be hidden to all
57445+ processes but those whose subject has the "view hidden processes"
57446+ flag.
57447+
57448+config GRKERNSEC_ACL_MAXTRIES
57449+ int "Maximum tries before password lockout"
57450+ default 3
57451+ help
57452+ This option enforces the maximum number of times a user can attempt
57453+ to authorize themselves with the grsecurity RBAC system before being
57454+ denied the ability to attempt authorization again for a specified time.
57455+ The lower the number, the harder it will be to brute-force a password.
57456+
57457+config GRKERNSEC_ACL_TIMEOUT
57458+ int "Time to wait after max password tries, in seconds"
57459+ default 30
57460+ help
57461+ This option specifies the time the user must wait after attempting to
57462+ authorize to the RBAC system with the maximum number of invalid
57463+ passwords. The higher the number, the harder it will be to brute-force
57464+ a password.
57465+
57466+endmenu
57467+menu "Filesystem Protections"
57468+depends on GRKERNSEC
57469+
57470+config GRKERNSEC_PROC
57471+ bool "Proc restrictions"
57472+ default y if GRKERNSEC_CONFIG_AUTO
57473+ help
57474+ If you say Y here, the permissions of the /proc filesystem
57475+ will be altered to enhance system security and privacy. You MUST
57476+ choose either a user only restriction or a user and group restriction.
57477+ Depending upon the option you choose, you can either restrict users to
57478+ see only the processes they themselves run, or choose a group that can
57479+ view all processes and files normally restricted to root if you choose
57480+ the "restrict to user only" option. NOTE: If you're running identd or
57481+ ntpd as a non-root user, you will have to run it as the group you
57482+ specify here.
57483+
57484+config GRKERNSEC_PROC_USER
57485+ bool "Restrict /proc to user only"
57486+ depends on GRKERNSEC_PROC
57487+ help
57488+ If you say Y here, non-root users will only be able to view their own
57489+ processes, and restricts them from viewing network-related information,
57490+ and viewing kernel symbol and module information.
57491+
57492+config GRKERNSEC_PROC_USERGROUP
57493+ bool "Allow special group"
57494+ default y if GRKERNSEC_CONFIG_AUTO
57495+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57496+ help
57497+ If you say Y here, you will be able to select a group that will be
57498+ able to view all processes and network-related information. If you've
57499+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57500+ remain hidden. This option is useful if you want to run identd as
57501+ a non-root user. The group you select may also be chosen at boot time
57502+ via "grsec_proc_gid=" on the kernel commandline.
57503+
57504+config GRKERNSEC_PROC_GID
57505+ int "GID for special group"
57506+ depends on GRKERNSEC_PROC_USERGROUP
57507+ default 1001
57508+
57509+config GRKERNSEC_PROC_ADD
57510+ bool "Additional restrictions"
57511+ default y if GRKERNSEC_CONFIG_AUTO
57512+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57513+ help
57514+ If you say Y here, additional restrictions will be placed on
57515+ /proc that keep normal users from viewing device information and
57516+ slabinfo information that could be useful for exploits.
57517+
57518+config GRKERNSEC_LINK
57519+ bool "Linking restrictions"
57520+ default y if GRKERNSEC_CONFIG_AUTO
57521+ help
57522+ If you say Y here, /tmp race exploits will be prevented, since users
57523+ will no longer be able to follow symlinks owned by other users in
57524+ world-writable +t directories (e.g. /tmp), unless the owner of the
57525+ symlink is the owner of the directory. users will also not be
57526+ able to hardlink to files they do not own. If the sysctl option is
57527+ enabled, a sysctl option with name "linking_restrictions" is created.
57528+
57529+config GRKERNSEC_SYMLINKOWN
57530+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57531+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57532+ help
57533+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57534+ that prevents it from being used as a security feature. As Apache
57535+ verifies the symlink by performing a stat() against the target of
57536+ the symlink before it is followed, an attacker can setup a symlink
57537+ to point to a same-owned file, then replace the symlink with one
57538+ that targets another user's file just after Apache "validates" the
57539+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57540+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57541+ will be in place for the group you specify. If the sysctl option
57542+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57543+ created.
57544+
57545+config GRKERNSEC_SYMLINKOWN_GID
57546+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57547+ depends on GRKERNSEC_SYMLINKOWN
57548+ default 1006
57549+ help
57550+ Setting this GID determines what group kernel-enforced
57551+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57552+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57553+
57554+config GRKERNSEC_FIFO
57555+ bool "FIFO restrictions"
57556+ default y if GRKERNSEC_CONFIG_AUTO
57557+ help
57558+ If you say Y here, users will not be able to write to FIFOs they don't
57559+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57560+ the FIFO is the same owner of the directory it's held in. If the sysctl
57561+ option is enabled, a sysctl option with name "fifo_restrictions" is
57562+ created.
57563+
57564+config GRKERNSEC_SYSFS_RESTRICT
57565+ bool "Sysfs/debugfs restriction"
57566+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57567+ depends on SYSFS
57568+ help
57569+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57570+ any filesystem normally mounted under it (e.g. debugfs) will be
57571+ mostly accessible only by root. These filesystems generally provide access
57572+ to hardware and debug information that isn't appropriate for unprivileged
57573+ users of the system. Sysfs and debugfs have also become a large source
57574+ of new vulnerabilities, ranging from infoleaks to local compromise.
57575+ There has been very little oversight with an eye toward security involved
57576+ in adding new exporters of information to these filesystems, so their
57577+ use is discouraged.
57578+ For reasons of compatibility, a few directories have been whitelisted
57579+ for access by non-root users:
57580+ /sys/fs/selinux
57581+ /sys/fs/fuse
57582+ /sys/devices/system/cpu
57583+
57584+config GRKERNSEC_ROFS
57585+ bool "Runtime read-only mount protection"
57586+ help
57587+ If you say Y here, a sysctl option with name "romount_protect" will
57588+ be created. By setting this option to 1 at runtime, filesystems
57589+ will be protected in the following ways:
57590+ * No new writable mounts will be allowed
57591+ * Existing read-only mounts won't be able to be remounted read/write
57592+ * Write operations will be denied on all block devices
57593+ This option acts independently of grsec_lock: once it is set to 1,
57594+ it cannot be turned off. Therefore, please be mindful of the resulting
57595+ behavior if this option is enabled in an init script on a read-only
57596+ filesystem. This feature is mainly intended for secure embedded systems.
57597+
57598+config GRKERNSEC_DEVICE_SIDECHANNEL
57599+ bool "Eliminate stat/notify-based device sidechannels"
57600+ default y if GRKERNSEC_CONFIG_AUTO
57601+ help
57602+ If you say Y here, timing analyses on block or character
57603+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57604+ will be thwarted for unprivileged users. If a process without
57605+ CAP_MKNOD stats such a device, the last access and last modify times
57606+ will match the device's create time. No access or modify events
57607+ will be triggered through inotify/dnotify/fanotify for such devices.
57608+ This feature will prevent attacks that may at a minimum
57609+ allow an attacker to determine the administrator's password length.
57610+
57611+config GRKERNSEC_CHROOT
57612+ bool "Chroot jail restrictions"
57613+ default y if GRKERNSEC_CONFIG_AUTO
57614+ help
57615+ If you say Y here, you will be able to choose several options that will
57616+ make breaking out of a chrooted jail much more difficult. If you
57617+ encounter no software incompatibilities with the following options, it
57618+ is recommended that you enable each one.
57619+
57620+config GRKERNSEC_CHROOT_MOUNT
57621+ bool "Deny mounts"
57622+ default y if GRKERNSEC_CONFIG_AUTO
57623+ depends on GRKERNSEC_CHROOT
57624+ help
57625+ If you say Y here, processes inside a chroot will not be able to
57626+ mount or remount filesystems. If the sysctl option is enabled, a
57627+ sysctl option with name "chroot_deny_mount" is created.
57628+
57629+config GRKERNSEC_CHROOT_DOUBLE
57630+ bool "Deny double-chroots"
57631+ default y if GRKERNSEC_CONFIG_AUTO
57632+ depends on GRKERNSEC_CHROOT
57633+ help
57634+ If you say Y here, processes inside a chroot will not be able to chroot
57635+ again outside the chroot. This is a widely used method of breaking
57636+ out of a chroot jail and should not be allowed. If the sysctl
57637+ option is enabled, a sysctl option with name
57638+ "chroot_deny_chroot" is created.
57639+
57640+config GRKERNSEC_CHROOT_PIVOT
57641+ bool "Deny pivot_root in chroot"
57642+ default y if GRKERNSEC_CONFIG_AUTO
57643+ depends on GRKERNSEC_CHROOT
57644+ help
57645+ If you say Y here, processes inside a chroot will not be able to use
57646+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57647+ works similar to chroot in that it changes the root filesystem. This
57648+ function could be misused in a chrooted process to attempt to break out
57649+ of the chroot, and therefore should not be allowed. If the sysctl
57650+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57651+ created.
57652+
57653+config GRKERNSEC_CHROOT_CHDIR
57654+ bool "Enforce chdir(\"/\") on all chroots"
57655+ default y if GRKERNSEC_CONFIG_AUTO
57656+ depends on GRKERNSEC_CHROOT
57657+ help
57658+ If you say Y here, the current working directory of all newly-chrooted
57659+ applications will be set to the the root directory of the chroot.
57660+ The man page on chroot(2) states:
57661+ Note that this call does not change the current working
57662+ directory, so that `.' can be outside the tree rooted at
57663+ `/'. In particular, the super-user can escape from a
57664+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57665+
57666+ It is recommended that you say Y here, since it's not known to break
57667+ any software. If the sysctl option is enabled, a sysctl option with
57668+ name "chroot_enforce_chdir" is created.
57669+
57670+config GRKERNSEC_CHROOT_CHMOD
57671+ bool "Deny (f)chmod +s"
57672+ default y if GRKERNSEC_CONFIG_AUTO
57673+ depends on GRKERNSEC_CHROOT
57674+ help
57675+ If you say Y here, processes inside a chroot will not be able to chmod
57676+ or fchmod files to make them have suid or sgid bits. This protects
57677+ against another published method of breaking a chroot. If the sysctl
57678+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57679+ created.
57680+
57681+config GRKERNSEC_CHROOT_FCHDIR
57682+ bool "Deny fchdir out of chroot"
57683+ default y if GRKERNSEC_CONFIG_AUTO
57684+ depends on GRKERNSEC_CHROOT
57685+ help
57686+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57687+ to a file descriptor of the chrooting process that points to a directory
57688+ outside the filesystem will be stopped. If the sysctl option
57689+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57690+
57691+config GRKERNSEC_CHROOT_MKNOD
57692+ bool "Deny mknod"
57693+ default y if GRKERNSEC_CONFIG_AUTO
57694+ depends on GRKERNSEC_CHROOT
57695+ help
57696+ If you say Y here, processes inside a chroot will not be allowed to
57697+ mknod. The problem with using mknod inside a chroot is that it
57698+ would allow an attacker to create a device entry that is the same
57699+ as one on the physical root of your system, which could range from
57700+ anything from the console device to a device for your harddrive (which
57701+ they could then use to wipe the drive or steal data). It is recommended
57702+ that you say Y here, unless you run into software incompatibilities.
57703+ If the sysctl option is enabled, a sysctl option with name
57704+ "chroot_deny_mknod" is created.
57705+
57706+config GRKERNSEC_CHROOT_SHMAT
57707+ bool "Deny shmat() out of chroot"
57708+ default y if GRKERNSEC_CONFIG_AUTO
57709+ depends on GRKERNSEC_CHROOT
57710+ help
57711+ If you say Y here, processes inside a chroot will not be able to attach
57712+ to shared memory segments that were created outside of the chroot jail.
57713+ It is recommended that you say Y here. If the sysctl option is enabled,
57714+ a sysctl option with name "chroot_deny_shmat" is created.
57715+
57716+config GRKERNSEC_CHROOT_UNIX
57717+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57718+ default y if GRKERNSEC_CONFIG_AUTO
57719+ depends on GRKERNSEC_CHROOT
57720+ help
57721+ If you say Y here, processes inside a chroot will not be able to
57722+ connect to abstract (meaning not belonging to a filesystem) Unix
57723+ domain sockets that were bound outside of a chroot. It is recommended
57724+ that you say Y here. If the sysctl option is enabled, a sysctl option
57725+ with name "chroot_deny_unix" is created.
57726+
57727+config GRKERNSEC_CHROOT_FINDTASK
57728+ bool "Protect outside processes"
57729+ default y if GRKERNSEC_CONFIG_AUTO
57730+ depends on GRKERNSEC_CHROOT
57731+ help
57732+ If you say Y here, processes inside a chroot will not be able to
57733+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57734+ getsid, or view any process outside of the chroot. If the sysctl
57735+ option is enabled, a sysctl option with name "chroot_findtask" is
57736+ created.
57737+
57738+config GRKERNSEC_CHROOT_NICE
57739+ bool "Restrict priority changes"
57740+ default y if GRKERNSEC_CONFIG_AUTO
57741+ depends on GRKERNSEC_CHROOT
57742+ help
57743+ If you say Y here, processes inside a chroot will not be able to raise
57744+ the priority of processes in the chroot, or alter the priority of
57745+ processes outside the chroot. This provides more security than simply
57746+ removing CAP_SYS_NICE from the process' capability set. If the
57747+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57748+ is created.
57749+
57750+config GRKERNSEC_CHROOT_SYSCTL
57751+ bool "Deny sysctl writes"
57752+ default y if GRKERNSEC_CONFIG_AUTO
57753+ depends on GRKERNSEC_CHROOT
57754+ help
57755+ If you say Y here, an attacker in a chroot will not be able to
57756+ write to sysctl entries, either by sysctl(2) or through a /proc
57757+ interface. It is strongly recommended that you say Y here. If the
57758+ sysctl option is enabled, a sysctl option with name
57759+ "chroot_deny_sysctl" is created.
57760+
57761+config GRKERNSEC_CHROOT_CAPS
57762+ bool "Capability restrictions"
57763+ default y if GRKERNSEC_CONFIG_AUTO
57764+ depends on GRKERNSEC_CHROOT
57765+ help
57766+ If you say Y here, the capabilities on all processes within a
57767+ chroot jail will be lowered to stop module insertion, raw i/o,
57768+ system and net admin tasks, rebooting the system, modifying immutable
57769+ files, modifying IPC owned by another, and changing the system time.
57770+ This is left an option because it can break some apps. Disable this
57771+ if your chrooted apps are having problems performing those kinds of
57772+ tasks. If the sysctl option is enabled, a sysctl option with
57773+ name "chroot_caps" is created.
57774+
57775+config GRKERNSEC_CHROOT_INITRD
57776+ bool "Exempt initrd tasks from restrictions"
57777+ default y if GRKERNSEC_CONFIG_AUTO
57778+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57779+ help
57780+ If you say Y here, tasks started prior to init will be exempted from
57781+ grsecurity's chroot restrictions. This option is mainly meant to
57782+ resolve Plymouth's performing privileged operations unnecessarily
57783+ in a chroot.
57784+
57785+endmenu
57786+menu "Kernel Auditing"
57787+depends on GRKERNSEC
57788+
57789+config GRKERNSEC_AUDIT_GROUP
57790+ bool "Single group for auditing"
57791+ help
57792+ If you say Y here, the exec and chdir logging features will only operate
57793+ on a group you specify. This option is recommended if you only want to
57794+ watch certain users instead of having a large amount of logs from the
57795+ entire system. If the sysctl option is enabled, a sysctl option with
57796+ name "audit_group" is created.
57797+
57798+config GRKERNSEC_AUDIT_GID
57799+ int "GID for auditing"
57800+ depends on GRKERNSEC_AUDIT_GROUP
57801+ default 1007
57802+
57803+config GRKERNSEC_EXECLOG
57804+ bool "Exec logging"
57805+ help
57806+ If you say Y here, all execve() calls will be logged (since the
57807+ other exec*() calls are frontends to execve(), all execution
57808+ will be logged). Useful for shell-servers that like to keep track
57809+ of their users. If the sysctl option is enabled, a sysctl option with
57810+ name "exec_logging" is created.
57811+ WARNING: This option when enabled will produce a LOT of logs, especially
57812+ on an active system.
57813+
57814+config GRKERNSEC_RESLOG
57815+ bool "Resource logging"
57816+ default y if GRKERNSEC_CONFIG_AUTO
57817+ help
57818+ If you say Y here, all attempts to overstep resource limits will
57819+ be logged with the resource name, the requested size, and the current
57820+ limit. It is highly recommended that you say Y here. If the sysctl
57821+ option is enabled, a sysctl option with name "resource_logging" is
57822+ created. If the RBAC system is enabled, the sysctl value is ignored.
57823+
57824+config GRKERNSEC_CHROOT_EXECLOG
57825+ bool "Log execs within chroot"
57826+ help
57827+ If you say Y here, all executions inside a chroot jail will be logged
57828+ to syslog. This can cause a large amount of logs if certain
57829+ applications (eg. djb's daemontools) are installed on the system, and
57830+ is therefore left as an option. If the sysctl option is enabled, a
57831+ sysctl option with name "chroot_execlog" is created.
57832+
57833+config GRKERNSEC_AUDIT_PTRACE
57834+ bool "Ptrace logging"
57835+ help
57836+ If you say Y here, all attempts to attach to a process via ptrace
57837+ will be logged. If the sysctl option is enabled, a sysctl option
57838+ with name "audit_ptrace" is created.
57839+
57840+config GRKERNSEC_AUDIT_CHDIR
57841+ bool "Chdir logging"
57842+ help
57843+ If you say Y here, all chdir() calls will be logged. If the sysctl
57844+ option is enabled, a sysctl option with name "audit_chdir" is created.
57845+
57846+config GRKERNSEC_AUDIT_MOUNT
57847+ bool "(Un)Mount logging"
57848+ help
57849+ If you say Y here, all mounts and unmounts will be logged. If the
57850+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57851+ created.
57852+
57853+config GRKERNSEC_SIGNAL
57854+ bool "Signal logging"
57855+ default y if GRKERNSEC_CONFIG_AUTO
57856+ help
57857+ If you say Y here, certain important signals will be logged, such as
57858+ SIGSEGV, which will as a result inform you of when a error in a program
57859+ occurred, which in some cases could mean a possible exploit attempt.
57860+ If the sysctl option is enabled, a sysctl option with name
57861+ "signal_logging" is created.
57862+
57863+config GRKERNSEC_FORKFAIL
57864+ bool "Fork failure logging"
57865+ help
57866+ If you say Y here, all failed fork() attempts will be logged.
57867+ This could suggest a fork bomb, or someone attempting to overstep
57868+ their process limit. If the sysctl option is enabled, a sysctl option
57869+ with name "forkfail_logging" is created.
57870+
57871+config GRKERNSEC_TIME
57872+ bool "Time change logging"
57873+ default y if GRKERNSEC_CONFIG_AUTO
57874+ help
57875+ If you say Y here, any changes of the system clock will be logged.
57876+ If the sysctl option is enabled, a sysctl option with name
57877+ "timechange_logging" is created.
57878+
57879+config GRKERNSEC_PROC_IPADDR
57880+ bool "/proc/<pid>/ipaddr support"
57881+ default y if GRKERNSEC_CONFIG_AUTO
57882+ help
57883+ If you say Y here, a new entry will be added to each /proc/<pid>
57884+ directory that contains the IP address of the person using the task.
57885+ The IP is carried across local TCP and AF_UNIX stream sockets.
57886+ This information can be useful for IDS/IPSes to perform remote response
57887+ to a local attack. The entry is readable by only the owner of the
57888+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57889+ the RBAC system), and thus does not create privacy concerns.
57890+
57891+config GRKERNSEC_RWXMAP_LOG
57892+ bool 'Denied RWX mmap/mprotect logging'
57893+ default y if GRKERNSEC_CONFIG_AUTO
57894+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57895+ help
57896+ If you say Y here, calls to mmap() and mprotect() with explicit
57897+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57898+ denied by the PAX_MPROTECT feature. If the sysctl option is
57899+ enabled, a sysctl option with name "rwxmap_logging" is created.
57900+
57901+config GRKERNSEC_AUDIT_TEXTREL
57902+ bool 'ELF text relocations logging (READ HELP)'
57903+ depends on PAX_MPROTECT
57904+ help
57905+ If you say Y here, text relocations will be logged with the filename
57906+ of the offending library or binary. The purpose of the feature is
57907+ to help Linux distribution developers get rid of libraries and
57908+ binaries that need text relocations which hinder the future progress
57909+ of PaX. Only Linux distribution developers should say Y here, and
57910+ never on a production machine, as this option creates an information
57911+ leak that could aid an attacker in defeating the randomization of
57912+ a single memory region. If the sysctl option is enabled, a sysctl
57913+ option with name "audit_textrel" is created.
57914+
57915+endmenu
57916+
57917+menu "Executable Protections"
57918+depends on GRKERNSEC
57919+
57920+config GRKERNSEC_DMESG
57921+ bool "Dmesg(8) restriction"
57922+ default y if GRKERNSEC_CONFIG_AUTO
57923+ help
57924+ If you say Y here, non-root users will not be able to use dmesg(8)
57925+ to view the contents of the kernel's circular log buffer.
57926+ The kernel's log buffer often contains kernel addresses and other
57927+ identifying information useful to an attacker in fingerprinting a
57928+ system for a targeted exploit.
57929+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57930+ created.
57931+
57932+config GRKERNSEC_HARDEN_PTRACE
57933+ bool "Deter ptrace-based process snooping"
57934+ default y if GRKERNSEC_CONFIG_AUTO
57935+ help
57936+ If you say Y here, TTY sniffers and other malicious monitoring
57937+ programs implemented through ptrace will be defeated. If you
57938+ have been using the RBAC system, this option has already been
57939+ enabled for several years for all users, with the ability to make
57940+ fine-grained exceptions.
57941+
57942+ This option only affects the ability of non-root users to ptrace
57943+ processes that are not a descendent of the ptracing process.
57944+ This means that strace ./binary and gdb ./binary will still work,
57945+ but attaching to arbitrary processes will not. If the sysctl
57946+ option is enabled, a sysctl option with name "harden_ptrace" is
57947+ created.
57948+
57949+config GRKERNSEC_PTRACE_READEXEC
57950+ bool "Require read access to ptrace sensitive binaries"
57951+ default y if GRKERNSEC_CONFIG_AUTO
57952+ help
57953+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57954+ binaries. This option is useful in environments that
57955+ remove the read bits (e.g. file mode 4711) from suid binaries to
57956+ prevent infoleaking of their contents. This option adds
57957+ consistency to the use of that file mode, as the binary could normally
57958+ be read out when run without privileges while ptracing.
57959+
57960+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57961+ is created.
57962+
57963+config GRKERNSEC_SETXID
57964+ bool "Enforce consistent multithreaded privileges"
57965+ default y if GRKERNSEC_CONFIG_AUTO
57966+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57967+ help
57968+ If you say Y here, a change from a root uid to a non-root uid
57969+ in a multithreaded application will cause the resulting uids,
57970+ gids, supplementary groups, and capabilities in that thread
57971+ to be propagated to the other threads of the process. In most
57972+ cases this is unnecessary, as glibc will emulate this behavior
57973+ on behalf of the application. Other libcs do not act in the
57974+ same way, allowing the other threads of the process to continue
57975+ running with root privileges. If the sysctl option is enabled,
57976+ a sysctl option with name "consistent_setxid" is created.
57977+
57978+config GRKERNSEC_TPE
57979+ bool "Trusted Path Execution (TPE)"
57980+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57981+ help
57982+ If you say Y here, you will be able to choose a gid to add to the
57983+ supplementary groups of users you want to mark as "untrusted."
57984+ These users will not be able to execute any files that are not in
57985+ root-owned directories writable only by root. If the sysctl option
57986+ is enabled, a sysctl option with name "tpe" is created.
57987+
57988+config GRKERNSEC_TPE_ALL
57989+ bool "Partially restrict all non-root users"
57990+ depends on GRKERNSEC_TPE
57991+ help
57992+ If you say Y here, all non-root users will be covered under
57993+ a weaker TPE restriction. This is separate from, and in addition to,
57994+ the main TPE options that you have selected elsewhere. Thus, if a
57995+ "trusted" GID is chosen, this restriction applies to even that GID.
57996+ Under this restriction, all non-root users will only be allowed to
57997+ execute files in directories they own that are not group or
57998+ world-writable, or in directories owned by root and writable only by
57999+ root. If the sysctl option is enabled, a sysctl option with name
58000+ "tpe_restrict_all" is created.
58001+
58002+config GRKERNSEC_TPE_INVERT
58003+ bool "Invert GID option"
58004+ depends on GRKERNSEC_TPE
58005+ help
58006+ If you say Y here, the group you specify in the TPE configuration will
58007+ decide what group TPE restrictions will be *disabled* for. This
58008+ option is useful if you want TPE restrictions to be applied to most
58009+ users on the system. If the sysctl option is enabled, a sysctl option
58010+ with name "tpe_invert" is created. Unlike other sysctl options, this
58011+ entry will default to on for backward-compatibility.
58012+
58013+config GRKERNSEC_TPE_GID
58014+ int
58015+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
58016+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
58017+
58018+config GRKERNSEC_TPE_UNTRUSTED_GID
58019+ int "GID for TPE-untrusted users"
58020+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
58021+ default 1005
58022+ help
58023+ Setting this GID determines what group TPE restrictions will be
58024+ *enabled* for. If the sysctl option is enabled, a sysctl option
58025+ with name "tpe_gid" is created.
58026+
58027+config GRKERNSEC_TPE_TRUSTED_GID
58028+ int "GID for TPE-trusted users"
58029+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
58030+ default 1005
58031+ help
58032+ Setting this GID determines what group TPE restrictions will be
58033+ *disabled* for. If the sysctl option is enabled, a sysctl option
58034+ with name "tpe_gid" is created.
58035+
58036+endmenu
58037+menu "Network Protections"
58038+depends on GRKERNSEC
58039+
58040+config GRKERNSEC_RANDNET
58041+ bool "Larger entropy pools"
58042+ default y if GRKERNSEC_CONFIG_AUTO
58043+ help
58044+ If you say Y here, the entropy pools used for many features of Linux
58045+ and grsecurity will be doubled in size. Since several grsecurity
58046+ features use additional randomness, it is recommended that you say Y
58047+ here. Saying Y here has a similar effect as modifying
58048+ /proc/sys/kernel/random/poolsize.
58049+
58050+config GRKERNSEC_BLACKHOLE
58051+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
58052+ default y if GRKERNSEC_CONFIG_AUTO
58053+ depends on NET
58054+ help
58055+ If you say Y here, neither TCP resets nor ICMP
58056+ destination-unreachable packets will be sent in response to packets
58057+ sent to ports for which no associated listening process exists.
58058+ This feature supports both IPV4 and IPV6 and exempts the
58059+ loopback interface from blackholing. Enabling this feature
58060+ makes a host more resilient to DoS attacks and reduces network
58061+ visibility against scanners.
58062+
58063+ The blackhole feature as-implemented is equivalent to the FreeBSD
58064+ blackhole feature, as it prevents RST responses to all packets, not
58065+ just SYNs. Under most application behavior this causes no
58066+ problems, but applications (like haproxy) may not close certain
58067+ connections in a way that cleanly terminates them on the remote
58068+ end, leaving the remote host in LAST_ACK state. Because of this
58069+ side-effect and to prevent intentional LAST_ACK DoSes, this
58070+ feature also adds automatic mitigation against such attacks.
58071+ The mitigation drastically reduces the amount of time a socket
58072+ can spend in LAST_ACK state. If you're using haproxy and not
58073+ all servers it connects to have this option enabled, consider
58074+ disabling this feature on the haproxy host.
58075+
58076+ If the sysctl option is enabled, two sysctl options with names
58077+ "ip_blackhole" and "lastack_retries" will be created.
58078+ While "ip_blackhole" takes the standard zero/non-zero on/off
58079+ toggle, "lastack_retries" uses the same kinds of values as
58080+ "tcp_retries1" and "tcp_retries2". The default value of 4
58081+ prevents a socket from lasting more than 45 seconds in LAST_ACK
58082+ state.
58083+
58084+config GRKERNSEC_NO_SIMULT_CONNECT
58085+ bool "Disable TCP Simultaneous Connect"
58086+ default y if GRKERNSEC_CONFIG_AUTO
58087+ depends on NET
58088+ help
58089+ If you say Y here, a feature by Willy Tarreau will be enabled that
58090+ removes a weakness in Linux's strict implementation of TCP that
58091+ allows two clients to connect to each other without either entering
58092+ a listening state. The weakness allows an attacker to easily prevent
58093+ a client from connecting to a known server provided the source port
58094+ for the connection is guessed correctly.
58095+
58096+ As the weakness could be used to prevent an antivirus or IPS from
58097+ fetching updates, or prevent an SSL gateway from fetching a CRL,
58098+ it should be eliminated by enabling this option. Though Linux is
58099+ one of few operating systems supporting simultaneous connect, it
58100+ has no legitimate use in practice and is rarely supported by firewalls.
58101+
58102+config GRKERNSEC_SOCKET
58103+ bool "Socket restrictions"
58104+ depends on NET
58105+ help
58106+ If you say Y here, you will be able to choose from several options.
58107+ If you assign a GID on your system and add it to the supplementary
58108+ groups of users you want to restrict socket access to, this patch
58109+ will perform up to three things, based on the option(s) you choose.
58110+
58111+config GRKERNSEC_SOCKET_ALL
58112+ bool "Deny any sockets to group"
58113+ depends on GRKERNSEC_SOCKET
58114+ help
58115+ If you say Y here, you will be able to choose a GID of whose users will
58116+ be unable to connect to other hosts from your machine or run server
58117+ applications from your machine. If the sysctl option is enabled, a
58118+ sysctl option with name "socket_all" is created.
58119+
58120+config GRKERNSEC_SOCKET_ALL_GID
58121+ int "GID to deny all sockets for"
58122+ depends on GRKERNSEC_SOCKET_ALL
58123+ default 1004
58124+ help
58125+ Here you can choose the GID to disable socket access for. Remember to
58126+ add the users you want socket access disabled for to the GID
58127+ specified here. If the sysctl option is enabled, a sysctl option
58128+ with name "socket_all_gid" is created.
58129+
58130+config GRKERNSEC_SOCKET_CLIENT
58131+ bool "Deny client sockets to group"
58132+ depends on GRKERNSEC_SOCKET
58133+ help
58134+ If you say Y here, you will be able to choose a GID of whose users will
58135+ be unable to connect to other hosts from your machine, but will be
58136+ able to run servers. If this option is enabled, all users in the group
58137+ you specify will have to use passive mode when initiating ftp transfers
58138+ from the shell on your machine. If the sysctl option is enabled, a
58139+ sysctl option with name "socket_client" is created.
58140+
58141+config GRKERNSEC_SOCKET_CLIENT_GID
58142+ int "GID to deny client sockets for"
58143+ depends on GRKERNSEC_SOCKET_CLIENT
58144+ default 1003
58145+ help
58146+ Here you can choose the GID to disable client socket access for.
58147+ Remember to add the users you want client socket access disabled for to
58148+ the GID specified here. If the sysctl option is enabled, a sysctl
58149+ option with name "socket_client_gid" is created.
58150+
58151+config GRKERNSEC_SOCKET_SERVER
58152+ bool "Deny server sockets to group"
58153+ depends on GRKERNSEC_SOCKET
58154+ help
58155+ If you say Y here, you will be able to choose a GID of whose users will
58156+ be unable to run server applications from your machine. If the sysctl
58157+ option is enabled, a sysctl option with name "socket_server" is created.
58158+
58159+config GRKERNSEC_SOCKET_SERVER_GID
58160+ int "GID to deny server sockets for"
58161+ depends on GRKERNSEC_SOCKET_SERVER
58162+ default 1002
58163+ help
58164+ Here you can choose the GID to disable server socket access for.
58165+ Remember to add the users you want server socket access disabled for to
58166+ the GID specified here. If the sysctl option is enabled, a sysctl
58167+ option with name "socket_server_gid" is created.
58168+
58169+endmenu
58170+menu "Sysctl Support"
58171+depends on GRKERNSEC && SYSCTL
58172+
58173+config GRKERNSEC_SYSCTL
58174+ bool "Sysctl support"
58175+ default y if GRKERNSEC_CONFIG_AUTO
58176+ help
58177+ If you say Y here, you will be able to change the options that
58178+ grsecurity runs with at bootup, without having to recompile your
58179+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58180+ to enable (1) or disable (0) various features. All the sysctl entries
58181+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58182+ All features enabled in the kernel configuration are disabled at boot
58183+ if you do not say Y to the "Turn on features by default" option.
58184+ All options should be set at startup, and the grsec_lock entry should
58185+ be set to a non-zero value after all the options are set.
58186+ *THIS IS EXTREMELY IMPORTANT*
58187+
58188+config GRKERNSEC_SYSCTL_DISTRO
58189+ bool "Extra sysctl support for distro makers (READ HELP)"
58190+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58191+ help
58192+ If you say Y here, additional sysctl options will be created
58193+ for features that affect processes running as root. Therefore,
58194+ it is critical when using this option that the grsec_lock entry be
58195+ enabled after boot. Only distros with prebuilt kernel packages
58196+ with this option enabled that can ensure grsec_lock is enabled
58197+ after boot should use this option.
58198+ *Failure to set grsec_lock after boot makes all grsec features
58199+ this option covers useless*
58200+
58201+ Currently this option creates the following sysctl entries:
58202+ "Disable Privileged I/O": "disable_priv_io"
58203+
58204+config GRKERNSEC_SYSCTL_ON
58205+ bool "Turn on features by default"
58206+ default y if GRKERNSEC_CONFIG_AUTO
58207+ depends on GRKERNSEC_SYSCTL
58208+ help
58209+ If you say Y here, instead of having all features enabled in the
58210+ kernel configuration disabled at boot time, the features will be
58211+ enabled at boot time. It is recommended you say Y here unless
58212+ there is some reason you would want all sysctl-tunable features to
58213+ be disabled by default. As mentioned elsewhere, it is important
58214+ to enable the grsec_lock entry once you have finished modifying
58215+ the sysctl entries.
58216+
58217+endmenu
58218+menu "Logging Options"
58219+depends on GRKERNSEC
58220+
58221+config GRKERNSEC_FLOODTIME
58222+ int "Seconds in between log messages (minimum)"
58223+ default 10
58224+ help
58225+ This option allows you to enforce the number of seconds between
58226+ grsecurity log messages. The default should be suitable for most
58227+ people, however, if you choose to change it, choose a value small enough
58228+ to allow informative logs to be produced, but large enough to
58229+ prevent flooding.
58230+
58231+config GRKERNSEC_FLOODBURST
58232+ int "Number of messages in a burst (maximum)"
58233+ default 6
58234+ help
58235+ This option allows you to choose the maximum number of messages allowed
58236+ within the flood time interval you chose in a separate option. The
58237+ default should be suitable for most people, however if you find that
58238+ many of your logs are being interpreted as flooding, you may want to
58239+ raise this value.
58240+
58241+endmenu
58242diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58243new file mode 100644
58244index 0000000..1b9afa9
58245--- /dev/null
58246+++ b/grsecurity/Makefile
58247@@ -0,0 +1,38 @@
58248+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58249+# during 2001-2009 it has been completely redesigned by Brad Spengler
58250+# into an RBAC system
58251+#
58252+# All code in this directory and various hooks inserted throughout the kernel
58253+# are copyright Brad Spengler - Open Source Security, Inc., and released
58254+# under the GPL v2 or higher
58255+
58256+KBUILD_CFLAGS += -Werror
58257+
58258+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58259+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58260+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58261+
58262+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58263+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58264+ gracl_learn.o grsec_log.o
58265+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58266+
58267+ifdef CONFIG_NET
58268+obj-y += grsec_sock.o
58269+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58270+endif
58271+
58272+ifndef CONFIG_GRKERNSEC
58273+obj-y += grsec_disabled.o
58274+endif
58275+
58276+ifdef CONFIG_GRKERNSEC_HIDESYM
58277+extra-y := grsec_hidesym.o
58278+$(obj)/grsec_hidesym.o:
58279+ @-chmod -f 500 /boot
58280+ @-chmod -f 500 /lib/modules
58281+ @-chmod -f 500 /lib64/modules
58282+ @-chmod -f 500 /lib32/modules
58283+ @-chmod -f 700 .
58284+ @echo ' grsec: protected kernel image paths'
58285+endif
58286diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58287new file mode 100644
58288index 0000000..0d5c602
58289--- /dev/null
58290+++ b/grsecurity/gracl.c
58291@@ -0,0 +1,4073 @@
58292+#include <linux/kernel.h>
58293+#include <linux/module.h>
58294+#include <linux/sched.h>
58295+#include <linux/mm.h>
58296+#include <linux/file.h>
58297+#include <linux/fs.h>
58298+#include <linux/namei.h>
58299+#include <linux/mount.h>
58300+#include <linux/tty.h>
58301+#include <linux/proc_fs.h>
58302+#include <linux/lglock.h>
58303+#include <linux/slab.h>
58304+#include <linux/vmalloc.h>
58305+#include <linux/types.h>
58306+#include <linux/sysctl.h>
58307+#include <linux/netdevice.h>
58308+#include <linux/ptrace.h>
58309+#include <linux/gracl.h>
58310+#include <linux/gralloc.h>
58311+#include <linux/security.h>
58312+#include <linux/grinternal.h>
58313+#include <linux/pid_namespace.h>
58314+#include <linux/stop_machine.h>
58315+#include <linux/fdtable.h>
58316+#include <linux/percpu.h>
58317+#include <linux/lglock.h>
58318+#include <linux/hugetlb.h>
58319+#include <linux/posix-timers.h>
58320+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58321+#include <linux/magic.h>
58322+#include <linux/pagemap.h>
58323+#include "../fs/btrfs/async-thread.h"
58324+#include "../fs/btrfs/ctree.h"
58325+#include "../fs/btrfs/btrfs_inode.h"
58326+#endif
58327+#include "../fs/mount.h"
58328+
58329+#include <asm/uaccess.h>
58330+#include <asm/errno.h>
58331+#include <asm/mman.h>
58332+
58333+extern struct lglock vfsmount_lock;
58334+
58335+static struct acl_role_db acl_role_set;
58336+static struct name_db name_set;
58337+static struct inodev_db inodev_set;
58338+
58339+/* for keeping track of userspace pointers used for subjects, so we
58340+ can share references in the kernel as well
58341+*/
58342+
58343+static struct path real_root;
58344+
58345+static struct acl_subj_map_db subj_map_set;
58346+
58347+static struct acl_role_label *default_role;
58348+
58349+static struct acl_role_label *role_list;
58350+
58351+static u16 acl_sp_role_value;
58352+
58353+extern char *gr_shared_page[4];
58354+static DEFINE_MUTEX(gr_dev_mutex);
58355+DEFINE_RWLOCK(gr_inode_lock);
58356+
58357+struct gr_arg *gr_usermode;
58358+
58359+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58360+
58361+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58362+extern void gr_clear_learn_entries(void);
58363+
58364+unsigned char *gr_system_salt;
58365+unsigned char *gr_system_sum;
58366+
58367+static struct sprole_pw **acl_special_roles = NULL;
58368+static __u16 num_sprole_pws = 0;
58369+
58370+static struct acl_role_label *kernel_role = NULL;
58371+
58372+static unsigned int gr_auth_attempts = 0;
58373+static unsigned long gr_auth_expires = 0UL;
58374+
58375+#ifdef CONFIG_NET
58376+extern struct vfsmount *sock_mnt;
58377+#endif
58378+
58379+extern struct vfsmount *pipe_mnt;
58380+extern struct vfsmount *shm_mnt;
58381+
58382+#ifdef CONFIG_HUGETLBFS
58383+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58384+#endif
58385+
58386+static struct acl_object_label *fakefs_obj_rw;
58387+static struct acl_object_label *fakefs_obj_rwx;
58388+
58389+extern int gr_init_uidset(void);
58390+extern void gr_free_uidset(void);
58391+extern void gr_remove_uid(uid_t uid);
58392+extern int gr_find_uid(uid_t uid);
58393+
58394+__inline__ int
58395+gr_acl_is_enabled(void)
58396+{
58397+ return (gr_status & GR_READY);
58398+}
58399+
58400+static inline dev_t __get_dev(const struct dentry *dentry)
58401+{
58402+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58403+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
58404+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
58405+ else
58406+#endif
58407+ return dentry->d_sb->s_dev;
58408+}
58409+
58410+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58411+{
58412+ return __get_dev(dentry);
58413+}
58414+
58415+static char gr_task_roletype_to_char(struct task_struct *task)
58416+{
58417+ switch (task->role->roletype &
58418+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58419+ GR_ROLE_SPECIAL)) {
58420+ case GR_ROLE_DEFAULT:
58421+ return 'D';
58422+ case GR_ROLE_USER:
58423+ return 'U';
58424+ case GR_ROLE_GROUP:
58425+ return 'G';
58426+ case GR_ROLE_SPECIAL:
58427+ return 'S';
58428+ }
58429+
58430+ return 'X';
58431+}
58432+
58433+char gr_roletype_to_char(void)
58434+{
58435+ return gr_task_roletype_to_char(current);
58436+}
58437+
58438+__inline__ int
58439+gr_acl_tpe_check(void)
58440+{
58441+ if (unlikely(!(gr_status & GR_READY)))
58442+ return 0;
58443+ if (current->role->roletype & GR_ROLE_TPE)
58444+ return 1;
58445+ else
58446+ return 0;
58447+}
58448+
58449+int
58450+gr_handle_rawio(const struct inode *inode)
58451+{
58452+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58453+ if (inode && S_ISBLK(inode->i_mode) &&
58454+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58455+ !capable(CAP_SYS_RAWIO))
58456+ return 1;
58457+#endif
58458+ return 0;
58459+}
58460+
58461+static int
58462+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58463+{
58464+ if (likely(lena != lenb))
58465+ return 0;
58466+
58467+ return !memcmp(a, b, lena);
58468+}
58469+
58470+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58471+{
58472+ *buflen -= namelen;
58473+ if (*buflen < 0)
58474+ return -ENAMETOOLONG;
58475+ *buffer -= namelen;
58476+ memcpy(*buffer, str, namelen);
58477+ return 0;
58478+}
58479+
58480+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58481+{
58482+ return prepend(buffer, buflen, name->name, name->len);
58483+}
58484+
58485+static int prepend_path(const struct path *path, struct path *root,
58486+ char **buffer, int *buflen)
58487+{
58488+ struct dentry *dentry = path->dentry;
58489+ struct vfsmount *vfsmnt = path->mnt;
58490+ struct mount *mnt = real_mount(vfsmnt);
58491+ bool slash = false;
58492+ int error = 0;
58493+
58494+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58495+ struct dentry * parent;
58496+
58497+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58498+ /* Global root? */
58499+ if (!mnt_has_parent(mnt)) {
58500+ goto out;
58501+ }
58502+ dentry = mnt->mnt_mountpoint;
58503+ mnt = mnt->mnt_parent;
58504+ vfsmnt = &mnt->mnt;
58505+ continue;
58506+ }
58507+ parent = dentry->d_parent;
58508+ prefetch(parent);
58509+ spin_lock(&dentry->d_lock);
58510+ error = prepend_name(buffer, buflen, &dentry->d_name);
58511+ spin_unlock(&dentry->d_lock);
58512+ if (!error)
58513+ error = prepend(buffer, buflen, "/", 1);
58514+ if (error)
58515+ break;
58516+
58517+ slash = true;
58518+ dentry = parent;
58519+ }
58520+
58521+out:
58522+ if (!error && !slash)
58523+ error = prepend(buffer, buflen, "/", 1);
58524+
58525+ return error;
58526+}
58527+
58528+/* this must be called with vfsmount_lock and rename_lock held */
58529+
58530+static char *__our_d_path(const struct path *path, struct path *root,
58531+ char *buf, int buflen)
58532+{
58533+ char *res = buf + buflen;
58534+ int error;
58535+
58536+ prepend(&res, &buflen, "\0", 1);
58537+ error = prepend_path(path, root, &res, &buflen);
58538+ if (error)
58539+ return ERR_PTR(error);
58540+
58541+ return res;
58542+}
58543+
58544+static char *
58545+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58546+{
58547+ char *retval;
58548+
58549+ retval = __our_d_path(path, root, buf, buflen);
58550+ if (unlikely(IS_ERR(retval)))
58551+ retval = strcpy(buf, "<path too long>");
58552+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58553+ retval[1] = '\0';
58554+
58555+ return retval;
58556+}
58557+
58558+static char *
58559+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58560+ char *buf, int buflen)
58561+{
58562+ struct path path;
58563+ char *res;
58564+
58565+ path.dentry = (struct dentry *)dentry;
58566+ path.mnt = (struct vfsmount *)vfsmnt;
58567+
58568+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58569+ by the RBAC system */
58570+ res = gen_full_path(&path, &real_root, buf, buflen);
58571+
58572+ return res;
58573+}
58574+
58575+static char *
58576+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58577+ char *buf, int buflen)
58578+{
58579+ char *res;
58580+ struct path path;
58581+ struct path root;
58582+ struct task_struct *reaper = init_pid_ns.child_reaper;
58583+
58584+ path.dentry = (struct dentry *)dentry;
58585+ path.mnt = (struct vfsmount *)vfsmnt;
58586+
58587+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58588+ get_fs_root(reaper->fs, &root);
58589+
58590+ br_read_lock(&vfsmount_lock);
58591+ write_seqlock(&rename_lock);
58592+ res = gen_full_path(&path, &root, buf, buflen);
58593+ write_sequnlock(&rename_lock);
58594+ br_read_unlock(&vfsmount_lock);
58595+
58596+ path_put(&root);
58597+ return res;
58598+}
58599+
58600+static char *
58601+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58602+{
58603+ char *ret;
58604+ br_read_lock(&vfsmount_lock);
58605+ write_seqlock(&rename_lock);
58606+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58607+ PAGE_SIZE);
58608+ write_sequnlock(&rename_lock);
58609+ br_read_unlock(&vfsmount_lock);
58610+ return ret;
58611+}
58612+
58613+static char *
58614+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58615+{
58616+ char *ret;
58617+ char *buf;
58618+ int buflen;
58619+
58620+ br_read_lock(&vfsmount_lock);
58621+ write_seqlock(&rename_lock);
58622+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58623+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58624+ buflen = (int)(ret - buf);
58625+ if (buflen >= 5)
58626+ prepend(&ret, &buflen, "/proc", 5);
58627+ else
58628+ ret = strcpy(buf, "<path too long>");
58629+ write_sequnlock(&rename_lock);
58630+ br_read_unlock(&vfsmount_lock);
58631+ return ret;
58632+}
58633+
58634+char *
58635+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58636+{
58637+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58638+ PAGE_SIZE);
58639+}
58640+
58641+char *
58642+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58643+{
58644+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58645+ PAGE_SIZE);
58646+}
58647+
58648+char *
58649+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58650+{
58651+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58652+ PAGE_SIZE);
58653+}
58654+
58655+char *
58656+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58657+{
58658+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58659+ PAGE_SIZE);
58660+}
58661+
58662+char *
58663+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58664+{
58665+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58666+ PAGE_SIZE);
58667+}
58668+
58669+__inline__ __u32
58670+to_gr_audit(const __u32 reqmode)
58671+{
58672+ /* masks off auditable permission flags, then shifts them to create
58673+ auditing flags, and adds the special case of append auditing if
58674+ we're requesting write */
58675+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58676+}
58677+
58678+struct acl_subject_label *
58679+lookup_subject_map(const struct acl_subject_label *userp)
58680+{
58681+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58682+ struct subject_map *match;
58683+
58684+ match = subj_map_set.s_hash[index];
58685+
58686+ while (match && match->user != userp)
58687+ match = match->next;
58688+
58689+ if (match != NULL)
58690+ return match->kernel;
58691+ else
58692+ return NULL;
58693+}
58694+
58695+static void
58696+insert_subj_map_entry(struct subject_map *subjmap)
58697+{
58698+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58699+ struct subject_map **curr;
58700+
58701+ subjmap->prev = NULL;
58702+
58703+ curr = &subj_map_set.s_hash[index];
58704+ if (*curr != NULL)
58705+ (*curr)->prev = subjmap;
58706+
58707+ subjmap->next = *curr;
58708+ *curr = subjmap;
58709+
58710+ return;
58711+}
58712+
58713+static struct acl_role_label *
58714+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58715+ const gid_t gid)
58716+{
58717+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58718+ struct acl_role_label *match;
58719+ struct role_allowed_ip *ipp;
58720+ unsigned int x;
58721+ u32 curr_ip = task->signal->curr_ip;
58722+
58723+ task->signal->saved_ip = curr_ip;
58724+
58725+ match = acl_role_set.r_hash[index];
58726+
58727+ while (match) {
58728+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58729+ for (x = 0; x < match->domain_child_num; x++) {
58730+ if (match->domain_children[x] == uid)
58731+ goto found;
58732+ }
58733+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58734+ break;
58735+ match = match->next;
58736+ }
58737+found:
58738+ if (match == NULL) {
58739+ try_group:
58740+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58741+ match = acl_role_set.r_hash[index];
58742+
58743+ while (match) {
58744+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58745+ for (x = 0; x < match->domain_child_num; x++) {
58746+ if (match->domain_children[x] == gid)
58747+ goto found2;
58748+ }
58749+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58750+ break;
58751+ match = match->next;
58752+ }
58753+found2:
58754+ if (match == NULL)
58755+ match = default_role;
58756+ if (match->allowed_ips == NULL)
58757+ return match;
58758+ else {
58759+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58760+ if (likely
58761+ ((ntohl(curr_ip) & ipp->netmask) ==
58762+ (ntohl(ipp->addr) & ipp->netmask)))
58763+ return match;
58764+ }
58765+ match = default_role;
58766+ }
58767+ } else if (match->allowed_ips == NULL) {
58768+ return match;
58769+ } else {
58770+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58771+ if (likely
58772+ ((ntohl(curr_ip) & ipp->netmask) ==
58773+ (ntohl(ipp->addr) & ipp->netmask)))
58774+ return match;
58775+ }
58776+ goto try_group;
58777+ }
58778+
58779+ return match;
58780+}
58781+
58782+struct acl_subject_label *
58783+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58784+ const struct acl_role_label *role)
58785+{
58786+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58787+ struct acl_subject_label *match;
58788+
58789+ match = role->subj_hash[index];
58790+
58791+ while (match && (match->inode != ino || match->device != dev ||
58792+ (match->mode & GR_DELETED))) {
58793+ match = match->next;
58794+ }
58795+
58796+ if (match && !(match->mode & GR_DELETED))
58797+ return match;
58798+ else
58799+ return NULL;
58800+}
58801+
58802+struct acl_subject_label *
58803+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58804+ const struct acl_role_label *role)
58805+{
58806+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58807+ struct acl_subject_label *match;
58808+
58809+ match = role->subj_hash[index];
58810+
58811+ while (match && (match->inode != ino || match->device != dev ||
58812+ !(match->mode & GR_DELETED))) {
58813+ match = match->next;
58814+ }
58815+
58816+ if (match && (match->mode & GR_DELETED))
58817+ return match;
58818+ else
58819+ return NULL;
58820+}
58821+
58822+static struct acl_object_label *
58823+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58824+ const struct acl_subject_label *subj)
58825+{
58826+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58827+ struct acl_object_label *match;
58828+
58829+ match = subj->obj_hash[index];
58830+
58831+ while (match && (match->inode != ino || match->device != dev ||
58832+ (match->mode & GR_DELETED))) {
58833+ match = match->next;
58834+ }
58835+
58836+ if (match && !(match->mode & GR_DELETED))
58837+ return match;
58838+ else
58839+ return NULL;
58840+}
58841+
58842+static struct acl_object_label *
58843+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58844+ const struct acl_subject_label *subj)
58845+{
58846+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58847+ struct acl_object_label *match;
58848+
58849+ match = subj->obj_hash[index];
58850+
58851+ while (match && (match->inode != ino || match->device != dev ||
58852+ !(match->mode & GR_DELETED))) {
58853+ match = match->next;
58854+ }
58855+
58856+ if (match && (match->mode & GR_DELETED))
58857+ return match;
58858+
58859+ match = subj->obj_hash[index];
58860+
58861+ while (match && (match->inode != ino || match->device != dev ||
58862+ (match->mode & GR_DELETED))) {
58863+ match = match->next;
58864+ }
58865+
58866+ if (match && !(match->mode & GR_DELETED))
58867+ return match;
58868+ else
58869+ return NULL;
58870+}
58871+
58872+static struct name_entry *
58873+lookup_name_entry(const char *name)
58874+{
58875+ unsigned int len = strlen(name);
58876+ unsigned int key = full_name_hash(name, len);
58877+ unsigned int index = key % name_set.n_size;
58878+ struct name_entry *match;
58879+
58880+ match = name_set.n_hash[index];
58881+
58882+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58883+ match = match->next;
58884+
58885+ return match;
58886+}
58887+
58888+static struct name_entry *
58889+lookup_name_entry_create(const char *name)
58890+{
58891+ unsigned int len = strlen(name);
58892+ unsigned int key = full_name_hash(name, len);
58893+ unsigned int index = key % name_set.n_size;
58894+ struct name_entry *match;
58895+
58896+ match = name_set.n_hash[index];
58897+
58898+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58899+ !match->deleted))
58900+ match = match->next;
58901+
58902+ if (match && match->deleted)
58903+ return match;
58904+
58905+ match = name_set.n_hash[index];
58906+
58907+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58908+ match->deleted))
58909+ match = match->next;
58910+
58911+ if (match && !match->deleted)
58912+ return match;
58913+ else
58914+ return NULL;
58915+}
58916+
58917+static struct inodev_entry *
58918+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58919+{
58920+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58921+ struct inodev_entry *match;
58922+
58923+ match = inodev_set.i_hash[index];
58924+
58925+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58926+ match = match->next;
58927+
58928+ return match;
58929+}
58930+
58931+static void
58932+insert_inodev_entry(struct inodev_entry *entry)
58933+{
58934+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58935+ inodev_set.i_size);
58936+ struct inodev_entry **curr;
58937+
58938+ entry->prev = NULL;
58939+
58940+ curr = &inodev_set.i_hash[index];
58941+ if (*curr != NULL)
58942+ (*curr)->prev = entry;
58943+
58944+ entry->next = *curr;
58945+ *curr = entry;
58946+
58947+ return;
58948+}
58949+
58950+static void
58951+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58952+{
58953+ unsigned int index =
58954+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58955+ struct acl_role_label **curr;
58956+ struct acl_role_label *tmp, *tmp2;
58957+
58958+ curr = &acl_role_set.r_hash[index];
58959+
58960+ /* simple case, slot is empty, just set it to our role */
58961+ if (*curr == NULL) {
58962+ *curr = role;
58963+ } else {
58964+ /* example:
58965+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58966+ 2 -> 3
58967+ */
58968+ /* first check to see if we can already be reached via this slot */
58969+ tmp = *curr;
58970+ while (tmp && tmp != role)
58971+ tmp = tmp->next;
58972+ if (tmp == role) {
58973+ /* we don't need to add ourselves to this slot's chain */
58974+ return;
58975+ }
58976+ /* we need to add ourselves to this chain, two cases */
58977+ if (role->next == NULL) {
58978+ /* simple case, append the current chain to our role */
58979+ role->next = *curr;
58980+ *curr = role;
58981+ } else {
58982+ /* 1 -> 2 -> 3 -> 4
58983+ 2 -> 3 -> 4
58984+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58985+ */
58986+ /* trickier case: walk our role's chain until we find
58987+ the role for the start of the current slot's chain */
58988+ tmp = role;
58989+ tmp2 = *curr;
58990+ while (tmp->next && tmp->next != tmp2)
58991+ tmp = tmp->next;
58992+ if (tmp->next == tmp2) {
58993+ /* from example above, we found 3, so just
58994+ replace this slot's chain with ours */
58995+ *curr = role;
58996+ } else {
58997+ /* we didn't find a subset of our role's chain
58998+ in the current slot's chain, so append their
58999+ chain to ours, and set us as the first role in
59000+ the slot's chain
59001+
59002+ we could fold this case with the case above,
59003+ but making it explicit for clarity
59004+ */
59005+ tmp->next = tmp2;
59006+ *curr = role;
59007+ }
59008+ }
59009+ }
59010+
59011+ return;
59012+}
59013+
59014+static void
59015+insert_acl_role_label(struct acl_role_label *role)
59016+{
59017+ int i;
59018+
59019+ if (role_list == NULL) {
59020+ role_list = role;
59021+ role->prev = NULL;
59022+ } else {
59023+ role->prev = role_list;
59024+ role_list = role;
59025+ }
59026+
59027+ /* used for hash chains */
59028+ role->next = NULL;
59029+
59030+ if (role->roletype & GR_ROLE_DOMAIN) {
59031+ for (i = 0; i < role->domain_child_num; i++)
59032+ __insert_acl_role_label(role, role->domain_children[i]);
59033+ } else
59034+ __insert_acl_role_label(role, role->uidgid);
59035+}
59036+
59037+static int
59038+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
59039+{
59040+ struct name_entry **curr, *nentry;
59041+ struct inodev_entry *ientry;
59042+ unsigned int len = strlen(name);
59043+ unsigned int key = full_name_hash(name, len);
59044+ unsigned int index = key % name_set.n_size;
59045+
59046+ curr = &name_set.n_hash[index];
59047+
59048+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
59049+ curr = &((*curr)->next);
59050+
59051+ if (*curr != NULL)
59052+ return 1;
59053+
59054+ nentry = acl_alloc(sizeof (struct name_entry));
59055+ if (nentry == NULL)
59056+ return 0;
59057+ ientry = acl_alloc(sizeof (struct inodev_entry));
59058+ if (ientry == NULL)
59059+ return 0;
59060+ ientry->nentry = nentry;
59061+
59062+ nentry->key = key;
59063+ nentry->name = name;
59064+ nentry->inode = inode;
59065+ nentry->device = device;
59066+ nentry->len = len;
59067+ nentry->deleted = deleted;
59068+
59069+ nentry->prev = NULL;
59070+ curr = &name_set.n_hash[index];
59071+ if (*curr != NULL)
59072+ (*curr)->prev = nentry;
59073+ nentry->next = *curr;
59074+ *curr = nentry;
59075+
59076+ /* insert us into the table searchable by inode/dev */
59077+ insert_inodev_entry(ientry);
59078+
59079+ return 1;
59080+}
59081+
59082+static void
59083+insert_acl_obj_label(struct acl_object_label *obj,
59084+ struct acl_subject_label *subj)
59085+{
59086+ unsigned int index =
59087+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
59088+ struct acl_object_label **curr;
59089+
59090+
59091+ obj->prev = NULL;
59092+
59093+ curr = &subj->obj_hash[index];
59094+ if (*curr != NULL)
59095+ (*curr)->prev = obj;
59096+
59097+ obj->next = *curr;
59098+ *curr = obj;
59099+
59100+ return;
59101+}
59102+
59103+static void
59104+insert_acl_subj_label(struct acl_subject_label *obj,
59105+ struct acl_role_label *role)
59106+{
59107+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
59108+ struct acl_subject_label **curr;
59109+
59110+ obj->prev = NULL;
59111+
59112+ curr = &role->subj_hash[index];
59113+ if (*curr != NULL)
59114+ (*curr)->prev = obj;
59115+
59116+ obj->next = *curr;
59117+ *curr = obj;
59118+
59119+ return;
59120+}
59121+
59122+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59123+
59124+static void *
59125+create_table(__u32 * len, int elementsize)
59126+{
59127+ unsigned int table_sizes[] = {
59128+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59129+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59130+ 4194301, 8388593, 16777213, 33554393, 67108859
59131+ };
59132+ void *newtable = NULL;
59133+ unsigned int pwr = 0;
59134+
59135+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59136+ table_sizes[pwr] <= *len)
59137+ pwr++;
59138+
59139+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59140+ return newtable;
59141+
59142+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59143+ newtable =
59144+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59145+ else
59146+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59147+
59148+ *len = table_sizes[pwr];
59149+
59150+ return newtable;
59151+}
59152+
59153+static int
59154+init_variables(const struct gr_arg *arg)
59155+{
59156+ struct task_struct *reaper = init_pid_ns.child_reaper;
59157+ unsigned int stacksize;
59158+
59159+ subj_map_set.s_size = arg->role_db.num_subjects;
59160+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59161+ name_set.n_size = arg->role_db.num_objects;
59162+ inodev_set.i_size = arg->role_db.num_objects;
59163+
59164+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59165+ !name_set.n_size || !inodev_set.i_size)
59166+ return 1;
59167+
59168+ if (!gr_init_uidset())
59169+ return 1;
59170+
59171+ /* set up the stack that holds allocation info */
59172+
59173+ stacksize = arg->role_db.num_pointers + 5;
59174+
59175+ if (!acl_alloc_stack_init(stacksize))
59176+ return 1;
59177+
59178+ /* grab reference for the real root dentry and vfsmount */
59179+ get_fs_root(reaper->fs, &real_root);
59180+
59181+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59182+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59183+#endif
59184+
59185+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59186+ if (fakefs_obj_rw == NULL)
59187+ return 1;
59188+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59189+
59190+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59191+ if (fakefs_obj_rwx == NULL)
59192+ return 1;
59193+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59194+
59195+ subj_map_set.s_hash =
59196+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59197+ acl_role_set.r_hash =
59198+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59199+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59200+ inodev_set.i_hash =
59201+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59202+
59203+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59204+ !name_set.n_hash || !inodev_set.i_hash)
59205+ return 1;
59206+
59207+ memset(subj_map_set.s_hash, 0,
59208+ sizeof(struct subject_map *) * subj_map_set.s_size);
59209+ memset(acl_role_set.r_hash, 0,
59210+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59211+ memset(name_set.n_hash, 0,
59212+ sizeof (struct name_entry *) * name_set.n_size);
59213+ memset(inodev_set.i_hash, 0,
59214+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59215+
59216+ return 0;
59217+}
59218+
59219+/* free information not needed after startup
59220+ currently contains user->kernel pointer mappings for subjects
59221+*/
59222+
59223+static void
59224+free_init_variables(void)
59225+{
59226+ __u32 i;
59227+
59228+ if (subj_map_set.s_hash) {
59229+ for (i = 0; i < subj_map_set.s_size; i++) {
59230+ if (subj_map_set.s_hash[i]) {
59231+ kfree(subj_map_set.s_hash[i]);
59232+ subj_map_set.s_hash[i] = NULL;
59233+ }
59234+ }
59235+
59236+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59237+ PAGE_SIZE)
59238+ kfree(subj_map_set.s_hash);
59239+ else
59240+ vfree(subj_map_set.s_hash);
59241+ }
59242+
59243+ return;
59244+}
59245+
59246+static void
59247+free_variables(void)
59248+{
59249+ struct acl_subject_label *s;
59250+ struct acl_role_label *r;
59251+ struct task_struct *task, *task2;
59252+ unsigned int x;
59253+
59254+ gr_clear_learn_entries();
59255+
59256+ read_lock(&tasklist_lock);
59257+ do_each_thread(task2, task) {
59258+ task->acl_sp_role = 0;
59259+ task->acl_role_id = 0;
59260+ task->acl = NULL;
59261+ task->role = NULL;
59262+ } while_each_thread(task2, task);
59263+ read_unlock(&tasklist_lock);
59264+
59265+ /* release the reference to the real root dentry and vfsmount */
59266+ path_put(&real_root);
59267+ memset(&real_root, 0, sizeof(real_root));
59268+
59269+ /* free all object hash tables */
59270+
59271+ FOR_EACH_ROLE_START(r)
59272+ if (r->subj_hash == NULL)
59273+ goto next_role;
59274+ FOR_EACH_SUBJECT_START(r, s, x)
59275+ if (s->obj_hash == NULL)
59276+ break;
59277+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59278+ kfree(s->obj_hash);
59279+ else
59280+ vfree(s->obj_hash);
59281+ FOR_EACH_SUBJECT_END(s, x)
59282+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59283+ if (s->obj_hash == NULL)
59284+ break;
59285+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59286+ kfree(s->obj_hash);
59287+ else
59288+ vfree(s->obj_hash);
59289+ FOR_EACH_NESTED_SUBJECT_END(s)
59290+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59291+ kfree(r->subj_hash);
59292+ else
59293+ vfree(r->subj_hash);
59294+ r->subj_hash = NULL;
59295+next_role:
59296+ FOR_EACH_ROLE_END(r)
59297+
59298+ acl_free_all();
59299+
59300+ if (acl_role_set.r_hash) {
59301+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59302+ PAGE_SIZE)
59303+ kfree(acl_role_set.r_hash);
59304+ else
59305+ vfree(acl_role_set.r_hash);
59306+ }
59307+ if (name_set.n_hash) {
59308+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59309+ PAGE_SIZE)
59310+ kfree(name_set.n_hash);
59311+ else
59312+ vfree(name_set.n_hash);
59313+ }
59314+
59315+ if (inodev_set.i_hash) {
59316+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59317+ PAGE_SIZE)
59318+ kfree(inodev_set.i_hash);
59319+ else
59320+ vfree(inodev_set.i_hash);
59321+ }
59322+
59323+ gr_free_uidset();
59324+
59325+ memset(&name_set, 0, sizeof (struct name_db));
59326+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59327+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59328+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59329+
59330+ default_role = NULL;
59331+ kernel_role = NULL;
59332+ role_list = NULL;
59333+
59334+ return;
59335+}
59336+
59337+static __u32
59338+count_user_objs(struct acl_object_label *userp)
59339+{
59340+ struct acl_object_label o_tmp;
59341+ __u32 num = 0;
59342+
59343+ while (userp) {
59344+ if (copy_from_user(&o_tmp, userp,
59345+ sizeof (struct acl_object_label)))
59346+ break;
59347+
59348+ userp = o_tmp.prev;
59349+ num++;
59350+ }
59351+
59352+ return num;
59353+}
59354+
59355+static struct acl_subject_label *
59356+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59357+
59358+static int
59359+copy_user_glob(struct acl_object_label *obj)
59360+{
59361+ struct acl_object_label *g_tmp, **guser;
59362+ unsigned int len;
59363+ char *tmp;
59364+
59365+ if (obj->globbed == NULL)
59366+ return 0;
59367+
59368+ guser = &obj->globbed;
59369+ while (*guser) {
59370+ g_tmp = (struct acl_object_label *)
59371+ acl_alloc(sizeof (struct acl_object_label));
59372+ if (g_tmp == NULL)
59373+ return -ENOMEM;
59374+
59375+ if (copy_from_user(g_tmp, *guser,
59376+ sizeof (struct acl_object_label)))
59377+ return -EFAULT;
59378+
59379+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59380+
59381+ if (!len || len >= PATH_MAX)
59382+ return -EINVAL;
59383+
59384+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59385+ return -ENOMEM;
59386+
59387+ if (copy_from_user(tmp, g_tmp->filename, len))
59388+ return -EFAULT;
59389+ tmp[len-1] = '\0';
59390+ g_tmp->filename = tmp;
59391+
59392+ *guser = g_tmp;
59393+ guser = &(g_tmp->next);
59394+ }
59395+
59396+ return 0;
59397+}
59398+
59399+static int
59400+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59401+ struct acl_role_label *role)
59402+{
59403+ struct acl_object_label *o_tmp;
59404+ unsigned int len;
59405+ int ret;
59406+ char *tmp;
59407+
59408+ while (userp) {
59409+ if ((o_tmp = (struct acl_object_label *)
59410+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59411+ return -ENOMEM;
59412+
59413+ if (copy_from_user(o_tmp, userp,
59414+ sizeof (struct acl_object_label)))
59415+ return -EFAULT;
59416+
59417+ userp = o_tmp->prev;
59418+
59419+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59420+
59421+ if (!len || len >= PATH_MAX)
59422+ return -EINVAL;
59423+
59424+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59425+ return -ENOMEM;
59426+
59427+ if (copy_from_user(tmp, o_tmp->filename, len))
59428+ return -EFAULT;
59429+ tmp[len-1] = '\0';
59430+ o_tmp->filename = tmp;
59431+
59432+ insert_acl_obj_label(o_tmp, subj);
59433+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59434+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59435+ return -ENOMEM;
59436+
59437+ ret = copy_user_glob(o_tmp);
59438+ if (ret)
59439+ return ret;
59440+
59441+ if (o_tmp->nested) {
59442+ int already_copied;
59443+
59444+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59445+ if (IS_ERR(o_tmp->nested))
59446+ return PTR_ERR(o_tmp->nested);
59447+
59448+ /* insert into nested subject list if we haven't copied this one yet
59449+ to prevent duplicate entries */
59450+ if (!already_copied) {
59451+ o_tmp->nested->next = role->hash->first;
59452+ role->hash->first = o_tmp->nested;
59453+ }
59454+ }
59455+ }
59456+
59457+ return 0;
59458+}
59459+
59460+static __u32
59461+count_user_subjs(struct acl_subject_label *userp)
59462+{
59463+ struct acl_subject_label s_tmp;
59464+ __u32 num = 0;
59465+
59466+ while (userp) {
59467+ if (copy_from_user(&s_tmp, userp,
59468+ sizeof (struct acl_subject_label)))
59469+ break;
59470+
59471+ userp = s_tmp.prev;
59472+ }
59473+
59474+ return num;
59475+}
59476+
59477+static int
59478+copy_user_allowedips(struct acl_role_label *rolep)
59479+{
59480+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59481+
59482+ ruserip = rolep->allowed_ips;
59483+
59484+ while (ruserip) {
59485+ rlast = rtmp;
59486+
59487+ if ((rtmp = (struct role_allowed_ip *)
59488+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59489+ return -ENOMEM;
59490+
59491+ if (copy_from_user(rtmp, ruserip,
59492+ sizeof (struct role_allowed_ip)))
59493+ return -EFAULT;
59494+
59495+ ruserip = rtmp->prev;
59496+
59497+ if (!rlast) {
59498+ rtmp->prev = NULL;
59499+ rolep->allowed_ips = rtmp;
59500+ } else {
59501+ rlast->next = rtmp;
59502+ rtmp->prev = rlast;
59503+ }
59504+
59505+ if (!ruserip)
59506+ rtmp->next = NULL;
59507+ }
59508+
59509+ return 0;
59510+}
59511+
59512+static int
59513+copy_user_transitions(struct acl_role_label *rolep)
59514+{
59515+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59516+
59517+ unsigned int len;
59518+ char *tmp;
59519+
59520+ rusertp = rolep->transitions;
59521+
59522+ while (rusertp) {
59523+ rlast = rtmp;
59524+
59525+ if ((rtmp = (struct role_transition *)
59526+ acl_alloc(sizeof (struct role_transition))) == NULL)
59527+ return -ENOMEM;
59528+
59529+ if (copy_from_user(rtmp, rusertp,
59530+ sizeof (struct role_transition)))
59531+ return -EFAULT;
59532+
59533+ rusertp = rtmp->prev;
59534+
59535+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59536+
59537+ if (!len || len >= GR_SPROLE_LEN)
59538+ return -EINVAL;
59539+
59540+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59541+ return -ENOMEM;
59542+
59543+ if (copy_from_user(tmp, rtmp->rolename, len))
59544+ return -EFAULT;
59545+ tmp[len-1] = '\0';
59546+ rtmp->rolename = tmp;
59547+
59548+ if (!rlast) {
59549+ rtmp->prev = NULL;
59550+ rolep->transitions = rtmp;
59551+ } else {
59552+ rlast->next = rtmp;
59553+ rtmp->prev = rlast;
59554+ }
59555+
59556+ if (!rusertp)
59557+ rtmp->next = NULL;
59558+ }
59559+
59560+ return 0;
59561+}
59562+
59563+static struct acl_subject_label *
59564+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59565+{
59566+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59567+ unsigned int len;
59568+ char *tmp;
59569+ __u32 num_objs;
59570+ struct acl_ip_label **i_tmp, *i_utmp2;
59571+ struct gr_hash_struct ghash;
59572+ struct subject_map *subjmap;
59573+ unsigned int i_num;
59574+ int err;
59575+
59576+ if (already_copied != NULL)
59577+ *already_copied = 0;
59578+
59579+ s_tmp = lookup_subject_map(userp);
59580+
59581+ /* we've already copied this subject into the kernel, just return
59582+ the reference to it, and don't copy it over again
59583+ */
59584+ if (s_tmp) {
59585+ if (already_copied != NULL)
59586+ *already_copied = 1;
59587+ return(s_tmp);
59588+ }
59589+
59590+ if ((s_tmp = (struct acl_subject_label *)
59591+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59592+ return ERR_PTR(-ENOMEM);
59593+
59594+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59595+ if (subjmap == NULL)
59596+ return ERR_PTR(-ENOMEM);
59597+
59598+ subjmap->user = userp;
59599+ subjmap->kernel = s_tmp;
59600+ insert_subj_map_entry(subjmap);
59601+
59602+ if (copy_from_user(s_tmp, userp,
59603+ sizeof (struct acl_subject_label)))
59604+ return ERR_PTR(-EFAULT);
59605+
59606+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59607+
59608+ if (!len || len >= PATH_MAX)
59609+ return ERR_PTR(-EINVAL);
59610+
59611+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59612+ return ERR_PTR(-ENOMEM);
59613+
59614+ if (copy_from_user(tmp, s_tmp->filename, len))
59615+ return ERR_PTR(-EFAULT);
59616+ tmp[len-1] = '\0';
59617+ s_tmp->filename = tmp;
59618+
59619+ if (!strcmp(s_tmp->filename, "/"))
59620+ role->root_label = s_tmp;
59621+
59622+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59623+ return ERR_PTR(-EFAULT);
59624+
59625+ /* copy user and group transition tables */
59626+
59627+ if (s_tmp->user_trans_num) {
59628+ uid_t *uidlist;
59629+
59630+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59631+ if (uidlist == NULL)
59632+ return ERR_PTR(-ENOMEM);
59633+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59634+ return ERR_PTR(-EFAULT);
59635+
59636+ s_tmp->user_transitions = uidlist;
59637+ }
59638+
59639+ if (s_tmp->group_trans_num) {
59640+ gid_t *gidlist;
59641+
59642+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59643+ if (gidlist == NULL)
59644+ return ERR_PTR(-ENOMEM);
59645+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59646+ return ERR_PTR(-EFAULT);
59647+
59648+ s_tmp->group_transitions = gidlist;
59649+ }
59650+
59651+ /* set up object hash table */
59652+ num_objs = count_user_objs(ghash.first);
59653+
59654+ s_tmp->obj_hash_size = num_objs;
59655+ s_tmp->obj_hash =
59656+ (struct acl_object_label **)
59657+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59658+
59659+ if (!s_tmp->obj_hash)
59660+ return ERR_PTR(-ENOMEM);
59661+
59662+ memset(s_tmp->obj_hash, 0,
59663+ s_tmp->obj_hash_size *
59664+ sizeof (struct acl_object_label *));
59665+
59666+ /* add in objects */
59667+ err = copy_user_objs(ghash.first, s_tmp, role);
59668+
59669+ if (err)
59670+ return ERR_PTR(err);
59671+
59672+ /* set pointer for parent subject */
59673+ if (s_tmp->parent_subject) {
59674+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59675+
59676+ if (IS_ERR(s_tmp2))
59677+ return s_tmp2;
59678+
59679+ s_tmp->parent_subject = s_tmp2;
59680+ }
59681+
59682+ /* add in ip acls */
59683+
59684+ if (!s_tmp->ip_num) {
59685+ s_tmp->ips = NULL;
59686+ goto insert;
59687+ }
59688+
59689+ i_tmp =
59690+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59691+ sizeof (struct acl_ip_label *));
59692+
59693+ if (!i_tmp)
59694+ return ERR_PTR(-ENOMEM);
59695+
59696+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59697+ *(i_tmp + i_num) =
59698+ (struct acl_ip_label *)
59699+ acl_alloc(sizeof (struct acl_ip_label));
59700+ if (!*(i_tmp + i_num))
59701+ return ERR_PTR(-ENOMEM);
59702+
59703+ if (copy_from_user
59704+ (&i_utmp2, s_tmp->ips + i_num,
59705+ sizeof (struct acl_ip_label *)))
59706+ return ERR_PTR(-EFAULT);
59707+
59708+ if (copy_from_user
59709+ (*(i_tmp + i_num), i_utmp2,
59710+ sizeof (struct acl_ip_label)))
59711+ return ERR_PTR(-EFAULT);
59712+
59713+ if ((*(i_tmp + i_num))->iface == NULL)
59714+ continue;
59715+
59716+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59717+ if (!len || len >= IFNAMSIZ)
59718+ return ERR_PTR(-EINVAL);
59719+ tmp = acl_alloc(len);
59720+ if (tmp == NULL)
59721+ return ERR_PTR(-ENOMEM);
59722+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59723+ return ERR_PTR(-EFAULT);
59724+ (*(i_tmp + i_num))->iface = tmp;
59725+ }
59726+
59727+ s_tmp->ips = i_tmp;
59728+
59729+insert:
59730+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59731+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59732+ return ERR_PTR(-ENOMEM);
59733+
59734+ return s_tmp;
59735+}
59736+
59737+static int
59738+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59739+{
59740+ struct acl_subject_label s_pre;
59741+ struct acl_subject_label * ret;
59742+ int err;
59743+
59744+ while (userp) {
59745+ if (copy_from_user(&s_pre, userp,
59746+ sizeof (struct acl_subject_label)))
59747+ return -EFAULT;
59748+
59749+ ret = do_copy_user_subj(userp, role, NULL);
59750+
59751+ err = PTR_ERR(ret);
59752+ if (IS_ERR(ret))
59753+ return err;
59754+
59755+ insert_acl_subj_label(ret, role);
59756+
59757+ userp = s_pre.prev;
59758+ }
59759+
59760+ return 0;
59761+}
59762+
59763+static int
59764+copy_user_acl(struct gr_arg *arg)
59765+{
59766+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59767+ struct acl_subject_label *subj_list;
59768+ struct sprole_pw *sptmp;
59769+ struct gr_hash_struct *ghash;
59770+ uid_t *domainlist;
59771+ unsigned int r_num;
59772+ unsigned int len;
59773+ char *tmp;
59774+ int err = 0;
59775+ __u16 i;
59776+ __u32 num_subjs;
59777+
59778+ /* we need a default and kernel role */
59779+ if (arg->role_db.num_roles < 2)
59780+ return -EINVAL;
59781+
59782+ /* copy special role authentication info from userspace */
59783+
59784+ num_sprole_pws = arg->num_sprole_pws;
59785+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59786+
59787+ if (!acl_special_roles && num_sprole_pws)
59788+ return -ENOMEM;
59789+
59790+ for (i = 0; i < num_sprole_pws; i++) {
59791+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59792+ if (!sptmp)
59793+ return -ENOMEM;
59794+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59795+ sizeof (struct sprole_pw)))
59796+ return -EFAULT;
59797+
59798+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59799+
59800+ if (!len || len >= GR_SPROLE_LEN)
59801+ return -EINVAL;
59802+
59803+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59804+ return -ENOMEM;
59805+
59806+ if (copy_from_user(tmp, sptmp->rolename, len))
59807+ return -EFAULT;
59808+
59809+ tmp[len-1] = '\0';
59810+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59811+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59812+#endif
59813+ sptmp->rolename = tmp;
59814+ acl_special_roles[i] = sptmp;
59815+ }
59816+
59817+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59818+
59819+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59820+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59821+
59822+ if (!r_tmp)
59823+ return -ENOMEM;
59824+
59825+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59826+ sizeof (struct acl_role_label *)))
59827+ return -EFAULT;
59828+
59829+ if (copy_from_user(r_tmp, r_utmp2,
59830+ sizeof (struct acl_role_label)))
59831+ return -EFAULT;
59832+
59833+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59834+
59835+ if (!len || len >= PATH_MAX)
59836+ return -EINVAL;
59837+
59838+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59839+ return -ENOMEM;
59840+
59841+ if (copy_from_user(tmp, r_tmp->rolename, len))
59842+ return -EFAULT;
59843+
59844+ tmp[len-1] = '\0';
59845+ r_tmp->rolename = tmp;
59846+
59847+ if (!strcmp(r_tmp->rolename, "default")
59848+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59849+ default_role = r_tmp;
59850+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59851+ kernel_role = r_tmp;
59852+ }
59853+
59854+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59855+ return -ENOMEM;
59856+
59857+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59858+ return -EFAULT;
59859+
59860+ r_tmp->hash = ghash;
59861+
59862+ num_subjs = count_user_subjs(r_tmp->hash->first);
59863+
59864+ r_tmp->subj_hash_size = num_subjs;
59865+ r_tmp->subj_hash =
59866+ (struct acl_subject_label **)
59867+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59868+
59869+ if (!r_tmp->subj_hash)
59870+ return -ENOMEM;
59871+
59872+ err = copy_user_allowedips(r_tmp);
59873+ if (err)
59874+ return err;
59875+
59876+ /* copy domain info */
59877+ if (r_tmp->domain_children != NULL) {
59878+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59879+ if (domainlist == NULL)
59880+ return -ENOMEM;
59881+
59882+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59883+ return -EFAULT;
59884+
59885+ r_tmp->domain_children = domainlist;
59886+ }
59887+
59888+ err = copy_user_transitions(r_tmp);
59889+ if (err)
59890+ return err;
59891+
59892+ memset(r_tmp->subj_hash, 0,
59893+ r_tmp->subj_hash_size *
59894+ sizeof (struct acl_subject_label *));
59895+
59896+ /* acquire the list of subjects, then NULL out
59897+ the list prior to parsing the subjects for this role,
59898+ as during this parsing the list is replaced with a list
59899+ of *nested* subjects for the role
59900+ */
59901+ subj_list = r_tmp->hash->first;
59902+
59903+ /* set nested subject list to null */
59904+ r_tmp->hash->first = NULL;
59905+
59906+ err = copy_user_subjs(subj_list, r_tmp);
59907+
59908+ if (err)
59909+ return err;
59910+
59911+ insert_acl_role_label(r_tmp);
59912+ }
59913+
59914+ if (default_role == NULL || kernel_role == NULL)
59915+ return -EINVAL;
59916+
59917+ return err;
59918+}
59919+
59920+static int
59921+gracl_init(struct gr_arg *args)
59922+{
59923+ int error = 0;
59924+
59925+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59926+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59927+
59928+ if (init_variables(args)) {
59929+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59930+ error = -ENOMEM;
59931+ free_variables();
59932+ goto out;
59933+ }
59934+
59935+ error = copy_user_acl(args);
59936+ free_init_variables();
59937+ if (error) {
59938+ free_variables();
59939+ goto out;
59940+ }
59941+
59942+ if ((error = gr_set_acls(0))) {
59943+ free_variables();
59944+ goto out;
59945+ }
59946+
59947+ pax_open_kernel();
59948+ gr_status |= GR_READY;
59949+ pax_close_kernel();
59950+
59951+ out:
59952+ return error;
59953+}
59954+
59955+/* derived from glibc fnmatch() 0: match, 1: no match*/
59956+
59957+static int
59958+glob_match(const char *p, const char *n)
59959+{
59960+ char c;
59961+
59962+ while ((c = *p++) != '\0') {
59963+ switch (c) {
59964+ case '?':
59965+ if (*n == '\0')
59966+ return 1;
59967+ else if (*n == '/')
59968+ return 1;
59969+ break;
59970+ case '\\':
59971+ if (*n != c)
59972+ return 1;
59973+ break;
59974+ case '*':
59975+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59976+ if (*n == '/')
59977+ return 1;
59978+ else if (c == '?') {
59979+ if (*n == '\0')
59980+ return 1;
59981+ else
59982+ ++n;
59983+ }
59984+ }
59985+ if (c == '\0') {
59986+ return 0;
59987+ } else {
59988+ const char *endp;
59989+
59990+ if ((endp = strchr(n, '/')) == NULL)
59991+ endp = n + strlen(n);
59992+
59993+ if (c == '[') {
59994+ for (--p; n < endp; ++n)
59995+ if (!glob_match(p, n))
59996+ return 0;
59997+ } else if (c == '/') {
59998+ while (*n != '\0' && *n != '/')
59999+ ++n;
60000+ if (*n == '/' && !glob_match(p, n + 1))
60001+ return 0;
60002+ } else {
60003+ for (--p; n < endp; ++n)
60004+ if (*n == c && !glob_match(p, n))
60005+ return 0;
60006+ }
60007+
60008+ return 1;
60009+ }
60010+ case '[':
60011+ {
60012+ int not;
60013+ char cold;
60014+
60015+ if (*n == '\0' || *n == '/')
60016+ return 1;
60017+
60018+ not = (*p == '!' || *p == '^');
60019+ if (not)
60020+ ++p;
60021+
60022+ c = *p++;
60023+ for (;;) {
60024+ unsigned char fn = (unsigned char)*n;
60025+
60026+ if (c == '\0')
60027+ return 1;
60028+ else {
60029+ if (c == fn)
60030+ goto matched;
60031+ cold = c;
60032+ c = *p++;
60033+
60034+ if (c == '-' && *p != ']') {
60035+ unsigned char cend = *p++;
60036+
60037+ if (cend == '\0')
60038+ return 1;
60039+
60040+ if (cold <= fn && fn <= cend)
60041+ goto matched;
60042+
60043+ c = *p++;
60044+ }
60045+ }
60046+
60047+ if (c == ']')
60048+ break;
60049+ }
60050+ if (!not)
60051+ return 1;
60052+ break;
60053+ matched:
60054+ while (c != ']') {
60055+ if (c == '\0')
60056+ return 1;
60057+
60058+ c = *p++;
60059+ }
60060+ if (not)
60061+ return 1;
60062+ }
60063+ break;
60064+ default:
60065+ if (c != *n)
60066+ return 1;
60067+ }
60068+
60069+ ++n;
60070+ }
60071+
60072+ if (*n == '\0')
60073+ return 0;
60074+
60075+ if (*n == '/')
60076+ return 0;
60077+
60078+ return 1;
60079+}
60080+
60081+static struct acl_object_label *
60082+chk_glob_label(struct acl_object_label *globbed,
60083+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
60084+{
60085+ struct acl_object_label *tmp;
60086+
60087+ if (*path == NULL)
60088+ *path = gr_to_filename_nolock(dentry, mnt);
60089+
60090+ tmp = globbed;
60091+
60092+ while (tmp) {
60093+ if (!glob_match(tmp->filename, *path))
60094+ return tmp;
60095+ tmp = tmp->next;
60096+ }
60097+
60098+ return NULL;
60099+}
60100+
60101+static struct acl_object_label *
60102+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60103+ const ino_t curr_ino, const dev_t curr_dev,
60104+ const struct acl_subject_label *subj, char **path, const int checkglob)
60105+{
60106+ struct acl_subject_label *tmpsubj;
60107+ struct acl_object_label *retval;
60108+ struct acl_object_label *retval2;
60109+
60110+ tmpsubj = (struct acl_subject_label *) subj;
60111+ read_lock(&gr_inode_lock);
60112+ do {
60113+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
60114+ if (retval) {
60115+ if (checkglob && retval->globbed) {
60116+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60117+ if (retval2)
60118+ retval = retval2;
60119+ }
60120+ break;
60121+ }
60122+ } while ((tmpsubj = tmpsubj->parent_subject));
60123+ read_unlock(&gr_inode_lock);
60124+
60125+ return retval;
60126+}
60127+
60128+static __inline__ struct acl_object_label *
60129+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60130+ struct dentry *curr_dentry,
60131+ const struct acl_subject_label *subj, char **path, const int checkglob)
60132+{
60133+ int newglob = checkglob;
60134+ ino_t inode;
60135+ dev_t device;
60136+
60137+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60138+ as we don't want a / * rule to match instead of the / object
60139+ don't do this for create lookups that call this function though, since they're looking up
60140+ on the parent and thus need globbing checks on all paths
60141+ */
60142+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60143+ newglob = GR_NO_GLOB;
60144+
60145+ spin_lock(&curr_dentry->d_lock);
60146+ inode = curr_dentry->d_inode->i_ino;
60147+ device = __get_dev(curr_dentry);
60148+ spin_unlock(&curr_dentry->d_lock);
60149+
60150+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60151+}
60152+
60153+#ifdef CONFIG_HUGETLBFS
60154+static inline bool
60155+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60156+{
60157+ int i;
60158+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60159+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60160+ return true;
60161+ }
60162+
60163+ return false;
60164+}
60165+#endif
60166+
60167+static struct acl_object_label *
60168+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60169+ const struct acl_subject_label *subj, char *path, const int checkglob)
60170+{
60171+ struct dentry *dentry = (struct dentry *) l_dentry;
60172+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60173+ struct mount *real_mnt = real_mount(mnt);
60174+ struct acl_object_label *retval;
60175+ struct dentry *parent;
60176+
60177+ br_read_lock(&vfsmount_lock);
60178+ write_seqlock(&rename_lock);
60179+
60180+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60181+#ifdef CONFIG_NET
60182+ mnt == sock_mnt ||
60183+#endif
60184+#ifdef CONFIG_HUGETLBFS
60185+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60186+#endif
60187+ /* ignore Eric Biederman */
60188+ IS_PRIVATE(l_dentry->d_inode))) {
60189+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60190+ goto out;
60191+ }
60192+
60193+ for (;;) {
60194+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60195+ break;
60196+
60197+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60198+ if (!mnt_has_parent(real_mnt))
60199+ break;
60200+
60201+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60202+ if (retval != NULL)
60203+ goto out;
60204+
60205+ dentry = real_mnt->mnt_mountpoint;
60206+ real_mnt = real_mnt->mnt_parent;
60207+ mnt = &real_mnt->mnt;
60208+ continue;
60209+ }
60210+
60211+ parent = dentry->d_parent;
60212+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60213+ if (retval != NULL)
60214+ goto out;
60215+
60216+ dentry = parent;
60217+ }
60218+
60219+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60220+
60221+ /* real_root is pinned so we don't have to hold a reference */
60222+ if (retval == NULL)
60223+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60224+out:
60225+ write_sequnlock(&rename_lock);
60226+ br_read_unlock(&vfsmount_lock);
60227+
60228+ BUG_ON(retval == NULL);
60229+
60230+ return retval;
60231+}
60232+
60233+static __inline__ struct acl_object_label *
60234+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60235+ const struct acl_subject_label *subj)
60236+{
60237+ char *path = NULL;
60238+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60239+}
60240+
60241+static __inline__ struct acl_object_label *
60242+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60243+ const struct acl_subject_label *subj)
60244+{
60245+ char *path = NULL;
60246+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60247+}
60248+
60249+static __inline__ struct acl_object_label *
60250+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60251+ const struct acl_subject_label *subj, char *path)
60252+{
60253+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60254+}
60255+
60256+static struct acl_subject_label *
60257+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60258+ const struct acl_role_label *role)
60259+{
60260+ struct dentry *dentry = (struct dentry *) l_dentry;
60261+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60262+ struct mount *real_mnt = real_mount(mnt);
60263+ struct acl_subject_label *retval;
60264+ struct dentry *parent;
60265+
60266+ br_read_lock(&vfsmount_lock);
60267+ write_seqlock(&rename_lock);
60268+
60269+ for (;;) {
60270+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60271+ break;
60272+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60273+ if (!mnt_has_parent(real_mnt))
60274+ break;
60275+
60276+ spin_lock(&dentry->d_lock);
60277+ read_lock(&gr_inode_lock);
60278+ retval =
60279+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60280+ __get_dev(dentry), role);
60281+ read_unlock(&gr_inode_lock);
60282+ spin_unlock(&dentry->d_lock);
60283+ if (retval != NULL)
60284+ goto out;
60285+
60286+ dentry = real_mnt->mnt_mountpoint;
60287+ real_mnt = real_mnt->mnt_parent;
60288+ mnt = &real_mnt->mnt;
60289+ continue;
60290+ }
60291+
60292+ spin_lock(&dentry->d_lock);
60293+ read_lock(&gr_inode_lock);
60294+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60295+ __get_dev(dentry), role);
60296+ read_unlock(&gr_inode_lock);
60297+ parent = dentry->d_parent;
60298+ spin_unlock(&dentry->d_lock);
60299+
60300+ if (retval != NULL)
60301+ goto out;
60302+
60303+ dentry = parent;
60304+ }
60305+
60306+ spin_lock(&dentry->d_lock);
60307+ read_lock(&gr_inode_lock);
60308+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60309+ __get_dev(dentry), role);
60310+ read_unlock(&gr_inode_lock);
60311+ spin_unlock(&dentry->d_lock);
60312+
60313+ if (unlikely(retval == NULL)) {
60314+ /* real_root is pinned, we don't need to hold a reference */
60315+ read_lock(&gr_inode_lock);
60316+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60317+ __get_dev(real_root.dentry), role);
60318+ read_unlock(&gr_inode_lock);
60319+ }
60320+out:
60321+ write_sequnlock(&rename_lock);
60322+ br_read_unlock(&vfsmount_lock);
60323+
60324+ BUG_ON(retval == NULL);
60325+
60326+ return retval;
60327+}
60328+
60329+static void
60330+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60331+{
60332+ struct task_struct *task = current;
60333+ const struct cred *cred = current_cred();
60334+
60335+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60336+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60337+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60338+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60339+
60340+ return;
60341+}
60342+
60343+static void
60344+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60345+{
60346+ struct task_struct *task = current;
60347+ const struct cred *cred = current_cred();
60348+
60349+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60350+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60351+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60352+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60353+
60354+ return;
60355+}
60356+
60357+static void
60358+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60359+{
60360+ struct task_struct *task = current;
60361+ const struct cred *cred = current_cred();
60362+
60363+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60364+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60365+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60366+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60367+
60368+ return;
60369+}
60370+
60371+__u32
60372+gr_search_file(const struct dentry * dentry, const __u32 mode,
60373+ const struct vfsmount * mnt)
60374+{
60375+ __u32 retval = mode;
60376+ struct acl_subject_label *curracl;
60377+ struct acl_object_label *currobj;
60378+
60379+ if (unlikely(!(gr_status & GR_READY)))
60380+ return (mode & ~GR_AUDITS);
60381+
60382+ curracl = current->acl;
60383+
60384+ currobj = chk_obj_label(dentry, mnt, curracl);
60385+ retval = currobj->mode & mode;
60386+
60387+ /* if we're opening a specified transfer file for writing
60388+ (e.g. /dev/initctl), then transfer our role to init
60389+ */
60390+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60391+ current->role->roletype & GR_ROLE_PERSIST)) {
60392+ struct task_struct *task = init_pid_ns.child_reaper;
60393+
60394+ if (task->role != current->role) {
60395+ task->acl_sp_role = 0;
60396+ task->acl_role_id = current->acl_role_id;
60397+ task->role = current->role;
60398+ rcu_read_lock();
60399+ read_lock(&grsec_exec_file_lock);
60400+ gr_apply_subject_to_task(task);
60401+ read_unlock(&grsec_exec_file_lock);
60402+ rcu_read_unlock();
60403+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60404+ }
60405+ }
60406+
60407+ if (unlikely
60408+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60409+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60410+ __u32 new_mode = mode;
60411+
60412+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60413+
60414+ retval = new_mode;
60415+
60416+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60417+ new_mode |= GR_INHERIT;
60418+
60419+ if (!(mode & GR_NOLEARN))
60420+ gr_log_learn(dentry, mnt, new_mode);
60421+ }
60422+
60423+ return retval;
60424+}
60425+
60426+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60427+ const struct dentry *parent,
60428+ const struct vfsmount *mnt)
60429+{
60430+ struct name_entry *match;
60431+ struct acl_object_label *matchpo;
60432+ struct acl_subject_label *curracl;
60433+ char *path;
60434+
60435+ if (unlikely(!(gr_status & GR_READY)))
60436+ return NULL;
60437+
60438+ preempt_disable();
60439+ path = gr_to_filename_rbac(new_dentry, mnt);
60440+ match = lookup_name_entry_create(path);
60441+
60442+ curracl = current->acl;
60443+
60444+ if (match) {
60445+ read_lock(&gr_inode_lock);
60446+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60447+ read_unlock(&gr_inode_lock);
60448+
60449+ if (matchpo) {
60450+ preempt_enable();
60451+ return matchpo;
60452+ }
60453+ }
60454+
60455+ // lookup parent
60456+
60457+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60458+
60459+ preempt_enable();
60460+ return matchpo;
60461+}
60462+
60463+__u32
60464+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60465+ const struct vfsmount * mnt, const __u32 mode)
60466+{
60467+ struct acl_object_label *matchpo;
60468+ __u32 retval;
60469+
60470+ if (unlikely(!(gr_status & GR_READY)))
60471+ return (mode & ~GR_AUDITS);
60472+
60473+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60474+
60475+ retval = matchpo->mode & mode;
60476+
60477+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60478+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60479+ __u32 new_mode = mode;
60480+
60481+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60482+
60483+ gr_log_learn(new_dentry, mnt, new_mode);
60484+ return new_mode;
60485+ }
60486+
60487+ return retval;
60488+}
60489+
60490+__u32
60491+gr_check_link(const struct dentry * new_dentry,
60492+ const struct dentry * parent_dentry,
60493+ const struct vfsmount * parent_mnt,
60494+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60495+{
60496+ struct acl_object_label *obj;
60497+ __u32 oldmode, newmode;
60498+ __u32 needmode;
60499+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60500+ GR_DELETE | GR_INHERIT;
60501+
60502+ if (unlikely(!(gr_status & GR_READY)))
60503+ return (GR_CREATE | GR_LINK);
60504+
60505+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60506+ oldmode = obj->mode;
60507+
60508+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60509+ newmode = obj->mode;
60510+
60511+ needmode = newmode & checkmodes;
60512+
60513+ // old name for hardlink must have at least the permissions of the new name
60514+ if ((oldmode & needmode) != needmode)
60515+ goto bad;
60516+
60517+ // if old name had restrictions/auditing, make sure the new name does as well
60518+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60519+
60520+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60521+ if (is_privileged_binary(old_dentry))
60522+ needmode |= GR_SETID;
60523+
60524+ if ((newmode & needmode) != needmode)
60525+ goto bad;
60526+
60527+ // enforce minimum permissions
60528+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60529+ return newmode;
60530+bad:
60531+ needmode = oldmode;
60532+ if (is_privileged_binary(old_dentry))
60533+ needmode |= GR_SETID;
60534+
60535+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60536+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60537+ return (GR_CREATE | GR_LINK);
60538+ } else if (newmode & GR_SUPPRESS)
60539+ return GR_SUPPRESS;
60540+ else
60541+ return 0;
60542+}
60543+
60544+int
60545+gr_check_hidden_task(const struct task_struct *task)
60546+{
60547+ if (unlikely(!(gr_status & GR_READY)))
60548+ return 0;
60549+
60550+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60551+ return 1;
60552+
60553+ return 0;
60554+}
60555+
60556+int
60557+gr_check_protected_task(const struct task_struct *task)
60558+{
60559+ if (unlikely(!(gr_status & GR_READY) || !task))
60560+ return 0;
60561+
60562+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60563+ task->acl != current->acl)
60564+ return 1;
60565+
60566+ return 0;
60567+}
60568+
60569+int
60570+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60571+{
60572+ struct task_struct *p;
60573+ int ret = 0;
60574+
60575+ if (unlikely(!(gr_status & GR_READY) || !pid))
60576+ return ret;
60577+
60578+ read_lock(&tasklist_lock);
60579+ do_each_pid_task(pid, type, p) {
60580+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60581+ p->acl != current->acl) {
60582+ ret = 1;
60583+ goto out;
60584+ }
60585+ } while_each_pid_task(pid, type, p);
60586+out:
60587+ read_unlock(&tasklist_lock);
60588+
60589+ return ret;
60590+}
60591+
60592+void
60593+gr_copy_label(struct task_struct *tsk)
60594+{
60595+ tsk->signal->used_accept = 0;
60596+ tsk->acl_sp_role = 0;
60597+ tsk->acl_role_id = current->acl_role_id;
60598+ tsk->acl = current->acl;
60599+ tsk->role = current->role;
60600+ tsk->signal->curr_ip = current->signal->curr_ip;
60601+ tsk->signal->saved_ip = current->signal->saved_ip;
60602+ if (current->exec_file)
60603+ get_file(current->exec_file);
60604+ tsk->exec_file = current->exec_file;
60605+ tsk->is_writable = current->is_writable;
60606+ if (unlikely(current->signal->used_accept)) {
60607+ current->signal->curr_ip = 0;
60608+ current->signal->saved_ip = 0;
60609+ }
60610+
60611+ return;
60612+}
60613+
60614+static void
60615+gr_set_proc_res(struct task_struct *task)
60616+{
60617+ struct acl_subject_label *proc;
60618+ unsigned short i;
60619+
60620+ proc = task->acl;
60621+
60622+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60623+ return;
60624+
60625+ for (i = 0; i < RLIM_NLIMITS; i++) {
60626+ if (!(proc->resmask & (1U << i)))
60627+ continue;
60628+
60629+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60630+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60631+
60632+ if (i == RLIMIT_CPU)
60633+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60634+ }
60635+
60636+ return;
60637+}
60638+
60639+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
60640+
60641+int
60642+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60643+{
60644+ unsigned int i;
60645+ __u16 num;
60646+ uid_t *uidlist;
60647+ uid_t curuid;
60648+ int realok = 0;
60649+ int effectiveok = 0;
60650+ int fsok = 0;
60651+ uid_t globalreal, globaleffective, globalfs;
60652+
60653+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
60654+ struct user_struct *user;
60655+
60656+ if (!uid_valid(real))
60657+ goto skipit;
60658+
60659+ /* find user based on global namespace */
60660+
60661+ globalreal = GR_GLOBAL_UID(real);
60662+
60663+ user = find_user(make_kuid(&init_user_ns, globalreal));
60664+ if (user == NULL)
60665+ goto skipit;
60666+
60667+ if (gr_process_kernel_setuid_ban(user)) {
60668+ /* for find_user */
60669+ free_uid(user);
60670+ return 1;
60671+ }
60672+
60673+ /* for find_user */
60674+ free_uid(user);
60675+
60676+skipit:
60677+#endif
60678+
60679+ if (unlikely(!(gr_status & GR_READY)))
60680+ return 0;
60681+
60682+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60683+ gr_log_learn_uid_change(real, effective, fs);
60684+
60685+ num = current->acl->user_trans_num;
60686+ uidlist = current->acl->user_transitions;
60687+
60688+ if (uidlist == NULL)
60689+ return 0;
60690+
60691+ if (!uid_valid(real)) {
60692+ realok = 1;
60693+ globalreal = (uid_t)-1;
60694+ } else {
60695+ globalreal = GR_GLOBAL_UID(real);
60696+ }
60697+ if (!uid_valid(effective)) {
60698+ effectiveok = 1;
60699+ globaleffective = (uid_t)-1;
60700+ } else {
60701+ globaleffective = GR_GLOBAL_UID(effective);
60702+ }
60703+ if (!uid_valid(fs)) {
60704+ fsok = 1;
60705+ globalfs = (uid_t)-1;
60706+ } else {
60707+ globalfs = GR_GLOBAL_UID(fs);
60708+ }
60709+
60710+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60711+ for (i = 0; i < num; i++) {
60712+ curuid = uidlist[i];
60713+ if (globalreal == curuid)
60714+ realok = 1;
60715+ if (globaleffective == curuid)
60716+ effectiveok = 1;
60717+ if (globalfs == curuid)
60718+ fsok = 1;
60719+ }
60720+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60721+ for (i = 0; i < num; i++) {
60722+ curuid = uidlist[i];
60723+ if (globalreal == curuid)
60724+ break;
60725+ if (globaleffective == curuid)
60726+ break;
60727+ if (globalfs == curuid)
60728+ break;
60729+ }
60730+ /* not in deny list */
60731+ if (i == num) {
60732+ realok = 1;
60733+ effectiveok = 1;
60734+ fsok = 1;
60735+ }
60736+ }
60737+
60738+ if (realok && effectiveok && fsok)
60739+ return 0;
60740+ else {
60741+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60742+ return 1;
60743+ }
60744+}
60745+
60746+int
60747+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60748+{
60749+ unsigned int i;
60750+ __u16 num;
60751+ gid_t *gidlist;
60752+ gid_t curgid;
60753+ int realok = 0;
60754+ int effectiveok = 0;
60755+ int fsok = 0;
60756+ gid_t globalreal, globaleffective, globalfs;
60757+
60758+ if (unlikely(!(gr_status & GR_READY)))
60759+ return 0;
60760+
60761+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60762+ gr_log_learn_gid_change(real, effective, fs);
60763+
60764+ num = current->acl->group_trans_num;
60765+ gidlist = current->acl->group_transitions;
60766+
60767+ if (gidlist == NULL)
60768+ return 0;
60769+
60770+ if (!gid_valid(real)) {
60771+ realok = 1;
60772+ globalreal = (gid_t)-1;
60773+ } else {
60774+ globalreal = GR_GLOBAL_GID(real);
60775+ }
60776+ if (!gid_valid(effective)) {
60777+ effectiveok = 1;
60778+ globaleffective = (gid_t)-1;
60779+ } else {
60780+ globaleffective = GR_GLOBAL_GID(effective);
60781+ }
60782+ if (!gid_valid(fs)) {
60783+ fsok = 1;
60784+ globalfs = (gid_t)-1;
60785+ } else {
60786+ globalfs = GR_GLOBAL_GID(fs);
60787+ }
60788+
60789+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60790+ for (i = 0; i < num; i++) {
60791+ curgid = gidlist[i];
60792+ if (globalreal == curgid)
60793+ realok = 1;
60794+ if (globaleffective == curgid)
60795+ effectiveok = 1;
60796+ if (globalfs == curgid)
60797+ fsok = 1;
60798+ }
60799+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60800+ for (i = 0; i < num; i++) {
60801+ curgid = gidlist[i];
60802+ if (globalreal == curgid)
60803+ break;
60804+ if (globaleffective == curgid)
60805+ break;
60806+ if (globalfs == curgid)
60807+ break;
60808+ }
60809+ /* not in deny list */
60810+ if (i == num) {
60811+ realok = 1;
60812+ effectiveok = 1;
60813+ fsok = 1;
60814+ }
60815+ }
60816+
60817+ if (realok && effectiveok && fsok)
60818+ return 0;
60819+ else {
60820+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60821+ return 1;
60822+ }
60823+}
60824+
60825+extern int gr_acl_is_capable(const int cap);
60826+
60827+void
60828+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60829+{
60830+ struct acl_role_label *role = task->role;
60831+ struct acl_subject_label *subj = NULL;
60832+ struct acl_object_label *obj;
60833+ struct file *filp;
60834+ uid_t uid;
60835+ gid_t gid;
60836+
60837+ if (unlikely(!(gr_status & GR_READY)))
60838+ return;
60839+
60840+ uid = GR_GLOBAL_UID(kuid);
60841+ gid = GR_GLOBAL_GID(kgid);
60842+
60843+ filp = task->exec_file;
60844+
60845+ /* kernel process, we'll give them the kernel role */
60846+ if (unlikely(!filp)) {
60847+ task->role = kernel_role;
60848+ task->acl = kernel_role->root_label;
60849+ return;
60850+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60851+ role = lookup_acl_role_label(task, uid, gid);
60852+
60853+ /* don't change the role if we're not a privileged process */
60854+ if (role && task->role != role &&
60855+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60856+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60857+ return;
60858+
60859+ /* perform subject lookup in possibly new role
60860+ we can use this result below in the case where role == task->role
60861+ */
60862+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60863+
60864+ /* if we changed uid/gid, but result in the same role
60865+ and are using inheritance, don't lose the inherited subject
60866+ if current subject is other than what normal lookup
60867+ would result in, we arrived via inheritance, don't
60868+ lose subject
60869+ */
60870+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60871+ (subj == task->acl)))
60872+ task->acl = subj;
60873+
60874+ task->role = role;
60875+
60876+ task->is_writable = 0;
60877+
60878+ /* ignore additional mmap checks for processes that are writable
60879+ by the default ACL */
60880+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60881+ if (unlikely(obj->mode & GR_WRITE))
60882+ task->is_writable = 1;
60883+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60884+ if (unlikely(obj->mode & GR_WRITE))
60885+ task->is_writable = 1;
60886+
60887+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60888+ 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);
60889+#endif
60890+
60891+ gr_set_proc_res(task);
60892+
60893+ return;
60894+}
60895+
60896+int
60897+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60898+ const int unsafe_flags)
60899+{
60900+ struct task_struct *task = current;
60901+ struct acl_subject_label *newacl;
60902+ struct acl_object_label *obj;
60903+ __u32 retmode;
60904+
60905+ if (unlikely(!(gr_status & GR_READY)))
60906+ return 0;
60907+
60908+ newacl = chk_subj_label(dentry, mnt, task->role);
60909+
60910+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60911+ did an exec
60912+ */
60913+ rcu_read_lock();
60914+ read_lock(&tasklist_lock);
60915+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60916+ (task->parent->acl->mode & GR_POVERRIDE))) {
60917+ read_unlock(&tasklist_lock);
60918+ rcu_read_unlock();
60919+ goto skip_check;
60920+ }
60921+ read_unlock(&tasklist_lock);
60922+ rcu_read_unlock();
60923+
60924+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60925+ !(task->role->roletype & GR_ROLE_GOD) &&
60926+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60927+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60928+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60929+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60930+ else
60931+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60932+ return -EACCES;
60933+ }
60934+
60935+skip_check:
60936+
60937+ obj = chk_obj_label(dentry, mnt, task->acl);
60938+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60939+
60940+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60941+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60942+ if (obj->nested)
60943+ task->acl = obj->nested;
60944+ else
60945+ task->acl = newacl;
60946+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60947+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60948+
60949+ task->is_writable = 0;
60950+
60951+ /* ignore additional mmap checks for processes that are writable
60952+ by the default ACL */
60953+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60954+ if (unlikely(obj->mode & GR_WRITE))
60955+ task->is_writable = 1;
60956+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60957+ if (unlikely(obj->mode & GR_WRITE))
60958+ task->is_writable = 1;
60959+
60960+ gr_set_proc_res(task);
60961+
60962+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60963+ 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);
60964+#endif
60965+ return 0;
60966+}
60967+
60968+/* always called with valid inodev ptr */
60969+static void
60970+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60971+{
60972+ struct acl_object_label *matchpo;
60973+ struct acl_subject_label *matchps;
60974+ struct acl_subject_label *subj;
60975+ struct acl_role_label *role;
60976+ unsigned int x;
60977+
60978+ FOR_EACH_ROLE_START(role)
60979+ FOR_EACH_SUBJECT_START(role, subj, x)
60980+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60981+ matchpo->mode |= GR_DELETED;
60982+ FOR_EACH_SUBJECT_END(subj,x)
60983+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60984+ /* nested subjects aren't in the role's subj_hash table */
60985+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60986+ matchpo->mode |= GR_DELETED;
60987+ FOR_EACH_NESTED_SUBJECT_END(subj)
60988+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60989+ matchps->mode |= GR_DELETED;
60990+ FOR_EACH_ROLE_END(role)
60991+
60992+ inodev->nentry->deleted = 1;
60993+
60994+ return;
60995+}
60996+
60997+void
60998+gr_handle_delete(const ino_t ino, const dev_t dev)
60999+{
61000+ struct inodev_entry *inodev;
61001+
61002+ if (unlikely(!(gr_status & GR_READY)))
61003+ return;
61004+
61005+ write_lock(&gr_inode_lock);
61006+ inodev = lookup_inodev_entry(ino, dev);
61007+ if (inodev != NULL)
61008+ do_handle_delete(inodev, ino, dev);
61009+ write_unlock(&gr_inode_lock);
61010+
61011+ return;
61012+}
61013+
61014+static void
61015+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
61016+ const ino_t newinode, const dev_t newdevice,
61017+ struct acl_subject_label *subj)
61018+{
61019+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
61020+ struct acl_object_label *match;
61021+
61022+ match = subj->obj_hash[index];
61023+
61024+ while (match && (match->inode != oldinode ||
61025+ match->device != olddevice ||
61026+ !(match->mode & GR_DELETED)))
61027+ match = match->next;
61028+
61029+ if (match && (match->inode == oldinode)
61030+ && (match->device == olddevice)
61031+ && (match->mode & GR_DELETED)) {
61032+ if (match->prev == NULL) {
61033+ subj->obj_hash[index] = match->next;
61034+ if (match->next != NULL)
61035+ match->next->prev = NULL;
61036+ } else {
61037+ match->prev->next = match->next;
61038+ if (match->next != NULL)
61039+ match->next->prev = match->prev;
61040+ }
61041+ match->prev = NULL;
61042+ match->next = NULL;
61043+ match->inode = newinode;
61044+ match->device = newdevice;
61045+ match->mode &= ~GR_DELETED;
61046+
61047+ insert_acl_obj_label(match, subj);
61048+ }
61049+
61050+ return;
61051+}
61052+
61053+static void
61054+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
61055+ const ino_t newinode, const dev_t newdevice,
61056+ struct acl_role_label *role)
61057+{
61058+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
61059+ struct acl_subject_label *match;
61060+
61061+ match = role->subj_hash[index];
61062+
61063+ while (match && (match->inode != oldinode ||
61064+ match->device != olddevice ||
61065+ !(match->mode & GR_DELETED)))
61066+ match = match->next;
61067+
61068+ if (match && (match->inode == oldinode)
61069+ && (match->device == olddevice)
61070+ && (match->mode & GR_DELETED)) {
61071+ if (match->prev == NULL) {
61072+ role->subj_hash[index] = match->next;
61073+ if (match->next != NULL)
61074+ match->next->prev = NULL;
61075+ } else {
61076+ match->prev->next = match->next;
61077+ if (match->next != NULL)
61078+ match->next->prev = match->prev;
61079+ }
61080+ match->prev = NULL;
61081+ match->next = NULL;
61082+ match->inode = newinode;
61083+ match->device = newdevice;
61084+ match->mode &= ~GR_DELETED;
61085+
61086+ insert_acl_subj_label(match, role);
61087+ }
61088+
61089+ return;
61090+}
61091+
61092+static void
61093+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
61094+ const ino_t newinode, const dev_t newdevice)
61095+{
61096+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
61097+ struct inodev_entry *match;
61098+
61099+ match = inodev_set.i_hash[index];
61100+
61101+ while (match && (match->nentry->inode != oldinode ||
61102+ match->nentry->device != olddevice || !match->nentry->deleted))
61103+ match = match->next;
61104+
61105+ if (match && (match->nentry->inode == oldinode)
61106+ && (match->nentry->device == olddevice) &&
61107+ match->nentry->deleted) {
61108+ if (match->prev == NULL) {
61109+ inodev_set.i_hash[index] = match->next;
61110+ if (match->next != NULL)
61111+ match->next->prev = NULL;
61112+ } else {
61113+ match->prev->next = match->next;
61114+ if (match->next != NULL)
61115+ match->next->prev = match->prev;
61116+ }
61117+ match->prev = NULL;
61118+ match->next = NULL;
61119+ match->nentry->inode = newinode;
61120+ match->nentry->device = newdevice;
61121+ match->nentry->deleted = 0;
61122+
61123+ insert_inodev_entry(match);
61124+ }
61125+
61126+ return;
61127+}
61128+
61129+static void
61130+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61131+{
61132+ struct acl_subject_label *subj;
61133+ struct acl_role_label *role;
61134+ unsigned int x;
61135+
61136+ FOR_EACH_ROLE_START(role)
61137+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61138+
61139+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61140+ if ((subj->inode == ino) && (subj->device == dev)) {
61141+ subj->inode = ino;
61142+ subj->device = dev;
61143+ }
61144+ /* nested subjects aren't in the role's subj_hash table */
61145+ update_acl_obj_label(matchn->inode, matchn->device,
61146+ ino, dev, subj);
61147+ FOR_EACH_NESTED_SUBJECT_END(subj)
61148+ FOR_EACH_SUBJECT_START(role, subj, x)
61149+ update_acl_obj_label(matchn->inode, matchn->device,
61150+ ino, dev, subj);
61151+ FOR_EACH_SUBJECT_END(subj,x)
61152+ FOR_EACH_ROLE_END(role)
61153+
61154+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61155+
61156+ return;
61157+}
61158+
61159+static void
61160+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61161+ const struct vfsmount *mnt)
61162+{
61163+ ino_t ino = dentry->d_inode->i_ino;
61164+ dev_t dev = __get_dev(dentry);
61165+
61166+ __do_handle_create(matchn, ino, dev);
61167+
61168+ return;
61169+}
61170+
61171+void
61172+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61173+{
61174+ struct name_entry *matchn;
61175+
61176+ if (unlikely(!(gr_status & GR_READY)))
61177+ return;
61178+
61179+ preempt_disable();
61180+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61181+
61182+ if (unlikely((unsigned long)matchn)) {
61183+ write_lock(&gr_inode_lock);
61184+ do_handle_create(matchn, dentry, mnt);
61185+ write_unlock(&gr_inode_lock);
61186+ }
61187+ preempt_enable();
61188+
61189+ return;
61190+}
61191+
61192+void
61193+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61194+{
61195+ struct name_entry *matchn;
61196+
61197+ if (unlikely(!(gr_status & GR_READY)))
61198+ return;
61199+
61200+ preempt_disable();
61201+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61202+
61203+ if (unlikely((unsigned long)matchn)) {
61204+ write_lock(&gr_inode_lock);
61205+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61206+ write_unlock(&gr_inode_lock);
61207+ }
61208+ preempt_enable();
61209+
61210+ return;
61211+}
61212+
61213+void
61214+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61215+ struct dentry *old_dentry,
61216+ struct dentry *new_dentry,
61217+ struct vfsmount *mnt, const __u8 replace)
61218+{
61219+ struct name_entry *matchn;
61220+ struct inodev_entry *inodev;
61221+ struct inode *inode = new_dentry->d_inode;
61222+ ino_t old_ino = old_dentry->d_inode->i_ino;
61223+ dev_t old_dev = __get_dev(old_dentry);
61224+
61225+ /* vfs_rename swaps the name and parent link for old_dentry and
61226+ new_dentry
61227+ at this point, old_dentry has the new name, parent link, and inode
61228+ for the renamed file
61229+ if a file is being replaced by a rename, new_dentry has the inode
61230+ and name for the replaced file
61231+ */
61232+
61233+ if (unlikely(!(gr_status & GR_READY)))
61234+ return;
61235+
61236+ preempt_disable();
61237+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61238+
61239+ /* we wouldn't have to check d_inode if it weren't for
61240+ NFS silly-renaming
61241+ */
61242+
61243+ write_lock(&gr_inode_lock);
61244+ if (unlikely(replace && inode)) {
61245+ ino_t new_ino = inode->i_ino;
61246+ dev_t new_dev = __get_dev(new_dentry);
61247+
61248+ inodev = lookup_inodev_entry(new_ino, new_dev);
61249+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61250+ do_handle_delete(inodev, new_ino, new_dev);
61251+ }
61252+
61253+ inodev = lookup_inodev_entry(old_ino, old_dev);
61254+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61255+ do_handle_delete(inodev, old_ino, old_dev);
61256+
61257+ if (unlikely((unsigned long)matchn))
61258+ do_handle_create(matchn, old_dentry, mnt);
61259+
61260+ write_unlock(&gr_inode_lock);
61261+ preempt_enable();
61262+
61263+ return;
61264+}
61265+
61266+static int
61267+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61268+ unsigned char **sum)
61269+{
61270+ struct acl_role_label *r;
61271+ struct role_allowed_ip *ipp;
61272+ struct role_transition *trans;
61273+ unsigned int i;
61274+ int found = 0;
61275+ u32 curr_ip = current->signal->curr_ip;
61276+
61277+ current->signal->saved_ip = curr_ip;
61278+
61279+ /* check transition table */
61280+
61281+ for (trans = current->role->transitions; trans; trans = trans->next) {
61282+ if (!strcmp(rolename, trans->rolename)) {
61283+ found = 1;
61284+ break;
61285+ }
61286+ }
61287+
61288+ if (!found)
61289+ return 0;
61290+
61291+ /* handle special roles that do not require authentication
61292+ and check ip */
61293+
61294+ FOR_EACH_ROLE_START(r)
61295+ if (!strcmp(rolename, r->rolename) &&
61296+ (r->roletype & GR_ROLE_SPECIAL)) {
61297+ found = 0;
61298+ if (r->allowed_ips != NULL) {
61299+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61300+ if ((ntohl(curr_ip) & ipp->netmask) ==
61301+ (ntohl(ipp->addr) & ipp->netmask))
61302+ found = 1;
61303+ }
61304+ } else
61305+ found = 2;
61306+ if (!found)
61307+ return 0;
61308+
61309+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61310+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61311+ *salt = NULL;
61312+ *sum = NULL;
61313+ return 1;
61314+ }
61315+ }
61316+ FOR_EACH_ROLE_END(r)
61317+
61318+ for (i = 0; i < num_sprole_pws; i++) {
61319+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61320+ *salt = acl_special_roles[i]->salt;
61321+ *sum = acl_special_roles[i]->sum;
61322+ return 1;
61323+ }
61324+ }
61325+
61326+ return 0;
61327+}
61328+
61329+static void
61330+assign_special_role(char *rolename)
61331+{
61332+ struct acl_object_label *obj;
61333+ struct acl_role_label *r;
61334+ struct acl_role_label *assigned = NULL;
61335+ struct task_struct *tsk;
61336+ struct file *filp;
61337+
61338+ FOR_EACH_ROLE_START(r)
61339+ if (!strcmp(rolename, r->rolename) &&
61340+ (r->roletype & GR_ROLE_SPECIAL)) {
61341+ assigned = r;
61342+ break;
61343+ }
61344+ FOR_EACH_ROLE_END(r)
61345+
61346+ if (!assigned)
61347+ return;
61348+
61349+ read_lock(&tasklist_lock);
61350+ read_lock(&grsec_exec_file_lock);
61351+
61352+ tsk = current->real_parent;
61353+ if (tsk == NULL)
61354+ goto out_unlock;
61355+
61356+ filp = tsk->exec_file;
61357+ if (filp == NULL)
61358+ goto out_unlock;
61359+
61360+ tsk->is_writable = 0;
61361+
61362+ tsk->acl_sp_role = 1;
61363+ tsk->acl_role_id = ++acl_sp_role_value;
61364+ tsk->role = assigned;
61365+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61366+
61367+ /* ignore additional mmap checks for processes that are writable
61368+ by the default ACL */
61369+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61370+ if (unlikely(obj->mode & GR_WRITE))
61371+ tsk->is_writable = 1;
61372+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61373+ if (unlikely(obj->mode & GR_WRITE))
61374+ tsk->is_writable = 1;
61375+
61376+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61377+ 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));
61378+#endif
61379+
61380+out_unlock:
61381+ read_unlock(&grsec_exec_file_lock);
61382+ read_unlock(&tasklist_lock);
61383+ return;
61384+}
61385+
61386+int gr_check_secure_terminal(struct task_struct *task)
61387+{
61388+ struct task_struct *p, *p2, *p3;
61389+ struct files_struct *files;
61390+ struct fdtable *fdt;
61391+ struct file *our_file = NULL, *file;
61392+ int i;
61393+
61394+ if (task->signal->tty == NULL)
61395+ return 1;
61396+
61397+ files = get_files_struct(task);
61398+ if (files != NULL) {
61399+ rcu_read_lock();
61400+ fdt = files_fdtable(files);
61401+ for (i=0; i < fdt->max_fds; i++) {
61402+ file = fcheck_files(files, i);
61403+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61404+ get_file(file);
61405+ our_file = file;
61406+ }
61407+ }
61408+ rcu_read_unlock();
61409+ put_files_struct(files);
61410+ }
61411+
61412+ if (our_file == NULL)
61413+ return 1;
61414+
61415+ read_lock(&tasklist_lock);
61416+ do_each_thread(p2, p) {
61417+ files = get_files_struct(p);
61418+ if (files == NULL ||
61419+ (p->signal && p->signal->tty == task->signal->tty)) {
61420+ if (files != NULL)
61421+ put_files_struct(files);
61422+ continue;
61423+ }
61424+ rcu_read_lock();
61425+ fdt = files_fdtable(files);
61426+ for (i=0; i < fdt->max_fds; i++) {
61427+ file = fcheck_files(files, i);
61428+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61429+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61430+ p3 = task;
61431+ while (task_pid_nr(p3) > 0) {
61432+ if (p3 == p)
61433+ break;
61434+ p3 = p3->real_parent;
61435+ }
61436+ if (p3 == p)
61437+ break;
61438+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61439+ gr_handle_alertkill(p);
61440+ rcu_read_unlock();
61441+ put_files_struct(files);
61442+ read_unlock(&tasklist_lock);
61443+ fput(our_file);
61444+ return 0;
61445+ }
61446+ }
61447+ rcu_read_unlock();
61448+ put_files_struct(files);
61449+ } while_each_thread(p2, p);
61450+ read_unlock(&tasklist_lock);
61451+
61452+ fput(our_file);
61453+ return 1;
61454+}
61455+
61456+static int gr_rbac_disable(void *unused)
61457+{
61458+ pax_open_kernel();
61459+ gr_status &= ~GR_READY;
61460+ pax_close_kernel();
61461+
61462+ return 0;
61463+}
61464+
61465+ssize_t
61466+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61467+{
61468+ struct gr_arg_wrapper uwrap;
61469+ unsigned char *sprole_salt = NULL;
61470+ unsigned char *sprole_sum = NULL;
61471+ int error = sizeof (struct gr_arg_wrapper);
61472+ int error2 = 0;
61473+
61474+ mutex_lock(&gr_dev_mutex);
61475+
61476+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61477+ error = -EPERM;
61478+ goto out;
61479+ }
61480+
61481+ if (count != sizeof (struct gr_arg_wrapper)) {
61482+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61483+ error = -EINVAL;
61484+ goto out;
61485+ }
61486+
61487+
61488+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61489+ gr_auth_expires = 0;
61490+ gr_auth_attempts = 0;
61491+ }
61492+
61493+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61494+ error = -EFAULT;
61495+ goto out;
61496+ }
61497+
61498+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61499+ error = -EINVAL;
61500+ goto out;
61501+ }
61502+
61503+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61504+ error = -EFAULT;
61505+ goto out;
61506+ }
61507+
61508+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61509+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61510+ time_after(gr_auth_expires, get_seconds())) {
61511+ error = -EBUSY;
61512+ goto out;
61513+ }
61514+
61515+ /* if non-root trying to do anything other than use a special role,
61516+ do not attempt authentication, do not count towards authentication
61517+ locking
61518+ */
61519+
61520+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61521+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61522+ gr_is_global_nonroot(current_uid())) {
61523+ error = -EPERM;
61524+ goto out;
61525+ }
61526+
61527+ /* ensure pw and special role name are null terminated */
61528+
61529+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61530+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61531+
61532+ /* Okay.
61533+ * We have our enough of the argument structure..(we have yet
61534+ * to copy_from_user the tables themselves) . Copy the tables
61535+ * only if we need them, i.e. for loading operations. */
61536+
61537+ switch (gr_usermode->mode) {
61538+ case GR_STATUS:
61539+ if (gr_status & GR_READY) {
61540+ error = 1;
61541+ if (!gr_check_secure_terminal(current))
61542+ error = 3;
61543+ } else
61544+ error = 2;
61545+ goto out;
61546+ case GR_SHUTDOWN:
61547+ if ((gr_status & GR_READY)
61548+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61549+ stop_machine(gr_rbac_disable, NULL, NULL);
61550+ free_variables();
61551+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61552+ memset(gr_system_salt, 0, GR_SALT_LEN);
61553+ memset(gr_system_sum, 0, GR_SHA_LEN);
61554+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61555+ } else if (gr_status & GR_READY) {
61556+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61557+ error = -EPERM;
61558+ } else {
61559+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61560+ error = -EAGAIN;
61561+ }
61562+ break;
61563+ case GR_ENABLE:
61564+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61565+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61566+ else {
61567+ if (gr_status & GR_READY)
61568+ error = -EAGAIN;
61569+ else
61570+ error = error2;
61571+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61572+ }
61573+ break;
61574+ case GR_RELOAD:
61575+ if (!(gr_status & GR_READY)) {
61576+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61577+ error = -EAGAIN;
61578+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61579+ stop_machine(gr_rbac_disable, NULL, NULL);
61580+ free_variables();
61581+ error2 = gracl_init(gr_usermode);
61582+ if (!error2)
61583+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61584+ else {
61585+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61586+ error = error2;
61587+ }
61588+ } else {
61589+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61590+ error = -EPERM;
61591+ }
61592+ break;
61593+ case GR_SEGVMOD:
61594+ if (unlikely(!(gr_status & GR_READY))) {
61595+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61596+ error = -EAGAIN;
61597+ break;
61598+ }
61599+
61600+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61601+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61602+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61603+ struct acl_subject_label *segvacl;
61604+ segvacl =
61605+ lookup_acl_subj_label(gr_usermode->segv_inode,
61606+ gr_usermode->segv_device,
61607+ current->role);
61608+ if (segvacl) {
61609+ segvacl->crashes = 0;
61610+ segvacl->expires = 0;
61611+ }
61612+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61613+ gr_remove_uid(gr_usermode->segv_uid);
61614+ }
61615+ } else {
61616+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61617+ error = -EPERM;
61618+ }
61619+ break;
61620+ case GR_SPROLE:
61621+ case GR_SPROLEPAM:
61622+ if (unlikely(!(gr_status & GR_READY))) {
61623+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61624+ error = -EAGAIN;
61625+ break;
61626+ }
61627+
61628+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61629+ current->role->expires = 0;
61630+ current->role->auth_attempts = 0;
61631+ }
61632+
61633+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61634+ time_after(current->role->expires, get_seconds())) {
61635+ error = -EBUSY;
61636+ goto out;
61637+ }
61638+
61639+ if (lookup_special_role_auth
61640+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61641+ && ((!sprole_salt && !sprole_sum)
61642+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61643+ char *p = "";
61644+ assign_special_role(gr_usermode->sp_role);
61645+ read_lock(&tasklist_lock);
61646+ if (current->real_parent)
61647+ p = current->real_parent->role->rolename;
61648+ read_unlock(&tasklist_lock);
61649+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61650+ p, acl_sp_role_value);
61651+ } else {
61652+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61653+ error = -EPERM;
61654+ if(!(current->role->auth_attempts++))
61655+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61656+
61657+ goto out;
61658+ }
61659+ break;
61660+ case GR_UNSPROLE:
61661+ if (unlikely(!(gr_status & GR_READY))) {
61662+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61663+ error = -EAGAIN;
61664+ break;
61665+ }
61666+
61667+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61668+ char *p = "";
61669+ int i = 0;
61670+
61671+ read_lock(&tasklist_lock);
61672+ if (current->real_parent) {
61673+ p = current->real_parent->role->rolename;
61674+ i = current->real_parent->acl_role_id;
61675+ }
61676+ read_unlock(&tasklist_lock);
61677+
61678+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61679+ gr_set_acls(1);
61680+ } else {
61681+ error = -EPERM;
61682+ goto out;
61683+ }
61684+ break;
61685+ default:
61686+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61687+ error = -EINVAL;
61688+ break;
61689+ }
61690+
61691+ if (error != -EPERM)
61692+ goto out;
61693+
61694+ if(!(gr_auth_attempts++))
61695+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61696+
61697+ out:
61698+ mutex_unlock(&gr_dev_mutex);
61699+ return error;
61700+}
61701+
61702+/* must be called with
61703+ rcu_read_lock();
61704+ read_lock(&tasklist_lock);
61705+ read_lock(&grsec_exec_file_lock);
61706+*/
61707+int gr_apply_subject_to_task(struct task_struct *task)
61708+{
61709+ struct acl_object_label *obj;
61710+ char *tmpname;
61711+ struct acl_subject_label *tmpsubj;
61712+ struct file *filp;
61713+ struct name_entry *nmatch;
61714+
61715+ filp = task->exec_file;
61716+ if (filp == NULL)
61717+ return 0;
61718+
61719+ /* the following is to apply the correct subject
61720+ on binaries running when the RBAC system
61721+ is enabled, when the binaries have been
61722+ replaced or deleted since their execution
61723+ -----
61724+ when the RBAC system starts, the inode/dev
61725+ from exec_file will be one the RBAC system
61726+ is unaware of. It only knows the inode/dev
61727+ of the present file on disk, or the absence
61728+ of it.
61729+ */
61730+ preempt_disable();
61731+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61732+
61733+ nmatch = lookup_name_entry(tmpname);
61734+ preempt_enable();
61735+ tmpsubj = NULL;
61736+ if (nmatch) {
61737+ if (nmatch->deleted)
61738+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61739+ else
61740+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61741+ if (tmpsubj != NULL)
61742+ task->acl = tmpsubj;
61743+ }
61744+ if (tmpsubj == NULL)
61745+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61746+ task->role);
61747+ if (task->acl) {
61748+ task->is_writable = 0;
61749+ /* ignore additional mmap checks for processes that are writable
61750+ by the default ACL */
61751+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61752+ if (unlikely(obj->mode & GR_WRITE))
61753+ task->is_writable = 1;
61754+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61755+ if (unlikely(obj->mode & GR_WRITE))
61756+ task->is_writable = 1;
61757+
61758+ gr_set_proc_res(task);
61759+
61760+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61761+ 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);
61762+#endif
61763+ } else {
61764+ return 1;
61765+ }
61766+
61767+ return 0;
61768+}
61769+
61770+int
61771+gr_set_acls(const int type)
61772+{
61773+ struct task_struct *task, *task2;
61774+ struct acl_role_label *role = current->role;
61775+ __u16 acl_role_id = current->acl_role_id;
61776+ const struct cred *cred;
61777+ int ret;
61778+
61779+ rcu_read_lock();
61780+ read_lock(&tasklist_lock);
61781+ read_lock(&grsec_exec_file_lock);
61782+ do_each_thread(task2, task) {
61783+ /* check to see if we're called from the exit handler,
61784+ if so, only replace ACLs that have inherited the admin
61785+ ACL */
61786+
61787+ if (type && (task->role != role ||
61788+ task->acl_role_id != acl_role_id))
61789+ continue;
61790+
61791+ task->acl_role_id = 0;
61792+ task->acl_sp_role = 0;
61793+
61794+ if (task->exec_file) {
61795+ cred = __task_cred(task);
61796+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61797+ ret = gr_apply_subject_to_task(task);
61798+ if (ret) {
61799+ read_unlock(&grsec_exec_file_lock);
61800+ read_unlock(&tasklist_lock);
61801+ rcu_read_unlock();
61802+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61803+ return ret;
61804+ }
61805+ } else {
61806+ // it's a kernel process
61807+ task->role = kernel_role;
61808+ task->acl = kernel_role->root_label;
61809+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61810+ task->acl->mode &= ~GR_PROCFIND;
61811+#endif
61812+ }
61813+ } while_each_thread(task2, task);
61814+ read_unlock(&grsec_exec_file_lock);
61815+ read_unlock(&tasklist_lock);
61816+ rcu_read_unlock();
61817+
61818+ return 0;
61819+}
61820+
61821+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61822+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61823+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61824+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61825+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61826+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61827+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61828+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61829+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61830+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61831+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61832+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61833+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61834+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61835+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61836+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61837+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61838+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61839+};
61840+
61841+void
61842+gr_learn_resource(const struct task_struct *task,
61843+ const int res, const unsigned long wanted, const int gt)
61844+{
61845+ struct acl_subject_label *acl;
61846+ const struct cred *cred;
61847+
61848+ if (unlikely((gr_status & GR_READY) &&
61849+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61850+ goto skip_reslog;
61851+
61852+ gr_log_resource(task, res, wanted, gt);
61853+skip_reslog:
61854+
61855+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61856+ return;
61857+
61858+ acl = task->acl;
61859+
61860+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61861+ !(acl->resmask & (1U << (unsigned short) res))))
61862+ return;
61863+
61864+ if (wanted >= acl->res[res].rlim_cur) {
61865+ unsigned long res_add;
61866+
61867+ res_add = wanted + res_learn_bumps[res];
61868+
61869+ acl->res[res].rlim_cur = res_add;
61870+
61871+ if (wanted > acl->res[res].rlim_max)
61872+ acl->res[res].rlim_max = res_add;
61873+
61874+ /* only log the subject filename, since resource logging is supported for
61875+ single-subject learning only */
61876+ rcu_read_lock();
61877+ cred = __task_cred(task);
61878+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61879+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61880+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61881+ "", (unsigned long) res, &task->signal->saved_ip);
61882+ rcu_read_unlock();
61883+ }
61884+
61885+ return;
61886+}
61887+EXPORT_SYMBOL(gr_learn_resource);
61888+#endif
61889+
61890+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61891+void
61892+pax_set_initial_flags(struct linux_binprm *bprm)
61893+{
61894+ struct task_struct *task = current;
61895+ struct acl_subject_label *proc;
61896+ unsigned long flags;
61897+
61898+ if (unlikely(!(gr_status & GR_READY)))
61899+ return;
61900+
61901+ flags = pax_get_flags(task);
61902+
61903+ proc = task->acl;
61904+
61905+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61906+ flags &= ~MF_PAX_PAGEEXEC;
61907+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61908+ flags &= ~MF_PAX_SEGMEXEC;
61909+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61910+ flags &= ~MF_PAX_RANDMMAP;
61911+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61912+ flags &= ~MF_PAX_EMUTRAMP;
61913+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61914+ flags &= ~MF_PAX_MPROTECT;
61915+
61916+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61917+ flags |= MF_PAX_PAGEEXEC;
61918+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61919+ flags |= MF_PAX_SEGMEXEC;
61920+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61921+ flags |= MF_PAX_RANDMMAP;
61922+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61923+ flags |= MF_PAX_EMUTRAMP;
61924+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61925+ flags |= MF_PAX_MPROTECT;
61926+
61927+ pax_set_flags(task, flags);
61928+
61929+ return;
61930+}
61931+#endif
61932+
61933+int
61934+gr_handle_proc_ptrace(struct task_struct *task)
61935+{
61936+ struct file *filp;
61937+ struct task_struct *tmp = task;
61938+ struct task_struct *curtemp = current;
61939+ __u32 retmode;
61940+
61941+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61942+ if (unlikely(!(gr_status & GR_READY)))
61943+ return 0;
61944+#endif
61945+
61946+ read_lock(&tasklist_lock);
61947+ read_lock(&grsec_exec_file_lock);
61948+ filp = task->exec_file;
61949+
61950+ while (task_pid_nr(tmp) > 0) {
61951+ if (tmp == curtemp)
61952+ break;
61953+ tmp = tmp->real_parent;
61954+ }
61955+
61956+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61957+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61958+ read_unlock(&grsec_exec_file_lock);
61959+ read_unlock(&tasklist_lock);
61960+ return 1;
61961+ }
61962+
61963+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61964+ if (!(gr_status & GR_READY)) {
61965+ read_unlock(&grsec_exec_file_lock);
61966+ read_unlock(&tasklist_lock);
61967+ return 0;
61968+ }
61969+#endif
61970+
61971+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61972+ read_unlock(&grsec_exec_file_lock);
61973+ read_unlock(&tasklist_lock);
61974+
61975+ if (retmode & GR_NOPTRACE)
61976+ return 1;
61977+
61978+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61979+ && (current->acl != task->acl || (current->acl != current->role->root_label
61980+ && task_pid_nr(current) != task_pid_nr(task))))
61981+ return 1;
61982+
61983+ return 0;
61984+}
61985+
61986+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61987+{
61988+ if (unlikely(!(gr_status & GR_READY)))
61989+ return;
61990+
61991+ if (!(current->role->roletype & GR_ROLE_GOD))
61992+ return;
61993+
61994+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61995+ p->role->rolename, gr_task_roletype_to_char(p),
61996+ p->acl->filename);
61997+}
61998+
61999+int
62000+gr_handle_ptrace(struct task_struct *task, const long request)
62001+{
62002+ struct task_struct *tmp = task;
62003+ struct task_struct *curtemp = current;
62004+ __u32 retmode;
62005+
62006+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
62007+ if (unlikely(!(gr_status & GR_READY)))
62008+ return 0;
62009+#endif
62010+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
62011+ read_lock(&tasklist_lock);
62012+ while (task_pid_nr(tmp) > 0) {
62013+ if (tmp == curtemp)
62014+ break;
62015+ tmp = tmp->real_parent;
62016+ }
62017+
62018+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
62019+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
62020+ read_unlock(&tasklist_lock);
62021+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62022+ return 1;
62023+ }
62024+ read_unlock(&tasklist_lock);
62025+ }
62026+
62027+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
62028+ if (!(gr_status & GR_READY))
62029+ return 0;
62030+#endif
62031+
62032+ read_lock(&grsec_exec_file_lock);
62033+ if (unlikely(!task->exec_file)) {
62034+ read_unlock(&grsec_exec_file_lock);
62035+ return 0;
62036+ }
62037+
62038+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
62039+ read_unlock(&grsec_exec_file_lock);
62040+
62041+ if (retmode & GR_NOPTRACE) {
62042+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62043+ return 1;
62044+ }
62045+
62046+ if (retmode & GR_PTRACERD) {
62047+ switch (request) {
62048+ case PTRACE_SEIZE:
62049+ case PTRACE_POKETEXT:
62050+ case PTRACE_POKEDATA:
62051+ case PTRACE_POKEUSR:
62052+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
62053+ case PTRACE_SETREGS:
62054+ case PTRACE_SETFPREGS:
62055+#endif
62056+#ifdef CONFIG_X86
62057+ case PTRACE_SETFPXREGS:
62058+#endif
62059+#ifdef CONFIG_ALTIVEC
62060+ case PTRACE_SETVRREGS:
62061+#endif
62062+ return 1;
62063+ default:
62064+ return 0;
62065+ }
62066+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
62067+ !(current->role->roletype & GR_ROLE_GOD) &&
62068+ (current->acl != task->acl)) {
62069+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
62070+ return 1;
62071+ }
62072+
62073+ return 0;
62074+}
62075+
62076+static int is_writable_mmap(const struct file *filp)
62077+{
62078+ struct task_struct *task = current;
62079+ struct acl_object_label *obj, *obj2;
62080+
62081+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
62082+ !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))) {
62083+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
62084+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
62085+ task->role->root_label);
62086+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
62087+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
62088+ return 1;
62089+ }
62090+ }
62091+ return 0;
62092+}
62093+
62094+int
62095+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
62096+{
62097+ __u32 mode;
62098+
62099+ if (unlikely(!file || !(prot & PROT_EXEC)))
62100+ return 1;
62101+
62102+ if (is_writable_mmap(file))
62103+ return 0;
62104+
62105+ mode =
62106+ gr_search_file(file->f_path.dentry,
62107+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62108+ file->f_path.mnt);
62109+
62110+ if (!gr_tpe_allow(file))
62111+ return 0;
62112+
62113+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62114+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62115+ return 0;
62116+ } else if (unlikely(!(mode & GR_EXEC))) {
62117+ return 0;
62118+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62119+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62120+ return 1;
62121+ }
62122+
62123+ return 1;
62124+}
62125+
62126+int
62127+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62128+{
62129+ __u32 mode;
62130+
62131+ if (unlikely(!file || !(prot & PROT_EXEC)))
62132+ return 1;
62133+
62134+ if (is_writable_mmap(file))
62135+ return 0;
62136+
62137+ mode =
62138+ gr_search_file(file->f_path.dentry,
62139+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62140+ file->f_path.mnt);
62141+
62142+ if (!gr_tpe_allow(file))
62143+ return 0;
62144+
62145+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62146+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62147+ return 0;
62148+ } else if (unlikely(!(mode & GR_EXEC))) {
62149+ return 0;
62150+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62151+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62152+ return 1;
62153+ }
62154+
62155+ return 1;
62156+}
62157+
62158+void
62159+gr_acl_handle_psacct(struct task_struct *task, const long code)
62160+{
62161+ unsigned long runtime;
62162+ unsigned long cputime;
62163+ unsigned int wday, cday;
62164+ __u8 whr, chr;
62165+ __u8 wmin, cmin;
62166+ __u8 wsec, csec;
62167+ struct timespec timeval;
62168+
62169+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62170+ !(task->acl->mode & GR_PROCACCT)))
62171+ return;
62172+
62173+ do_posix_clock_monotonic_gettime(&timeval);
62174+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62175+ wday = runtime / (3600 * 24);
62176+ runtime -= wday * (3600 * 24);
62177+ whr = runtime / 3600;
62178+ runtime -= whr * 3600;
62179+ wmin = runtime / 60;
62180+ runtime -= wmin * 60;
62181+ wsec = runtime;
62182+
62183+ cputime = (task->utime + task->stime) / HZ;
62184+ cday = cputime / (3600 * 24);
62185+ cputime -= cday * (3600 * 24);
62186+ chr = cputime / 3600;
62187+ cputime -= chr * 3600;
62188+ cmin = cputime / 60;
62189+ cputime -= cmin * 60;
62190+ csec = cputime;
62191+
62192+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62193+
62194+ return;
62195+}
62196+
62197+void gr_set_kernel_label(struct task_struct *task)
62198+{
62199+ if (gr_status & GR_READY) {
62200+ task->role = kernel_role;
62201+ task->acl = kernel_role->root_label;
62202+ }
62203+ return;
62204+}
62205+
62206+#ifdef CONFIG_TASKSTATS
62207+int gr_is_taskstats_denied(int pid)
62208+{
62209+ struct task_struct *task;
62210+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62211+ const struct cred *cred;
62212+#endif
62213+ int ret = 0;
62214+
62215+ /* restrict taskstats viewing to un-chrooted root users
62216+ who have the 'view' subject flag if the RBAC system is enabled
62217+ */
62218+
62219+ rcu_read_lock();
62220+ read_lock(&tasklist_lock);
62221+ task = find_task_by_vpid(pid);
62222+ if (task) {
62223+#ifdef CONFIG_GRKERNSEC_CHROOT
62224+ if (proc_is_chrooted(task))
62225+ ret = -EACCES;
62226+#endif
62227+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62228+ cred = __task_cred(task);
62229+#ifdef CONFIG_GRKERNSEC_PROC_USER
62230+ if (gr_is_global_nonroot(cred->uid))
62231+ ret = -EACCES;
62232+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62233+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62234+ ret = -EACCES;
62235+#endif
62236+#endif
62237+ if (gr_status & GR_READY) {
62238+ if (!(task->acl->mode & GR_VIEW))
62239+ ret = -EACCES;
62240+ }
62241+ } else
62242+ ret = -ENOENT;
62243+
62244+ read_unlock(&tasklist_lock);
62245+ rcu_read_unlock();
62246+
62247+ return ret;
62248+}
62249+#endif
62250+
62251+/* AUXV entries are filled via a descendant of search_binary_handler
62252+ after we've already applied the subject for the target
62253+*/
62254+int gr_acl_enable_at_secure(void)
62255+{
62256+ if (unlikely(!(gr_status & GR_READY)))
62257+ return 0;
62258+
62259+ if (current->acl->mode & GR_ATSECURE)
62260+ return 1;
62261+
62262+ return 0;
62263+}
62264+
62265+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62266+{
62267+ struct task_struct *task = current;
62268+ struct dentry *dentry = file->f_path.dentry;
62269+ struct vfsmount *mnt = file->f_path.mnt;
62270+ struct acl_object_label *obj, *tmp;
62271+ struct acl_subject_label *subj;
62272+ unsigned int bufsize;
62273+ int is_not_root;
62274+ char *path;
62275+ dev_t dev = __get_dev(dentry);
62276+
62277+ if (unlikely(!(gr_status & GR_READY)))
62278+ return 1;
62279+
62280+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62281+ return 1;
62282+
62283+ /* ignore Eric Biederman */
62284+ if (IS_PRIVATE(dentry->d_inode))
62285+ return 1;
62286+
62287+ subj = task->acl;
62288+ read_lock(&gr_inode_lock);
62289+ do {
62290+ obj = lookup_acl_obj_label(ino, dev, subj);
62291+ if (obj != NULL) {
62292+ read_unlock(&gr_inode_lock);
62293+ return (obj->mode & GR_FIND) ? 1 : 0;
62294+ }
62295+ } while ((subj = subj->parent_subject));
62296+ read_unlock(&gr_inode_lock);
62297+
62298+ /* this is purely an optimization since we're looking for an object
62299+ for the directory we're doing a readdir on
62300+ if it's possible for any globbed object to match the entry we're
62301+ filling into the directory, then the object we find here will be
62302+ an anchor point with attached globbed objects
62303+ */
62304+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62305+ if (obj->globbed == NULL)
62306+ return (obj->mode & GR_FIND) ? 1 : 0;
62307+
62308+ is_not_root = ((obj->filename[0] == '/') &&
62309+ (obj->filename[1] == '\0')) ? 0 : 1;
62310+ bufsize = PAGE_SIZE - namelen - is_not_root;
62311+
62312+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62313+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62314+ return 1;
62315+
62316+ preempt_disable();
62317+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62318+ bufsize);
62319+
62320+ bufsize = strlen(path);
62321+
62322+ /* if base is "/", don't append an additional slash */
62323+ if (is_not_root)
62324+ *(path + bufsize) = '/';
62325+ memcpy(path + bufsize + is_not_root, name, namelen);
62326+ *(path + bufsize + namelen + is_not_root) = '\0';
62327+
62328+ tmp = obj->globbed;
62329+ while (tmp) {
62330+ if (!glob_match(tmp->filename, path)) {
62331+ preempt_enable();
62332+ return (tmp->mode & GR_FIND) ? 1 : 0;
62333+ }
62334+ tmp = tmp->next;
62335+ }
62336+ preempt_enable();
62337+ return (obj->mode & GR_FIND) ? 1 : 0;
62338+}
62339+
62340+void gr_put_exec_file(struct task_struct *task)
62341+{
62342+ struct file *filp;
62343+
62344+ write_lock(&grsec_exec_file_lock);
62345+ filp = task->exec_file;
62346+ task->exec_file = NULL;
62347+ write_unlock(&grsec_exec_file_lock);
62348+
62349+ if (filp)
62350+ fput(filp);
62351+
62352+ return;
62353+}
62354+
62355+
62356+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62357+EXPORT_SYMBOL(gr_acl_is_enabled);
62358+#endif
62359+EXPORT_SYMBOL(gr_set_kernel_label);
62360+#ifdef CONFIG_SECURITY
62361+EXPORT_SYMBOL(gr_check_user_change);
62362+EXPORT_SYMBOL(gr_check_group_change);
62363+#endif
62364+
62365diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62366new file mode 100644
62367index 0000000..34fefda
62368--- /dev/null
62369+++ b/grsecurity/gracl_alloc.c
62370@@ -0,0 +1,105 @@
62371+#include <linux/kernel.h>
62372+#include <linux/mm.h>
62373+#include <linux/slab.h>
62374+#include <linux/vmalloc.h>
62375+#include <linux/gracl.h>
62376+#include <linux/grsecurity.h>
62377+
62378+static unsigned long alloc_stack_next = 1;
62379+static unsigned long alloc_stack_size = 1;
62380+static void **alloc_stack;
62381+
62382+static __inline__ int
62383+alloc_pop(void)
62384+{
62385+ if (alloc_stack_next == 1)
62386+ return 0;
62387+
62388+ kfree(alloc_stack[alloc_stack_next - 2]);
62389+
62390+ alloc_stack_next--;
62391+
62392+ return 1;
62393+}
62394+
62395+static __inline__ int
62396+alloc_push(void *buf)
62397+{
62398+ if (alloc_stack_next >= alloc_stack_size)
62399+ return 1;
62400+
62401+ alloc_stack[alloc_stack_next - 1] = buf;
62402+
62403+ alloc_stack_next++;
62404+
62405+ return 0;
62406+}
62407+
62408+void *
62409+acl_alloc(unsigned long len)
62410+{
62411+ void *ret = NULL;
62412+
62413+ if (!len || len > PAGE_SIZE)
62414+ goto out;
62415+
62416+ ret = kmalloc(len, GFP_KERNEL);
62417+
62418+ if (ret) {
62419+ if (alloc_push(ret)) {
62420+ kfree(ret);
62421+ ret = NULL;
62422+ }
62423+ }
62424+
62425+out:
62426+ return ret;
62427+}
62428+
62429+void *
62430+acl_alloc_num(unsigned long num, unsigned long len)
62431+{
62432+ if (!len || (num > (PAGE_SIZE / len)))
62433+ return NULL;
62434+
62435+ return acl_alloc(num * len);
62436+}
62437+
62438+void
62439+acl_free_all(void)
62440+{
62441+ if (gr_acl_is_enabled() || !alloc_stack)
62442+ return;
62443+
62444+ while (alloc_pop()) ;
62445+
62446+ if (alloc_stack) {
62447+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62448+ kfree(alloc_stack);
62449+ else
62450+ vfree(alloc_stack);
62451+ }
62452+
62453+ alloc_stack = NULL;
62454+ alloc_stack_size = 1;
62455+ alloc_stack_next = 1;
62456+
62457+ return;
62458+}
62459+
62460+int
62461+acl_alloc_stack_init(unsigned long size)
62462+{
62463+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62464+ alloc_stack =
62465+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62466+ else
62467+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62468+
62469+ alloc_stack_size = size;
62470+
62471+ if (!alloc_stack)
62472+ return 0;
62473+ else
62474+ return 1;
62475+}
62476diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62477new file mode 100644
62478index 0000000..bdd51ea
62479--- /dev/null
62480+++ b/grsecurity/gracl_cap.c
62481@@ -0,0 +1,110 @@
62482+#include <linux/kernel.h>
62483+#include <linux/module.h>
62484+#include <linux/sched.h>
62485+#include <linux/gracl.h>
62486+#include <linux/grsecurity.h>
62487+#include <linux/grinternal.h>
62488+
62489+extern const char *captab_log[];
62490+extern int captab_log_entries;
62491+
62492+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62493+{
62494+ struct acl_subject_label *curracl;
62495+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62496+ kernel_cap_t cap_audit = __cap_empty_set;
62497+
62498+ if (!gr_acl_is_enabled())
62499+ return 1;
62500+
62501+ curracl = task->acl;
62502+
62503+ cap_drop = curracl->cap_lower;
62504+ cap_mask = curracl->cap_mask;
62505+ cap_audit = curracl->cap_invert_audit;
62506+
62507+ while ((curracl = curracl->parent_subject)) {
62508+ /* if the cap isn't specified in the current computed mask but is specified in the
62509+ current level subject, and is lowered in the current level subject, then add
62510+ it to the set of dropped capabilities
62511+ otherwise, add the current level subject's mask to the current computed mask
62512+ */
62513+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62514+ cap_raise(cap_mask, cap);
62515+ if (cap_raised(curracl->cap_lower, cap))
62516+ cap_raise(cap_drop, cap);
62517+ if (cap_raised(curracl->cap_invert_audit, cap))
62518+ cap_raise(cap_audit, cap);
62519+ }
62520+ }
62521+
62522+ if (!cap_raised(cap_drop, cap)) {
62523+ if (cap_raised(cap_audit, cap))
62524+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62525+ return 1;
62526+ }
62527+
62528+ curracl = task->acl;
62529+
62530+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62531+ && cap_raised(cred->cap_effective, cap)) {
62532+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62533+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62534+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62535+ gr_to_filename(task->exec_file->f_path.dentry,
62536+ task->exec_file->f_path.mnt) : curracl->filename,
62537+ curracl->filename, 0UL,
62538+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62539+ return 1;
62540+ }
62541+
62542+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62543+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62544+
62545+ return 0;
62546+}
62547+
62548+int
62549+gr_acl_is_capable(const int cap)
62550+{
62551+ return gr_task_acl_is_capable(current, current_cred(), cap);
62552+}
62553+
62554+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62555+{
62556+ struct acl_subject_label *curracl;
62557+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62558+
62559+ if (!gr_acl_is_enabled())
62560+ return 1;
62561+
62562+ curracl = task->acl;
62563+
62564+ cap_drop = curracl->cap_lower;
62565+ cap_mask = curracl->cap_mask;
62566+
62567+ while ((curracl = curracl->parent_subject)) {
62568+ /* if the cap isn't specified in the current computed mask but is specified in the
62569+ current level subject, and is lowered in the current level subject, then add
62570+ it to the set of dropped capabilities
62571+ otherwise, add the current level subject's mask to the current computed mask
62572+ */
62573+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62574+ cap_raise(cap_mask, cap);
62575+ if (cap_raised(curracl->cap_lower, cap))
62576+ cap_raise(cap_drop, cap);
62577+ }
62578+ }
62579+
62580+ if (!cap_raised(cap_drop, cap))
62581+ return 1;
62582+
62583+ return 0;
62584+}
62585+
62586+int
62587+gr_acl_is_capable_nolog(const int cap)
62588+{
62589+ return gr_task_acl_is_capable_nolog(current, cap);
62590+}
62591+
62592diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62593new file mode 100644
62594index 0000000..a340c17
62595--- /dev/null
62596+++ b/grsecurity/gracl_fs.c
62597@@ -0,0 +1,431 @@
62598+#include <linux/kernel.h>
62599+#include <linux/sched.h>
62600+#include <linux/types.h>
62601+#include <linux/fs.h>
62602+#include <linux/file.h>
62603+#include <linux/stat.h>
62604+#include <linux/grsecurity.h>
62605+#include <linux/grinternal.h>
62606+#include <linux/gracl.h>
62607+
62608+umode_t
62609+gr_acl_umask(void)
62610+{
62611+ if (unlikely(!gr_acl_is_enabled()))
62612+ return 0;
62613+
62614+ return current->role->umask;
62615+}
62616+
62617+__u32
62618+gr_acl_handle_hidden_file(const struct dentry * dentry,
62619+ const struct vfsmount * mnt)
62620+{
62621+ __u32 mode;
62622+
62623+ if (unlikely(!dentry->d_inode))
62624+ return GR_FIND;
62625+
62626+ mode =
62627+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62628+
62629+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62630+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62631+ return mode;
62632+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62633+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62634+ return 0;
62635+ } else if (unlikely(!(mode & GR_FIND)))
62636+ return 0;
62637+
62638+ return GR_FIND;
62639+}
62640+
62641+__u32
62642+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62643+ int acc_mode)
62644+{
62645+ __u32 reqmode = GR_FIND;
62646+ __u32 mode;
62647+
62648+ if (unlikely(!dentry->d_inode))
62649+ return reqmode;
62650+
62651+ if (acc_mode & MAY_APPEND)
62652+ reqmode |= GR_APPEND;
62653+ else if (acc_mode & MAY_WRITE)
62654+ reqmode |= GR_WRITE;
62655+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62656+ reqmode |= GR_READ;
62657+
62658+ mode =
62659+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62660+ mnt);
62661+
62662+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62663+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62664+ reqmode & GR_READ ? " reading" : "",
62665+ reqmode & GR_WRITE ? " writing" : reqmode &
62666+ GR_APPEND ? " appending" : "");
62667+ return reqmode;
62668+ } else
62669+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62670+ {
62671+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62672+ reqmode & GR_READ ? " reading" : "",
62673+ reqmode & GR_WRITE ? " writing" : reqmode &
62674+ GR_APPEND ? " appending" : "");
62675+ return 0;
62676+ } else if (unlikely((mode & reqmode) != reqmode))
62677+ return 0;
62678+
62679+ return reqmode;
62680+}
62681+
62682+__u32
62683+gr_acl_handle_creat(const struct dentry * dentry,
62684+ const struct dentry * p_dentry,
62685+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62686+ const int imode)
62687+{
62688+ __u32 reqmode = GR_WRITE | GR_CREATE;
62689+ __u32 mode;
62690+
62691+ if (acc_mode & MAY_APPEND)
62692+ reqmode |= GR_APPEND;
62693+ // if a directory was required or the directory already exists, then
62694+ // don't count this open as a read
62695+ if ((acc_mode & MAY_READ) &&
62696+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62697+ reqmode |= GR_READ;
62698+ if ((open_flags & O_CREAT) &&
62699+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62700+ reqmode |= GR_SETID;
62701+
62702+ mode =
62703+ gr_check_create(dentry, p_dentry, p_mnt,
62704+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62705+
62706+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62707+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62708+ reqmode & GR_READ ? " reading" : "",
62709+ reqmode & GR_WRITE ? " writing" : reqmode &
62710+ GR_APPEND ? " appending" : "");
62711+ return reqmode;
62712+ } else
62713+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62714+ {
62715+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62716+ reqmode & GR_READ ? " reading" : "",
62717+ reqmode & GR_WRITE ? " writing" : reqmode &
62718+ GR_APPEND ? " appending" : "");
62719+ return 0;
62720+ } else if (unlikely((mode & reqmode) != reqmode))
62721+ return 0;
62722+
62723+ return reqmode;
62724+}
62725+
62726+__u32
62727+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62728+ const int fmode)
62729+{
62730+ __u32 mode, reqmode = GR_FIND;
62731+
62732+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62733+ reqmode |= GR_EXEC;
62734+ if (fmode & S_IWOTH)
62735+ reqmode |= GR_WRITE;
62736+ if (fmode & S_IROTH)
62737+ reqmode |= GR_READ;
62738+
62739+ mode =
62740+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62741+ mnt);
62742+
62743+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62744+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62745+ reqmode & GR_READ ? " reading" : "",
62746+ reqmode & GR_WRITE ? " writing" : "",
62747+ reqmode & GR_EXEC ? " executing" : "");
62748+ return reqmode;
62749+ } else
62750+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62751+ {
62752+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62753+ reqmode & GR_READ ? " reading" : "",
62754+ reqmode & GR_WRITE ? " writing" : "",
62755+ reqmode & GR_EXEC ? " executing" : "");
62756+ return 0;
62757+ } else if (unlikely((mode & reqmode) != reqmode))
62758+ return 0;
62759+
62760+ return reqmode;
62761+}
62762+
62763+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62764+{
62765+ __u32 mode;
62766+
62767+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62768+
62769+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62770+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62771+ return mode;
62772+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62773+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62774+ return 0;
62775+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62776+ return 0;
62777+
62778+ return (reqmode);
62779+}
62780+
62781+__u32
62782+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62783+{
62784+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62785+}
62786+
62787+__u32
62788+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62789+{
62790+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62791+}
62792+
62793+__u32
62794+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62795+{
62796+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62797+}
62798+
62799+__u32
62800+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62801+{
62802+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62803+}
62804+
62805+__u32
62806+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62807+ umode_t *modeptr)
62808+{
62809+ umode_t mode;
62810+
62811+ *modeptr &= ~gr_acl_umask();
62812+ mode = *modeptr;
62813+
62814+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62815+ return 1;
62816+
62817+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62818+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62819+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62820+ GR_CHMOD_ACL_MSG);
62821+ } else {
62822+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62823+ }
62824+}
62825+
62826+__u32
62827+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62828+{
62829+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62830+}
62831+
62832+__u32
62833+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62834+{
62835+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62836+}
62837+
62838+__u32
62839+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62840+{
62841+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62842+}
62843+
62844+__u32
62845+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62846+{
62847+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62848+ GR_UNIXCONNECT_ACL_MSG);
62849+}
62850+
62851+/* hardlinks require at minimum create and link permission,
62852+ any additional privilege required is based on the
62853+ privilege of the file being linked to
62854+*/
62855+__u32
62856+gr_acl_handle_link(const struct dentry * new_dentry,
62857+ const struct dentry * parent_dentry,
62858+ const struct vfsmount * parent_mnt,
62859+ const struct dentry * old_dentry,
62860+ const struct vfsmount * old_mnt, const struct filename *to)
62861+{
62862+ __u32 mode;
62863+ __u32 needmode = GR_CREATE | GR_LINK;
62864+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62865+
62866+ mode =
62867+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62868+ old_mnt);
62869+
62870+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62871+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62872+ return mode;
62873+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62874+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62875+ return 0;
62876+ } else if (unlikely((mode & needmode) != needmode))
62877+ return 0;
62878+
62879+ return 1;
62880+}
62881+
62882+__u32
62883+gr_acl_handle_symlink(const struct dentry * new_dentry,
62884+ const struct dentry * parent_dentry,
62885+ const struct vfsmount * parent_mnt, const struct filename *from)
62886+{
62887+ __u32 needmode = GR_WRITE | GR_CREATE;
62888+ __u32 mode;
62889+
62890+ mode =
62891+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62892+ GR_CREATE | GR_AUDIT_CREATE |
62893+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62894+
62895+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62896+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62897+ return mode;
62898+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62899+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62900+ return 0;
62901+ } else if (unlikely((mode & needmode) != needmode))
62902+ return 0;
62903+
62904+ return (GR_WRITE | GR_CREATE);
62905+}
62906+
62907+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)
62908+{
62909+ __u32 mode;
62910+
62911+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62912+
62913+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62914+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62915+ return mode;
62916+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62917+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62918+ return 0;
62919+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62920+ return 0;
62921+
62922+ return (reqmode);
62923+}
62924+
62925+__u32
62926+gr_acl_handle_mknod(const struct dentry * new_dentry,
62927+ const struct dentry * parent_dentry,
62928+ const struct vfsmount * parent_mnt,
62929+ const int mode)
62930+{
62931+ __u32 reqmode = GR_WRITE | GR_CREATE;
62932+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62933+ reqmode |= GR_SETID;
62934+
62935+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62936+ reqmode, GR_MKNOD_ACL_MSG);
62937+}
62938+
62939+__u32
62940+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62941+ const struct dentry *parent_dentry,
62942+ const struct vfsmount *parent_mnt)
62943+{
62944+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62945+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62946+}
62947+
62948+#define RENAME_CHECK_SUCCESS(old, new) \
62949+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62950+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62951+
62952+int
62953+gr_acl_handle_rename(struct dentry *new_dentry,
62954+ struct dentry *parent_dentry,
62955+ const struct vfsmount *parent_mnt,
62956+ struct dentry *old_dentry,
62957+ struct inode *old_parent_inode,
62958+ struct vfsmount *old_mnt, const struct filename *newname)
62959+{
62960+ __u32 comp1, comp2;
62961+ int error = 0;
62962+
62963+ if (unlikely(!gr_acl_is_enabled()))
62964+ return 0;
62965+
62966+ if (!new_dentry->d_inode) {
62967+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62968+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62969+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62970+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62971+ GR_DELETE | GR_AUDIT_DELETE |
62972+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62973+ GR_SUPPRESS, old_mnt);
62974+ } else {
62975+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62976+ GR_CREATE | GR_DELETE |
62977+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62978+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62979+ GR_SUPPRESS, parent_mnt);
62980+ comp2 =
62981+ gr_search_file(old_dentry,
62982+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62983+ GR_DELETE | GR_AUDIT_DELETE |
62984+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62985+ }
62986+
62987+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62988+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62989+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62990+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62991+ && !(comp2 & GR_SUPPRESS)) {
62992+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62993+ error = -EACCES;
62994+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62995+ error = -EACCES;
62996+
62997+ return error;
62998+}
62999+
63000+void
63001+gr_acl_handle_exit(void)
63002+{
63003+ u16 id;
63004+ char *rolename;
63005+
63006+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
63007+ !(current->role->roletype & GR_ROLE_PERSIST))) {
63008+ id = current->acl_role_id;
63009+ rolename = current->role->rolename;
63010+ gr_set_acls(1);
63011+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
63012+ }
63013+
63014+ gr_put_exec_file(current);
63015+ return;
63016+}
63017+
63018+int
63019+gr_acl_handle_procpidmem(const struct task_struct *task)
63020+{
63021+ if (unlikely(!gr_acl_is_enabled()))
63022+ return 0;
63023+
63024+ if (task != current && task->acl->mode & GR_PROTPROCFD)
63025+ return -EACCES;
63026+
63027+ return 0;
63028+}
63029diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
63030new file mode 100644
63031index 0000000..8132048
63032--- /dev/null
63033+++ b/grsecurity/gracl_ip.c
63034@@ -0,0 +1,387 @@
63035+#include <linux/kernel.h>
63036+#include <asm/uaccess.h>
63037+#include <asm/errno.h>
63038+#include <net/sock.h>
63039+#include <linux/file.h>
63040+#include <linux/fs.h>
63041+#include <linux/net.h>
63042+#include <linux/in.h>
63043+#include <linux/skbuff.h>
63044+#include <linux/ip.h>
63045+#include <linux/udp.h>
63046+#include <linux/types.h>
63047+#include <linux/sched.h>
63048+#include <linux/netdevice.h>
63049+#include <linux/inetdevice.h>
63050+#include <linux/gracl.h>
63051+#include <linux/grsecurity.h>
63052+#include <linux/grinternal.h>
63053+
63054+#define GR_BIND 0x01
63055+#define GR_CONNECT 0x02
63056+#define GR_INVERT 0x04
63057+#define GR_BINDOVERRIDE 0x08
63058+#define GR_CONNECTOVERRIDE 0x10
63059+#define GR_SOCK_FAMILY 0x20
63060+
63061+static const char * gr_protocols[IPPROTO_MAX] = {
63062+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
63063+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
63064+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
63065+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
63066+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
63067+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
63068+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
63069+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
63070+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
63071+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
63072+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
63073+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
63074+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
63075+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
63076+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
63077+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
63078+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
63079+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
63080+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
63081+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
63082+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
63083+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
63084+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
63085+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
63086+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
63087+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
63088+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
63089+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
63090+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
63091+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
63092+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
63093+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
63094+ };
63095+
63096+static const char * gr_socktypes[SOCK_MAX] = {
63097+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
63098+ "unknown:7", "unknown:8", "unknown:9", "packet"
63099+ };
63100+
63101+static const char * gr_sockfamilies[AF_MAX+1] = {
63102+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
63103+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
63104+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
63105+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
63106+ };
63107+
63108+const char *
63109+gr_proto_to_name(unsigned char proto)
63110+{
63111+ return gr_protocols[proto];
63112+}
63113+
63114+const char *
63115+gr_socktype_to_name(unsigned char type)
63116+{
63117+ return gr_socktypes[type];
63118+}
63119+
63120+const char *
63121+gr_sockfamily_to_name(unsigned char family)
63122+{
63123+ return gr_sockfamilies[family];
63124+}
63125+
63126+int
63127+gr_search_socket(const int domain, const int type, const int protocol)
63128+{
63129+ struct acl_subject_label *curr;
63130+ const struct cred *cred = current_cred();
63131+
63132+ if (unlikely(!gr_acl_is_enabled()))
63133+ goto exit;
63134+
63135+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63136+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63137+ goto exit; // let the kernel handle it
63138+
63139+ curr = current->acl;
63140+
63141+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63142+ /* the family is allowed, if this is PF_INET allow it only if
63143+ the extra sock type/protocol checks pass */
63144+ if (domain == PF_INET)
63145+ goto inet_check;
63146+ goto exit;
63147+ } else {
63148+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63149+ __u32 fakeip = 0;
63150+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63151+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63152+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63153+ gr_to_filename(current->exec_file->f_path.dentry,
63154+ current->exec_file->f_path.mnt) :
63155+ curr->filename, curr->filename,
63156+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63157+ &current->signal->saved_ip);
63158+ goto exit;
63159+ }
63160+ goto exit_fail;
63161+ }
63162+
63163+inet_check:
63164+ /* the rest of this checking is for IPv4 only */
63165+ if (!curr->ips)
63166+ goto exit;
63167+
63168+ if ((curr->ip_type & (1U << type)) &&
63169+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63170+ goto exit;
63171+
63172+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63173+ /* we don't place acls on raw sockets , and sometimes
63174+ dgram/ip sockets are opened for ioctl and not
63175+ bind/connect, so we'll fake a bind learn log */
63176+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63177+ __u32 fakeip = 0;
63178+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63179+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63180+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63181+ gr_to_filename(current->exec_file->f_path.dentry,
63182+ current->exec_file->f_path.mnt) :
63183+ curr->filename, curr->filename,
63184+ &fakeip, 0, type,
63185+ protocol, GR_CONNECT, &current->signal->saved_ip);
63186+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63187+ __u32 fakeip = 0;
63188+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63189+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63190+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63191+ gr_to_filename(current->exec_file->f_path.dentry,
63192+ current->exec_file->f_path.mnt) :
63193+ curr->filename, curr->filename,
63194+ &fakeip, 0, type,
63195+ protocol, GR_BIND, &current->signal->saved_ip);
63196+ }
63197+ /* we'll log when they use connect or bind */
63198+ goto exit;
63199+ }
63200+
63201+exit_fail:
63202+ if (domain == PF_INET)
63203+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63204+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63205+ else
63206+#ifndef CONFIG_IPV6
63207+ if (domain != PF_INET6)
63208+#endif
63209+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63210+ gr_socktype_to_name(type), protocol);
63211+
63212+ return 0;
63213+exit:
63214+ return 1;
63215+}
63216+
63217+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)
63218+{
63219+ if ((ip->mode & mode) &&
63220+ (ip_port >= ip->low) &&
63221+ (ip_port <= ip->high) &&
63222+ ((ntohl(ip_addr) & our_netmask) ==
63223+ (ntohl(our_addr) & our_netmask))
63224+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63225+ && (ip->type & (1U << type))) {
63226+ if (ip->mode & GR_INVERT)
63227+ return 2; // specifically denied
63228+ else
63229+ return 1; // allowed
63230+ }
63231+
63232+ return 0; // not specifically allowed, may continue parsing
63233+}
63234+
63235+static int
63236+gr_search_connectbind(const int full_mode, struct sock *sk,
63237+ struct sockaddr_in *addr, const int type)
63238+{
63239+ char iface[IFNAMSIZ] = {0};
63240+ struct acl_subject_label *curr;
63241+ struct acl_ip_label *ip;
63242+ struct inet_sock *isk;
63243+ struct net_device *dev;
63244+ struct in_device *idev;
63245+ unsigned long i;
63246+ int ret;
63247+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63248+ __u32 ip_addr = 0;
63249+ __u32 our_addr;
63250+ __u32 our_netmask;
63251+ char *p;
63252+ __u16 ip_port = 0;
63253+ const struct cred *cred = current_cred();
63254+
63255+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63256+ return 0;
63257+
63258+ curr = current->acl;
63259+ isk = inet_sk(sk);
63260+
63261+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63262+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63263+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63264+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63265+ struct sockaddr_in saddr;
63266+ int err;
63267+
63268+ saddr.sin_family = AF_INET;
63269+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63270+ saddr.sin_port = isk->inet_sport;
63271+
63272+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63273+ if (err)
63274+ return err;
63275+
63276+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63277+ if (err)
63278+ return err;
63279+ }
63280+
63281+ if (!curr->ips)
63282+ return 0;
63283+
63284+ ip_addr = addr->sin_addr.s_addr;
63285+ ip_port = ntohs(addr->sin_port);
63286+
63287+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63288+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63289+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63290+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63291+ gr_to_filename(current->exec_file->f_path.dentry,
63292+ current->exec_file->f_path.mnt) :
63293+ curr->filename, curr->filename,
63294+ &ip_addr, ip_port, type,
63295+ sk->sk_protocol, mode, &current->signal->saved_ip);
63296+ return 0;
63297+ }
63298+
63299+ for (i = 0; i < curr->ip_num; i++) {
63300+ ip = *(curr->ips + i);
63301+ if (ip->iface != NULL) {
63302+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63303+ p = strchr(iface, ':');
63304+ if (p != NULL)
63305+ *p = '\0';
63306+ dev = dev_get_by_name(sock_net(sk), iface);
63307+ if (dev == NULL)
63308+ continue;
63309+ idev = in_dev_get(dev);
63310+ if (idev == NULL) {
63311+ dev_put(dev);
63312+ continue;
63313+ }
63314+ rcu_read_lock();
63315+ for_ifa(idev) {
63316+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63317+ our_addr = ifa->ifa_address;
63318+ our_netmask = 0xffffffff;
63319+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63320+ if (ret == 1) {
63321+ rcu_read_unlock();
63322+ in_dev_put(idev);
63323+ dev_put(dev);
63324+ return 0;
63325+ } else if (ret == 2) {
63326+ rcu_read_unlock();
63327+ in_dev_put(idev);
63328+ dev_put(dev);
63329+ goto denied;
63330+ }
63331+ }
63332+ } endfor_ifa(idev);
63333+ rcu_read_unlock();
63334+ in_dev_put(idev);
63335+ dev_put(dev);
63336+ } else {
63337+ our_addr = ip->addr;
63338+ our_netmask = ip->netmask;
63339+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63340+ if (ret == 1)
63341+ return 0;
63342+ else if (ret == 2)
63343+ goto denied;
63344+ }
63345+ }
63346+
63347+denied:
63348+ if (mode == GR_BIND)
63349+ 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));
63350+ else if (mode == GR_CONNECT)
63351+ 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));
63352+
63353+ return -EACCES;
63354+}
63355+
63356+int
63357+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63358+{
63359+ /* always allow disconnection of dgram sockets with connect */
63360+ if (addr->sin_family == AF_UNSPEC)
63361+ return 0;
63362+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63363+}
63364+
63365+int
63366+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63367+{
63368+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63369+}
63370+
63371+int gr_search_listen(struct socket *sock)
63372+{
63373+ struct sock *sk = sock->sk;
63374+ struct sockaddr_in addr;
63375+
63376+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63377+ addr.sin_port = inet_sk(sk)->inet_sport;
63378+
63379+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63380+}
63381+
63382+int gr_search_accept(struct socket *sock)
63383+{
63384+ struct sock *sk = sock->sk;
63385+ struct sockaddr_in addr;
63386+
63387+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63388+ addr.sin_port = inet_sk(sk)->inet_sport;
63389+
63390+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63391+}
63392+
63393+int
63394+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63395+{
63396+ if (addr)
63397+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63398+ else {
63399+ struct sockaddr_in sin;
63400+ const struct inet_sock *inet = inet_sk(sk);
63401+
63402+ sin.sin_addr.s_addr = inet->inet_daddr;
63403+ sin.sin_port = inet->inet_dport;
63404+
63405+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63406+ }
63407+}
63408+
63409+int
63410+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63411+{
63412+ struct sockaddr_in sin;
63413+
63414+ if (unlikely(skb->len < sizeof (struct udphdr)))
63415+ return 0; // skip this packet
63416+
63417+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63418+ sin.sin_port = udp_hdr(skb)->source;
63419+
63420+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63421+}
63422diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63423new file mode 100644
63424index 0000000..25f54ef
63425--- /dev/null
63426+++ b/grsecurity/gracl_learn.c
63427@@ -0,0 +1,207 @@
63428+#include <linux/kernel.h>
63429+#include <linux/mm.h>
63430+#include <linux/sched.h>
63431+#include <linux/poll.h>
63432+#include <linux/string.h>
63433+#include <linux/file.h>
63434+#include <linux/types.h>
63435+#include <linux/vmalloc.h>
63436+#include <linux/grinternal.h>
63437+
63438+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63439+ size_t count, loff_t *ppos);
63440+extern int gr_acl_is_enabled(void);
63441+
63442+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63443+static int gr_learn_attached;
63444+
63445+/* use a 512k buffer */
63446+#define LEARN_BUFFER_SIZE (512 * 1024)
63447+
63448+static DEFINE_SPINLOCK(gr_learn_lock);
63449+static DEFINE_MUTEX(gr_learn_user_mutex);
63450+
63451+/* we need to maintain two buffers, so that the kernel context of grlearn
63452+ uses a semaphore around the userspace copying, and the other kernel contexts
63453+ use a spinlock when copying into the buffer, since they cannot sleep
63454+*/
63455+static char *learn_buffer;
63456+static char *learn_buffer_user;
63457+static int learn_buffer_len;
63458+static int learn_buffer_user_len;
63459+
63460+static ssize_t
63461+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63462+{
63463+ DECLARE_WAITQUEUE(wait, current);
63464+ ssize_t retval = 0;
63465+
63466+ add_wait_queue(&learn_wait, &wait);
63467+ set_current_state(TASK_INTERRUPTIBLE);
63468+ do {
63469+ mutex_lock(&gr_learn_user_mutex);
63470+ spin_lock(&gr_learn_lock);
63471+ if (learn_buffer_len)
63472+ break;
63473+ spin_unlock(&gr_learn_lock);
63474+ mutex_unlock(&gr_learn_user_mutex);
63475+ if (file->f_flags & O_NONBLOCK) {
63476+ retval = -EAGAIN;
63477+ goto out;
63478+ }
63479+ if (signal_pending(current)) {
63480+ retval = -ERESTARTSYS;
63481+ goto out;
63482+ }
63483+
63484+ schedule();
63485+ } while (1);
63486+
63487+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63488+ learn_buffer_user_len = learn_buffer_len;
63489+ retval = learn_buffer_len;
63490+ learn_buffer_len = 0;
63491+
63492+ spin_unlock(&gr_learn_lock);
63493+
63494+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63495+ retval = -EFAULT;
63496+
63497+ mutex_unlock(&gr_learn_user_mutex);
63498+out:
63499+ set_current_state(TASK_RUNNING);
63500+ remove_wait_queue(&learn_wait, &wait);
63501+ return retval;
63502+}
63503+
63504+static unsigned int
63505+poll_learn(struct file * file, poll_table * wait)
63506+{
63507+ poll_wait(file, &learn_wait, wait);
63508+
63509+ if (learn_buffer_len)
63510+ return (POLLIN | POLLRDNORM);
63511+
63512+ return 0;
63513+}
63514+
63515+void
63516+gr_clear_learn_entries(void)
63517+{
63518+ char *tmp;
63519+
63520+ mutex_lock(&gr_learn_user_mutex);
63521+ spin_lock(&gr_learn_lock);
63522+ tmp = learn_buffer;
63523+ learn_buffer = NULL;
63524+ spin_unlock(&gr_learn_lock);
63525+ if (tmp)
63526+ vfree(tmp);
63527+ if (learn_buffer_user != NULL) {
63528+ vfree(learn_buffer_user);
63529+ learn_buffer_user = NULL;
63530+ }
63531+ learn_buffer_len = 0;
63532+ mutex_unlock(&gr_learn_user_mutex);
63533+
63534+ return;
63535+}
63536+
63537+void
63538+gr_add_learn_entry(const char *fmt, ...)
63539+{
63540+ va_list args;
63541+ unsigned int len;
63542+
63543+ if (!gr_learn_attached)
63544+ return;
63545+
63546+ spin_lock(&gr_learn_lock);
63547+
63548+ /* leave a gap at the end so we know when it's "full" but don't have to
63549+ compute the exact length of the string we're trying to append
63550+ */
63551+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63552+ spin_unlock(&gr_learn_lock);
63553+ wake_up_interruptible(&learn_wait);
63554+ return;
63555+ }
63556+ if (learn_buffer == NULL) {
63557+ spin_unlock(&gr_learn_lock);
63558+ return;
63559+ }
63560+
63561+ va_start(args, fmt);
63562+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63563+ va_end(args);
63564+
63565+ learn_buffer_len += len + 1;
63566+
63567+ spin_unlock(&gr_learn_lock);
63568+ wake_up_interruptible(&learn_wait);
63569+
63570+ return;
63571+}
63572+
63573+static int
63574+open_learn(struct inode *inode, struct file *file)
63575+{
63576+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63577+ return -EBUSY;
63578+ if (file->f_mode & FMODE_READ) {
63579+ int retval = 0;
63580+ mutex_lock(&gr_learn_user_mutex);
63581+ if (learn_buffer == NULL)
63582+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63583+ if (learn_buffer_user == NULL)
63584+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63585+ if (learn_buffer == NULL) {
63586+ retval = -ENOMEM;
63587+ goto out_error;
63588+ }
63589+ if (learn_buffer_user == NULL) {
63590+ retval = -ENOMEM;
63591+ goto out_error;
63592+ }
63593+ learn_buffer_len = 0;
63594+ learn_buffer_user_len = 0;
63595+ gr_learn_attached = 1;
63596+out_error:
63597+ mutex_unlock(&gr_learn_user_mutex);
63598+ return retval;
63599+ }
63600+ return 0;
63601+}
63602+
63603+static int
63604+close_learn(struct inode *inode, struct file *file)
63605+{
63606+ if (file->f_mode & FMODE_READ) {
63607+ char *tmp = NULL;
63608+ mutex_lock(&gr_learn_user_mutex);
63609+ spin_lock(&gr_learn_lock);
63610+ tmp = learn_buffer;
63611+ learn_buffer = NULL;
63612+ spin_unlock(&gr_learn_lock);
63613+ if (tmp)
63614+ vfree(tmp);
63615+ if (learn_buffer_user != NULL) {
63616+ vfree(learn_buffer_user);
63617+ learn_buffer_user = NULL;
63618+ }
63619+ learn_buffer_len = 0;
63620+ learn_buffer_user_len = 0;
63621+ gr_learn_attached = 0;
63622+ mutex_unlock(&gr_learn_user_mutex);
63623+ }
63624+
63625+ return 0;
63626+}
63627+
63628+const struct file_operations grsec_fops = {
63629+ .read = read_learn,
63630+ .write = write_grsec_handler,
63631+ .open = open_learn,
63632+ .release = close_learn,
63633+ .poll = poll_learn,
63634+};
63635diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63636new file mode 100644
63637index 0000000..39645c9
63638--- /dev/null
63639+++ b/grsecurity/gracl_res.c
63640@@ -0,0 +1,68 @@
63641+#include <linux/kernel.h>
63642+#include <linux/sched.h>
63643+#include <linux/gracl.h>
63644+#include <linux/grinternal.h>
63645+
63646+static const char *restab_log[] = {
63647+ [RLIMIT_CPU] = "RLIMIT_CPU",
63648+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63649+ [RLIMIT_DATA] = "RLIMIT_DATA",
63650+ [RLIMIT_STACK] = "RLIMIT_STACK",
63651+ [RLIMIT_CORE] = "RLIMIT_CORE",
63652+ [RLIMIT_RSS] = "RLIMIT_RSS",
63653+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63654+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63655+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63656+ [RLIMIT_AS] = "RLIMIT_AS",
63657+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63658+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63659+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63660+ [RLIMIT_NICE] = "RLIMIT_NICE",
63661+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63662+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63663+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63664+};
63665+
63666+void
63667+gr_log_resource(const struct task_struct *task,
63668+ const int res, const unsigned long wanted, const int gt)
63669+{
63670+ const struct cred *cred;
63671+ unsigned long rlim;
63672+
63673+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63674+ return;
63675+
63676+ // not yet supported resource
63677+ if (unlikely(!restab_log[res]))
63678+ return;
63679+
63680+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63681+ rlim = task_rlimit_max(task, res);
63682+ else
63683+ rlim = task_rlimit(task, res);
63684+
63685+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63686+ return;
63687+
63688+ rcu_read_lock();
63689+ cred = __task_cred(task);
63690+
63691+ if (res == RLIMIT_NPROC &&
63692+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63693+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63694+ goto out_rcu_unlock;
63695+ else if (res == RLIMIT_MEMLOCK &&
63696+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63697+ goto out_rcu_unlock;
63698+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63699+ goto out_rcu_unlock;
63700+ rcu_read_unlock();
63701+
63702+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63703+
63704+ return;
63705+out_rcu_unlock:
63706+ rcu_read_unlock();
63707+ return;
63708+}
63709diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63710new file mode 100644
63711index 0000000..3c38bfe
63712--- /dev/null
63713+++ b/grsecurity/gracl_segv.c
63714@@ -0,0 +1,305 @@
63715+#include <linux/kernel.h>
63716+#include <linux/mm.h>
63717+#include <asm/uaccess.h>
63718+#include <asm/errno.h>
63719+#include <asm/mman.h>
63720+#include <net/sock.h>
63721+#include <linux/file.h>
63722+#include <linux/fs.h>
63723+#include <linux/net.h>
63724+#include <linux/in.h>
63725+#include <linux/slab.h>
63726+#include <linux/types.h>
63727+#include <linux/sched.h>
63728+#include <linux/timer.h>
63729+#include <linux/gracl.h>
63730+#include <linux/grsecurity.h>
63731+#include <linux/grinternal.h>
63732+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63733+#include <linux/magic.h>
63734+#include <linux/pagemap.h>
63735+#include "../fs/btrfs/async-thread.h"
63736+#include "../fs/btrfs/ctree.h"
63737+#include "../fs/btrfs/btrfs_inode.h"
63738+#endif
63739+
63740+static struct crash_uid *uid_set;
63741+static unsigned short uid_used;
63742+static DEFINE_SPINLOCK(gr_uid_lock);
63743+extern rwlock_t gr_inode_lock;
63744+extern struct acl_subject_label *
63745+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63746+ struct acl_role_label *role);
63747+
63748+static inline dev_t __get_dev(const struct dentry *dentry)
63749+{
63750+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63751+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63752+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63753+ else
63754+#endif
63755+ return dentry->d_sb->s_dev;
63756+}
63757+
63758+int
63759+gr_init_uidset(void)
63760+{
63761+ uid_set =
63762+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63763+ uid_used = 0;
63764+
63765+ return uid_set ? 1 : 0;
63766+}
63767+
63768+void
63769+gr_free_uidset(void)
63770+{
63771+ if (uid_set)
63772+ kfree(uid_set);
63773+
63774+ return;
63775+}
63776+
63777+int
63778+gr_find_uid(const uid_t uid)
63779+{
63780+ struct crash_uid *tmp = uid_set;
63781+ uid_t buid;
63782+ int low = 0, high = uid_used - 1, mid;
63783+
63784+ while (high >= low) {
63785+ mid = (low + high) >> 1;
63786+ buid = tmp[mid].uid;
63787+ if (buid == uid)
63788+ return mid;
63789+ if (buid > uid)
63790+ high = mid - 1;
63791+ if (buid < uid)
63792+ low = mid + 1;
63793+ }
63794+
63795+ return -1;
63796+}
63797+
63798+static __inline__ void
63799+gr_insertsort(void)
63800+{
63801+ unsigned short i, j;
63802+ struct crash_uid index;
63803+
63804+ for (i = 1; i < uid_used; i++) {
63805+ index = uid_set[i];
63806+ j = i;
63807+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63808+ uid_set[j] = uid_set[j - 1];
63809+ j--;
63810+ }
63811+ uid_set[j] = index;
63812+ }
63813+
63814+ return;
63815+}
63816+
63817+static __inline__ void
63818+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63819+{
63820+ int loc;
63821+ uid_t uid = GR_GLOBAL_UID(kuid);
63822+
63823+ if (uid_used == GR_UIDTABLE_MAX)
63824+ return;
63825+
63826+ loc = gr_find_uid(uid);
63827+
63828+ if (loc >= 0) {
63829+ uid_set[loc].expires = expires;
63830+ return;
63831+ }
63832+
63833+ uid_set[uid_used].uid = uid;
63834+ uid_set[uid_used].expires = expires;
63835+ uid_used++;
63836+
63837+ gr_insertsort();
63838+
63839+ return;
63840+}
63841+
63842+void
63843+gr_remove_uid(const unsigned short loc)
63844+{
63845+ unsigned short i;
63846+
63847+ for (i = loc + 1; i < uid_used; i++)
63848+ uid_set[i - 1] = uid_set[i];
63849+
63850+ uid_used--;
63851+
63852+ return;
63853+}
63854+
63855+int
63856+gr_check_crash_uid(const kuid_t kuid)
63857+{
63858+ int loc;
63859+ int ret = 0;
63860+ uid_t uid;
63861+
63862+ if (unlikely(!gr_acl_is_enabled()))
63863+ return 0;
63864+
63865+ uid = GR_GLOBAL_UID(kuid);
63866+
63867+ spin_lock(&gr_uid_lock);
63868+ loc = gr_find_uid(uid);
63869+
63870+ if (loc < 0)
63871+ goto out_unlock;
63872+
63873+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63874+ gr_remove_uid(loc);
63875+ else
63876+ ret = 1;
63877+
63878+out_unlock:
63879+ spin_unlock(&gr_uid_lock);
63880+ return ret;
63881+}
63882+
63883+static __inline__ int
63884+proc_is_setxid(const struct cred *cred)
63885+{
63886+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63887+ !uid_eq(cred->uid, cred->fsuid))
63888+ return 1;
63889+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63890+ !gid_eq(cred->gid, cred->fsgid))
63891+ return 1;
63892+
63893+ return 0;
63894+}
63895+
63896+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63897+
63898+void
63899+gr_handle_crash(struct task_struct *task, const int sig)
63900+{
63901+ struct acl_subject_label *curr;
63902+ struct task_struct *tsk, *tsk2;
63903+ const struct cred *cred;
63904+ const struct cred *cred2;
63905+
63906+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63907+ return;
63908+
63909+ if (unlikely(!gr_acl_is_enabled()))
63910+ return;
63911+
63912+ curr = task->acl;
63913+
63914+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63915+ return;
63916+
63917+ if (time_before_eq(curr->expires, get_seconds())) {
63918+ curr->expires = 0;
63919+ curr->crashes = 0;
63920+ }
63921+
63922+ curr->crashes++;
63923+
63924+ if (!curr->expires)
63925+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63926+
63927+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63928+ time_after(curr->expires, get_seconds())) {
63929+ rcu_read_lock();
63930+ cred = __task_cred(task);
63931+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63932+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63933+ spin_lock(&gr_uid_lock);
63934+ gr_insert_uid(cred->uid, curr->expires);
63935+ spin_unlock(&gr_uid_lock);
63936+ curr->expires = 0;
63937+ curr->crashes = 0;
63938+ read_lock(&tasklist_lock);
63939+ do_each_thread(tsk2, tsk) {
63940+ cred2 = __task_cred(tsk);
63941+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63942+ gr_fake_force_sig(SIGKILL, tsk);
63943+ } while_each_thread(tsk2, tsk);
63944+ read_unlock(&tasklist_lock);
63945+ } else {
63946+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63947+ read_lock(&tasklist_lock);
63948+ read_lock(&grsec_exec_file_lock);
63949+ do_each_thread(tsk2, tsk) {
63950+ if (likely(tsk != task)) {
63951+ // if this thread has the same subject as the one that triggered
63952+ // RES_CRASH and it's the same binary, kill it
63953+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
63954+ gr_fake_force_sig(SIGKILL, tsk);
63955+ }
63956+ } while_each_thread(tsk2, tsk);
63957+ read_unlock(&grsec_exec_file_lock);
63958+ read_unlock(&tasklist_lock);
63959+ }
63960+ rcu_read_unlock();
63961+ }
63962+
63963+ return;
63964+}
63965+
63966+int
63967+gr_check_crash_exec(const struct file *filp)
63968+{
63969+ struct acl_subject_label *curr;
63970+
63971+ if (unlikely(!gr_acl_is_enabled()))
63972+ return 0;
63973+
63974+ read_lock(&gr_inode_lock);
63975+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63976+ __get_dev(filp->f_path.dentry),
63977+ current->role);
63978+ read_unlock(&gr_inode_lock);
63979+
63980+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63981+ (!curr->crashes && !curr->expires))
63982+ return 0;
63983+
63984+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63985+ time_after(curr->expires, get_seconds()))
63986+ return 1;
63987+ else if (time_before_eq(curr->expires, get_seconds())) {
63988+ curr->crashes = 0;
63989+ curr->expires = 0;
63990+ }
63991+
63992+ return 0;
63993+}
63994+
63995+void
63996+gr_handle_alertkill(struct task_struct *task)
63997+{
63998+ struct acl_subject_label *curracl;
63999+ __u32 curr_ip;
64000+ struct task_struct *p, *p2;
64001+
64002+ if (unlikely(!gr_acl_is_enabled()))
64003+ return;
64004+
64005+ curracl = task->acl;
64006+ curr_ip = task->signal->curr_ip;
64007+
64008+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
64009+ read_lock(&tasklist_lock);
64010+ do_each_thread(p2, p) {
64011+ if (p->signal->curr_ip == curr_ip)
64012+ gr_fake_force_sig(SIGKILL, p);
64013+ } while_each_thread(p2, p);
64014+ read_unlock(&tasklist_lock);
64015+ } else if (curracl->mode & GR_KILLPROC)
64016+ gr_fake_force_sig(SIGKILL, task);
64017+
64018+ return;
64019+}
64020diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
64021new file mode 100644
64022index 0000000..98011b0
64023--- /dev/null
64024+++ b/grsecurity/gracl_shm.c
64025@@ -0,0 +1,40 @@
64026+#include <linux/kernel.h>
64027+#include <linux/mm.h>
64028+#include <linux/sched.h>
64029+#include <linux/file.h>
64030+#include <linux/ipc.h>
64031+#include <linux/gracl.h>
64032+#include <linux/grsecurity.h>
64033+#include <linux/grinternal.h>
64034+
64035+int
64036+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64037+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64038+{
64039+ struct task_struct *task;
64040+
64041+ if (!gr_acl_is_enabled())
64042+ return 1;
64043+
64044+ rcu_read_lock();
64045+ read_lock(&tasklist_lock);
64046+
64047+ task = find_task_by_vpid(shm_cprid);
64048+
64049+ if (unlikely(!task))
64050+ task = find_task_by_vpid(shm_lapid);
64051+
64052+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
64053+ (task_pid_nr(task) == shm_lapid)) &&
64054+ (task->acl->mode & GR_PROTSHM) &&
64055+ (task->acl != current->acl))) {
64056+ read_unlock(&tasklist_lock);
64057+ rcu_read_unlock();
64058+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
64059+ return 0;
64060+ }
64061+ read_unlock(&tasklist_lock);
64062+ rcu_read_unlock();
64063+
64064+ return 1;
64065+}
64066diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
64067new file mode 100644
64068index 0000000..bc0be01
64069--- /dev/null
64070+++ b/grsecurity/grsec_chdir.c
64071@@ -0,0 +1,19 @@
64072+#include <linux/kernel.h>
64073+#include <linux/sched.h>
64074+#include <linux/fs.h>
64075+#include <linux/file.h>
64076+#include <linux/grsecurity.h>
64077+#include <linux/grinternal.h>
64078+
64079+void
64080+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
64081+{
64082+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
64083+ if ((grsec_enable_chdir && grsec_enable_group &&
64084+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
64085+ !grsec_enable_group)) {
64086+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
64087+ }
64088+#endif
64089+ return;
64090+}
64091diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
64092new file mode 100644
64093index 0000000..bd6e105
64094--- /dev/null
64095+++ b/grsecurity/grsec_chroot.c
64096@@ -0,0 +1,370 @@
64097+#include <linux/kernel.h>
64098+#include <linux/module.h>
64099+#include <linux/sched.h>
64100+#include <linux/file.h>
64101+#include <linux/fs.h>
64102+#include <linux/mount.h>
64103+#include <linux/types.h>
64104+#include "../fs/mount.h"
64105+#include <linux/grsecurity.h>
64106+#include <linux/grinternal.h>
64107+
64108+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64109+static int gr_init_ran;
64110+#endif
64111+
64112+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
64113+{
64114+#ifdef CONFIG_GRKERNSEC
64115+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64116+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
64117+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64118+ && gr_init_ran
64119+#endif
64120+ )
64121+ task->gr_is_chrooted = 1;
64122+ else {
64123+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64124+ if (task_pid_nr(task) == 1 && !gr_init_ran)
64125+ gr_init_ran = 1;
64126+#endif
64127+ task->gr_is_chrooted = 0;
64128+ }
64129+
64130+ task->gr_chroot_dentry = path->dentry;
64131+#endif
64132+ return;
64133+}
64134+
64135+void gr_clear_chroot_entries(struct task_struct *task)
64136+{
64137+#ifdef CONFIG_GRKERNSEC
64138+ task->gr_is_chrooted = 0;
64139+ task->gr_chroot_dentry = NULL;
64140+#endif
64141+ return;
64142+}
64143+
64144+int
64145+gr_handle_chroot_unix(const pid_t pid)
64146+{
64147+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64148+ struct task_struct *p;
64149+
64150+ if (unlikely(!grsec_enable_chroot_unix))
64151+ return 1;
64152+
64153+ if (likely(!proc_is_chrooted(current)))
64154+ return 1;
64155+
64156+ rcu_read_lock();
64157+ read_lock(&tasklist_lock);
64158+ p = find_task_by_vpid_unrestricted(pid);
64159+ if (unlikely(p && !have_same_root(current, p))) {
64160+ read_unlock(&tasklist_lock);
64161+ rcu_read_unlock();
64162+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64163+ return 0;
64164+ }
64165+ read_unlock(&tasklist_lock);
64166+ rcu_read_unlock();
64167+#endif
64168+ return 1;
64169+}
64170+
64171+int
64172+gr_handle_chroot_nice(void)
64173+{
64174+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64175+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64176+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64177+ return -EPERM;
64178+ }
64179+#endif
64180+ return 0;
64181+}
64182+
64183+int
64184+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64185+{
64186+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64187+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64188+ && proc_is_chrooted(current)) {
64189+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64190+ return -EACCES;
64191+ }
64192+#endif
64193+ return 0;
64194+}
64195+
64196+int
64197+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64198+{
64199+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64200+ struct task_struct *p;
64201+ int ret = 0;
64202+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64203+ return ret;
64204+
64205+ read_lock(&tasklist_lock);
64206+ do_each_pid_task(pid, type, p) {
64207+ if (!have_same_root(current, p)) {
64208+ ret = 1;
64209+ goto out;
64210+ }
64211+ } while_each_pid_task(pid, type, p);
64212+out:
64213+ read_unlock(&tasklist_lock);
64214+ return ret;
64215+#endif
64216+ return 0;
64217+}
64218+
64219+int
64220+gr_pid_is_chrooted(struct task_struct *p)
64221+{
64222+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64223+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64224+ return 0;
64225+
64226+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64227+ !have_same_root(current, p)) {
64228+ return 1;
64229+ }
64230+#endif
64231+ return 0;
64232+}
64233+
64234+EXPORT_SYMBOL(gr_pid_is_chrooted);
64235+
64236+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64237+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64238+{
64239+ struct path path, currentroot;
64240+ int ret = 0;
64241+
64242+ path.dentry = (struct dentry *)u_dentry;
64243+ path.mnt = (struct vfsmount *)u_mnt;
64244+ get_fs_root(current->fs, &currentroot);
64245+ if (path_is_under(&path, &currentroot))
64246+ ret = 1;
64247+ path_put(&currentroot);
64248+
64249+ return ret;
64250+}
64251+#endif
64252+
64253+int
64254+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64255+{
64256+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64257+ if (!grsec_enable_chroot_fchdir)
64258+ return 1;
64259+
64260+ if (!proc_is_chrooted(current))
64261+ return 1;
64262+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64263+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64264+ return 0;
64265+ }
64266+#endif
64267+ return 1;
64268+}
64269+
64270+int
64271+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64272+ const time_t shm_createtime)
64273+{
64274+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64275+ struct task_struct *p;
64276+ time_t starttime;
64277+
64278+ if (unlikely(!grsec_enable_chroot_shmat))
64279+ return 1;
64280+
64281+ if (likely(!proc_is_chrooted(current)))
64282+ return 1;
64283+
64284+ rcu_read_lock();
64285+ read_lock(&tasklist_lock);
64286+
64287+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64288+ starttime = p->start_time.tv_sec;
64289+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64290+ if (have_same_root(current, p)) {
64291+ goto allow;
64292+ } else {
64293+ read_unlock(&tasklist_lock);
64294+ rcu_read_unlock();
64295+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64296+ return 0;
64297+ }
64298+ }
64299+ /* creator exited, pid reuse, fall through to next check */
64300+ }
64301+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64302+ if (unlikely(!have_same_root(current, p))) {
64303+ read_unlock(&tasklist_lock);
64304+ rcu_read_unlock();
64305+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64306+ return 0;
64307+ }
64308+ }
64309+
64310+allow:
64311+ read_unlock(&tasklist_lock);
64312+ rcu_read_unlock();
64313+#endif
64314+ return 1;
64315+}
64316+
64317+void
64318+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64319+{
64320+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64321+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64322+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64323+#endif
64324+ return;
64325+}
64326+
64327+int
64328+gr_handle_chroot_mknod(const struct dentry *dentry,
64329+ const struct vfsmount *mnt, const int mode)
64330+{
64331+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64332+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64333+ proc_is_chrooted(current)) {
64334+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64335+ return -EPERM;
64336+ }
64337+#endif
64338+ return 0;
64339+}
64340+
64341+int
64342+gr_handle_chroot_mount(const struct dentry *dentry,
64343+ const struct vfsmount *mnt, const char *dev_name)
64344+{
64345+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64346+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64347+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64348+ return -EPERM;
64349+ }
64350+#endif
64351+ return 0;
64352+}
64353+
64354+int
64355+gr_handle_chroot_pivot(void)
64356+{
64357+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64358+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64359+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64360+ return -EPERM;
64361+ }
64362+#endif
64363+ return 0;
64364+}
64365+
64366+int
64367+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64368+{
64369+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64370+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64371+ !gr_is_outside_chroot(dentry, mnt)) {
64372+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64373+ return -EPERM;
64374+ }
64375+#endif
64376+ return 0;
64377+}
64378+
64379+extern const char *captab_log[];
64380+extern int captab_log_entries;
64381+
64382+int
64383+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64384+{
64385+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64386+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64387+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64388+ if (cap_raised(chroot_caps, cap)) {
64389+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64390+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64391+ }
64392+ return 0;
64393+ }
64394+ }
64395+#endif
64396+ return 1;
64397+}
64398+
64399+int
64400+gr_chroot_is_capable(const int cap)
64401+{
64402+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64403+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64404+#endif
64405+ return 1;
64406+}
64407+
64408+int
64409+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64410+{
64411+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64412+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64413+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64414+ if (cap_raised(chroot_caps, cap)) {
64415+ return 0;
64416+ }
64417+ }
64418+#endif
64419+ return 1;
64420+}
64421+
64422+int
64423+gr_chroot_is_capable_nolog(const int cap)
64424+{
64425+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64426+ return gr_task_chroot_is_capable_nolog(current, cap);
64427+#endif
64428+ return 1;
64429+}
64430+
64431+int
64432+gr_handle_chroot_sysctl(const int op)
64433+{
64434+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64435+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64436+ proc_is_chrooted(current))
64437+ return -EACCES;
64438+#endif
64439+ return 0;
64440+}
64441+
64442+void
64443+gr_handle_chroot_chdir(const struct path *path)
64444+{
64445+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64446+ if (grsec_enable_chroot_chdir)
64447+ set_fs_pwd(current->fs, path);
64448+#endif
64449+ return;
64450+}
64451+
64452+int
64453+gr_handle_chroot_chmod(const struct dentry *dentry,
64454+ const struct vfsmount *mnt, const int mode)
64455+{
64456+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64457+ /* allow chmod +s on directories, but not files */
64458+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64459+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64460+ proc_is_chrooted(current)) {
64461+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64462+ return -EPERM;
64463+ }
64464+#endif
64465+ return 0;
64466+}
64467diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64468new file mode 100644
64469index 0000000..ce65ceb
64470--- /dev/null
64471+++ b/grsecurity/grsec_disabled.c
64472@@ -0,0 +1,434 @@
64473+#include <linux/kernel.h>
64474+#include <linux/module.h>
64475+#include <linux/sched.h>
64476+#include <linux/file.h>
64477+#include <linux/fs.h>
64478+#include <linux/kdev_t.h>
64479+#include <linux/net.h>
64480+#include <linux/in.h>
64481+#include <linux/ip.h>
64482+#include <linux/skbuff.h>
64483+#include <linux/sysctl.h>
64484+
64485+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64486+void
64487+pax_set_initial_flags(struct linux_binprm *bprm)
64488+{
64489+ return;
64490+}
64491+#endif
64492+
64493+#ifdef CONFIG_SYSCTL
64494+__u32
64495+gr_handle_sysctl(const struct ctl_table * table, const int op)
64496+{
64497+ return 0;
64498+}
64499+#endif
64500+
64501+#ifdef CONFIG_TASKSTATS
64502+int gr_is_taskstats_denied(int pid)
64503+{
64504+ return 0;
64505+}
64506+#endif
64507+
64508+int
64509+gr_acl_is_enabled(void)
64510+{
64511+ return 0;
64512+}
64513+
64514+void
64515+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64516+{
64517+ return;
64518+}
64519+
64520+int
64521+gr_handle_rawio(const struct inode *inode)
64522+{
64523+ return 0;
64524+}
64525+
64526+void
64527+gr_acl_handle_psacct(struct task_struct *task, const long code)
64528+{
64529+ return;
64530+}
64531+
64532+int
64533+gr_handle_ptrace(struct task_struct *task, const long request)
64534+{
64535+ return 0;
64536+}
64537+
64538+int
64539+gr_handle_proc_ptrace(struct task_struct *task)
64540+{
64541+ return 0;
64542+}
64543+
64544+int
64545+gr_set_acls(const int type)
64546+{
64547+ return 0;
64548+}
64549+
64550+int
64551+gr_check_hidden_task(const struct task_struct *tsk)
64552+{
64553+ return 0;
64554+}
64555+
64556+int
64557+gr_check_protected_task(const struct task_struct *task)
64558+{
64559+ return 0;
64560+}
64561+
64562+int
64563+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64564+{
64565+ return 0;
64566+}
64567+
64568+void
64569+gr_copy_label(struct task_struct *tsk)
64570+{
64571+ return;
64572+}
64573+
64574+void
64575+gr_set_pax_flags(struct task_struct *task)
64576+{
64577+ return;
64578+}
64579+
64580+int
64581+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64582+ const int unsafe_share)
64583+{
64584+ return 0;
64585+}
64586+
64587+void
64588+gr_handle_delete(const ino_t ino, const dev_t dev)
64589+{
64590+ return;
64591+}
64592+
64593+void
64594+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64595+{
64596+ return;
64597+}
64598+
64599+void
64600+gr_handle_crash(struct task_struct *task, const int sig)
64601+{
64602+ return;
64603+}
64604+
64605+int
64606+gr_check_crash_exec(const struct file *filp)
64607+{
64608+ return 0;
64609+}
64610+
64611+int
64612+gr_check_crash_uid(const kuid_t uid)
64613+{
64614+ return 0;
64615+}
64616+
64617+void
64618+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64619+ struct dentry *old_dentry,
64620+ struct dentry *new_dentry,
64621+ struct vfsmount *mnt, const __u8 replace)
64622+{
64623+ return;
64624+}
64625+
64626+int
64627+gr_search_socket(const int family, const int type, const int protocol)
64628+{
64629+ return 1;
64630+}
64631+
64632+int
64633+gr_search_connectbind(const int mode, const struct socket *sock,
64634+ const struct sockaddr_in *addr)
64635+{
64636+ return 0;
64637+}
64638+
64639+void
64640+gr_handle_alertkill(struct task_struct *task)
64641+{
64642+ return;
64643+}
64644+
64645+__u32
64646+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64647+{
64648+ return 1;
64649+}
64650+
64651+__u32
64652+gr_acl_handle_hidden_file(const struct dentry * dentry,
64653+ const struct vfsmount * mnt)
64654+{
64655+ return 1;
64656+}
64657+
64658+__u32
64659+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64660+ int acc_mode)
64661+{
64662+ return 1;
64663+}
64664+
64665+__u32
64666+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64667+{
64668+ return 1;
64669+}
64670+
64671+__u32
64672+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64673+{
64674+ return 1;
64675+}
64676+
64677+int
64678+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64679+ unsigned int *vm_flags)
64680+{
64681+ return 1;
64682+}
64683+
64684+__u32
64685+gr_acl_handle_truncate(const struct dentry * dentry,
64686+ const struct vfsmount * mnt)
64687+{
64688+ return 1;
64689+}
64690+
64691+__u32
64692+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64693+{
64694+ return 1;
64695+}
64696+
64697+__u32
64698+gr_acl_handle_access(const struct dentry * dentry,
64699+ const struct vfsmount * mnt, const int fmode)
64700+{
64701+ return 1;
64702+}
64703+
64704+__u32
64705+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64706+ umode_t *mode)
64707+{
64708+ return 1;
64709+}
64710+
64711+__u32
64712+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64713+{
64714+ return 1;
64715+}
64716+
64717+__u32
64718+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64719+{
64720+ return 1;
64721+}
64722+
64723+void
64724+grsecurity_init(void)
64725+{
64726+ return;
64727+}
64728+
64729+umode_t gr_acl_umask(void)
64730+{
64731+ return 0;
64732+}
64733+
64734+__u32
64735+gr_acl_handle_mknod(const struct dentry * new_dentry,
64736+ const struct dentry * parent_dentry,
64737+ const struct vfsmount * parent_mnt,
64738+ const int mode)
64739+{
64740+ return 1;
64741+}
64742+
64743+__u32
64744+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64745+ const struct dentry * parent_dentry,
64746+ const struct vfsmount * parent_mnt)
64747+{
64748+ return 1;
64749+}
64750+
64751+__u32
64752+gr_acl_handle_symlink(const struct dentry * new_dentry,
64753+ const struct dentry * parent_dentry,
64754+ const struct vfsmount * parent_mnt, const struct filename *from)
64755+{
64756+ return 1;
64757+}
64758+
64759+__u32
64760+gr_acl_handle_link(const struct dentry * new_dentry,
64761+ const struct dentry * parent_dentry,
64762+ const struct vfsmount * parent_mnt,
64763+ const struct dentry * old_dentry,
64764+ const struct vfsmount * old_mnt, const struct filename *to)
64765+{
64766+ return 1;
64767+}
64768+
64769+int
64770+gr_acl_handle_rename(const struct dentry *new_dentry,
64771+ const struct dentry *parent_dentry,
64772+ const struct vfsmount *parent_mnt,
64773+ const struct dentry *old_dentry,
64774+ const struct inode *old_parent_inode,
64775+ const struct vfsmount *old_mnt, const struct filename *newname)
64776+{
64777+ return 0;
64778+}
64779+
64780+int
64781+gr_acl_handle_filldir(const struct file *file, const char *name,
64782+ const int namelen, const ino_t ino)
64783+{
64784+ return 1;
64785+}
64786+
64787+int
64788+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64789+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64790+{
64791+ return 1;
64792+}
64793+
64794+int
64795+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64796+{
64797+ return 0;
64798+}
64799+
64800+int
64801+gr_search_accept(const struct socket *sock)
64802+{
64803+ return 0;
64804+}
64805+
64806+int
64807+gr_search_listen(const struct socket *sock)
64808+{
64809+ return 0;
64810+}
64811+
64812+int
64813+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64814+{
64815+ return 0;
64816+}
64817+
64818+__u32
64819+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64820+{
64821+ return 1;
64822+}
64823+
64824+__u32
64825+gr_acl_handle_creat(const struct dentry * dentry,
64826+ const struct dentry * p_dentry,
64827+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64828+ const int imode)
64829+{
64830+ return 1;
64831+}
64832+
64833+void
64834+gr_acl_handle_exit(void)
64835+{
64836+ return;
64837+}
64838+
64839+int
64840+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64841+{
64842+ return 1;
64843+}
64844+
64845+void
64846+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64847+{
64848+ return;
64849+}
64850+
64851+int
64852+gr_acl_handle_procpidmem(const struct task_struct *task)
64853+{
64854+ return 0;
64855+}
64856+
64857+int
64858+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64859+{
64860+ return 0;
64861+}
64862+
64863+int
64864+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64865+{
64866+ return 0;
64867+}
64868+
64869+void
64870+gr_set_kernel_label(struct task_struct *task)
64871+{
64872+ return;
64873+}
64874+
64875+int
64876+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64877+{
64878+ return 0;
64879+}
64880+
64881+int
64882+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64883+{
64884+ return 0;
64885+}
64886+
64887+int gr_acl_enable_at_secure(void)
64888+{
64889+ return 0;
64890+}
64891+
64892+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64893+{
64894+ return dentry->d_sb->s_dev;
64895+}
64896+
64897+void gr_put_exec_file(struct task_struct *task)
64898+{
64899+ return;
64900+}
64901+
64902+EXPORT_SYMBOL(gr_set_kernel_label);
64903+#ifdef CONFIG_SECURITY
64904+EXPORT_SYMBOL(gr_check_user_change);
64905+EXPORT_SYMBOL(gr_check_group_change);
64906+#endif
64907diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64908new file mode 100644
64909index 0000000..387032b
64910--- /dev/null
64911+++ b/grsecurity/grsec_exec.c
64912@@ -0,0 +1,187 @@
64913+#include <linux/kernel.h>
64914+#include <linux/sched.h>
64915+#include <linux/file.h>
64916+#include <linux/binfmts.h>
64917+#include <linux/fs.h>
64918+#include <linux/types.h>
64919+#include <linux/grdefs.h>
64920+#include <linux/grsecurity.h>
64921+#include <linux/grinternal.h>
64922+#include <linux/capability.h>
64923+#include <linux/module.h>
64924+#include <linux/compat.h>
64925+
64926+#include <asm/uaccess.h>
64927+
64928+#ifdef CONFIG_GRKERNSEC_EXECLOG
64929+static char gr_exec_arg_buf[132];
64930+static DEFINE_MUTEX(gr_exec_arg_mutex);
64931+#endif
64932+
64933+struct user_arg_ptr {
64934+#ifdef CONFIG_COMPAT
64935+ bool is_compat;
64936+#endif
64937+ union {
64938+ const char __user *const __user *native;
64939+#ifdef CONFIG_COMPAT
64940+ const compat_uptr_t __user *compat;
64941+#endif
64942+ } ptr;
64943+};
64944+
64945+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64946+
64947+void
64948+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64949+{
64950+#ifdef CONFIG_GRKERNSEC_EXECLOG
64951+ char *grarg = gr_exec_arg_buf;
64952+ unsigned int i, x, execlen = 0;
64953+ char c;
64954+
64955+ if (!((grsec_enable_execlog && grsec_enable_group &&
64956+ in_group_p(grsec_audit_gid))
64957+ || (grsec_enable_execlog && !grsec_enable_group)))
64958+ return;
64959+
64960+ mutex_lock(&gr_exec_arg_mutex);
64961+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64962+
64963+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64964+ const char __user *p;
64965+ unsigned int len;
64966+
64967+ p = get_user_arg_ptr(argv, i);
64968+ if (IS_ERR(p))
64969+ goto log;
64970+
64971+ len = strnlen_user(p, 128 - execlen);
64972+ if (len > 128 - execlen)
64973+ len = 128 - execlen;
64974+ else if (len > 0)
64975+ len--;
64976+ if (copy_from_user(grarg + execlen, p, len))
64977+ goto log;
64978+
64979+ /* rewrite unprintable characters */
64980+ for (x = 0; x < len; x++) {
64981+ c = *(grarg + execlen + x);
64982+ if (c < 32 || c > 126)
64983+ *(grarg + execlen + x) = ' ';
64984+ }
64985+
64986+ execlen += len;
64987+ *(grarg + execlen) = ' ';
64988+ *(grarg + execlen + 1) = '\0';
64989+ execlen++;
64990+ }
64991+
64992+ log:
64993+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64994+ bprm->file->f_path.mnt, grarg);
64995+ mutex_unlock(&gr_exec_arg_mutex);
64996+#endif
64997+ return;
64998+}
64999+
65000+#ifdef CONFIG_GRKERNSEC
65001+extern int gr_acl_is_capable(const int cap);
65002+extern int gr_acl_is_capable_nolog(const int cap);
65003+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65004+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
65005+extern int gr_chroot_is_capable(const int cap);
65006+extern int gr_chroot_is_capable_nolog(const int cap);
65007+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65008+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
65009+#endif
65010+
65011+const char *captab_log[] = {
65012+ "CAP_CHOWN",
65013+ "CAP_DAC_OVERRIDE",
65014+ "CAP_DAC_READ_SEARCH",
65015+ "CAP_FOWNER",
65016+ "CAP_FSETID",
65017+ "CAP_KILL",
65018+ "CAP_SETGID",
65019+ "CAP_SETUID",
65020+ "CAP_SETPCAP",
65021+ "CAP_LINUX_IMMUTABLE",
65022+ "CAP_NET_BIND_SERVICE",
65023+ "CAP_NET_BROADCAST",
65024+ "CAP_NET_ADMIN",
65025+ "CAP_NET_RAW",
65026+ "CAP_IPC_LOCK",
65027+ "CAP_IPC_OWNER",
65028+ "CAP_SYS_MODULE",
65029+ "CAP_SYS_RAWIO",
65030+ "CAP_SYS_CHROOT",
65031+ "CAP_SYS_PTRACE",
65032+ "CAP_SYS_PACCT",
65033+ "CAP_SYS_ADMIN",
65034+ "CAP_SYS_BOOT",
65035+ "CAP_SYS_NICE",
65036+ "CAP_SYS_RESOURCE",
65037+ "CAP_SYS_TIME",
65038+ "CAP_SYS_TTY_CONFIG",
65039+ "CAP_MKNOD",
65040+ "CAP_LEASE",
65041+ "CAP_AUDIT_WRITE",
65042+ "CAP_AUDIT_CONTROL",
65043+ "CAP_SETFCAP",
65044+ "CAP_MAC_OVERRIDE",
65045+ "CAP_MAC_ADMIN",
65046+ "CAP_SYSLOG",
65047+ "CAP_WAKE_ALARM"
65048+};
65049+
65050+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
65051+
65052+int gr_is_capable(const int cap)
65053+{
65054+#ifdef CONFIG_GRKERNSEC
65055+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
65056+ return 1;
65057+ return 0;
65058+#else
65059+ return 1;
65060+#endif
65061+}
65062+
65063+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
65064+{
65065+#ifdef CONFIG_GRKERNSEC
65066+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
65067+ return 1;
65068+ return 0;
65069+#else
65070+ return 1;
65071+#endif
65072+}
65073+
65074+int gr_is_capable_nolog(const int cap)
65075+{
65076+#ifdef CONFIG_GRKERNSEC
65077+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
65078+ return 1;
65079+ return 0;
65080+#else
65081+ return 1;
65082+#endif
65083+}
65084+
65085+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
65086+{
65087+#ifdef CONFIG_GRKERNSEC
65088+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
65089+ return 1;
65090+ return 0;
65091+#else
65092+ return 1;
65093+#endif
65094+}
65095+
65096+EXPORT_SYMBOL(gr_is_capable);
65097+EXPORT_SYMBOL(gr_is_capable_nolog);
65098+EXPORT_SYMBOL(gr_task_is_capable);
65099+EXPORT_SYMBOL(gr_task_is_capable_nolog);
65100diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
65101new file mode 100644
65102index 0000000..06cc6ea
65103--- /dev/null
65104+++ b/grsecurity/grsec_fifo.c
65105@@ -0,0 +1,24 @@
65106+#include <linux/kernel.h>
65107+#include <linux/sched.h>
65108+#include <linux/fs.h>
65109+#include <linux/file.h>
65110+#include <linux/grinternal.h>
65111+
65112+int
65113+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
65114+ const struct dentry *dir, const int flag, const int acc_mode)
65115+{
65116+#ifdef CONFIG_GRKERNSEC_FIFO
65117+ const struct cred *cred = current_cred();
65118+
65119+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65120+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65121+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65122+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65123+ if (!inode_permission(dentry->d_inode, acc_mode))
65124+ 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));
65125+ return -EACCES;
65126+ }
65127+#endif
65128+ return 0;
65129+}
65130diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65131new file mode 100644
65132index 0000000..8ca18bf
65133--- /dev/null
65134+++ b/grsecurity/grsec_fork.c
65135@@ -0,0 +1,23 @@
65136+#include <linux/kernel.h>
65137+#include <linux/sched.h>
65138+#include <linux/grsecurity.h>
65139+#include <linux/grinternal.h>
65140+#include <linux/errno.h>
65141+
65142+void
65143+gr_log_forkfail(const int retval)
65144+{
65145+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65146+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65147+ switch (retval) {
65148+ case -EAGAIN:
65149+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65150+ break;
65151+ case -ENOMEM:
65152+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65153+ break;
65154+ }
65155+ }
65156+#endif
65157+ return;
65158+}
65159diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65160new file mode 100644
65161index 0000000..a862e9f
65162--- /dev/null
65163+++ b/grsecurity/grsec_init.c
65164@@ -0,0 +1,283 @@
65165+#include <linux/kernel.h>
65166+#include <linux/sched.h>
65167+#include <linux/mm.h>
65168+#include <linux/gracl.h>
65169+#include <linux/slab.h>
65170+#include <linux/vmalloc.h>
65171+#include <linux/percpu.h>
65172+#include <linux/module.h>
65173+
65174+int grsec_enable_ptrace_readexec;
65175+int grsec_enable_setxid;
65176+int grsec_enable_symlinkown;
65177+kgid_t grsec_symlinkown_gid;
65178+int grsec_enable_brute;
65179+int grsec_enable_link;
65180+int grsec_enable_dmesg;
65181+int grsec_enable_harden_ptrace;
65182+int grsec_enable_fifo;
65183+int grsec_enable_execlog;
65184+int grsec_enable_signal;
65185+int grsec_enable_forkfail;
65186+int grsec_enable_audit_ptrace;
65187+int grsec_enable_time;
65188+int grsec_enable_audit_textrel;
65189+int grsec_enable_group;
65190+kgid_t grsec_audit_gid;
65191+int grsec_enable_chdir;
65192+int grsec_enable_mount;
65193+int grsec_enable_rofs;
65194+int grsec_enable_chroot_findtask;
65195+int grsec_enable_chroot_mount;
65196+int grsec_enable_chroot_shmat;
65197+int grsec_enable_chroot_fchdir;
65198+int grsec_enable_chroot_double;
65199+int grsec_enable_chroot_pivot;
65200+int grsec_enable_chroot_chdir;
65201+int grsec_enable_chroot_chmod;
65202+int grsec_enable_chroot_mknod;
65203+int grsec_enable_chroot_nice;
65204+int grsec_enable_chroot_execlog;
65205+int grsec_enable_chroot_caps;
65206+int grsec_enable_chroot_sysctl;
65207+int grsec_enable_chroot_unix;
65208+int grsec_enable_tpe;
65209+kgid_t grsec_tpe_gid;
65210+int grsec_enable_blackhole;
65211+#ifdef CONFIG_IPV6_MODULE
65212+EXPORT_SYMBOL(grsec_enable_blackhole);
65213+#endif
65214+int grsec_lastack_retries;
65215+int grsec_enable_tpe_all;
65216+int grsec_enable_tpe_invert;
65217+int grsec_enable_socket_all;
65218+kgid_t grsec_socket_all_gid;
65219+int grsec_enable_socket_client;
65220+kgid_t grsec_socket_client_gid;
65221+int grsec_enable_socket_server;
65222+kgid_t grsec_socket_server_gid;
65223+int grsec_resource_logging;
65224+int grsec_disable_privio;
65225+int grsec_enable_log_rwxmaps;
65226+int grsec_lock;
65227+
65228+DEFINE_SPINLOCK(grsec_alert_lock);
65229+unsigned long grsec_alert_wtime = 0;
65230+unsigned long grsec_alert_fyet = 0;
65231+
65232+DEFINE_SPINLOCK(grsec_audit_lock);
65233+
65234+DEFINE_RWLOCK(grsec_exec_file_lock);
65235+
65236+char *gr_shared_page[4];
65237+
65238+char *gr_alert_log_fmt;
65239+char *gr_audit_log_fmt;
65240+char *gr_alert_log_buf;
65241+char *gr_audit_log_buf;
65242+
65243+extern struct gr_arg *gr_usermode;
65244+extern unsigned char *gr_system_salt;
65245+extern unsigned char *gr_system_sum;
65246+
65247+void __init
65248+grsecurity_init(void)
65249+{
65250+ int j;
65251+ /* create the per-cpu shared pages */
65252+
65253+#ifdef CONFIG_X86
65254+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65255+#endif
65256+
65257+ for (j = 0; j < 4; j++) {
65258+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65259+ if (gr_shared_page[j] == NULL) {
65260+ panic("Unable to allocate grsecurity shared page");
65261+ return;
65262+ }
65263+ }
65264+
65265+ /* allocate log buffers */
65266+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65267+ if (!gr_alert_log_fmt) {
65268+ panic("Unable to allocate grsecurity alert log format buffer");
65269+ return;
65270+ }
65271+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65272+ if (!gr_audit_log_fmt) {
65273+ panic("Unable to allocate grsecurity audit log format buffer");
65274+ return;
65275+ }
65276+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65277+ if (!gr_alert_log_buf) {
65278+ panic("Unable to allocate grsecurity alert log buffer");
65279+ return;
65280+ }
65281+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65282+ if (!gr_audit_log_buf) {
65283+ panic("Unable to allocate grsecurity audit log buffer");
65284+ return;
65285+ }
65286+
65287+ /* allocate memory for authentication structure */
65288+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65289+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65290+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65291+
65292+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65293+ panic("Unable to allocate grsecurity authentication structure");
65294+ return;
65295+ }
65296+
65297+
65298+#ifdef CONFIG_GRKERNSEC_IO
65299+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65300+ grsec_disable_privio = 1;
65301+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65302+ grsec_disable_privio = 1;
65303+#else
65304+ grsec_disable_privio = 0;
65305+#endif
65306+#endif
65307+
65308+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65309+ /* for backward compatibility, tpe_invert always defaults to on if
65310+ enabled in the kernel
65311+ */
65312+ grsec_enable_tpe_invert = 1;
65313+#endif
65314+
65315+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65316+#ifndef CONFIG_GRKERNSEC_SYSCTL
65317+ grsec_lock = 1;
65318+#endif
65319+
65320+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65321+ grsec_enable_audit_textrel = 1;
65322+#endif
65323+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65324+ grsec_enable_log_rwxmaps = 1;
65325+#endif
65326+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65327+ grsec_enable_group = 1;
65328+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65329+#endif
65330+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65331+ grsec_enable_ptrace_readexec = 1;
65332+#endif
65333+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65334+ grsec_enable_chdir = 1;
65335+#endif
65336+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65337+ grsec_enable_harden_ptrace = 1;
65338+#endif
65339+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65340+ grsec_enable_mount = 1;
65341+#endif
65342+#ifdef CONFIG_GRKERNSEC_LINK
65343+ grsec_enable_link = 1;
65344+#endif
65345+#ifdef CONFIG_GRKERNSEC_BRUTE
65346+ grsec_enable_brute = 1;
65347+#endif
65348+#ifdef CONFIG_GRKERNSEC_DMESG
65349+ grsec_enable_dmesg = 1;
65350+#endif
65351+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65352+ grsec_enable_blackhole = 1;
65353+ grsec_lastack_retries = 4;
65354+#endif
65355+#ifdef CONFIG_GRKERNSEC_FIFO
65356+ grsec_enable_fifo = 1;
65357+#endif
65358+#ifdef CONFIG_GRKERNSEC_EXECLOG
65359+ grsec_enable_execlog = 1;
65360+#endif
65361+#ifdef CONFIG_GRKERNSEC_SETXID
65362+ grsec_enable_setxid = 1;
65363+#endif
65364+#ifdef CONFIG_GRKERNSEC_SIGNAL
65365+ grsec_enable_signal = 1;
65366+#endif
65367+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65368+ grsec_enable_forkfail = 1;
65369+#endif
65370+#ifdef CONFIG_GRKERNSEC_TIME
65371+ grsec_enable_time = 1;
65372+#endif
65373+#ifdef CONFIG_GRKERNSEC_RESLOG
65374+ grsec_resource_logging = 1;
65375+#endif
65376+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65377+ grsec_enable_chroot_findtask = 1;
65378+#endif
65379+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65380+ grsec_enable_chroot_unix = 1;
65381+#endif
65382+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65383+ grsec_enable_chroot_mount = 1;
65384+#endif
65385+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65386+ grsec_enable_chroot_fchdir = 1;
65387+#endif
65388+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65389+ grsec_enable_chroot_shmat = 1;
65390+#endif
65391+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65392+ grsec_enable_audit_ptrace = 1;
65393+#endif
65394+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65395+ grsec_enable_chroot_double = 1;
65396+#endif
65397+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65398+ grsec_enable_chroot_pivot = 1;
65399+#endif
65400+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65401+ grsec_enable_chroot_chdir = 1;
65402+#endif
65403+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65404+ grsec_enable_chroot_chmod = 1;
65405+#endif
65406+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65407+ grsec_enable_chroot_mknod = 1;
65408+#endif
65409+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65410+ grsec_enable_chroot_nice = 1;
65411+#endif
65412+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65413+ grsec_enable_chroot_execlog = 1;
65414+#endif
65415+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65416+ grsec_enable_chroot_caps = 1;
65417+#endif
65418+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65419+ grsec_enable_chroot_sysctl = 1;
65420+#endif
65421+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65422+ grsec_enable_symlinkown = 1;
65423+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65424+#endif
65425+#ifdef CONFIG_GRKERNSEC_TPE
65426+ grsec_enable_tpe = 1;
65427+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65428+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65429+ grsec_enable_tpe_all = 1;
65430+#endif
65431+#endif
65432+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65433+ grsec_enable_socket_all = 1;
65434+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65435+#endif
65436+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65437+ grsec_enable_socket_client = 1;
65438+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65439+#endif
65440+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65441+ grsec_enable_socket_server = 1;
65442+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65443+#endif
65444+#endif
65445+
65446+ return;
65447+}
65448diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65449new file mode 100644
65450index 0000000..5e05e20
65451--- /dev/null
65452+++ b/grsecurity/grsec_link.c
65453@@ -0,0 +1,58 @@
65454+#include <linux/kernel.h>
65455+#include <linux/sched.h>
65456+#include <linux/fs.h>
65457+#include <linux/file.h>
65458+#include <linux/grinternal.h>
65459+
65460+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65461+{
65462+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65463+ const struct inode *link_inode = link->dentry->d_inode;
65464+
65465+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65466+ /* ignore root-owned links, e.g. /proc/self */
65467+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65468+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65469+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65470+ return 1;
65471+ }
65472+#endif
65473+ return 0;
65474+}
65475+
65476+int
65477+gr_handle_follow_link(const struct inode *parent,
65478+ const struct inode *inode,
65479+ const struct dentry *dentry, const struct vfsmount *mnt)
65480+{
65481+#ifdef CONFIG_GRKERNSEC_LINK
65482+ const struct cred *cred = current_cred();
65483+
65484+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65485+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65486+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65487+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65488+ return -EACCES;
65489+ }
65490+#endif
65491+ return 0;
65492+}
65493+
65494+int
65495+gr_handle_hardlink(const struct dentry *dentry,
65496+ const struct vfsmount *mnt,
65497+ struct inode *inode, const int mode, const struct filename *to)
65498+{
65499+#ifdef CONFIG_GRKERNSEC_LINK
65500+ const struct cred *cred = current_cred();
65501+
65502+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65503+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65504+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65505+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65506+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65507+ return -EPERM;
65508+ }
65509+#endif
65510+ return 0;
65511+}
65512diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65513new file mode 100644
65514index 0000000..7c06085
65515--- /dev/null
65516+++ b/grsecurity/grsec_log.c
65517@@ -0,0 +1,326 @@
65518+#include <linux/kernel.h>
65519+#include <linux/sched.h>
65520+#include <linux/file.h>
65521+#include <linux/tty.h>
65522+#include <linux/fs.h>
65523+#include <linux/grinternal.h>
65524+
65525+#ifdef CONFIG_TREE_PREEMPT_RCU
65526+#define DISABLE_PREEMPT() preempt_disable()
65527+#define ENABLE_PREEMPT() preempt_enable()
65528+#else
65529+#define DISABLE_PREEMPT()
65530+#define ENABLE_PREEMPT()
65531+#endif
65532+
65533+#define BEGIN_LOCKS(x) \
65534+ DISABLE_PREEMPT(); \
65535+ rcu_read_lock(); \
65536+ read_lock(&tasklist_lock); \
65537+ read_lock(&grsec_exec_file_lock); \
65538+ if (x != GR_DO_AUDIT) \
65539+ spin_lock(&grsec_alert_lock); \
65540+ else \
65541+ spin_lock(&grsec_audit_lock)
65542+
65543+#define END_LOCKS(x) \
65544+ if (x != GR_DO_AUDIT) \
65545+ spin_unlock(&grsec_alert_lock); \
65546+ else \
65547+ spin_unlock(&grsec_audit_lock); \
65548+ read_unlock(&grsec_exec_file_lock); \
65549+ read_unlock(&tasklist_lock); \
65550+ rcu_read_unlock(); \
65551+ ENABLE_PREEMPT(); \
65552+ if (x == GR_DONT_AUDIT) \
65553+ gr_handle_alertkill(current)
65554+
65555+enum {
65556+ FLOODING,
65557+ NO_FLOODING
65558+};
65559+
65560+extern char *gr_alert_log_fmt;
65561+extern char *gr_audit_log_fmt;
65562+extern char *gr_alert_log_buf;
65563+extern char *gr_audit_log_buf;
65564+
65565+static int gr_log_start(int audit)
65566+{
65567+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65568+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65569+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65570+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65571+ unsigned long curr_secs = get_seconds();
65572+
65573+ if (audit == GR_DO_AUDIT)
65574+ goto set_fmt;
65575+
65576+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65577+ grsec_alert_wtime = curr_secs;
65578+ grsec_alert_fyet = 0;
65579+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65580+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65581+ grsec_alert_fyet++;
65582+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65583+ grsec_alert_wtime = curr_secs;
65584+ grsec_alert_fyet++;
65585+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65586+ return FLOODING;
65587+ }
65588+ else return FLOODING;
65589+
65590+set_fmt:
65591+#endif
65592+ memset(buf, 0, PAGE_SIZE);
65593+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65594+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65595+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65596+ } else if (current->signal->curr_ip) {
65597+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65598+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65599+ } else if (gr_acl_is_enabled()) {
65600+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65601+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65602+ } else {
65603+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65604+ strcpy(buf, fmt);
65605+ }
65606+
65607+ return NO_FLOODING;
65608+}
65609+
65610+static void gr_log_middle(int audit, const char *msg, va_list ap)
65611+ __attribute__ ((format (printf, 2, 0)));
65612+
65613+static void gr_log_middle(int audit, const char *msg, va_list ap)
65614+{
65615+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65616+ unsigned int len = strlen(buf);
65617+
65618+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65619+
65620+ return;
65621+}
65622+
65623+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65624+ __attribute__ ((format (printf, 2, 3)));
65625+
65626+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65627+{
65628+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65629+ unsigned int len = strlen(buf);
65630+ va_list ap;
65631+
65632+ va_start(ap, msg);
65633+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65634+ va_end(ap);
65635+
65636+ return;
65637+}
65638+
65639+static void gr_log_end(int audit, int append_default)
65640+{
65641+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65642+ if (append_default) {
65643+ struct task_struct *task = current;
65644+ struct task_struct *parent = task->real_parent;
65645+ const struct cred *cred = __task_cred(task);
65646+ const struct cred *pcred = __task_cred(parent);
65647+ unsigned int len = strlen(buf);
65648+
65649+ 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));
65650+ }
65651+
65652+ printk("%s\n", buf);
65653+
65654+ return;
65655+}
65656+
65657+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65658+{
65659+ int logtype;
65660+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65661+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65662+ void *voidptr = NULL;
65663+ int num1 = 0, num2 = 0;
65664+ unsigned long ulong1 = 0, ulong2 = 0;
65665+ struct dentry *dentry = NULL;
65666+ struct vfsmount *mnt = NULL;
65667+ struct file *file = NULL;
65668+ struct task_struct *task = NULL;
65669+ const struct cred *cred, *pcred;
65670+ va_list ap;
65671+
65672+ BEGIN_LOCKS(audit);
65673+ logtype = gr_log_start(audit);
65674+ if (logtype == FLOODING) {
65675+ END_LOCKS(audit);
65676+ return;
65677+ }
65678+ va_start(ap, argtypes);
65679+ switch (argtypes) {
65680+ case GR_TTYSNIFF:
65681+ task = va_arg(ap, struct task_struct *);
65682+ 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));
65683+ break;
65684+ case GR_SYSCTL_HIDDEN:
65685+ str1 = va_arg(ap, char *);
65686+ gr_log_middle_varargs(audit, msg, result, str1);
65687+ break;
65688+ case GR_RBAC:
65689+ dentry = va_arg(ap, struct dentry *);
65690+ mnt = va_arg(ap, struct vfsmount *);
65691+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65692+ break;
65693+ case GR_RBAC_STR:
65694+ dentry = va_arg(ap, struct dentry *);
65695+ mnt = va_arg(ap, struct vfsmount *);
65696+ str1 = va_arg(ap, char *);
65697+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65698+ break;
65699+ case GR_STR_RBAC:
65700+ str1 = va_arg(ap, char *);
65701+ dentry = va_arg(ap, struct dentry *);
65702+ mnt = va_arg(ap, struct vfsmount *);
65703+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65704+ break;
65705+ case GR_RBAC_MODE2:
65706+ dentry = va_arg(ap, struct dentry *);
65707+ mnt = va_arg(ap, struct vfsmount *);
65708+ str1 = va_arg(ap, char *);
65709+ str2 = va_arg(ap, char *);
65710+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65711+ break;
65712+ case GR_RBAC_MODE3:
65713+ dentry = va_arg(ap, struct dentry *);
65714+ mnt = va_arg(ap, struct vfsmount *);
65715+ str1 = va_arg(ap, char *);
65716+ str2 = va_arg(ap, char *);
65717+ str3 = va_arg(ap, char *);
65718+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65719+ break;
65720+ case GR_FILENAME:
65721+ dentry = va_arg(ap, struct dentry *);
65722+ mnt = va_arg(ap, struct vfsmount *);
65723+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65724+ break;
65725+ case GR_STR_FILENAME:
65726+ str1 = va_arg(ap, char *);
65727+ dentry = va_arg(ap, struct dentry *);
65728+ mnt = va_arg(ap, struct vfsmount *);
65729+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65730+ break;
65731+ case GR_FILENAME_STR:
65732+ dentry = va_arg(ap, struct dentry *);
65733+ mnt = va_arg(ap, struct vfsmount *);
65734+ str1 = va_arg(ap, char *);
65735+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65736+ break;
65737+ case GR_FILENAME_TWO_INT:
65738+ dentry = va_arg(ap, struct dentry *);
65739+ mnt = va_arg(ap, struct vfsmount *);
65740+ num1 = va_arg(ap, int);
65741+ num2 = va_arg(ap, int);
65742+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65743+ break;
65744+ case GR_FILENAME_TWO_INT_STR:
65745+ dentry = va_arg(ap, struct dentry *);
65746+ mnt = va_arg(ap, struct vfsmount *);
65747+ num1 = va_arg(ap, int);
65748+ num2 = va_arg(ap, int);
65749+ str1 = va_arg(ap, char *);
65750+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65751+ break;
65752+ case GR_TEXTREL:
65753+ file = va_arg(ap, struct file *);
65754+ ulong1 = va_arg(ap, unsigned long);
65755+ ulong2 = va_arg(ap, unsigned long);
65756+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65757+ break;
65758+ case GR_PTRACE:
65759+ task = va_arg(ap, struct task_struct *);
65760+ 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));
65761+ break;
65762+ case GR_RESOURCE:
65763+ task = va_arg(ap, struct task_struct *);
65764+ cred = __task_cred(task);
65765+ pcred = __task_cred(task->real_parent);
65766+ ulong1 = va_arg(ap, unsigned long);
65767+ str1 = va_arg(ap, char *);
65768+ ulong2 = va_arg(ap, unsigned long);
65769+ 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));
65770+ break;
65771+ case GR_CAP:
65772+ task = va_arg(ap, struct task_struct *);
65773+ cred = __task_cred(task);
65774+ pcred = __task_cred(task->real_parent);
65775+ str1 = va_arg(ap, char *);
65776+ 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));
65777+ break;
65778+ case GR_SIG:
65779+ str1 = va_arg(ap, char *);
65780+ voidptr = va_arg(ap, void *);
65781+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65782+ break;
65783+ case GR_SIG2:
65784+ task = va_arg(ap, struct task_struct *);
65785+ cred = __task_cred(task);
65786+ pcred = __task_cred(task->real_parent);
65787+ num1 = va_arg(ap, int);
65788+ 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));
65789+ break;
65790+ case GR_CRASH1:
65791+ task = va_arg(ap, struct task_struct *);
65792+ cred = __task_cred(task);
65793+ pcred = __task_cred(task->real_parent);
65794+ ulong1 = va_arg(ap, unsigned long);
65795+ 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);
65796+ break;
65797+ case GR_CRASH2:
65798+ task = va_arg(ap, struct task_struct *);
65799+ cred = __task_cred(task);
65800+ pcred = __task_cred(task->real_parent);
65801+ ulong1 = va_arg(ap, unsigned long);
65802+ 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);
65803+ break;
65804+ case GR_RWXMAP:
65805+ file = va_arg(ap, struct file *);
65806+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65807+ break;
65808+ case GR_PSACCT:
65809+ {
65810+ unsigned int wday, cday;
65811+ __u8 whr, chr;
65812+ __u8 wmin, cmin;
65813+ __u8 wsec, csec;
65814+ char cur_tty[64] = { 0 };
65815+ char parent_tty[64] = { 0 };
65816+
65817+ task = va_arg(ap, struct task_struct *);
65818+ wday = va_arg(ap, unsigned int);
65819+ cday = va_arg(ap, unsigned int);
65820+ whr = va_arg(ap, int);
65821+ chr = va_arg(ap, int);
65822+ wmin = va_arg(ap, int);
65823+ cmin = va_arg(ap, int);
65824+ wsec = va_arg(ap, int);
65825+ csec = va_arg(ap, int);
65826+ ulong1 = va_arg(ap, unsigned long);
65827+ cred = __task_cred(task);
65828+ pcred = __task_cred(task->real_parent);
65829+
65830+ 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));
65831+ }
65832+ break;
65833+ default:
65834+ gr_log_middle(audit, msg, ap);
65835+ }
65836+ va_end(ap);
65837+ // these don't need DEFAULTSECARGS printed on the end
65838+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65839+ gr_log_end(audit, 0);
65840+ else
65841+ gr_log_end(audit, 1);
65842+ END_LOCKS(audit);
65843+}
65844diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65845new file mode 100644
65846index 0000000..f536303
65847--- /dev/null
65848+++ b/grsecurity/grsec_mem.c
65849@@ -0,0 +1,40 @@
65850+#include <linux/kernel.h>
65851+#include <linux/sched.h>
65852+#include <linux/mm.h>
65853+#include <linux/mman.h>
65854+#include <linux/grinternal.h>
65855+
65856+void
65857+gr_handle_ioperm(void)
65858+{
65859+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65860+ return;
65861+}
65862+
65863+void
65864+gr_handle_iopl(void)
65865+{
65866+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65867+ return;
65868+}
65869+
65870+void
65871+gr_handle_mem_readwrite(u64 from, u64 to)
65872+{
65873+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65874+ return;
65875+}
65876+
65877+void
65878+gr_handle_vm86(void)
65879+{
65880+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65881+ return;
65882+}
65883+
65884+void
65885+gr_log_badprocpid(const char *entry)
65886+{
65887+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65888+ return;
65889+}
65890diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65891new file mode 100644
65892index 0000000..2131422
65893--- /dev/null
65894+++ b/grsecurity/grsec_mount.c
65895@@ -0,0 +1,62 @@
65896+#include <linux/kernel.h>
65897+#include <linux/sched.h>
65898+#include <linux/mount.h>
65899+#include <linux/grsecurity.h>
65900+#include <linux/grinternal.h>
65901+
65902+void
65903+gr_log_remount(const char *devname, const int retval)
65904+{
65905+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65906+ if (grsec_enable_mount && (retval >= 0))
65907+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65908+#endif
65909+ return;
65910+}
65911+
65912+void
65913+gr_log_unmount(const char *devname, const int retval)
65914+{
65915+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65916+ if (grsec_enable_mount && (retval >= 0))
65917+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65918+#endif
65919+ return;
65920+}
65921+
65922+void
65923+gr_log_mount(const char *from, const char *to, const int retval)
65924+{
65925+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65926+ if (grsec_enable_mount && (retval >= 0))
65927+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65928+#endif
65929+ return;
65930+}
65931+
65932+int
65933+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65934+{
65935+#ifdef CONFIG_GRKERNSEC_ROFS
65936+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65937+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65938+ return -EPERM;
65939+ } else
65940+ return 0;
65941+#endif
65942+ return 0;
65943+}
65944+
65945+int
65946+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65947+{
65948+#ifdef CONFIG_GRKERNSEC_ROFS
65949+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65950+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65951+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65952+ return -EPERM;
65953+ } else
65954+ return 0;
65955+#endif
65956+ return 0;
65957+}
65958diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65959new file mode 100644
65960index 0000000..a3b12a0
65961--- /dev/null
65962+++ b/grsecurity/grsec_pax.c
65963@@ -0,0 +1,36 @@
65964+#include <linux/kernel.h>
65965+#include <linux/sched.h>
65966+#include <linux/mm.h>
65967+#include <linux/file.h>
65968+#include <linux/grinternal.h>
65969+#include <linux/grsecurity.h>
65970+
65971+void
65972+gr_log_textrel(struct vm_area_struct * vma)
65973+{
65974+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65975+ if (grsec_enable_audit_textrel)
65976+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65977+#endif
65978+ return;
65979+}
65980+
65981+void
65982+gr_log_rwxmmap(struct file *file)
65983+{
65984+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65985+ if (grsec_enable_log_rwxmaps)
65986+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65987+#endif
65988+ return;
65989+}
65990+
65991+void
65992+gr_log_rwxmprotect(struct file *file)
65993+{
65994+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65995+ if (grsec_enable_log_rwxmaps)
65996+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65997+#endif
65998+ return;
65999+}
66000diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
66001new file mode 100644
66002index 0000000..f7f29aa
66003--- /dev/null
66004+++ b/grsecurity/grsec_ptrace.c
66005@@ -0,0 +1,30 @@
66006+#include <linux/kernel.h>
66007+#include <linux/sched.h>
66008+#include <linux/grinternal.h>
66009+#include <linux/security.h>
66010+
66011+void
66012+gr_audit_ptrace(struct task_struct *task)
66013+{
66014+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66015+ if (grsec_enable_audit_ptrace)
66016+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
66017+#endif
66018+ return;
66019+}
66020+
66021+int
66022+gr_ptrace_readexec(struct file *file, int unsafe_flags)
66023+{
66024+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66025+ const struct dentry *dentry = file->f_path.dentry;
66026+ const struct vfsmount *mnt = file->f_path.mnt;
66027+
66028+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
66029+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
66030+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
66031+ return -EACCES;
66032+ }
66033+#endif
66034+ return 0;
66035+}
66036diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
66037new file mode 100644
66038index 0000000..4e29cc7
66039--- /dev/null
66040+++ b/grsecurity/grsec_sig.c
66041@@ -0,0 +1,246 @@
66042+#include <linux/kernel.h>
66043+#include <linux/sched.h>
66044+#include <linux/fs.h>
66045+#include <linux/delay.h>
66046+#include <linux/grsecurity.h>
66047+#include <linux/grinternal.h>
66048+#include <linux/hardirq.h>
66049+
66050+char *signames[] = {
66051+ [SIGSEGV] = "Segmentation fault",
66052+ [SIGILL] = "Illegal instruction",
66053+ [SIGABRT] = "Abort",
66054+ [SIGBUS] = "Invalid alignment/Bus error"
66055+};
66056+
66057+void
66058+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
66059+{
66060+#ifdef CONFIG_GRKERNSEC_SIGNAL
66061+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
66062+ (sig == SIGABRT) || (sig == SIGBUS))) {
66063+ if (task_pid_nr(t) == task_pid_nr(current)) {
66064+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
66065+ } else {
66066+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
66067+ }
66068+ }
66069+#endif
66070+ return;
66071+}
66072+
66073+int
66074+gr_handle_signal(const struct task_struct *p, const int sig)
66075+{
66076+#ifdef CONFIG_GRKERNSEC
66077+ /* ignore the 0 signal for protected task checks */
66078+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
66079+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
66080+ return -EPERM;
66081+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
66082+ return -EPERM;
66083+ }
66084+#endif
66085+ return 0;
66086+}
66087+
66088+#ifdef CONFIG_GRKERNSEC
66089+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
66090+
66091+int gr_fake_force_sig(int sig, struct task_struct *t)
66092+{
66093+ unsigned long int flags;
66094+ int ret, blocked, ignored;
66095+ struct k_sigaction *action;
66096+
66097+ spin_lock_irqsave(&t->sighand->siglock, flags);
66098+ action = &t->sighand->action[sig-1];
66099+ ignored = action->sa.sa_handler == SIG_IGN;
66100+ blocked = sigismember(&t->blocked, sig);
66101+ if (blocked || ignored) {
66102+ action->sa.sa_handler = SIG_DFL;
66103+ if (blocked) {
66104+ sigdelset(&t->blocked, sig);
66105+ recalc_sigpending_and_wake(t);
66106+ }
66107+ }
66108+ if (action->sa.sa_handler == SIG_DFL)
66109+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
66110+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
66111+
66112+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
66113+
66114+ return ret;
66115+}
66116+#endif
66117+
66118+#ifdef CONFIG_GRKERNSEC_BRUTE
66119+#define GR_USER_BAN_TIME (15 * 60)
66120+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66121+
66122+static int __get_dumpable(unsigned long mm_flags)
66123+{
66124+ int ret;
66125+
66126+ ret = mm_flags & MMF_DUMPABLE_MASK;
66127+ return (ret >= 2) ? 2 : ret;
66128+}
66129+#endif
66130+
66131+void gr_handle_brute_attach(unsigned long mm_flags)
66132+{
66133+#ifdef CONFIG_GRKERNSEC_BRUTE
66134+ struct task_struct *p = current;
66135+ kuid_t uid = GLOBAL_ROOT_UID;
66136+ int daemon = 0;
66137+
66138+ if (!grsec_enable_brute)
66139+ return;
66140+
66141+ rcu_read_lock();
66142+ read_lock(&tasklist_lock);
66143+ read_lock(&grsec_exec_file_lock);
66144+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
66145+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66146+ p->real_parent->brute = 1;
66147+ daemon = 1;
66148+ } else {
66149+ const struct cred *cred = __task_cred(p), *cred2;
66150+ struct task_struct *tsk, *tsk2;
66151+
66152+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66153+ struct user_struct *user;
66154+
66155+ uid = cred->uid;
66156+
66157+ /* this is put upon execution past expiration */
66158+ user = find_user(uid);
66159+ if (user == NULL)
66160+ goto unlock;
66161+ user->suid_banned = 1;
66162+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
66163+ if (user->suid_ban_expires == ~0UL)
66164+ user->suid_ban_expires--;
66165+
66166+ /* only kill other threads of the same binary, from the same user */
66167+ do_each_thread(tsk2, tsk) {
66168+ cred2 = __task_cred(tsk);
66169+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
66170+ gr_fake_force_sig(SIGKILL, tsk);
66171+ } while_each_thread(tsk2, tsk);
66172+ }
66173+ }
66174+unlock:
66175+ read_unlock(&grsec_exec_file_lock);
66176+ read_unlock(&tasklist_lock);
66177+ rcu_read_unlock();
66178+
66179+ if (gr_is_global_nonroot(uid))
66180+ 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);
66181+ else if (daemon)
66182+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66183+
66184+#endif
66185+ return;
66186+}
66187+
66188+void gr_handle_brute_check(void)
66189+{
66190+#ifdef CONFIG_GRKERNSEC_BRUTE
66191+ struct task_struct *p = current;
66192+
66193+ if (unlikely(p->brute)) {
66194+ if (!grsec_enable_brute)
66195+ p->brute = 0;
66196+ else if (time_before(get_seconds(), p->brute_expires))
66197+ msleep(30 * 1000);
66198+ }
66199+#endif
66200+ return;
66201+}
66202+
66203+void gr_handle_kernel_exploit(void)
66204+{
66205+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66206+ const struct cred *cred;
66207+ struct task_struct *tsk, *tsk2;
66208+ struct user_struct *user;
66209+ kuid_t uid;
66210+
66211+ if (in_irq() || in_serving_softirq() || in_nmi())
66212+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66213+
66214+ uid = current_uid();
66215+
66216+ if (gr_is_global_root(uid))
66217+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66218+ else {
66219+ /* kill all the processes of this user, hold a reference
66220+ to their creds struct, and prevent them from creating
66221+ another process until system reset
66222+ */
66223+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66224+ GR_GLOBAL_UID(uid));
66225+ /* we intentionally leak this ref */
66226+ user = get_uid(current->cred->user);
66227+ if (user)
66228+ user->kernel_banned = 1;
66229+
66230+ /* kill all processes of this user */
66231+ read_lock(&tasklist_lock);
66232+ do_each_thread(tsk2, tsk) {
66233+ cred = __task_cred(tsk);
66234+ if (uid_eq(cred->uid, uid))
66235+ gr_fake_force_sig(SIGKILL, tsk);
66236+ } while_each_thread(tsk2, tsk);
66237+ read_unlock(&tasklist_lock);
66238+ }
66239+#endif
66240+}
66241+
66242+#ifdef CONFIG_GRKERNSEC_BRUTE
66243+static bool suid_ban_expired(struct user_struct *user)
66244+{
66245+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
66246+ user->suid_banned = 0;
66247+ user->suid_ban_expires = 0;
66248+ free_uid(user);
66249+ return true;
66250+ }
66251+
66252+ return false;
66253+}
66254+#endif
66255+
66256+int gr_process_kernel_exec_ban(void)
66257+{
66258+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66259+ if (unlikely(current->cred->user->kernel_banned))
66260+ return -EPERM;
66261+#endif
66262+ return 0;
66263+}
66264+
66265+int gr_process_kernel_setuid_ban(struct user_struct *user)
66266+{
66267+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66268+ if (unlikely(user->kernel_banned))
66269+ gr_fake_force_sig(SIGKILL, current);
66270+#endif
66271+ return 0;
66272+}
66273+
66274+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
66275+{
66276+#ifdef CONFIG_GRKERNSEC_BRUTE
66277+ struct user_struct *user = current->cred->user;
66278+ if (unlikely(user->suid_banned)) {
66279+ if (suid_ban_expired(user))
66280+ return 0;
66281+ /* disallow execution of suid binaries only */
66282+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
66283+ return -EPERM;
66284+ }
66285+#endif
66286+ return 0;
66287+}
66288diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66289new file mode 100644
66290index 0000000..4030d57
66291--- /dev/null
66292+++ b/grsecurity/grsec_sock.c
66293@@ -0,0 +1,244 @@
66294+#include <linux/kernel.h>
66295+#include <linux/module.h>
66296+#include <linux/sched.h>
66297+#include <linux/file.h>
66298+#include <linux/net.h>
66299+#include <linux/in.h>
66300+#include <linux/ip.h>
66301+#include <net/sock.h>
66302+#include <net/inet_sock.h>
66303+#include <linux/grsecurity.h>
66304+#include <linux/grinternal.h>
66305+#include <linux/gracl.h>
66306+
66307+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66308+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66309+
66310+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66311+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66312+
66313+#ifdef CONFIG_UNIX_MODULE
66314+EXPORT_SYMBOL(gr_acl_handle_unix);
66315+EXPORT_SYMBOL(gr_acl_handle_mknod);
66316+EXPORT_SYMBOL(gr_handle_chroot_unix);
66317+EXPORT_SYMBOL(gr_handle_create);
66318+#endif
66319+
66320+#ifdef CONFIG_GRKERNSEC
66321+#define gr_conn_table_size 32749
66322+struct conn_table_entry {
66323+ struct conn_table_entry *next;
66324+ struct signal_struct *sig;
66325+};
66326+
66327+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66328+DEFINE_SPINLOCK(gr_conn_table_lock);
66329+
66330+extern const char * gr_socktype_to_name(unsigned char type);
66331+extern const char * gr_proto_to_name(unsigned char proto);
66332+extern const char * gr_sockfamily_to_name(unsigned char family);
66333+
66334+static __inline__ int
66335+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66336+{
66337+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66338+}
66339+
66340+static __inline__ int
66341+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66342+ __u16 sport, __u16 dport)
66343+{
66344+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66345+ sig->gr_sport == sport && sig->gr_dport == dport))
66346+ return 1;
66347+ else
66348+ return 0;
66349+}
66350+
66351+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66352+{
66353+ struct conn_table_entry **match;
66354+ unsigned int index;
66355+
66356+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66357+ sig->gr_sport, sig->gr_dport,
66358+ gr_conn_table_size);
66359+
66360+ newent->sig = sig;
66361+
66362+ match = &gr_conn_table[index];
66363+ newent->next = *match;
66364+ *match = newent;
66365+
66366+ return;
66367+}
66368+
66369+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66370+{
66371+ struct conn_table_entry *match, *last = NULL;
66372+ unsigned int index;
66373+
66374+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66375+ sig->gr_sport, sig->gr_dport,
66376+ gr_conn_table_size);
66377+
66378+ match = gr_conn_table[index];
66379+ while (match && !conn_match(match->sig,
66380+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66381+ sig->gr_dport)) {
66382+ last = match;
66383+ match = match->next;
66384+ }
66385+
66386+ if (match) {
66387+ if (last)
66388+ last->next = match->next;
66389+ else
66390+ gr_conn_table[index] = NULL;
66391+ kfree(match);
66392+ }
66393+
66394+ return;
66395+}
66396+
66397+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66398+ __u16 sport, __u16 dport)
66399+{
66400+ struct conn_table_entry *match;
66401+ unsigned int index;
66402+
66403+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66404+
66405+ match = gr_conn_table[index];
66406+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66407+ match = match->next;
66408+
66409+ if (match)
66410+ return match->sig;
66411+ else
66412+ return NULL;
66413+}
66414+
66415+#endif
66416+
66417+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66418+{
66419+#ifdef CONFIG_GRKERNSEC
66420+ struct signal_struct *sig = task->signal;
66421+ struct conn_table_entry *newent;
66422+
66423+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66424+ if (newent == NULL)
66425+ return;
66426+ /* no bh lock needed since we are called with bh disabled */
66427+ spin_lock(&gr_conn_table_lock);
66428+ gr_del_task_from_ip_table_nolock(sig);
66429+ sig->gr_saddr = inet->inet_rcv_saddr;
66430+ sig->gr_daddr = inet->inet_daddr;
66431+ sig->gr_sport = inet->inet_sport;
66432+ sig->gr_dport = inet->inet_dport;
66433+ gr_add_to_task_ip_table_nolock(sig, newent);
66434+ spin_unlock(&gr_conn_table_lock);
66435+#endif
66436+ return;
66437+}
66438+
66439+void gr_del_task_from_ip_table(struct task_struct *task)
66440+{
66441+#ifdef CONFIG_GRKERNSEC
66442+ spin_lock_bh(&gr_conn_table_lock);
66443+ gr_del_task_from_ip_table_nolock(task->signal);
66444+ spin_unlock_bh(&gr_conn_table_lock);
66445+#endif
66446+ return;
66447+}
66448+
66449+void
66450+gr_attach_curr_ip(const struct sock *sk)
66451+{
66452+#ifdef CONFIG_GRKERNSEC
66453+ struct signal_struct *p, *set;
66454+ const struct inet_sock *inet = inet_sk(sk);
66455+
66456+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66457+ return;
66458+
66459+ set = current->signal;
66460+
66461+ spin_lock_bh(&gr_conn_table_lock);
66462+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66463+ inet->inet_dport, inet->inet_sport);
66464+ if (unlikely(p != NULL)) {
66465+ set->curr_ip = p->curr_ip;
66466+ set->used_accept = 1;
66467+ gr_del_task_from_ip_table_nolock(p);
66468+ spin_unlock_bh(&gr_conn_table_lock);
66469+ return;
66470+ }
66471+ spin_unlock_bh(&gr_conn_table_lock);
66472+
66473+ set->curr_ip = inet->inet_daddr;
66474+ set->used_accept = 1;
66475+#endif
66476+ return;
66477+}
66478+
66479+int
66480+gr_handle_sock_all(const int family, const int type, const int protocol)
66481+{
66482+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66483+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66484+ (family != AF_UNIX)) {
66485+ if (family == AF_INET)
66486+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66487+ else
66488+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66489+ return -EACCES;
66490+ }
66491+#endif
66492+ return 0;
66493+}
66494+
66495+int
66496+gr_handle_sock_server(const struct sockaddr *sck)
66497+{
66498+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66499+ if (grsec_enable_socket_server &&
66500+ in_group_p(grsec_socket_server_gid) &&
66501+ sck && (sck->sa_family != AF_UNIX) &&
66502+ (sck->sa_family != AF_LOCAL)) {
66503+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66504+ return -EACCES;
66505+ }
66506+#endif
66507+ return 0;
66508+}
66509+
66510+int
66511+gr_handle_sock_server_other(const struct sock *sck)
66512+{
66513+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66514+ if (grsec_enable_socket_server &&
66515+ in_group_p(grsec_socket_server_gid) &&
66516+ sck && (sck->sk_family != AF_UNIX) &&
66517+ (sck->sk_family != AF_LOCAL)) {
66518+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66519+ return -EACCES;
66520+ }
66521+#endif
66522+ return 0;
66523+}
66524+
66525+int
66526+gr_handle_sock_client(const struct sockaddr *sck)
66527+{
66528+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66529+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66530+ sck && (sck->sa_family != AF_UNIX) &&
66531+ (sck->sa_family != AF_LOCAL)) {
66532+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66533+ return -EACCES;
66534+ }
66535+#endif
66536+ return 0;
66537+}
66538diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66539new file mode 100644
66540index 0000000..f55ef0f
66541--- /dev/null
66542+++ b/grsecurity/grsec_sysctl.c
66543@@ -0,0 +1,469 @@
66544+#include <linux/kernel.h>
66545+#include <linux/sched.h>
66546+#include <linux/sysctl.h>
66547+#include <linux/grsecurity.h>
66548+#include <linux/grinternal.h>
66549+
66550+int
66551+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66552+{
66553+#ifdef CONFIG_GRKERNSEC_SYSCTL
66554+ if (dirname == NULL || name == NULL)
66555+ return 0;
66556+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66557+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66558+ return -EACCES;
66559+ }
66560+#endif
66561+ return 0;
66562+}
66563+
66564+#ifdef CONFIG_GRKERNSEC_ROFS
66565+static int __maybe_unused one = 1;
66566+#endif
66567+
66568+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66569+struct ctl_table grsecurity_table[] = {
66570+#ifdef CONFIG_GRKERNSEC_SYSCTL
66571+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66572+#ifdef CONFIG_GRKERNSEC_IO
66573+ {
66574+ .procname = "disable_priv_io",
66575+ .data = &grsec_disable_privio,
66576+ .maxlen = sizeof(int),
66577+ .mode = 0600,
66578+ .proc_handler = &proc_dointvec,
66579+ },
66580+#endif
66581+#endif
66582+#ifdef CONFIG_GRKERNSEC_LINK
66583+ {
66584+ .procname = "linking_restrictions",
66585+ .data = &grsec_enable_link,
66586+ .maxlen = sizeof(int),
66587+ .mode = 0600,
66588+ .proc_handler = &proc_dointvec,
66589+ },
66590+#endif
66591+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66592+ {
66593+ .procname = "enforce_symlinksifowner",
66594+ .data = &grsec_enable_symlinkown,
66595+ .maxlen = sizeof(int),
66596+ .mode = 0600,
66597+ .proc_handler = &proc_dointvec,
66598+ },
66599+ {
66600+ .procname = "symlinkown_gid",
66601+ .data = &grsec_symlinkown_gid,
66602+ .maxlen = sizeof(int),
66603+ .mode = 0600,
66604+ .proc_handler = &proc_dointvec,
66605+ },
66606+#endif
66607+#ifdef CONFIG_GRKERNSEC_BRUTE
66608+ {
66609+ .procname = "deter_bruteforce",
66610+ .data = &grsec_enable_brute,
66611+ .maxlen = sizeof(int),
66612+ .mode = 0600,
66613+ .proc_handler = &proc_dointvec,
66614+ },
66615+#endif
66616+#ifdef CONFIG_GRKERNSEC_FIFO
66617+ {
66618+ .procname = "fifo_restrictions",
66619+ .data = &grsec_enable_fifo,
66620+ .maxlen = sizeof(int),
66621+ .mode = 0600,
66622+ .proc_handler = &proc_dointvec,
66623+ },
66624+#endif
66625+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66626+ {
66627+ .procname = "ptrace_readexec",
66628+ .data = &grsec_enable_ptrace_readexec,
66629+ .maxlen = sizeof(int),
66630+ .mode = 0600,
66631+ .proc_handler = &proc_dointvec,
66632+ },
66633+#endif
66634+#ifdef CONFIG_GRKERNSEC_SETXID
66635+ {
66636+ .procname = "consistent_setxid",
66637+ .data = &grsec_enable_setxid,
66638+ .maxlen = sizeof(int),
66639+ .mode = 0600,
66640+ .proc_handler = &proc_dointvec,
66641+ },
66642+#endif
66643+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66644+ {
66645+ .procname = "ip_blackhole",
66646+ .data = &grsec_enable_blackhole,
66647+ .maxlen = sizeof(int),
66648+ .mode = 0600,
66649+ .proc_handler = &proc_dointvec,
66650+ },
66651+ {
66652+ .procname = "lastack_retries",
66653+ .data = &grsec_lastack_retries,
66654+ .maxlen = sizeof(int),
66655+ .mode = 0600,
66656+ .proc_handler = &proc_dointvec,
66657+ },
66658+#endif
66659+#ifdef CONFIG_GRKERNSEC_EXECLOG
66660+ {
66661+ .procname = "exec_logging",
66662+ .data = &grsec_enable_execlog,
66663+ .maxlen = sizeof(int),
66664+ .mode = 0600,
66665+ .proc_handler = &proc_dointvec,
66666+ },
66667+#endif
66668+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66669+ {
66670+ .procname = "rwxmap_logging",
66671+ .data = &grsec_enable_log_rwxmaps,
66672+ .maxlen = sizeof(int),
66673+ .mode = 0600,
66674+ .proc_handler = &proc_dointvec,
66675+ },
66676+#endif
66677+#ifdef CONFIG_GRKERNSEC_SIGNAL
66678+ {
66679+ .procname = "signal_logging",
66680+ .data = &grsec_enable_signal,
66681+ .maxlen = sizeof(int),
66682+ .mode = 0600,
66683+ .proc_handler = &proc_dointvec,
66684+ },
66685+#endif
66686+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66687+ {
66688+ .procname = "forkfail_logging",
66689+ .data = &grsec_enable_forkfail,
66690+ .maxlen = sizeof(int),
66691+ .mode = 0600,
66692+ .proc_handler = &proc_dointvec,
66693+ },
66694+#endif
66695+#ifdef CONFIG_GRKERNSEC_TIME
66696+ {
66697+ .procname = "timechange_logging",
66698+ .data = &grsec_enable_time,
66699+ .maxlen = sizeof(int),
66700+ .mode = 0600,
66701+ .proc_handler = &proc_dointvec,
66702+ },
66703+#endif
66704+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66705+ {
66706+ .procname = "chroot_deny_shmat",
66707+ .data = &grsec_enable_chroot_shmat,
66708+ .maxlen = sizeof(int),
66709+ .mode = 0600,
66710+ .proc_handler = &proc_dointvec,
66711+ },
66712+#endif
66713+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66714+ {
66715+ .procname = "chroot_deny_unix",
66716+ .data = &grsec_enable_chroot_unix,
66717+ .maxlen = sizeof(int),
66718+ .mode = 0600,
66719+ .proc_handler = &proc_dointvec,
66720+ },
66721+#endif
66722+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66723+ {
66724+ .procname = "chroot_deny_mount",
66725+ .data = &grsec_enable_chroot_mount,
66726+ .maxlen = sizeof(int),
66727+ .mode = 0600,
66728+ .proc_handler = &proc_dointvec,
66729+ },
66730+#endif
66731+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66732+ {
66733+ .procname = "chroot_deny_fchdir",
66734+ .data = &grsec_enable_chroot_fchdir,
66735+ .maxlen = sizeof(int),
66736+ .mode = 0600,
66737+ .proc_handler = &proc_dointvec,
66738+ },
66739+#endif
66740+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66741+ {
66742+ .procname = "chroot_deny_chroot",
66743+ .data = &grsec_enable_chroot_double,
66744+ .maxlen = sizeof(int),
66745+ .mode = 0600,
66746+ .proc_handler = &proc_dointvec,
66747+ },
66748+#endif
66749+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66750+ {
66751+ .procname = "chroot_deny_pivot",
66752+ .data = &grsec_enable_chroot_pivot,
66753+ .maxlen = sizeof(int),
66754+ .mode = 0600,
66755+ .proc_handler = &proc_dointvec,
66756+ },
66757+#endif
66758+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66759+ {
66760+ .procname = "chroot_enforce_chdir",
66761+ .data = &grsec_enable_chroot_chdir,
66762+ .maxlen = sizeof(int),
66763+ .mode = 0600,
66764+ .proc_handler = &proc_dointvec,
66765+ },
66766+#endif
66767+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66768+ {
66769+ .procname = "chroot_deny_chmod",
66770+ .data = &grsec_enable_chroot_chmod,
66771+ .maxlen = sizeof(int),
66772+ .mode = 0600,
66773+ .proc_handler = &proc_dointvec,
66774+ },
66775+#endif
66776+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66777+ {
66778+ .procname = "chroot_deny_mknod",
66779+ .data = &grsec_enable_chroot_mknod,
66780+ .maxlen = sizeof(int),
66781+ .mode = 0600,
66782+ .proc_handler = &proc_dointvec,
66783+ },
66784+#endif
66785+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66786+ {
66787+ .procname = "chroot_restrict_nice",
66788+ .data = &grsec_enable_chroot_nice,
66789+ .maxlen = sizeof(int),
66790+ .mode = 0600,
66791+ .proc_handler = &proc_dointvec,
66792+ },
66793+#endif
66794+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66795+ {
66796+ .procname = "chroot_execlog",
66797+ .data = &grsec_enable_chroot_execlog,
66798+ .maxlen = sizeof(int),
66799+ .mode = 0600,
66800+ .proc_handler = &proc_dointvec,
66801+ },
66802+#endif
66803+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66804+ {
66805+ .procname = "chroot_caps",
66806+ .data = &grsec_enable_chroot_caps,
66807+ .maxlen = sizeof(int),
66808+ .mode = 0600,
66809+ .proc_handler = &proc_dointvec,
66810+ },
66811+#endif
66812+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66813+ {
66814+ .procname = "chroot_deny_sysctl",
66815+ .data = &grsec_enable_chroot_sysctl,
66816+ .maxlen = sizeof(int),
66817+ .mode = 0600,
66818+ .proc_handler = &proc_dointvec,
66819+ },
66820+#endif
66821+#ifdef CONFIG_GRKERNSEC_TPE
66822+ {
66823+ .procname = "tpe",
66824+ .data = &grsec_enable_tpe,
66825+ .maxlen = sizeof(int),
66826+ .mode = 0600,
66827+ .proc_handler = &proc_dointvec,
66828+ },
66829+ {
66830+ .procname = "tpe_gid",
66831+ .data = &grsec_tpe_gid,
66832+ .maxlen = sizeof(int),
66833+ .mode = 0600,
66834+ .proc_handler = &proc_dointvec,
66835+ },
66836+#endif
66837+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66838+ {
66839+ .procname = "tpe_invert",
66840+ .data = &grsec_enable_tpe_invert,
66841+ .maxlen = sizeof(int),
66842+ .mode = 0600,
66843+ .proc_handler = &proc_dointvec,
66844+ },
66845+#endif
66846+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66847+ {
66848+ .procname = "tpe_restrict_all",
66849+ .data = &grsec_enable_tpe_all,
66850+ .maxlen = sizeof(int),
66851+ .mode = 0600,
66852+ .proc_handler = &proc_dointvec,
66853+ },
66854+#endif
66855+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66856+ {
66857+ .procname = "socket_all",
66858+ .data = &grsec_enable_socket_all,
66859+ .maxlen = sizeof(int),
66860+ .mode = 0600,
66861+ .proc_handler = &proc_dointvec,
66862+ },
66863+ {
66864+ .procname = "socket_all_gid",
66865+ .data = &grsec_socket_all_gid,
66866+ .maxlen = sizeof(int),
66867+ .mode = 0600,
66868+ .proc_handler = &proc_dointvec,
66869+ },
66870+#endif
66871+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66872+ {
66873+ .procname = "socket_client",
66874+ .data = &grsec_enable_socket_client,
66875+ .maxlen = sizeof(int),
66876+ .mode = 0600,
66877+ .proc_handler = &proc_dointvec,
66878+ },
66879+ {
66880+ .procname = "socket_client_gid",
66881+ .data = &grsec_socket_client_gid,
66882+ .maxlen = sizeof(int),
66883+ .mode = 0600,
66884+ .proc_handler = &proc_dointvec,
66885+ },
66886+#endif
66887+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66888+ {
66889+ .procname = "socket_server",
66890+ .data = &grsec_enable_socket_server,
66891+ .maxlen = sizeof(int),
66892+ .mode = 0600,
66893+ .proc_handler = &proc_dointvec,
66894+ },
66895+ {
66896+ .procname = "socket_server_gid",
66897+ .data = &grsec_socket_server_gid,
66898+ .maxlen = sizeof(int),
66899+ .mode = 0600,
66900+ .proc_handler = &proc_dointvec,
66901+ },
66902+#endif
66903+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66904+ {
66905+ .procname = "audit_group",
66906+ .data = &grsec_enable_group,
66907+ .maxlen = sizeof(int),
66908+ .mode = 0600,
66909+ .proc_handler = &proc_dointvec,
66910+ },
66911+ {
66912+ .procname = "audit_gid",
66913+ .data = &grsec_audit_gid,
66914+ .maxlen = sizeof(int),
66915+ .mode = 0600,
66916+ .proc_handler = &proc_dointvec,
66917+ },
66918+#endif
66919+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66920+ {
66921+ .procname = "audit_chdir",
66922+ .data = &grsec_enable_chdir,
66923+ .maxlen = sizeof(int),
66924+ .mode = 0600,
66925+ .proc_handler = &proc_dointvec,
66926+ },
66927+#endif
66928+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66929+ {
66930+ .procname = "audit_mount",
66931+ .data = &grsec_enable_mount,
66932+ .maxlen = sizeof(int),
66933+ .mode = 0600,
66934+ .proc_handler = &proc_dointvec,
66935+ },
66936+#endif
66937+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66938+ {
66939+ .procname = "audit_textrel",
66940+ .data = &grsec_enable_audit_textrel,
66941+ .maxlen = sizeof(int),
66942+ .mode = 0600,
66943+ .proc_handler = &proc_dointvec,
66944+ },
66945+#endif
66946+#ifdef CONFIG_GRKERNSEC_DMESG
66947+ {
66948+ .procname = "dmesg",
66949+ .data = &grsec_enable_dmesg,
66950+ .maxlen = sizeof(int),
66951+ .mode = 0600,
66952+ .proc_handler = &proc_dointvec,
66953+ },
66954+#endif
66955+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66956+ {
66957+ .procname = "chroot_findtask",
66958+ .data = &grsec_enable_chroot_findtask,
66959+ .maxlen = sizeof(int),
66960+ .mode = 0600,
66961+ .proc_handler = &proc_dointvec,
66962+ },
66963+#endif
66964+#ifdef CONFIG_GRKERNSEC_RESLOG
66965+ {
66966+ .procname = "resource_logging",
66967+ .data = &grsec_resource_logging,
66968+ .maxlen = sizeof(int),
66969+ .mode = 0600,
66970+ .proc_handler = &proc_dointvec,
66971+ },
66972+#endif
66973+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66974+ {
66975+ .procname = "audit_ptrace",
66976+ .data = &grsec_enable_audit_ptrace,
66977+ .maxlen = sizeof(int),
66978+ .mode = 0600,
66979+ .proc_handler = &proc_dointvec,
66980+ },
66981+#endif
66982+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66983+ {
66984+ .procname = "harden_ptrace",
66985+ .data = &grsec_enable_harden_ptrace,
66986+ .maxlen = sizeof(int),
66987+ .mode = 0600,
66988+ .proc_handler = &proc_dointvec,
66989+ },
66990+#endif
66991+ {
66992+ .procname = "grsec_lock",
66993+ .data = &grsec_lock,
66994+ .maxlen = sizeof(int),
66995+ .mode = 0600,
66996+ .proc_handler = &proc_dointvec,
66997+ },
66998+#endif
66999+#ifdef CONFIG_GRKERNSEC_ROFS
67000+ {
67001+ .procname = "romount_protect",
67002+ .data = &grsec_enable_rofs,
67003+ .maxlen = sizeof(int),
67004+ .mode = 0600,
67005+ .proc_handler = &proc_dointvec_minmax,
67006+ .extra1 = &one,
67007+ .extra2 = &one,
67008+ },
67009+#endif
67010+ { }
67011+};
67012+#endif
67013diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
67014new file mode 100644
67015index 0000000..0dc13c3
67016--- /dev/null
67017+++ b/grsecurity/grsec_time.c
67018@@ -0,0 +1,16 @@
67019+#include <linux/kernel.h>
67020+#include <linux/sched.h>
67021+#include <linux/grinternal.h>
67022+#include <linux/module.h>
67023+
67024+void
67025+gr_log_timechange(void)
67026+{
67027+#ifdef CONFIG_GRKERNSEC_TIME
67028+ if (grsec_enable_time)
67029+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
67030+#endif
67031+ return;
67032+}
67033+
67034+EXPORT_SYMBOL(gr_log_timechange);
67035diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
67036new file mode 100644
67037index 0000000..ee57dcf
67038--- /dev/null
67039+++ b/grsecurity/grsec_tpe.c
67040@@ -0,0 +1,73 @@
67041+#include <linux/kernel.h>
67042+#include <linux/sched.h>
67043+#include <linux/file.h>
67044+#include <linux/fs.h>
67045+#include <linux/grinternal.h>
67046+
67047+extern int gr_acl_tpe_check(void);
67048+
67049+int
67050+gr_tpe_allow(const struct file *file)
67051+{
67052+#ifdef CONFIG_GRKERNSEC
67053+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
67054+ const struct cred *cred = current_cred();
67055+ char *msg = NULL;
67056+ char *msg2 = NULL;
67057+
67058+ // never restrict root
67059+ if (gr_is_global_root(cred->uid))
67060+ return 1;
67061+
67062+ if (grsec_enable_tpe) {
67063+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
67064+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
67065+ msg = "not being in trusted group";
67066+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
67067+ msg = "being in untrusted group";
67068+#else
67069+ if (in_group_p(grsec_tpe_gid))
67070+ msg = "being in untrusted group";
67071+#endif
67072+ }
67073+ if (!msg && gr_acl_tpe_check())
67074+ msg = "being in untrusted role";
67075+
67076+ // not in any affected group/role
67077+ if (!msg)
67078+ goto next_check;
67079+
67080+ if (gr_is_global_nonroot(inode->i_uid))
67081+ msg2 = "file in non-root-owned directory";
67082+ else if (inode->i_mode & S_IWOTH)
67083+ msg2 = "file in world-writable directory";
67084+ else if (inode->i_mode & S_IWGRP)
67085+ msg2 = "file in group-writable directory";
67086+
67087+ if (msg && msg2) {
67088+ char fullmsg[70] = {0};
67089+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
67090+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
67091+ return 0;
67092+ }
67093+ msg = NULL;
67094+next_check:
67095+#ifdef CONFIG_GRKERNSEC_TPE_ALL
67096+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
67097+ return 1;
67098+
67099+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
67100+ msg = "directory not owned by user";
67101+ else if (inode->i_mode & S_IWOTH)
67102+ msg = "file in world-writable directory";
67103+ else if (inode->i_mode & S_IWGRP)
67104+ msg = "file in group-writable directory";
67105+
67106+ if (msg) {
67107+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
67108+ return 0;
67109+ }
67110+#endif
67111+#endif
67112+ return 1;
67113+}
67114diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
67115new file mode 100644
67116index 0000000..9f7b1ac
67117--- /dev/null
67118+++ b/grsecurity/grsum.c
67119@@ -0,0 +1,61 @@
67120+#include <linux/err.h>
67121+#include <linux/kernel.h>
67122+#include <linux/sched.h>
67123+#include <linux/mm.h>
67124+#include <linux/scatterlist.h>
67125+#include <linux/crypto.h>
67126+#include <linux/gracl.h>
67127+
67128+
67129+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
67130+#error "crypto and sha256 must be built into the kernel"
67131+#endif
67132+
67133+int
67134+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
67135+{
67136+ char *p;
67137+ struct crypto_hash *tfm;
67138+ struct hash_desc desc;
67139+ struct scatterlist sg;
67140+ unsigned char temp_sum[GR_SHA_LEN];
67141+ volatile int retval = 0;
67142+ volatile int dummy = 0;
67143+ unsigned int i;
67144+
67145+ sg_init_table(&sg, 1);
67146+
67147+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
67148+ if (IS_ERR(tfm)) {
67149+ /* should never happen, since sha256 should be built in */
67150+ return 1;
67151+ }
67152+
67153+ desc.tfm = tfm;
67154+ desc.flags = 0;
67155+
67156+ crypto_hash_init(&desc);
67157+
67158+ p = salt;
67159+ sg_set_buf(&sg, p, GR_SALT_LEN);
67160+ crypto_hash_update(&desc, &sg, sg.length);
67161+
67162+ p = entry->pw;
67163+ sg_set_buf(&sg, p, strlen(p));
67164+
67165+ crypto_hash_update(&desc, &sg, sg.length);
67166+
67167+ crypto_hash_final(&desc, temp_sum);
67168+
67169+ memset(entry->pw, 0, GR_PW_LEN);
67170+
67171+ for (i = 0; i < GR_SHA_LEN; i++)
67172+ if (sum[i] != temp_sum[i])
67173+ retval = 1;
67174+ else
67175+ dummy = 1; // waste a cycle
67176+
67177+ crypto_free_hash(tfm);
67178+
67179+ return retval;
67180+}
67181diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67182index 77ff547..181834f 100644
67183--- a/include/asm-generic/4level-fixup.h
67184+++ b/include/asm-generic/4level-fixup.h
67185@@ -13,8 +13,10 @@
67186 #define pmd_alloc(mm, pud, address) \
67187 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67188 NULL: pmd_offset(pud, address))
67189+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67190
67191 #define pud_alloc(mm, pgd, address) (pgd)
67192+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67193 #define pud_offset(pgd, start) (pgd)
67194 #define pud_none(pud) 0
67195 #define pud_bad(pud) 0
67196diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67197index b7babf0..04ad282 100644
67198--- a/include/asm-generic/atomic-long.h
67199+++ b/include/asm-generic/atomic-long.h
67200@@ -22,6 +22,12 @@
67201
67202 typedef atomic64_t atomic_long_t;
67203
67204+#ifdef CONFIG_PAX_REFCOUNT
67205+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67206+#else
67207+typedef atomic64_t atomic_long_unchecked_t;
67208+#endif
67209+
67210 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67211
67212 static inline long atomic_long_read(atomic_long_t *l)
67213@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67214 return (long)atomic64_read(v);
67215 }
67216
67217+#ifdef CONFIG_PAX_REFCOUNT
67218+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67219+{
67220+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67221+
67222+ return (long)atomic64_read_unchecked(v);
67223+}
67224+#endif
67225+
67226 static inline void atomic_long_set(atomic_long_t *l, long i)
67227 {
67228 atomic64_t *v = (atomic64_t *)l;
67229@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67230 atomic64_set(v, i);
67231 }
67232
67233+#ifdef CONFIG_PAX_REFCOUNT
67234+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67235+{
67236+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67237+
67238+ atomic64_set_unchecked(v, i);
67239+}
67240+#endif
67241+
67242 static inline void atomic_long_inc(atomic_long_t *l)
67243 {
67244 atomic64_t *v = (atomic64_t *)l;
67245@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67246 atomic64_inc(v);
67247 }
67248
67249+#ifdef CONFIG_PAX_REFCOUNT
67250+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67251+{
67252+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67253+
67254+ atomic64_inc_unchecked(v);
67255+}
67256+#endif
67257+
67258 static inline void atomic_long_dec(atomic_long_t *l)
67259 {
67260 atomic64_t *v = (atomic64_t *)l;
67261@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67262 atomic64_dec(v);
67263 }
67264
67265+#ifdef CONFIG_PAX_REFCOUNT
67266+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67267+{
67268+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67269+
67270+ atomic64_dec_unchecked(v);
67271+}
67272+#endif
67273+
67274 static inline void atomic_long_add(long i, atomic_long_t *l)
67275 {
67276 atomic64_t *v = (atomic64_t *)l;
67277@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67278 atomic64_add(i, v);
67279 }
67280
67281+#ifdef CONFIG_PAX_REFCOUNT
67282+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67283+{
67284+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67285+
67286+ atomic64_add_unchecked(i, v);
67287+}
67288+#endif
67289+
67290 static inline void atomic_long_sub(long i, atomic_long_t *l)
67291 {
67292 atomic64_t *v = (atomic64_t *)l;
67293@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67294 atomic64_sub(i, v);
67295 }
67296
67297+#ifdef CONFIG_PAX_REFCOUNT
67298+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67299+{
67300+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67301+
67302+ atomic64_sub_unchecked(i, v);
67303+}
67304+#endif
67305+
67306 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67307 {
67308 atomic64_t *v = (atomic64_t *)l;
67309@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67310 return (long)atomic64_add_return(i, v);
67311 }
67312
67313+#ifdef CONFIG_PAX_REFCOUNT
67314+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67315+{
67316+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67317+
67318+ return (long)atomic64_add_return_unchecked(i, v);
67319+}
67320+#endif
67321+
67322 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67323 {
67324 atomic64_t *v = (atomic64_t *)l;
67325@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67326 return (long)atomic64_inc_return(v);
67327 }
67328
67329+#ifdef CONFIG_PAX_REFCOUNT
67330+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67331+{
67332+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67333+
67334+ return (long)atomic64_inc_return_unchecked(v);
67335+}
67336+#endif
67337+
67338 static inline long atomic_long_dec_return(atomic_long_t *l)
67339 {
67340 atomic64_t *v = (atomic64_t *)l;
67341@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67342
67343 typedef atomic_t atomic_long_t;
67344
67345+#ifdef CONFIG_PAX_REFCOUNT
67346+typedef atomic_unchecked_t atomic_long_unchecked_t;
67347+#else
67348+typedef atomic_t atomic_long_unchecked_t;
67349+#endif
67350+
67351 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67352 static inline long atomic_long_read(atomic_long_t *l)
67353 {
67354@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67355 return (long)atomic_read(v);
67356 }
67357
67358+#ifdef CONFIG_PAX_REFCOUNT
67359+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67360+{
67361+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67362+
67363+ return (long)atomic_read_unchecked(v);
67364+}
67365+#endif
67366+
67367 static inline void atomic_long_set(atomic_long_t *l, long i)
67368 {
67369 atomic_t *v = (atomic_t *)l;
67370@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67371 atomic_set(v, i);
67372 }
67373
67374+#ifdef CONFIG_PAX_REFCOUNT
67375+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67376+{
67377+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67378+
67379+ atomic_set_unchecked(v, i);
67380+}
67381+#endif
67382+
67383 static inline void atomic_long_inc(atomic_long_t *l)
67384 {
67385 atomic_t *v = (atomic_t *)l;
67386@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67387 atomic_inc(v);
67388 }
67389
67390+#ifdef CONFIG_PAX_REFCOUNT
67391+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67392+{
67393+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67394+
67395+ atomic_inc_unchecked(v);
67396+}
67397+#endif
67398+
67399 static inline void atomic_long_dec(atomic_long_t *l)
67400 {
67401 atomic_t *v = (atomic_t *)l;
67402@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67403 atomic_dec(v);
67404 }
67405
67406+#ifdef CONFIG_PAX_REFCOUNT
67407+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67408+{
67409+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67410+
67411+ atomic_dec_unchecked(v);
67412+}
67413+#endif
67414+
67415 static inline void atomic_long_add(long i, atomic_long_t *l)
67416 {
67417 atomic_t *v = (atomic_t *)l;
67418@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67419 atomic_add(i, v);
67420 }
67421
67422+#ifdef CONFIG_PAX_REFCOUNT
67423+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67424+{
67425+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67426+
67427+ atomic_add_unchecked(i, v);
67428+}
67429+#endif
67430+
67431 static inline void atomic_long_sub(long i, atomic_long_t *l)
67432 {
67433 atomic_t *v = (atomic_t *)l;
67434@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67435 atomic_sub(i, v);
67436 }
67437
67438+#ifdef CONFIG_PAX_REFCOUNT
67439+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67440+{
67441+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67442+
67443+ atomic_sub_unchecked(i, v);
67444+}
67445+#endif
67446+
67447 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67448 {
67449 atomic_t *v = (atomic_t *)l;
67450@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67451 return (long)atomic_add_return(i, v);
67452 }
67453
67454+#ifdef CONFIG_PAX_REFCOUNT
67455+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67456+{
67457+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67458+
67459+ return (long)atomic_add_return_unchecked(i, v);
67460+}
67461+
67462+#endif
67463+
67464 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67465 {
67466 atomic_t *v = (atomic_t *)l;
67467@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67468 return (long)atomic_inc_return(v);
67469 }
67470
67471+#ifdef CONFIG_PAX_REFCOUNT
67472+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67473+{
67474+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67475+
67476+ return (long)atomic_inc_return_unchecked(v);
67477+}
67478+#endif
67479+
67480 static inline long atomic_long_dec_return(atomic_long_t *l)
67481 {
67482 atomic_t *v = (atomic_t *)l;
67483@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67484
67485 #endif /* BITS_PER_LONG == 64 */
67486
67487+#ifdef CONFIG_PAX_REFCOUNT
67488+static inline void pax_refcount_needs_these_functions(void)
67489+{
67490+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67491+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67492+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67493+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67494+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67495+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67496+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67497+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67498+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67499+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67500+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67501+#ifdef CONFIG_X86
67502+ atomic_clear_mask_unchecked(0, NULL);
67503+ atomic_set_mask_unchecked(0, NULL);
67504+#endif
67505+
67506+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67507+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67508+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67509+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67510+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67511+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67512+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67513+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67514+}
67515+#else
67516+#define atomic_read_unchecked(v) atomic_read(v)
67517+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67518+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67519+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67520+#define atomic_inc_unchecked(v) atomic_inc(v)
67521+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67522+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67523+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67524+#define atomic_dec_unchecked(v) atomic_dec(v)
67525+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67526+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67527+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67528+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67529+
67530+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67531+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67532+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67533+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67534+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67535+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67536+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67537+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67538+#endif
67539+
67540 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67541diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67542index 33bd2de..f31bff97 100644
67543--- a/include/asm-generic/atomic.h
67544+++ b/include/asm-generic/atomic.h
67545@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67546 * Atomically clears the bits set in @mask from @v
67547 */
67548 #ifndef atomic_clear_mask
67549-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67550+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67551 {
67552 unsigned long flags;
67553
67554diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67555index b18ce4f..2ee2843 100644
67556--- a/include/asm-generic/atomic64.h
67557+++ b/include/asm-generic/atomic64.h
67558@@ -16,6 +16,8 @@ typedef struct {
67559 long long counter;
67560 } atomic64_t;
67561
67562+typedef atomic64_t atomic64_unchecked_t;
67563+
67564 #define ATOMIC64_INIT(i) { (i) }
67565
67566 extern long long atomic64_read(const atomic64_t *v);
67567@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67568 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67569 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67570
67571+#define atomic64_read_unchecked(v) atomic64_read(v)
67572+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67573+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67574+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67575+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67576+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67577+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67578+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67579+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67580+
67581 #endif /* _ASM_GENERIC_ATOMIC64_H */
67582diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67583index 1bfcfe5..e04c5c9 100644
67584--- a/include/asm-generic/cache.h
67585+++ b/include/asm-generic/cache.h
67586@@ -6,7 +6,7 @@
67587 * cache lines need to provide their own cache.h.
67588 */
67589
67590-#define L1_CACHE_SHIFT 5
67591-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67592+#define L1_CACHE_SHIFT 5UL
67593+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67594
67595 #endif /* __ASM_GENERIC_CACHE_H */
67596diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67597index 0d68a1e..b74a761 100644
67598--- a/include/asm-generic/emergency-restart.h
67599+++ b/include/asm-generic/emergency-restart.h
67600@@ -1,7 +1,7 @@
67601 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67602 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67603
67604-static inline void machine_emergency_restart(void)
67605+static inline __noreturn void machine_emergency_restart(void)
67606 {
67607 machine_restart(NULL);
67608 }
67609diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67610index 90f99c7..00ce236 100644
67611--- a/include/asm-generic/kmap_types.h
67612+++ b/include/asm-generic/kmap_types.h
67613@@ -2,9 +2,9 @@
67614 #define _ASM_GENERIC_KMAP_TYPES_H
67615
67616 #ifdef __WITH_KM_FENCE
67617-# define KM_TYPE_NR 41
67618+# define KM_TYPE_NR 42
67619 #else
67620-# define KM_TYPE_NR 20
67621+# define KM_TYPE_NR 21
67622 #endif
67623
67624 #endif
67625diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67626index 9ceb03b..62b0b8f 100644
67627--- a/include/asm-generic/local.h
67628+++ b/include/asm-generic/local.h
67629@@ -23,24 +23,37 @@ typedef struct
67630 atomic_long_t a;
67631 } local_t;
67632
67633+typedef struct {
67634+ atomic_long_unchecked_t a;
67635+} local_unchecked_t;
67636+
67637 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67638
67639 #define local_read(l) atomic_long_read(&(l)->a)
67640+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67641 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67642+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67643 #define local_inc(l) atomic_long_inc(&(l)->a)
67644+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67645 #define local_dec(l) atomic_long_dec(&(l)->a)
67646+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67647 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67648+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67649 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67650+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67651
67652 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67653 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67654 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67655 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67656 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67657+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67658 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67659 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67660+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67661
67662 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67663+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67664 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67665 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67666 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67667diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67668index 725612b..9cc513a 100644
67669--- a/include/asm-generic/pgtable-nopmd.h
67670+++ b/include/asm-generic/pgtable-nopmd.h
67671@@ -1,14 +1,19 @@
67672 #ifndef _PGTABLE_NOPMD_H
67673 #define _PGTABLE_NOPMD_H
67674
67675-#ifndef __ASSEMBLY__
67676-
67677 #include <asm-generic/pgtable-nopud.h>
67678
67679-struct mm_struct;
67680-
67681 #define __PAGETABLE_PMD_FOLDED
67682
67683+#define PMD_SHIFT PUD_SHIFT
67684+#define PTRS_PER_PMD 1
67685+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67686+#define PMD_MASK (~(PMD_SIZE-1))
67687+
67688+#ifndef __ASSEMBLY__
67689+
67690+struct mm_struct;
67691+
67692 /*
67693 * Having the pmd type consist of a pud gets the size right, and allows
67694 * us to conceptually access the pud entry that this pmd is folded into
67695@@ -16,11 +21,6 @@ struct mm_struct;
67696 */
67697 typedef struct { pud_t pud; } pmd_t;
67698
67699-#define PMD_SHIFT PUD_SHIFT
67700-#define PTRS_PER_PMD 1
67701-#define PMD_SIZE (1UL << PMD_SHIFT)
67702-#define PMD_MASK (~(PMD_SIZE-1))
67703-
67704 /*
67705 * The "pud_xxx()" functions here are trivial for a folded two-level
67706 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67707diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67708index 810431d..0ec4804f 100644
67709--- a/include/asm-generic/pgtable-nopud.h
67710+++ b/include/asm-generic/pgtable-nopud.h
67711@@ -1,10 +1,15 @@
67712 #ifndef _PGTABLE_NOPUD_H
67713 #define _PGTABLE_NOPUD_H
67714
67715-#ifndef __ASSEMBLY__
67716-
67717 #define __PAGETABLE_PUD_FOLDED
67718
67719+#define PUD_SHIFT PGDIR_SHIFT
67720+#define PTRS_PER_PUD 1
67721+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67722+#define PUD_MASK (~(PUD_SIZE-1))
67723+
67724+#ifndef __ASSEMBLY__
67725+
67726 /*
67727 * Having the pud type consist of a pgd gets the size right, and allows
67728 * us to conceptually access the pgd entry that this pud is folded into
67729@@ -12,11 +17,6 @@
67730 */
67731 typedef struct { pgd_t pgd; } pud_t;
67732
67733-#define PUD_SHIFT PGDIR_SHIFT
67734-#define PTRS_PER_PUD 1
67735-#define PUD_SIZE (1UL << PUD_SHIFT)
67736-#define PUD_MASK (~(PUD_SIZE-1))
67737-
67738 /*
67739 * The "pgd_xxx()" functions here are trivial for a folded two-level
67740 * setup: the pud is never bad, and a pud always exists (as it's folded
67741@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67742 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67743
67744 #define pgd_populate(mm, pgd, pud) do { } while (0)
67745+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67746 /*
67747 * (puds are folded into pgds so this doesn't get actually called,
67748 * but the define is needed for a generic inline function.)
67749diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67750index a59ff51..2594a70 100644
67751--- a/include/asm-generic/pgtable.h
67752+++ b/include/asm-generic/pgtable.h
67753@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67754 }
67755 #endif /* CONFIG_NUMA_BALANCING */
67756
67757+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67758+static inline unsigned long pax_open_kernel(void) { return 0; }
67759+#endif
67760+
67761+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67762+static inline unsigned long pax_close_kernel(void) { return 0; }
67763+#endif
67764+
67765 #endif /* CONFIG_MMU */
67766
67767 #endif /* !__ASSEMBLY__ */
67768diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67769index eb58d2d..df131bf 100644
67770--- a/include/asm-generic/vmlinux.lds.h
67771+++ b/include/asm-generic/vmlinux.lds.h
67772@@ -239,6 +239,7 @@
67773 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67774 VMLINUX_SYMBOL(__start_rodata) = .; \
67775 *(.rodata) *(.rodata.*) \
67776+ *(.data..read_only) \
67777 *(__vermagic) /* Kernel version magic */ \
67778 . = ALIGN(8); \
67779 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67780@@ -749,17 +750,18 @@
67781 * section in the linker script will go there too. @phdr should have
67782 * a leading colon.
67783 *
67784- * Note that this macros defines __per_cpu_load as an absolute symbol.
67785+ * Note that this macros defines per_cpu_load as an absolute symbol.
67786 * If there is no need to put the percpu section at a predetermined
67787 * address, use PERCPU_SECTION.
67788 */
67789 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67790- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67791- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67792+ per_cpu_load = .; \
67793+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67794 - LOAD_OFFSET) { \
67795+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67796 PERCPU_INPUT(cacheline) \
67797 } phdr \
67798- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67799+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67800
67801 /**
67802 * PERCPU_SECTION - define output section for percpu area, simple version
67803diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67804index 418d270..bfd2794 100644
67805--- a/include/crypto/algapi.h
67806+++ b/include/crypto/algapi.h
67807@@ -34,7 +34,7 @@ struct crypto_type {
67808 unsigned int maskclear;
67809 unsigned int maskset;
67810 unsigned int tfmsize;
67811-};
67812+} __do_const;
67813
67814 struct crypto_instance {
67815 struct crypto_alg alg;
67816diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67817index 63d17ee..716de2b 100644
67818--- a/include/drm/drmP.h
67819+++ b/include/drm/drmP.h
67820@@ -72,6 +72,7 @@
67821 #include <linux/workqueue.h>
67822 #include <linux/poll.h>
67823 #include <asm/pgalloc.h>
67824+#include <asm/local.h>
67825 #include <drm/drm.h>
67826 #include <drm/drm_sarea.h>
67827
67828@@ -296,10 +297,12 @@ do { \
67829 * \param cmd command.
67830 * \param arg argument.
67831 */
67832-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67833+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67834+ struct drm_file *file_priv);
67835+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67836 struct drm_file *file_priv);
67837
67838-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67839+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67840 unsigned long arg);
67841
67842 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67843@@ -314,10 +317,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67844 struct drm_ioctl_desc {
67845 unsigned int cmd;
67846 int flags;
67847- drm_ioctl_t *func;
67848+ drm_ioctl_t func;
67849 unsigned int cmd_drv;
67850 const char *name;
67851-};
67852+} __do_const;
67853
67854 /**
67855 * Creates a driver or general drm_ioctl_desc array entry for the given
67856@@ -1015,7 +1018,7 @@ struct drm_info_list {
67857 int (*show)(struct seq_file*, void*); /** show callback */
67858 u32 driver_features; /**< Required driver features for this entry */
67859 void *data;
67860-};
67861+} __do_const;
67862
67863 /**
67864 * debugfs node structure. This structure represents a debugfs file.
67865@@ -1088,7 +1091,7 @@ struct drm_device {
67866
67867 /** \name Usage Counters */
67868 /*@{ */
67869- int open_count; /**< Outstanding files open */
67870+ local_t open_count; /**< Outstanding files open */
67871 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67872 atomic_t vma_count; /**< Outstanding vma areas open */
67873 int buf_use; /**< Buffers in use -- cannot alloc */
67874@@ -1099,7 +1102,7 @@ struct drm_device {
67875 /*@{ */
67876 unsigned long counters;
67877 enum drm_stat_type types[15];
67878- atomic_t counts[15];
67879+ atomic_unchecked_t counts[15];
67880 /*@} */
67881
67882 struct list_head filelist;
67883diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67884index f43d556..94d9343 100644
67885--- a/include/drm/drm_crtc_helper.h
67886+++ b/include/drm/drm_crtc_helper.h
67887@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67888 struct drm_connector *connector);
67889 /* disable encoder when not in use - more explicit than dpms off */
67890 void (*disable)(struct drm_encoder *encoder);
67891-};
67892+} __no_const;
67893
67894 /**
67895 * drm_connector_helper_funcs - helper operations for connectors
67896diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67897index 72dcbe8..8db58d7 100644
67898--- a/include/drm/ttm/ttm_memory.h
67899+++ b/include/drm/ttm/ttm_memory.h
67900@@ -48,7 +48,7 @@
67901
67902 struct ttm_mem_shrink {
67903 int (*do_shrink) (struct ttm_mem_shrink *);
67904-};
67905+} __no_const;
67906
67907 /**
67908 * struct ttm_mem_global - Global memory accounting structure.
67909diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67910index 4b840e8..155d235 100644
67911--- a/include/keys/asymmetric-subtype.h
67912+++ b/include/keys/asymmetric-subtype.h
67913@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67914 /* Verify the signature on a key of this subtype (optional) */
67915 int (*verify_signature)(const struct key *key,
67916 const struct public_key_signature *sig);
67917-};
67918+} __do_const;
67919
67920 /**
67921 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67922diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67923index c1da539..1dcec55 100644
67924--- a/include/linux/atmdev.h
67925+++ b/include/linux/atmdev.h
67926@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67927 #endif
67928
67929 struct k_atm_aal_stats {
67930-#define __HANDLE_ITEM(i) atomic_t i
67931+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67932 __AAL_STAT_ITEMS
67933 #undef __HANDLE_ITEM
67934 };
67935@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67936 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67937 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67938 struct module *owner;
67939-};
67940+} __do_const ;
67941
67942 struct atmphy_ops {
67943 int (*start)(struct atm_dev *dev);
67944diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67945index 70cf138..cabb82e 100644
67946--- a/include/linux/binfmts.h
67947+++ b/include/linux/binfmts.h
67948@@ -73,8 +73,9 @@ struct linux_binfmt {
67949 int (*load_binary)(struct linux_binprm *);
67950 int (*load_shlib)(struct file *);
67951 int (*core_dump)(struct coredump_params *cprm);
67952+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67953 unsigned long min_coredump; /* minimal dump size */
67954-};
67955+} __do_const;
67956
67957 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67958
67959diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67960index 2fdb4a4..54aad7e 100644
67961--- a/include/linux/blkdev.h
67962+++ b/include/linux/blkdev.h
67963@@ -1526,7 +1526,7 @@ struct block_device_operations {
67964 /* this callback is with swap_lock and sometimes page table lock held */
67965 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67966 struct module *owner;
67967-};
67968+} __do_const;
67969
67970 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67971 unsigned long);
67972diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67973index 7c2e030..b72475d 100644
67974--- a/include/linux/blktrace_api.h
67975+++ b/include/linux/blktrace_api.h
67976@@ -23,7 +23,7 @@ struct blk_trace {
67977 struct dentry *dir;
67978 struct dentry *dropped_file;
67979 struct dentry *msg_file;
67980- atomic_t dropped;
67981+ atomic_unchecked_t dropped;
67982 };
67983
67984 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67985diff --git a/include/linux/cache.h b/include/linux/cache.h
67986index 4c57065..4307975 100644
67987--- a/include/linux/cache.h
67988+++ b/include/linux/cache.h
67989@@ -16,6 +16,10 @@
67990 #define __read_mostly
67991 #endif
67992
67993+#ifndef __read_only
67994+#define __read_only __read_mostly
67995+#endif
67996+
67997 #ifndef ____cacheline_aligned
67998 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67999 #endif
68000diff --git a/include/linux/capability.h b/include/linux/capability.h
68001index d9a4f7f4..19f77d6 100644
68002--- a/include/linux/capability.h
68003+++ b/include/linux/capability.h
68004@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
68005 extern bool nsown_capable(int cap);
68006 extern bool inode_capable(const struct inode *inode, int cap);
68007 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
68008+extern bool capable_nolog(int cap);
68009+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
68010+extern bool inode_capable_nolog(const struct inode *inode, int cap);
68011
68012 /* audit system wants to get cap info from files as well */
68013 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
68014
68015+extern int is_privileged_binary(const struct dentry *dentry);
68016+
68017 #endif /* !_LINUX_CAPABILITY_H */
68018diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
68019index 8609d57..86e4d79 100644
68020--- a/include/linux/cdrom.h
68021+++ b/include/linux/cdrom.h
68022@@ -87,7 +87,6 @@ struct cdrom_device_ops {
68023
68024 /* driver specifications */
68025 const int capability; /* capability flags */
68026- int n_minors; /* number of active minor devices */
68027 /* handle uniform packets for scsi type devices (scsi,atapi) */
68028 int (*generic_packet) (struct cdrom_device_info *,
68029 struct packet_command *);
68030diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
68031index 4ce9056..86caac6 100644
68032--- a/include/linux/cleancache.h
68033+++ b/include/linux/cleancache.h
68034@@ -31,7 +31,7 @@ struct cleancache_ops {
68035 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
68036 void (*invalidate_inode)(int, struct cleancache_filekey);
68037 void (*invalidate_fs)(int);
68038-};
68039+} __no_const;
68040
68041 extern struct cleancache_ops *
68042 cleancache_register_ops(struct cleancache_ops *ops);
68043diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
68044index 1186098..f87e53d 100644
68045--- a/include/linux/clk-provider.h
68046+++ b/include/linux/clk-provider.h
68047@@ -132,6 +132,7 @@ struct clk_ops {
68048 unsigned long);
68049 void (*init)(struct clk_hw *hw);
68050 };
68051+typedef struct clk_ops __no_const clk_ops_no_const;
68052
68053 /**
68054 * struct clk_init_data - holds init data that's common to all clocks and is
68055diff --git a/include/linux/compat.h b/include/linux/compat.h
68056index 7f0c1dd..b5729c6 100644
68057--- a/include/linux/compat.h
68058+++ b/include/linux/compat.h
68059@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
68060 compat_size_t __user *len_ptr);
68061
68062 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
68063-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
68064+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
68065 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
68066 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
68067 compat_ssize_t msgsz, int msgflg);
68068@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
68069 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
68070 compat_ulong_t addr, compat_ulong_t data);
68071 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
68072- compat_long_t addr, compat_long_t data);
68073+ compat_ulong_t addr, compat_ulong_t data);
68074
68075 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
68076 /*
68077diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
68078index 842de22..7f3a41f 100644
68079--- a/include/linux/compiler-gcc4.h
68080+++ b/include/linux/compiler-gcc4.h
68081@@ -39,9 +39,29 @@
68082 # define __compiletime_warning(message) __attribute__((warning(message)))
68083 # define __compiletime_error(message) __attribute__((error(message)))
68084 #endif /* __CHECKER__ */
68085+
68086+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
68087+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
68088+#define __bos0(ptr) __bos((ptr), 0)
68089+#define __bos1(ptr) __bos((ptr), 1)
68090 #endif /* GCC_VERSION >= 40300 */
68091
68092 #if GCC_VERSION >= 40500
68093+
68094+#ifdef CONSTIFY_PLUGIN
68095+#define __no_const __attribute__((no_const))
68096+#define __do_const __attribute__((do_const))
68097+#endif
68098+
68099+#ifdef SIZE_OVERFLOW_PLUGIN
68100+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
68101+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
68102+#endif
68103+
68104+#ifdef LATENT_ENTROPY_PLUGIN
68105+#define __latent_entropy __attribute__((latent_entropy))
68106+#endif
68107+
68108 /*
68109 * Mark a position in code as unreachable. This can be used to
68110 * suppress control flow warnings after asm blocks that transfer
68111diff --git a/include/linux/compiler.h b/include/linux/compiler.h
68112index 92669cd..1771a15 100644
68113--- a/include/linux/compiler.h
68114+++ b/include/linux/compiler.h
68115@@ -5,11 +5,14 @@
68116
68117 #ifdef __CHECKER__
68118 # define __user __attribute__((noderef, address_space(1)))
68119+# define __force_user __force __user
68120 # define __kernel __attribute__((address_space(0)))
68121+# define __force_kernel __force __kernel
68122 # define __safe __attribute__((safe))
68123 # define __force __attribute__((force))
68124 # define __nocast __attribute__((nocast))
68125 # define __iomem __attribute__((noderef, address_space(2)))
68126+# define __force_iomem __force __iomem
68127 # define __must_hold(x) __attribute__((context(x,1,1)))
68128 # define __acquires(x) __attribute__((context(x,0,1)))
68129 # define __releases(x) __attribute__((context(x,1,0)))
68130@@ -17,20 +20,37 @@
68131 # define __release(x) __context__(x,-1)
68132 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
68133 # define __percpu __attribute__((noderef, address_space(3)))
68134+# define __force_percpu __force __percpu
68135 #ifdef CONFIG_SPARSE_RCU_POINTER
68136 # define __rcu __attribute__((noderef, address_space(4)))
68137+# define __force_rcu __force __rcu
68138 #else
68139 # define __rcu
68140+# define __force_rcu
68141 #endif
68142 extern void __chk_user_ptr(const volatile void __user *);
68143 extern void __chk_io_ptr(const volatile void __iomem *);
68144 #else
68145-# define __user
68146-# define __kernel
68147+# ifdef CHECKER_PLUGIN
68148+//# define __user
68149+//# define __force_user
68150+//# define __kernel
68151+//# define __force_kernel
68152+# else
68153+# ifdef STRUCTLEAK_PLUGIN
68154+# define __user __attribute__((user))
68155+# else
68156+# define __user
68157+# endif
68158+# define __force_user
68159+# define __kernel
68160+# define __force_kernel
68161+# endif
68162 # define __safe
68163 # define __force
68164 # define __nocast
68165 # define __iomem
68166+# define __force_iomem
68167 # define __chk_user_ptr(x) (void)0
68168 # define __chk_io_ptr(x) (void)0
68169 # define __builtin_warning(x, y...) (1)
68170@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68171 # define __release(x) (void)0
68172 # define __cond_lock(x,c) (c)
68173 # define __percpu
68174+# define __force_percpu
68175 # define __rcu
68176+# define __force_rcu
68177 #endif
68178
68179 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68180@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68181 # define __attribute_const__ /* unimplemented */
68182 #endif
68183
68184+#ifndef __no_const
68185+# define __no_const
68186+#endif
68187+
68188+#ifndef __do_const
68189+# define __do_const
68190+#endif
68191+
68192+#ifndef __size_overflow
68193+# define __size_overflow(...)
68194+#endif
68195+
68196+#ifndef __intentional_overflow
68197+# define __intentional_overflow(...)
68198+#endif
68199+
68200+#ifndef __latent_entropy
68201+# define __latent_entropy
68202+#endif
68203+
68204 /*
68205 * Tell gcc if a function is cold. The compiler will assume any path
68206 * directly leading to the call is unlikely.
68207@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68208 #define __cold
68209 #endif
68210
68211+#ifndef __alloc_size
68212+#define __alloc_size(...)
68213+#endif
68214+
68215+#ifndef __bos
68216+#define __bos(ptr, arg)
68217+#endif
68218+
68219+#ifndef __bos0
68220+#define __bos0(ptr)
68221+#endif
68222+
68223+#ifndef __bos1
68224+#define __bos1(ptr)
68225+#endif
68226+
68227 /* Simple shorthand for a section definition */
68228 #ifndef __section
68229 # define __section(S) __attribute__ ((__section__(#S)))
68230@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68231 * use is to mediate communication between process-level code and irq/NMI
68232 * handlers, all running on the same CPU.
68233 */
68234-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68235+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68236+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68237
68238 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
68239 #ifdef CONFIG_KPROBES
68240diff --git a/include/linux/completion.h b/include/linux/completion.h
68241index 33f0280..35c6568 100644
68242--- a/include/linux/completion.h
68243+++ b/include/linux/completion.h
68244@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
68245 extern void wait_for_completion(struct completion *);
68246 extern void wait_for_completion_io(struct completion *);
68247 extern int wait_for_completion_interruptible(struct completion *x);
68248-extern int wait_for_completion_killable(struct completion *x);
68249+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68250 extern unsigned long wait_for_completion_timeout(struct completion *x,
68251 unsigned long timeout);
68252 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
68253 unsigned long timeout);
68254 extern long wait_for_completion_interruptible_timeout(
68255- struct completion *x, unsigned long timeout);
68256+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68257 extern long wait_for_completion_killable_timeout(
68258- struct completion *x, unsigned long timeout);
68259+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68260 extern bool try_wait_for_completion(struct completion *x);
68261 extern bool completion_done(struct completion *x);
68262
68263diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68264index 34025df..d94bbbc 100644
68265--- a/include/linux/configfs.h
68266+++ b/include/linux/configfs.h
68267@@ -125,7 +125,7 @@ struct configfs_attribute {
68268 const char *ca_name;
68269 struct module *ca_owner;
68270 umode_t ca_mode;
68271-};
68272+} __do_const;
68273
68274 /*
68275 * Users often need to create attribute structures for their configurable
68276diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68277index 9f3c7e8..a18c7b6 100644
68278--- a/include/linux/cpu.h
68279+++ b/include/linux/cpu.h
68280@@ -115,7 +115,7 @@ enum {
68281 /* Need to know about CPUs going up/down? */
68282 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68283 #define cpu_notifier(fn, pri) { \
68284- static struct notifier_block fn##_nb __cpuinitdata = \
68285+ static struct notifier_block fn##_nb = \
68286 { .notifier_call = fn, .priority = pri }; \
68287 register_cpu_notifier(&fn##_nb); \
68288 }
68289diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68290index 037d36a..ca5fe6e 100644
68291--- a/include/linux/cpufreq.h
68292+++ b/include/linux/cpufreq.h
68293@@ -262,7 +262,7 @@ struct cpufreq_driver {
68294 int (*suspend) (struct cpufreq_policy *policy);
68295 int (*resume) (struct cpufreq_policy *policy);
68296 struct freq_attr **attr;
68297-};
68298+} __do_const;
68299
68300 /* flags */
68301
68302@@ -321,6 +321,7 @@ struct global_attr {
68303 ssize_t (*store)(struct kobject *a, struct attribute *b,
68304 const char *c, size_t count);
68305 };
68306+typedef struct global_attr __no_const global_attr_no_const;
68307
68308 #define define_one_global_ro(_name) \
68309 static struct global_attr _name = \
68310diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68311index 8f04062..900239a 100644
68312--- a/include/linux/cpuidle.h
68313+++ b/include/linux/cpuidle.h
68314@@ -52,7 +52,8 @@ struct cpuidle_state {
68315 int index);
68316
68317 int (*enter_dead) (struct cpuidle_device *dev, int index);
68318-};
68319+} __do_const;
68320+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68321
68322 /* Idle State Flags */
68323 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68324@@ -191,7 +192,7 @@ struct cpuidle_governor {
68325 void (*reflect) (struct cpuidle_device *dev, int index);
68326
68327 struct module *owner;
68328-};
68329+} __do_const;
68330
68331 #ifdef CONFIG_CPU_IDLE
68332
68333diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68334index d08e4d2..95fad61 100644
68335--- a/include/linux/cpumask.h
68336+++ b/include/linux/cpumask.h
68337@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68338 }
68339
68340 /* Valid inputs for n are -1 and 0. */
68341-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68342+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68343 {
68344 return n+1;
68345 }
68346
68347-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68348+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68349 {
68350 return n+1;
68351 }
68352
68353-static inline unsigned int cpumask_next_and(int n,
68354+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68355 const struct cpumask *srcp,
68356 const struct cpumask *andp)
68357 {
68358@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68359 *
68360 * Returns >= nr_cpu_ids if no further cpus set.
68361 */
68362-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68363+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68364 {
68365 /* -1 is a legal arg here. */
68366 if (n != -1)
68367@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68368 *
68369 * Returns >= nr_cpu_ids if no further cpus unset.
68370 */
68371-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68372+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68373 {
68374 /* -1 is a legal arg here. */
68375 if (n != -1)
68376@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68377 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68378 }
68379
68380-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68381+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68382 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68383
68384 /**
68385diff --git a/include/linux/cred.h b/include/linux/cred.h
68386index 04421e8..6bce4ef 100644
68387--- a/include/linux/cred.h
68388+++ b/include/linux/cred.h
68389@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68390 static inline void validate_process_creds(void)
68391 {
68392 }
68393+static inline void validate_task_creds(struct task_struct *task)
68394+{
68395+}
68396 #endif
68397
68398 /**
68399diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68400index b92eadf..b4ecdc1 100644
68401--- a/include/linux/crypto.h
68402+++ b/include/linux/crypto.h
68403@@ -373,7 +373,7 @@ struct cipher_tfm {
68404 const u8 *key, unsigned int keylen);
68405 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68406 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68407-};
68408+} __no_const;
68409
68410 struct hash_tfm {
68411 int (*init)(struct hash_desc *desc);
68412@@ -394,13 +394,13 @@ struct compress_tfm {
68413 int (*cot_decompress)(struct crypto_tfm *tfm,
68414 const u8 *src, unsigned int slen,
68415 u8 *dst, unsigned int *dlen);
68416-};
68417+} __no_const;
68418
68419 struct rng_tfm {
68420 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68421 unsigned int dlen);
68422 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68423-};
68424+} __no_const;
68425
68426 #define crt_ablkcipher crt_u.ablkcipher
68427 #define crt_aead crt_u.aead
68428diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68429index 653589e..4ef254a 100644
68430--- a/include/linux/ctype.h
68431+++ b/include/linux/ctype.h
68432@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68433 * Fast implementation of tolower() for internal usage. Do not use in your
68434 * code.
68435 */
68436-static inline char _tolower(const char c)
68437+static inline unsigned char _tolower(const unsigned char c)
68438 {
68439 return c | 0x20;
68440 }
68441diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68442index 7925bf0..d5143d2 100644
68443--- a/include/linux/decompress/mm.h
68444+++ b/include/linux/decompress/mm.h
68445@@ -77,7 +77,7 @@ static void free(void *where)
68446 * warnings when not needed (indeed large_malloc / large_free are not
68447 * needed by inflate */
68448
68449-#define malloc(a) kmalloc(a, GFP_KERNEL)
68450+#define malloc(a) kmalloc((a), GFP_KERNEL)
68451 #define free(a) kfree(a)
68452
68453 #define large_malloc(a) vmalloc(a)
68454diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68455index fe8c447..bdc1f33 100644
68456--- a/include/linux/devfreq.h
68457+++ b/include/linux/devfreq.h
68458@@ -114,7 +114,7 @@ struct devfreq_governor {
68459 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68460 int (*event_handler)(struct devfreq *devfreq,
68461 unsigned int event, void *data);
68462-};
68463+} __do_const;
68464
68465 /**
68466 * struct devfreq - Device devfreq structure
68467diff --git a/include/linux/device.h b/include/linux/device.h
68468index c0a1261..dba7569 100644
68469--- a/include/linux/device.h
68470+++ b/include/linux/device.h
68471@@ -290,7 +290,7 @@ struct subsys_interface {
68472 struct list_head node;
68473 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68474 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68475-};
68476+} __do_const;
68477
68478 int subsys_interface_register(struct subsys_interface *sif);
68479 void subsys_interface_unregister(struct subsys_interface *sif);
68480@@ -473,7 +473,7 @@ struct device_type {
68481 void (*release)(struct device *dev);
68482
68483 const struct dev_pm_ops *pm;
68484-};
68485+} __do_const;
68486
68487 /* interface for exporting device attributes */
68488 struct device_attribute {
68489@@ -483,11 +483,12 @@ struct device_attribute {
68490 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68491 const char *buf, size_t count);
68492 };
68493+typedef struct device_attribute __no_const device_attribute_no_const;
68494
68495 struct dev_ext_attribute {
68496 struct device_attribute attr;
68497 void *var;
68498-};
68499+} __do_const;
68500
68501 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68502 char *buf);
68503diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68504index 94af418..b1ca7a2 100644
68505--- a/include/linux/dma-mapping.h
68506+++ b/include/linux/dma-mapping.h
68507@@ -54,7 +54,7 @@ struct dma_map_ops {
68508 u64 (*get_required_mask)(struct device *dev);
68509 #endif
68510 int is_phys;
68511-};
68512+} __do_const;
68513
68514 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68515
68516diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68517index 96d3e4a..dc36433 100644
68518--- a/include/linux/dmaengine.h
68519+++ b/include/linux/dmaengine.h
68520@@ -1035,9 +1035,9 @@ struct dma_pinned_list {
68521 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68522 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68523
68524-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68525+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68526 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68527-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68528+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68529 struct dma_pinned_list *pinned_list, struct page *page,
68530 unsigned int offset, size_t len);
68531
68532diff --git a/include/linux/efi.h b/include/linux/efi.h
68533index 2bc0ad7..3f7b006 100644
68534--- a/include/linux/efi.h
68535+++ b/include/linux/efi.h
68536@@ -745,6 +745,7 @@ struct efivar_operations {
68537 efi_set_variable_t *set_variable;
68538 efi_query_variable_store_t *query_variable_store;
68539 };
68540+typedef struct efivar_operations __no_const efivar_operations_no_const;
68541
68542 struct efivars {
68543 /*
68544diff --git a/include/linux/elf.h b/include/linux/elf.h
68545index 40a3c0e..4c45a38 100644
68546--- a/include/linux/elf.h
68547+++ b/include/linux/elf.h
68548@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
68549 #define elf_note elf32_note
68550 #define elf_addr_t Elf32_Off
68551 #define Elf_Half Elf32_Half
68552+#define elf_dyn Elf32_Dyn
68553
68554 #else
68555
68556@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
68557 #define elf_note elf64_note
68558 #define elf_addr_t Elf64_Off
68559 #define Elf_Half Elf64_Half
68560+#define elf_dyn Elf64_Dyn
68561
68562 #endif
68563
68564diff --git a/include/linux/err.h b/include/linux/err.h
68565index f2edce2..cc2082c 100644
68566--- a/include/linux/err.h
68567+++ b/include/linux/err.h
68568@@ -19,12 +19,12 @@
68569
68570 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68571
68572-static inline void * __must_check ERR_PTR(long error)
68573+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68574 {
68575 return (void *) error;
68576 }
68577
68578-static inline long __must_check PTR_ERR(const void *ptr)
68579+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68580 {
68581 return (long) ptr;
68582 }
68583diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68584index fcb51c8..bdafcf6 100644
68585--- a/include/linux/extcon.h
68586+++ b/include/linux/extcon.h
68587@@ -134,7 +134,7 @@ struct extcon_dev {
68588 /* /sys/class/extcon/.../mutually_exclusive/... */
68589 struct attribute_group attr_g_muex;
68590 struct attribute **attrs_muex;
68591- struct device_attribute *d_attrs_muex;
68592+ device_attribute_no_const *d_attrs_muex;
68593 };
68594
68595 /**
68596diff --git a/include/linux/fb.h b/include/linux/fb.h
68597index d49c60f..2834fbe 100644
68598--- a/include/linux/fb.h
68599+++ b/include/linux/fb.h
68600@@ -304,7 +304,7 @@ struct fb_ops {
68601 /* called at KDB enter and leave time to prepare the console */
68602 int (*fb_debug_enter)(struct fb_info *info);
68603 int (*fb_debug_leave)(struct fb_info *info);
68604-};
68605+} __do_const;
68606
68607 #ifdef CONFIG_FB_TILEBLITTING
68608 #define FB_TILE_CURSOR_NONE 0
68609diff --git a/include/linux/filter.h b/include/linux/filter.h
68610index f65f5a6..2f4f93a 100644
68611--- a/include/linux/filter.h
68612+++ b/include/linux/filter.h
68613@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68614
68615 struct sk_buff;
68616 struct sock;
68617+struct bpf_jit_work;
68618
68619 struct sk_filter
68620 {
68621@@ -27,6 +28,9 @@ struct sk_filter
68622 unsigned int len; /* Number of filter blocks */
68623 unsigned int (*bpf_func)(const struct sk_buff *skb,
68624 const struct sock_filter *filter);
68625+#ifdef CONFIG_BPF_JIT
68626+ struct bpf_jit_work *work;
68627+#endif
68628 struct rcu_head rcu;
68629 struct sock_filter insns[0];
68630 };
68631diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68632index 8293262..2b3b8bd 100644
68633--- a/include/linux/frontswap.h
68634+++ b/include/linux/frontswap.h
68635@@ -11,7 +11,7 @@ struct frontswap_ops {
68636 int (*load)(unsigned, pgoff_t, struct page *);
68637 void (*invalidate_page)(unsigned, pgoff_t);
68638 void (*invalidate_area)(unsigned);
68639-};
68640+} __no_const;
68641
68642 extern bool frontswap_enabled;
68643 extern struct frontswap_ops *
68644diff --git a/include/linux/fs.h b/include/linux/fs.h
68645index 65c2be2..4c53f6e 100644
68646--- a/include/linux/fs.h
68647+++ b/include/linux/fs.h
68648@@ -1543,7 +1543,8 @@ struct file_operations {
68649 long (*fallocate)(struct file *file, int mode, loff_t offset,
68650 loff_t len);
68651 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68652-};
68653+} __do_const;
68654+typedef struct file_operations __no_const file_operations_no_const;
68655
68656 struct inode_operations {
68657 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68658@@ -2688,4 +2689,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68659 inode->i_flags |= S_NOSEC;
68660 }
68661
68662+static inline bool is_sidechannel_device(const struct inode *inode)
68663+{
68664+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68665+ umode_t mode = inode->i_mode;
68666+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68667+#else
68668+ return false;
68669+#endif
68670+}
68671+
68672 #endif /* _LINUX_FS_H */
68673diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68674index 2b93a9a..855d94a 100644
68675--- a/include/linux/fs_struct.h
68676+++ b/include/linux/fs_struct.h
68677@@ -6,7 +6,7 @@
68678 #include <linux/seqlock.h>
68679
68680 struct fs_struct {
68681- int users;
68682+ atomic_t users;
68683 spinlock_t lock;
68684 seqcount_t seq;
68685 int umask;
68686diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68687index 5dfa0aa..6acf322 100644
68688--- a/include/linux/fscache-cache.h
68689+++ b/include/linux/fscache-cache.h
68690@@ -112,7 +112,7 @@ struct fscache_operation {
68691 fscache_operation_release_t release;
68692 };
68693
68694-extern atomic_t fscache_op_debug_id;
68695+extern atomic_unchecked_t fscache_op_debug_id;
68696 extern void fscache_op_work_func(struct work_struct *work);
68697
68698 extern void fscache_enqueue_operation(struct fscache_operation *);
68699@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68700 INIT_WORK(&op->work, fscache_op_work_func);
68701 atomic_set(&op->usage, 1);
68702 op->state = FSCACHE_OP_ST_INITIALISED;
68703- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68704+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68705 op->processor = processor;
68706 op->release = release;
68707 INIT_LIST_HEAD(&op->pend_link);
68708diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68709index 7a08623..4c07b0f 100644
68710--- a/include/linux/fscache.h
68711+++ b/include/linux/fscache.h
68712@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68713 * - this is mandatory for any object that may have data
68714 */
68715 void (*now_uncached)(void *cookie_netfs_data);
68716-};
68717+} __do_const;
68718
68719 /*
68720 * fscache cached network filesystem type
68721diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68722index a78680a..87bd73e 100644
68723--- a/include/linux/fsnotify.h
68724+++ b/include/linux/fsnotify.h
68725@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68726 struct inode *inode = path->dentry->d_inode;
68727 __u32 mask = FS_ACCESS;
68728
68729+ if (is_sidechannel_device(inode))
68730+ return;
68731+
68732 if (S_ISDIR(inode->i_mode))
68733 mask |= FS_ISDIR;
68734
68735@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68736 struct inode *inode = path->dentry->d_inode;
68737 __u32 mask = FS_MODIFY;
68738
68739+ if (is_sidechannel_device(inode))
68740+ return;
68741+
68742 if (S_ISDIR(inode->i_mode))
68743 mask |= FS_ISDIR;
68744
68745@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68746 */
68747 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68748 {
68749- return kstrdup(name, GFP_KERNEL);
68750+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68751 }
68752
68753 /*
68754diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68755index 9f3c275..911b591 100644
68756--- a/include/linux/genhd.h
68757+++ b/include/linux/genhd.h
68758@@ -194,7 +194,7 @@ struct gendisk {
68759 struct kobject *slave_dir;
68760
68761 struct timer_rand_state *random;
68762- atomic_t sync_io; /* RAID */
68763+ atomic_unchecked_t sync_io; /* RAID */
68764 struct disk_events *ev;
68765 #ifdef CONFIG_BLK_DEV_INTEGRITY
68766 struct blk_integrity *integrity;
68767diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68768index 023bc34..b02b46a 100644
68769--- a/include/linux/genl_magic_func.h
68770+++ b/include/linux/genl_magic_func.h
68771@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68772 },
68773
68774 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68775-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68776+static struct genl_ops ZZZ_genl_ops[] = {
68777 #include GENL_MAGIC_INCLUDE_FILE
68778 };
68779
68780diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68781index 0f615eb..5c3832f 100644
68782--- a/include/linux/gfp.h
68783+++ b/include/linux/gfp.h
68784@@ -35,6 +35,13 @@ struct vm_area_struct;
68785 #define ___GFP_NO_KSWAPD 0x400000u
68786 #define ___GFP_OTHER_NODE 0x800000u
68787 #define ___GFP_WRITE 0x1000000u
68788+
68789+#ifdef CONFIG_PAX_USERCOPY_SLABS
68790+#define ___GFP_USERCOPY 0x2000000u
68791+#else
68792+#define ___GFP_USERCOPY 0
68793+#endif
68794+
68795 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68796
68797 /*
68798@@ -92,6 +99,7 @@ struct vm_area_struct;
68799 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68800 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68801 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68802+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68803
68804 /*
68805 * This may seem redundant, but it's a way of annotating false positives vs.
68806@@ -99,7 +107,7 @@ struct vm_area_struct;
68807 */
68808 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68809
68810-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68811+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68812 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68813
68814 /* This equals 0, but use constants in case they ever change */
68815@@ -153,6 +161,8 @@ struct vm_area_struct;
68816 /* 4GB DMA on some platforms */
68817 #define GFP_DMA32 __GFP_DMA32
68818
68819+#define GFP_USERCOPY __GFP_USERCOPY
68820+
68821 /* Convert GFP flags to their corresponding migrate type */
68822 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68823 {
68824diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68825new file mode 100644
68826index 0000000..ebe6d72
68827--- /dev/null
68828+++ b/include/linux/gracl.h
68829@@ -0,0 +1,319 @@
68830+#ifndef GR_ACL_H
68831+#define GR_ACL_H
68832+
68833+#include <linux/grdefs.h>
68834+#include <linux/resource.h>
68835+#include <linux/capability.h>
68836+#include <linux/dcache.h>
68837+#include <asm/resource.h>
68838+
68839+/* Major status information */
68840+
68841+#define GR_VERSION "grsecurity 2.9.1"
68842+#define GRSECURITY_VERSION 0x2901
68843+
68844+enum {
68845+ GR_SHUTDOWN = 0,
68846+ GR_ENABLE = 1,
68847+ GR_SPROLE = 2,
68848+ GR_RELOAD = 3,
68849+ GR_SEGVMOD = 4,
68850+ GR_STATUS = 5,
68851+ GR_UNSPROLE = 6,
68852+ GR_PASSSET = 7,
68853+ GR_SPROLEPAM = 8,
68854+};
68855+
68856+/* Password setup definitions
68857+ * kernel/grhash.c */
68858+enum {
68859+ GR_PW_LEN = 128,
68860+ GR_SALT_LEN = 16,
68861+ GR_SHA_LEN = 32,
68862+};
68863+
68864+enum {
68865+ GR_SPROLE_LEN = 64,
68866+};
68867+
68868+enum {
68869+ GR_NO_GLOB = 0,
68870+ GR_REG_GLOB,
68871+ GR_CREATE_GLOB
68872+};
68873+
68874+#define GR_NLIMITS 32
68875+
68876+/* Begin Data Structures */
68877+
68878+struct sprole_pw {
68879+ unsigned char *rolename;
68880+ unsigned char salt[GR_SALT_LEN];
68881+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68882+};
68883+
68884+struct name_entry {
68885+ __u32 key;
68886+ ino_t inode;
68887+ dev_t device;
68888+ char *name;
68889+ __u16 len;
68890+ __u8 deleted;
68891+ struct name_entry *prev;
68892+ struct name_entry *next;
68893+};
68894+
68895+struct inodev_entry {
68896+ struct name_entry *nentry;
68897+ struct inodev_entry *prev;
68898+ struct inodev_entry *next;
68899+};
68900+
68901+struct acl_role_db {
68902+ struct acl_role_label **r_hash;
68903+ __u32 r_size;
68904+};
68905+
68906+struct inodev_db {
68907+ struct inodev_entry **i_hash;
68908+ __u32 i_size;
68909+};
68910+
68911+struct name_db {
68912+ struct name_entry **n_hash;
68913+ __u32 n_size;
68914+};
68915+
68916+struct crash_uid {
68917+ uid_t uid;
68918+ unsigned long expires;
68919+};
68920+
68921+struct gr_hash_struct {
68922+ void **table;
68923+ void **nametable;
68924+ void *first;
68925+ __u32 table_size;
68926+ __u32 used_size;
68927+ int type;
68928+};
68929+
68930+/* Userspace Grsecurity ACL data structures */
68931+
68932+struct acl_subject_label {
68933+ char *filename;
68934+ ino_t inode;
68935+ dev_t device;
68936+ __u32 mode;
68937+ kernel_cap_t cap_mask;
68938+ kernel_cap_t cap_lower;
68939+ kernel_cap_t cap_invert_audit;
68940+
68941+ struct rlimit res[GR_NLIMITS];
68942+ __u32 resmask;
68943+
68944+ __u8 user_trans_type;
68945+ __u8 group_trans_type;
68946+ uid_t *user_transitions;
68947+ gid_t *group_transitions;
68948+ __u16 user_trans_num;
68949+ __u16 group_trans_num;
68950+
68951+ __u32 sock_families[2];
68952+ __u32 ip_proto[8];
68953+ __u32 ip_type;
68954+ struct acl_ip_label **ips;
68955+ __u32 ip_num;
68956+ __u32 inaddr_any_override;
68957+
68958+ __u32 crashes;
68959+ unsigned long expires;
68960+
68961+ struct acl_subject_label *parent_subject;
68962+ struct gr_hash_struct *hash;
68963+ struct acl_subject_label *prev;
68964+ struct acl_subject_label *next;
68965+
68966+ struct acl_object_label **obj_hash;
68967+ __u32 obj_hash_size;
68968+ __u16 pax_flags;
68969+};
68970+
68971+struct role_allowed_ip {
68972+ __u32 addr;
68973+ __u32 netmask;
68974+
68975+ struct role_allowed_ip *prev;
68976+ struct role_allowed_ip *next;
68977+};
68978+
68979+struct role_transition {
68980+ char *rolename;
68981+
68982+ struct role_transition *prev;
68983+ struct role_transition *next;
68984+};
68985+
68986+struct acl_role_label {
68987+ char *rolename;
68988+ uid_t uidgid;
68989+ __u16 roletype;
68990+
68991+ __u16 auth_attempts;
68992+ unsigned long expires;
68993+
68994+ struct acl_subject_label *root_label;
68995+ struct gr_hash_struct *hash;
68996+
68997+ struct acl_role_label *prev;
68998+ struct acl_role_label *next;
68999+
69000+ struct role_transition *transitions;
69001+ struct role_allowed_ip *allowed_ips;
69002+ uid_t *domain_children;
69003+ __u16 domain_child_num;
69004+
69005+ umode_t umask;
69006+
69007+ struct acl_subject_label **subj_hash;
69008+ __u32 subj_hash_size;
69009+};
69010+
69011+struct user_acl_role_db {
69012+ struct acl_role_label **r_table;
69013+ __u32 num_pointers; /* Number of allocations to track */
69014+ __u32 num_roles; /* Number of roles */
69015+ __u32 num_domain_children; /* Number of domain children */
69016+ __u32 num_subjects; /* Number of subjects */
69017+ __u32 num_objects; /* Number of objects */
69018+};
69019+
69020+struct acl_object_label {
69021+ char *filename;
69022+ ino_t inode;
69023+ dev_t device;
69024+ __u32 mode;
69025+
69026+ struct acl_subject_label *nested;
69027+ struct acl_object_label *globbed;
69028+
69029+ /* next two structures not used */
69030+
69031+ struct acl_object_label *prev;
69032+ struct acl_object_label *next;
69033+};
69034+
69035+struct acl_ip_label {
69036+ char *iface;
69037+ __u32 addr;
69038+ __u32 netmask;
69039+ __u16 low, high;
69040+ __u8 mode;
69041+ __u32 type;
69042+ __u32 proto[8];
69043+
69044+ /* next two structures not used */
69045+
69046+ struct acl_ip_label *prev;
69047+ struct acl_ip_label *next;
69048+};
69049+
69050+struct gr_arg {
69051+ struct user_acl_role_db role_db;
69052+ unsigned char pw[GR_PW_LEN];
69053+ unsigned char salt[GR_SALT_LEN];
69054+ unsigned char sum[GR_SHA_LEN];
69055+ unsigned char sp_role[GR_SPROLE_LEN];
69056+ struct sprole_pw *sprole_pws;
69057+ dev_t segv_device;
69058+ ino_t segv_inode;
69059+ uid_t segv_uid;
69060+ __u16 num_sprole_pws;
69061+ __u16 mode;
69062+};
69063+
69064+struct gr_arg_wrapper {
69065+ struct gr_arg *arg;
69066+ __u32 version;
69067+ __u32 size;
69068+};
69069+
69070+struct subject_map {
69071+ struct acl_subject_label *user;
69072+ struct acl_subject_label *kernel;
69073+ struct subject_map *prev;
69074+ struct subject_map *next;
69075+};
69076+
69077+struct acl_subj_map_db {
69078+ struct subject_map **s_hash;
69079+ __u32 s_size;
69080+};
69081+
69082+/* End Data Structures Section */
69083+
69084+/* Hash functions generated by empirical testing by Brad Spengler
69085+ Makes good use of the low bits of the inode. Generally 0-1 times
69086+ in loop for successful match. 0-3 for unsuccessful match.
69087+ Shift/add algorithm with modulus of table size and an XOR*/
69088+
69089+static __inline__ unsigned int
69090+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
69091+{
69092+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
69093+}
69094+
69095+ static __inline__ unsigned int
69096+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
69097+{
69098+ return ((const unsigned long)userp % sz);
69099+}
69100+
69101+static __inline__ unsigned int
69102+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
69103+{
69104+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
69105+}
69106+
69107+static __inline__ unsigned int
69108+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
69109+{
69110+ return full_name_hash((const unsigned char *)name, len) % sz;
69111+}
69112+
69113+#define FOR_EACH_ROLE_START(role) \
69114+ role = role_list; \
69115+ while (role) {
69116+
69117+#define FOR_EACH_ROLE_END(role) \
69118+ role = role->prev; \
69119+ }
69120+
69121+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
69122+ subj = NULL; \
69123+ iter = 0; \
69124+ while (iter < role->subj_hash_size) { \
69125+ if (subj == NULL) \
69126+ subj = role->subj_hash[iter]; \
69127+ if (subj == NULL) { \
69128+ iter++; \
69129+ continue; \
69130+ }
69131+
69132+#define FOR_EACH_SUBJECT_END(subj,iter) \
69133+ subj = subj->next; \
69134+ if (subj == NULL) \
69135+ iter++; \
69136+ }
69137+
69138+
69139+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
69140+ subj = role->hash->first; \
69141+ while (subj != NULL) {
69142+
69143+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
69144+ subj = subj->next; \
69145+ }
69146+
69147+#endif
69148+
69149diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69150new file mode 100644
69151index 0000000..323ecf2
69152--- /dev/null
69153+++ b/include/linux/gralloc.h
69154@@ -0,0 +1,9 @@
69155+#ifndef __GRALLOC_H
69156+#define __GRALLOC_H
69157+
69158+void acl_free_all(void);
69159+int acl_alloc_stack_init(unsigned long size);
69160+void *acl_alloc(unsigned long len);
69161+void *acl_alloc_num(unsigned long num, unsigned long len);
69162+
69163+#endif
69164diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69165new file mode 100644
69166index 0000000..be66033
69167--- /dev/null
69168+++ b/include/linux/grdefs.h
69169@@ -0,0 +1,140 @@
69170+#ifndef GRDEFS_H
69171+#define GRDEFS_H
69172+
69173+/* Begin grsecurity status declarations */
69174+
69175+enum {
69176+ GR_READY = 0x01,
69177+ GR_STATUS_INIT = 0x00 // disabled state
69178+};
69179+
69180+/* Begin ACL declarations */
69181+
69182+/* Role flags */
69183+
69184+enum {
69185+ GR_ROLE_USER = 0x0001,
69186+ GR_ROLE_GROUP = 0x0002,
69187+ GR_ROLE_DEFAULT = 0x0004,
69188+ GR_ROLE_SPECIAL = 0x0008,
69189+ GR_ROLE_AUTH = 0x0010,
69190+ GR_ROLE_NOPW = 0x0020,
69191+ GR_ROLE_GOD = 0x0040,
69192+ GR_ROLE_LEARN = 0x0080,
69193+ GR_ROLE_TPE = 0x0100,
69194+ GR_ROLE_DOMAIN = 0x0200,
69195+ GR_ROLE_PAM = 0x0400,
69196+ GR_ROLE_PERSIST = 0x0800
69197+};
69198+
69199+/* ACL Subject and Object mode flags */
69200+enum {
69201+ GR_DELETED = 0x80000000
69202+};
69203+
69204+/* ACL Object-only mode flags */
69205+enum {
69206+ GR_READ = 0x00000001,
69207+ GR_APPEND = 0x00000002,
69208+ GR_WRITE = 0x00000004,
69209+ GR_EXEC = 0x00000008,
69210+ GR_FIND = 0x00000010,
69211+ GR_INHERIT = 0x00000020,
69212+ GR_SETID = 0x00000040,
69213+ GR_CREATE = 0x00000080,
69214+ GR_DELETE = 0x00000100,
69215+ GR_LINK = 0x00000200,
69216+ GR_AUDIT_READ = 0x00000400,
69217+ GR_AUDIT_APPEND = 0x00000800,
69218+ GR_AUDIT_WRITE = 0x00001000,
69219+ GR_AUDIT_EXEC = 0x00002000,
69220+ GR_AUDIT_FIND = 0x00004000,
69221+ GR_AUDIT_INHERIT= 0x00008000,
69222+ GR_AUDIT_SETID = 0x00010000,
69223+ GR_AUDIT_CREATE = 0x00020000,
69224+ GR_AUDIT_DELETE = 0x00040000,
69225+ GR_AUDIT_LINK = 0x00080000,
69226+ GR_PTRACERD = 0x00100000,
69227+ GR_NOPTRACE = 0x00200000,
69228+ GR_SUPPRESS = 0x00400000,
69229+ GR_NOLEARN = 0x00800000,
69230+ GR_INIT_TRANSFER= 0x01000000
69231+};
69232+
69233+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69234+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69235+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69236+
69237+/* ACL subject-only mode flags */
69238+enum {
69239+ GR_KILL = 0x00000001,
69240+ GR_VIEW = 0x00000002,
69241+ GR_PROTECTED = 0x00000004,
69242+ GR_LEARN = 0x00000008,
69243+ GR_OVERRIDE = 0x00000010,
69244+ /* just a placeholder, this mode is only used in userspace */
69245+ GR_DUMMY = 0x00000020,
69246+ GR_PROTSHM = 0x00000040,
69247+ GR_KILLPROC = 0x00000080,
69248+ GR_KILLIPPROC = 0x00000100,
69249+ /* just a placeholder, this mode is only used in userspace */
69250+ GR_NOTROJAN = 0x00000200,
69251+ GR_PROTPROCFD = 0x00000400,
69252+ GR_PROCACCT = 0x00000800,
69253+ GR_RELAXPTRACE = 0x00001000,
69254+ //GR_NESTED = 0x00002000,
69255+ GR_INHERITLEARN = 0x00004000,
69256+ GR_PROCFIND = 0x00008000,
69257+ GR_POVERRIDE = 0x00010000,
69258+ GR_KERNELAUTH = 0x00020000,
69259+ GR_ATSECURE = 0x00040000,
69260+ GR_SHMEXEC = 0x00080000
69261+};
69262+
69263+enum {
69264+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69265+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69266+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69267+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69268+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69269+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69270+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69271+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69272+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69273+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69274+};
69275+
69276+enum {
69277+ GR_ID_USER = 0x01,
69278+ GR_ID_GROUP = 0x02,
69279+};
69280+
69281+enum {
69282+ GR_ID_ALLOW = 0x01,
69283+ GR_ID_DENY = 0x02,
69284+};
69285+
69286+#define GR_CRASH_RES 31
69287+#define GR_UIDTABLE_MAX 500
69288+
69289+/* begin resource learning section */
69290+enum {
69291+ GR_RLIM_CPU_BUMP = 60,
69292+ GR_RLIM_FSIZE_BUMP = 50000,
69293+ GR_RLIM_DATA_BUMP = 10000,
69294+ GR_RLIM_STACK_BUMP = 1000,
69295+ GR_RLIM_CORE_BUMP = 10000,
69296+ GR_RLIM_RSS_BUMP = 500000,
69297+ GR_RLIM_NPROC_BUMP = 1,
69298+ GR_RLIM_NOFILE_BUMP = 5,
69299+ GR_RLIM_MEMLOCK_BUMP = 50000,
69300+ GR_RLIM_AS_BUMP = 500000,
69301+ GR_RLIM_LOCKS_BUMP = 2,
69302+ GR_RLIM_SIGPENDING_BUMP = 5,
69303+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69304+ GR_RLIM_NICE_BUMP = 1,
69305+ GR_RLIM_RTPRIO_BUMP = 1,
69306+ GR_RLIM_RTTIME_BUMP = 1000000
69307+};
69308+
69309+#endif
69310diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69311new file mode 100644
69312index 0000000..12994b5
69313--- /dev/null
69314+++ b/include/linux/grinternal.h
69315@@ -0,0 +1,227 @@
69316+#ifndef __GRINTERNAL_H
69317+#define __GRINTERNAL_H
69318+
69319+#ifdef CONFIG_GRKERNSEC
69320+
69321+#include <linux/fs.h>
69322+#include <linux/mnt_namespace.h>
69323+#include <linux/nsproxy.h>
69324+#include <linux/gracl.h>
69325+#include <linux/grdefs.h>
69326+#include <linux/grmsg.h>
69327+
69328+void gr_add_learn_entry(const char *fmt, ...)
69329+ __attribute__ ((format (printf, 1, 2)));
69330+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69331+ const struct vfsmount *mnt);
69332+__u32 gr_check_create(const struct dentry *new_dentry,
69333+ const struct dentry *parent,
69334+ const struct vfsmount *mnt, const __u32 mode);
69335+int gr_check_protected_task(const struct task_struct *task);
69336+__u32 to_gr_audit(const __u32 reqmode);
69337+int gr_set_acls(const int type);
69338+int gr_apply_subject_to_task(struct task_struct *task);
69339+int gr_acl_is_enabled(void);
69340+char gr_roletype_to_char(void);
69341+
69342+void gr_handle_alertkill(struct task_struct *task);
69343+char *gr_to_filename(const struct dentry *dentry,
69344+ const struct vfsmount *mnt);
69345+char *gr_to_filename1(const struct dentry *dentry,
69346+ const struct vfsmount *mnt);
69347+char *gr_to_filename2(const struct dentry *dentry,
69348+ const struct vfsmount *mnt);
69349+char *gr_to_filename3(const struct dentry *dentry,
69350+ const struct vfsmount *mnt);
69351+
69352+extern int grsec_enable_ptrace_readexec;
69353+extern int grsec_enable_harden_ptrace;
69354+extern int grsec_enable_link;
69355+extern int grsec_enable_fifo;
69356+extern int grsec_enable_execve;
69357+extern int grsec_enable_shm;
69358+extern int grsec_enable_execlog;
69359+extern int grsec_enable_signal;
69360+extern int grsec_enable_audit_ptrace;
69361+extern int grsec_enable_forkfail;
69362+extern int grsec_enable_time;
69363+extern int grsec_enable_rofs;
69364+extern int grsec_enable_chroot_shmat;
69365+extern int grsec_enable_chroot_mount;
69366+extern int grsec_enable_chroot_double;
69367+extern int grsec_enable_chroot_pivot;
69368+extern int grsec_enable_chroot_chdir;
69369+extern int grsec_enable_chroot_chmod;
69370+extern int grsec_enable_chroot_mknod;
69371+extern int grsec_enable_chroot_fchdir;
69372+extern int grsec_enable_chroot_nice;
69373+extern int grsec_enable_chroot_execlog;
69374+extern int grsec_enable_chroot_caps;
69375+extern int grsec_enable_chroot_sysctl;
69376+extern int grsec_enable_chroot_unix;
69377+extern int grsec_enable_symlinkown;
69378+extern kgid_t grsec_symlinkown_gid;
69379+extern int grsec_enable_tpe;
69380+extern kgid_t grsec_tpe_gid;
69381+extern int grsec_enable_tpe_all;
69382+extern int grsec_enable_tpe_invert;
69383+extern int grsec_enable_socket_all;
69384+extern kgid_t grsec_socket_all_gid;
69385+extern int grsec_enable_socket_client;
69386+extern kgid_t grsec_socket_client_gid;
69387+extern int grsec_enable_socket_server;
69388+extern kgid_t grsec_socket_server_gid;
69389+extern kgid_t grsec_audit_gid;
69390+extern int grsec_enable_group;
69391+extern int grsec_enable_audit_textrel;
69392+extern int grsec_enable_log_rwxmaps;
69393+extern int grsec_enable_mount;
69394+extern int grsec_enable_chdir;
69395+extern int grsec_resource_logging;
69396+extern int grsec_enable_blackhole;
69397+extern int grsec_lastack_retries;
69398+extern int grsec_enable_brute;
69399+extern int grsec_lock;
69400+
69401+extern spinlock_t grsec_alert_lock;
69402+extern unsigned long grsec_alert_wtime;
69403+extern unsigned long grsec_alert_fyet;
69404+
69405+extern spinlock_t grsec_audit_lock;
69406+
69407+extern rwlock_t grsec_exec_file_lock;
69408+
69409+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69410+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69411+ (tsk)->exec_file->f_path.mnt) : "/")
69412+
69413+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69414+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69415+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
69416+
69417+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69418+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69419+ (tsk)->exec_file->f_path.mnt) : "/")
69420+
69421+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69422+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69423+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
69424+
69425+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69426+
69427+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69428+
69429+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
69430+{
69431+ if (file1 && file2) {
69432+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
69433+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
69434+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
69435+ return true;
69436+ }
69437+
69438+ return false;
69439+}
69440+
69441+#define GR_CHROOT_CAPS {{ \
69442+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69443+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69444+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69445+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69446+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69447+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69448+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69449+
69450+#define security_learn(normal_msg,args...) \
69451+({ \
69452+ read_lock(&grsec_exec_file_lock); \
69453+ gr_add_learn_entry(normal_msg "\n", ## args); \
69454+ read_unlock(&grsec_exec_file_lock); \
69455+})
69456+
69457+enum {
69458+ GR_DO_AUDIT,
69459+ GR_DONT_AUDIT,
69460+ /* used for non-audit messages that we shouldn't kill the task on */
69461+ GR_DONT_AUDIT_GOOD
69462+};
69463+
69464+enum {
69465+ GR_TTYSNIFF,
69466+ GR_RBAC,
69467+ GR_RBAC_STR,
69468+ GR_STR_RBAC,
69469+ GR_RBAC_MODE2,
69470+ GR_RBAC_MODE3,
69471+ GR_FILENAME,
69472+ GR_SYSCTL_HIDDEN,
69473+ GR_NOARGS,
69474+ GR_ONE_INT,
69475+ GR_ONE_INT_TWO_STR,
69476+ GR_ONE_STR,
69477+ GR_STR_INT,
69478+ GR_TWO_STR_INT,
69479+ GR_TWO_INT,
69480+ GR_TWO_U64,
69481+ GR_THREE_INT,
69482+ GR_FIVE_INT_TWO_STR,
69483+ GR_TWO_STR,
69484+ GR_THREE_STR,
69485+ GR_FOUR_STR,
69486+ GR_STR_FILENAME,
69487+ GR_FILENAME_STR,
69488+ GR_FILENAME_TWO_INT,
69489+ GR_FILENAME_TWO_INT_STR,
69490+ GR_TEXTREL,
69491+ GR_PTRACE,
69492+ GR_RESOURCE,
69493+ GR_CAP,
69494+ GR_SIG,
69495+ GR_SIG2,
69496+ GR_CRASH1,
69497+ GR_CRASH2,
69498+ GR_PSACCT,
69499+ GR_RWXMAP
69500+};
69501+
69502+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69503+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69504+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69505+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69506+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69507+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69508+#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)
69509+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69510+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69511+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69512+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69513+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69514+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69515+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69516+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69517+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69518+#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)
69519+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69520+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69521+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69522+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69523+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69524+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69525+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69526+#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)
69527+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69528+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69529+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69530+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69531+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69532+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69533+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69534+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69535+#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)
69536+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69537+
69538+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69539+
69540+#endif
69541+
69542+#endif
69543diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69544new file mode 100644
69545index 0000000..2f159b5
69546--- /dev/null
69547+++ b/include/linux/grmsg.h
69548@@ -0,0 +1,112 @@
69549+#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"
69550+#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"
69551+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69552+#define GR_STOPMOD_MSG "denied modification of module state by "
69553+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69554+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69555+#define GR_IOPERM_MSG "denied use of ioperm() by "
69556+#define GR_IOPL_MSG "denied use of iopl() by "
69557+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69558+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69559+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69560+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69561+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69562+#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"
69563+#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"
69564+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69565+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69566+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69567+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69568+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69569+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69570+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69571+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69572+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69573+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69574+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69575+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69576+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69577+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69578+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69579+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69580+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69581+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69582+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69583+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69584+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69585+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69586+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69587+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69588+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69589+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69590+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69591+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69592+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69593+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69594+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69595+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69596+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69597+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69598+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69599+#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"
69600+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69601+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69602+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69603+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69604+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69605+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69606+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69607+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69608+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69609+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69610+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69611+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69612+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69613+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69614+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69615+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69616+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69617+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69618+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69619+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69620+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69621+#define GR_NICE_CHROOT_MSG "denied priority change by "
69622+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69623+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69624+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69625+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69626+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69627+#define GR_TIME_MSG "time set by "
69628+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69629+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69630+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69631+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69632+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69633+#define GR_BIND_MSG "denied bind() by "
69634+#define GR_CONNECT_MSG "denied connect() by "
69635+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69636+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69637+#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"
69638+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69639+#define GR_CAP_ACL_MSG "use of %s denied for "
69640+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69641+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69642+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69643+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69644+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69645+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69646+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69647+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69648+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69649+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69650+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69651+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69652+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69653+#define GR_VM86_MSG "denied use of vm86 by "
69654+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69655+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69656+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69657+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69658+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69659+#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 "
69660+#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 "
69661diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69662new file mode 100644
69663index 0000000..d957f6d
69664--- /dev/null
69665+++ b/include/linux/grsecurity.h
69666@@ -0,0 +1,241 @@
69667+#ifndef GR_SECURITY_H
69668+#define GR_SECURITY_H
69669+#include <linux/fs.h>
69670+#include <linux/fs_struct.h>
69671+#include <linux/binfmts.h>
69672+#include <linux/gracl.h>
69673+
69674+/* notify of brain-dead configs */
69675+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69676+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69677+#endif
69678+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69679+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69680+#endif
69681+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69682+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69683+#endif
69684+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69685+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69686+#endif
69687+
69688+void gr_handle_brute_attach(unsigned long mm_flags);
69689+void gr_handle_brute_check(void);
69690+void gr_handle_kernel_exploit(void);
69691+
69692+char gr_roletype_to_char(void);
69693+
69694+int gr_acl_enable_at_secure(void);
69695+
69696+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69697+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69698+
69699+void gr_del_task_from_ip_table(struct task_struct *p);
69700+
69701+int gr_pid_is_chrooted(struct task_struct *p);
69702+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69703+int gr_handle_chroot_nice(void);
69704+int gr_handle_chroot_sysctl(const int op);
69705+int gr_handle_chroot_setpriority(struct task_struct *p,
69706+ const int niceval);
69707+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69708+int gr_handle_chroot_chroot(const struct dentry *dentry,
69709+ const struct vfsmount *mnt);
69710+void gr_handle_chroot_chdir(const struct path *path);
69711+int gr_handle_chroot_chmod(const struct dentry *dentry,
69712+ const struct vfsmount *mnt, const int mode);
69713+int gr_handle_chroot_mknod(const struct dentry *dentry,
69714+ const struct vfsmount *mnt, const int mode);
69715+int gr_handle_chroot_mount(const struct dentry *dentry,
69716+ const struct vfsmount *mnt,
69717+ const char *dev_name);
69718+int gr_handle_chroot_pivot(void);
69719+int gr_handle_chroot_unix(const pid_t pid);
69720+
69721+int gr_handle_rawio(const struct inode *inode);
69722+
69723+void gr_handle_ioperm(void);
69724+void gr_handle_iopl(void);
69725+
69726+umode_t gr_acl_umask(void);
69727+
69728+int gr_tpe_allow(const struct file *file);
69729+
69730+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
69731+void gr_clear_chroot_entries(struct task_struct *task);
69732+
69733+void gr_log_forkfail(const int retval);
69734+void gr_log_timechange(void);
69735+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69736+void gr_log_chdir(const struct dentry *dentry,
69737+ const struct vfsmount *mnt);
69738+void gr_log_chroot_exec(const struct dentry *dentry,
69739+ const struct vfsmount *mnt);
69740+void gr_log_remount(const char *devname, const int retval);
69741+void gr_log_unmount(const char *devname, const int retval);
69742+void gr_log_mount(const char *from, const char *to, const int retval);
69743+void gr_log_textrel(struct vm_area_struct *vma);
69744+void gr_log_rwxmmap(struct file *file);
69745+void gr_log_rwxmprotect(struct file *file);
69746+
69747+int gr_handle_follow_link(const struct inode *parent,
69748+ const struct inode *inode,
69749+ const struct dentry *dentry,
69750+ const struct vfsmount *mnt);
69751+int gr_handle_fifo(const struct dentry *dentry,
69752+ const struct vfsmount *mnt,
69753+ const struct dentry *dir, const int flag,
69754+ const int acc_mode);
69755+int gr_handle_hardlink(const struct dentry *dentry,
69756+ const struct vfsmount *mnt,
69757+ struct inode *inode,
69758+ const int mode, const struct filename *to);
69759+
69760+int gr_is_capable(const int cap);
69761+int gr_is_capable_nolog(const int cap);
69762+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69763+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69764+
69765+void gr_copy_label(struct task_struct *tsk);
69766+void gr_handle_crash(struct task_struct *task, const int sig);
69767+int gr_handle_signal(const struct task_struct *p, const int sig);
69768+int gr_check_crash_uid(const kuid_t uid);
69769+int gr_check_protected_task(const struct task_struct *task);
69770+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69771+int gr_acl_handle_mmap(const struct file *file,
69772+ const unsigned long prot);
69773+int gr_acl_handle_mprotect(const struct file *file,
69774+ const unsigned long prot);
69775+int gr_check_hidden_task(const struct task_struct *tsk);
69776+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69777+ const struct vfsmount *mnt);
69778+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69779+ const struct vfsmount *mnt);
69780+__u32 gr_acl_handle_access(const struct dentry *dentry,
69781+ const struct vfsmount *mnt, const int fmode);
69782+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69783+ const struct vfsmount *mnt, umode_t *mode);
69784+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69785+ const struct vfsmount *mnt);
69786+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69787+ const struct vfsmount *mnt);
69788+int gr_handle_ptrace(struct task_struct *task, const long request);
69789+int gr_handle_proc_ptrace(struct task_struct *task);
69790+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69791+ const struct vfsmount *mnt);
69792+int gr_check_crash_exec(const struct file *filp);
69793+int gr_acl_is_enabled(void);
69794+void gr_set_kernel_label(struct task_struct *task);
69795+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69796+ const kgid_t gid);
69797+int gr_set_proc_label(const struct dentry *dentry,
69798+ const struct vfsmount *mnt,
69799+ const int unsafe_flags);
69800+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69801+ const struct vfsmount *mnt);
69802+__u32 gr_acl_handle_open(const struct dentry *dentry,
69803+ const struct vfsmount *mnt, int acc_mode);
69804+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69805+ const struct dentry *p_dentry,
69806+ const struct vfsmount *p_mnt,
69807+ int open_flags, int acc_mode, const int imode);
69808+void gr_handle_create(const struct dentry *dentry,
69809+ const struct vfsmount *mnt);
69810+void gr_handle_proc_create(const struct dentry *dentry,
69811+ const struct inode *inode);
69812+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69813+ const struct dentry *parent_dentry,
69814+ const struct vfsmount *parent_mnt,
69815+ const int mode);
69816+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69817+ const struct dentry *parent_dentry,
69818+ const struct vfsmount *parent_mnt);
69819+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69820+ const struct vfsmount *mnt);
69821+void gr_handle_delete(const ino_t ino, const dev_t dev);
69822+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69823+ const struct vfsmount *mnt);
69824+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69825+ const struct dentry *parent_dentry,
69826+ const struct vfsmount *parent_mnt,
69827+ const struct filename *from);
69828+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69829+ const struct dentry *parent_dentry,
69830+ const struct vfsmount *parent_mnt,
69831+ const struct dentry *old_dentry,
69832+ const struct vfsmount *old_mnt, const struct filename *to);
69833+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69834+int gr_acl_handle_rename(struct dentry *new_dentry,
69835+ struct dentry *parent_dentry,
69836+ const struct vfsmount *parent_mnt,
69837+ struct dentry *old_dentry,
69838+ struct inode *old_parent_inode,
69839+ struct vfsmount *old_mnt, const struct filename *newname);
69840+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69841+ struct dentry *old_dentry,
69842+ struct dentry *new_dentry,
69843+ struct vfsmount *mnt, const __u8 replace);
69844+__u32 gr_check_link(const struct dentry *new_dentry,
69845+ const struct dentry *parent_dentry,
69846+ const struct vfsmount *parent_mnt,
69847+ const struct dentry *old_dentry,
69848+ const struct vfsmount *old_mnt);
69849+int gr_acl_handle_filldir(const struct file *file, const char *name,
69850+ const unsigned int namelen, const ino_t ino);
69851+
69852+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69853+ const struct vfsmount *mnt);
69854+void gr_acl_handle_exit(void);
69855+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69856+int gr_acl_handle_procpidmem(const struct task_struct *task);
69857+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69858+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69859+void gr_audit_ptrace(struct task_struct *task);
69860+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69861+void gr_put_exec_file(struct task_struct *task);
69862+
69863+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69864+
69865+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69866+extern void gr_learn_resource(const struct task_struct *task, const int res,
69867+ const unsigned long wanted, const int gt);
69868+#else
69869+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69870+ const unsigned long wanted, const int gt)
69871+{
69872+}
69873+#endif
69874+
69875+#ifdef CONFIG_GRKERNSEC_RESLOG
69876+extern void gr_log_resource(const struct task_struct *task, const int res,
69877+ const unsigned long wanted, const int gt);
69878+#else
69879+static inline void gr_log_resource(const struct task_struct *task, const int res,
69880+ const unsigned long wanted, const int gt)
69881+{
69882+}
69883+#endif
69884+
69885+#ifdef CONFIG_GRKERNSEC
69886+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69887+void gr_handle_vm86(void);
69888+void gr_handle_mem_readwrite(u64 from, u64 to);
69889+
69890+void gr_log_badprocpid(const char *entry);
69891+
69892+extern int grsec_enable_dmesg;
69893+extern int grsec_disable_privio;
69894+
69895+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69896+extern kgid_t grsec_proc_gid;
69897+#endif
69898+
69899+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69900+extern int grsec_enable_chroot_findtask;
69901+#endif
69902+#ifdef CONFIG_GRKERNSEC_SETXID
69903+extern int grsec_enable_setxid;
69904+#endif
69905+#endif
69906+
69907+#endif
69908diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69909new file mode 100644
69910index 0000000..e7ffaaf
69911--- /dev/null
69912+++ b/include/linux/grsock.h
69913@@ -0,0 +1,19 @@
69914+#ifndef __GRSOCK_H
69915+#define __GRSOCK_H
69916+
69917+extern void gr_attach_curr_ip(const struct sock *sk);
69918+extern int gr_handle_sock_all(const int family, const int type,
69919+ const int protocol);
69920+extern int gr_handle_sock_server(const struct sockaddr *sck);
69921+extern int gr_handle_sock_server_other(const struct sock *sck);
69922+extern int gr_handle_sock_client(const struct sockaddr *sck);
69923+extern int gr_search_connect(struct socket * sock,
69924+ struct sockaddr_in * addr);
69925+extern int gr_search_bind(struct socket * sock,
69926+ struct sockaddr_in * addr);
69927+extern int gr_search_listen(struct socket * sock);
69928+extern int gr_search_accept(struct socket * sock);
69929+extern int gr_search_socket(const int domain, const int type,
69930+ const int protocol);
69931+
69932+#endif
69933diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69934index 7fb31da..08b5114 100644
69935--- a/include/linux/highmem.h
69936+++ b/include/linux/highmem.h
69937@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69938 kunmap_atomic(kaddr);
69939 }
69940
69941+static inline void sanitize_highpage(struct page *page)
69942+{
69943+ void *kaddr;
69944+ unsigned long flags;
69945+
69946+ local_irq_save(flags);
69947+ kaddr = kmap_atomic(page);
69948+ clear_page(kaddr);
69949+ kunmap_atomic(kaddr);
69950+ local_irq_restore(flags);
69951+}
69952+
69953 static inline void zero_user_segments(struct page *page,
69954 unsigned start1, unsigned end1,
69955 unsigned start2, unsigned end2)
69956diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69957index 1c7b89a..7f52502 100644
69958--- a/include/linux/hwmon-sysfs.h
69959+++ b/include/linux/hwmon-sysfs.h
69960@@ -25,7 +25,8 @@
69961 struct sensor_device_attribute{
69962 struct device_attribute dev_attr;
69963 int index;
69964-};
69965+} __do_const;
69966+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69967 #define to_sensor_dev_attr(_dev_attr) \
69968 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69969
69970@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69971 struct device_attribute dev_attr;
69972 u8 index;
69973 u8 nr;
69974-};
69975+} __do_const;
69976 #define to_sensor_dev_attr_2(_dev_attr) \
69977 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69978
69979diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69980index e988fa9..ff9f17e 100644
69981--- a/include/linux/i2c.h
69982+++ b/include/linux/i2c.h
69983@@ -366,6 +366,7 @@ struct i2c_algorithm {
69984 /* To determine what the adapter supports */
69985 u32 (*functionality) (struct i2c_adapter *);
69986 };
69987+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69988
69989 /**
69990 * struct i2c_bus_recovery_info - I2C bus recovery information
69991diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69992index d23c3c2..eb63c81 100644
69993--- a/include/linux/i2o.h
69994+++ b/include/linux/i2o.h
69995@@ -565,7 +565,7 @@ struct i2o_controller {
69996 struct i2o_device *exec; /* Executive */
69997 #if BITS_PER_LONG == 64
69998 spinlock_t context_list_lock; /* lock for context_list */
69999- atomic_t context_list_counter; /* needed for unique contexts */
70000+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
70001 struct list_head context_list; /* list of context id's
70002 and pointers */
70003 #endif
70004diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
70005index aff7ad8..3942bbd 100644
70006--- a/include/linux/if_pppox.h
70007+++ b/include/linux/if_pppox.h
70008@@ -76,7 +76,7 @@ struct pppox_proto {
70009 int (*ioctl)(struct socket *sock, unsigned int cmd,
70010 unsigned long arg);
70011 struct module *owner;
70012-};
70013+} __do_const;
70014
70015 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
70016 extern void unregister_pppox_proto(int proto_num);
70017diff --git a/include/linux/init.h b/include/linux/init.h
70018index 8618147..0821126 100644
70019--- a/include/linux/init.h
70020+++ b/include/linux/init.h
70021@@ -39,9 +39,36 @@
70022 * Also note, that this data cannot be "const".
70023 */
70024
70025+#ifdef MODULE
70026+#define add_init_latent_entropy
70027+#define add_devinit_latent_entropy
70028+#define add_cpuinit_latent_entropy
70029+#define add_meminit_latent_entropy
70030+#else
70031+#define add_init_latent_entropy __latent_entropy
70032+
70033+#ifdef CONFIG_HOTPLUG
70034+#define add_devinit_latent_entropy
70035+#else
70036+#define add_devinit_latent_entropy __latent_entropy
70037+#endif
70038+
70039+#ifdef CONFIG_HOTPLUG_CPU
70040+#define add_cpuinit_latent_entropy
70041+#else
70042+#define add_cpuinit_latent_entropy __latent_entropy
70043+#endif
70044+
70045+#ifdef CONFIG_MEMORY_HOTPLUG
70046+#define add_meminit_latent_entropy
70047+#else
70048+#define add_meminit_latent_entropy __latent_entropy
70049+#endif
70050+#endif
70051+
70052 /* These are for everybody (although not all archs will actually
70053 discard it in modules) */
70054-#define __init __section(.init.text) __cold notrace
70055+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
70056 #define __initdata __section(.init.data)
70057 #define __initconst __constsection(.init.rodata)
70058 #define __exitdata __section(.exit.data)
70059@@ -94,7 +121,7 @@
70060 #define __exit __section(.exit.text) __exitused __cold notrace
70061
70062 /* Used for HOTPLUG_CPU */
70063-#define __cpuinit __section(.cpuinit.text) __cold notrace
70064+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
70065 #define __cpuinitdata __section(.cpuinit.data)
70066 #define __cpuinitconst __constsection(.cpuinit.rodata)
70067 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
70068@@ -102,7 +129,7 @@
70069 #define __cpuexitconst __constsection(.cpuexit.rodata)
70070
70071 /* Used for MEMORY_HOTPLUG */
70072-#define __meminit __section(.meminit.text) __cold notrace
70073+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
70074 #define __meminitdata __section(.meminit.data)
70075 #define __meminitconst __constsection(.meminit.rodata)
70076 #define __memexit __section(.memexit.text) __exitused __cold notrace
70077diff --git a/include/linux/init_task.h b/include/linux/init_task.h
70078index 5cd0f09..c9f67cc 100644
70079--- a/include/linux/init_task.h
70080+++ b/include/linux/init_task.h
70081@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
70082
70083 #define INIT_TASK_COMM "swapper"
70084
70085+#ifdef CONFIG_X86
70086+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
70087+#else
70088+#define INIT_TASK_THREAD_INFO
70089+#endif
70090+
70091 /*
70092 * INIT_TASK is used to set up the first task table, touch at
70093 * your own risk!. Base=0, limit=0x1fffff (=2MB)
70094@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
70095 RCU_POINTER_INITIALIZER(cred, &init_cred), \
70096 .comm = INIT_TASK_COMM, \
70097 .thread = INIT_THREAD, \
70098+ INIT_TASK_THREAD_INFO \
70099 .fs = &init_fs, \
70100 .files = &init_files, \
70101 .signal = &init_signals, \
70102diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
70103index 5fa5afe..ac55b25 100644
70104--- a/include/linux/interrupt.h
70105+++ b/include/linux/interrupt.h
70106@@ -430,7 +430,7 @@ enum
70107 /* map softirq index to softirq name. update 'softirq_to_name' in
70108 * kernel/softirq.c when adding a new softirq.
70109 */
70110-extern char *softirq_to_name[NR_SOFTIRQS];
70111+extern const char * const softirq_to_name[NR_SOFTIRQS];
70112
70113 /* softirq mask and active fields moved to irq_cpustat_t in
70114 * asm/hardirq.h to get better cache usage. KAO
70115@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
70116
70117 struct softirq_action
70118 {
70119- void (*action)(struct softirq_action *);
70120-};
70121+ void (*action)(void);
70122+} __no_const;
70123
70124 asmlinkage void do_softirq(void);
70125 asmlinkage void __do_softirq(void);
70126-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
70127+extern void open_softirq(int nr, void (*action)(void));
70128 extern void softirq_init(void);
70129 extern void __raise_softirq_irqoff(unsigned int nr);
70130
70131diff --git a/include/linux/iommu.h b/include/linux/iommu.h
70132index 3aeb730..2177f39 100644
70133--- a/include/linux/iommu.h
70134+++ b/include/linux/iommu.h
70135@@ -113,7 +113,7 @@ struct iommu_ops {
70136 u32 (*domain_get_windows)(struct iommu_domain *domain);
70137
70138 unsigned long pgsize_bitmap;
70139-};
70140+} __do_const;
70141
70142 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70143 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70144diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70145index 89b7c24..382af74 100644
70146--- a/include/linux/ioport.h
70147+++ b/include/linux/ioport.h
70148@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70149 int adjust_resource(struct resource *res, resource_size_t start,
70150 resource_size_t size);
70151 resource_size_t resource_alignment(struct resource *res);
70152-static inline resource_size_t resource_size(const struct resource *res)
70153+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70154 {
70155 return res->end - res->start + 1;
70156 }
70157diff --git a/include/linux/irq.h b/include/linux/irq.h
70158index bc4e066..50468a9 100644
70159--- a/include/linux/irq.h
70160+++ b/include/linux/irq.h
70161@@ -328,7 +328,8 @@ struct irq_chip {
70162 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70163
70164 unsigned long flags;
70165-};
70166+} __do_const;
70167+typedef struct irq_chip __no_const irq_chip_no_const;
70168
70169 /*
70170 * irq_chip specific flags
70171diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
70172index 3e203eb..3fe68d0 100644
70173--- a/include/linux/irqchip/arm-gic.h
70174+++ b/include/linux/irqchip/arm-gic.h
70175@@ -59,9 +59,11 @@
70176
70177 #ifndef __ASSEMBLY__
70178
70179+#include <linux/irq.h>
70180+
70181 struct device_node;
70182
70183-extern struct irq_chip gic_arch_extn;
70184+extern irq_chip_no_const gic_arch_extn;
70185
70186 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
70187 u32 offset, struct device_node *);
70188diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70189index 6883e19..06992b1 100644
70190--- a/include/linux/kallsyms.h
70191+++ b/include/linux/kallsyms.h
70192@@ -15,7 +15,8 @@
70193
70194 struct module;
70195
70196-#ifdef CONFIG_KALLSYMS
70197+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70198+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70199 /* Lookup the address for a symbol. Returns 0 if not found. */
70200 unsigned long kallsyms_lookup_name(const char *name);
70201
70202@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70203 /* Stupid that this does nothing, but I didn't create this mess. */
70204 #define __print_symbol(fmt, addr)
70205 #endif /*CONFIG_KALLSYMS*/
70206+#else /* when included by kallsyms.c, vsnprintf.c, or
70207+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70208+extern void __print_symbol(const char *fmt, unsigned long address);
70209+extern int sprint_backtrace(char *buffer, unsigned long address);
70210+extern int sprint_symbol(char *buffer, unsigned long address);
70211+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70212+const char *kallsyms_lookup(unsigned long addr,
70213+ unsigned long *symbolsize,
70214+ unsigned long *offset,
70215+ char **modname, char *namebuf);
70216+#endif
70217
70218 /* This macro allows us to keep printk typechecking */
70219 static __printf(1, 2)
70220diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70221index 518a53a..5e28358 100644
70222--- a/include/linux/key-type.h
70223+++ b/include/linux/key-type.h
70224@@ -125,7 +125,7 @@ struct key_type {
70225 /* internal fields */
70226 struct list_head link; /* link in types list */
70227 struct lock_class_key lock_class; /* key->sem lock class */
70228-};
70229+} __do_const;
70230
70231 extern struct key_type key_type_keyring;
70232
70233diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70234index c6e091b..a940adf 100644
70235--- a/include/linux/kgdb.h
70236+++ b/include/linux/kgdb.h
70237@@ -52,7 +52,7 @@ extern int kgdb_connected;
70238 extern int kgdb_io_module_registered;
70239
70240 extern atomic_t kgdb_setting_breakpoint;
70241-extern atomic_t kgdb_cpu_doing_single_step;
70242+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70243
70244 extern struct task_struct *kgdb_usethread;
70245 extern struct task_struct *kgdb_contthread;
70246@@ -254,7 +254,7 @@ struct kgdb_arch {
70247 void (*correct_hw_break)(void);
70248
70249 void (*enable_nmi)(bool on);
70250-};
70251+} __do_const;
70252
70253 /**
70254 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70255@@ -279,7 +279,7 @@ struct kgdb_io {
70256 void (*pre_exception) (void);
70257 void (*post_exception) (void);
70258 int is_console;
70259-};
70260+} __do_const;
70261
70262 extern struct kgdb_arch arch_kgdb_ops;
70263
70264diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70265index 0555cc6..b16a7a4 100644
70266--- a/include/linux/kmod.h
70267+++ b/include/linux/kmod.h
70268@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70269 * usually useless though. */
70270 extern __printf(2, 3)
70271 int __request_module(bool wait, const char *name, ...);
70272+extern __printf(3, 4)
70273+int ___request_module(bool wait, char *param_name, const char *name, ...);
70274 #define request_module(mod...) __request_module(true, mod)
70275 #define request_module_nowait(mod...) __request_module(false, mod)
70276 #define try_then_request_module(x, mod...) \
70277diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70278index 939b112..ed6ed51 100644
70279--- a/include/linux/kobject.h
70280+++ b/include/linux/kobject.h
70281@@ -111,7 +111,7 @@ struct kobj_type {
70282 struct attribute **default_attrs;
70283 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70284 const void *(*namespace)(struct kobject *kobj);
70285-};
70286+} __do_const;
70287
70288 struct kobj_uevent_env {
70289 char *envp[UEVENT_NUM_ENVP];
70290@@ -134,6 +134,7 @@ struct kobj_attribute {
70291 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70292 const char *buf, size_t count);
70293 };
70294+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70295
70296 extern const struct sysfs_ops kobj_sysfs_ops;
70297
70298diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70299index f66b065..c2c29b4 100644
70300--- a/include/linux/kobject_ns.h
70301+++ b/include/linux/kobject_ns.h
70302@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70303 const void *(*netlink_ns)(struct sock *sk);
70304 const void *(*initial_ns)(void);
70305 void (*drop_ns)(void *);
70306-};
70307+} __do_const;
70308
70309 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70310 int kobj_ns_type_registered(enum kobj_ns_type type);
70311diff --git a/include/linux/kref.h b/include/linux/kref.h
70312index 484604d..0f6c5b6 100644
70313--- a/include/linux/kref.h
70314+++ b/include/linux/kref.h
70315@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
70316 static inline int kref_sub(struct kref *kref, unsigned int count,
70317 void (*release)(struct kref *kref))
70318 {
70319- WARN_ON(release == NULL);
70320+ BUG_ON(release == NULL);
70321
70322 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70323 release(kref);
70324diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70325index 8db53cf..c21121d 100644
70326--- a/include/linux/kvm_host.h
70327+++ b/include/linux/kvm_host.h
70328@@ -444,7 +444,7 @@ static inline void kvm_irqfd_exit(void)
70329 {
70330 }
70331 #endif
70332-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70333+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70334 struct module *module);
70335 void kvm_exit(void);
70336
70337@@ -616,7 +616,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70338 struct kvm_guest_debug *dbg);
70339 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70340
70341-int kvm_arch_init(void *opaque);
70342+int kvm_arch_init(const void *opaque);
70343 void kvm_arch_exit(void);
70344
70345 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70346diff --git a/include/linux/libata.h b/include/linux/libata.h
70347index eae7a05..2cdd875 100644
70348--- a/include/linux/libata.h
70349+++ b/include/linux/libata.h
70350@@ -919,7 +919,7 @@ struct ata_port_operations {
70351 * fields must be pointers.
70352 */
70353 const struct ata_port_operations *inherits;
70354-};
70355+} __do_const;
70356
70357 struct ata_port_info {
70358 unsigned long flags;
70359diff --git a/include/linux/list.h b/include/linux/list.h
70360index b83e565..baa6c1d 100644
70361--- a/include/linux/list.h
70362+++ b/include/linux/list.h
70363@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70364 extern void list_del(struct list_head *entry);
70365 #endif
70366
70367+extern void __pax_list_add(struct list_head *new,
70368+ struct list_head *prev,
70369+ struct list_head *next);
70370+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70371+{
70372+ __pax_list_add(new, head, head->next);
70373+}
70374+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70375+{
70376+ __pax_list_add(new, head->prev, head);
70377+}
70378+extern void pax_list_del(struct list_head *entry);
70379+
70380 /**
70381 * list_replace - replace old entry by new one
70382 * @old : the element to be replaced
70383@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70384 INIT_LIST_HEAD(entry);
70385 }
70386
70387+extern void pax_list_del_init(struct list_head *entry);
70388+
70389 /**
70390 * list_move - delete from one list and add as another's head
70391 * @list: the entry to move
70392diff --git a/include/linux/math64.h b/include/linux/math64.h
70393index 2913b86..4209244 100644
70394--- a/include/linux/math64.h
70395+++ b/include/linux/math64.h
70396@@ -15,7 +15,7 @@
70397 * This is commonly provided by 32bit archs to provide an optimized 64bit
70398 * divide.
70399 */
70400-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70401+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70402 {
70403 *remainder = dividend % divisor;
70404 return dividend / divisor;
70405@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70406 #define div64_ul(x, y) div_u64((x), (y))
70407
70408 #ifndef div_u64_rem
70409-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70410+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70411 {
70412 *remainder = do_div(dividend, divisor);
70413 return dividend;
70414@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70415 * divide.
70416 */
70417 #ifndef div_u64
70418-static inline u64 div_u64(u64 dividend, u32 divisor)
70419+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70420 {
70421 u32 remainder;
70422 return div_u64_rem(dividend, divisor, &remainder);
70423diff --git a/include/linux/mm.h b/include/linux/mm.h
70424index e0c8528..bcf0c29 100644
70425--- a/include/linux/mm.h
70426+++ b/include/linux/mm.h
70427@@ -104,6 +104,11 @@ extern unsigned int kobjsize(const void *objp);
70428 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70429 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70430 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70431+
70432+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70433+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70434+#endif
70435+
70436 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70437
70438 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70439@@ -205,8 +210,8 @@ struct vm_operations_struct {
70440 /* called by access_process_vm when get_user_pages() fails, typically
70441 * for use by special VMAs that can switch between memory and hardware
70442 */
70443- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70444- void *buf, int len, int write);
70445+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70446+ void *buf, size_t len, int write);
70447 #ifdef CONFIG_NUMA
70448 /*
70449 * set_policy() op must add a reference to any non-NULL @new mempolicy
70450@@ -236,6 +241,7 @@ struct vm_operations_struct {
70451 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70452 unsigned long size, pgoff_t pgoff);
70453 };
70454+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70455
70456 struct mmu_gather;
70457 struct inode;
70458@@ -980,8 +986,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70459 unsigned long *pfn);
70460 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70461 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70462-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70463- void *buf, int len, int write);
70464+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70465+ void *buf, size_t len, int write);
70466
70467 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70468 loff_t const holebegin, loff_t const holelen)
70469@@ -1020,9 +1026,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70470 }
70471 #endif
70472
70473-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70474-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70475- void *buf, int len, int write);
70476+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70477+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70478+ void *buf, size_t len, int write);
70479
70480 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70481 unsigned long start, unsigned long nr_pages,
70482@@ -1053,34 +1059,6 @@ int set_page_dirty(struct page *page);
70483 int set_page_dirty_lock(struct page *page);
70484 int clear_page_dirty_for_io(struct page *page);
70485
70486-/* Is the vma a continuation of the stack vma above it? */
70487-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70488-{
70489- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70490-}
70491-
70492-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70493- unsigned long addr)
70494-{
70495- return (vma->vm_flags & VM_GROWSDOWN) &&
70496- (vma->vm_start == addr) &&
70497- !vma_growsdown(vma->vm_prev, addr);
70498-}
70499-
70500-/* Is the vma a continuation of the stack vma below it? */
70501-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70502-{
70503- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70504-}
70505-
70506-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70507- unsigned long addr)
70508-{
70509- return (vma->vm_flags & VM_GROWSUP) &&
70510- (vma->vm_end == addr) &&
70511- !vma_growsup(vma->vm_next, addr);
70512-}
70513-
70514 extern pid_t
70515 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70516
70517@@ -1180,6 +1158,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70518 }
70519 #endif
70520
70521+#ifdef CONFIG_MMU
70522+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70523+#else
70524+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70525+{
70526+ return __pgprot(0);
70527+}
70528+#endif
70529+
70530 int vma_wants_writenotify(struct vm_area_struct *vma);
70531
70532 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70533@@ -1198,8 +1185,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70534 {
70535 return 0;
70536 }
70537+
70538+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70539+ unsigned long address)
70540+{
70541+ return 0;
70542+}
70543 #else
70544 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70545+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70546 #endif
70547
70548 #ifdef __PAGETABLE_PMD_FOLDED
70549@@ -1208,8 +1202,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70550 {
70551 return 0;
70552 }
70553+
70554+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70555+ unsigned long address)
70556+{
70557+ return 0;
70558+}
70559 #else
70560 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70561+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70562 #endif
70563
70564 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70565@@ -1227,11 +1228,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70566 NULL: pud_offset(pgd, address);
70567 }
70568
70569+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70570+{
70571+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70572+ NULL: pud_offset(pgd, address);
70573+}
70574+
70575 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70576 {
70577 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70578 NULL: pmd_offset(pud, address);
70579 }
70580+
70581+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70582+{
70583+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70584+ NULL: pmd_offset(pud, address);
70585+}
70586 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70587
70588 #if USE_SPLIT_PTLOCKS
70589@@ -1517,6 +1530,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70590 unsigned long len, unsigned long prot, unsigned long flags,
70591 unsigned long pgoff, unsigned long *populate);
70592 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70593+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70594
70595 #ifdef CONFIG_MMU
70596 extern int __mm_populate(unsigned long addr, unsigned long len,
70597@@ -1545,10 +1559,11 @@ struct vm_unmapped_area_info {
70598 unsigned long high_limit;
70599 unsigned long align_mask;
70600 unsigned long align_offset;
70601+ unsigned long threadstack_offset;
70602 };
70603
70604-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
70605-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70606+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
70607+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
70608
70609 /*
70610 * Search for an unmapped address range.
70611@@ -1560,7 +1575,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70612 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
70613 */
70614 static inline unsigned long
70615-vm_unmapped_area(struct vm_unmapped_area_info *info)
70616+vm_unmapped_area(const struct vm_unmapped_area_info *info)
70617 {
70618 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
70619 return unmapped_area(info);
70620@@ -1623,6 +1638,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70621 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70622 struct vm_area_struct **pprev);
70623
70624+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70625+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70626+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70627+
70628 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70629 NULL if none. Assume start_addr < end_addr. */
70630 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70631@@ -1651,15 +1670,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70632 return vma;
70633 }
70634
70635-#ifdef CONFIG_MMU
70636-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70637-#else
70638-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70639-{
70640- return __pgprot(0);
70641-}
70642-#endif
70643-
70644 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70645 unsigned long change_prot_numa(struct vm_area_struct *vma,
70646 unsigned long start, unsigned long end);
70647@@ -1711,6 +1721,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70648 static inline void vm_stat_account(struct mm_struct *mm,
70649 unsigned long flags, struct file *file, long pages)
70650 {
70651+
70652+#ifdef CONFIG_PAX_RANDMMAP
70653+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70654+#endif
70655+
70656 mm->total_vm += pages;
70657 }
70658 #endif /* CONFIG_PROC_FS */
70659@@ -1791,7 +1806,7 @@ extern int unpoison_memory(unsigned long pfn);
70660 extern int sysctl_memory_failure_early_kill;
70661 extern int sysctl_memory_failure_recovery;
70662 extern void shake_page(struct page *p, int access);
70663-extern atomic_long_t num_poisoned_pages;
70664+extern atomic_long_unchecked_t num_poisoned_pages;
70665 extern int soft_offline_page(struct page *page, int flags);
70666
70667 extern void dump_page(struct page *page);
70668@@ -1828,5 +1843,11 @@ void __init setup_nr_node_ids(void);
70669 static inline void setup_nr_node_ids(void) {}
70670 #endif
70671
70672+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70673+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70674+#else
70675+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70676+#endif
70677+
70678 #endif /* __KERNEL__ */
70679 #endif /* _LINUX_MM_H */
70680diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70681index ace9a5f..81bdb59 100644
70682--- a/include/linux/mm_types.h
70683+++ b/include/linux/mm_types.h
70684@@ -289,6 +289,8 @@ struct vm_area_struct {
70685 #ifdef CONFIG_NUMA
70686 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70687 #endif
70688+
70689+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70690 };
70691
70692 struct core_thread {
70693@@ -437,6 +439,24 @@ struct mm_struct {
70694 int first_nid;
70695 #endif
70696 struct uprobes_state uprobes_state;
70697+
70698+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70699+ unsigned long pax_flags;
70700+#endif
70701+
70702+#ifdef CONFIG_PAX_DLRESOLVE
70703+ unsigned long call_dl_resolve;
70704+#endif
70705+
70706+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70707+ unsigned long call_syscall;
70708+#endif
70709+
70710+#ifdef CONFIG_PAX_ASLR
70711+ unsigned long delta_mmap; /* randomized offset */
70712+ unsigned long delta_stack; /* randomized offset */
70713+#endif
70714+
70715 };
70716
70717 /* first nid will either be a valid NID or one of these values */
70718diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70719index c5d5278..f0b68c8 100644
70720--- a/include/linux/mmiotrace.h
70721+++ b/include/linux/mmiotrace.h
70722@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70723 /* Called from ioremap.c */
70724 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70725 void __iomem *addr);
70726-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70727+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70728
70729 /* For anyone to insert markers. Remember trailing newline. */
70730 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70731@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70732 {
70733 }
70734
70735-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70736+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70737 {
70738 }
70739
70740diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70741index 5c76737..61f518e 100644
70742--- a/include/linux/mmzone.h
70743+++ b/include/linux/mmzone.h
70744@@ -396,7 +396,7 @@ struct zone {
70745 unsigned long flags; /* zone flags, see below */
70746
70747 /* Zone statistics */
70748- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70749+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70750
70751 /*
70752 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70753diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70754index b508016..237cfe5 100644
70755--- a/include/linux/mod_devicetable.h
70756+++ b/include/linux/mod_devicetable.h
70757@@ -13,7 +13,7 @@
70758 typedef unsigned long kernel_ulong_t;
70759 #endif
70760
70761-#define PCI_ANY_ID (~0)
70762+#define PCI_ANY_ID ((__u16)~0)
70763
70764 struct pci_device_id {
70765 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70766@@ -139,7 +139,7 @@ struct usb_device_id {
70767 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70768 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70769
70770-#define HID_ANY_ID (~0)
70771+#define HID_ANY_ID (~0U)
70772 #define HID_BUS_ANY 0xffff
70773 #define HID_GROUP_ANY 0x0000
70774
70775@@ -465,7 +465,7 @@ struct dmi_system_id {
70776 const char *ident;
70777 struct dmi_strmatch matches[4];
70778 void *driver_data;
70779-};
70780+} __do_const;
70781 /*
70782 * struct dmi_device_id appears during expansion of
70783 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70784diff --git a/include/linux/module.h b/include/linux/module.h
70785index 46f1ea0..a34ca37 100644
70786--- a/include/linux/module.h
70787+++ b/include/linux/module.h
70788@@ -17,9 +17,11 @@
70789 #include <linux/moduleparam.h>
70790 #include <linux/tracepoint.h>
70791 #include <linux/export.h>
70792+#include <linux/fs.h>
70793
70794 #include <linux/percpu.h>
70795 #include <asm/module.h>
70796+#include <asm/pgtable.h>
70797
70798 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70799 #define MODULE_SIG_STRING "~Module signature appended~\n"
70800@@ -54,12 +56,13 @@ struct module_attribute {
70801 int (*test)(struct module *);
70802 void (*free)(struct module *);
70803 };
70804+typedef struct module_attribute __no_const module_attribute_no_const;
70805
70806 struct module_version_attribute {
70807 struct module_attribute mattr;
70808 const char *module_name;
70809 const char *version;
70810-} __attribute__ ((__aligned__(sizeof(void *))));
70811+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70812
70813 extern ssize_t __modver_version_show(struct module_attribute *,
70814 struct module_kobject *, char *);
70815@@ -232,7 +235,7 @@ struct module
70816
70817 /* Sysfs stuff. */
70818 struct module_kobject mkobj;
70819- struct module_attribute *modinfo_attrs;
70820+ module_attribute_no_const *modinfo_attrs;
70821 const char *version;
70822 const char *srcversion;
70823 struct kobject *holders_dir;
70824@@ -281,19 +284,16 @@ struct module
70825 int (*init)(void);
70826
70827 /* If this is non-NULL, vfree after init() returns */
70828- void *module_init;
70829+ void *module_init_rx, *module_init_rw;
70830
70831 /* Here is the actual code + data, vfree'd on unload. */
70832- void *module_core;
70833+ void *module_core_rx, *module_core_rw;
70834
70835 /* Here are the sizes of the init and core sections */
70836- unsigned int init_size, core_size;
70837+ unsigned int init_size_rw, core_size_rw;
70838
70839 /* The size of the executable code in each section. */
70840- unsigned int init_text_size, core_text_size;
70841-
70842- /* Size of RO sections of the module (text+rodata) */
70843- unsigned int init_ro_size, core_ro_size;
70844+ unsigned int init_size_rx, core_size_rx;
70845
70846 /* Arch-specific module values */
70847 struct mod_arch_specific arch;
70848@@ -349,6 +349,10 @@ struct module
70849 #ifdef CONFIG_EVENT_TRACING
70850 struct ftrace_event_call **trace_events;
70851 unsigned int num_trace_events;
70852+ struct file_operations trace_id;
70853+ struct file_operations trace_enable;
70854+ struct file_operations trace_format;
70855+ struct file_operations trace_filter;
70856 #endif
70857 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70858 unsigned int num_ftrace_callsites;
70859@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70860 bool is_module_percpu_address(unsigned long addr);
70861 bool is_module_text_address(unsigned long addr);
70862
70863+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70864+{
70865+
70866+#ifdef CONFIG_PAX_KERNEXEC
70867+ if (ktla_ktva(addr) >= (unsigned long)start &&
70868+ ktla_ktva(addr) < (unsigned long)start + size)
70869+ return 1;
70870+#endif
70871+
70872+ return ((void *)addr >= start && (void *)addr < start + size);
70873+}
70874+
70875+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
70876+{
70877+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70878+}
70879+
70880+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
70881+{
70882+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70883+}
70884+
70885+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
70886+{
70887+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70888+}
70889+
70890+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
70891+{
70892+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70893+}
70894+
70895 static inline int within_module_core(unsigned long addr, const struct module *mod)
70896 {
70897- return (unsigned long)mod->module_core <= addr &&
70898- addr < (unsigned long)mod->module_core + mod->core_size;
70899+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70900 }
70901
70902 static inline int within_module_init(unsigned long addr, const struct module *mod)
70903 {
70904- return (unsigned long)mod->module_init <= addr &&
70905- addr < (unsigned long)mod->module_init + mod->init_size;
70906+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70907 }
70908
70909 /* Search for module by name: must hold module_mutex. */
70910diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70911index 560ca53..ef621ef 100644
70912--- a/include/linux/moduleloader.h
70913+++ b/include/linux/moduleloader.h
70914@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70915 sections. Returns NULL on failure. */
70916 void *module_alloc(unsigned long size);
70917
70918+#ifdef CONFIG_PAX_KERNEXEC
70919+void *module_alloc_exec(unsigned long size);
70920+#else
70921+#define module_alloc_exec(x) module_alloc(x)
70922+#endif
70923+
70924 /* Free memory returned from module_alloc. */
70925 void module_free(struct module *mod, void *module_region);
70926
70927+#ifdef CONFIG_PAX_KERNEXEC
70928+void module_free_exec(struct module *mod, void *module_region);
70929+#else
70930+#define module_free_exec(x, y) module_free((x), (y))
70931+#endif
70932+
70933 /*
70934 * Apply the given relocation to the (simplified) ELF. Return -error
70935 * or 0.
70936@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70937 unsigned int relsec,
70938 struct module *me)
70939 {
70940+#ifdef CONFIG_MODULES
70941 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70942+#endif
70943 return -ENOEXEC;
70944 }
70945 #endif
70946@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70947 unsigned int relsec,
70948 struct module *me)
70949 {
70950+#ifdef CONFIG_MODULES
70951 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70952+#endif
70953 return -ENOEXEC;
70954 }
70955 #endif
70956diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70957index 137b419..fe663ec 100644
70958--- a/include/linux/moduleparam.h
70959+++ b/include/linux/moduleparam.h
70960@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70961 * @len is usually just sizeof(string).
70962 */
70963 #define module_param_string(name, string, len, perm) \
70964- static const struct kparam_string __param_string_##name \
70965+ static const struct kparam_string __param_string_##name __used \
70966 = { len, string }; \
70967 __module_param_call(MODULE_PARAM_PREFIX, name, \
70968 &param_ops_string, \
70969@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70970 */
70971 #define module_param_array_named(name, array, type, nump, perm) \
70972 param_check_##type(name, &(array)[0]); \
70973- static const struct kparam_array __param_arr_##name \
70974+ static const struct kparam_array __param_arr_##name __used \
70975 = { .max = ARRAY_SIZE(array), .num = nump, \
70976 .ops = &param_ops_##type, \
70977 .elemsize = sizeof(array[0]), .elem = array }; \
70978diff --git a/include/linux/namei.h b/include/linux/namei.h
70979index 5a5ff57..5ae5070 100644
70980--- a/include/linux/namei.h
70981+++ b/include/linux/namei.h
70982@@ -19,7 +19,7 @@ struct nameidata {
70983 unsigned seq;
70984 int last_type;
70985 unsigned depth;
70986- char *saved_names[MAX_NESTED_LINKS + 1];
70987+ const char *saved_names[MAX_NESTED_LINKS + 1];
70988 };
70989
70990 /*
70991@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70992
70993 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70994
70995-static inline void nd_set_link(struct nameidata *nd, char *path)
70996+static inline void nd_set_link(struct nameidata *nd, const char *path)
70997 {
70998 nd->saved_names[nd->depth] = path;
70999 }
71000
71001-static inline char *nd_get_link(struct nameidata *nd)
71002+static inline const char *nd_get_link(const struct nameidata *nd)
71003 {
71004 return nd->saved_names[nd->depth];
71005 }
71006diff --git a/include/linux/net.h b/include/linux/net.h
71007index 99c9f0c..e1cf296 100644
71008--- a/include/linux/net.h
71009+++ b/include/linux/net.h
71010@@ -183,7 +183,7 @@ struct net_proto_family {
71011 int (*create)(struct net *net, struct socket *sock,
71012 int protocol, int kern);
71013 struct module *owner;
71014-};
71015+} __do_const;
71016
71017 struct iovec;
71018 struct kvec;
71019diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
71020index 96e4c21..9cc8278 100644
71021--- a/include/linux/netdevice.h
71022+++ b/include/linux/netdevice.h
71023@@ -1026,6 +1026,7 @@ struct net_device_ops {
71024 int (*ndo_change_carrier)(struct net_device *dev,
71025 bool new_carrier);
71026 };
71027+typedef struct net_device_ops __no_const net_device_ops_no_const;
71028
71029 /*
71030 * The DEVICE structure.
71031@@ -1094,7 +1095,7 @@ struct net_device {
71032 int iflink;
71033
71034 struct net_device_stats stats;
71035- atomic_long_t rx_dropped; /* dropped packets by core network
71036+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
71037 * Do not use this in drivers.
71038 */
71039
71040diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
71041index 0060fde..481c6ae 100644
71042--- a/include/linux/netfilter.h
71043+++ b/include/linux/netfilter.h
71044@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
71045 #endif
71046 /* Use the module struct to lock set/get code in place */
71047 struct module *owner;
71048-};
71049+} __do_const;
71050
71051 /* Function to register/unregister hook points. */
71052 int nf_register_hook(struct nf_hook_ops *reg);
71053diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
71054index d80e275..c3510b8 100644
71055--- a/include/linux/netfilter/ipset/ip_set.h
71056+++ b/include/linux/netfilter/ipset/ip_set.h
71057@@ -124,7 +124,7 @@ struct ip_set_type_variant {
71058 /* Return true if "b" set is the same as "a"
71059 * according to the create set parameters */
71060 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
71061-};
71062+} __do_const;
71063
71064 /* The core set type structure */
71065 struct ip_set_type {
71066diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
71067index cadb740..d7c37c0 100644
71068--- a/include/linux/netfilter/nfnetlink.h
71069+++ b/include/linux/netfilter/nfnetlink.h
71070@@ -16,7 +16,7 @@ struct nfnl_callback {
71071 const struct nlattr * const cda[]);
71072 const struct nla_policy *policy; /* netlink attribute policy */
71073 const u_int16_t attr_count; /* number of nlattr's */
71074-};
71075+} __do_const;
71076
71077 struct nfnetlink_subsystem {
71078 const char *name;
71079diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
71080new file mode 100644
71081index 0000000..33f4af8
71082--- /dev/null
71083+++ b/include/linux/netfilter/xt_gradm.h
71084@@ -0,0 +1,9 @@
71085+#ifndef _LINUX_NETFILTER_XT_GRADM_H
71086+#define _LINUX_NETFILTER_XT_GRADM_H 1
71087+
71088+struct xt_gradm_mtinfo {
71089+ __u16 flags;
71090+ __u16 invflags;
71091+};
71092+
71093+#endif
71094diff --git a/include/linux/nls.h b/include/linux/nls.h
71095index 5dc635f..35f5e11 100644
71096--- a/include/linux/nls.h
71097+++ b/include/linux/nls.h
71098@@ -31,7 +31,7 @@ struct nls_table {
71099 const unsigned char *charset2upper;
71100 struct module *owner;
71101 struct nls_table *next;
71102-};
71103+} __do_const;
71104
71105 /* this value hold the maximum octet of charset */
71106 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
71107diff --git a/include/linux/notifier.h b/include/linux/notifier.h
71108index d14a4c3..a078786 100644
71109--- a/include/linux/notifier.h
71110+++ b/include/linux/notifier.h
71111@@ -54,7 +54,8 @@ struct notifier_block {
71112 notifier_fn_t notifier_call;
71113 struct notifier_block __rcu *next;
71114 int priority;
71115-};
71116+} __do_const;
71117+typedef struct notifier_block __no_const notifier_block_no_const;
71118
71119 struct atomic_notifier_head {
71120 spinlock_t lock;
71121diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
71122index a4c5624..79d6d88 100644
71123--- a/include/linux/oprofile.h
71124+++ b/include/linux/oprofile.h
71125@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
71126 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
71127 char const * name, ulong * val);
71128
71129-/** Create a file for read-only access to an atomic_t. */
71130+/** Create a file for read-only access to an atomic_unchecked_t. */
71131 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
71132- char const * name, atomic_t * val);
71133+ char const * name, atomic_unchecked_t * val);
71134
71135 /** create a directory */
71136 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
71137diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
71138index 8db71dc..a76bf2c 100644
71139--- a/include/linux/pci_hotplug.h
71140+++ b/include/linux/pci_hotplug.h
71141@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
71142 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
71143 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
71144 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
71145-};
71146+} __do_const;
71147+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
71148
71149 /**
71150 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
71151diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
71152index c5b6dbf..b124155 100644
71153--- a/include/linux/perf_event.h
71154+++ b/include/linux/perf_event.h
71155@@ -318,8 +318,8 @@ struct perf_event {
71156
71157 enum perf_event_active_state state;
71158 unsigned int attach_state;
71159- local64_t count;
71160- atomic64_t child_count;
71161+ local64_t count; /* PaX: fix it one day */
71162+ atomic64_unchecked_t child_count;
71163
71164 /*
71165 * These are the total time in nanoseconds that the event
71166@@ -370,8 +370,8 @@ struct perf_event {
71167 * These accumulate total time (in nanoseconds) that children
71168 * events have been enabled and running, respectively.
71169 */
71170- atomic64_t child_total_time_enabled;
71171- atomic64_t child_total_time_running;
71172+ atomic64_unchecked_t child_total_time_enabled;
71173+ atomic64_unchecked_t child_total_time_running;
71174
71175 /*
71176 * Protect attach/detach and child_list:
71177@@ -692,7 +692,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
71178 entry->ip[entry->nr++] = ip;
71179 }
71180
71181-extern int sysctl_perf_event_paranoid;
71182+extern int sysctl_perf_event_legitimately_concerned;
71183 extern int sysctl_perf_event_mlock;
71184 extern int sysctl_perf_event_sample_rate;
71185
71186@@ -700,19 +700,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
71187 void __user *buffer, size_t *lenp,
71188 loff_t *ppos);
71189
71190+static inline bool perf_paranoid_any(void)
71191+{
71192+ return sysctl_perf_event_legitimately_concerned > 2;
71193+}
71194+
71195 static inline bool perf_paranoid_tracepoint_raw(void)
71196 {
71197- return sysctl_perf_event_paranoid > -1;
71198+ return sysctl_perf_event_legitimately_concerned > -1;
71199 }
71200
71201 static inline bool perf_paranoid_cpu(void)
71202 {
71203- return sysctl_perf_event_paranoid > 0;
71204+ return sysctl_perf_event_legitimately_concerned > 0;
71205 }
71206
71207 static inline bool perf_paranoid_kernel(void)
71208 {
71209- return sysctl_perf_event_paranoid > 1;
71210+ return sysctl_perf_event_legitimately_concerned > 1;
71211 }
71212
71213 extern void perf_event_init(void);
71214@@ -806,7 +811,7 @@ static inline void perf_restore_debug_store(void) { }
71215 */
71216 #define perf_cpu_notifier(fn) \
71217 do { \
71218- static struct notifier_block fn##_nb __cpuinitdata = \
71219+ static struct notifier_block fn##_nb = \
71220 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71221 unsigned long cpu = smp_processor_id(); \
71222 unsigned long flags; \
71223@@ -826,7 +831,7 @@ struct perf_pmu_events_attr {
71224 struct device_attribute attr;
71225 u64 id;
71226 const char *event_str;
71227-};
71228+} __do_const;
71229
71230 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
71231 static struct perf_pmu_events_attr _var = { \
71232diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71233index b8809fe..ae4ccd0 100644
71234--- a/include/linux/pipe_fs_i.h
71235+++ b/include/linux/pipe_fs_i.h
71236@@ -47,10 +47,10 @@ struct pipe_inode_info {
71237 struct mutex mutex;
71238 wait_queue_head_t wait;
71239 unsigned int nrbufs, curbuf, buffers;
71240- unsigned int readers;
71241- unsigned int writers;
71242- unsigned int files;
71243- unsigned int waiting_writers;
71244+ atomic_t readers;
71245+ atomic_t writers;
71246+ atomic_t files;
71247+ atomic_t waiting_writers;
71248 unsigned int r_counter;
71249 unsigned int w_counter;
71250 struct page *tmp_page;
71251diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71252index 5f28cae..3d23723 100644
71253--- a/include/linux/platform_data/usb-ehci-s5p.h
71254+++ b/include/linux/platform_data/usb-ehci-s5p.h
71255@@ -14,7 +14,7 @@
71256 struct s5p_ehci_platdata {
71257 int (*phy_init)(struct platform_device *pdev, int type);
71258 int (*phy_exit)(struct platform_device *pdev, int type);
71259-};
71260+} __no_const;
71261
71262 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71263
71264diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
71265index c256c59..8ea94c7 100644
71266--- a/include/linux/platform_data/usb-ohci-exynos.h
71267+++ b/include/linux/platform_data/usb-ohci-exynos.h
71268@@ -14,7 +14,7 @@
71269 struct exynos4_ohci_platdata {
71270 int (*phy_init)(struct platform_device *pdev, int type);
71271 int (*phy_exit)(struct platform_device *pdev, int type);
71272-};
71273+} __no_const;
71274
71275 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71276
71277diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71278index 7c1d252..c5c773e 100644
71279--- a/include/linux/pm_domain.h
71280+++ b/include/linux/pm_domain.h
71281@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71282
71283 struct gpd_cpu_data {
71284 unsigned int saved_exit_latency;
71285- struct cpuidle_state *idle_state;
71286+ cpuidle_state_no_const *idle_state;
71287 };
71288
71289 struct generic_pm_domain {
71290diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71291index 7d7e09e..8671ef8 100644
71292--- a/include/linux/pm_runtime.h
71293+++ b/include/linux/pm_runtime.h
71294@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71295
71296 static inline void pm_runtime_mark_last_busy(struct device *dev)
71297 {
71298- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71299+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71300 }
71301
71302 #else /* !CONFIG_PM_RUNTIME */
71303diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71304index 195aafc..49a7bc2 100644
71305--- a/include/linux/pnp.h
71306+++ b/include/linux/pnp.h
71307@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71308 struct pnp_fixup {
71309 char id[7];
71310 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71311-};
71312+} __do_const;
71313
71314 /* config parameters */
71315 #define PNP_CONFIG_NORMAL 0x0001
71316diff --git a/include/linux/poison.h b/include/linux/poison.h
71317index 2110a81..13a11bb 100644
71318--- a/include/linux/poison.h
71319+++ b/include/linux/poison.h
71320@@ -19,8 +19,8 @@
71321 * under normal circumstances, used to verify that nobody uses
71322 * non-initialized list entries.
71323 */
71324-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71325-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71326+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71327+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71328
71329 /********** include/linux/timer.h **********/
71330 /*
71331diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71332index c0f44c2..1572583 100644
71333--- a/include/linux/power/smartreflex.h
71334+++ b/include/linux/power/smartreflex.h
71335@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71336 int (*notify)(struct omap_sr *sr, u32 status);
71337 u8 notify_flags;
71338 u8 class_type;
71339-};
71340+} __do_const;
71341
71342 /**
71343 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71344diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71345index 4ea1d37..80f4b33 100644
71346--- a/include/linux/ppp-comp.h
71347+++ b/include/linux/ppp-comp.h
71348@@ -84,7 +84,7 @@ struct compressor {
71349 struct module *owner;
71350 /* Extra skb space needed by the compressor algorithm */
71351 unsigned int comp_extra;
71352-};
71353+} __do_const;
71354
71355 /*
71356 * The return value from decompress routine is the length of the
71357diff --git a/include/linux/printk.h b/include/linux/printk.h
71358index 22c7052..ad3fa0a 100644
71359--- a/include/linux/printk.h
71360+++ b/include/linux/printk.h
71361@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
71362 void early_printk(const char *s, ...) { }
71363 #endif
71364
71365+extern int kptr_restrict;
71366+
71367 #ifdef CONFIG_PRINTK
71368 asmlinkage __printf(5, 0)
71369 int vprintk_emit(int facility, int level,
71370@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71371
71372 extern int printk_delay_msec;
71373 extern int dmesg_restrict;
71374-extern int kptr_restrict;
71375
71376 extern void wake_up_klogd(void);
71377
71378diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71379index 608e60a..c26f864 100644
71380--- a/include/linux/proc_fs.h
71381+++ b/include/linux/proc_fs.h
71382@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
71383 return proc_create_data(name, mode, parent, proc_fops, NULL);
71384 }
71385
71386+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71387+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71388+{
71389+#ifdef CONFIG_GRKERNSEC_PROC_USER
71390+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71391+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71392+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71393+#else
71394+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71395+#endif
71396+}
71397+
71398+
71399 extern void proc_set_size(struct proc_dir_entry *, loff_t);
71400 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
71401 extern void *PDE_DATA(const struct inode *);
71402diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
71403index 34a1e10..03a6d03 100644
71404--- a/include/linux/proc_ns.h
71405+++ b/include/linux/proc_ns.h
71406@@ -14,7 +14,7 @@ struct proc_ns_operations {
71407 void (*put)(void *ns);
71408 int (*install)(struct nsproxy *nsproxy, void *ns);
71409 unsigned int (*inum)(void *ns);
71410-};
71411+} __do_const;
71412
71413 struct proc_ns {
71414 void *ns;
71415diff --git a/include/linux/random.h b/include/linux/random.h
71416index 3b9377d..61b506a 100644
71417--- a/include/linux/random.h
71418+++ b/include/linux/random.h
71419@@ -32,6 +32,11 @@ void prandom_seed(u32 seed);
71420 u32 prandom_u32_state(struct rnd_state *);
71421 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71422
71423+static inline unsigned long pax_get_random_long(void)
71424+{
71425+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71426+}
71427+
71428 /*
71429 * Handle minimum values for seeds
71430 */
71431diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71432index f4b1001..8ddb2b6 100644
71433--- a/include/linux/rculist.h
71434+++ b/include/linux/rculist.h
71435@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71436 struct list_head *prev, struct list_head *next);
71437 #endif
71438
71439+extern void __pax_list_add_rcu(struct list_head *new,
71440+ struct list_head *prev, struct list_head *next);
71441+
71442 /**
71443 * list_add_rcu - add a new entry to rcu-protected list
71444 * @new: new entry to be added
71445@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71446 __list_add_rcu(new, head, head->next);
71447 }
71448
71449+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71450+{
71451+ __pax_list_add_rcu(new, head, head->next);
71452+}
71453+
71454 /**
71455 * list_add_tail_rcu - add a new entry to rcu-protected list
71456 * @new: new entry to be added
71457@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71458 __list_add_rcu(new, head->prev, head);
71459 }
71460
71461+static inline void pax_list_add_tail_rcu(struct list_head *new,
71462+ struct list_head *head)
71463+{
71464+ __pax_list_add_rcu(new, head->prev, head);
71465+}
71466+
71467 /**
71468 * list_del_rcu - deletes entry from list without re-initialization
71469 * @entry: the element to delete from the list.
71470@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71471 entry->prev = LIST_POISON2;
71472 }
71473
71474+extern void pax_list_del_rcu(struct list_head *entry);
71475+
71476 /**
71477 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71478 * @n: the element to delete from the hash list.
71479diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71480index 23b3630..e1bc12b 100644
71481--- a/include/linux/reboot.h
71482+++ b/include/linux/reboot.h
71483@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71484 * Architecture-specific implementations of sys_reboot commands.
71485 */
71486
71487-extern void machine_restart(char *cmd);
71488-extern void machine_halt(void);
71489-extern void machine_power_off(void);
71490+extern void machine_restart(char *cmd) __noreturn;
71491+extern void machine_halt(void) __noreturn;
71492+extern void machine_power_off(void) __noreturn;
71493
71494 extern void machine_shutdown(void);
71495 struct pt_regs;
71496@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71497 */
71498
71499 extern void kernel_restart_prepare(char *cmd);
71500-extern void kernel_restart(char *cmd);
71501-extern void kernel_halt(void);
71502-extern void kernel_power_off(void);
71503+extern void kernel_restart(char *cmd) __noreturn;
71504+extern void kernel_halt(void) __noreturn;
71505+extern void kernel_power_off(void) __noreturn;
71506
71507 extern int C_A_D; /* for sysctl */
71508 void ctrl_alt_del(void);
71509@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71510 * Emergency restart, callable from an interrupt handler.
71511 */
71512
71513-extern void emergency_restart(void);
71514+extern void emergency_restart(void) __noreturn;
71515 #include <asm/emergency-restart.h>
71516
71517 #endif /* _LINUX_REBOOT_H */
71518diff --git a/include/linux/regset.h b/include/linux/regset.h
71519index 8e0c9fe..ac4d221 100644
71520--- a/include/linux/regset.h
71521+++ b/include/linux/regset.h
71522@@ -161,7 +161,8 @@ struct user_regset {
71523 unsigned int align;
71524 unsigned int bias;
71525 unsigned int core_note_type;
71526-};
71527+} __do_const;
71528+typedef struct user_regset __no_const user_regset_no_const;
71529
71530 /**
71531 * struct user_regset_view - available regsets
71532diff --git a/include/linux/relay.h b/include/linux/relay.h
71533index d7c8359..818daf5 100644
71534--- a/include/linux/relay.h
71535+++ b/include/linux/relay.h
71536@@ -157,7 +157,7 @@ struct rchan_callbacks
71537 * The callback should return 0 if successful, negative if not.
71538 */
71539 int (*remove_buf_file)(struct dentry *dentry);
71540-};
71541+} __no_const;
71542
71543 /*
71544 * CONFIG_RELAY kernel API, kernel/relay.c
71545diff --git a/include/linux/rio.h b/include/linux/rio.h
71546index 18e0993..8ab5b21 100644
71547--- a/include/linux/rio.h
71548+++ b/include/linux/rio.h
71549@@ -345,7 +345,7 @@ struct rio_ops {
71550 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71551 u64 rstart, u32 size, u32 flags);
71552 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71553-};
71554+} __no_const;
71555
71556 #define RIO_RESOURCE_MEM 0x00000100
71557 #define RIO_RESOURCE_DOORBELL 0x00000200
71558diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71559index 6dacb93..6174423 100644
71560--- a/include/linux/rmap.h
71561+++ b/include/linux/rmap.h
71562@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71563 void anon_vma_init(void); /* create anon_vma_cachep */
71564 int anon_vma_prepare(struct vm_area_struct *);
71565 void unlink_anon_vmas(struct vm_area_struct *);
71566-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71567-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71568+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71569+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71570
71571 static inline void anon_vma_merge(struct vm_area_struct *vma,
71572 struct vm_area_struct *next)
71573diff --git a/include/linux/sched.h b/include/linux/sched.h
71574index 178a8d9..52e71a3 100644
71575--- a/include/linux/sched.h
71576+++ b/include/linux/sched.h
71577@@ -62,6 +62,7 @@ struct bio_list;
71578 struct fs_struct;
71579 struct perf_event_context;
71580 struct blk_plug;
71581+struct linux_binprm;
71582
71583 /*
71584 * List of flags we want to share for kernel threads,
71585@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
71586 extern int in_sched_functions(unsigned long addr);
71587
71588 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71589-extern signed long schedule_timeout(signed long timeout);
71590+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71591 extern signed long schedule_timeout_interruptible(signed long timeout);
71592 extern signed long schedule_timeout_killable(signed long timeout);
71593 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71594@@ -314,6 +315,19 @@ struct nsproxy;
71595 struct user_namespace;
71596
71597 #ifdef CONFIG_MMU
71598+
71599+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71600+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71601+#else
71602+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71603+{
71604+ return 0;
71605+}
71606+#endif
71607+
71608+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71609+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71610+
71611 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71612 extern unsigned long
71613 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71614@@ -591,6 +605,17 @@ struct signal_struct {
71615 #ifdef CONFIG_TASKSTATS
71616 struct taskstats *stats;
71617 #endif
71618+
71619+#ifdef CONFIG_GRKERNSEC
71620+ u32 curr_ip;
71621+ u32 saved_ip;
71622+ u32 gr_saddr;
71623+ u32 gr_daddr;
71624+ u16 gr_sport;
71625+ u16 gr_dport;
71626+ u8 used_accept:1;
71627+#endif
71628+
71629 #ifdef CONFIG_AUDIT
71630 unsigned audit_tty;
71631 unsigned audit_tty_log_passwd;
71632@@ -671,6 +696,14 @@ struct user_struct {
71633 struct key *session_keyring; /* UID's default session keyring */
71634 #endif
71635
71636+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
71637+ unsigned char kernel_banned;
71638+#endif
71639+#ifdef CONFIG_GRKERNSEC_BRUTE
71640+ unsigned char suid_banned;
71641+ unsigned long suid_ban_expires;
71642+#endif
71643+
71644 /* Hash table maintenance information */
71645 struct hlist_node uidhash_node;
71646 kuid_t uid;
71647@@ -1158,8 +1191,8 @@ struct task_struct {
71648 struct list_head thread_group;
71649
71650 struct completion *vfork_done; /* for vfork() */
71651- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71652- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71653+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71654+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71655
71656 cputime_t utime, stime, utimescaled, stimescaled;
71657 cputime_t gtime;
71658@@ -1184,11 +1217,6 @@ struct task_struct {
71659 struct task_cputime cputime_expires;
71660 struct list_head cpu_timers[3];
71661
71662-/* process credentials */
71663- const struct cred __rcu *real_cred; /* objective and real subjective task
71664- * credentials (COW) */
71665- const struct cred __rcu *cred; /* effective (overridable) subjective task
71666- * credentials (COW) */
71667 char comm[TASK_COMM_LEN]; /* executable name excluding path
71668 - access with [gs]et_task_comm (which lock
71669 it with task_lock())
71670@@ -1205,6 +1233,10 @@ struct task_struct {
71671 #endif
71672 /* CPU-specific state of this task */
71673 struct thread_struct thread;
71674+/* thread_info moved to task_struct */
71675+#ifdef CONFIG_X86
71676+ struct thread_info tinfo;
71677+#endif
71678 /* filesystem information */
71679 struct fs_struct *fs;
71680 /* open file information */
71681@@ -1278,6 +1310,10 @@ struct task_struct {
71682 gfp_t lockdep_reclaim_gfp;
71683 #endif
71684
71685+/* process credentials */
71686+ const struct cred __rcu *real_cred; /* objective and real subjective task
71687+ * credentials (COW) */
71688+
71689 /* journalling filesystem info */
71690 void *journal_info;
71691
71692@@ -1316,6 +1352,10 @@ struct task_struct {
71693 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71694 struct list_head cg_list;
71695 #endif
71696+
71697+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71698+ * credentials (COW) */
71699+
71700 #ifdef CONFIG_FUTEX
71701 struct robust_list_head __user *robust_list;
71702 #ifdef CONFIG_COMPAT
71703@@ -1416,8 +1456,74 @@ struct task_struct {
71704 unsigned int sequential_io;
71705 unsigned int sequential_io_avg;
71706 #endif
71707+
71708+#ifdef CONFIG_GRKERNSEC
71709+ /* grsecurity */
71710+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71711+ u64 exec_id;
71712+#endif
71713+#ifdef CONFIG_GRKERNSEC_SETXID
71714+ const struct cred *delayed_cred;
71715+#endif
71716+ struct dentry *gr_chroot_dentry;
71717+ struct acl_subject_label *acl;
71718+ struct acl_role_label *role;
71719+ struct file *exec_file;
71720+ unsigned long brute_expires;
71721+ u16 acl_role_id;
71722+ /* is this the task that authenticated to the special role */
71723+ u8 acl_sp_role;
71724+ u8 is_writable;
71725+ u8 brute;
71726+ u8 gr_is_chrooted;
71727+#endif
71728+
71729 };
71730
71731+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71732+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71733+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71734+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71735+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71736+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71737+
71738+#ifdef CONFIG_PAX_SOFTMODE
71739+extern int pax_softmode;
71740+#endif
71741+
71742+extern int pax_check_flags(unsigned long *);
71743+
71744+/* if tsk != current then task_lock must be held on it */
71745+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71746+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71747+{
71748+ if (likely(tsk->mm))
71749+ return tsk->mm->pax_flags;
71750+ else
71751+ return 0UL;
71752+}
71753+
71754+/* if tsk != current then task_lock must be held on it */
71755+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71756+{
71757+ if (likely(tsk->mm)) {
71758+ tsk->mm->pax_flags = flags;
71759+ return 0;
71760+ }
71761+ return -EINVAL;
71762+}
71763+#endif
71764+
71765+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71766+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71767+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71768+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71769+#endif
71770+
71771+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71772+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71773+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71774+
71775 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71776 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71777
71778@@ -1476,7 +1582,7 @@ struct pid_namespace;
71779 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71780 struct pid_namespace *ns);
71781
71782-static inline pid_t task_pid_nr(struct task_struct *tsk)
71783+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71784 {
71785 return tsk->pid;
71786 }
71787@@ -1919,7 +2025,9 @@ void yield(void);
71788 extern struct exec_domain default_exec_domain;
71789
71790 union thread_union {
71791+#ifndef CONFIG_X86
71792 struct thread_info thread_info;
71793+#endif
71794 unsigned long stack[THREAD_SIZE/sizeof(long)];
71795 };
71796
71797@@ -1952,6 +2060,7 @@ extern struct pid_namespace init_pid_ns;
71798 */
71799
71800 extern struct task_struct *find_task_by_vpid(pid_t nr);
71801+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71802 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71803 struct pid_namespace *ns);
71804
71805@@ -2118,7 +2227,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71806 extern void exit_itimers(struct signal_struct *);
71807 extern void flush_itimer_signals(void);
71808
71809-extern void do_group_exit(int);
71810+extern __noreturn void do_group_exit(int);
71811
71812 extern int allow_signal(int);
71813 extern int disallow_signal(int);
71814@@ -2309,9 +2418,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71815
71816 #endif
71817
71818-static inline int object_is_on_stack(void *obj)
71819+static inline int object_starts_on_stack(void *obj)
71820 {
71821- void *stack = task_stack_page(current);
71822+ const void *stack = task_stack_page(current);
71823
71824 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71825 }
71826diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
71827index bf8086b..962b035 100644
71828--- a/include/linux/sched/sysctl.h
71829+++ b/include/linux/sched/sysctl.h
71830@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
71831 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71832
71833 extern int sysctl_max_map_count;
71834+extern unsigned long sysctl_heap_stack_gap;
71835
71836 extern unsigned int sysctl_sched_latency;
71837 extern unsigned int sysctl_sched_min_granularity;
71838diff --git a/include/linux/security.h b/include/linux/security.h
71839index 4686491..2bd210e 100644
71840--- a/include/linux/security.h
71841+++ b/include/linux/security.h
71842@@ -26,6 +26,7 @@
71843 #include <linux/capability.h>
71844 #include <linux/slab.h>
71845 #include <linux/err.h>
71846+#include <linux/grsecurity.h>
71847
71848 struct linux_binprm;
71849 struct cred;
71850diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71851index 2da29ac..aac448ec 100644
71852--- a/include/linux/seq_file.h
71853+++ b/include/linux/seq_file.h
71854@@ -26,6 +26,9 @@ struct seq_file {
71855 struct mutex lock;
71856 const struct seq_operations *op;
71857 int poll_event;
71858+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71859+ u64 exec_id;
71860+#endif
71861 #ifdef CONFIG_USER_NS
71862 struct user_namespace *user_ns;
71863 #endif
71864@@ -38,6 +41,7 @@ struct seq_operations {
71865 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71866 int (*show) (struct seq_file *m, void *v);
71867 };
71868+typedef struct seq_operations __no_const seq_operations_no_const;
71869
71870 #define SEQ_SKIP 1
71871
71872diff --git a/include/linux/shm.h b/include/linux/shm.h
71873index 429c199..4d42e38 100644
71874--- a/include/linux/shm.h
71875+++ b/include/linux/shm.h
71876@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71877
71878 /* The task created the shm object. NULL if the task is dead. */
71879 struct task_struct *shm_creator;
71880+#ifdef CONFIG_GRKERNSEC
71881+ time_t shm_createtime;
71882+ pid_t shm_lapid;
71883+#endif
71884 };
71885
71886 /* shm_mode upper byte flags */
71887diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71888index dec1748..112c1f9 100644
71889--- a/include/linux/skbuff.h
71890+++ b/include/linux/skbuff.h
71891@@ -640,7 +640,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71892 extern struct sk_buff *__alloc_skb(unsigned int size,
71893 gfp_t priority, int flags, int node);
71894 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71895-static inline struct sk_buff *alloc_skb(unsigned int size,
71896+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71897 gfp_t priority)
71898 {
71899 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71900@@ -756,7 +756,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71901 */
71902 static inline int skb_queue_empty(const struct sk_buff_head *list)
71903 {
71904- return list->next == (struct sk_buff *)list;
71905+ return list->next == (const struct sk_buff *)list;
71906 }
71907
71908 /**
71909@@ -769,7 +769,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71910 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71911 const struct sk_buff *skb)
71912 {
71913- return skb->next == (struct sk_buff *)list;
71914+ return skb->next == (const struct sk_buff *)list;
71915 }
71916
71917 /**
71918@@ -782,7 +782,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71919 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71920 const struct sk_buff *skb)
71921 {
71922- return skb->prev == (struct sk_buff *)list;
71923+ return skb->prev == (const struct sk_buff *)list;
71924 }
71925
71926 /**
71927@@ -1848,7 +1848,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71928 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71929 */
71930 #ifndef NET_SKB_PAD
71931-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71932+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71933 #endif
71934
71935 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71936@@ -2443,7 +2443,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71937 int noblock, int *err);
71938 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71939 struct poll_table_struct *wait);
71940-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71941+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71942 int offset, struct iovec *to,
71943 int size);
71944 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71945@@ -2733,6 +2733,9 @@ static inline void nf_reset(struct sk_buff *skb)
71946 nf_bridge_put(skb->nf_bridge);
71947 skb->nf_bridge = NULL;
71948 #endif
71949+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71950+ skb->nf_trace = 0;
71951+#endif
71952 }
71953
71954 static inline void nf_reset_trace(struct sk_buff *skb)
71955diff --git a/include/linux/slab.h b/include/linux/slab.h
71956index 0c62175..9ece3d8 100644
71957--- a/include/linux/slab.h
71958+++ b/include/linux/slab.h
71959@@ -12,13 +12,20 @@
71960 #include <linux/gfp.h>
71961 #include <linux/types.h>
71962 #include <linux/workqueue.h>
71963-
71964+#include <linux/err.h>
71965
71966 /*
71967 * Flags to pass to kmem_cache_create().
71968 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71969 */
71970 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71971+
71972+#ifdef CONFIG_PAX_USERCOPY_SLABS
71973+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71974+#else
71975+#define SLAB_USERCOPY 0x00000000UL
71976+#endif
71977+
71978 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71979 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71980 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71981@@ -89,10 +96,13 @@
71982 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71983 * Both make kfree a no-op.
71984 */
71985-#define ZERO_SIZE_PTR ((void *)16)
71986+#define ZERO_SIZE_PTR \
71987+({ \
71988+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71989+ (void *)(-MAX_ERRNO-1L); \
71990+})
71991
71992-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71993- (unsigned long)ZERO_SIZE_PTR)
71994+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71995
71996
71997 struct mem_cgroup;
71998@@ -132,6 +142,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71999 void kfree(const void *);
72000 void kzfree(const void *);
72001 size_t ksize(const void *);
72002+const char *check_heap_object(const void *ptr, unsigned long n);
72003+bool is_usercopy_object(const void *ptr);
72004
72005 /*
72006 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
72007@@ -164,7 +176,7 @@ struct kmem_cache {
72008 unsigned int align; /* Alignment as calculated */
72009 unsigned long flags; /* Active flags on the slab */
72010 const char *name; /* Slab name for sysfs */
72011- int refcount; /* Use counter */
72012+ atomic_t refcount; /* Use counter */
72013 void (*ctor)(void *); /* Called on object slot creation */
72014 struct list_head list; /* List of all slab caches on the system */
72015 };
72016@@ -226,6 +238,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
72017 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
72018 #endif
72019
72020+#ifdef CONFIG_PAX_USERCOPY_SLABS
72021+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
72022+#endif
72023+
72024 /*
72025 * Figure out which kmalloc slab an allocation of a certain size
72026 * belongs to.
72027@@ -234,7 +250,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
72028 * 2 = 120 .. 192 bytes
72029 * n = 2^(n-1) .. 2^n -1
72030 */
72031-static __always_inline int kmalloc_index(size_t size)
72032+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
72033 {
72034 if (!size)
72035 return 0;
72036@@ -406,6 +422,7 @@ void print_slabinfo_header(struct seq_file *m);
72037 * for general use, and so are not documented here. For a full list of
72038 * potential flags, always refer to linux/gfp.h.
72039 */
72040+
72041 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
72042 {
72043 if (size != 0 && n > SIZE_MAX / size)
72044@@ -465,7 +482,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
72045 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72046 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72047 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72048-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72049+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
72050 #define kmalloc_track_caller(size, flags) \
72051 __kmalloc_track_caller(size, flags, _RET_IP_)
72052 #else
72053@@ -485,7 +502,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
72054 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
72055 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
72056 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
72057-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
72058+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
72059 #define kmalloc_node_track_caller(size, flags, node) \
72060 __kmalloc_node_track_caller(size, flags, node, \
72061 _RET_IP_)
72062diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
72063index cd40158..d9dc02c 100644
72064--- a/include/linux/slab_def.h
72065+++ b/include/linux/slab_def.h
72066@@ -50,7 +50,7 @@ struct kmem_cache {
72067 /* 4) cache creation/removal */
72068 const char *name;
72069 struct list_head list;
72070- int refcount;
72071+ atomic_t refcount;
72072 int object_size;
72073 int align;
72074
72075@@ -66,10 +66,10 @@ struct kmem_cache {
72076 unsigned long node_allocs;
72077 unsigned long node_frees;
72078 unsigned long node_overflow;
72079- atomic_t allochit;
72080- atomic_t allocmiss;
72081- atomic_t freehit;
72082- atomic_t freemiss;
72083+ atomic_unchecked_t allochit;
72084+ atomic_unchecked_t allocmiss;
72085+ atomic_unchecked_t freehit;
72086+ atomic_unchecked_t freemiss;
72087
72088 /*
72089 * If debugging is enabled, then the allocator can add additional
72090@@ -103,7 +103,7 @@ struct kmem_cache {
72091 };
72092
72093 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72094-void *__kmalloc(size_t size, gfp_t flags);
72095+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
72096
72097 #ifdef CONFIG_TRACING
72098 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
72099@@ -136,6 +136,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72100 cachep = kmalloc_dma_caches[i];
72101 else
72102 #endif
72103+
72104+#ifdef CONFIG_PAX_USERCOPY_SLABS
72105+ if (flags & GFP_USERCOPY)
72106+ cachep = kmalloc_usercopy_caches[i];
72107+ else
72108+#endif
72109+
72110 cachep = kmalloc_caches[i];
72111
72112 ret = kmem_cache_alloc_trace(cachep, flags, size);
72113@@ -146,7 +153,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72114 }
72115
72116 #ifdef CONFIG_NUMA
72117-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
72118+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72119 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72120
72121 #ifdef CONFIG_TRACING
72122@@ -185,6 +192,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72123 cachep = kmalloc_dma_caches[i];
72124 else
72125 #endif
72126+
72127+#ifdef CONFIG_PAX_USERCOPY_SLABS
72128+ if (flags & GFP_USERCOPY)
72129+ cachep = kmalloc_usercopy_caches[i];
72130+ else
72131+#endif
72132+
72133 cachep = kmalloc_caches[i];
72134
72135 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
72136diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
72137index f28e14a..7831211 100644
72138--- a/include/linux/slob_def.h
72139+++ b/include/linux/slob_def.h
72140@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
72141 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
72142 }
72143
72144-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72145+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72146
72147 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72148 {
72149@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72150 return __kmalloc_node(size, flags, NUMA_NO_NODE);
72151 }
72152
72153-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
72154+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
72155 {
72156 return kmalloc(size, flags);
72157 }
72158diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
72159index 027276f..092bfe8 100644
72160--- a/include/linux/slub_def.h
72161+++ b/include/linux/slub_def.h
72162@@ -80,7 +80,7 @@ struct kmem_cache {
72163 struct kmem_cache_order_objects max;
72164 struct kmem_cache_order_objects min;
72165 gfp_t allocflags; /* gfp flags to use on each alloc */
72166- int refcount; /* Refcount for slab cache destroy */
72167+ atomic_t refcount; /* Refcount for slab cache destroy */
72168 void (*ctor)(void *);
72169 int inuse; /* Offset to metadata */
72170 int align; /* Alignment */
72171@@ -105,7 +105,7 @@ struct kmem_cache {
72172 };
72173
72174 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72175-void *__kmalloc(size_t size, gfp_t flags);
72176+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
72177
72178 static __always_inline void *
72179 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
72180@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
72181 }
72182 #endif
72183
72184-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
72185+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
72186 {
72187 unsigned int order = get_order(size);
72188 return kmalloc_order_trace(size, flags, order);
72189@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72190 }
72191
72192 #ifdef CONFIG_NUMA
72193-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72194+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72195 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72196
72197 #ifdef CONFIG_TRACING
72198diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
72199index 54f91d3..be2c379 100644
72200--- a/include/linux/sock_diag.h
72201+++ b/include/linux/sock_diag.h
72202@@ -11,7 +11,7 @@ struct sock;
72203 struct sock_diag_handler {
72204 __u8 family;
72205 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
72206-};
72207+} __do_const;
72208
72209 int sock_diag_register(const struct sock_diag_handler *h);
72210 void sock_diag_unregister(const struct sock_diag_handler *h);
72211diff --git a/include/linux/sonet.h b/include/linux/sonet.h
72212index 680f9a3..f13aeb0 100644
72213--- a/include/linux/sonet.h
72214+++ b/include/linux/sonet.h
72215@@ -7,7 +7,7 @@
72216 #include <uapi/linux/sonet.h>
72217
72218 struct k_sonet_stats {
72219-#define __HANDLE_ITEM(i) atomic_t i
72220+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72221 __SONET_ITEMS
72222 #undef __HANDLE_ITEM
72223 };
72224diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
72225index 07d8e53..dc934c9 100644
72226--- a/include/linux/sunrpc/addr.h
72227+++ b/include/linux/sunrpc/addr.h
72228@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72229 {
72230 switch (sap->sa_family) {
72231 case AF_INET:
72232- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72233+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72234 case AF_INET6:
72235- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72236+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72237 }
72238 return 0;
72239 }
72240@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72241 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
72242 const struct sockaddr *src)
72243 {
72244- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
72245+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72246 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72247
72248 dsin->sin_family = ssin->sin_family;
72249@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72250 if (sa->sa_family != AF_INET6)
72251 return 0;
72252
72253- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72254+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72255 }
72256
72257 #endif /* _LINUX_SUNRPC_ADDR_H */
72258diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
72259index bfe11be..12bc8c4 100644
72260--- a/include/linux/sunrpc/clnt.h
72261+++ b/include/linux/sunrpc/clnt.h
72262@@ -96,7 +96,7 @@ struct rpc_procinfo {
72263 unsigned int p_timer; /* Which RTT timer to use */
72264 u32 p_statidx; /* Which procedure to account */
72265 const char * p_name; /* name of procedure */
72266-};
72267+} __do_const;
72268
72269 #ifdef __KERNEL__
72270
72271diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72272index 1f0216b..6a4fa50 100644
72273--- a/include/linux/sunrpc/svc.h
72274+++ b/include/linux/sunrpc/svc.h
72275@@ -411,7 +411,7 @@ struct svc_procedure {
72276 unsigned int pc_count; /* call count */
72277 unsigned int pc_cachetype; /* cache info (NFS) */
72278 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72279-};
72280+} __do_const;
72281
72282 /*
72283 * Function prototypes.
72284diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72285index 0b8e3e6..33e0a01 100644
72286--- a/include/linux/sunrpc/svc_rdma.h
72287+++ b/include/linux/sunrpc/svc_rdma.h
72288@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72289 extern unsigned int svcrdma_max_requests;
72290 extern unsigned int svcrdma_max_req_size;
72291
72292-extern atomic_t rdma_stat_recv;
72293-extern atomic_t rdma_stat_read;
72294-extern atomic_t rdma_stat_write;
72295-extern atomic_t rdma_stat_sq_starve;
72296-extern atomic_t rdma_stat_rq_starve;
72297-extern atomic_t rdma_stat_rq_poll;
72298-extern atomic_t rdma_stat_rq_prod;
72299-extern atomic_t rdma_stat_sq_poll;
72300-extern atomic_t rdma_stat_sq_prod;
72301+extern atomic_unchecked_t rdma_stat_recv;
72302+extern atomic_unchecked_t rdma_stat_read;
72303+extern atomic_unchecked_t rdma_stat_write;
72304+extern atomic_unchecked_t rdma_stat_sq_starve;
72305+extern atomic_unchecked_t rdma_stat_rq_starve;
72306+extern atomic_unchecked_t rdma_stat_rq_poll;
72307+extern atomic_unchecked_t rdma_stat_rq_prod;
72308+extern atomic_unchecked_t rdma_stat_sq_poll;
72309+extern atomic_unchecked_t rdma_stat_sq_prod;
72310
72311 #define RPCRDMA_VERSION 1
72312
72313diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72314index ff374ab..7fd2ecb 100644
72315--- a/include/linux/sunrpc/svcauth.h
72316+++ b/include/linux/sunrpc/svcauth.h
72317@@ -109,7 +109,7 @@ struct auth_ops {
72318 int (*release)(struct svc_rqst *rq);
72319 void (*domain_release)(struct auth_domain *);
72320 int (*set_client)(struct svc_rqst *rq);
72321-};
72322+} __do_const;
72323
72324 #define SVC_GARBAGE 1
72325 #define SVC_SYSERR 2
72326diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72327index a5ffd32..0935dea 100644
72328--- a/include/linux/swiotlb.h
72329+++ b/include/linux/swiotlb.h
72330@@ -60,7 +60,8 @@ extern void
72331
72332 extern void
72333 swiotlb_free_coherent(struct device *hwdev, size_t size,
72334- void *vaddr, dma_addr_t dma_handle);
72335+ void *vaddr, dma_addr_t dma_handle,
72336+ struct dma_attrs *attrs);
72337
72338 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72339 unsigned long offset, size_t size,
72340diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72341index 4147d70..31a1791 100644
72342--- a/include/linux/syscalls.h
72343+++ b/include/linux/syscalls.h
72344@@ -362,11 +362,11 @@ asmlinkage long sys_sync(void);
72345 asmlinkage long sys_fsync(unsigned int fd);
72346 asmlinkage long sys_fdatasync(unsigned int fd);
72347 asmlinkage long sys_bdflush(int func, long data);
72348-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
72349- char __user *type, unsigned long flags,
72350+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
72351+ const char __user *type, unsigned long flags,
72352 void __user *data);
72353-asmlinkage long sys_umount(char __user *name, int flags);
72354-asmlinkage long sys_oldumount(char __user *name);
72355+asmlinkage long sys_umount(const char __user *name, int flags);
72356+asmlinkage long sys_oldumount(const char __user *name);
72357 asmlinkage long sys_truncate(const char __user *path, long length);
72358 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
72359 asmlinkage long sys_stat(const char __user *filename,
72360@@ -578,7 +578,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72361 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72362 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72363 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72364- struct sockaddr __user *, int);
72365+ struct sockaddr __user *, int) __intentional_overflow(0);
72366 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72367 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72368 unsigned int vlen, unsigned flags);
72369diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72370index 27b3b0b..e093dd9 100644
72371--- a/include/linux/syscore_ops.h
72372+++ b/include/linux/syscore_ops.h
72373@@ -16,7 +16,7 @@ struct syscore_ops {
72374 int (*suspend)(void);
72375 void (*resume)(void);
72376 void (*shutdown)(void);
72377-};
72378+} __do_const;
72379
72380 extern void register_syscore_ops(struct syscore_ops *ops);
72381 extern void unregister_syscore_ops(struct syscore_ops *ops);
72382diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72383index 14a8ff2..af52bad 100644
72384--- a/include/linux/sysctl.h
72385+++ b/include/linux/sysctl.h
72386@@ -34,13 +34,13 @@ struct ctl_table_root;
72387 struct ctl_table_header;
72388 struct ctl_dir;
72389
72390-typedef struct ctl_table ctl_table;
72391-
72392 typedef int proc_handler (struct ctl_table *ctl, int write,
72393 void __user *buffer, size_t *lenp, loff_t *ppos);
72394
72395 extern int proc_dostring(struct ctl_table *, int,
72396 void __user *, size_t *, loff_t *);
72397+extern int proc_dostring_modpriv(struct ctl_table *, int,
72398+ void __user *, size_t *, loff_t *);
72399 extern int proc_dointvec(struct ctl_table *, int,
72400 void __user *, size_t *, loff_t *);
72401 extern int proc_dointvec_minmax(struct ctl_table *, int,
72402@@ -115,7 +115,9 @@ struct ctl_table
72403 struct ctl_table_poll *poll;
72404 void *extra1;
72405 void *extra2;
72406-};
72407+} __do_const;
72408+typedef struct ctl_table __no_const ctl_table_no_const;
72409+typedef struct ctl_table ctl_table;
72410
72411 struct ctl_node {
72412 struct rb_node node;
72413diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72414index e2cee22..3ddb921 100644
72415--- a/include/linux/sysfs.h
72416+++ b/include/linux/sysfs.h
72417@@ -31,7 +31,8 @@ struct attribute {
72418 struct lock_class_key *key;
72419 struct lock_class_key skey;
72420 #endif
72421-};
72422+} __do_const;
72423+typedef struct attribute __no_const attribute_no_const;
72424
72425 /**
72426 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72427@@ -59,8 +60,8 @@ struct attribute_group {
72428 umode_t (*is_visible)(struct kobject *,
72429 struct attribute *, int);
72430 struct attribute **attrs;
72431-};
72432-
72433+} __do_const;
72434+typedef struct attribute_group __no_const attribute_group_no_const;
72435
72436
72437 /**
72438@@ -107,7 +108,8 @@ struct bin_attribute {
72439 char *, loff_t, size_t);
72440 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72441 struct vm_area_struct *vma);
72442-};
72443+} __do_const;
72444+typedef struct bin_attribute __no_const bin_attribute_no_const;
72445
72446 /**
72447 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72448diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72449index 7faf933..9b85a0c 100644
72450--- a/include/linux/sysrq.h
72451+++ b/include/linux/sysrq.h
72452@@ -16,6 +16,7 @@
72453
72454 #include <linux/errno.h>
72455 #include <linux/types.h>
72456+#include <linux/compiler.h>
72457
72458 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72459 #define SYSRQ_DEFAULT_ENABLE 1
72460@@ -36,7 +37,7 @@ struct sysrq_key_op {
72461 char *help_msg;
72462 char *action_msg;
72463 int enable_mask;
72464-};
72465+} __do_const;
72466
72467 #ifdef CONFIG_MAGIC_SYSRQ
72468
72469diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72470index e7e0473..7989295 100644
72471--- a/include/linux/thread_info.h
72472+++ b/include/linux/thread_info.h
72473@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72474 #error "no set_restore_sigmask() provided and default one won't work"
72475 #endif
72476
72477+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72478+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72479+{
72480+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72481+ if (!__builtin_constant_p(n))
72482+#endif
72483+ __check_object_size(ptr, n, to_user);
72484+}
72485+
72486 #endif /* __KERNEL__ */
72487
72488 #endif /* _LINUX_THREAD_INFO_H */
72489diff --git a/include/linux/tty.h b/include/linux/tty.h
72490index 8780bd2..d1ae08b 100644
72491--- a/include/linux/tty.h
72492+++ b/include/linux/tty.h
72493@@ -194,7 +194,7 @@ struct tty_port {
72494 const struct tty_port_operations *ops; /* Port operations */
72495 spinlock_t lock; /* Lock protecting tty field */
72496 int blocked_open; /* Waiting to open */
72497- int count; /* Usage count */
72498+ atomic_t count; /* Usage count */
72499 wait_queue_head_t open_wait; /* Open waiters */
72500 wait_queue_head_t close_wait; /* Close waiters */
72501 wait_queue_head_t delta_msr_wait; /* Modem status change */
72502@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
72503 struct tty_struct *tty, struct file *filp);
72504 static inline int tty_port_users(struct tty_port *port)
72505 {
72506- return port->count + port->blocked_open;
72507+ return atomic_read(&port->count) + port->blocked_open;
72508 }
72509
72510 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72511diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72512index 756a609..b302dd6 100644
72513--- a/include/linux/tty_driver.h
72514+++ b/include/linux/tty_driver.h
72515@@ -285,7 +285,7 @@ struct tty_operations {
72516 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72517 #endif
72518 const struct file_operations *proc_fops;
72519-};
72520+} __do_const;
72521
72522 struct tty_driver {
72523 int magic; /* magic number for this structure */
72524diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72525index 58390c7..95e214c 100644
72526--- a/include/linux/tty_ldisc.h
72527+++ b/include/linux/tty_ldisc.h
72528@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
72529
72530 struct module *owner;
72531
72532- int refcount;
72533+ atomic_t refcount;
72534 };
72535
72536 struct tty_ldisc {
72537diff --git a/include/linux/types.h b/include/linux/types.h
72538index 4d118ba..c3ee9bf 100644
72539--- a/include/linux/types.h
72540+++ b/include/linux/types.h
72541@@ -176,10 +176,26 @@ typedef struct {
72542 int counter;
72543 } atomic_t;
72544
72545+#ifdef CONFIG_PAX_REFCOUNT
72546+typedef struct {
72547+ int counter;
72548+} atomic_unchecked_t;
72549+#else
72550+typedef atomic_t atomic_unchecked_t;
72551+#endif
72552+
72553 #ifdef CONFIG_64BIT
72554 typedef struct {
72555 long counter;
72556 } atomic64_t;
72557+
72558+#ifdef CONFIG_PAX_REFCOUNT
72559+typedef struct {
72560+ long counter;
72561+} atomic64_unchecked_t;
72562+#else
72563+typedef atomic64_t atomic64_unchecked_t;
72564+#endif
72565 #endif
72566
72567 struct list_head {
72568diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72569index 5ca0951..ab496a5 100644
72570--- a/include/linux/uaccess.h
72571+++ b/include/linux/uaccess.h
72572@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72573 long ret; \
72574 mm_segment_t old_fs = get_fs(); \
72575 \
72576- set_fs(KERNEL_DS); \
72577 pagefault_disable(); \
72578- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72579- pagefault_enable(); \
72580+ set_fs(KERNEL_DS); \
72581+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72582 set_fs(old_fs); \
72583+ pagefault_enable(); \
72584 ret; \
72585 })
72586
72587diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72588index 8e522cbc..aa8572d 100644
72589--- a/include/linux/uidgid.h
72590+++ b/include/linux/uidgid.h
72591@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72592
72593 #endif /* CONFIG_USER_NS */
72594
72595+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72596+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72597+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72598+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72599+
72600 #endif /* _LINUX_UIDGID_H */
72601diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72602index 99c1b4d..562e6f3 100644
72603--- a/include/linux/unaligned/access_ok.h
72604+++ b/include/linux/unaligned/access_ok.h
72605@@ -4,34 +4,34 @@
72606 #include <linux/kernel.h>
72607 #include <asm/byteorder.h>
72608
72609-static inline u16 get_unaligned_le16(const void *p)
72610+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72611 {
72612- return le16_to_cpup((__le16 *)p);
72613+ return le16_to_cpup((const __le16 *)p);
72614 }
72615
72616-static inline u32 get_unaligned_le32(const void *p)
72617+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72618 {
72619- return le32_to_cpup((__le32 *)p);
72620+ return le32_to_cpup((const __le32 *)p);
72621 }
72622
72623-static inline u64 get_unaligned_le64(const void *p)
72624+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72625 {
72626- return le64_to_cpup((__le64 *)p);
72627+ return le64_to_cpup((const __le64 *)p);
72628 }
72629
72630-static inline u16 get_unaligned_be16(const void *p)
72631+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72632 {
72633- return be16_to_cpup((__be16 *)p);
72634+ return be16_to_cpup((const __be16 *)p);
72635 }
72636
72637-static inline u32 get_unaligned_be32(const void *p)
72638+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72639 {
72640- return be32_to_cpup((__be32 *)p);
72641+ return be32_to_cpup((const __be32 *)p);
72642 }
72643
72644-static inline u64 get_unaligned_be64(const void *p)
72645+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72646 {
72647- return be64_to_cpup((__be64 *)p);
72648+ return be64_to_cpup((const __be64 *)p);
72649 }
72650
72651 static inline void put_unaligned_le16(u16 val, void *p)
72652diff --git a/include/linux/usb.h b/include/linux/usb.h
72653index a0bee5a..5533a52 100644
72654--- a/include/linux/usb.h
72655+++ b/include/linux/usb.h
72656@@ -552,7 +552,7 @@ struct usb_device {
72657 int maxchild;
72658
72659 u32 quirks;
72660- atomic_t urbnum;
72661+ atomic_unchecked_t urbnum;
72662
72663 unsigned long active_duration;
72664
72665@@ -1607,7 +1607,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72666
72667 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72668 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72669- void *data, __u16 size, int timeout);
72670+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72671 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72672 void *data, int len, int *actual_length, int timeout);
72673 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72674diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72675index e452ba6..78f8e80 100644
72676--- a/include/linux/usb/renesas_usbhs.h
72677+++ b/include/linux/usb/renesas_usbhs.h
72678@@ -39,7 +39,7 @@ enum {
72679 */
72680 struct renesas_usbhs_driver_callback {
72681 int (*notify_hotplug)(struct platform_device *pdev);
72682-};
72683+} __no_const;
72684
72685 /*
72686 * callback functions for platform
72687diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72688index 6f8fbcf..8259001 100644
72689--- a/include/linux/vermagic.h
72690+++ b/include/linux/vermagic.h
72691@@ -25,9 +25,35 @@
72692 #define MODULE_ARCH_VERMAGIC ""
72693 #endif
72694
72695+#ifdef CONFIG_PAX_REFCOUNT
72696+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72697+#else
72698+#define MODULE_PAX_REFCOUNT ""
72699+#endif
72700+
72701+#ifdef CONSTIFY_PLUGIN
72702+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72703+#else
72704+#define MODULE_CONSTIFY_PLUGIN ""
72705+#endif
72706+
72707+#ifdef STACKLEAK_PLUGIN
72708+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72709+#else
72710+#define MODULE_STACKLEAK_PLUGIN ""
72711+#endif
72712+
72713+#ifdef CONFIG_GRKERNSEC
72714+#define MODULE_GRSEC "GRSEC "
72715+#else
72716+#define MODULE_GRSEC ""
72717+#endif
72718+
72719 #define VERMAGIC_STRING \
72720 UTS_RELEASE " " \
72721 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72722 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72723- MODULE_ARCH_VERMAGIC
72724+ MODULE_ARCH_VERMAGIC \
72725+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72726+ MODULE_GRSEC
72727
72728diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72729index 7d5773a..541c01c 100644
72730--- a/include/linux/vmalloc.h
72731+++ b/include/linux/vmalloc.h
72732@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72733 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72734 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72735 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72736+
72737+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72738+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72739+#endif
72740+
72741 /* bits [20..32] reserved for arch specific ioremap internals */
72742
72743 /*
72744@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
72745 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72746 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72747 unsigned long start, unsigned long end, gfp_t gfp_mask,
72748- pgprot_t prot, int node, const void *caller);
72749+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72750 extern void vfree(const void *addr);
72751
72752 extern void *vmap(struct page **pages, unsigned int count,
72753@@ -137,8 +142,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72754 extern void free_vm_area(struct vm_struct *area);
72755
72756 /* for /dev/kmem */
72757-extern long vread(char *buf, char *addr, unsigned long count);
72758-extern long vwrite(char *buf, char *addr, unsigned long count);
72759+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72760+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72761
72762 /*
72763 * Internals. Dont't use..
72764diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72765index c586679..f06b389 100644
72766--- a/include/linux/vmstat.h
72767+++ b/include/linux/vmstat.h
72768@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
72769 /*
72770 * Zone based page accounting with per cpu differentials.
72771 */
72772-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72773+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72774
72775 static inline void zone_page_state_add(long x, struct zone *zone,
72776 enum zone_stat_item item)
72777 {
72778- atomic_long_add(x, &zone->vm_stat[item]);
72779- atomic_long_add(x, &vm_stat[item]);
72780+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72781+ atomic_long_add_unchecked(x, &vm_stat[item]);
72782 }
72783
72784 static inline unsigned long global_page_state(enum zone_stat_item item)
72785 {
72786- long x = atomic_long_read(&vm_stat[item]);
72787+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72788 #ifdef CONFIG_SMP
72789 if (x < 0)
72790 x = 0;
72791@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72792 static inline unsigned long zone_page_state(struct zone *zone,
72793 enum zone_stat_item item)
72794 {
72795- long x = atomic_long_read(&zone->vm_stat[item]);
72796+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72797 #ifdef CONFIG_SMP
72798 if (x < 0)
72799 x = 0;
72800@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72801 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72802 enum zone_stat_item item)
72803 {
72804- long x = atomic_long_read(&zone->vm_stat[item]);
72805+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72806
72807 #ifdef CONFIG_SMP
72808 int cpu;
72809@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72810
72811 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72812 {
72813- atomic_long_inc(&zone->vm_stat[item]);
72814- atomic_long_inc(&vm_stat[item]);
72815+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72816+ atomic_long_inc_unchecked(&vm_stat[item]);
72817 }
72818
72819 static inline void __inc_zone_page_state(struct page *page,
72820@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
72821
72822 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72823 {
72824- atomic_long_dec(&zone->vm_stat[item]);
72825- atomic_long_dec(&vm_stat[item]);
72826+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72827+ atomic_long_dec_unchecked(&vm_stat[item]);
72828 }
72829
72830 static inline void __dec_zone_page_state(struct page *page,
72831diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72832index fdbafc6..49dfe4f 100644
72833--- a/include/linux/xattr.h
72834+++ b/include/linux/xattr.h
72835@@ -28,7 +28,7 @@ struct xattr_handler {
72836 size_t size, int handler_flags);
72837 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72838 size_t size, int flags, int handler_flags);
72839-};
72840+} __do_const;
72841
72842 struct xattr {
72843 char *name;
72844@@ -37,6 +37,9 @@ struct xattr {
72845 };
72846
72847 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
72848+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
72849+ssize_t pax_getxattr(struct dentry *, void *, size_t);
72850+#endif
72851 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
72852 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
72853 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
72854diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72855index 9c5a6b4..09c9438 100644
72856--- a/include/linux/zlib.h
72857+++ b/include/linux/zlib.h
72858@@ -31,6 +31,7 @@
72859 #define _ZLIB_H
72860
72861 #include <linux/zconf.h>
72862+#include <linux/compiler.h>
72863
72864 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72865 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72866@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72867
72868 /* basic functions */
72869
72870-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72871+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72872 /*
72873 Returns the number of bytes that needs to be allocated for a per-
72874 stream workspace with the specified parameters. A pointer to this
72875diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72876index 95d1c91..6798cca 100644
72877--- a/include/media/v4l2-dev.h
72878+++ b/include/media/v4l2-dev.h
72879@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72880 int (*mmap) (struct file *, struct vm_area_struct *);
72881 int (*open) (struct file *);
72882 int (*release) (struct file *);
72883-};
72884+} __do_const;
72885
72886 /*
72887 * Newer version of video_device, handled by videodev2.c
72888diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72889index adcbb20..62c2559 100644
72890--- a/include/net/9p/transport.h
72891+++ b/include/net/9p/transport.h
72892@@ -57,7 +57,7 @@ struct p9_trans_module {
72893 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72894 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72895 char *, char *, int , int, int, int);
72896-};
72897+} __do_const;
72898
72899 void v9fs_register_trans(struct p9_trans_module *m);
72900 void v9fs_unregister_trans(struct p9_trans_module *m);
72901diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72902index fb94cf1..7c0c987 100644
72903--- a/include/net/bluetooth/l2cap.h
72904+++ b/include/net/bluetooth/l2cap.h
72905@@ -551,7 +551,7 @@ struct l2cap_ops {
72906 void (*defer) (struct l2cap_chan *chan);
72907 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72908 unsigned long len, int nb);
72909-};
72910+} __do_const;
72911
72912 struct l2cap_conn {
72913 struct hci_conn *hcon;
72914diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72915index f2ae33d..c457cf0 100644
72916--- a/include/net/caif/cfctrl.h
72917+++ b/include/net/caif/cfctrl.h
72918@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72919 void (*radioset_rsp)(void);
72920 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72921 struct cflayer *client_layer);
72922-};
72923+} __no_const;
72924
72925 /* Link Setup Parameters for CAIF-Links. */
72926 struct cfctrl_link_param {
72927@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72928 struct cfctrl {
72929 struct cfsrvl serv;
72930 struct cfctrl_rsp res;
72931- atomic_t req_seq_no;
72932- atomic_t rsp_seq_no;
72933+ atomic_unchecked_t req_seq_no;
72934+ atomic_unchecked_t rsp_seq_no;
72935 struct list_head list;
72936 /* Protects from simultaneous access to first_req list */
72937 spinlock_t info_list_lock;
72938diff --git a/include/net/flow.h b/include/net/flow.h
72939index 628e11b..4c475df 100644
72940--- a/include/net/flow.h
72941+++ b/include/net/flow.h
72942@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72943
72944 extern void flow_cache_flush(void);
72945 extern void flow_cache_flush_deferred(void);
72946-extern atomic_t flow_cache_genid;
72947+extern atomic_unchecked_t flow_cache_genid;
72948
72949 #endif
72950diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72951index 93024a4..eeb6b6e 100644
72952--- a/include/net/genetlink.h
72953+++ b/include/net/genetlink.h
72954@@ -119,7 +119,7 @@ struct genl_ops {
72955 struct netlink_callback *cb);
72956 int (*done)(struct netlink_callback *cb);
72957 struct list_head ops_list;
72958-};
72959+} __do_const;
72960
72961 extern int genl_register_family(struct genl_family *family);
72962 extern int genl_register_family_with_ops(struct genl_family *family,
72963diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72964index 734d9b5..48a9a4b 100644
72965--- a/include/net/gro_cells.h
72966+++ b/include/net/gro_cells.h
72967@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72968 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72969
72970 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72971- atomic_long_inc(&dev->rx_dropped);
72972+ atomic_long_inc_unchecked(&dev->rx_dropped);
72973 kfree_skb(skb);
72974 return;
72975 }
72976diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72977index de2c785..0588a6b 100644
72978--- a/include/net/inet_connection_sock.h
72979+++ b/include/net/inet_connection_sock.h
72980@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72981 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72982 int (*bind_conflict)(const struct sock *sk,
72983 const struct inet_bind_bucket *tb, bool relax);
72984-};
72985+} __do_const;
72986
72987 /** inet_connection_sock - INET connection oriented sock
72988 *
72989diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72990index 53f464d..ba76aaa 100644
72991--- a/include/net/inetpeer.h
72992+++ b/include/net/inetpeer.h
72993@@ -47,8 +47,8 @@ struct inet_peer {
72994 */
72995 union {
72996 struct {
72997- atomic_t rid; /* Frag reception counter */
72998- atomic_t ip_id_count; /* IP ID for the next packet */
72999+ atomic_unchecked_t rid; /* Frag reception counter */
73000+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
73001 };
73002 struct rcu_head rcu;
73003 struct inet_peer *gc_next;
73004@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
73005 more++;
73006 inet_peer_refcheck(p);
73007 do {
73008- old = atomic_read(&p->ip_id_count);
73009+ old = atomic_read_unchecked(&p->ip_id_count);
73010 new = old + more;
73011 if (!new)
73012 new = 1;
73013- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
73014+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
73015 return new;
73016 }
73017
73018diff --git a/include/net/ip.h b/include/net/ip.h
73019index a68f838..74518ab 100644
73020--- a/include/net/ip.h
73021+++ b/include/net/ip.h
73022@@ -202,7 +202,7 @@ extern struct local_ports {
73023 } sysctl_local_ports;
73024 extern void inet_get_local_port_range(int *low, int *high);
73025
73026-extern unsigned long *sysctl_local_reserved_ports;
73027+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
73028 static inline int inet_is_reserved_local_port(int port)
73029 {
73030 return test_bit(port, sysctl_local_reserved_ports);
73031diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
73032index e49db91..76a81de 100644
73033--- a/include/net/ip_fib.h
73034+++ b/include/net/ip_fib.h
73035@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
73036
73037 #define FIB_RES_SADDR(net, res) \
73038 ((FIB_RES_NH(res).nh_saddr_genid == \
73039- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
73040+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
73041 FIB_RES_NH(res).nh_saddr : \
73042 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
73043 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
73044diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
73045index 4c062cc..3562c31 100644
73046--- a/include/net/ip_vs.h
73047+++ b/include/net/ip_vs.h
73048@@ -612,7 +612,7 @@ struct ip_vs_conn {
73049 struct ip_vs_conn *control; /* Master control connection */
73050 atomic_t n_control; /* Number of controlled ones */
73051 struct ip_vs_dest *dest; /* real server */
73052- atomic_t in_pkts; /* incoming packet counter */
73053+ atomic_unchecked_t in_pkts; /* incoming packet counter */
73054
73055 /* packet transmitter for different forwarding methods. If it
73056 mangles the packet, it must return NF_DROP or better NF_STOLEN,
73057@@ -761,7 +761,7 @@ struct ip_vs_dest {
73058 __be16 port; /* port number of the server */
73059 union nf_inet_addr addr; /* IP address of the server */
73060 volatile unsigned int flags; /* dest status flags */
73061- atomic_t conn_flags; /* flags to copy to conn */
73062+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
73063 atomic_t weight; /* server weight */
73064
73065 atomic_t refcnt; /* reference counter */
73066@@ -1013,11 +1013,11 @@ struct netns_ipvs {
73067 /* ip_vs_lblc */
73068 int sysctl_lblc_expiration;
73069 struct ctl_table_header *lblc_ctl_header;
73070- struct ctl_table *lblc_ctl_table;
73071+ ctl_table_no_const *lblc_ctl_table;
73072 /* ip_vs_lblcr */
73073 int sysctl_lblcr_expiration;
73074 struct ctl_table_header *lblcr_ctl_header;
73075- struct ctl_table *lblcr_ctl_table;
73076+ ctl_table_no_const *lblcr_ctl_table;
73077 /* ip_vs_est */
73078 struct list_head est_list; /* estimator list */
73079 spinlock_t est_lock;
73080diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
73081index 80ffde3..968b0f4 100644
73082--- a/include/net/irda/ircomm_tty.h
73083+++ b/include/net/irda/ircomm_tty.h
73084@@ -35,6 +35,7 @@
73085 #include <linux/termios.h>
73086 #include <linux/timer.h>
73087 #include <linux/tty.h> /* struct tty_struct */
73088+#include <asm/local.h>
73089
73090 #include <net/irda/irias_object.h>
73091 #include <net/irda/ircomm_core.h>
73092diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
73093index 714cc9a..ea05f3e 100644
73094--- a/include/net/iucv/af_iucv.h
73095+++ b/include/net/iucv/af_iucv.h
73096@@ -149,7 +149,7 @@ struct iucv_skb_cb {
73097 struct iucv_sock_list {
73098 struct hlist_head head;
73099 rwlock_t lock;
73100- atomic_t autobind_name;
73101+ atomic_unchecked_t autobind_name;
73102 };
73103
73104 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
73105diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
73106index df83f69..9b640b8 100644
73107--- a/include/net/llc_c_ac.h
73108+++ b/include/net/llc_c_ac.h
73109@@ -87,7 +87,7 @@
73110 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
73111 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
73112
73113-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73114+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73115
73116 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
73117 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
73118diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
73119index 6ca3113..f8026dd 100644
73120--- a/include/net/llc_c_ev.h
73121+++ b/include/net/llc_c_ev.h
73122@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
73123 return (struct llc_conn_state_ev *)skb->cb;
73124 }
73125
73126-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73127-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73128+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73129+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73130
73131 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
73132 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
73133diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
73134index 0e79cfb..f46db31 100644
73135--- a/include/net/llc_c_st.h
73136+++ b/include/net/llc_c_st.h
73137@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
73138 u8 next_state;
73139 llc_conn_ev_qfyr_t *ev_qualifiers;
73140 llc_conn_action_t *ev_actions;
73141-};
73142+} __do_const;
73143
73144 struct llc_conn_state {
73145 u8 current_state;
73146diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
73147index 37a3bbd..55a4241 100644
73148--- a/include/net/llc_s_ac.h
73149+++ b/include/net/llc_s_ac.h
73150@@ -23,7 +23,7 @@
73151 #define SAP_ACT_TEST_IND 9
73152
73153 /* All action functions must look like this */
73154-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73155+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73156
73157 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
73158 struct sk_buff *skb);
73159diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
73160index 567c681..cd73ac0 100644
73161--- a/include/net/llc_s_st.h
73162+++ b/include/net/llc_s_st.h
73163@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
73164 llc_sap_ev_t ev;
73165 u8 next_state;
73166 llc_sap_action_t *ev_actions;
73167-};
73168+} __do_const;
73169
73170 struct llc_sap_state {
73171 u8 curr_state;
73172diff --git a/include/net/mac80211.h b/include/net/mac80211.h
73173index 885898a..cdace34 100644
73174--- a/include/net/mac80211.h
73175+++ b/include/net/mac80211.h
73176@@ -4205,7 +4205,7 @@ struct rate_control_ops {
73177 void (*add_sta_debugfs)(void *priv, void *priv_sta,
73178 struct dentry *dir);
73179 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
73180-};
73181+} __do_const;
73182
73183 static inline int rate_supported(struct ieee80211_sta *sta,
73184 enum ieee80211_band band,
73185diff --git a/include/net/neighbour.h b/include/net/neighbour.h
73186index 7e748ad..5c6229b 100644
73187--- a/include/net/neighbour.h
73188+++ b/include/net/neighbour.h
73189@@ -123,7 +123,7 @@ struct neigh_ops {
73190 void (*error_report)(struct neighbour *, struct sk_buff *);
73191 int (*output)(struct neighbour *, struct sk_buff *);
73192 int (*connected_output)(struct neighbour *, struct sk_buff *);
73193-};
73194+} __do_const;
73195
73196 struct pneigh_entry {
73197 struct pneigh_entry *next;
73198diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
73199index b176978..ea169f4 100644
73200--- a/include/net/net_namespace.h
73201+++ b/include/net/net_namespace.h
73202@@ -117,7 +117,7 @@ struct net {
73203 #endif
73204 struct netns_ipvs *ipvs;
73205 struct sock *diag_nlsk;
73206- atomic_t rt_genid;
73207+ atomic_unchecked_t rt_genid;
73208 };
73209
73210 /*
73211@@ -274,7 +274,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73212 #define __net_init __init
73213 #define __net_exit __exit_refok
73214 #define __net_initdata __initdata
73215+#ifdef CONSTIFY_PLUGIN
73216 #define __net_initconst __initconst
73217+#else
73218+#define __net_initconst __initdata
73219+#endif
73220 #endif
73221
73222 struct pernet_operations {
73223@@ -284,7 +288,7 @@ struct pernet_operations {
73224 void (*exit_batch)(struct list_head *net_exit_list);
73225 int *id;
73226 size_t size;
73227-};
73228+} __do_const;
73229
73230 /*
73231 * Use these carefully. If you implement a network device and it
73232@@ -332,12 +336,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73233
73234 static inline int rt_genid(struct net *net)
73235 {
73236- return atomic_read(&net->rt_genid);
73237+ return atomic_read_unchecked(&net->rt_genid);
73238 }
73239
73240 static inline void rt_genid_bump(struct net *net)
73241 {
73242- atomic_inc(&net->rt_genid);
73243+ atomic_inc_unchecked(&net->rt_genid);
73244 }
73245
73246 #endif /* __NET_NET_NAMESPACE_H */
73247diff --git a/include/net/netdma.h b/include/net/netdma.h
73248index 8ba8ce2..99b7fff 100644
73249--- a/include/net/netdma.h
73250+++ b/include/net/netdma.h
73251@@ -24,7 +24,7 @@
73252 #include <linux/dmaengine.h>
73253 #include <linux/skbuff.h>
73254
73255-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73256+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73257 struct sk_buff *skb, int offset, struct iovec *to,
73258 size_t len, struct dma_pinned_list *pinned_list);
73259
73260diff --git a/include/net/netlink.h b/include/net/netlink.h
73261index 9690b0f..87aded7 100644
73262--- a/include/net/netlink.h
73263+++ b/include/net/netlink.h
73264@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73265 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73266 {
73267 if (mark)
73268- skb_trim(skb, (unsigned char *) mark - skb->data);
73269+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73270 }
73271
73272 /**
73273diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73274index c9c0c53..53f24c3 100644
73275--- a/include/net/netns/conntrack.h
73276+++ b/include/net/netns/conntrack.h
73277@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73278 struct nf_proto_net {
73279 #ifdef CONFIG_SYSCTL
73280 struct ctl_table_header *ctl_table_header;
73281- struct ctl_table *ctl_table;
73282+ ctl_table_no_const *ctl_table;
73283 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73284 struct ctl_table_header *ctl_compat_header;
73285- struct ctl_table *ctl_compat_table;
73286+ ctl_table_no_const *ctl_compat_table;
73287 #endif
73288 #endif
73289 unsigned int users;
73290@@ -58,7 +58,7 @@ struct nf_ip_net {
73291 struct nf_icmp_net icmpv6;
73292 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73293 struct ctl_table_header *ctl_table_header;
73294- struct ctl_table *ctl_table;
73295+ ctl_table_no_const *ctl_table;
73296 #endif
73297 };
73298
73299diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73300index 2ba9de8..47bd6c7 100644
73301--- a/include/net/netns/ipv4.h
73302+++ b/include/net/netns/ipv4.h
73303@@ -67,7 +67,7 @@ struct netns_ipv4 {
73304 kgid_t sysctl_ping_group_range[2];
73305 long sysctl_tcp_mem[3];
73306
73307- atomic_t dev_addr_genid;
73308+ atomic_unchecked_t dev_addr_genid;
73309
73310 #ifdef CONFIG_IP_MROUTE
73311 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73312diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
73313index 005e2c2..023d340 100644
73314--- a/include/net/netns/ipv6.h
73315+++ b/include/net/netns/ipv6.h
73316@@ -71,7 +71,7 @@ struct netns_ipv6 {
73317 struct fib_rules_ops *mr6_rules_ops;
73318 #endif
73319 #endif
73320- atomic_t dev_addr_genid;
73321+ atomic_unchecked_t dev_addr_genid;
73322 };
73323
73324 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
73325diff --git a/include/net/protocol.h b/include/net/protocol.h
73326index 047c047..b9dad15 100644
73327--- a/include/net/protocol.h
73328+++ b/include/net/protocol.h
73329@@ -44,7 +44,7 @@ struct net_protocol {
73330 void (*err_handler)(struct sk_buff *skb, u32 info);
73331 unsigned int no_policy:1,
73332 netns_ok:1;
73333-};
73334+} __do_const;
73335
73336 #if IS_ENABLED(CONFIG_IPV6)
73337 struct inet6_protocol {
73338@@ -57,7 +57,7 @@ struct inet6_protocol {
73339 u8 type, u8 code, int offset,
73340 __be32 info);
73341 unsigned int flags; /* INET6_PROTO_xxx */
73342-};
73343+} __do_const;
73344
73345 #define INET6_PROTO_NOPOLICY 0x1
73346 #define INET6_PROTO_FINAL 0x2
73347diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73348index 7026648..584cc8c 100644
73349--- a/include/net/rtnetlink.h
73350+++ b/include/net/rtnetlink.h
73351@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73352 const struct net_device *dev);
73353 unsigned int (*get_num_tx_queues)(void);
73354 unsigned int (*get_num_rx_queues)(void);
73355-};
73356+} __do_const;
73357
73358 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73359 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73360diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73361index cd89510..d67810f 100644
73362--- a/include/net/sctp/sctp.h
73363+++ b/include/net/sctp/sctp.h
73364@@ -330,9 +330,9 @@ do { \
73365
73366 #else /* SCTP_DEBUG */
73367
73368-#define SCTP_DEBUG_PRINTK(whatever...)
73369-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73370-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73371+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73372+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73373+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73374 #define SCTP_ENABLE_DEBUG
73375 #define SCTP_DISABLE_DEBUG
73376 #define SCTP_ASSERT(expr, str, func)
73377diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73378index 2a82d13..62a31c2 100644
73379--- a/include/net/sctp/sm.h
73380+++ b/include/net/sctp/sm.h
73381@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73382 typedef struct {
73383 sctp_state_fn_t *fn;
73384 const char *name;
73385-} sctp_sm_table_entry_t;
73386+} __do_const sctp_sm_table_entry_t;
73387
73388 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73389 * currently in use.
73390@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73391 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73392
73393 /* Extern declarations for major data structures. */
73394-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73395+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73396
73397
73398 /* Get the size of a DATA chunk payload. */
73399diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73400index 1bd4c41..9250b5b 100644
73401--- a/include/net/sctp/structs.h
73402+++ b/include/net/sctp/structs.h
73403@@ -516,7 +516,7 @@ struct sctp_pf {
73404 struct sctp_association *asoc);
73405 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73406 struct sctp_af *af;
73407-};
73408+} __do_const;
73409
73410
73411 /* Structure to track chunk fragments that have been acked, but peer
73412diff --git a/include/net/sock.h b/include/net/sock.h
73413index 66772cf..25bc45b 100644
73414--- a/include/net/sock.h
73415+++ b/include/net/sock.h
73416@@ -325,7 +325,7 @@ struct sock {
73417 #ifdef CONFIG_RPS
73418 __u32 sk_rxhash;
73419 #endif
73420- atomic_t sk_drops;
73421+ atomic_unchecked_t sk_drops;
73422 int sk_rcvbuf;
73423
73424 struct sk_filter __rcu *sk_filter;
73425@@ -1797,7 +1797,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73426 }
73427
73428 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73429- char __user *from, char *to,
73430+ char __user *from, unsigned char *to,
73431 int copy, int offset)
73432 {
73433 if (skb->ip_summed == CHECKSUM_NONE) {
73434@@ -2056,7 +2056,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73435 }
73436 }
73437
73438-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73439+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73440
73441 /**
73442 * sk_page_frag - return an appropriate page_frag
73443diff --git a/include/net/tcp.h b/include/net/tcp.h
73444index 5bba80f..8520a82 100644
73445--- a/include/net/tcp.h
73446+++ b/include/net/tcp.h
73447@@ -524,7 +524,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73448 extern void tcp_xmit_retransmit_queue(struct sock *);
73449 extern void tcp_simple_retransmit(struct sock *);
73450 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73451-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73452+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73453
73454 extern void tcp_send_probe0(struct sock *);
73455 extern void tcp_send_partial(struct sock *);
73456@@ -697,8 +697,8 @@ struct tcp_skb_cb {
73457 struct inet6_skb_parm h6;
73458 #endif
73459 } header; /* For incoming frames */
73460- __u32 seq; /* Starting sequence number */
73461- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73462+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73463+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73464 __u32 when; /* used to compute rtt's */
73465 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73466
73467@@ -712,7 +712,7 @@ struct tcp_skb_cb {
73468
73469 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73470 /* 1 byte hole */
73471- __u32 ack_seq; /* Sequence number ACK'd */
73472+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73473 };
73474
73475 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73476diff --git a/include/net/udp.h b/include/net/udp.h
73477index 065f379..ad99eed 100644
73478--- a/include/net/udp.h
73479+++ b/include/net/udp.h
73480@@ -181,6 +181,7 @@ extern int udp_get_port(struct sock *sk, unsigned short snum,
73481 extern void udp_err(struct sk_buff *, u32);
73482 extern int udp_sendmsg(struct kiocb *iocb, struct sock *sk,
73483 struct msghdr *msg, size_t len);
73484+extern int udp_push_pending_frames(struct sock *sk);
73485 extern void udp_flush_pending_frames(struct sock *sk);
73486 extern int udp_rcv(struct sk_buff *skb);
73487 extern int udp_ioctl(struct sock *sk, int cmd, unsigned long arg);
73488diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73489index 94ce082..62b278d 100644
73490--- a/include/net/xfrm.h
73491+++ b/include/net/xfrm.h
73492@@ -305,7 +305,7 @@ struct xfrm_policy_afinfo {
73493 struct net_device *dev,
73494 const struct flowi *fl);
73495 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73496-};
73497+} __do_const;
73498
73499 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73500 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73501@@ -341,7 +341,7 @@ struct xfrm_state_afinfo {
73502 struct sk_buff *skb);
73503 int (*transport_finish)(struct sk_buff *skb,
73504 int async);
73505-};
73506+} __do_const;
73507
73508 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73509 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73510@@ -424,7 +424,7 @@ struct xfrm_mode {
73511 struct module *owner;
73512 unsigned int encap;
73513 int flags;
73514-};
73515+} __do_const;
73516
73517 /* Flags for xfrm_mode. */
73518 enum {
73519@@ -521,7 +521,7 @@ struct xfrm_policy {
73520 struct timer_list timer;
73521
73522 struct flow_cache_object flo;
73523- atomic_t genid;
73524+ atomic_unchecked_t genid;
73525 u32 priority;
73526 u32 index;
73527 struct xfrm_mark mark;
73528diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73529index 1a046b1..ee0bef0 100644
73530--- a/include/rdma/iw_cm.h
73531+++ b/include/rdma/iw_cm.h
73532@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73533 int backlog);
73534
73535 int (*destroy_listen)(struct iw_cm_id *cm_id);
73536-};
73537+} __no_const;
73538
73539 /**
73540 * iw_create_cm_id - Create an IW CM identifier.
73541diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73542index e1379b4..67eafbe 100644
73543--- a/include/scsi/libfc.h
73544+++ b/include/scsi/libfc.h
73545@@ -762,6 +762,7 @@ struct libfc_function_template {
73546 */
73547 void (*disc_stop_final) (struct fc_lport *);
73548 };
73549+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73550
73551 /**
73552 * struct fc_disc - Discovery context
73553@@ -866,7 +867,7 @@ struct fc_lport {
73554 struct fc_vport *vport;
73555
73556 /* Operational Information */
73557- struct libfc_function_template tt;
73558+ libfc_function_template_no_const tt;
73559 u8 link_up;
73560 u8 qfull;
73561 enum fc_lport_state state;
73562diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73563index cc64587..608f523 100644
73564--- a/include/scsi/scsi_device.h
73565+++ b/include/scsi/scsi_device.h
73566@@ -171,9 +171,9 @@ struct scsi_device {
73567 unsigned int max_device_blocked; /* what device_blocked counts down from */
73568 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73569
73570- atomic_t iorequest_cnt;
73571- atomic_t iodone_cnt;
73572- atomic_t ioerr_cnt;
73573+ atomic_unchecked_t iorequest_cnt;
73574+ atomic_unchecked_t iodone_cnt;
73575+ atomic_unchecked_t ioerr_cnt;
73576
73577 struct device sdev_gendev,
73578 sdev_dev;
73579diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73580index b797e8f..8e2c3aa 100644
73581--- a/include/scsi/scsi_transport_fc.h
73582+++ b/include/scsi/scsi_transport_fc.h
73583@@ -751,7 +751,8 @@ struct fc_function_template {
73584 unsigned long show_host_system_hostname:1;
73585
73586 unsigned long disable_target_scan:1;
73587-};
73588+} __do_const;
73589+typedef struct fc_function_template __no_const fc_function_template_no_const;
73590
73591
73592 /**
73593diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
73594index 9031a26..750d592 100644
73595--- a/include/sound/compress_driver.h
73596+++ b/include/sound/compress_driver.h
73597@@ -128,7 +128,7 @@ struct snd_compr_ops {
73598 struct snd_compr_caps *caps);
73599 int (*get_codec_caps) (struct snd_compr_stream *stream,
73600 struct snd_compr_codec_caps *codec);
73601-};
73602+} __no_const;
73603
73604 /**
73605 * struct snd_compr: Compressed device
73606diff --git a/include/sound/soc.h b/include/sound/soc.h
73607index 85c1522..f44bad1 100644
73608--- a/include/sound/soc.h
73609+++ b/include/sound/soc.h
73610@@ -781,7 +781,7 @@ struct snd_soc_codec_driver {
73611 /* probe ordering - for components with runtime dependencies */
73612 int probe_order;
73613 int remove_order;
73614-};
73615+} __do_const;
73616
73617 /* SoC platform interface */
73618 struct snd_soc_platform_driver {
73619@@ -827,7 +827,7 @@ struct snd_soc_platform_driver {
73620 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73621 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73622 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73623-};
73624+} __do_const;
73625
73626 struct snd_soc_platform {
73627 const char *name;
73628diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73629index 4ea4f98..a63629b 100644
73630--- a/include/target/target_core_base.h
73631+++ b/include/target/target_core_base.h
73632@@ -653,7 +653,7 @@ struct se_device {
73633 spinlock_t stats_lock;
73634 /* Active commands on this virtual SE device */
73635 atomic_t simple_cmds;
73636- atomic_t dev_ordered_id;
73637+ atomic_unchecked_t dev_ordered_id;
73638 atomic_t dev_ordered_sync;
73639 atomic_t dev_qf_count;
73640 int export_count;
73641diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73642new file mode 100644
73643index 0000000..fb634b7
73644--- /dev/null
73645+++ b/include/trace/events/fs.h
73646@@ -0,0 +1,53 @@
73647+#undef TRACE_SYSTEM
73648+#define TRACE_SYSTEM fs
73649+
73650+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73651+#define _TRACE_FS_H
73652+
73653+#include <linux/fs.h>
73654+#include <linux/tracepoint.h>
73655+
73656+TRACE_EVENT(do_sys_open,
73657+
73658+ TP_PROTO(const char *filename, int flags, int mode),
73659+
73660+ TP_ARGS(filename, flags, mode),
73661+
73662+ TP_STRUCT__entry(
73663+ __string( filename, filename )
73664+ __field( int, flags )
73665+ __field( int, mode )
73666+ ),
73667+
73668+ TP_fast_assign(
73669+ __assign_str(filename, filename);
73670+ __entry->flags = flags;
73671+ __entry->mode = mode;
73672+ ),
73673+
73674+ TP_printk("\"%s\" %x %o",
73675+ __get_str(filename), __entry->flags, __entry->mode)
73676+);
73677+
73678+TRACE_EVENT(open_exec,
73679+
73680+ TP_PROTO(const char *filename),
73681+
73682+ TP_ARGS(filename),
73683+
73684+ TP_STRUCT__entry(
73685+ __string( filename, filename )
73686+ ),
73687+
73688+ TP_fast_assign(
73689+ __assign_str(filename, filename);
73690+ ),
73691+
73692+ TP_printk("\"%s\"",
73693+ __get_str(filename))
73694+);
73695+
73696+#endif /* _TRACE_FS_H */
73697+
73698+/* This part must be outside protection */
73699+#include <trace/define_trace.h>
73700diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73701index 1c09820..7f5ec79 100644
73702--- a/include/trace/events/irq.h
73703+++ b/include/trace/events/irq.h
73704@@ -36,7 +36,7 @@ struct softirq_action;
73705 */
73706 TRACE_EVENT(irq_handler_entry,
73707
73708- TP_PROTO(int irq, struct irqaction *action),
73709+ TP_PROTO(int irq, const struct irqaction *action),
73710
73711 TP_ARGS(irq, action),
73712
73713@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73714 */
73715 TRACE_EVENT(irq_handler_exit,
73716
73717- TP_PROTO(int irq, struct irqaction *action, int ret),
73718+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73719
73720 TP_ARGS(irq, action, ret),
73721
73722diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73723index 7caf44c..23c6f27 100644
73724--- a/include/uapi/linux/a.out.h
73725+++ b/include/uapi/linux/a.out.h
73726@@ -39,6 +39,14 @@ enum machine_type {
73727 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73728 };
73729
73730+/* Constants for the N_FLAGS field */
73731+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73732+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73733+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73734+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73735+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73736+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73737+
73738 #if !defined (N_MAGIC)
73739 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73740 #endif
73741diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73742index d876736..ccce5c0 100644
73743--- a/include/uapi/linux/byteorder/little_endian.h
73744+++ b/include/uapi/linux/byteorder/little_endian.h
73745@@ -42,51 +42,51 @@
73746
73747 static inline __le64 __cpu_to_le64p(const __u64 *p)
73748 {
73749- return (__force __le64)*p;
73750+ return (__force const __le64)*p;
73751 }
73752-static inline __u64 __le64_to_cpup(const __le64 *p)
73753+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73754 {
73755- return (__force __u64)*p;
73756+ return (__force const __u64)*p;
73757 }
73758 static inline __le32 __cpu_to_le32p(const __u32 *p)
73759 {
73760- return (__force __le32)*p;
73761+ return (__force const __le32)*p;
73762 }
73763 static inline __u32 __le32_to_cpup(const __le32 *p)
73764 {
73765- return (__force __u32)*p;
73766+ return (__force const __u32)*p;
73767 }
73768 static inline __le16 __cpu_to_le16p(const __u16 *p)
73769 {
73770- return (__force __le16)*p;
73771+ return (__force const __le16)*p;
73772 }
73773 static inline __u16 __le16_to_cpup(const __le16 *p)
73774 {
73775- return (__force __u16)*p;
73776+ return (__force const __u16)*p;
73777 }
73778 static inline __be64 __cpu_to_be64p(const __u64 *p)
73779 {
73780- return (__force __be64)__swab64p(p);
73781+ return (__force const __be64)__swab64p(p);
73782 }
73783 static inline __u64 __be64_to_cpup(const __be64 *p)
73784 {
73785- return __swab64p((__u64 *)p);
73786+ return __swab64p((const __u64 *)p);
73787 }
73788 static inline __be32 __cpu_to_be32p(const __u32 *p)
73789 {
73790- return (__force __be32)__swab32p(p);
73791+ return (__force const __be32)__swab32p(p);
73792 }
73793-static inline __u32 __be32_to_cpup(const __be32 *p)
73794+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73795 {
73796- return __swab32p((__u32 *)p);
73797+ return __swab32p((const __u32 *)p);
73798 }
73799 static inline __be16 __cpu_to_be16p(const __u16 *p)
73800 {
73801- return (__force __be16)__swab16p(p);
73802+ return (__force const __be16)__swab16p(p);
73803 }
73804 static inline __u16 __be16_to_cpup(const __be16 *p)
73805 {
73806- return __swab16p((__u16 *)p);
73807+ return __swab16p((const __u16 *)p);
73808 }
73809 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73810 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73811diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73812index ef6103b..d4e65dd 100644
73813--- a/include/uapi/linux/elf.h
73814+++ b/include/uapi/linux/elf.h
73815@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73816 #define PT_GNU_EH_FRAME 0x6474e550
73817
73818 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73819+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73820+
73821+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73822+
73823+/* Constants for the e_flags field */
73824+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73825+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73826+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73827+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73828+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73829+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73830
73831 /*
73832 * Extended Numbering
73833@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73834 #define DT_DEBUG 21
73835 #define DT_TEXTREL 22
73836 #define DT_JMPREL 23
73837+#define DT_FLAGS 30
73838+ #define DF_TEXTREL 0x00000004
73839 #define DT_ENCODING 32
73840 #define OLD_DT_LOOS 0x60000000
73841 #define DT_LOOS 0x6000000d
73842@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73843 #define PF_W 0x2
73844 #define PF_X 0x1
73845
73846+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73847+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73848+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73849+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73850+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73851+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73852+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73853+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73854+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73855+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73856+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73857+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73858+
73859 typedef struct elf32_phdr{
73860 Elf32_Word p_type;
73861 Elf32_Off p_offset;
73862@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73863 #define EI_OSABI 7
73864 #define EI_PAD 8
73865
73866+#define EI_PAX 14
73867+
73868 #define ELFMAG0 0x7f /* EI_MAG */
73869 #define ELFMAG1 'E'
73870 #define ELFMAG2 'L'
73871diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73872index aa169c4..6a2771d 100644
73873--- a/include/uapi/linux/personality.h
73874+++ b/include/uapi/linux/personality.h
73875@@ -30,6 +30,7 @@ enum {
73876 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73877 ADDR_NO_RANDOMIZE | \
73878 ADDR_COMPAT_LAYOUT | \
73879+ ADDR_LIMIT_3GB | \
73880 MMAP_PAGE_ZERO)
73881
73882 /*
73883diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73884index 7530e74..e714828 100644
73885--- a/include/uapi/linux/screen_info.h
73886+++ b/include/uapi/linux/screen_info.h
73887@@ -43,7 +43,8 @@ struct screen_info {
73888 __u16 pages; /* 0x32 */
73889 __u16 vesa_attributes; /* 0x34 */
73890 __u32 capabilities; /* 0x36 */
73891- __u8 _reserved[6]; /* 0x3a */
73892+ __u16 vesapm_size; /* 0x3a */
73893+ __u8 _reserved[4]; /* 0x3c */
73894 } __attribute__((packed));
73895
73896 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73897diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73898index 0e011eb..82681b1 100644
73899--- a/include/uapi/linux/swab.h
73900+++ b/include/uapi/linux/swab.h
73901@@ -43,7 +43,7 @@
73902 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73903 */
73904
73905-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73906+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73907 {
73908 #ifdef __HAVE_BUILTIN_BSWAP16__
73909 return __builtin_bswap16(val);
73910@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73911 #endif
73912 }
73913
73914-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73915+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73916 {
73917 #ifdef __HAVE_BUILTIN_BSWAP32__
73918 return __builtin_bswap32(val);
73919@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73920 #endif
73921 }
73922
73923-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73924+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73925 {
73926 #ifdef __HAVE_BUILTIN_BSWAP64__
73927 return __builtin_bswap64(val);
73928diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73929index 6d67213..8dab561 100644
73930--- a/include/uapi/linux/sysctl.h
73931+++ b/include/uapi/linux/sysctl.h
73932@@ -155,7 +155,11 @@ enum
73933 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73934 };
73935
73936-
73937+#ifdef CONFIG_PAX_SOFTMODE
73938+enum {
73939+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73940+};
73941+#endif
73942
73943 /* CTL_VM names: */
73944 enum
73945diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73946index e4629b9..6958086 100644
73947--- a/include/uapi/linux/xattr.h
73948+++ b/include/uapi/linux/xattr.h
73949@@ -63,5 +63,9 @@
73950 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73951 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73952
73953+/* User namespace */
73954+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73955+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73956+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73957
73958 #endif /* _UAPI_LINUX_XATTR_H */
73959diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73960index f9466fa..f4e2b81 100644
73961--- a/include/video/udlfb.h
73962+++ b/include/video/udlfb.h
73963@@ -53,10 +53,10 @@ struct dlfb_data {
73964 u32 pseudo_palette[256];
73965 int blank_mode; /*one of FB_BLANK_ */
73966 /* blit-only rendering path metrics, exposed through sysfs */
73967- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73968- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73969- atomic_t bytes_sent; /* to usb, after compression including overhead */
73970- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73971+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73972+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73973+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73974+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73975 };
73976
73977 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73978diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73979index 1a91850..28573f8 100644
73980--- a/include/video/uvesafb.h
73981+++ b/include/video/uvesafb.h
73982@@ -122,6 +122,7 @@ struct uvesafb_par {
73983 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73984 u8 pmi_setpal; /* PMI for palette changes */
73985 u16 *pmi_base; /* protected mode interface location */
73986+ u8 *pmi_code; /* protected mode code location */
73987 void *pmi_start;
73988 void *pmi_pal;
73989 u8 *vbe_state_orig; /*
73990diff --git a/init/Kconfig b/init/Kconfig
73991index 2d9b831..ae4c8ac 100644
73992--- a/init/Kconfig
73993+++ b/init/Kconfig
73994@@ -1029,6 +1029,7 @@ endif # CGROUPS
73995
73996 config CHECKPOINT_RESTORE
73997 bool "Checkpoint/restore support" if EXPERT
73998+ depends on !GRKERNSEC
73999 default n
74000 help
74001 Enables additional kernel features in a sake of checkpoint/restore.
74002@@ -1516,7 +1517,7 @@ config SLUB_DEBUG
74003
74004 config COMPAT_BRK
74005 bool "Disable heap randomization"
74006- default y
74007+ default n
74008 help
74009 Randomizing heap placement makes heap exploits harder, but it
74010 also breaks ancient binaries (including anything libc5 based).
74011@@ -1779,7 +1780,7 @@ config INIT_ALL_POSSIBLE
74012 config STOP_MACHINE
74013 bool
74014 default y
74015- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
74016+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
74017 help
74018 Need stop_machine() primitive.
74019
74020diff --git a/init/Makefile b/init/Makefile
74021index 7bc47ee..6da2dc7 100644
74022--- a/init/Makefile
74023+++ b/init/Makefile
74024@@ -2,6 +2,9 @@
74025 # Makefile for the linux kernel.
74026 #
74027
74028+ccflags-y := $(GCC_PLUGINS_CFLAGS)
74029+asflags-y := $(GCC_PLUGINS_AFLAGS)
74030+
74031 obj-y := main.o version.o mounts.o
74032 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
74033 obj-y += noinitramfs.o
74034diff --git a/init/do_mounts.c b/init/do_mounts.c
74035index a2b49f2..03a0e17c 100644
74036--- a/init/do_mounts.c
74037+++ b/init/do_mounts.c
74038@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
74039 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
74040 {
74041 struct super_block *s;
74042- int err = sys_mount(name, "/root", fs, flags, data);
74043+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
74044 if (err)
74045 return err;
74046
74047- sys_chdir("/root");
74048+ sys_chdir((const char __force_user *)"/root");
74049 s = current->fs->pwd.dentry->d_sb;
74050 ROOT_DEV = s->s_dev;
74051 printk(KERN_INFO
74052@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
74053 va_start(args, fmt);
74054 vsprintf(buf, fmt, args);
74055 va_end(args);
74056- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
74057+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
74058 if (fd >= 0) {
74059 sys_ioctl(fd, FDEJECT, 0);
74060 sys_close(fd);
74061 }
74062 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
74063- fd = sys_open("/dev/console", O_RDWR, 0);
74064+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
74065 if (fd >= 0) {
74066 sys_ioctl(fd, TCGETS, (long)&termios);
74067 termios.c_lflag &= ~ICANON;
74068 sys_ioctl(fd, TCSETSF, (long)&termios);
74069- sys_read(fd, &c, 1);
74070+ sys_read(fd, (char __user *)&c, 1);
74071 termios.c_lflag |= ICANON;
74072 sys_ioctl(fd, TCSETSF, (long)&termios);
74073 sys_close(fd);
74074@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
74075 mount_root();
74076 out:
74077 devtmpfs_mount("dev");
74078- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74079- sys_chroot(".");
74080+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74081+ sys_chroot((const char __force_user *)".");
74082 }
74083diff --git a/init/do_mounts.h b/init/do_mounts.h
74084index f5b978a..69dbfe8 100644
74085--- a/init/do_mounts.h
74086+++ b/init/do_mounts.h
74087@@ -15,15 +15,15 @@ extern int root_mountflags;
74088
74089 static inline int create_dev(char *name, dev_t dev)
74090 {
74091- sys_unlink(name);
74092- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
74093+ sys_unlink((char __force_user *)name);
74094+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
74095 }
74096
74097 #if BITS_PER_LONG == 32
74098 static inline u32 bstat(char *name)
74099 {
74100 struct stat64 stat;
74101- if (sys_stat64(name, &stat) != 0)
74102+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
74103 return 0;
74104 if (!S_ISBLK(stat.st_mode))
74105 return 0;
74106@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
74107 static inline u32 bstat(char *name)
74108 {
74109 struct stat stat;
74110- if (sys_newstat(name, &stat) != 0)
74111+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
74112 return 0;
74113 if (!S_ISBLK(stat.st_mode))
74114 return 0;
74115diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
74116index 3e0878e..8a9d7a0 100644
74117--- a/init/do_mounts_initrd.c
74118+++ b/init/do_mounts_initrd.c
74119@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
74120 {
74121 sys_unshare(CLONE_FS | CLONE_FILES);
74122 /* stdin/stdout/stderr for /linuxrc */
74123- sys_open("/dev/console", O_RDWR, 0);
74124+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
74125 sys_dup(0);
74126 sys_dup(0);
74127 /* move initrd over / and chdir/chroot in initrd root */
74128- sys_chdir("/root");
74129- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74130- sys_chroot(".");
74131+ sys_chdir((const char __force_user *)"/root");
74132+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74133+ sys_chroot((const char __force_user *)".");
74134 sys_setsid();
74135 return 0;
74136 }
74137@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
74138 create_dev("/dev/root.old", Root_RAM0);
74139 /* mount initrd on rootfs' /root */
74140 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
74141- sys_mkdir("/old", 0700);
74142- sys_chdir("/old");
74143+ sys_mkdir((const char __force_user *)"/old", 0700);
74144+ sys_chdir((const char __force_user *)"/old");
74145
74146 /* try loading default modules from initrd */
74147 load_default_modules();
74148@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
74149 current->flags &= ~PF_FREEZER_SKIP;
74150
74151 /* move initrd to rootfs' /old */
74152- sys_mount("..", ".", NULL, MS_MOVE, NULL);
74153+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
74154 /* switch root and cwd back to / of rootfs */
74155- sys_chroot("..");
74156+ sys_chroot((const char __force_user *)"..");
74157
74158 if (new_decode_dev(real_root_dev) == Root_RAM0) {
74159- sys_chdir("/old");
74160+ sys_chdir((const char __force_user *)"/old");
74161 return;
74162 }
74163
74164- sys_chdir("/");
74165+ sys_chdir((const char __force_user *)"/");
74166 ROOT_DEV = new_decode_dev(real_root_dev);
74167 mount_root();
74168
74169 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
74170- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
74171+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
74172 if (!error)
74173 printk("okay\n");
74174 else {
74175- int fd = sys_open("/dev/root.old", O_RDWR, 0);
74176+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
74177 if (error == -ENOENT)
74178 printk("/initrd does not exist. Ignored.\n");
74179 else
74180 printk("failed\n");
74181 printk(KERN_NOTICE "Unmounting old root\n");
74182- sys_umount("/old", MNT_DETACH);
74183+ sys_umount((char __force_user *)"/old", MNT_DETACH);
74184 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
74185 if (fd < 0) {
74186 error = fd;
74187@@ -127,11 +127,11 @@ int __init initrd_load(void)
74188 * mounted in the normal path.
74189 */
74190 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
74191- sys_unlink("/initrd.image");
74192+ sys_unlink((const char __force_user *)"/initrd.image");
74193 handle_initrd();
74194 return 1;
74195 }
74196 }
74197- sys_unlink("/initrd.image");
74198+ sys_unlink((const char __force_user *)"/initrd.image");
74199 return 0;
74200 }
74201diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
74202index 8cb6db5..d729f50 100644
74203--- a/init/do_mounts_md.c
74204+++ b/init/do_mounts_md.c
74205@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
74206 partitioned ? "_d" : "", minor,
74207 md_setup_args[ent].device_names);
74208
74209- fd = sys_open(name, 0, 0);
74210+ fd = sys_open((char __force_user *)name, 0, 0);
74211 if (fd < 0) {
74212 printk(KERN_ERR "md: open failed - cannot start "
74213 "array %s\n", name);
74214@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
74215 * array without it
74216 */
74217 sys_close(fd);
74218- fd = sys_open(name, 0, 0);
74219+ fd = sys_open((char __force_user *)name, 0, 0);
74220 sys_ioctl(fd, BLKRRPART, 0);
74221 }
74222 sys_close(fd);
74223@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
74224
74225 wait_for_device_probe();
74226
74227- fd = sys_open("/dev/md0", 0, 0);
74228+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
74229 if (fd >= 0) {
74230 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
74231 sys_close(fd);
74232diff --git a/init/init_task.c b/init/init_task.c
74233index ba0a7f36..2bcf1d5 100644
74234--- a/init/init_task.c
74235+++ b/init/init_task.c
74236@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
74237 * Initial thread structure. Alignment of this is handled by a special
74238 * linker map entry.
74239 */
74240+#ifdef CONFIG_X86
74241+union thread_union init_thread_union __init_task_data;
74242+#else
74243 union thread_union init_thread_union __init_task_data =
74244 { INIT_THREAD_INFO(init_task) };
74245+#endif
74246diff --git a/init/initramfs.c b/init/initramfs.c
74247index a67ef9d..2d17ed9 100644
74248--- a/init/initramfs.c
74249+++ b/init/initramfs.c
74250@@ -84,7 +84,7 @@ static void __init free_hash(void)
74251 }
74252 }
74253
74254-static long __init do_utime(char *filename, time_t mtime)
74255+static long __init do_utime(char __force_user *filename, time_t mtime)
74256 {
74257 struct timespec t[2];
74258
74259@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74260 struct dir_entry *de, *tmp;
74261 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74262 list_del(&de->list);
74263- do_utime(de->name, de->mtime);
74264+ do_utime((char __force_user *)de->name, de->mtime);
74265 kfree(de->name);
74266 kfree(de);
74267 }
74268@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74269 if (nlink >= 2) {
74270 char *old = find_link(major, minor, ino, mode, collected);
74271 if (old)
74272- return (sys_link(old, collected) < 0) ? -1 : 1;
74273+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74274 }
74275 return 0;
74276 }
74277@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74278 {
74279 struct stat st;
74280
74281- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74282+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74283 if (S_ISDIR(st.st_mode))
74284- sys_rmdir(path);
74285+ sys_rmdir((char __force_user *)path);
74286 else
74287- sys_unlink(path);
74288+ sys_unlink((char __force_user *)path);
74289 }
74290 }
74291
74292@@ -315,7 +315,7 @@ static int __init do_name(void)
74293 int openflags = O_WRONLY|O_CREAT;
74294 if (ml != 1)
74295 openflags |= O_TRUNC;
74296- wfd = sys_open(collected, openflags, mode);
74297+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74298
74299 if (wfd >= 0) {
74300 sys_fchown(wfd, uid, gid);
74301@@ -327,17 +327,17 @@ static int __init do_name(void)
74302 }
74303 }
74304 } else if (S_ISDIR(mode)) {
74305- sys_mkdir(collected, mode);
74306- sys_chown(collected, uid, gid);
74307- sys_chmod(collected, mode);
74308+ sys_mkdir((char __force_user *)collected, mode);
74309+ sys_chown((char __force_user *)collected, uid, gid);
74310+ sys_chmod((char __force_user *)collected, mode);
74311 dir_add(collected, mtime);
74312 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74313 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74314 if (maybe_link() == 0) {
74315- sys_mknod(collected, mode, rdev);
74316- sys_chown(collected, uid, gid);
74317- sys_chmod(collected, mode);
74318- do_utime(collected, mtime);
74319+ sys_mknod((char __force_user *)collected, mode, rdev);
74320+ sys_chown((char __force_user *)collected, uid, gid);
74321+ sys_chmod((char __force_user *)collected, mode);
74322+ do_utime((char __force_user *)collected, mtime);
74323 }
74324 }
74325 return 0;
74326@@ -346,15 +346,15 @@ static int __init do_name(void)
74327 static int __init do_copy(void)
74328 {
74329 if (count >= body_len) {
74330- sys_write(wfd, victim, body_len);
74331+ sys_write(wfd, (char __force_user *)victim, body_len);
74332 sys_close(wfd);
74333- do_utime(vcollected, mtime);
74334+ do_utime((char __force_user *)vcollected, mtime);
74335 kfree(vcollected);
74336 eat(body_len);
74337 state = SkipIt;
74338 return 0;
74339 } else {
74340- sys_write(wfd, victim, count);
74341+ sys_write(wfd, (char __force_user *)victim, count);
74342 body_len -= count;
74343 eat(count);
74344 return 1;
74345@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74346 {
74347 collected[N_ALIGN(name_len) + body_len] = '\0';
74348 clean_path(collected, 0);
74349- sys_symlink(collected + N_ALIGN(name_len), collected);
74350- sys_lchown(collected, uid, gid);
74351- do_utime(collected, mtime);
74352+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74353+ sys_lchown((char __force_user *)collected, uid, gid);
74354+ do_utime((char __force_user *)collected, mtime);
74355 state = SkipIt;
74356 next_state = Reset;
74357 return 0;
74358@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
74359 {
74360 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
74361 if (err)
74362- panic(err); /* Failed to decompress INTERNAL initramfs */
74363+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
74364 if (initrd_start) {
74365 #ifdef CONFIG_BLK_DEV_RAM
74366 int fd;
74367diff --git a/init/main.c b/init/main.c
74368index 9484f4b..4c01430 100644
74369--- a/init/main.c
74370+++ b/init/main.c
74371@@ -100,6 +100,8 @@ static inline void mark_rodata_ro(void) { }
74372 extern void tc_init(void);
74373 #endif
74374
74375+extern void grsecurity_init(void);
74376+
74377 /*
74378 * Debug helper: via this flag we know that we are in 'early bootup code'
74379 * where only the boot processor is running with IRQ disabled. This means
74380@@ -153,6 +155,64 @@ static int __init set_reset_devices(char *str)
74381
74382 __setup("reset_devices", set_reset_devices);
74383
74384+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74385+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74386+static int __init setup_grsec_proc_gid(char *str)
74387+{
74388+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74389+ return 1;
74390+}
74391+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74392+#endif
74393+
74394+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74395+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
74396+EXPORT_SYMBOL(pax_user_shadow_base);
74397+extern char pax_enter_kernel_user[];
74398+extern char pax_exit_kernel_user[];
74399+extern pgdval_t clone_pgd_mask;
74400+#endif
74401+
74402+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74403+static int __init setup_pax_nouderef(char *str)
74404+{
74405+#ifdef CONFIG_X86_32
74406+ unsigned int cpu;
74407+ struct desc_struct *gdt;
74408+
74409+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74410+ gdt = get_cpu_gdt_table(cpu);
74411+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74412+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74413+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74414+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74415+ }
74416+ loadsegment(ds, __KERNEL_DS);
74417+ loadsegment(es, __KERNEL_DS);
74418+ loadsegment(ss, __KERNEL_DS);
74419+#else
74420+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74421+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74422+ clone_pgd_mask = ~(pgdval_t)0UL;
74423+ pax_user_shadow_base = 0UL;
74424+#endif
74425+
74426+ return 0;
74427+}
74428+early_param("pax_nouderef", setup_pax_nouderef);
74429+#endif
74430+
74431+#ifdef CONFIG_PAX_SOFTMODE
74432+int pax_softmode;
74433+
74434+static int __init setup_pax_softmode(char *str)
74435+{
74436+ get_option(&str, &pax_softmode);
74437+ return 1;
74438+}
74439+__setup("pax_softmode=", setup_pax_softmode);
74440+#endif
74441+
74442 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74443 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74444 static const char *panic_later, *panic_param;
74445@@ -655,8 +715,6 @@ static void __init do_ctors(void)
74446 bool initcall_debug;
74447 core_param(initcall_debug, initcall_debug, bool, 0644);
74448
74449-static char msgbuf[64];
74450-
74451 static int __init_or_module do_one_initcall_debug(initcall_t fn)
74452 {
74453 ktime_t calltime, delta, rettime;
74454@@ -679,23 +737,22 @@ int __init_or_module do_one_initcall(initcall_t fn)
74455 {
74456 int count = preempt_count();
74457 int ret;
74458+ const char *msg1 = "", *msg2 = "";
74459
74460 if (initcall_debug)
74461 ret = do_one_initcall_debug(fn);
74462 else
74463 ret = fn();
74464
74465- msgbuf[0] = 0;
74466-
74467 if (preempt_count() != count) {
74468- sprintf(msgbuf, "preemption imbalance ");
74469+ msg1 = " preemption imbalance";
74470 preempt_count() = count;
74471 }
74472 if (irqs_disabled()) {
74473- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74474+ msg2 = " disabled interrupts";
74475 local_irq_enable();
74476 }
74477- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
74478+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
74479
74480 return ret;
74481 }
74482@@ -748,8 +805,14 @@ static void __init do_initcall_level(int level)
74483 level, level,
74484 &repair_env_string);
74485
74486- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74487+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74488 do_one_initcall(*fn);
74489+
74490+#ifdef LATENT_ENTROPY_PLUGIN
74491+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74492+#endif
74493+
74494+ }
74495 }
74496
74497 static void __init do_initcalls(void)
74498@@ -783,8 +846,14 @@ static void __init do_pre_smp_initcalls(void)
74499 {
74500 initcall_t *fn;
74501
74502- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74503+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74504 do_one_initcall(*fn);
74505+
74506+#ifdef LATENT_ENTROPY_PLUGIN
74507+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74508+#endif
74509+
74510+ }
74511 }
74512
74513 /*
74514@@ -802,8 +871,8 @@ static int run_init_process(const char *init_filename)
74515 {
74516 argv_init[0] = init_filename;
74517 return do_execve(init_filename,
74518- (const char __user *const __user *)argv_init,
74519- (const char __user *const __user *)envp_init);
74520+ (const char __user *const __force_user *)argv_init,
74521+ (const char __user *const __force_user *)envp_init);
74522 }
74523
74524 static noinline void __init kernel_init_freeable(void);
74525@@ -880,7 +949,7 @@ static noinline void __init kernel_init_freeable(void)
74526 do_basic_setup();
74527
74528 /* Open the /dev/console on the rootfs, this should never fail */
74529- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74530+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74531 pr_err("Warning: unable to open an initial console.\n");
74532
74533 (void) sys_dup(0);
74534@@ -893,11 +962,13 @@ static noinline void __init kernel_init_freeable(void)
74535 if (!ramdisk_execute_command)
74536 ramdisk_execute_command = "/init";
74537
74538- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74539+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74540 ramdisk_execute_command = NULL;
74541 prepare_namespace();
74542 }
74543
74544+ grsecurity_init();
74545+
74546 /*
74547 * Ok, we have completed the initial bootup, and
74548 * we're essentially up and running. Get rid of the
74549diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74550index 130dfec..cc88451 100644
74551--- a/ipc/ipc_sysctl.c
74552+++ b/ipc/ipc_sysctl.c
74553@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74554 static int proc_ipc_dointvec(ctl_table *table, int write,
74555 void __user *buffer, size_t *lenp, loff_t *ppos)
74556 {
74557- struct ctl_table ipc_table;
74558+ ctl_table_no_const ipc_table;
74559
74560 memcpy(&ipc_table, table, sizeof(ipc_table));
74561 ipc_table.data = get_ipc(table);
74562@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74563 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74564 void __user *buffer, size_t *lenp, loff_t *ppos)
74565 {
74566- struct ctl_table ipc_table;
74567+ ctl_table_no_const ipc_table;
74568
74569 memcpy(&ipc_table, table, sizeof(ipc_table));
74570 ipc_table.data = get_ipc(table);
74571@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74572 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74573 void __user *buffer, size_t *lenp, loff_t *ppos)
74574 {
74575- struct ctl_table ipc_table;
74576+ ctl_table_no_const ipc_table;
74577 size_t lenp_bef = *lenp;
74578 int rc;
74579
74580@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74581 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74582 void __user *buffer, size_t *lenp, loff_t *ppos)
74583 {
74584- struct ctl_table ipc_table;
74585+ ctl_table_no_const ipc_table;
74586 memcpy(&ipc_table, table, sizeof(ipc_table));
74587 ipc_table.data = get_ipc(table);
74588
74589@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74590 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74591 void __user *buffer, size_t *lenp, loff_t *ppos)
74592 {
74593- struct ctl_table ipc_table;
74594+ ctl_table_no_const ipc_table;
74595 size_t lenp_bef = *lenp;
74596 int oldval;
74597 int rc;
74598diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74599index 383d638..943fdbb 100644
74600--- a/ipc/mq_sysctl.c
74601+++ b/ipc/mq_sysctl.c
74602@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74603 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74604 void __user *buffer, size_t *lenp, loff_t *ppos)
74605 {
74606- struct ctl_table mq_table;
74607+ ctl_table_no_const mq_table;
74608 memcpy(&mq_table, table, sizeof(mq_table));
74609 mq_table.data = get_mq(table);
74610
74611diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74612index e4e47f6..a85e0ad 100644
74613--- a/ipc/mqueue.c
74614+++ b/ipc/mqueue.c
74615@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74616 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74617 info->attr.mq_msgsize);
74618
74619+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74620 spin_lock(&mq_lock);
74621 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74622 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74623diff --git a/ipc/msg.c b/ipc/msg.c
74624index d0c6d96..69a893c 100644
74625--- a/ipc/msg.c
74626+++ b/ipc/msg.c
74627@@ -296,18 +296,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74628 return security_msg_queue_associate(msq, msgflg);
74629 }
74630
74631+static struct ipc_ops msg_ops = {
74632+ .getnew = newque,
74633+ .associate = msg_security,
74634+ .more_checks = NULL
74635+};
74636+
74637 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74638 {
74639 struct ipc_namespace *ns;
74640- struct ipc_ops msg_ops;
74641 struct ipc_params msg_params;
74642
74643 ns = current->nsproxy->ipc_ns;
74644
74645- msg_ops.getnew = newque;
74646- msg_ops.associate = msg_security;
74647- msg_ops.more_checks = NULL;
74648-
74649 msg_params.key = key;
74650 msg_params.flg = msgflg;
74651
74652diff --git a/ipc/sem.c b/ipc/sem.c
74653index 70480a3..f4e8262 100644
74654--- a/ipc/sem.c
74655+++ b/ipc/sem.c
74656@@ -460,10 +460,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74657 return 0;
74658 }
74659
74660+static struct ipc_ops sem_ops = {
74661+ .getnew = newary,
74662+ .associate = sem_security,
74663+ .more_checks = sem_more_checks
74664+};
74665+
74666 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74667 {
74668 struct ipc_namespace *ns;
74669- struct ipc_ops sem_ops;
74670 struct ipc_params sem_params;
74671
74672 ns = current->nsproxy->ipc_ns;
74673@@ -471,10 +476,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74674 if (nsems < 0 || nsems > ns->sc_semmsl)
74675 return -EINVAL;
74676
74677- sem_ops.getnew = newary;
74678- sem_ops.associate = sem_security;
74679- sem_ops.more_checks = sem_more_checks;
74680-
74681 sem_params.key = key;
74682 sem_params.flg = semflg;
74683 sem_params.u.nsems = nsems;
74684diff --git a/ipc/shm.c b/ipc/shm.c
74685index 7e199fa..180a1ca 100644
74686--- a/ipc/shm.c
74687+++ b/ipc/shm.c
74688@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74689 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74690 #endif
74691
74692+#ifdef CONFIG_GRKERNSEC
74693+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74694+ const time_t shm_createtime, const kuid_t cuid,
74695+ const int shmid);
74696+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74697+ const time_t shm_createtime);
74698+#endif
74699+
74700 void shm_init_ns(struct ipc_namespace *ns)
74701 {
74702 ns->shm_ctlmax = SHMMAX;
74703@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74704 shp->shm_lprid = 0;
74705 shp->shm_atim = shp->shm_dtim = 0;
74706 shp->shm_ctim = get_seconds();
74707+#ifdef CONFIG_GRKERNSEC
74708+ {
74709+ struct timespec timeval;
74710+ do_posix_clock_monotonic_gettime(&timeval);
74711+
74712+ shp->shm_createtime = timeval.tv_sec;
74713+ }
74714+#endif
74715 shp->shm_segsz = size;
74716 shp->shm_nattch = 0;
74717 shp->shm_file = file;
74718@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74719 return 0;
74720 }
74721
74722+static struct ipc_ops shm_ops = {
74723+ .getnew = newseg,
74724+ .associate = shm_security,
74725+ .more_checks = shm_more_checks
74726+};
74727+
74728 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74729 {
74730 struct ipc_namespace *ns;
74731- struct ipc_ops shm_ops;
74732 struct ipc_params shm_params;
74733
74734 ns = current->nsproxy->ipc_ns;
74735
74736- shm_ops.getnew = newseg;
74737- shm_ops.associate = shm_security;
74738- shm_ops.more_checks = shm_more_checks;
74739-
74740 shm_params.key = key;
74741 shm_params.flg = shmflg;
74742 shm_params.u.size = size;
74743@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74744 f_mode = FMODE_READ | FMODE_WRITE;
74745 }
74746 if (shmflg & SHM_EXEC) {
74747+
74748+#ifdef CONFIG_PAX_MPROTECT
74749+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74750+ goto out;
74751+#endif
74752+
74753 prot |= PROT_EXEC;
74754 acc_mode |= S_IXUGO;
74755 }
74756@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74757 if (err)
74758 goto out_unlock;
74759
74760+#ifdef CONFIG_GRKERNSEC
74761+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74762+ shp->shm_perm.cuid, shmid) ||
74763+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74764+ err = -EACCES;
74765+ goto out_unlock;
74766+ }
74767+#endif
74768+
74769 path = shp->shm_file->f_path;
74770 path_get(&path);
74771 shp->shm_nattch++;
74772+#ifdef CONFIG_GRKERNSEC
74773+ shp->shm_lapid = current->pid;
74774+#endif
74775 size = i_size_read(path.dentry->d_inode);
74776 shm_unlock(shp);
74777
74778diff --git a/kernel/acct.c b/kernel/acct.c
74779index 8d6e145..33e0b1e 100644
74780--- a/kernel/acct.c
74781+++ b/kernel/acct.c
74782@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74783 */
74784 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74785 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74786- file->f_op->write(file, (char *)&ac,
74787+ file->f_op->write(file, (char __force_user *)&ac,
74788 sizeof(acct_t), &file->f_pos);
74789 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74790 set_fs(fs);
74791diff --git a/kernel/audit.c b/kernel/audit.c
74792index 91e53d0..d9e3ec4 100644
74793--- a/kernel/audit.c
74794+++ b/kernel/audit.c
74795@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
74796 3) suppressed due to audit_rate_limit
74797 4) suppressed due to audit_backlog_limit
74798 */
74799-static atomic_t audit_lost = ATOMIC_INIT(0);
74800+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74801
74802 /* The netlink socket. */
74803 static struct sock *audit_sock;
74804@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
74805 unsigned long now;
74806 int print;
74807
74808- atomic_inc(&audit_lost);
74809+ atomic_inc_unchecked(&audit_lost);
74810
74811 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74812
74813@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
74814 printk(KERN_WARNING
74815 "audit: audit_lost=%d audit_rate_limit=%d "
74816 "audit_backlog_limit=%d\n",
74817- atomic_read(&audit_lost),
74818+ atomic_read_unchecked(&audit_lost),
74819 audit_rate_limit,
74820 audit_backlog_limit);
74821 audit_panic(message);
74822@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74823 status_set.pid = audit_pid;
74824 status_set.rate_limit = audit_rate_limit;
74825 status_set.backlog_limit = audit_backlog_limit;
74826- status_set.lost = atomic_read(&audit_lost);
74827+ status_set.lost = atomic_read_unchecked(&audit_lost);
74828 status_set.backlog = skb_queue_len(&audit_skb_queue);
74829 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74830 &status_set, sizeof(status_set));
74831diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
74832index 6bd4a90..0ee9eff 100644
74833--- a/kernel/auditfilter.c
74834+++ b/kernel/auditfilter.c
74835@@ -423,7 +423,7 @@ static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
74836 f->lsm_rule = NULL;
74837
74838 /* Support legacy tests for a valid loginuid */
74839- if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295)) {
74840+ if ((f->type == AUDIT_LOGINUID) && (f->val == 4294967295U)) {
74841 f->type = AUDIT_LOGINUID_SET;
74842 f->val = 0;
74843 }
74844diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74845index 3c8a601..3a416f6 100644
74846--- a/kernel/auditsc.c
74847+++ b/kernel/auditsc.c
74848@@ -1956,7 +1956,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74849 }
74850
74851 /* global counter which is incremented every time something logs in */
74852-static atomic_t session_id = ATOMIC_INIT(0);
74853+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74854
74855 /**
74856 * audit_set_loginuid - set current task's audit_context loginuid
74857@@ -1980,7 +1980,7 @@ int audit_set_loginuid(kuid_t loginuid)
74858 return -EPERM;
74859 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74860
74861- sessionid = atomic_inc_return(&session_id);
74862+ sessionid = atomic_inc_return_unchecked(&session_id);
74863 if (context && context->in_syscall) {
74864 struct audit_buffer *ab;
74865
74866diff --git a/kernel/capability.c b/kernel/capability.c
74867index f6c2ce5..982c0f9 100644
74868--- a/kernel/capability.c
74869+++ b/kernel/capability.c
74870@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74871 * before modification is attempted and the application
74872 * fails.
74873 */
74874+ if (tocopy > ARRAY_SIZE(kdata))
74875+ return -EFAULT;
74876+
74877 if (copy_to_user(dataptr, kdata, tocopy
74878 * sizeof(struct __user_cap_data_struct))) {
74879 return -EFAULT;
74880@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74881 int ret;
74882
74883 rcu_read_lock();
74884- ret = security_capable(__task_cred(t), ns, cap);
74885+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74886+ gr_task_is_capable(t, __task_cred(t), cap);
74887 rcu_read_unlock();
74888
74889- return (ret == 0);
74890+ return ret;
74891 }
74892
74893 /**
74894@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74895 int ret;
74896
74897 rcu_read_lock();
74898- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74899+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74900 rcu_read_unlock();
74901
74902- return (ret == 0);
74903+ return ret;
74904 }
74905
74906 /**
74907@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74908 BUG();
74909 }
74910
74911- if (security_capable(current_cred(), ns, cap) == 0) {
74912+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74913 current->flags |= PF_SUPERPRIV;
74914 return true;
74915 }
74916@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74917 }
74918 EXPORT_SYMBOL(ns_capable);
74919
74920+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74921+{
74922+ if (unlikely(!cap_valid(cap))) {
74923+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74924+ BUG();
74925+ }
74926+
74927+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74928+ current->flags |= PF_SUPERPRIV;
74929+ return true;
74930+ }
74931+ return false;
74932+}
74933+EXPORT_SYMBOL(ns_capable_nolog);
74934+
74935 /**
74936 * file_ns_capable - Determine if the file's opener had a capability in effect
74937 * @file: The file we want to check
74938@@ -432,6 +451,12 @@ bool capable(int cap)
74939 }
74940 EXPORT_SYMBOL(capable);
74941
74942+bool capable_nolog(int cap)
74943+{
74944+ return ns_capable_nolog(&init_user_ns, cap);
74945+}
74946+EXPORT_SYMBOL(capable_nolog);
74947+
74948 /**
74949 * nsown_capable - Check superior capability to one's own user_ns
74950 * @cap: The capability in question
74951@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74952
74953 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74954 }
74955+
74956+bool inode_capable_nolog(const struct inode *inode, int cap)
74957+{
74958+ struct user_namespace *ns = current_user_ns();
74959+
74960+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74961+}
74962diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74963index a7c9e6d..a16aa75 100644
74964--- a/kernel/cgroup.c
74965+++ b/kernel/cgroup.c
74966@@ -5378,7 +5378,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74967 struct css_set *cg = link->cg;
74968 struct task_struct *task;
74969 int count = 0;
74970- seq_printf(seq, "css_set %p\n", cg);
74971+ seq_printf(seq, "css_set %pK\n", cg);
74972 list_for_each_entry(task, &cg->tasks, cg_list) {
74973 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74974 seq_puts(seq, " ...\n");
74975diff --git a/kernel/compat.c b/kernel/compat.c
74976index 0a09e48..f44f3f0 100644
74977--- a/kernel/compat.c
74978+++ b/kernel/compat.c
74979@@ -13,6 +13,7 @@
74980
74981 #include <linux/linkage.h>
74982 #include <linux/compat.h>
74983+#include <linux/module.h>
74984 #include <linux/errno.h>
74985 #include <linux/time.h>
74986 #include <linux/signal.h>
74987@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74988 mm_segment_t oldfs;
74989 long ret;
74990
74991- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74992+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74993 oldfs = get_fs();
74994 set_fs(KERNEL_DS);
74995 ret = hrtimer_nanosleep_restart(restart);
74996@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74997 oldfs = get_fs();
74998 set_fs(KERNEL_DS);
74999 ret = hrtimer_nanosleep(&tu,
75000- rmtp ? (struct timespec __user *)&rmt : NULL,
75001+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
75002 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
75003 set_fs(oldfs);
75004
75005@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
75006 mm_segment_t old_fs = get_fs();
75007
75008 set_fs(KERNEL_DS);
75009- ret = sys_sigpending((old_sigset_t __user *) &s);
75010+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
75011 set_fs(old_fs);
75012 if (ret == 0)
75013 ret = put_user(s, set);
75014@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
75015 mm_segment_t old_fs = get_fs();
75016
75017 set_fs(KERNEL_DS);
75018- ret = sys_old_getrlimit(resource, &r);
75019+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
75020 set_fs(old_fs);
75021
75022 if (!ret) {
75023@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
75024 set_fs (KERNEL_DS);
75025 ret = sys_wait4(pid,
75026 (stat_addr ?
75027- (unsigned int __user *) &status : NULL),
75028- options, (struct rusage __user *) &r);
75029+ (unsigned int __force_user *) &status : NULL),
75030+ options, (struct rusage __force_user *) &r);
75031 set_fs (old_fs);
75032
75033 if (ret > 0) {
75034@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
75035 memset(&info, 0, sizeof(info));
75036
75037 set_fs(KERNEL_DS);
75038- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
75039- uru ? (struct rusage __user *)&ru : NULL);
75040+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
75041+ uru ? (struct rusage __force_user *)&ru : NULL);
75042 set_fs(old_fs);
75043
75044 if ((ret < 0) || (info.si_signo == 0))
75045@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
75046 oldfs = get_fs();
75047 set_fs(KERNEL_DS);
75048 err = sys_timer_settime(timer_id, flags,
75049- (struct itimerspec __user *) &newts,
75050- (struct itimerspec __user *) &oldts);
75051+ (struct itimerspec __force_user *) &newts,
75052+ (struct itimerspec __force_user *) &oldts);
75053 set_fs(oldfs);
75054 if (!err && old && put_compat_itimerspec(old, &oldts))
75055 return -EFAULT;
75056@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
75057 oldfs = get_fs();
75058 set_fs(KERNEL_DS);
75059 err = sys_timer_gettime(timer_id,
75060- (struct itimerspec __user *) &ts);
75061+ (struct itimerspec __force_user *) &ts);
75062 set_fs(oldfs);
75063 if (!err && put_compat_itimerspec(setting, &ts))
75064 return -EFAULT;
75065@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
75066 oldfs = get_fs();
75067 set_fs(KERNEL_DS);
75068 err = sys_clock_settime(which_clock,
75069- (struct timespec __user *) &ts);
75070+ (struct timespec __force_user *) &ts);
75071 set_fs(oldfs);
75072 return err;
75073 }
75074@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
75075 oldfs = get_fs();
75076 set_fs(KERNEL_DS);
75077 err = sys_clock_gettime(which_clock,
75078- (struct timespec __user *) &ts);
75079+ (struct timespec __force_user *) &ts);
75080 set_fs(oldfs);
75081 if (!err && put_compat_timespec(&ts, tp))
75082 return -EFAULT;
75083@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
75084
75085 oldfs = get_fs();
75086 set_fs(KERNEL_DS);
75087- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
75088+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
75089 set_fs(oldfs);
75090
75091 err = compat_put_timex(utp, &txc);
75092@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
75093 oldfs = get_fs();
75094 set_fs(KERNEL_DS);
75095 err = sys_clock_getres(which_clock,
75096- (struct timespec __user *) &ts);
75097+ (struct timespec __force_user *) &ts);
75098 set_fs(oldfs);
75099 if (!err && tp && put_compat_timespec(&ts, tp))
75100 return -EFAULT;
75101@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
75102 long err;
75103 mm_segment_t oldfs;
75104 struct timespec tu;
75105- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
75106+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
75107
75108- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
75109+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
75110 oldfs = get_fs();
75111 set_fs(KERNEL_DS);
75112 err = clock_nanosleep_restart(restart);
75113@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
75114 oldfs = get_fs();
75115 set_fs(KERNEL_DS);
75116 err = sys_clock_nanosleep(which_clock, flags,
75117- (struct timespec __user *) &in,
75118- (struct timespec __user *) &out);
75119+ (struct timespec __force_user *) &in,
75120+ (struct timespec __force_user *) &out);
75121 set_fs(oldfs);
75122
75123 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
75124diff --git a/kernel/configs.c b/kernel/configs.c
75125index c18b1f1..b9a0132 100644
75126--- a/kernel/configs.c
75127+++ b/kernel/configs.c
75128@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
75129 struct proc_dir_entry *entry;
75130
75131 /* create the current config file */
75132+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
75133+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
75134+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
75135+ &ikconfig_file_ops);
75136+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75137+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
75138+ &ikconfig_file_ops);
75139+#endif
75140+#else
75141 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
75142 &ikconfig_file_ops);
75143+#endif
75144+
75145 if (!entry)
75146 return -ENOMEM;
75147
75148diff --git a/kernel/cred.c b/kernel/cred.c
75149index e0573a4..3874e41 100644
75150--- a/kernel/cred.c
75151+++ b/kernel/cred.c
75152@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
75153 validate_creds(cred);
75154 alter_cred_subscribers(cred, -1);
75155 put_cred(cred);
75156+
75157+#ifdef CONFIG_GRKERNSEC_SETXID
75158+ cred = (struct cred *) tsk->delayed_cred;
75159+ if (cred != NULL) {
75160+ tsk->delayed_cred = NULL;
75161+ validate_creds(cred);
75162+ alter_cred_subscribers(cred, -1);
75163+ put_cred(cred);
75164+ }
75165+#endif
75166 }
75167
75168 /**
75169@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
75170 * Always returns 0 thus allowing this function to be tail-called at the end
75171 * of, say, sys_setgid().
75172 */
75173-int commit_creds(struct cred *new)
75174+static int __commit_creds(struct cred *new)
75175 {
75176 struct task_struct *task = current;
75177 const struct cred *old = task->real_cred;
75178@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
75179
75180 get_cred(new); /* we will require a ref for the subj creds too */
75181
75182+ gr_set_role_label(task, new->uid, new->gid);
75183+
75184 /* dumpability changes */
75185 if (!uid_eq(old->euid, new->euid) ||
75186 !gid_eq(old->egid, new->egid) ||
75187@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
75188 put_cred(old);
75189 return 0;
75190 }
75191+#ifdef CONFIG_GRKERNSEC_SETXID
75192+extern int set_user(struct cred *new);
75193+
75194+void gr_delayed_cred_worker(void)
75195+{
75196+ const struct cred *new = current->delayed_cred;
75197+ struct cred *ncred;
75198+
75199+ current->delayed_cred = NULL;
75200+
75201+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
75202+ // from doing get_cred on it when queueing this
75203+ put_cred(new);
75204+ return;
75205+ } else if (new == NULL)
75206+ return;
75207+
75208+ ncred = prepare_creds();
75209+ if (!ncred)
75210+ goto die;
75211+ // uids
75212+ ncred->uid = new->uid;
75213+ ncred->euid = new->euid;
75214+ ncred->suid = new->suid;
75215+ ncred->fsuid = new->fsuid;
75216+ // gids
75217+ ncred->gid = new->gid;
75218+ ncred->egid = new->egid;
75219+ ncred->sgid = new->sgid;
75220+ ncred->fsgid = new->fsgid;
75221+ // groups
75222+ if (set_groups(ncred, new->group_info) < 0) {
75223+ abort_creds(ncred);
75224+ goto die;
75225+ }
75226+ // caps
75227+ ncred->securebits = new->securebits;
75228+ ncred->cap_inheritable = new->cap_inheritable;
75229+ ncred->cap_permitted = new->cap_permitted;
75230+ ncred->cap_effective = new->cap_effective;
75231+ ncred->cap_bset = new->cap_bset;
75232+
75233+ if (set_user(ncred)) {
75234+ abort_creds(ncred);
75235+ goto die;
75236+ }
75237+
75238+ // from doing get_cred on it when queueing this
75239+ put_cred(new);
75240+
75241+ __commit_creds(ncred);
75242+ return;
75243+die:
75244+ // from doing get_cred on it when queueing this
75245+ put_cred(new);
75246+ do_group_exit(SIGKILL);
75247+}
75248+#endif
75249+
75250+int commit_creds(struct cred *new)
75251+{
75252+#ifdef CONFIG_GRKERNSEC_SETXID
75253+ int ret;
75254+ int schedule_it = 0;
75255+ struct task_struct *t;
75256+
75257+ /* we won't get called with tasklist_lock held for writing
75258+ and interrupts disabled as the cred struct in that case is
75259+ init_cred
75260+ */
75261+ if (grsec_enable_setxid && !current_is_single_threaded() &&
75262+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
75263+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
75264+ schedule_it = 1;
75265+ }
75266+ ret = __commit_creds(new);
75267+ if (schedule_it) {
75268+ rcu_read_lock();
75269+ read_lock(&tasklist_lock);
75270+ for (t = next_thread(current); t != current;
75271+ t = next_thread(t)) {
75272+ if (t->delayed_cred == NULL) {
75273+ t->delayed_cred = get_cred(new);
75274+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
75275+ set_tsk_need_resched(t);
75276+ }
75277+ }
75278+ read_unlock(&tasklist_lock);
75279+ rcu_read_unlock();
75280+ }
75281+ return ret;
75282+#else
75283+ return __commit_creds(new);
75284+#endif
75285+}
75286+
75287 EXPORT_SYMBOL(commit_creds);
75288
75289 /**
75290diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
75291index 0506d44..2c20034 100644
75292--- a/kernel/debug/debug_core.c
75293+++ b/kernel/debug/debug_core.c
75294@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75295 */
75296 static atomic_t masters_in_kgdb;
75297 static atomic_t slaves_in_kgdb;
75298-static atomic_t kgdb_break_tasklet_var;
75299+static atomic_unchecked_t kgdb_break_tasklet_var;
75300 atomic_t kgdb_setting_breakpoint;
75301
75302 struct task_struct *kgdb_usethread;
75303@@ -133,7 +133,7 @@ int kgdb_single_step;
75304 static pid_t kgdb_sstep_pid;
75305
75306 /* to keep track of the CPU which is doing the single stepping*/
75307-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75308+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75309
75310 /*
75311 * If you are debugging a problem where roundup (the collection of
75312@@ -541,7 +541,7 @@ return_normal:
75313 * kernel will only try for the value of sstep_tries before
75314 * giving up and continuing on.
75315 */
75316- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75317+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75318 (kgdb_info[cpu].task &&
75319 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75320 atomic_set(&kgdb_active, -1);
75321@@ -635,8 +635,8 @@ cpu_master_loop:
75322 }
75323
75324 kgdb_restore:
75325- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75326- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75327+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75328+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75329 if (kgdb_info[sstep_cpu].task)
75330 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75331 else
75332@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
75333 static void kgdb_tasklet_bpt(unsigned long ing)
75334 {
75335 kgdb_breakpoint();
75336- atomic_set(&kgdb_break_tasklet_var, 0);
75337+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75338 }
75339
75340 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75341
75342 void kgdb_schedule_breakpoint(void)
75343 {
75344- if (atomic_read(&kgdb_break_tasklet_var) ||
75345+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75346 atomic_read(&kgdb_active) != -1 ||
75347 atomic_read(&kgdb_setting_breakpoint))
75348 return;
75349- atomic_inc(&kgdb_break_tasklet_var);
75350+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75351 tasklet_schedule(&kgdb_tasklet_breakpoint);
75352 }
75353 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75354diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75355index 00eb8f7..d7e3244 100644
75356--- a/kernel/debug/kdb/kdb_main.c
75357+++ b/kernel/debug/kdb/kdb_main.c
75358@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75359 continue;
75360
75361 kdb_printf("%-20s%8u 0x%p ", mod->name,
75362- mod->core_size, (void *)mod);
75363+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75364 #ifdef CONFIG_MODULE_UNLOAD
75365 kdb_printf("%4ld ", module_refcount(mod));
75366 #endif
75367@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75368 kdb_printf(" (Loading)");
75369 else
75370 kdb_printf(" (Live)");
75371- kdb_printf(" 0x%p", mod->module_core);
75372+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75373
75374 #ifdef CONFIG_MODULE_UNLOAD
75375 {
75376diff --git a/kernel/events/core.c b/kernel/events/core.c
75377index b391907..a0e2372 100644
75378--- a/kernel/events/core.c
75379+++ b/kernel/events/core.c
75380@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
75381 * 0 - disallow raw tracepoint access for unpriv
75382 * 1 - disallow cpu events for unpriv
75383 * 2 - disallow kernel profiling for unpriv
75384+ * 3 - disallow all unpriv perf event use
75385 */
75386-int sysctl_perf_event_paranoid __read_mostly = 1;
75387+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75388+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
75389+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
75390+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
75391+#else
75392+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
75393+#endif
75394
75395 /* Minimum for 512 kiB + 1 user control page */
75396 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
75397@@ -184,7 +191,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75398 return 0;
75399 }
75400
75401-static atomic64_t perf_event_id;
75402+static atomic64_unchecked_t perf_event_id;
75403
75404 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75405 enum event_type_t event_type);
75406@@ -2725,7 +2732,7 @@ static void __perf_event_read(void *info)
75407
75408 static inline u64 perf_event_count(struct perf_event *event)
75409 {
75410- return local64_read(&event->count) + atomic64_read(&event->child_count);
75411+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75412 }
75413
75414 static u64 perf_event_read(struct perf_event *event)
75415@@ -3071,9 +3078,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75416 mutex_lock(&event->child_mutex);
75417 total += perf_event_read(event);
75418 *enabled += event->total_time_enabled +
75419- atomic64_read(&event->child_total_time_enabled);
75420+ atomic64_read_unchecked(&event->child_total_time_enabled);
75421 *running += event->total_time_running +
75422- atomic64_read(&event->child_total_time_running);
75423+ atomic64_read_unchecked(&event->child_total_time_running);
75424
75425 list_for_each_entry(child, &event->child_list, child_list) {
75426 total += perf_event_read(child);
75427@@ -3459,10 +3466,10 @@ void perf_event_update_userpage(struct perf_event *event)
75428 userpg->offset -= local64_read(&event->hw.prev_count);
75429
75430 userpg->time_enabled = enabled +
75431- atomic64_read(&event->child_total_time_enabled);
75432+ atomic64_read_unchecked(&event->child_total_time_enabled);
75433
75434 userpg->time_running = running +
75435- atomic64_read(&event->child_total_time_running);
75436+ atomic64_read_unchecked(&event->child_total_time_running);
75437
75438 arch_perf_update_userpage(userpg, now);
75439
75440@@ -4012,7 +4019,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
75441
75442 /* Data. */
75443 sp = perf_user_stack_pointer(regs);
75444- rem = __output_copy_user(handle, (void *) sp, dump_size);
75445+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
75446 dyn_size = dump_size - rem;
75447
75448 perf_output_skip(handle, rem);
75449@@ -4100,11 +4107,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75450 values[n++] = perf_event_count(event);
75451 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75452 values[n++] = enabled +
75453- atomic64_read(&event->child_total_time_enabled);
75454+ atomic64_read_unchecked(&event->child_total_time_enabled);
75455 }
75456 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75457 values[n++] = running +
75458- atomic64_read(&event->child_total_time_running);
75459+ atomic64_read_unchecked(&event->child_total_time_running);
75460 }
75461 if (read_format & PERF_FORMAT_ID)
75462 values[n++] = primary_event_id(event);
75463@@ -4813,12 +4820,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75464 * need to add enough zero bytes after the string to handle
75465 * the 64bit alignment we do later.
75466 */
75467- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75468+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75469 if (!buf) {
75470 name = strncpy(tmp, "//enomem", sizeof(tmp));
75471 goto got_name;
75472 }
75473- name = d_path(&file->f_path, buf, PATH_MAX);
75474+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75475 if (IS_ERR(name)) {
75476 name = strncpy(tmp, "//toolong", sizeof(tmp));
75477 goto got_name;
75478@@ -6240,7 +6247,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75479 event->parent = parent_event;
75480
75481 event->ns = get_pid_ns(task_active_pid_ns(current));
75482- event->id = atomic64_inc_return(&perf_event_id);
75483+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75484
75485 event->state = PERF_EVENT_STATE_INACTIVE;
75486
75487@@ -6550,6 +6557,11 @@ SYSCALL_DEFINE5(perf_event_open,
75488 if (flags & ~PERF_FLAG_ALL)
75489 return -EINVAL;
75490
75491+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75492+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
75493+ return -EACCES;
75494+#endif
75495+
75496 err = perf_copy_attr(attr_uptr, &attr);
75497 if (err)
75498 return err;
75499@@ -6882,10 +6894,10 @@ static void sync_child_event(struct perf_event *child_event,
75500 /*
75501 * Add back the child's count to the parent's count:
75502 */
75503- atomic64_add(child_val, &parent_event->child_count);
75504- atomic64_add(child_event->total_time_enabled,
75505+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75506+ atomic64_add_unchecked(child_event->total_time_enabled,
75507 &parent_event->child_total_time_enabled);
75508- atomic64_add(child_event->total_time_running,
75509+ atomic64_add_unchecked(child_event->total_time_running,
75510 &parent_event->child_total_time_running);
75511
75512 /*
75513diff --git a/kernel/events/internal.h b/kernel/events/internal.h
75514index ca65997..cc8cee4 100644
75515--- a/kernel/events/internal.h
75516+++ b/kernel/events/internal.h
75517@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
75518 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
75519 }
75520
75521-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
75522+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
75523 static inline unsigned int \
75524 func_name(struct perf_output_handle *handle, \
75525- const void *buf, unsigned int len) \
75526+ const void user *buf, unsigned int len) \
75527 { \
75528 unsigned long size, written; \
75529 \
75530@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
75531 return n;
75532 }
75533
75534-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
75535+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
75536
75537 #define MEMCPY_SKIP(dst, src, n) (n)
75538
75539-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
75540+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
75541
75542 #ifndef arch_perf_out_copy_user
75543 #define arch_perf_out_copy_user __copy_from_user_inatomic
75544 #endif
75545
75546-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
75547+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
75548
75549 /* Callchain handling */
75550 extern struct perf_callchain_entry *
75551diff --git a/kernel/exit.c b/kernel/exit.c
75552index 7bb73f9..d7978ed 100644
75553--- a/kernel/exit.c
75554+++ b/kernel/exit.c
75555@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
75556 struct task_struct *leader;
75557 int zap_leader;
75558 repeat:
75559+#ifdef CONFIG_NET
75560+ gr_del_task_from_ip_table(p);
75561+#endif
75562+
75563 /* don't need to get the RCU readlock here - the process is dead and
75564 * can't be modifying its own credentials. But shut RCU-lockdep up */
75565 rcu_read_lock();
75566@@ -340,7 +344,7 @@ int allow_signal(int sig)
75567 * know it'll be handled, so that they don't get converted to
75568 * SIGKILL or just silently dropped.
75569 */
75570- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75571+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75572 recalc_sigpending();
75573 spin_unlock_irq(&current->sighand->siglock);
75574 return 0;
75575@@ -709,6 +713,8 @@ void do_exit(long code)
75576 struct task_struct *tsk = current;
75577 int group_dead;
75578
75579+ set_fs(USER_DS);
75580+
75581 profile_task_exit(tsk);
75582
75583 WARN_ON(blk_needs_flush_plug(tsk));
75584@@ -725,7 +731,6 @@ void do_exit(long code)
75585 * mm_release()->clear_child_tid() from writing to a user-controlled
75586 * kernel address.
75587 */
75588- set_fs(USER_DS);
75589
75590 ptrace_event(PTRACE_EVENT_EXIT, code);
75591
75592@@ -784,6 +789,9 @@ void do_exit(long code)
75593 tsk->exit_code = code;
75594 taskstats_exit(tsk, group_dead);
75595
75596+ gr_acl_handle_psacct(tsk, code);
75597+ gr_acl_handle_exit();
75598+
75599 exit_mm(tsk);
75600
75601 if (group_dead)
75602@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75603 * Take down every thread in the group. This is called by fatal signals
75604 * as well as by sys_exit_group (below).
75605 */
75606-void
75607+__noreturn void
75608 do_group_exit(int exit_code)
75609 {
75610 struct signal_struct *sig = current->signal;
75611diff --git a/kernel/fork.c b/kernel/fork.c
75612index 987b28a..4e03c05 100644
75613--- a/kernel/fork.c
75614+++ b/kernel/fork.c
75615@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75616 *stackend = STACK_END_MAGIC; /* for overflow detection */
75617
75618 #ifdef CONFIG_CC_STACKPROTECTOR
75619- tsk->stack_canary = get_random_int();
75620+ tsk->stack_canary = pax_get_random_long();
75621 #endif
75622
75623 /*
75624@@ -345,13 +345,81 @@ free_tsk:
75625 }
75626
75627 #ifdef CONFIG_MMU
75628+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75629+{
75630+ struct vm_area_struct *tmp;
75631+ unsigned long charge;
75632+ struct mempolicy *pol;
75633+ struct file *file;
75634+
75635+ charge = 0;
75636+ if (mpnt->vm_flags & VM_ACCOUNT) {
75637+ unsigned long len = vma_pages(mpnt);
75638+
75639+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75640+ goto fail_nomem;
75641+ charge = len;
75642+ }
75643+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75644+ if (!tmp)
75645+ goto fail_nomem;
75646+ *tmp = *mpnt;
75647+ tmp->vm_mm = mm;
75648+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75649+ pol = mpol_dup(vma_policy(mpnt));
75650+ if (IS_ERR(pol))
75651+ goto fail_nomem_policy;
75652+ vma_set_policy(tmp, pol);
75653+ if (anon_vma_fork(tmp, mpnt))
75654+ goto fail_nomem_anon_vma_fork;
75655+ tmp->vm_flags &= ~VM_LOCKED;
75656+ tmp->vm_next = tmp->vm_prev = NULL;
75657+ tmp->vm_mirror = NULL;
75658+ file = tmp->vm_file;
75659+ if (file) {
75660+ struct inode *inode = file_inode(file);
75661+ struct address_space *mapping = file->f_mapping;
75662+
75663+ get_file(file);
75664+ if (tmp->vm_flags & VM_DENYWRITE)
75665+ atomic_dec(&inode->i_writecount);
75666+ mutex_lock(&mapping->i_mmap_mutex);
75667+ if (tmp->vm_flags & VM_SHARED)
75668+ mapping->i_mmap_writable++;
75669+ flush_dcache_mmap_lock(mapping);
75670+ /* insert tmp into the share list, just after mpnt */
75671+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75672+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75673+ else
75674+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75675+ flush_dcache_mmap_unlock(mapping);
75676+ mutex_unlock(&mapping->i_mmap_mutex);
75677+ }
75678+
75679+ /*
75680+ * Clear hugetlb-related page reserves for children. This only
75681+ * affects MAP_PRIVATE mappings. Faults generated by the child
75682+ * are not guaranteed to succeed, even if read-only
75683+ */
75684+ if (is_vm_hugetlb_page(tmp))
75685+ reset_vma_resv_huge_pages(tmp);
75686+
75687+ return tmp;
75688+
75689+fail_nomem_anon_vma_fork:
75690+ mpol_put(pol);
75691+fail_nomem_policy:
75692+ kmem_cache_free(vm_area_cachep, tmp);
75693+fail_nomem:
75694+ vm_unacct_memory(charge);
75695+ return NULL;
75696+}
75697+
75698 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75699 {
75700 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75701 struct rb_node **rb_link, *rb_parent;
75702 int retval;
75703- unsigned long charge;
75704- struct mempolicy *pol;
75705
75706 uprobe_start_dup_mmap();
75707 down_write(&oldmm->mmap_sem);
75708@@ -365,8 +433,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75709 mm->locked_vm = 0;
75710 mm->mmap = NULL;
75711 mm->mmap_cache = NULL;
75712- mm->free_area_cache = oldmm->mmap_base;
75713- mm->cached_hole_size = ~0UL;
75714+ mm->free_area_cache = oldmm->free_area_cache;
75715+ mm->cached_hole_size = oldmm->cached_hole_size;
75716 mm->map_count = 0;
75717 cpumask_clear(mm_cpumask(mm));
75718 mm->mm_rb = RB_ROOT;
75719@@ -382,57 +450,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75720
75721 prev = NULL;
75722 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75723- struct file *file;
75724-
75725 if (mpnt->vm_flags & VM_DONTCOPY) {
75726 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75727 -vma_pages(mpnt));
75728 continue;
75729 }
75730- charge = 0;
75731- if (mpnt->vm_flags & VM_ACCOUNT) {
75732- unsigned long len = vma_pages(mpnt);
75733-
75734- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75735- goto fail_nomem;
75736- charge = len;
75737- }
75738- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75739- if (!tmp)
75740- goto fail_nomem;
75741- *tmp = *mpnt;
75742- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75743- pol = mpol_dup(vma_policy(mpnt));
75744- retval = PTR_ERR(pol);
75745- if (IS_ERR(pol))
75746- goto fail_nomem_policy;
75747- vma_set_policy(tmp, pol);
75748- tmp->vm_mm = mm;
75749- if (anon_vma_fork(tmp, mpnt))
75750- goto fail_nomem_anon_vma_fork;
75751- tmp->vm_flags &= ~VM_LOCKED;
75752- tmp->vm_next = tmp->vm_prev = NULL;
75753- file = tmp->vm_file;
75754- if (file) {
75755- struct inode *inode = file_inode(file);
75756- struct address_space *mapping = file->f_mapping;
75757-
75758- get_file(file);
75759- if (tmp->vm_flags & VM_DENYWRITE)
75760- atomic_dec(&inode->i_writecount);
75761- mutex_lock(&mapping->i_mmap_mutex);
75762- if (tmp->vm_flags & VM_SHARED)
75763- mapping->i_mmap_writable++;
75764- flush_dcache_mmap_lock(mapping);
75765- /* insert tmp into the share list, just after mpnt */
75766- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75767- vma_nonlinear_insert(tmp,
75768- &mapping->i_mmap_nonlinear);
75769- else
75770- vma_interval_tree_insert_after(tmp, mpnt,
75771- &mapping->i_mmap);
75772- flush_dcache_mmap_unlock(mapping);
75773- mutex_unlock(&mapping->i_mmap_mutex);
75774+ tmp = dup_vma(mm, oldmm, mpnt);
75775+ if (!tmp) {
75776+ retval = -ENOMEM;
75777+ goto out;
75778 }
75779
75780 /*
75781@@ -464,6 +490,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75782 if (retval)
75783 goto out;
75784 }
75785+
75786+#ifdef CONFIG_PAX_SEGMEXEC
75787+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75788+ struct vm_area_struct *mpnt_m;
75789+
75790+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75791+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75792+
75793+ if (!mpnt->vm_mirror)
75794+ continue;
75795+
75796+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75797+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75798+ mpnt->vm_mirror = mpnt_m;
75799+ } else {
75800+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75801+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75802+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75803+ mpnt->vm_mirror->vm_mirror = mpnt;
75804+ }
75805+ }
75806+ BUG_ON(mpnt_m);
75807+ }
75808+#endif
75809+
75810 /* a new mm has just been created */
75811 arch_dup_mmap(oldmm, mm);
75812 retval = 0;
75813@@ -473,14 +524,6 @@ out:
75814 up_write(&oldmm->mmap_sem);
75815 uprobe_end_dup_mmap();
75816 return retval;
75817-fail_nomem_anon_vma_fork:
75818- mpol_put(pol);
75819-fail_nomem_policy:
75820- kmem_cache_free(vm_area_cachep, tmp);
75821-fail_nomem:
75822- retval = -ENOMEM;
75823- vm_unacct_memory(charge);
75824- goto out;
75825 }
75826
75827 static inline int mm_alloc_pgd(struct mm_struct *mm)
75828@@ -695,8 +738,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75829 return ERR_PTR(err);
75830
75831 mm = get_task_mm(task);
75832- if (mm && mm != current->mm &&
75833- !ptrace_may_access(task, mode)) {
75834+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75835+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75836 mmput(mm);
75837 mm = ERR_PTR(-EACCES);
75838 }
75839@@ -918,13 +961,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75840 spin_unlock(&fs->lock);
75841 return -EAGAIN;
75842 }
75843- fs->users++;
75844+ atomic_inc(&fs->users);
75845 spin_unlock(&fs->lock);
75846 return 0;
75847 }
75848 tsk->fs = copy_fs_struct(fs);
75849 if (!tsk->fs)
75850 return -ENOMEM;
75851+ /* Carry through gr_chroot_dentry and is_chrooted instead
75852+ of recomputing it here. Already copied when the task struct
75853+ is duplicated. This allows pivot_root to not be treated as
75854+ a chroot
75855+ */
75856+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75857+
75858 return 0;
75859 }
75860
75861@@ -1197,10 +1247,13 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75862 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75863 #endif
75864 retval = -EAGAIN;
75865+
75866+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75867+
75868 if (atomic_read(&p->real_cred->user->processes) >=
75869 task_rlimit(p, RLIMIT_NPROC)) {
75870- if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75871- p->real_cred->user != INIT_USER)
75872+ if (p->real_cred->user != INIT_USER &&
75873+ !capable(CAP_SYS_RESOURCE) && !capable(CAP_SYS_ADMIN))
75874 goto bad_fork_free;
75875 }
75876 current->flags &= ~PF_NPROC_EXCEEDED;
75877@@ -1446,6 +1499,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75878 goto bad_fork_free_pid;
75879 }
75880
75881+ /* synchronizes with gr_set_acls()
75882+ we need to call this past the point of no return for fork()
75883+ */
75884+ gr_copy_label(p);
75885+
75886 if (clone_flags & CLONE_THREAD) {
75887 current->signal->nr_threads++;
75888 atomic_inc(&current->signal->live);
75889@@ -1529,6 +1587,8 @@ bad_fork_cleanup_count:
75890 bad_fork_free:
75891 free_task(p);
75892 fork_out:
75893+ gr_log_forkfail(retval);
75894+
75895 return ERR_PTR(retval);
75896 }
75897
75898@@ -1579,6 +1639,23 @@ long do_fork(unsigned long clone_flags,
75899 return -EINVAL;
75900 }
75901
75902+#ifdef CONFIG_GRKERNSEC
75903+ if (clone_flags & CLONE_NEWUSER) {
75904+ /*
75905+ * This doesn't really inspire confidence:
75906+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75907+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75908+ * Increases kernel attack surface in areas developers
75909+ * previously cared little about ("low importance due
75910+ * to requiring "root" capability")
75911+ * To be removed when this code receives *proper* review
75912+ */
75913+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75914+ !capable(CAP_SETGID))
75915+ return -EPERM;
75916+ }
75917+#endif
75918+
75919 /*
75920 * Determine whether and which event to report to ptracer. When
75921 * called from kernel_thread or CLONE_UNTRACED is explicitly
75922@@ -1613,6 +1690,8 @@ long do_fork(unsigned long clone_flags,
75923 if (clone_flags & CLONE_PARENT_SETTID)
75924 put_user(nr, parent_tidptr);
75925
75926+ gr_handle_brute_check();
75927+
75928 if (clone_flags & CLONE_VFORK) {
75929 p->vfork_done = &vfork;
75930 init_completion(&vfork);
75931@@ -1763,7 +1842,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75932 return 0;
75933
75934 /* don't need lock here; in the worst case we'll do useless copy */
75935- if (fs->users == 1)
75936+ if (atomic_read(&fs->users) == 1)
75937 return 0;
75938
75939 *new_fsp = copy_fs_struct(fs);
75940@@ -1875,7 +1954,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75941 fs = current->fs;
75942 spin_lock(&fs->lock);
75943 current->fs = new_fs;
75944- if (--fs->users)
75945+ gr_set_chroot_entries(current, &current->fs->root);
75946+ if (atomic_dec_return(&fs->users))
75947 new_fs = NULL;
75948 else
75949 new_fs = fs;
75950diff --git a/kernel/futex.c b/kernel/futex.c
75951index 49dacfb..5c6b450 100644
75952--- a/kernel/futex.c
75953+++ b/kernel/futex.c
75954@@ -54,6 +54,7 @@
75955 #include <linux/mount.h>
75956 #include <linux/pagemap.h>
75957 #include <linux/syscalls.h>
75958+#include <linux/ptrace.h>
75959 #include <linux/signal.h>
75960 #include <linux/export.h>
75961 #include <linux/magic.h>
75962@@ -242,6 +243,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75963 struct page *page, *page_head;
75964 int err, ro = 0;
75965
75966+#ifdef CONFIG_PAX_SEGMEXEC
75967+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75968+ return -EFAULT;
75969+#endif
75970+
75971 /*
75972 * The futex address must be "naturally" aligned.
75973 */
75974@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
75975 {
75976 u32 curval;
75977 int i;
75978+ mm_segment_t oldfs;
75979
75980 /*
75981 * This will fail and we want it. Some arch implementations do
75982@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
75983 * implementation, the non-functional ones will return
75984 * -ENOSYS.
75985 */
75986+ oldfs = get_fs();
75987+ set_fs(USER_DS);
75988 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75989 futex_cmpxchg_enabled = 1;
75990+ set_fs(oldfs);
75991
75992 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75993 plist_head_init(&futex_queues[i].chain);
75994diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75995index f9f44fd..29885e4 100644
75996--- a/kernel/futex_compat.c
75997+++ b/kernel/futex_compat.c
75998@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75999 return 0;
76000 }
76001
76002-static void __user *futex_uaddr(struct robust_list __user *entry,
76003+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
76004 compat_long_t futex_offset)
76005 {
76006 compat_uptr_t base = ptr_to_compat(entry);
76007diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
76008index 9b22d03..6295b62 100644
76009--- a/kernel/gcov/base.c
76010+++ b/kernel/gcov/base.c
76011@@ -102,11 +102,6 @@ void gcov_enable_events(void)
76012 }
76013
76014 #ifdef CONFIG_MODULES
76015-static inline int within(void *addr, void *start, unsigned long size)
76016-{
76017- return ((addr >= start) && (addr < start + size));
76018-}
76019-
76020 /* Update list and generate events when modules are unloaded. */
76021 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
76022 void *data)
76023@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
76024 prev = NULL;
76025 /* Remove entries located in module from linked list. */
76026 for (info = gcov_info_head; info; info = info->next) {
76027- if (within(info, mod->module_core, mod->core_size)) {
76028+ if (within_module_core_rw((unsigned long)info, mod)) {
76029 if (prev)
76030 prev->next = info->next;
76031 else
76032diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
76033index fd4b13b..09a5ccb 100644
76034--- a/kernel/hrtimer.c
76035+++ b/kernel/hrtimer.c
76036@@ -1430,7 +1430,7 @@ void hrtimer_peek_ahead_timers(void)
76037 local_irq_restore(flags);
76038 }
76039
76040-static void run_hrtimer_softirq(struct softirq_action *h)
76041+static void run_hrtimer_softirq(void)
76042 {
76043 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
76044
76045@@ -1772,7 +1772,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
76046 return NOTIFY_OK;
76047 }
76048
76049-static struct notifier_block __cpuinitdata hrtimers_nb = {
76050+static struct notifier_block hrtimers_nb = {
76051 .notifier_call = hrtimer_cpu_notify,
76052 };
76053
76054diff --git a/kernel/irq_work.c b/kernel/irq_work.c
76055index 55fcce6..0e4cf34 100644
76056--- a/kernel/irq_work.c
76057+++ b/kernel/irq_work.c
76058@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
76059 return NOTIFY_OK;
76060 }
76061
76062-static struct notifier_block cpu_notify;
76063+static struct notifier_block cpu_notify = {
76064+ .notifier_call = irq_work_cpu_notify,
76065+ .priority = 0,
76066+};
76067
76068 static __init int irq_work_init_cpu_notifier(void)
76069 {
76070- cpu_notify.notifier_call = irq_work_cpu_notify;
76071- cpu_notify.priority = 0;
76072 register_cpu_notifier(&cpu_notify);
76073 return 0;
76074 }
76075diff --git a/kernel/jump_label.c b/kernel/jump_label.c
76076index 60f48fa..7f3a770 100644
76077--- a/kernel/jump_label.c
76078+++ b/kernel/jump_label.c
76079@@ -13,6 +13,7 @@
76080 #include <linux/sort.h>
76081 #include <linux/err.h>
76082 #include <linux/static_key.h>
76083+#include <linux/mm.h>
76084
76085 #ifdef HAVE_JUMP_LABEL
76086
76087@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
76088
76089 size = (((unsigned long)stop - (unsigned long)start)
76090 / sizeof(struct jump_entry));
76091+ pax_open_kernel();
76092 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
76093+ pax_close_kernel();
76094 }
76095
76096 static void jump_label_update(struct static_key *key, int enable);
76097@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
76098 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
76099 struct jump_entry *iter;
76100
76101+ pax_open_kernel();
76102 for (iter = iter_start; iter < iter_stop; iter++) {
76103 if (within_module_init(iter->code, mod))
76104 iter->code = 0;
76105 }
76106+ pax_close_kernel();
76107 }
76108
76109 static int
76110diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
76111index 3127ad5..159d880 100644
76112--- a/kernel/kallsyms.c
76113+++ b/kernel/kallsyms.c
76114@@ -11,6 +11,9 @@
76115 * Changed the compression method from stem compression to "table lookup"
76116 * compression (see scripts/kallsyms.c for a more complete description)
76117 */
76118+#ifdef CONFIG_GRKERNSEC_HIDESYM
76119+#define __INCLUDED_BY_HIDESYM 1
76120+#endif
76121 #include <linux/kallsyms.h>
76122 #include <linux/module.h>
76123 #include <linux/init.h>
76124@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
76125
76126 static inline int is_kernel_inittext(unsigned long addr)
76127 {
76128+ if (system_state != SYSTEM_BOOTING)
76129+ return 0;
76130+
76131 if (addr >= (unsigned long)_sinittext
76132 && addr <= (unsigned long)_einittext)
76133 return 1;
76134 return 0;
76135 }
76136
76137+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76138+#ifdef CONFIG_MODULES
76139+static inline int is_module_text(unsigned long addr)
76140+{
76141+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
76142+ return 1;
76143+
76144+ addr = ktla_ktva(addr);
76145+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
76146+}
76147+#else
76148+static inline int is_module_text(unsigned long addr)
76149+{
76150+ return 0;
76151+}
76152+#endif
76153+#endif
76154+
76155 static inline int is_kernel_text(unsigned long addr)
76156 {
76157 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
76158@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
76159
76160 static inline int is_kernel(unsigned long addr)
76161 {
76162+
76163+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76164+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
76165+ return 1;
76166+
76167+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
76168+#else
76169 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
76170+#endif
76171+
76172 return 1;
76173 return in_gate_area_no_mm(addr);
76174 }
76175
76176 static int is_ksym_addr(unsigned long addr)
76177 {
76178+
76179+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76180+ if (is_module_text(addr))
76181+ return 0;
76182+#endif
76183+
76184 if (all_var)
76185 return is_kernel(addr);
76186
76187@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
76188
76189 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
76190 {
76191- iter->name[0] = '\0';
76192 iter->nameoff = get_symbol_offset(new_pos);
76193 iter->pos = new_pos;
76194 }
76195@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
76196 {
76197 struct kallsym_iter *iter = m->private;
76198
76199+#ifdef CONFIG_GRKERNSEC_HIDESYM
76200+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
76201+ return 0;
76202+#endif
76203+
76204 /* Some debugging symbols have no name. Ignore them. */
76205 if (!iter->name[0])
76206 return 0;
76207@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
76208 */
76209 type = iter->exported ? toupper(iter->type) :
76210 tolower(iter->type);
76211+
76212 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
76213 type, iter->name, iter->module_name);
76214 } else
76215@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
76216 struct kallsym_iter *iter;
76217 int ret;
76218
76219- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
76220+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
76221 if (!iter)
76222 return -ENOMEM;
76223 reset_iter(iter, 0);
76224diff --git a/kernel/kcmp.c b/kernel/kcmp.c
76225index e30ac0f..3528cac 100644
76226--- a/kernel/kcmp.c
76227+++ b/kernel/kcmp.c
76228@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
76229 struct task_struct *task1, *task2;
76230 int ret;
76231
76232+#ifdef CONFIG_GRKERNSEC
76233+ return -ENOSYS;
76234+#endif
76235+
76236 rcu_read_lock();
76237
76238 /*
76239diff --git a/kernel/kexec.c b/kernel/kexec.c
76240index 59f7b55..4022f65 100644
76241--- a/kernel/kexec.c
76242+++ b/kernel/kexec.c
76243@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
76244 unsigned long flags)
76245 {
76246 struct compat_kexec_segment in;
76247- struct kexec_segment out, __user *ksegments;
76248+ struct kexec_segment out;
76249+ struct kexec_segment __user *ksegments;
76250 unsigned long i, result;
76251
76252 /* Don't allow clients that don't understand the native
76253diff --git a/kernel/kmod.c b/kernel/kmod.c
76254index 8241906..d625f2c 100644
76255--- a/kernel/kmod.c
76256+++ b/kernel/kmod.c
76257@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
76258 kfree(info->argv);
76259 }
76260
76261-static int call_modprobe(char *module_name, int wait)
76262+static int call_modprobe(char *module_name, char *module_param, int wait)
76263 {
76264 struct subprocess_info *info;
76265 static char *envp[] = {
76266@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
76267 NULL
76268 };
76269
76270- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
76271+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
76272 if (!argv)
76273 goto out;
76274
76275@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
76276 argv[1] = "-q";
76277 argv[2] = "--";
76278 argv[3] = module_name; /* check free_modprobe_argv() */
76279- argv[4] = NULL;
76280+ argv[4] = module_param;
76281+ argv[5] = NULL;
76282
76283 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
76284 NULL, free_modprobe_argv, NULL);
76285@@ -129,9 +130,8 @@ out:
76286 * If module auto-loading support is disabled then this function
76287 * becomes a no-operation.
76288 */
76289-int __request_module(bool wait, const char *fmt, ...)
76290+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
76291 {
76292- va_list args;
76293 char module_name[MODULE_NAME_LEN];
76294 unsigned int max_modprobes;
76295 int ret;
76296@@ -147,9 +147,7 @@ int __request_module(bool wait, const char *fmt, ...)
76297 */
76298 WARN_ON_ONCE(wait && current_is_async());
76299
76300- va_start(args, fmt);
76301- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
76302- va_end(args);
76303+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
76304 if (ret >= MODULE_NAME_LEN)
76305 return -ENAMETOOLONG;
76306
76307@@ -157,6 +155,20 @@ int __request_module(bool wait, const char *fmt, ...)
76308 if (ret)
76309 return ret;
76310
76311+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76312+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76313+ /* hack to workaround consolekit/udisks stupidity */
76314+ read_lock(&tasklist_lock);
76315+ if (!strcmp(current->comm, "mount") &&
76316+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
76317+ read_unlock(&tasklist_lock);
76318+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
76319+ return -EPERM;
76320+ }
76321+ read_unlock(&tasklist_lock);
76322+ }
76323+#endif
76324+
76325 /* If modprobe needs a service that is in a module, we get a recursive
76326 * loop. Limit the number of running kmod threads to max_threads/2 or
76327 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
76328@@ -185,11 +197,52 @@ int __request_module(bool wait, const char *fmt, ...)
76329
76330 trace_module_request(module_name, wait, _RET_IP_);
76331
76332- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76333+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76334
76335 atomic_dec(&kmod_concurrent);
76336 return ret;
76337 }
76338+
76339+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
76340+{
76341+ va_list args;
76342+ int ret;
76343+
76344+ va_start(args, fmt);
76345+ ret = ____request_module(wait, module_param, fmt, args);
76346+ va_end(args);
76347+
76348+ return ret;
76349+}
76350+
76351+int __request_module(bool wait, const char *fmt, ...)
76352+{
76353+ va_list args;
76354+ int ret;
76355+
76356+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76357+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76358+ char module_param[MODULE_NAME_LEN];
76359+
76360+ memset(module_param, 0, sizeof(module_param));
76361+
76362+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
76363+
76364+ va_start(args, fmt);
76365+ ret = ____request_module(wait, module_param, fmt, args);
76366+ va_end(args);
76367+
76368+ return ret;
76369+ }
76370+#endif
76371+
76372+ va_start(args, fmt);
76373+ ret = ____request_module(wait, NULL, fmt, args);
76374+ va_end(args);
76375+
76376+ return ret;
76377+}
76378+
76379 EXPORT_SYMBOL(__request_module);
76380 #endif /* CONFIG_MODULES */
76381
76382@@ -300,7 +353,7 @@ static int wait_for_helper(void *data)
76383 *
76384 * Thus the __user pointer cast is valid here.
76385 */
76386- sys_wait4(pid, (int __user *)&ret, 0, NULL);
76387+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
76388
76389 /*
76390 * If ret is 0, either ____call_usermodehelper failed and the
76391@@ -651,7 +704,7 @@ EXPORT_SYMBOL(call_usermodehelper);
76392 static int proc_cap_handler(struct ctl_table *table, int write,
76393 void __user *buffer, size_t *lenp, loff_t *ppos)
76394 {
76395- struct ctl_table t;
76396+ ctl_table_no_const t;
76397 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76398 kernel_cap_t new_cap;
76399 int err, i;
76400diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76401index bddf3b2..07b90dd 100644
76402--- a/kernel/kprobes.c
76403+++ b/kernel/kprobes.c
76404@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76405 * kernel image and loaded module images reside. This is required
76406 * so x86_64 can correctly handle the %rip-relative fixups.
76407 */
76408- kip->insns = module_alloc(PAGE_SIZE);
76409+ kip->insns = module_alloc_exec(PAGE_SIZE);
76410 if (!kip->insns) {
76411 kfree(kip);
76412 return NULL;
76413@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76414 */
76415 if (!list_is_singular(&kip->list)) {
76416 list_del(&kip->list);
76417- module_free(NULL, kip->insns);
76418+ module_free_exec(NULL, kip->insns);
76419 kfree(kip);
76420 }
76421 return 1;
76422@@ -2083,7 +2083,7 @@ static int __init init_kprobes(void)
76423 {
76424 int i, err = 0;
76425 unsigned long offset = 0, size = 0;
76426- char *modname, namebuf[128];
76427+ char *modname, namebuf[KSYM_NAME_LEN];
76428 const char *symbol_name;
76429 void *addr;
76430 struct kprobe_blackpoint *kb;
76431@@ -2168,11 +2168,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76432 kprobe_type = "k";
76433
76434 if (sym)
76435- seq_printf(pi, "%p %s %s+0x%x %s ",
76436+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76437 p->addr, kprobe_type, sym, offset,
76438 (modname ? modname : " "));
76439 else
76440- seq_printf(pi, "%p %s %p ",
76441+ seq_printf(pi, "%pK %s %pK ",
76442 p->addr, kprobe_type, p->addr);
76443
76444 if (!pp)
76445@@ -2209,7 +2209,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76446 const char *sym = NULL;
76447 unsigned int i = *(loff_t *) v;
76448 unsigned long offset = 0;
76449- char *modname, namebuf[128];
76450+ char *modname, namebuf[KSYM_NAME_LEN];
76451
76452 head = &kprobe_table[i];
76453 preempt_disable();
76454diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76455index 6ada93c..dce7d5d 100644
76456--- a/kernel/ksysfs.c
76457+++ b/kernel/ksysfs.c
76458@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76459 {
76460 if (count+1 > UEVENT_HELPER_PATH_LEN)
76461 return -ENOENT;
76462+ if (!capable(CAP_SYS_ADMIN))
76463+ return -EPERM;
76464 memcpy(uevent_helper, buf, count);
76465 uevent_helper[count] = '\0';
76466 if (count && uevent_helper[count-1] == '\n')
76467@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76468 return count;
76469 }
76470
76471-static struct bin_attribute notes_attr = {
76472+static bin_attribute_no_const notes_attr __read_only = {
76473 .attr = {
76474 .name = "notes",
76475 .mode = S_IRUGO,
76476diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76477index 1f3186b..bb7dbc6 100644
76478--- a/kernel/lockdep.c
76479+++ b/kernel/lockdep.c
76480@@ -596,6 +596,10 @@ static int static_obj(void *obj)
76481 end = (unsigned long) &_end,
76482 addr = (unsigned long) obj;
76483
76484+#ifdef CONFIG_PAX_KERNEXEC
76485+ start = ktla_ktva(start);
76486+#endif
76487+
76488 /*
76489 * static variable?
76490 */
76491@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76492 if (!static_obj(lock->key)) {
76493 debug_locks_off();
76494 printk("INFO: trying to register non-static key.\n");
76495+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76496 printk("the code is fine but needs lockdep annotation.\n");
76497 printk("turning off the locking correctness validator.\n");
76498 dump_stack();
76499@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76500 if (!class)
76501 return 0;
76502 }
76503- atomic_inc((atomic_t *)&class->ops);
76504+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76505 if (very_verbose(class)) {
76506 printk("\nacquire class [%p] %s", class->key, class->name);
76507 if (class->name_version > 1)
76508diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76509index b2c71c5..7b88d63 100644
76510--- a/kernel/lockdep_proc.c
76511+++ b/kernel/lockdep_proc.c
76512@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76513 return 0;
76514 }
76515
76516- seq_printf(m, "%p", class->key);
76517+ seq_printf(m, "%pK", class->key);
76518 #ifdef CONFIG_DEBUG_LOCKDEP
76519 seq_printf(m, " OPS:%8ld", class->ops);
76520 #endif
76521@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76522
76523 list_for_each_entry(entry, &class->locks_after, entry) {
76524 if (entry->distance == 1) {
76525- seq_printf(m, " -> [%p] ", entry->class->key);
76526+ seq_printf(m, " -> [%pK] ", entry->class->key);
76527 print_name(m, entry->class);
76528 seq_puts(m, "\n");
76529 }
76530@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76531 if (!class->key)
76532 continue;
76533
76534- seq_printf(m, "[%p] ", class->key);
76535+ seq_printf(m, "[%pK] ", class->key);
76536 print_name(m, class);
76537 seq_puts(m, "\n");
76538 }
76539@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76540 if (!i)
76541 seq_line(m, '-', 40-namelen, namelen);
76542
76543- snprintf(ip, sizeof(ip), "[<%p>]",
76544+ snprintf(ip, sizeof(ip), "[<%pK>]",
76545 (void *)class->contention_point[i]);
76546 seq_printf(m, "%40s %14lu %29s %pS\n",
76547 name, stats->contention_point[i],
76548@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76549 if (!i)
76550 seq_line(m, '-', 40-namelen, namelen);
76551
76552- snprintf(ip, sizeof(ip), "[<%p>]",
76553+ snprintf(ip, sizeof(ip), "[<%pK>]",
76554 (void *)class->contending_point[i]);
76555 seq_printf(m, "%40s %14lu %29s %pS\n",
76556 name, stats->contending_point[i],
76557diff --git a/kernel/module.c b/kernel/module.c
76558index fa53db8..6f17200 100644
76559--- a/kernel/module.c
76560+++ b/kernel/module.c
76561@@ -61,6 +61,7 @@
76562 #include <linux/pfn.h>
76563 #include <linux/bsearch.h>
76564 #include <linux/fips.h>
76565+#include <linux/grsecurity.h>
76566 #include <uapi/linux/module.h>
76567 #include "module-internal.h"
76568
76569@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76570
76571 /* Bounds of module allocation, for speeding __module_address.
76572 * Protected by module_mutex. */
76573-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76574+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76575+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76576
76577 int register_module_notifier(struct notifier_block * nb)
76578 {
76579@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76580 return true;
76581
76582 list_for_each_entry_rcu(mod, &modules, list) {
76583- struct symsearch arr[] = {
76584+ struct symsearch modarr[] = {
76585 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76586 NOT_GPL_ONLY, false },
76587 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76588@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76589 if (mod->state == MODULE_STATE_UNFORMED)
76590 continue;
76591
76592- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76593+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76594 return true;
76595 }
76596 return false;
76597@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76598 static int percpu_modalloc(struct module *mod,
76599 unsigned long size, unsigned long align)
76600 {
76601- if (align > PAGE_SIZE) {
76602+ if (align-1 >= PAGE_SIZE) {
76603 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76604 mod->name, align, PAGE_SIZE);
76605 align = PAGE_SIZE;
76606@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
76607 static ssize_t show_coresize(struct module_attribute *mattr,
76608 struct module_kobject *mk, char *buffer)
76609 {
76610- return sprintf(buffer, "%u\n", mk->mod->core_size);
76611+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76612 }
76613
76614 static struct module_attribute modinfo_coresize =
76615@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
76616 static ssize_t show_initsize(struct module_attribute *mattr,
76617 struct module_kobject *mk, char *buffer)
76618 {
76619- return sprintf(buffer, "%u\n", mk->mod->init_size);
76620+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76621 }
76622
76623 static struct module_attribute modinfo_initsize =
76624@@ -1313,7 +1315,7 @@ resolve_symbol_wait(struct module *mod,
76625 */
76626 #ifdef CONFIG_SYSFS
76627
76628-#ifdef CONFIG_KALLSYMS
76629+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76630 static inline bool sect_empty(const Elf_Shdr *sect)
76631 {
76632 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76633@@ -1453,7 +1455,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76634 {
76635 unsigned int notes, loaded, i;
76636 struct module_notes_attrs *notes_attrs;
76637- struct bin_attribute *nattr;
76638+ bin_attribute_no_const *nattr;
76639
76640 /* failed to create section attributes, so can't create notes */
76641 if (!mod->sect_attrs)
76642@@ -1565,7 +1567,7 @@ static void del_usage_links(struct module *mod)
76643 static int module_add_modinfo_attrs(struct module *mod)
76644 {
76645 struct module_attribute *attr;
76646- struct module_attribute *temp_attr;
76647+ module_attribute_no_const *temp_attr;
76648 int error = 0;
76649 int i;
76650
76651@@ -1779,21 +1781,21 @@ static void set_section_ro_nx(void *base,
76652
76653 static void unset_module_core_ro_nx(struct module *mod)
76654 {
76655- set_page_attributes(mod->module_core + mod->core_text_size,
76656- mod->module_core + mod->core_size,
76657+ set_page_attributes(mod->module_core_rw,
76658+ mod->module_core_rw + mod->core_size_rw,
76659 set_memory_x);
76660- set_page_attributes(mod->module_core,
76661- mod->module_core + mod->core_ro_size,
76662+ set_page_attributes(mod->module_core_rx,
76663+ mod->module_core_rx + mod->core_size_rx,
76664 set_memory_rw);
76665 }
76666
76667 static void unset_module_init_ro_nx(struct module *mod)
76668 {
76669- set_page_attributes(mod->module_init + mod->init_text_size,
76670- mod->module_init + mod->init_size,
76671+ set_page_attributes(mod->module_init_rw,
76672+ mod->module_init_rw + mod->init_size_rw,
76673 set_memory_x);
76674- set_page_attributes(mod->module_init,
76675- mod->module_init + mod->init_ro_size,
76676+ set_page_attributes(mod->module_init_rx,
76677+ mod->module_init_rx + mod->init_size_rx,
76678 set_memory_rw);
76679 }
76680
76681@@ -1806,14 +1808,14 @@ void set_all_modules_text_rw(void)
76682 list_for_each_entry_rcu(mod, &modules, list) {
76683 if (mod->state == MODULE_STATE_UNFORMED)
76684 continue;
76685- if ((mod->module_core) && (mod->core_text_size)) {
76686- set_page_attributes(mod->module_core,
76687- mod->module_core + mod->core_text_size,
76688+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76689+ set_page_attributes(mod->module_core_rx,
76690+ mod->module_core_rx + mod->core_size_rx,
76691 set_memory_rw);
76692 }
76693- if ((mod->module_init) && (mod->init_text_size)) {
76694- set_page_attributes(mod->module_init,
76695- mod->module_init + mod->init_text_size,
76696+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76697+ set_page_attributes(mod->module_init_rx,
76698+ mod->module_init_rx + mod->init_size_rx,
76699 set_memory_rw);
76700 }
76701 }
76702@@ -1829,14 +1831,14 @@ void set_all_modules_text_ro(void)
76703 list_for_each_entry_rcu(mod, &modules, list) {
76704 if (mod->state == MODULE_STATE_UNFORMED)
76705 continue;
76706- if ((mod->module_core) && (mod->core_text_size)) {
76707- set_page_attributes(mod->module_core,
76708- mod->module_core + mod->core_text_size,
76709+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76710+ set_page_attributes(mod->module_core_rx,
76711+ mod->module_core_rx + mod->core_size_rx,
76712 set_memory_ro);
76713 }
76714- if ((mod->module_init) && (mod->init_text_size)) {
76715- set_page_attributes(mod->module_init,
76716- mod->module_init + mod->init_text_size,
76717+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76718+ set_page_attributes(mod->module_init_rx,
76719+ mod->module_init_rx + mod->init_size_rx,
76720 set_memory_ro);
76721 }
76722 }
76723@@ -1887,16 +1889,19 @@ static void free_module(struct module *mod)
76724
76725 /* This may be NULL, but that's OK */
76726 unset_module_init_ro_nx(mod);
76727- module_free(mod, mod->module_init);
76728+ module_free(mod, mod->module_init_rw);
76729+ module_free_exec(mod, mod->module_init_rx);
76730 kfree(mod->args);
76731 percpu_modfree(mod);
76732
76733 /* Free lock-classes: */
76734- lockdep_free_key_range(mod->module_core, mod->core_size);
76735+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76736+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76737
76738 /* Finally, free the core (containing the module structure) */
76739 unset_module_core_ro_nx(mod);
76740- module_free(mod, mod->module_core);
76741+ module_free_exec(mod, mod->module_core_rx);
76742+ module_free(mod, mod->module_core_rw);
76743
76744 #ifdef CONFIG_MPU
76745 update_protections(current->mm);
76746@@ -1966,9 +1971,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76747 int ret = 0;
76748 const struct kernel_symbol *ksym;
76749
76750+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76751+ int is_fs_load = 0;
76752+ int register_filesystem_found = 0;
76753+ char *p;
76754+
76755+ p = strstr(mod->args, "grsec_modharden_fs");
76756+ if (p) {
76757+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76758+ /* copy \0 as well */
76759+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76760+ is_fs_load = 1;
76761+ }
76762+#endif
76763+
76764 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76765 const char *name = info->strtab + sym[i].st_name;
76766
76767+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76768+ /* it's a real shame this will never get ripped and copied
76769+ upstream! ;(
76770+ */
76771+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76772+ register_filesystem_found = 1;
76773+#endif
76774+
76775 switch (sym[i].st_shndx) {
76776 case SHN_COMMON:
76777 /* We compiled with -fno-common. These are not
76778@@ -1989,7 +2016,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76779 ksym = resolve_symbol_wait(mod, info, name);
76780 /* Ok if resolved. */
76781 if (ksym && !IS_ERR(ksym)) {
76782+ pax_open_kernel();
76783 sym[i].st_value = ksym->value;
76784+ pax_close_kernel();
76785 break;
76786 }
76787
76788@@ -2008,11 +2037,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76789 secbase = (unsigned long)mod_percpu(mod);
76790 else
76791 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76792+ pax_open_kernel();
76793 sym[i].st_value += secbase;
76794+ pax_close_kernel();
76795 break;
76796 }
76797 }
76798
76799+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76800+ if (is_fs_load && !register_filesystem_found) {
76801+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76802+ ret = -EPERM;
76803+ }
76804+#endif
76805+
76806 return ret;
76807 }
76808
76809@@ -2096,22 +2134,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76810 || s->sh_entsize != ~0UL
76811 || strstarts(sname, ".init"))
76812 continue;
76813- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76814+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76815+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76816+ else
76817+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76818 pr_debug("\t%s\n", sname);
76819 }
76820- switch (m) {
76821- case 0: /* executable */
76822- mod->core_size = debug_align(mod->core_size);
76823- mod->core_text_size = mod->core_size;
76824- break;
76825- case 1: /* RO: text and ro-data */
76826- mod->core_size = debug_align(mod->core_size);
76827- mod->core_ro_size = mod->core_size;
76828- break;
76829- case 3: /* whole core */
76830- mod->core_size = debug_align(mod->core_size);
76831- break;
76832- }
76833 }
76834
76835 pr_debug("Init section allocation order:\n");
76836@@ -2125,23 +2153,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76837 || s->sh_entsize != ~0UL
76838 || !strstarts(sname, ".init"))
76839 continue;
76840- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76841- | INIT_OFFSET_MASK);
76842+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76843+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76844+ else
76845+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76846+ s->sh_entsize |= INIT_OFFSET_MASK;
76847 pr_debug("\t%s\n", sname);
76848 }
76849- switch (m) {
76850- case 0: /* executable */
76851- mod->init_size = debug_align(mod->init_size);
76852- mod->init_text_size = mod->init_size;
76853- break;
76854- case 1: /* RO: text and ro-data */
76855- mod->init_size = debug_align(mod->init_size);
76856- mod->init_ro_size = mod->init_size;
76857- break;
76858- case 3: /* whole init */
76859- mod->init_size = debug_align(mod->init_size);
76860- break;
76861- }
76862 }
76863 }
76864
76865@@ -2314,7 +2332,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76866
76867 /* Put symbol section at end of init part of module. */
76868 symsect->sh_flags |= SHF_ALLOC;
76869- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76870+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76871 info->index.sym) | INIT_OFFSET_MASK;
76872 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76873
76874@@ -2331,13 +2349,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76875 }
76876
76877 /* Append room for core symbols at end of core part. */
76878- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76879- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76880- mod->core_size += strtab_size;
76881+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76882+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76883+ mod->core_size_rx += strtab_size;
76884
76885 /* Put string table section at end of init part of module. */
76886 strsect->sh_flags |= SHF_ALLOC;
76887- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76888+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76889 info->index.str) | INIT_OFFSET_MASK;
76890 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76891 }
76892@@ -2355,12 +2373,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76893 /* Make sure we get permanent strtab: don't use info->strtab. */
76894 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76895
76896+ pax_open_kernel();
76897+
76898 /* Set types up while we still have access to sections. */
76899 for (i = 0; i < mod->num_symtab; i++)
76900 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76901
76902- mod->core_symtab = dst = mod->module_core + info->symoffs;
76903- mod->core_strtab = s = mod->module_core + info->stroffs;
76904+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76905+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76906 src = mod->symtab;
76907 for (ndst = i = 0; i < mod->num_symtab; i++) {
76908 if (i == 0 ||
76909@@ -2372,6 +2392,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76910 }
76911 }
76912 mod->core_num_syms = ndst;
76913+
76914+ pax_close_kernel();
76915 }
76916 #else
76917 static inline void layout_symtab(struct module *mod, struct load_info *info)
76918@@ -2405,17 +2427,33 @@ void * __weak module_alloc(unsigned long size)
76919 return vmalloc_exec(size);
76920 }
76921
76922-static void *module_alloc_update_bounds(unsigned long size)
76923+static void *module_alloc_update_bounds_rw(unsigned long size)
76924 {
76925 void *ret = module_alloc(size);
76926
76927 if (ret) {
76928 mutex_lock(&module_mutex);
76929 /* Update module bounds. */
76930- if ((unsigned long)ret < module_addr_min)
76931- module_addr_min = (unsigned long)ret;
76932- if ((unsigned long)ret + size > module_addr_max)
76933- module_addr_max = (unsigned long)ret + size;
76934+ if ((unsigned long)ret < module_addr_min_rw)
76935+ module_addr_min_rw = (unsigned long)ret;
76936+ if ((unsigned long)ret + size > module_addr_max_rw)
76937+ module_addr_max_rw = (unsigned long)ret + size;
76938+ mutex_unlock(&module_mutex);
76939+ }
76940+ return ret;
76941+}
76942+
76943+static void *module_alloc_update_bounds_rx(unsigned long size)
76944+{
76945+ void *ret = module_alloc_exec(size);
76946+
76947+ if (ret) {
76948+ mutex_lock(&module_mutex);
76949+ /* Update module bounds. */
76950+ if ((unsigned long)ret < module_addr_min_rx)
76951+ module_addr_min_rx = (unsigned long)ret;
76952+ if ((unsigned long)ret + size > module_addr_max_rx)
76953+ module_addr_max_rx = (unsigned long)ret + size;
76954 mutex_unlock(&module_mutex);
76955 }
76956 return ret;
76957@@ -2691,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76958 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76959 {
76960 const char *modmagic = get_modinfo(info, "vermagic");
76961+ const char *license = get_modinfo(info, "license");
76962 int err;
76963
76964+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76965+ if (!license || !license_is_gpl_compatible(license))
76966+ return -ENOEXEC;
76967+#endif
76968+
76969 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76970 modmagic = NULL;
76971
76972@@ -2718,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76973 }
76974
76975 /* Set up license info based on the info section */
76976- set_license(mod, get_modinfo(info, "license"));
76977+ set_license(mod, license);
76978
76979 return 0;
76980 }
76981@@ -2799,7 +2843,7 @@ static int move_module(struct module *mod, struct load_info *info)
76982 void *ptr;
76983
76984 /* Do the allocs. */
76985- ptr = module_alloc_update_bounds(mod->core_size);
76986+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76987 /*
76988 * The pointer to this block is stored in the module structure
76989 * which is inside the block. Just mark it as not being a
76990@@ -2809,11 +2853,11 @@ static int move_module(struct module *mod, struct load_info *info)
76991 if (!ptr)
76992 return -ENOMEM;
76993
76994- memset(ptr, 0, mod->core_size);
76995- mod->module_core = ptr;
76996+ memset(ptr, 0, mod->core_size_rw);
76997+ mod->module_core_rw = ptr;
76998
76999- if (mod->init_size) {
77000- ptr = module_alloc_update_bounds(mod->init_size);
77001+ if (mod->init_size_rw) {
77002+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
77003 /*
77004 * The pointer to this block is stored in the module structure
77005 * which is inside the block. This block doesn't need to be
77006@@ -2822,13 +2866,45 @@ static int move_module(struct module *mod, struct load_info *info)
77007 */
77008 kmemleak_ignore(ptr);
77009 if (!ptr) {
77010- module_free(mod, mod->module_core);
77011+ module_free(mod, mod->module_core_rw);
77012 return -ENOMEM;
77013 }
77014- memset(ptr, 0, mod->init_size);
77015- mod->module_init = ptr;
77016+ memset(ptr, 0, mod->init_size_rw);
77017+ mod->module_init_rw = ptr;
77018 } else
77019- mod->module_init = NULL;
77020+ mod->module_init_rw = NULL;
77021+
77022+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
77023+ kmemleak_not_leak(ptr);
77024+ if (!ptr) {
77025+ if (mod->module_init_rw)
77026+ module_free(mod, mod->module_init_rw);
77027+ module_free(mod, mod->module_core_rw);
77028+ return -ENOMEM;
77029+ }
77030+
77031+ pax_open_kernel();
77032+ memset(ptr, 0, mod->core_size_rx);
77033+ pax_close_kernel();
77034+ mod->module_core_rx = ptr;
77035+
77036+ if (mod->init_size_rx) {
77037+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
77038+ kmemleak_ignore(ptr);
77039+ if (!ptr && mod->init_size_rx) {
77040+ module_free_exec(mod, mod->module_core_rx);
77041+ if (mod->module_init_rw)
77042+ module_free(mod, mod->module_init_rw);
77043+ module_free(mod, mod->module_core_rw);
77044+ return -ENOMEM;
77045+ }
77046+
77047+ pax_open_kernel();
77048+ memset(ptr, 0, mod->init_size_rx);
77049+ pax_close_kernel();
77050+ mod->module_init_rx = ptr;
77051+ } else
77052+ mod->module_init_rx = NULL;
77053
77054 /* Transfer each section which specifies SHF_ALLOC */
77055 pr_debug("final section addresses:\n");
77056@@ -2839,16 +2915,45 @@ static int move_module(struct module *mod, struct load_info *info)
77057 if (!(shdr->sh_flags & SHF_ALLOC))
77058 continue;
77059
77060- if (shdr->sh_entsize & INIT_OFFSET_MASK)
77061- dest = mod->module_init
77062- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77063- else
77064- dest = mod->module_core + shdr->sh_entsize;
77065+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
77066+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77067+ dest = mod->module_init_rw
77068+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77069+ else
77070+ dest = mod->module_init_rx
77071+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
77072+ } else {
77073+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
77074+ dest = mod->module_core_rw + shdr->sh_entsize;
77075+ else
77076+ dest = mod->module_core_rx + shdr->sh_entsize;
77077+ }
77078+
77079+ if (shdr->sh_type != SHT_NOBITS) {
77080+
77081+#ifdef CONFIG_PAX_KERNEXEC
77082+#ifdef CONFIG_X86_64
77083+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
77084+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
77085+#endif
77086+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
77087+ pax_open_kernel();
77088+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77089+ pax_close_kernel();
77090+ } else
77091+#endif
77092
77093- if (shdr->sh_type != SHT_NOBITS)
77094 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
77095+ }
77096 /* Update sh_addr to point to copy in image. */
77097- shdr->sh_addr = (unsigned long)dest;
77098+
77099+#ifdef CONFIG_PAX_KERNEXEC
77100+ if (shdr->sh_flags & SHF_EXECINSTR)
77101+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
77102+ else
77103+#endif
77104+
77105+ shdr->sh_addr = (unsigned long)dest;
77106 pr_debug("\t0x%lx %s\n",
77107 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
77108 }
77109@@ -2905,12 +3010,12 @@ static void flush_module_icache(const struct module *mod)
77110 * Do it before processing of module parameters, so the module
77111 * can provide parameter accessor functions of its own.
77112 */
77113- if (mod->module_init)
77114- flush_icache_range((unsigned long)mod->module_init,
77115- (unsigned long)mod->module_init
77116- + mod->init_size);
77117- flush_icache_range((unsigned long)mod->module_core,
77118- (unsigned long)mod->module_core + mod->core_size);
77119+ if (mod->module_init_rx)
77120+ flush_icache_range((unsigned long)mod->module_init_rx,
77121+ (unsigned long)mod->module_init_rx
77122+ + mod->init_size_rx);
77123+ flush_icache_range((unsigned long)mod->module_core_rx,
77124+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
77125
77126 set_fs(old_fs);
77127 }
77128@@ -2977,8 +3082,10 @@ static int alloc_module_percpu(struct module *mod, struct load_info *info)
77129 static void module_deallocate(struct module *mod, struct load_info *info)
77130 {
77131 percpu_modfree(mod);
77132- module_free(mod, mod->module_init);
77133- module_free(mod, mod->module_core);
77134+ module_free_exec(mod, mod->module_init_rx);
77135+ module_free_exec(mod, mod->module_core_rx);
77136+ module_free(mod, mod->module_init_rw);
77137+ module_free(mod, mod->module_core_rw);
77138 }
77139
77140 int __weak module_finalize(const Elf_Ehdr *hdr,
77141@@ -2991,7 +3098,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
77142 static int post_relocation(struct module *mod, const struct load_info *info)
77143 {
77144 /* Sort exception table now relocations are done. */
77145+ pax_open_kernel();
77146 sort_extable(mod->extable, mod->extable + mod->num_exentries);
77147+ pax_close_kernel();
77148
77149 /* Copy relocated percpu area over. */
77150 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
77151@@ -3045,16 +3154,16 @@ static int do_init_module(struct module *mod)
77152 MODULE_STATE_COMING, mod);
77153
77154 /* Set RO and NX regions for core */
77155- set_section_ro_nx(mod->module_core,
77156- mod->core_text_size,
77157- mod->core_ro_size,
77158- mod->core_size);
77159+ set_section_ro_nx(mod->module_core_rx,
77160+ mod->core_size_rx,
77161+ mod->core_size_rx,
77162+ mod->core_size_rx);
77163
77164 /* Set RO and NX regions for init */
77165- set_section_ro_nx(mod->module_init,
77166- mod->init_text_size,
77167- mod->init_ro_size,
77168- mod->init_size);
77169+ set_section_ro_nx(mod->module_init_rx,
77170+ mod->init_size_rx,
77171+ mod->init_size_rx,
77172+ mod->init_size_rx);
77173
77174 do_mod_ctors(mod);
77175 /* Start the module */
77176@@ -3116,11 +3225,12 @@ static int do_init_module(struct module *mod)
77177 mod->strtab = mod->core_strtab;
77178 #endif
77179 unset_module_init_ro_nx(mod);
77180- module_free(mod, mod->module_init);
77181- mod->module_init = NULL;
77182- mod->init_size = 0;
77183- mod->init_ro_size = 0;
77184- mod->init_text_size = 0;
77185+ module_free(mod, mod->module_init_rw);
77186+ module_free_exec(mod, mod->module_init_rx);
77187+ mod->module_init_rw = NULL;
77188+ mod->module_init_rx = NULL;
77189+ mod->init_size_rw = 0;
77190+ mod->init_size_rx = 0;
77191 mutex_unlock(&module_mutex);
77192 wake_up_all(&module_wq);
77193
77194@@ -3252,9 +3362,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
77195 if (err)
77196 goto free_unload;
77197
77198+ /* Now copy in args */
77199+ mod->args = strndup_user(uargs, ~0UL >> 1);
77200+ if (IS_ERR(mod->args)) {
77201+ err = PTR_ERR(mod->args);
77202+ goto free_unload;
77203+ }
77204+
77205 /* Set up MODINFO_ATTR fields */
77206 setup_modinfo(mod, info);
77207
77208+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77209+ {
77210+ char *p, *p2;
77211+
77212+ if (strstr(mod->args, "grsec_modharden_netdev")) {
77213+ 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);
77214+ err = -EPERM;
77215+ goto free_modinfo;
77216+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
77217+ p += sizeof("grsec_modharden_normal") - 1;
77218+ p2 = strstr(p, "_");
77219+ if (p2) {
77220+ *p2 = '\0';
77221+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
77222+ *p2 = '_';
77223+ }
77224+ err = -EPERM;
77225+ goto free_modinfo;
77226+ }
77227+ }
77228+#endif
77229+
77230 /* Fix up syms, so that st_value is a pointer to location. */
77231 err = simplify_symbols(mod, info);
77232 if (err < 0)
77233@@ -3270,13 +3409,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
77234
77235 flush_module_icache(mod);
77236
77237- /* Now copy in args */
77238- mod->args = strndup_user(uargs, ~0UL >> 1);
77239- if (IS_ERR(mod->args)) {
77240- err = PTR_ERR(mod->args);
77241- goto free_arch_cleanup;
77242- }
77243-
77244 dynamic_debug_setup(info->debug, info->num_debug);
77245
77246 /* Finally it's fully formed, ready to start executing. */
77247@@ -3311,11 +3443,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
77248 ddebug_cleanup:
77249 dynamic_debug_remove(info->debug);
77250 synchronize_sched();
77251- kfree(mod->args);
77252- free_arch_cleanup:
77253 module_arch_cleanup(mod);
77254 free_modinfo:
77255 free_modinfo(mod);
77256+ kfree(mod->args);
77257 free_unload:
77258 module_unload_free(mod);
77259 unlink_mod:
77260@@ -3398,10 +3529,16 @@ static const char *get_ksymbol(struct module *mod,
77261 unsigned long nextval;
77262
77263 /* At worse, next value is at end of module */
77264- if (within_module_init(addr, mod))
77265- nextval = (unsigned long)mod->module_init+mod->init_text_size;
77266+ if (within_module_init_rx(addr, mod))
77267+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
77268+ else if (within_module_init_rw(addr, mod))
77269+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
77270+ else if (within_module_core_rx(addr, mod))
77271+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
77272+ else if (within_module_core_rw(addr, mod))
77273+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
77274 else
77275- nextval = (unsigned long)mod->module_core+mod->core_text_size;
77276+ return NULL;
77277
77278 /* Scan for closest preceding symbol, and next symbol. (ELF
77279 starts real symbols at 1). */
77280@@ -3654,7 +3791,7 @@ static int m_show(struct seq_file *m, void *p)
77281 return 0;
77282
77283 seq_printf(m, "%s %u",
77284- mod->name, mod->init_size + mod->core_size);
77285+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
77286 print_unload_info(m, mod);
77287
77288 /* Informative for users. */
77289@@ -3663,7 +3800,7 @@ static int m_show(struct seq_file *m, void *p)
77290 mod->state == MODULE_STATE_COMING ? "Loading":
77291 "Live");
77292 /* Used by oprofile and other similar tools. */
77293- seq_printf(m, " 0x%pK", mod->module_core);
77294+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
77295
77296 /* Taints info */
77297 if (mod->taints)
77298@@ -3699,7 +3836,17 @@ static const struct file_operations proc_modules_operations = {
77299
77300 static int __init proc_modules_init(void)
77301 {
77302+#ifndef CONFIG_GRKERNSEC_HIDESYM
77303+#ifdef CONFIG_GRKERNSEC_PROC_USER
77304+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77305+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77306+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
77307+#else
77308 proc_create("modules", 0, NULL, &proc_modules_operations);
77309+#endif
77310+#else
77311+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77312+#endif
77313 return 0;
77314 }
77315 module_init(proc_modules_init);
77316@@ -3760,14 +3907,14 @@ struct module *__module_address(unsigned long addr)
77317 {
77318 struct module *mod;
77319
77320- if (addr < module_addr_min || addr > module_addr_max)
77321+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
77322+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
77323 return NULL;
77324
77325 list_for_each_entry_rcu(mod, &modules, list) {
77326 if (mod->state == MODULE_STATE_UNFORMED)
77327 continue;
77328- if (within_module_core(addr, mod)
77329- || within_module_init(addr, mod))
77330+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
77331 return mod;
77332 }
77333 return NULL;
77334@@ -3802,11 +3949,20 @@ bool is_module_text_address(unsigned long addr)
77335 */
77336 struct module *__module_text_address(unsigned long addr)
77337 {
77338- struct module *mod = __module_address(addr);
77339+ struct module *mod;
77340+
77341+#ifdef CONFIG_X86_32
77342+ addr = ktla_ktva(addr);
77343+#endif
77344+
77345+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
77346+ return NULL;
77347+
77348+ mod = __module_address(addr);
77349+
77350 if (mod) {
77351 /* Make sure it's within the text section. */
77352- if (!within(addr, mod->module_init, mod->init_text_size)
77353- && !within(addr, mod->module_core, mod->core_text_size))
77354+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
77355 mod = NULL;
77356 }
77357 return mod;
77358diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
77359index 7e3443f..b2a1e6b 100644
77360--- a/kernel/mutex-debug.c
77361+++ b/kernel/mutex-debug.c
77362@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
77363 }
77364
77365 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77366- struct thread_info *ti)
77367+ struct task_struct *task)
77368 {
77369 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
77370
77371 /* Mark the current thread as blocked on the lock: */
77372- ti->task->blocked_on = waiter;
77373+ task->blocked_on = waiter;
77374 }
77375
77376 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77377- struct thread_info *ti)
77378+ struct task_struct *task)
77379 {
77380 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
77381- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
77382- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
77383- ti->task->blocked_on = NULL;
77384+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
77385+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
77386+ task->blocked_on = NULL;
77387
77388 list_del_init(&waiter->list);
77389 waiter->task = NULL;
77390diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
77391index 0799fd3..d06ae3b 100644
77392--- a/kernel/mutex-debug.h
77393+++ b/kernel/mutex-debug.h
77394@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
77395 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77396 extern void debug_mutex_add_waiter(struct mutex *lock,
77397 struct mutex_waiter *waiter,
77398- struct thread_info *ti);
77399+ struct task_struct *task);
77400 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77401- struct thread_info *ti);
77402+ struct task_struct *task);
77403 extern void debug_mutex_unlock(struct mutex *lock);
77404 extern void debug_mutex_init(struct mutex *lock, const char *name,
77405 struct lock_class_key *key);
77406diff --git a/kernel/mutex.c b/kernel/mutex.c
77407index ad53a66..f1bf8bc 100644
77408--- a/kernel/mutex.c
77409+++ b/kernel/mutex.c
77410@@ -134,7 +134,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
77411 node->locked = 1;
77412 return;
77413 }
77414- ACCESS_ONCE(prev->next) = node;
77415+ ACCESS_ONCE_RW(prev->next) = node;
77416 smp_wmb();
77417 /* Wait until the lock holder passes the lock down */
77418 while (!ACCESS_ONCE(node->locked))
77419@@ -155,7 +155,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
77420 while (!(next = ACCESS_ONCE(node->next)))
77421 arch_mutex_cpu_relax();
77422 }
77423- ACCESS_ONCE(next->locked) = 1;
77424+ ACCESS_ONCE_RW(next->locked) = 1;
77425 smp_wmb();
77426 }
77427
77428@@ -341,7 +341,7 @@ slowpath:
77429 spin_lock_mutex(&lock->wait_lock, flags);
77430
77431 debug_mutex_lock_common(lock, &waiter);
77432- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77433+ debug_mutex_add_waiter(lock, &waiter, task);
77434
77435 /* add waiting tasks to the end of the waitqueue (FIFO): */
77436 list_add_tail(&waiter.list, &lock->wait_list);
77437@@ -371,8 +371,7 @@ slowpath:
77438 * TASK_UNINTERRUPTIBLE case.)
77439 */
77440 if (unlikely(signal_pending_state(state, task))) {
77441- mutex_remove_waiter(lock, &waiter,
77442- task_thread_info(task));
77443+ mutex_remove_waiter(lock, &waiter, task);
77444 mutex_release(&lock->dep_map, 1, ip);
77445 spin_unlock_mutex(&lock->wait_lock, flags);
77446
77447@@ -391,7 +390,7 @@ slowpath:
77448 done:
77449 lock_acquired(&lock->dep_map, ip);
77450 /* got the lock - rejoice! */
77451- mutex_remove_waiter(lock, &waiter, current_thread_info());
77452+ mutex_remove_waiter(lock, &waiter, task);
77453 mutex_set_owner(lock);
77454
77455 /* set it to 0 if there are no waiters left: */
77456diff --git a/kernel/notifier.c b/kernel/notifier.c
77457index 2d5cc4c..d9ea600 100644
77458--- a/kernel/notifier.c
77459+++ b/kernel/notifier.c
77460@@ -5,6 +5,7 @@
77461 #include <linux/rcupdate.h>
77462 #include <linux/vmalloc.h>
77463 #include <linux/reboot.h>
77464+#include <linux/mm.h>
77465
77466 /*
77467 * Notifier list for kernel code which wants to be called
77468@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77469 while ((*nl) != NULL) {
77470 if (n->priority > (*nl)->priority)
77471 break;
77472- nl = &((*nl)->next);
77473+ nl = (struct notifier_block **)&((*nl)->next);
77474 }
77475- n->next = *nl;
77476+ pax_open_kernel();
77477+ *(const void **)&n->next = *nl;
77478 rcu_assign_pointer(*nl, n);
77479+ pax_close_kernel();
77480 return 0;
77481 }
77482
77483@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77484 return 0;
77485 if (n->priority > (*nl)->priority)
77486 break;
77487- nl = &((*nl)->next);
77488+ nl = (struct notifier_block **)&((*nl)->next);
77489 }
77490- n->next = *nl;
77491+ pax_open_kernel();
77492+ *(const void **)&n->next = *nl;
77493 rcu_assign_pointer(*nl, n);
77494+ pax_close_kernel();
77495 return 0;
77496 }
77497
77498@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77499 {
77500 while ((*nl) != NULL) {
77501 if ((*nl) == n) {
77502+ pax_open_kernel();
77503 rcu_assign_pointer(*nl, n->next);
77504+ pax_close_kernel();
77505 return 0;
77506 }
77507- nl = &((*nl)->next);
77508+ nl = (struct notifier_block **)&((*nl)->next);
77509 }
77510 return -ENOENT;
77511 }
77512diff --git a/kernel/panic.c b/kernel/panic.c
77513index 167ec09..0dda5f9 100644
77514--- a/kernel/panic.c
77515+++ b/kernel/panic.c
77516@@ -400,7 +400,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77517 unsigned taint, struct slowpath_args *args)
77518 {
77519 printk(KERN_WARNING "------------[ cut here ]------------\n");
77520- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77521+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77522
77523 if (args)
77524 vprintk(args->fmt, args->args);
77525@@ -453,7 +453,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77526 */
77527 void __stack_chk_fail(void)
77528 {
77529- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77530+ dump_stack();
77531+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77532 __builtin_return_address(0));
77533 }
77534 EXPORT_SYMBOL(__stack_chk_fail);
77535diff --git a/kernel/pid.c b/kernel/pid.c
77536index 0db3e79..95b9dc2 100644
77537--- a/kernel/pid.c
77538+++ b/kernel/pid.c
77539@@ -33,6 +33,7 @@
77540 #include <linux/rculist.h>
77541 #include <linux/bootmem.h>
77542 #include <linux/hash.h>
77543+#include <linux/security.h>
77544 #include <linux/pid_namespace.h>
77545 #include <linux/init_task.h>
77546 #include <linux/syscalls.h>
77547@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77548
77549 int pid_max = PID_MAX_DEFAULT;
77550
77551-#define RESERVED_PIDS 300
77552+#define RESERVED_PIDS 500
77553
77554 int pid_max_min = RESERVED_PIDS + 1;
77555 int pid_max_max = PID_MAX_LIMIT;
77556@@ -442,10 +443,18 @@ EXPORT_SYMBOL(pid_task);
77557 */
77558 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77559 {
77560+ struct task_struct *task;
77561+
77562 rcu_lockdep_assert(rcu_read_lock_held(),
77563 "find_task_by_pid_ns() needs rcu_read_lock()"
77564 " protection");
77565- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77566+
77567+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77568+
77569+ if (gr_pid_is_chrooted(task))
77570+ return NULL;
77571+
77572+ return task;
77573 }
77574
77575 struct task_struct *find_task_by_vpid(pid_t vnr)
77576@@ -453,6 +462,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77577 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77578 }
77579
77580+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77581+{
77582+ rcu_lockdep_assert(rcu_read_lock_held(),
77583+ "find_task_by_pid_ns() needs rcu_read_lock()"
77584+ " protection");
77585+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77586+}
77587+
77588 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77589 {
77590 struct pid *pid;
77591diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77592index 6917e8e..9909aeb 100644
77593--- a/kernel/pid_namespace.c
77594+++ b/kernel/pid_namespace.c
77595@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77596 void __user *buffer, size_t *lenp, loff_t *ppos)
77597 {
77598 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77599- struct ctl_table tmp = *table;
77600+ ctl_table_no_const tmp = *table;
77601
77602 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77603 return -EPERM;
77604diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77605index 42670e9..8719c2f 100644
77606--- a/kernel/posix-cpu-timers.c
77607+++ b/kernel/posix-cpu-timers.c
77608@@ -1636,14 +1636,14 @@ struct k_clock clock_posix_cpu = {
77609
77610 static __init int init_posix_cpu_timers(void)
77611 {
77612- struct k_clock process = {
77613+ static struct k_clock process = {
77614 .clock_getres = process_cpu_clock_getres,
77615 .clock_get = process_cpu_clock_get,
77616 .timer_create = process_cpu_timer_create,
77617 .nsleep = process_cpu_nsleep,
77618 .nsleep_restart = process_cpu_nsleep_restart,
77619 };
77620- struct k_clock thread = {
77621+ static struct k_clock thread = {
77622 .clock_getres = thread_cpu_clock_getres,
77623 .clock_get = thread_cpu_clock_get,
77624 .timer_create = thread_cpu_timer_create,
77625diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77626index 424c2d4..a9194f7 100644
77627--- a/kernel/posix-timers.c
77628+++ b/kernel/posix-timers.c
77629@@ -43,6 +43,7 @@
77630 #include <linux/hash.h>
77631 #include <linux/posix-clock.h>
77632 #include <linux/posix-timers.h>
77633+#include <linux/grsecurity.h>
77634 #include <linux/syscalls.h>
77635 #include <linux/wait.h>
77636 #include <linux/workqueue.h>
77637@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
77638 * which we beg off on and pass to do_sys_settimeofday().
77639 */
77640
77641-static struct k_clock posix_clocks[MAX_CLOCKS];
77642+static struct k_clock *posix_clocks[MAX_CLOCKS];
77643
77644 /*
77645 * These ones are defined below.
77646@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
77647 */
77648 static __init int init_posix_timers(void)
77649 {
77650- struct k_clock clock_realtime = {
77651+ static struct k_clock clock_realtime = {
77652 .clock_getres = hrtimer_get_res,
77653 .clock_get = posix_clock_realtime_get,
77654 .clock_set = posix_clock_realtime_set,
77655@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
77656 .timer_get = common_timer_get,
77657 .timer_del = common_timer_del,
77658 };
77659- struct k_clock clock_monotonic = {
77660+ static struct k_clock clock_monotonic = {
77661 .clock_getres = hrtimer_get_res,
77662 .clock_get = posix_ktime_get_ts,
77663 .nsleep = common_nsleep,
77664@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
77665 .timer_get = common_timer_get,
77666 .timer_del = common_timer_del,
77667 };
77668- struct k_clock clock_monotonic_raw = {
77669+ static struct k_clock clock_monotonic_raw = {
77670 .clock_getres = hrtimer_get_res,
77671 .clock_get = posix_get_monotonic_raw,
77672 };
77673- struct k_clock clock_realtime_coarse = {
77674+ static struct k_clock clock_realtime_coarse = {
77675 .clock_getres = posix_get_coarse_res,
77676 .clock_get = posix_get_realtime_coarse,
77677 };
77678- struct k_clock clock_monotonic_coarse = {
77679+ static struct k_clock clock_monotonic_coarse = {
77680 .clock_getres = posix_get_coarse_res,
77681 .clock_get = posix_get_monotonic_coarse,
77682 };
77683- struct k_clock clock_tai = {
77684+ static struct k_clock clock_tai = {
77685 .clock_getres = hrtimer_get_res,
77686 .clock_get = posix_get_tai,
77687 .nsleep = common_nsleep,
77688@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
77689 .timer_get = common_timer_get,
77690 .timer_del = common_timer_del,
77691 };
77692- struct k_clock clock_boottime = {
77693+ static struct k_clock clock_boottime = {
77694 .clock_getres = hrtimer_get_res,
77695 .clock_get = posix_get_boottime,
77696 .nsleep = common_nsleep,
77697@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77698 return;
77699 }
77700
77701- posix_clocks[clock_id] = *new_clock;
77702+ posix_clocks[clock_id] = new_clock;
77703 }
77704 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77705
77706@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77707 return (id & CLOCKFD_MASK) == CLOCKFD ?
77708 &clock_posix_dynamic : &clock_posix_cpu;
77709
77710- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77711+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77712 return NULL;
77713- return &posix_clocks[id];
77714+ return posix_clocks[id];
77715 }
77716
77717 static int common_timer_create(struct k_itimer *new_timer)
77718@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77719 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77720 return -EFAULT;
77721
77722+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77723+ have their clock_set fptr set to a nosettime dummy function
77724+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77725+ call common_clock_set, which calls do_sys_settimeofday, which
77726+ we hook
77727+ */
77728+
77729 return kc->clock_set(which_clock, &new_tp);
77730 }
77731
77732diff --git a/kernel/power/process.c b/kernel/power/process.c
77733index 98088e0..aaf95c0 100644
77734--- a/kernel/power/process.c
77735+++ b/kernel/power/process.c
77736@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77737 u64 elapsed_csecs64;
77738 unsigned int elapsed_csecs;
77739 bool wakeup = false;
77740+ bool timedout = false;
77741
77742 do_gettimeofday(&start);
77743
77744@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77745
77746 while (true) {
77747 todo = 0;
77748+ if (time_after(jiffies, end_time))
77749+ timedout = true;
77750 read_lock(&tasklist_lock);
77751 do_each_thread(g, p) {
77752 if (p == current || !freeze_task(p))
77753 continue;
77754
77755- if (!freezer_should_skip(p))
77756+ if (!freezer_should_skip(p)) {
77757 todo++;
77758+ if (timedout) {
77759+ printk(KERN_ERR "Task refusing to freeze:\n");
77760+ sched_show_task(p);
77761+ }
77762+ }
77763 } while_each_thread(g, p);
77764 read_unlock(&tasklist_lock);
77765
77766@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77767 todo += wq_busy;
77768 }
77769
77770- if (!todo || time_after(jiffies, end_time))
77771+ if (!todo || timedout)
77772 break;
77773
77774 if (pm_wakeup_pending()) {
77775diff --git a/kernel/printk.c b/kernel/printk.c
77776index 8212c1a..eb61021 100644
77777--- a/kernel/printk.c
77778+++ b/kernel/printk.c
77779@@ -390,6 +390,11 @@ static int check_syslog_permissions(int type, bool from_file)
77780 if (from_file && type != SYSLOG_ACTION_OPEN)
77781 return 0;
77782
77783+#ifdef CONFIG_GRKERNSEC_DMESG
77784+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77785+ return -EPERM;
77786+#endif
77787+
77788 if (syslog_action_restricted(type)) {
77789 if (capable(CAP_SYSLOG))
77790 return 0;
77791diff --git a/kernel/profile.c b/kernel/profile.c
77792index 0bf4007..6234708 100644
77793--- a/kernel/profile.c
77794+++ b/kernel/profile.c
77795@@ -37,7 +37,7 @@ struct profile_hit {
77796 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
77797 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
77798
77799-static atomic_t *prof_buffer;
77800+static atomic_unchecked_t *prof_buffer;
77801 static unsigned long prof_len, prof_shift;
77802
77803 int prof_on __read_mostly;
77804@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
77805 hits[i].pc = 0;
77806 continue;
77807 }
77808- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77809+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77810 hits[i].hits = hits[i].pc = 0;
77811 }
77812 }
77813@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77814 * Add the current hit(s) and flush the write-queue out
77815 * to the global buffer:
77816 */
77817- atomic_add(nr_hits, &prof_buffer[pc]);
77818+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77819 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77820- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77821+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77822 hits[i].pc = hits[i].hits = 0;
77823 }
77824 out:
77825@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77826 {
77827 unsigned long pc;
77828 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77829- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77830+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77831 }
77832 #endif /* !CONFIG_SMP */
77833
77834@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77835 return -EFAULT;
77836 buf++; p++; count--; read++;
77837 }
77838- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77839+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77840 if (copy_to_user(buf, (void *)pnt, count))
77841 return -EFAULT;
77842 read += count;
77843@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77844 }
77845 #endif
77846 profile_discard_flip_buffers();
77847- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77848+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77849 return count;
77850 }
77851
77852diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77853index 335a7ae..3bbbceb 100644
77854--- a/kernel/ptrace.c
77855+++ b/kernel/ptrace.c
77856@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77857 if (seize)
77858 flags |= PT_SEIZED;
77859 rcu_read_lock();
77860- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77861+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77862 flags |= PT_PTRACE_CAP;
77863 rcu_read_unlock();
77864 task->ptrace = flags;
77865@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77866 break;
77867 return -EIO;
77868 }
77869- if (copy_to_user(dst, buf, retval))
77870+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77871 return -EFAULT;
77872 copied += retval;
77873 src += retval;
77874@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
77875 bool seized = child->ptrace & PT_SEIZED;
77876 int ret = -EIO;
77877 siginfo_t siginfo, *si;
77878- void __user *datavp = (void __user *) data;
77879+ void __user *datavp = (__force void __user *) data;
77880 unsigned long __user *datalp = datavp;
77881 unsigned long flags;
77882
77883@@ -1011,14 +1011,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77884 goto out;
77885 }
77886
77887+ if (gr_handle_ptrace(child, request)) {
77888+ ret = -EPERM;
77889+ goto out_put_task_struct;
77890+ }
77891+
77892 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77893 ret = ptrace_attach(child, request, addr, data);
77894 /*
77895 * Some architectures need to do book-keeping after
77896 * a ptrace attach.
77897 */
77898- if (!ret)
77899+ if (!ret) {
77900 arch_ptrace_attach(child);
77901+ gr_audit_ptrace(child);
77902+ }
77903 goto out_put_task_struct;
77904 }
77905
77906@@ -1046,7 +1053,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77907 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77908 if (copied != sizeof(tmp))
77909 return -EIO;
77910- return put_user(tmp, (unsigned long __user *)data);
77911+ return put_user(tmp, (__force unsigned long __user *)data);
77912 }
77913
77914 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77915@@ -1140,7 +1147,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77916 }
77917
77918 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77919- compat_long_t addr, compat_long_t data)
77920+ compat_ulong_t addr, compat_ulong_t data)
77921 {
77922 struct task_struct *child;
77923 long ret;
77924@@ -1156,14 +1163,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77925 goto out;
77926 }
77927
77928+ if (gr_handle_ptrace(child, request)) {
77929+ ret = -EPERM;
77930+ goto out_put_task_struct;
77931+ }
77932+
77933 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77934 ret = ptrace_attach(child, request, addr, data);
77935 /*
77936 * Some architectures need to do book-keeping after
77937 * a ptrace attach.
77938 */
77939- if (!ret)
77940+ if (!ret) {
77941 arch_ptrace_attach(child);
77942+ gr_audit_ptrace(child);
77943+ }
77944 goto out_put_task_struct;
77945 }
77946
77947diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
77948index 48ab703..07561d4 100644
77949--- a/kernel/rcupdate.c
77950+++ b/kernel/rcupdate.c
77951@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
77952 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77953 */
77954 if (till_stall_check < 3) {
77955- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77956+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77957 till_stall_check = 3;
77958 } else if (till_stall_check > 300) {
77959- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77960+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77961 till_stall_check = 300;
77962 }
77963 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77964diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77965index a0714a5..2ab5e34 100644
77966--- a/kernel/rcutiny.c
77967+++ b/kernel/rcutiny.c
77968@@ -46,7 +46,7 @@
77969 struct rcu_ctrlblk;
77970 static void invoke_rcu_callbacks(void);
77971 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77972-static void rcu_process_callbacks(struct softirq_action *unused);
77973+static void rcu_process_callbacks(void);
77974 static void __call_rcu(struct rcu_head *head,
77975 void (*func)(struct rcu_head *rcu),
77976 struct rcu_ctrlblk *rcp);
77977@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77978 rcu_is_callbacks_kthread()));
77979 }
77980
77981-static void rcu_process_callbacks(struct softirq_action *unused)
77982+static void rcu_process_callbacks(void)
77983 {
77984 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77985 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77986diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77987index 8a23300..4255818 100644
77988--- a/kernel/rcutiny_plugin.h
77989+++ b/kernel/rcutiny_plugin.h
77990@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
77991 have_rcu_kthread_work = morework;
77992 local_irq_restore(flags);
77993 if (work)
77994- rcu_process_callbacks(NULL);
77995+ rcu_process_callbacks();
77996 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77997 }
77998
77999diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
78000index e1f3a8c..42c94a2 100644
78001--- a/kernel/rcutorture.c
78002+++ b/kernel/rcutorture.c
78003@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
78004 { 0 };
78005 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
78006 { 0 };
78007-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
78008-static atomic_t n_rcu_torture_alloc;
78009-static atomic_t n_rcu_torture_alloc_fail;
78010-static atomic_t n_rcu_torture_free;
78011-static atomic_t n_rcu_torture_mberror;
78012-static atomic_t n_rcu_torture_error;
78013+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
78014+static atomic_unchecked_t n_rcu_torture_alloc;
78015+static atomic_unchecked_t n_rcu_torture_alloc_fail;
78016+static atomic_unchecked_t n_rcu_torture_free;
78017+static atomic_unchecked_t n_rcu_torture_mberror;
78018+static atomic_unchecked_t n_rcu_torture_error;
78019 static long n_rcu_torture_barrier_error;
78020 static long n_rcu_torture_boost_ktrerror;
78021 static long n_rcu_torture_boost_rterror;
78022@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
78023
78024 spin_lock_bh(&rcu_torture_lock);
78025 if (list_empty(&rcu_torture_freelist)) {
78026- atomic_inc(&n_rcu_torture_alloc_fail);
78027+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
78028 spin_unlock_bh(&rcu_torture_lock);
78029 return NULL;
78030 }
78031- atomic_inc(&n_rcu_torture_alloc);
78032+ atomic_inc_unchecked(&n_rcu_torture_alloc);
78033 p = rcu_torture_freelist.next;
78034 list_del_init(p);
78035 spin_unlock_bh(&rcu_torture_lock);
78036@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
78037 static void
78038 rcu_torture_free(struct rcu_torture *p)
78039 {
78040- atomic_inc(&n_rcu_torture_free);
78041+ atomic_inc_unchecked(&n_rcu_torture_free);
78042 spin_lock_bh(&rcu_torture_lock);
78043 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
78044 spin_unlock_bh(&rcu_torture_lock);
78045@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
78046 i = rp->rtort_pipe_count;
78047 if (i > RCU_TORTURE_PIPE_LEN)
78048 i = RCU_TORTURE_PIPE_LEN;
78049- atomic_inc(&rcu_torture_wcount[i]);
78050+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78051 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78052 rp->rtort_mbtest = 0;
78053 rcu_torture_free(rp);
78054@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
78055 i = rp->rtort_pipe_count;
78056 if (i > RCU_TORTURE_PIPE_LEN)
78057 i = RCU_TORTURE_PIPE_LEN;
78058- atomic_inc(&rcu_torture_wcount[i]);
78059+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78060 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
78061 rp->rtort_mbtest = 0;
78062 list_del(&rp->rtort_free);
78063@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
78064 i = old_rp->rtort_pipe_count;
78065 if (i > RCU_TORTURE_PIPE_LEN)
78066 i = RCU_TORTURE_PIPE_LEN;
78067- atomic_inc(&rcu_torture_wcount[i]);
78068+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
78069 old_rp->rtort_pipe_count++;
78070 cur_ops->deferred_free(old_rp);
78071 }
78072@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
78073 return;
78074 }
78075 if (p->rtort_mbtest == 0)
78076- atomic_inc(&n_rcu_torture_mberror);
78077+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78078 spin_lock(&rand_lock);
78079 cur_ops->read_delay(&rand);
78080 n_rcu_torture_timers++;
78081@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
78082 continue;
78083 }
78084 if (p->rtort_mbtest == 0)
78085- atomic_inc(&n_rcu_torture_mberror);
78086+ atomic_inc_unchecked(&n_rcu_torture_mberror);
78087 cur_ops->read_delay(&rand);
78088 preempt_disable();
78089 pipe_count = p->rtort_pipe_count;
78090@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
78091 rcu_torture_current,
78092 rcu_torture_current_version,
78093 list_empty(&rcu_torture_freelist),
78094- atomic_read(&n_rcu_torture_alloc),
78095- atomic_read(&n_rcu_torture_alloc_fail),
78096- atomic_read(&n_rcu_torture_free));
78097+ atomic_read_unchecked(&n_rcu_torture_alloc),
78098+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
78099+ atomic_read_unchecked(&n_rcu_torture_free));
78100 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
78101- atomic_read(&n_rcu_torture_mberror),
78102+ atomic_read_unchecked(&n_rcu_torture_mberror),
78103 n_rcu_torture_boost_ktrerror,
78104 n_rcu_torture_boost_rterror);
78105 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
78106@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
78107 n_barrier_attempts,
78108 n_rcu_torture_barrier_error);
78109 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
78110- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
78111+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
78112 n_rcu_torture_barrier_error != 0 ||
78113 n_rcu_torture_boost_ktrerror != 0 ||
78114 n_rcu_torture_boost_rterror != 0 ||
78115 n_rcu_torture_boost_failure != 0 ||
78116 i > 1) {
78117 cnt += sprintf(&page[cnt], "!!! ");
78118- atomic_inc(&n_rcu_torture_error);
78119+ atomic_inc_unchecked(&n_rcu_torture_error);
78120 WARN_ON_ONCE(1);
78121 }
78122 cnt += sprintf(&page[cnt], "Reader Pipe: ");
78123@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
78124 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
78125 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78126 cnt += sprintf(&page[cnt], " %d",
78127- atomic_read(&rcu_torture_wcount[i]));
78128+ atomic_read_unchecked(&rcu_torture_wcount[i]));
78129 }
78130 cnt += sprintf(&page[cnt], "\n");
78131 if (cur_ops->stats)
78132@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
78133
78134 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
78135
78136- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78137+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
78138 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
78139 else if (n_online_successes != n_online_attempts ||
78140 n_offline_successes != n_offline_attempts)
78141@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
78142
78143 rcu_torture_current = NULL;
78144 rcu_torture_current_version = 0;
78145- atomic_set(&n_rcu_torture_alloc, 0);
78146- atomic_set(&n_rcu_torture_alloc_fail, 0);
78147- atomic_set(&n_rcu_torture_free, 0);
78148- atomic_set(&n_rcu_torture_mberror, 0);
78149- atomic_set(&n_rcu_torture_error, 0);
78150+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
78151+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
78152+ atomic_set_unchecked(&n_rcu_torture_free, 0);
78153+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
78154+ atomic_set_unchecked(&n_rcu_torture_error, 0);
78155 n_rcu_torture_barrier_error = 0;
78156 n_rcu_torture_boost_ktrerror = 0;
78157 n_rcu_torture_boost_rterror = 0;
78158 n_rcu_torture_boost_failure = 0;
78159 n_rcu_torture_boosts = 0;
78160 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
78161- atomic_set(&rcu_torture_wcount[i], 0);
78162+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
78163 for_each_possible_cpu(cpu) {
78164 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
78165 per_cpu(rcu_torture_count, cpu)[i] = 0;
78166diff --git a/kernel/rcutree.c b/kernel/rcutree.c
78167index 3538001..e379e0b 100644
78168--- a/kernel/rcutree.c
78169+++ b/kernel/rcutree.c
78170@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
78171 rcu_prepare_for_idle(smp_processor_id());
78172 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78173 smp_mb__before_atomic_inc(); /* See above. */
78174- atomic_inc(&rdtp->dynticks);
78175+ atomic_inc_unchecked(&rdtp->dynticks);
78176 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
78177- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78178+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78179
78180 /*
78181 * It is illegal to enter an extended quiescent state while
78182@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
78183 int user)
78184 {
78185 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
78186- atomic_inc(&rdtp->dynticks);
78187+ atomic_inc_unchecked(&rdtp->dynticks);
78188 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78189 smp_mb__after_atomic_inc(); /* See above. */
78190- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78191+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78192 rcu_cleanup_after_idle(smp_processor_id());
78193 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
78194 if (!user && !is_idle_task(current)) {
78195@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
78196 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
78197
78198 if (rdtp->dynticks_nmi_nesting == 0 &&
78199- (atomic_read(&rdtp->dynticks) & 0x1))
78200+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
78201 return;
78202 rdtp->dynticks_nmi_nesting++;
78203 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
78204- atomic_inc(&rdtp->dynticks);
78205+ atomic_inc_unchecked(&rdtp->dynticks);
78206 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78207 smp_mb__after_atomic_inc(); /* See above. */
78208- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78209+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78210 }
78211
78212 /**
78213@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
78214 return;
78215 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78216 smp_mb__before_atomic_inc(); /* See above. */
78217- atomic_inc(&rdtp->dynticks);
78218+ atomic_inc_unchecked(&rdtp->dynticks);
78219 smp_mb__after_atomic_inc(); /* Force delay to next write. */
78220- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78221+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78222 }
78223
78224 /**
78225@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
78226 int ret;
78227
78228 preempt_disable();
78229- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78230+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78231 preempt_enable();
78232 return ret;
78233 }
78234@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
78235 */
78236 static int dyntick_save_progress_counter(struct rcu_data *rdp)
78237 {
78238- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
78239+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78240 return (rdp->dynticks_snap & 0x1) == 0;
78241 }
78242
78243@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
78244 unsigned int curr;
78245 unsigned int snap;
78246
78247- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
78248+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78249 snap = (unsigned int)rdp->dynticks_snap;
78250
78251 /*
78252@@ -1440,9 +1440,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
78253 rdp = this_cpu_ptr(rsp->rda);
78254 rcu_preempt_check_blocked_tasks(rnp);
78255 rnp->qsmask = rnp->qsmaskinit;
78256- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
78257+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
78258 WARN_ON_ONCE(rnp->completed != rsp->completed);
78259- ACCESS_ONCE(rnp->completed) = rsp->completed;
78260+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
78261 if (rnp == rdp->mynode)
78262 rcu_start_gp_per_cpu(rsp, rnp, rdp);
78263 rcu_preempt_boost_start_gp(rnp);
78264@@ -1524,7 +1524,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
78265 */
78266 rcu_for_each_node_breadth_first(rsp, rnp) {
78267 raw_spin_lock_irq(&rnp->lock);
78268- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
78269+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
78270 rdp = this_cpu_ptr(rsp->rda);
78271 if (rnp == rdp->mynode)
78272 __rcu_process_gp_end(rsp, rnp, rdp);
78273@@ -1855,7 +1855,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
78274 rsp->qlen += rdp->qlen;
78275 rdp->n_cbs_orphaned += rdp->qlen;
78276 rdp->qlen_lazy = 0;
78277- ACCESS_ONCE(rdp->qlen) = 0;
78278+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78279 }
78280
78281 /*
78282@@ -2101,7 +2101,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
78283 }
78284 smp_mb(); /* List handling before counting for rcu_barrier(). */
78285 rdp->qlen_lazy -= count_lazy;
78286- ACCESS_ONCE(rdp->qlen) -= count;
78287+ ACCESS_ONCE_RW(rdp->qlen) -= count;
78288 rdp->n_cbs_invoked += count;
78289
78290 /* Reinstate batch limit if we have worked down the excess. */
78291@@ -2295,7 +2295,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
78292 /*
78293 * Do RCU core processing for the current CPU.
78294 */
78295-static void rcu_process_callbacks(struct softirq_action *unused)
78296+static void rcu_process_callbacks(void)
78297 {
78298 struct rcu_state *rsp;
78299
78300@@ -2419,7 +2419,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
78301 local_irq_restore(flags);
78302 return;
78303 }
78304- ACCESS_ONCE(rdp->qlen)++;
78305+ ACCESS_ONCE_RW(rdp->qlen)++;
78306 if (lazy)
78307 rdp->qlen_lazy++;
78308 else
78309@@ -2628,11 +2628,11 @@ void synchronize_sched_expedited(void)
78310 * counter wrap on a 32-bit system. Quite a few more CPUs would of
78311 * course be required on a 64-bit system.
78312 */
78313- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
78314+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
78315 (ulong)atomic_long_read(&rsp->expedited_done) +
78316 ULONG_MAX / 8)) {
78317 synchronize_sched();
78318- atomic_long_inc(&rsp->expedited_wrap);
78319+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
78320 return;
78321 }
78322
78323@@ -2640,7 +2640,7 @@ void synchronize_sched_expedited(void)
78324 * Take a ticket. Note that atomic_inc_return() implies a
78325 * full memory barrier.
78326 */
78327- snap = atomic_long_inc_return(&rsp->expedited_start);
78328+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
78329 firstsnap = snap;
78330 get_online_cpus();
78331 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
78332@@ -2653,14 +2653,14 @@ void synchronize_sched_expedited(void)
78333 synchronize_sched_expedited_cpu_stop,
78334 NULL) == -EAGAIN) {
78335 put_online_cpus();
78336- atomic_long_inc(&rsp->expedited_tryfail);
78337+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
78338
78339 /* Check to see if someone else did our work for us. */
78340 s = atomic_long_read(&rsp->expedited_done);
78341 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78342 /* ensure test happens before caller kfree */
78343 smp_mb__before_atomic_inc(); /* ^^^ */
78344- atomic_long_inc(&rsp->expedited_workdone1);
78345+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
78346 return;
78347 }
78348
78349@@ -2669,7 +2669,7 @@ void synchronize_sched_expedited(void)
78350 udelay(trycount * num_online_cpus());
78351 } else {
78352 wait_rcu_gp(call_rcu_sched);
78353- atomic_long_inc(&rsp->expedited_normal);
78354+ atomic_long_inc_unchecked(&rsp->expedited_normal);
78355 return;
78356 }
78357
78358@@ -2678,7 +2678,7 @@ void synchronize_sched_expedited(void)
78359 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78360 /* ensure test happens before caller kfree */
78361 smp_mb__before_atomic_inc(); /* ^^^ */
78362- atomic_long_inc(&rsp->expedited_workdone2);
78363+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
78364 return;
78365 }
78366
78367@@ -2690,10 +2690,10 @@ void synchronize_sched_expedited(void)
78368 * period works for us.
78369 */
78370 get_online_cpus();
78371- snap = atomic_long_read(&rsp->expedited_start);
78372+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
78373 smp_mb(); /* ensure read is before try_stop_cpus(). */
78374 }
78375- atomic_long_inc(&rsp->expedited_stoppedcpus);
78376+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
78377
78378 /*
78379 * Everyone up to our most recent fetch is covered by our grace
78380@@ -2702,16 +2702,16 @@ void synchronize_sched_expedited(void)
78381 * than we did already did their update.
78382 */
78383 do {
78384- atomic_long_inc(&rsp->expedited_done_tries);
78385+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
78386 s = atomic_long_read(&rsp->expedited_done);
78387 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
78388 /* ensure test happens before caller kfree */
78389 smp_mb__before_atomic_inc(); /* ^^^ */
78390- atomic_long_inc(&rsp->expedited_done_lost);
78391+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
78392 break;
78393 }
78394 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
78395- atomic_long_inc(&rsp->expedited_done_exit);
78396+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
78397
78398 put_online_cpus();
78399 }
78400@@ -2893,7 +2893,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78401 * ACCESS_ONCE() to prevent the compiler from speculating
78402 * the increment to precede the early-exit check.
78403 */
78404- ACCESS_ONCE(rsp->n_barrier_done)++;
78405+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78406 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
78407 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
78408 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
78409@@ -2943,7 +2943,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78410
78411 /* Increment ->n_barrier_done to prevent duplicate work. */
78412 smp_mb(); /* Keep increment after above mechanism. */
78413- ACCESS_ONCE(rsp->n_barrier_done)++;
78414+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78415 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
78416 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
78417 smp_mb(); /* Keep increment before caller's subsequent code. */
78418@@ -2988,10 +2988,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
78419 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
78420 init_callback_list(rdp);
78421 rdp->qlen_lazy = 0;
78422- ACCESS_ONCE(rdp->qlen) = 0;
78423+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78424 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78425 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78426- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78427+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78428 rdp->cpu = cpu;
78429 rdp->rsp = rsp;
78430 rcu_boot_init_nocb_percpu_data(rdp);
78431@@ -3024,8 +3024,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78432 rdp->blimit = blimit;
78433 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78434 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78435- atomic_set(&rdp->dynticks->dynticks,
78436- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78437+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78438+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78439 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78440
78441 /* Add CPU to rcu_node bitmasks. */
78442@@ -3120,7 +3120,7 @@ static int __init rcu_spawn_gp_kthread(void)
78443 struct task_struct *t;
78444
78445 for_each_rcu_flavor(rsp) {
78446- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
78447+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
78448 BUG_ON(IS_ERR(t));
78449 rnp = rcu_get_root(rsp);
78450 raw_spin_lock_irqsave(&rnp->lock, flags);
78451diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78452index 4df5034..5ee93f2 100644
78453--- a/kernel/rcutree.h
78454+++ b/kernel/rcutree.h
78455@@ -87,7 +87,7 @@ struct rcu_dynticks {
78456 long long dynticks_nesting; /* Track irq/process nesting level. */
78457 /* Process level is worth LLONG_MAX/2. */
78458 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78459- atomic_t dynticks; /* Even value for idle, else odd. */
78460+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78461 #ifdef CONFIG_RCU_FAST_NO_HZ
78462 bool all_lazy; /* Are all CPU's CBs lazy? */
78463 unsigned long nonlazy_posted;
78464@@ -414,17 +414,17 @@ struct rcu_state {
78465 /* _rcu_barrier(). */
78466 /* End of fields guarded by barrier_mutex. */
78467
78468- atomic_long_t expedited_start; /* Starting ticket. */
78469- atomic_long_t expedited_done; /* Done ticket. */
78470- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78471- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78472- atomic_long_t expedited_workdone1; /* # done by others #1. */
78473- atomic_long_t expedited_workdone2; /* # done by others #2. */
78474- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78475- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78476- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78477- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78478- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78479+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78480+ atomic_long_t expedited_done; /* Done ticket. */
78481+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78482+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78483+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78484+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78485+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78486+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78487+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78488+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78489+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78490
78491 unsigned long jiffies_force_qs; /* Time at which to invoke */
78492 /* force_quiescent_state(). */
78493diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78494index 3db5a37..b395fb35 100644
78495--- a/kernel/rcutree_plugin.h
78496+++ b/kernel/rcutree_plugin.h
78497@@ -903,7 +903,7 @@ void synchronize_rcu_expedited(void)
78498
78499 /* Clean up and exit. */
78500 smp_mb(); /* ensure expedited GP seen before counter increment. */
78501- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78502+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78503 unlock_mb_ret:
78504 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78505 mb_ret:
78506@@ -1451,7 +1451,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78507 free_cpumask_var(cm);
78508 }
78509
78510-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78511+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78512 .store = &rcu_cpu_kthread_task,
78513 .thread_should_run = rcu_cpu_kthread_should_run,
78514 .thread_fn = rcu_cpu_kthread,
78515@@ -1916,7 +1916,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78516 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78517 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
78518 cpu, ticks_value, ticks_title,
78519- atomic_read(&rdtp->dynticks) & 0xfff,
78520+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78521 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78522 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
78523 fast_no_hz);
78524@@ -2079,7 +2079,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78525
78526 /* Enqueue the callback on the nocb list and update counts. */
78527 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78528- ACCESS_ONCE(*old_rhpp) = rhp;
78529+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78530 atomic_long_add(rhcount, &rdp->nocb_q_count);
78531 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78532
78533@@ -2219,12 +2219,12 @@ static int rcu_nocb_kthread(void *arg)
78534 * Extract queued callbacks, update counts, and wait
78535 * for a grace period to elapse.
78536 */
78537- ACCESS_ONCE(rdp->nocb_head) = NULL;
78538+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78539 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78540 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78541 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78542- ACCESS_ONCE(rdp->nocb_p_count) += c;
78543- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78544+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78545+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78546 rcu_nocb_wait_gp(rdp);
78547
78548 /* Each pass through the following loop invokes a callback. */
78549@@ -2246,8 +2246,8 @@ static int rcu_nocb_kthread(void *arg)
78550 list = next;
78551 }
78552 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78553- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78554- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78555+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78556+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78557 rdp->n_nocbs_invoked += c;
78558 }
78559 return 0;
78560@@ -2274,7 +2274,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78561 t = kthread_run(rcu_nocb_kthread, rdp,
78562 "rcuo%c/%d", rsp->abbr, cpu);
78563 BUG_ON(IS_ERR(t));
78564- ACCESS_ONCE(rdp->nocb_kthread) = t;
78565+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78566 }
78567 }
78568
78569diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78570index cf6c174..a8f4b50 100644
78571--- a/kernel/rcutree_trace.c
78572+++ b/kernel/rcutree_trace.c
78573@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78574 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78575 rdp->passed_quiesce, rdp->qs_pending);
78576 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78577- atomic_read(&rdp->dynticks->dynticks),
78578+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78579 rdp->dynticks->dynticks_nesting,
78580 rdp->dynticks->dynticks_nmi_nesting,
78581 rdp->dynticks_fqs);
78582@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78583 struct rcu_state *rsp = (struct rcu_state *)m->private;
78584
78585 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",
78586- atomic_long_read(&rsp->expedited_start),
78587+ atomic_long_read_unchecked(&rsp->expedited_start),
78588 atomic_long_read(&rsp->expedited_done),
78589- atomic_long_read(&rsp->expedited_wrap),
78590- atomic_long_read(&rsp->expedited_tryfail),
78591- atomic_long_read(&rsp->expedited_workdone1),
78592- atomic_long_read(&rsp->expedited_workdone2),
78593- atomic_long_read(&rsp->expedited_normal),
78594- atomic_long_read(&rsp->expedited_stoppedcpus),
78595- atomic_long_read(&rsp->expedited_done_tries),
78596- atomic_long_read(&rsp->expedited_done_lost),
78597- atomic_long_read(&rsp->expedited_done_exit));
78598+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78599+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78600+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78601+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78602+ atomic_long_read_unchecked(&rsp->expedited_normal),
78603+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78604+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78605+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78606+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78607 return 0;
78608 }
78609
78610diff --git a/kernel/resource.c b/kernel/resource.c
78611index d738698..5f8e60a 100644
78612--- a/kernel/resource.c
78613+++ b/kernel/resource.c
78614@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
78615
78616 static int __init ioresources_init(void)
78617 {
78618+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78619+#ifdef CONFIG_GRKERNSEC_PROC_USER
78620+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78621+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78622+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78623+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78624+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78625+#endif
78626+#else
78627 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78628 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78629+#endif
78630 return 0;
78631 }
78632 __initcall(ioresources_init);
78633diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78634index 1d96dd0..994ff19 100644
78635--- a/kernel/rtmutex-tester.c
78636+++ b/kernel/rtmutex-tester.c
78637@@ -22,7 +22,7 @@
78638 #define MAX_RT_TEST_MUTEXES 8
78639
78640 static spinlock_t rttest_lock;
78641-static atomic_t rttest_event;
78642+static atomic_unchecked_t rttest_event;
78643
78644 struct test_thread_data {
78645 int opcode;
78646@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78647
78648 case RTTEST_LOCKCONT:
78649 td->mutexes[td->opdata] = 1;
78650- td->event = atomic_add_return(1, &rttest_event);
78651+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78652 return 0;
78653
78654 case RTTEST_RESET:
78655@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78656 return 0;
78657
78658 case RTTEST_RESETEVENT:
78659- atomic_set(&rttest_event, 0);
78660+ atomic_set_unchecked(&rttest_event, 0);
78661 return 0;
78662
78663 default:
78664@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78665 return ret;
78666
78667 td->mutexes[id] = 1;
78668- td->event = atomic_add_return(1, &rttest_event);
78669+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78670 rt_mutex_lock(&mutexes[id]);
78671- td->event = atomic_add_return(1, &rttest_event);
78672+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78673 td->mutexes[id] = 4;
78674 return 0;
78675
78676@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78677 return ret;
78678
78679 td->mutexes[id] = 1;
78680- td->event = atomic_add_return(1, &rttest_event);
78681+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78682 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78683- td->event = atomic_add_return(1, &rttest_event);
78684+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78685 td->mutexes[id] = ret ? 0 : 4;
78686 return ret ? -EINTR : 0;
78687
78688@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78689 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78690 return ret;
78691
78692- td->event = atomic_add_return(1, &rttest_event);
78693+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78694 rt_mutex_unlock(&mutexes[id]);
78695- td->event = atomic_add_return(1, &rttest_event);
78696+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78697 td->mutexes[id] = 0;
78698 return 0;
78699
78700@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78701 break;
78702
78703 td->mutexes[dat] = 2;
78704- td->event = atomic_add_return(1, &rttest_event);
78705+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78706 break;
78707
78708 default:
78709@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78710 return;
78711
78712 td->mutexes[dat] = 3;
78713- td->event = atomic_add_return(1, &rttest_event);
78714+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78715 break;
78716
78717 case RTTEST_LOCKNOWAIT:
78718@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78719 return;
78720
78721 td->mutexes[dat] = 1;
78722- td->event = atomic_add_return(1, &rttest_event);
78723+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78724 return;
78725
78726 default:
78727diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78728index 64de5f8..7735e12 100644
78729--- a/kernel/sched/auto_group.c
78730+++ b/kernel/sched/auto_group.c
78731@@ -11,7 +11,7 @@
78732
78733 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78734 static struct autogroup autogroup_default;
78735-static atomic_t autogroup_seq_nr;
78736+static atomic_unchecked_t autogroup_seq_nr;
78737
78738 void __init autogroup_init(struct task_struct *init_task)
78739 {
78740@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
78741
78742 kref_init(&ag->kref);
78743 init_rwsem(&ag->lock);
78744- ag->id = atomic_inc_return(&autogroup_seq_nr);
78745+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78746 ag->tg = tg;
78747 #ifdef CONFIG_RT_GROUP_SCHED
78748 /*
78749diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78750index e8b3350..d83d44e 100644
78751--- a/kernel/sched/core.c
78752+++ b/kernel/sched/core.c
78753@@ -3440,7 +3440,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78754 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78755 * positive (at least 1, or number of jiffies left till timeout) if completed.
78756 */
78757-long __sched
78758+long __sched __intentional_overflow(-1)
78759 wait_for_completion_interruptible_timeout(struct completion *x,
78760 unsigned long timeout)
78761 {
78762@@ -3457,7 +3457,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78763 *
78764 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78765 */
78766-int __sched wait_for_completion_killable(struct completion *x)
78767+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78768 {
78769 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78770 if (t == -ERESTARTSYS)
78771@@ -3478,7 +3478,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78772 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78773 * positive (at least 1, or number of jiffies left till timeout) if completed.
78774 */
78775-long __sched
78776+long __sched __intentional_overflow(-1)
78777 wait_for_completion_killable_timeout(struct completion *x,
78778 unsigned long timeout)
78779 {
78780@@ -3704,6 +3704,8 @@ int can_nice(const struct task_struct *p, const int nice)
78781 /* convert nice value [19,-20] to rlimit style value [1,40] */
78782 int nice_rlim = 20 - nice;
78783
78784+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78785+
78786 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78787 capable(CAP_SYS_NICE));
78788 }
78789@@ -3737,7 +3739,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78790 if (nice > 19)
78791 nice = 19;
78792
78793- if (increment < 0 && !can_nice(current, nice))
78794+ if (increment < 0 && (!can_nice(current, nice) ||
78795+ gr_handle_chroot_nice()))
78796 return -EPERM;
78797
78798 retval = security_task_setnice(current, nice);
78799@@ -3891,6 +3894,7 @@ recheck:
78800 unsigned long rlim_rtprio =
78801 task_rlimit(p, RLIMIT_RTPRIO);
78802
78803+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78804 /* can't set/change the rt policy */
78805 if (policy != p->policy && !rlim_rtprio)
78806 return -EPERM;
78807@@ -4988,7 +4992,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78808
78809 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78810
78811-static struct ctl_table sd_ctl_dir[] = {
78812+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78813 {
78814 .procname = "sched_domain",
78815 .mode = 0555,
78816@@ -5005,17 +5009,17 @@ static struct ctl_table sd_ctl_root[] = {
78817 {}
78818 };
78819
78820-static struct ctl_table *sd_alloc_ctl_entry(int n)
78821+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78822 {
78823- struct ctl_table *entry =
78824+ ctl_table_no_const *entry =
78825 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78826
78827 return entry;
78828 }
78829
78830-static void sd_free_ctl_entry(struct ctl_table **tablep)
78831+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78832 {
78833- struct ctl_table *entry;
78834+ ctl_table_no_const *entry;
78835
78836 /*
78837 * In the intermediate directories, both the child directory and
78838@@ -5023,22 +5027,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78839 * will always be set. In the lowest directory the names are
78840 * static strings and all have proc handlers.
78841 */
78842- for (entry = *tablep; entry->mode; entry++) {
78843- if (entry->child)
78844- sd_free_ctl_entry(&entry->child);
78845+ for (entry = tablep; entry->mode; entry++) {
78846+ if (entry->child) {
78847+ sd_free_ctl_entry(entry->child);
78848+ pax_open_kernel();
78849+ entry->child = NULL;
78850+ pax_close_kernel();
78851+ }
78852 if (entry->proc_handler == NULL)
78853 kfree(entry->procname);
78854 }
78855
78856- kfree(*tablep);
78857- *tablep = NULL;
78858+ kfree(tablep);
78859 }
78860
78861 static int min_load_idx = 0;
78862 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78863
78864 static void
78865-set_table_entry(struct ctl_table *entry,
78866+set_table_entry(ctl_table_no_const *entry,
78867 const char *procname, void *data, int maxlen,
78868 umode_t mode, proc_handler *proc_handler,
78869 bool load_idx)
78870@@ -5058,7 +5065,7 @@ set_table_entry(struct ctl_table *entry,
78871 static struct ctl_table *
78872 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78873 {
78874- struct ctl_table *table = sd_alloc_ctl_entry(13);
78875+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78876
78877 if (table == NULL)
78878 return NULL;
78879@@ -5093,9 +5100,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78880 return table;
78881 }
78882
78883-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78884+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78885 {
78886- struct ctl_table *entry, *table;
78887+ ctl_table_no_const *entry, *table;
78888 struct sched_domain *sd;
78889 int domain_num = 0, i;
78890 char buf[32];
78891@@ -5122,11 +5129,13 @@ static struct ctl_table_header *sd_sysctl_header;
78892 static void register_sched_domain_sysctl(void)
78893 {
78894 int i, cpu_num = num_possible_cpus();
78895- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78896+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78897 char buf[32];
78898
78899 WARN_ON(sd_ctl_dir[0].child);
78900+ pax_open_kernel();
78901 sd_ctl_dir[0].child = entry;
78902+ pax_close_kernel();
78903
78904 if (entry == NULL)
78905 return;
78906@@ -5149,8 +5158,12 @@ static void unregister_sched_domain_sysctl(void)
78907 if (sd_sysctl_header)
78908 unregister_sysctl_table(sd_sysctl_header);
78909 sd_sysctl_header = NULL;
78910- if (sd_ctl_dir[0].child)
78911- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78912+ if (sd_ctl_dir[0].child) {
78913+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78914+ pax_open_kernel();
78915+ sd_ctl_dir[0].child = NULL;
78916+ pax_close_kernel();
78917+ }
78918 }
78919 #else
78920 static void register_sched_domain_sysctl(void)
78921@@ -5249,7 +5262,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78922 * happens before everything else. This has to be lower priority than
78923 * the notifier in the perf_event subsystem, though.
78924 */
78925-static struct notifier_block __cpuinitdata migration_notifier = {
78926+static struct notifier_block migration_notifier = {
78927 .notifier_call = migration_call,
78928 .priority = CPU_PRI_MIGRATION,
78929 };
78930diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78931index c61a614..d7f3d7e 100644
78932--- a/kernel/sched/fair.c
78933+++ b/kernel/sched/fair.c
78934@@ -831,7 +831,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78935
78936 static void reset_ptenuma_scan(struct task_struct *p)
78937 {
78938- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78939+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78940 p->mm->numa_scan_offset = 0;
78941 }
78942
78943@@ -5686,7 +5686,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78944 * run_rebalance_domains is triggered when needed from the scheduler tick.
78945 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78946 */
78947-static void run_rebalance_domains(struct softirq_action *h)
78948+static void run_rebalance_domains(void)
78949 {
78950 int this_cpu = smp_processor_id();
78951 struct rq *this_rq = cpu_rq(this_cpu);
78952diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
78953index ce39224..0e09343 100644
78954--- a/kernel/sched/sched.h
78955+++ b/kernel/sched/sched.h
78956@@ -1009,7 +1009,7 @@ struct sched_class {
78957 #ifdef CONFIG_FAIR_GROUP_SCHED
78958 void (*task_move_group) (struct task_struct *p, int on_rq);
78959 #endif
78960-};
78961+} __do_const;
78962
78963 #define sched_class_highest (&stop_sched_class)
78964 #define for_each_class(class) \
78965diff --git a/kernel/signal.c b/kernel/signal.c
78966index 113411b..17190e2 100644
78967--- a/kernel/signal.c
78968+++ b/kernel/signal.c
78969@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
78970
78971 int print_fatal_signals __read_mostly;
78972
78973-static void __user *sig_handler(struct task_struct *t, int sig)
78974+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78975 {
78976 return t->sighand->action[sig - 1].sa.sa_handler;
78977 }
78978
78979-static int sig_handler_ignored(void __user *handler, int sig)
78980+static int sig_handler_ignored(__sighandler_t handler, int sig)
78981 {
78982 /* Is it explicitly or implicitly ignored? */
78983 return handler == SIG_IGN ||
78984@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78985
78986 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78987 {
78988- void __user *handler;
78989+ __sighandler_t handler;
78990
78991 handler = sig_handler(t, sig);
78992
78993@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78994 atomic_inc(&user->sigpending);
78995 rcu_read_unlock();
78996
78997+ if (!override_rlimit)
78998+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78999+
79000 if (override_rlimit ||
79001 atomic_read(&user->sigpending) <=
79002 task_rlimit(t, RLIMIT_SIGPENDING)) {
79003@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
79004
79005 int unhandled_signal(struct task_struct *tsk, int sig)
79006 {
79007- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
79008+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
79009 if (is_global_init(tsk))
79010 return 1;
79011 if (handler != SIG_IGN && handler != SIG_DFL)
79012@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
79013 }
79014 }
79015
79016+ /* allow glibc communication via tgkill to other threads in our
79017+ thread group */
79018+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
79019+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
79020+ && gr_handle_signal(t, sig))
79021+ return -EPERM;
79022+
79023 return security_task_kill(t, info, sig, 0);
79024 }
79025
79026@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79027 return send_signal(sig, info, p, 1);
79028 }
79029
79030-static int
79031+int
79032 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79033 {
79034 return send_signal(sig, info, t, 0);
79035@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79036 unsigned long int flags;
79037 int ret, blocked, ignored;
79038 struct k_sigaction *action;
79039+ int is_unhandled = 0;
79040
79041 spin_lock_irqsave(&t->sighand->siglock, flags);
79042 action = &t->sighand->action[sig-1];
79043@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
79044 }
79045 if (action->sa.sa_handler == SIG_DFL)
79046 t->signal->flags &= ~SIGNAL_UNKILLABLE;
79047+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
79048+ is_unhandled = 1;
79049 ret = specific_send_sig_info(sig, info, t);
79050 spin_unlock_irqrestore(&t->sighand->siglock, flags);
79051
79052+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
79053+ normal operation */
79054+ if (is_unhandled) {
79055+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
79056+ gr_handle_crash(t, sig);
79057+ }
79058+
79059 return ret;
79060 }
79061
79062@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
79063 ret = check_kill_permission(sig, info, p);
79064 rcu_read_unlock();
79065
79066- if (!ret && sig)
79067+ if (!ret && sig) {
79068 ret = do_send_sig_info(sig, info, p, true);
79069+ if (!ret)
79070+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
79071+ }
79072
79073 return ret;
79074 }
79075@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
79076 int error = -ESRCH;
79077
79078 rcu_read_lock();
79079- p = find_task_by_vpid(pid);
79080+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79081+ /* allow glibc communication via tgkill to other threads in our
79082+ thread group */
79083+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
79084+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
79085+ p = find_task_by_vpid_unrestricted(pid);
79086+ else
79087+#endif
79088+ p = find_task_by_vpid(pid);
79089 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
79090 error = check_kill_permission(sig, info, p);
79091 /*
79092@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
79093 }
79094 seg = get_fs();
79095 set_fs(KERNEL_DS);
79096- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
79097- (stack_t __force __user *) &uoss,
79098+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
79099+ (stack_t __force_user *) &uoss,
79100 compat_user_stack_pointer());
79101 set_fs(seg);
79102 if (ret >= 0 && uoss_ptr) {
79103diff --git a/kernel/smp.c b/kernel/smp.c
79104index 4dba0f7..fe9f773 100644
79105--- a/kernel/smp.c
79106+++ b/kernel/smp.c
79107@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
79108 return NOTIFY_OK;
79109 }
79110
79111-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
79112+static struct notifier_block hotplug_cfd_notifier = {
79113 .notifier_call = hotplug_cfd,
79114 };
79115
79116diff --git a/kernel/smpboot.c b/kernel/smpboot.c
79117index 02fc5c9..e54c335 100644
79118--- a/kernel/smpboot.c
79119+++ b/kernel/smpboot.c
79120@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
79121 }
79122 smpboot_unpark_thread(plug_thread, cpu);
79123 }
79124- list_add(&plug_thread->list, &hotplug_threads);
79125+ pax_list_add(&plug_thread->list, &hotplug_threads);
79126 out:
79127 mutex_unlock(&smpboot_threads_lock);
79128 return ret;
79129@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
79130 {
79131 get_online_cpus();
79132 mutex_lock(&smpboot_threads_lock);
79133- list_del(&plug_thread->list);
79134+ pax_list_del(&plug_thread->list);
79135 smpboot_destroy_threads(plug_thread);
79136 mutex_unlock(&smpboot_threads_lock);
79137 put_online_cpus();
79138diff --git a/kernel/softirq.c b/kernel/softirq.c
79139index 3d6833f..da6d93d 100644
79140--- a/kernel/softirq.c
79141+++ b/kernel/softirq.c
79142@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
79143 EXPORT_SYMBOL(irq_stat);
79144 #endif
79145
79146-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
79147+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
79148
79149 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
79150
79151-char *softirq_to_name[NR_SOFTIRQS] = {
79152+const char * const softirq_to_name[NR_SOFTIRQS] = {
79153 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
79154 "TASKLET", "SCHED", "HRTIMER", "RCU"
79155 };
79156@@ -250,7 +250,7 @@ restart:
79157 kstat_incr_softirqs_this_cpu(vec_nr);
79158
79159 trace_softirq_entry(vec_nr);
79160- h->action(h);
79161+ h->action();
79162 trace_softirq_exit(vec_nr);
79163 if (unlikely(prev_count != preempt_count())) {
79164 printk(KERN_ERR "huh, entered softirq %u %s %p"
79165@@ -405,7 +405,7 @@ void __raise_softirq_irqoff(unsigned int nr)
79166 or_softirq_pending(1UL << nr);
79167 }
79168
79169-void open_softirq(int nr, void (*action)(struct softirq_action *))
79170+void __init open_softirq(int nr, void (*action)(void))
79171 {
79172 softirq_vec[nr].action = action;
79173 }
79174@@ -461,7 +461,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
79175
79176 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
79177
79178-static void tasklet_action(struct softirq_action *a)
79179+static void tasklet_action(void)
79180 {
79181 struct tasklet_struct *list;
79182
79183@@ -496,7 +496,7 @@ static void tasklet_action(struct softirq_action *a)
79184 }
79185 }
79186
79187-static void tasklet_hi_action(struct softirq_action *a)
79188+static void tasklet_hi_action(void)
79189 {
79190 struct tasklet_struct *list;
79191
79192@@ -730,7 +730,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
79193 return NOTIFY_OK;
79194 }
79195
79196-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
79197+static struct notifier_block remote_softirq_cpu_notifier = {
79198 .notifier_call = remote_softirq_cpu_notify,
79199 };
79200
79201@@ -847,11 +847,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
79202 return NOTIFY_OK;
79203 }
79204
79205-static struct notifier_block __cpuinitdata cpu_nfb = {
79206+static struct notifier_block cpu_nfb = {
79207 .notifier_call = cpu_callback
79208 };
79209
79210-static struct smp_hotplug_thread softirq_threads = {
79211+static struct smp_hotplug_thread softirq_threads __read_only = {
79212 .store = &ksoftirqd,
79213 .thread_should_run = ksoftirqd_should_run,
79214 .thread_fn = run_ksoftirqd,
79215diff --git a/kernel/srcu.c b/kernel/srcu.c
79216index 01d5ccb..cdcbee6 100644
79217--- a/kernel/srcu.c
79218+++ b/kernel/srcu.c
79219@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
79220
79221 idx = ACCESS_ONCE(sp->completed) & 0x1;
79222 preempt_disable();
79223- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79224+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79225 smp_mb(); /* B */ /* Avoid leaking the critical section. */
79226- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79227+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79228 preempt_enable();
79229 return idx;
79230 }
79231diff --git a/kernel/sys.c b/kernel/sys.c
79232index 2bbd9a7..0875671 100644
79233--- a/kernel/sys.c
79234+++ b/kernel/sys.c
79235@@ -163,6 +163,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
79236 error = -EACCES;
79237 goto out;
79238 }
79239+
79240+ if (gr_handle_chroot_setpriority(p, niceval)) {
79241+ error = -EACCES;
79242+ goto out;
79243+ }
79244+
79245 no_nice = security_task_setnice(p, niceval);
79246 if (no_nice) {
79247 error = no_nice;
79248@@ -626,6 +632,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
79249 goto error;
79250 }
79251
79252+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
79253+ goto error;
79254+
79255 if (rgid != (gid_t) -1 ||
79256 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
79257 new->sgid = new->egid;
79258@@ -661,6 +670,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
79259 old = current_cred();
79260
79261 retval = -EPERM;
79262+
79263+ if (gr_check_group_change(kgid, kgid, kgid))
79264+ goto error;
79265+
79266 if (nsown_capable(CAP_SETGID))
79267 new->gid = new->egid = new->sgid = new->fsgid = kgid;
79268 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
79269@@ -678,7 +691,7 @@ error:
79270 /*
79271 * change the user struct in a credentials set to match the new UID
79272 */
79273-static int set_user(struct cred *new)
79274+int set_user(struct cred *new)
79275 {
79276 struct user_struct *new_user;
79277
79278@@ -758,6 +771,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
79279 goto error;
79280 }
79281
79282+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
79283+ goto error;
79284+
79285 if (!uid_eq(new->uid, old->uid)) {
79286 retval = set_user(new);
79287 if (retval < 0)
79288@@ -808,6 +824,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
79289 old = current_cred();
79290
79291 retval = -EPERM;
79292+
79293+ if (gr_check_crash_uid(kuid))
79294+ goto error;
79295+ if (gr_check_user_change(kuid, kuid, kuid))
79296+ goto error;
79297+
79298 if (nsown_capable(CAP_SETUID)) {
79299 new->suid = new->uid = kuid;
79300 if (!uid_eq(kuid, old->uid)) {
79301@@ -877,6 +899,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
79302 goto error;
79303 }
79304
79305+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
79306+ goto error;
79307+
79308 if (ruid != (uid_t) -1) {
79309 new->uid = kruid;
79310 if (!uid_eq(kruid, old->uid)) {
79311@@ -959,6 +984,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
79312 goto error;
79313 }
79314
79315+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
79316+ goto error;
79317+
79318 if (rgid != (gid_t) -1)
79319 new->gid = krgid;
79320 if (egid != (gid_t) -1)
79321@@ -1020,12 +1048,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
79322 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
79323 nsown_capable(CAP_SETUID)) {
79324 if (!uid_eq(kuid, old->fsuid)) {
79325+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
79326+ goto error;
79327+
79328 new->fsuid = kuid;
79329 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
79330 goto change_okay;
79331 }
79332 }
79333
79334+error:
79335 abort_creds(new);
79336 return old_fsuid;
79337
79338@@ -1058,12 +1090,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
79339 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
79340 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
79341 nsown_capable(CAP_SETGID)) {
79342+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
79343+ goto error;
79344+
79345 if (!gid_eq(kgid, old->fsgid)) {
79346 new->fsgid = kgid;
79347 goto change_okay;
79348 }
79349 }
79350
79351+error:
79352 abort_creds(new);
79353 return old_fsgid;
79354
79355@@ -1432,19 +1468,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
79356 return -EFAULT;
79357
79358 down_read(&uts_sem);
79359- error = __copy_to_user(&name->sysname, &utsname()->sysname,
79360+ error = __copy_to_user(name->sysname, &utsname()->sysname,
79361 __OLD_UTS_LEN);
79362 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
79363- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
79364+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
79365 __OLD_UTS_LEN);
79366 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
79367- error |= __copy_to_user(&name->release, &utsname()->release,
79368+ error |= __copy_to_user(name->release, &utsname()->release,
79369 __OLD_UTS_LEN);
79370 error |= __put_user(0, name->release + __OLD_UTS_LEN);
79371- error |= __copy_to_user(&name->version, &utsname()->version,
79372+ error |= __copy_to_user(name->version, &utsname()->version,
79373 __OLD_UTS_LEN);
79374 error |= __put_user(0, name->version + __OLD_UTS_LEN);
79375- error |= __copy_to_user(&name->machine, &utsname()->machine,
79376+ error |= __copy_to_user(name->machine, &utsname()->machine,
79377 __OLD_UTS_LEN);
79378 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
79379 up_read(&uts_sem);
79380@@ -1646,6 +1682,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
79381 */
79382 new_rlim->rlim_cur = 1;
79383 }
79384+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
79385+ is changed to a lower value. Since tasks can be created by the same
79386+ user in between this limit change and an execve by this task, force
79387+ a recheck only for this task by setting PF_NPROC_EXCEEDED
79388+ */
79389+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
79390+ tsk->flags |= PF_NPROC_EXCEEDED;
79391 }
79392 if (!retval) {
79393 if (old_rlim)
79394diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79395index 9edcf45..713c960 100644
79396--- a/kernel/sysctl.c
79397+++ b/kernel/sysctl.c
79398@@ -93,7 +93,6 @@
79399
79400
79401 #if defined(CONFIG_SYSCTL)
79402-
79403 /* External variables not in a header file. */
79404 extern int sysctl_overcommit_memory;
79405 extern int sysctl_overcommit_ratio;
79406@@ -119,18 +118,18 @@ extern int blk_iopoll_enabled;
79407
79408 /* Constants used for minimum and maximum */
79409 #ifdef CONFIG_LOCKUP_DETECTOR
79410-static int sixty = 60;
79411-static int neg_one = -1;
79412+static int sixty __read_only = 60;
79413 #endif
79414
79415-static int zero;
79416-static int __maybe_unused one = 1;
79417-static int __maybe_unused two = 2;
79418-static int __maybe_unused three = 3;
79419-static unsigned long one_ul = 1;
79420-static int one_hundred = 100;
79421+static int neg_one __read_only = -1;
79422+static int zero __read_only = 0;
79423+static int __maybe_unused one __read_only = 1;
79424+static int __maybe_unused two __read_only = 2;
79425+static int __maybe_unused three __read_only = 3;
79426+static unsigned long one_ul __read_only = 1;
79427+static int one_hundred __read_only = 100;
79428 #ifdef CONFIG_PRINTK
79429-static int ten_thousand = 10000;
79430+static int ten_thousand __read_only = 10000;
79431 #endif
79432
79433 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
79434@@ -177,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
79435 void __user *buffer, size_t *lenp, loff_t *ppos);
79436 #endif
79437
79438-#ifdef CONFIG_PRINTK
79439 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79440 void __user *buffer, size_t *lenp, loff_t *ppos);
79441-#endif
79442
79443 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79444 void __user *buffer, size_t *lenp, loff_t *ppos);
79445@@ -211,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79446
79447 #endif
79448
79449+extern struct ctl_table grsecurity_table[];
79450+
79451 static struct ctl_table kern_table[];
79452 static struct ctl_table vm_table[];
79453 static struct ctl_table fs_table[];
79454@@ -225,6 +224,20 @@ extern struct ctl_table epoll_table[];
79455 int sysctl_legacy_va_layout;
79456 #endif
79457
79458+#ifdef CONFIG_PAX_SOFTMODE
79459+static ctl_table pax_table[] = {
79460+ {
79461+ .procname = "softmode",
79462+ .data = &pax_softmode,
79463+ .maxlen = sizeof(unsigned int),
79464+ .mode = 0600,
79465+ .proc_handler = &proc_dointvec,
79466+ },
79467+
79468+ { }
79469+};
79470+#endif
79471+
79472 /* The default sysctl tables: */
79473
79474 static struct ctl_table sysctl_base_table[] = {
79475@@ -273,6 +286,22 @@ static int max_extfrag_threshold = 1000;
79476 #endif
79477
79478 static struct ctl_table kern_table[] = {
79479+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79480+ {
79481+ .procname = "grsecurity",
79482+ .mode = 0500,
79483+ .child = grsecurity_table,
79484+ },
79485+#endif
79486+
79487+#ifdef CONFIG_PAX_SOFTMODE
79488+ {
79489+ .procname = "pax",
79490+ .mode = 0500,
79491+ .child = pax_table,
79492+ },
79493+#endif
79494+
79495 {
79496 .procname = "sched_child_runs_first",
79497 .data = &sysctl_sched_child_runs_first,
79498@@ -607,7 +636,7 @@ static struct ctl_table kern_table[] = {
79499 .data = &modprobe_path,
79500 .maxlen = KMOD_PATH_LEN,
79501 .mode = 0644,
79502- .proc_handler = proc_dostring,
79503+ .proc_handler = proc_dostring_modpriv,
79504 },
79505 {
79506 .procname = "modules_disabled",
79507@@ -774,16 +803,20 @@ static struct ctl_table kern_table[] = {
79508 .extra1 = &zero,
79509 .extra2 = &one,
79510 },
79511+#endif
79512 {
79513 .procname = "kptr_restrict",
79514 .data = &kptr_restrict,
79515 .maxlen = sizeof(int),
79516 .mode = 0644,
79517 .proc_handler = proc_dointvec_minmax_sysadmin,
79518+#ifdef CONFIG_GRKERNSEC_HIDESYM
79519+ .extra1 = &two,
79520+#else
79521 .extra1 = &zero,
79522+#endif
79523 .extra2 = &two,
79524 },
79525-#endif
79526 {
79527 .procname = "ngroups_max",
79528 .data = &ngroups_max,
79529@@ -1025,10 +1058,17 @@ static struct ctl_table kern_table[] = {
79530 */
79531 {
79532 .procname = "perf_event_paranoid",
79533- .data = &sysctl_perf_event_paranoid,
79534- .maxlen = sizeof(sysctl_perf_event_paranoid),
79535+ .data = &sysctl_perf_event_legitimately_concerned,
79536+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
79537 .mode = 0644,
79538- .proc_handler = proc_dointvec,
79539+ /* go ahead, be a hero */
79540+ .proc_handler = proc_dointvec_minmax_sysadmin,
79541+ .extra1 = &neg_one,
79542+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79543+ .extra2 = &three,
79544+#else
79545+ .extra2 = &two,
79546+#endif
79547 },
79548 {
79549 .procname = "perf_event_mlock_kb",
79550@@ -1282,6 +1322,13 @@ static struct ctl_table vm_table[] = {
79551 .proc_handler = proc_dointvec_minmax,
79552 .extra1 = &zero,
79553 },
79554+ {
79555+ .procname = "heap_stack_gap",
79556+ .data = &sysctl_heap_stack_gap,
79557+ .maxlen = sizeof(sysctl_heap_stack_gap),
79558+ .mode = 0644,
79559+ .proc_handler = proc_doulongvec_minmax,
79560+ },
79561 #else
79562 {
79563 .procname = "nr_trim_pages",
79564@@ -1746,6 +1793,16 @@ int proc_dostring(struct ctl_table *table, int write,
79565 buffer, lenp, ppos);
79566 }
79567
79568+int proc_dostring_modpriv(struct ctl_table *table, int write,
79569+ void __user *buffer, size_t *lenp, loff_t *ppos)
79570+{
79571+ if (write && !capable(CAP_SYS_MODULE))
79572+ return -EPERM;
79573+
79574+ return _proc_do_string(table->data, table->maxlen, write,
79575+ buffer, lenp, ppos);
79576+}
79577+
79578 static size_t proc_skip_spaces(char **buf)
79579 {
79580 size_t ret;
79581@@ -1851,6 +1908,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79582 len = strlen(tmp);
79583 if (len > *size)
79584 len = *size;
79585+ if (len > sizeof(tmp))
79586+ len = sizeof(tmp);
79587 if (copy_to_user(*buf, tmp, len))
79588 return -EFAULT;
79589 *size -= len;
79590@@ -2015,7 +2074,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79591 static int proc_taint(struct ctl_table *table, int write,
79592 void __user *buffer, size_t *lenp, loff_t *ppos)
79593 {
79594- struct ctl_table t;
79595+ ctl_table_no_const t;
79596 unsigned long tmptaint = get_taint();
79597 int err;
79598
79599@@ -2043,7 +2102,6 @@ static int proc_taint(struct ctl_table *table, int write,
79600 return err;
79601 }
79602
79603-#ifdef CONFIG_PRINTK
79604 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79605 void __user *buffer, size_t *lenp, loff_t *ppos)
79606 {
79607@@ -2052,7 +2110,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79608
79609 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79610 }
79611-#endif
79612
79613 struct do_proc_dointvec_minmax_conv_param {
79614 int *min;
79615@@ -2199,8 +2256,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79616 *i = val;
79617 } else {
79618 val = convdiv * (*i) / convmul;
79619- if (!first)
79620+ if (!first) {
79621 err = proc_put_char(&buffer, &left, '\t');
79622+ if (err)
79623+ break;
79624+ }
79625 err = proc_put_long(&buffer, &left, val, false);
79626 if (err)
79627 break;
79628@@ -2592,6 +2652,12 @@ int proc_dostring(struct ctl_table *table, int write,
79629 return -ENOSYS;
79630 }
79631
79632+int proc_dostring_modpriv(struct ctl_table *table, int write,
79633+ void __user *buffer, size_t *lenp, loff_t *ppos)
79634+{
79635+ return -ENOSYS;
79636+}
79637+
79638 int proc_dointvec(struct ctl_table *table, int write,
79639 void __user *buffer, size_t *lenp, loff_t *ppos)
79640 {
79641@@ -2648,5 +2714,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79642 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79643 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79644 EXPORT_SYMBOL(proc_dostring);
79645+EXPORT_SYMBOL(proc_dostring_modpriv);
79646 EXPORT_SYMBOL(proc_doulongvec_minmax);
79647 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79648diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79649index 145bb4d..b2aa969 100644
79650--- a/kernel/taskstats.c
79651+++ b/kernel/taskstats.c
79652@@ -28,9 +28,12 @@
79653 #include <linux/fs.h>
79654 #include <linux/file.h>
79655 #include <linux/pid_namespace.h>
79656+#include <linux/grsecurity.h>
79657 #include <net/genetlink.h>
79658 #include <linux/atomic.h>
79659
79660+extern int gr_is_taskstats_denied(int pid);
79661+
79662 /*
79663 * Maximum length of a cpumask that can be specified in
79664 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79665@@ -570,6 +573,9 @@ err:
79666
79667 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79668 {
79669+ if (gr_is_taskstats_denied(current->pid))
79670+ return -EACCES;
79671+
79672 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79673 return cmd_attr_register_cpumask(info);
79674 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79675diff --git a/kernel/time.c b/kernel/time.c
79676index d3617db..c98bbe9 100644
79677--- a/kernel/time.c
79678+++ b/kernel/time.c
79679@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79680 return error;
79681
79682 if (tz) {
79683+ /* we log in do_settimeofday called below, so don't log twice
79684+ */
79685+ if (!tv)
79686+ gr_log_timechange();
79687+
79688 sys_tz = *tz;
79689 update_vsyscall_tz();
79690 if (firsttime) {
79691@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79692 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79693 * value to a scaled second value.
79694 */
79695-unsigned long
79696+unsigned long __intentional_overflow(-1)
79697 timespec_to_jiffies(const struct timespec *value)
79698 {
79699 unsigned long sec = value->tv_sec;
79700diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79701index f11d83b..d016d91 100644
79702--- a/kernel/time/alarmtimer.c
79703+++ b/kernel/time/alarmtimer.c
79704@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79705 struct platform_device *pdev;
79706 int error = 0;
79707 int i;
79708- struct k_clock alarm_clock = {
79709+ static struct k_clock alarm_clock = {
79710 .clock_getres = alarm_clock_getres,
79711 .clock_get = alarm_clock_get,
79712 .timer_create = alarm_timer_create,
79713diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79714index 20d6fba..09e103a 100644
79715--- a/kernel/time/tick-broadcast.c
79716+++ b/kernel/time/tick-broadcast.c
79717@@ -147,7 +147,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79718 * then clear the broadcast bit.
79719 */
79720 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79721- int cpu = smp_processor_id();
79722+ cpu = smp_processor_id();
79723 cpumask_clear_cpu(cpu, tick_broadcast_mask);
79724 tick_broadcast_clear_oneshot(cpu);
79725 } else {
79726diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79727index baeeb5c..c22704a 100644
79728--- a/kernel/time/timekeeping.c
79729+++ b/kernel/time/timekeeping.c
79730@@ -15,6 +15,7 @@
79731 #include <linux/init.h>
79732 #include <linux/mm.h>
79733 #include <linux/sched.h>
79734+#include <linux/grsecurity.h>
79735 #include <linux/syscore_ops.h>
79736 #include <linux/clocksource.h>
79737 #include <linux/jiffies.h>
79738@@ -495,6 +496,8 @@ int do_settimeofday(const struct timespec *tv)
79739 if (!timespec_valid_strict(tv))
79740 return -EINVAL;
79741
79742+ gr_log_timechange();
79743+
79744 raw_spin_lock_irqsave(&timekeeper_lock, flags);
79745 write_seqcount_begin(&timekeeper_seq);
79746
79747diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79748index 3bdf283..cc68d83 100644
79749--- a/kernel/time/timer_list.c
79750+++ b/kernel/time/timer_list.c
79751@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79752
79753 static void print_name_offset(struct seq_file *m, void *sym)
79754 {
79755+#ifdef CONFIG_GRKERNSEC_HIDESYM
79756+ SEQ_printf(m, "<%p>", NULL);
79757+#else
79758 char symname[KSYM_NAME_LEN];
79759
79760 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79761 SEQ_printf(m, "<%pK>", sym);
79762 else
79763 SEQ_printf(m, "%s", symname);
79764+#endif
79765 }
79766
79767 static void
79768@@ -119,7 +123,11 @@ next_one:
79769 static void
79770 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79771 {
79772+#ifdef CONFIG_GRKERNSEC_HIDESYM
79773+ SEQ_printf(m, " .base: %p\n", NULL);
79774+#else
79775 SEQ_printf(m, " .base: %pK\n", base);
79776+#endif
79777 SEQ_printf(m, " .index: %d\n",
79778 base->index);
79779 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79780@@ -355,7 +363,11 @@ static int __init init_timer_list_procfs(void)
79781 {
79782 struct proc_dir_entry *pe;
79783
79784+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79785+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79786+#else
79787 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79788+#endif
79789 if (!pe)
79790 return -ENOMEM;
79791 return 0;
79792diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79793index 0b537f2..40d6c20 100644
79794--- a/kernel/time/timer_stats.c
79795+++ b/kernel/time/timer_stats.c
79796@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79797 static unsigned long nr_entries;
79798 static struct entry entries[MAX_ENTRIES];
79799
79800-static atomic_t overflow_count;
79801+static atomic_unchecked_t overflow_count;
79802
79803 /*
79804 * The entries are in a hash-table, for fast lookup:
79805@@ -140,7 +140,7 @@ static void reset_entries(void)
79806 nr_entries = 0;
79807 memset(entries, 0, sizeof(entries));
79808 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79809- atomic_set(&overflow_count, 0);
79810+ atomic_set_unchecked(&overflow_count, 0);
79811 }
79812
79813 static struct entry *alloc_entry(void)
79814@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79815 if (likely(entry))
79816 entry->count++;
79817 else
79818- atomic_inc(&overflow_count);
79819+ atomic_inc_unchecked(&overflow_count);
79820
79821 out_unlock:
79822 raw_spin_unlock_irqrestore(lock, flags);
79823@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79824
79825 static void print_name_offset(struct seq_file *m, unsigned long addr)
79826 {
79827+#ifdef CONFIG_GRKERNSEC_HIDESYM
79828+ seq_printf(m, "<%p>", NULL);
79829+#else
79830 char symname[KSYM_NAME_LEN];
79831
79832 if (lookup_symbol_name(addr, symname) < 0)
79833- seq_printf(m, "<%p>", (void *)addr);
79834+ seq_printf(m, "<%pK>", (void *)addr);
79835 else
79836 seq_printf(m, "%s", symname);
79837+#endif
79838 }
79839
79840 static int tstats_show(struct seq_file *m, void *v)
79841@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79842
79843 seq_puts(m, "Timer Stats Version: v0.2\n");
79844 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79845- if (atomic_read(&overflow_count))
79846+ if (atomic_read_unchecked(&overflow_count))
79847 seq_printf(m, "Overflow: %d entries\n",
79848- atomic_read(&overflow_count));
79849+ atomic_read_unchecked(&overflow_count));
79850
79851 for (i = 0; i < nr_entries; i++) {
79852 entry = entries + i;
79853@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79854 {
79855 struct proc_dir_entry *pe;
79856
79857+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79858+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79859+#else
79860 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79861+#endif
79862 if (!pe)
79863 return -ENOMEM;
79864 return 0;
79865diff --git a/kernel/timer.c b/kernel/timer.c
79866index 15ffdb3..62d885c 100644
79867--- a/kernel/timer.c
79868+++ b/kernel/timer.c
79869@@ -1364,7 +1364,7 @@ void update_process_times(int user_tick)
79870 /*
79871 * This function runs timers and the timer-tq in bottom half context.
79872 */
79873-static void run_timer_softirq(struct softirq_action *h)
79874+static void run_timer_softirq(void)
79875 {
79876 struct tvec_base *base = __this_cpu_read(tvec_bases);
79877
79878@@ -1427,7 +1427,7 @@ static void process_timeout(unsigned long __data)
79879 *
79880 * In all cases the return value is guaranteed to be non-negative.
79881 */
79882-signed long __sched schedule_timeout(signed long timeout)
79883+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79884 {
79885 struct timer_list timer;
79886 unsigned long expire;
79887@@ -1633,7 +1633,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79888 return NOTIFY_OK;
79889 }
79890
79891-static struct notifier_block __cpuinitdata timers_nb = {
79892+static struct notifier_block timers_nb = {
79893 .notifier_call = timer_cpu_notify,
79894 };
79895
79896diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79897index b8b8560..75b1a09 100644
79898--- a/kernel/trace/blktrace.c
79899+++ b/kernel/trace/blktrace.c
79900@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79901 struct blk_trace *bt = filp->private_data;
79902 char buf[16];
79903
79904- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79905+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79906
79907 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79908 }
79909@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79910 return 1;
79911
79912 bt = buf->chan->private_data;
79913- atomic_inc(&bt->dropped);
79914+ atomic_inc_unchecked(&bt->dropped);
79915 return 0;
79916 }
79917
79918@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79919
79920 bt->dir = dir;
79921 bt->dev = dev;
79922- atomic_set(&bt->dropped, 0);
79923+ atomic_set_unchecked(&bt->dropped, 0);
79924
79925 ret = -EIO;
79926 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79927diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79928index 6c508ff..ee55a13 100644
79929--- a/kernel/trace/ftrace.c
79930+++ b/kernel/trace/ftrace.c
79931@@ -1915,12 +1915,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79932 if (unlikely(ftrace_disabled))
79933 return 0;
79934
79935+ ret = ftrace_arch_code_modify_prepare();
79936+ FTRACE_WARN_ON(ret);
79937+ if (ret)
79938+ return 0;
79939+
79940 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79941+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79942 if (ret) {
79943 ftrace_bug(ret, ip);
79944- return 0;
79945 }
79946- return 1;
79947+ return ret ? 0 : 1;
79948 }
79949
79950 /*
79951@@ -3931,8 +3936,10 @@ static int ftrace_process_locs(struct module *mod,
79952 if (!count)
79953 return 0;
79954
79955+ pax_open_kernel();
79956 sort(start, count, sizeof(*start),
79957 ftrace_cmp_ips, ftrace_swap_ips);
79958+ pax_close_kernel();
79959
79960 start_pg = ftrace_allocate_pages(count);
79961 if (!start_pg)
79962@@ -4655,8 +4662,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79963 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79964
79965 static int ftrace_graph_active;
79966-static struct notifier_block ftrace_suspend_notifier;
79967-
79968 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79969 {
79970 return 0;
79971@@ -4800,6 +4805,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79972 return NOTIFY_DONE;
79973 }
79974
79975+static struct notifier_block ftrace_suspend_notifier = {
79976+ .notifier_call = ftrace_suspend_notifier_call
79977+};
79978+
79979 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79980 trace_func_graph_ent_t entryfunc)
79981 {
79982@@ -4813,7 +4822,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79983 goto out;
79984 }
79985
79986- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79987 register_pm_notifier(&ftrace_suspend_notifier);
79988
79989 ftrace_graph_active++;
79990diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79991index e444ff8..438b8f4 100644
79992--- a/kernel/trace/ring_buffer.c
79993+++ b/kernel/trace/ring_buffer.c
79994@@ -352,9 +352,9 @@ struct buffer_data_page {
79995 */
79996 struct buffer_page {
79997 struct list_head list; /* list of buffer pages */
79998- local_t write; /* index for next write */
79999+ local_unchecked_t write; /* index for next write */
80000 unsigned read; /* index for next read */
80001- local_t entries; /* entries on this page */
80002+ local_unchecked_t entries; /* entries on this page */
80003 unsigned long real_end; /* real end of data */
80004 struct buffer_data_page *page; /* Actual data page */
80005 };
80006@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
80007 unsigned long last_overrun;
80008 local_t entries_bytes;
80009 local_t entries;
80010- local_t overrun;
80011- local_t commit_overrun;
80012+ local_unchecked_t overrun;
80013+ local_unchecked_t commit_overrun;
80014 local_t dropped_events;
80015 local_t committing;
80016 local_t commits;
80017@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
80018 *
80019 * We add a counter to the write field to denote this.
80020 */
80021- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
80022- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
80023+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
80024+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
80025
80026 /*
80027 * Just make sure we have seen our old_write and synchronize
80028@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
80029 * cmpxchg to only update if an interrupt did not already
80030 * do it for us. If the cmpxchg fails, we don't care.
80031 */
80032- (void)local_cmpxchg(&next_page->write, old_write, val);
80033- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
80034+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
80035+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
80036
80037 /*
80038 * No need to worry about races with clearing out the commit.
80039@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
80040
80041 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
80042 {
80043- return local_read(&bpage->entries) & RB_WRITE_MASK;
80044+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
80045 }
80046
80047 static inline unsigned long rb_page_write(struct buffer_page *bpage)
80048 {
80049- return local_read(&bpage->write) & RB_WRITE_MASK;
80050+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
80051 }
80052
80053 static int
80054@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
80055 * bytes consumed in ring buffer from here.
80056 * Increment overrun to account for the lost events.
80057 */
80058- local_add(page_entries, &cpu_buffer->overrun);
80059+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
80060 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80061 }
80062
80063@@ -2063,7 +2063,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
80064 * it is our responsibility to update
80065 * the counters.
80066 */
80067- local_add(entries, &cpu_buffer->overrun);
80068+ local_add_unchecked(entries, &cpu_buffer->overrun);
80069 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
80070
80071 /*
80072@@ -2213,7 +2213,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80073 if (tail == BUF_PAGE_SIZE)
80074 tail_page->real_end = 0;
80075
80076- local_sub(length, &tail_page->write);
80077+ local_sub_unchecked(length, &tail_page->write);
80078 return;
80079 }
80080
80081@@ -2248,7 +2248,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80082 rb_event_set_padding(event);
80083
80084 /* Set the write back to the previous setting */
80085- local_sub(length, &tail_page->write);
80086+ local_sub_unchecked(length, &tail_page->write);
80087 return;
80088 }
80089
80090@@ -2260,7 +2260,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
80091
80092 /* Set write to end of buffer */
80093 length = (tail + length) - BUF_PAGE_SIZE;
80094- local_sub(length, &tail_page->write);
80095+ local_sub_unchecked(length, &tail_page->write);
80096 }
80097
80098 /*
80099@@ -2286,7 +2286,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80100 * about it.
80101 */
80102 if (unlikely(next_page == commit_page)) {
80103- local_inc(&cpu_buffer->commit_overrun);
80104+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80105 goto out_reset;
80106 }
80107
80108@@ -2342,7 +2342,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
80109 cpu_buffer->tail_page) &&
80110 (cpu_buffer->commit_page ==
80111 cpu_buffer->reader_page))) {
80112- local_inc(&cpu_buffer->commit_overrun);
80113+ local_inc_unchecked(&cpu_buffer->commit_overrun);
80114 goto out_reset;
80115 }
80116 }
80117@@ -2390,7 +2390,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80118 length += RB_LEN_TIME_EXTEND;
80119
80120 tail_page = cpu_buffer->tail_page;
80121- write = local_add_return(length, &tail_page->write);
80122+ write = local_add_return_unchecked(length, &tail_page->write);
80123
80124 /* set write to only the index of the write */
80125 write &= RB_WRITE_MASK;
80126@@ -2407,7 +2407,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
80127 kmemcheck_annotate_bitfield(event, bitfield);
80128 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
80129
80130- local_inc(&tail_page->entries);
80131+ local_inc_unchecked(&tail_page->entries);
80132
80133 /*
80134 * If this is the first commit on the page, then update
80135@@ -2440,7 +2440,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80136
80137 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
80138 unsigned long write_mask =
80139- local_read(&bpage->write) & ~RB_WRITE_MASK;
80140+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
80141 unsigned long event_length = rb_event_length(event);
80142 /*
80143 * This is on the tail page. It is possible that
80144@@ -2450,7 +2450,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
80145 */
80146 old_index += write_mask;
80147 new_index += write_mask;
80148- index = local_cmpxchg(&bpage->write, old_index, new_index);
80149+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
80150 if (index == old_index) {
80151 /* update counters */
80152 local_sub(event_length, &cpu_buffer->entries_bytes);
80153@@ -2842,7 +2842,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80154
80155 /* Do the likely case first */
80156 if (likely(bpage->page == (void *)addr)) {
80157- local_dec(&bpage->entries);
80158+ local_dec_unchecked(&bpage->entries);
80159 return;
80160 }
80161
80162@@ -2854,7 +2854,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
80163 start = bpage;
80164 do {
80165 if (bpage->page == (void *)addr) {
80166- local_dec(&bpage->entries);
80167+ local_dec_unchecked(&bpage->entries);
80168 return;
80169 }
80170 rb_inc_page(cpu_buffer, &bpage);
80171@@ -3138,7 +3138,7 @@ static inline unsigned long
80172 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
80173 {
80174 return local_read(&cpu_buffer->entries) -
80175- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
80176+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
80177 }
80178
80179 /**
80180@@ -3227,7 +3227,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
80181 return 0;
80182
80183 cpu_buffer = buffer->buffers[cpu];
80184- ret = local_read(&cpu_buffer->overrun);
80185+ ret = local_read_unchecked(&cpu_buffer->overrun);
80186
80187 return ret;
80188 }
80189@@ -3250,7 +3250,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
80190 return 0;
80191
80192 cpu_buffer = buffer->buffers[cpu];
80193- ret = local_read(&cpu_buffer->commit_overrun);
80194+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
80195
80196 return ret;
80197 }
80198@@ -3335,7 +3335,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
80199 /* if you care about this being correct, lock the buffer */
80200 for_each_buffer_cpu(buffer, cpu) {
80201 cpu_buffer = buffer->buffers[cpu];
80202- overruns += local_read(&cpu_buffer->overrun);
80203+ overruns += local_read_unchecked(&cpu_buffer->overrun);
80204 }
80205
80206 return overruns;
80207@@ -3511,8 +3511,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80208 /*
80209 * Reset the reader page to size zero.
80210 */
80211- local_set(&cpu_buffer->reader_page->write, 0);
80212- local_set(&cpu_buffer->reader_page->entries, 0);
80213+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80214+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80215 local_set(&cpu_buffer->reader_page->page->commit, 0);
80216 cpu_buffer->reader_page->real_end = 0;
80217
80218@@ -3546,7 +3546,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80219 * want to compare with the last_overrun.
80220 */
80221 smp_mb();
80222- overwrite = local_read(&(cpu_buffer->overrun));
80223+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
80224
80225 /*
80226 * Here's the tricky part.
80227@@ -4116,8 +4116,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80228
80229 cpu_buffer->head_page
80230 = list_entry(cpu_buffer->pages, struct buffer_page, list);
80231- local_set(&cpu_buffer->head_page->write, 0);
80232- local_set(&cpu_buffer->head_page->entries, 0);
80233+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
80234+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
80235 local_set(&cpu_buffer->head_page->page->commit, 0);
80236
80237 cpu_buffer->head_page->read = 0;
80238@@ -4127,14 +4127,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80239
80240 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
80241 INIT_LIST_HEAD(&cpu_buffer->new_pages);
80242- local_set(&cpu_buffer->reader_page->write, 0);
80243- local_set(&cpu_buffer->reader_page->entries, 0);
80244+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80245+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80246 local_set(&cpu_buffer->reader_page->page->commit, 0);
80247 cpu_buffer->reader_page->read = 0;
80248
80249 local_set(&cpu_buffer->entries_bytes, 0);
80250- local_set(&cpu_buffer->overrun, 0);
80251- local_set(&cpu_buffer->commit_overrun, 0);
80252+ local_set_unchecked(&cpu_buffer->overrun, 0);
80253+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
80254 local_set(&cpu_buffer->dropped_events, 0);
80255 local_set(&cpu_buffer->entries, 0);
80256 local_set(&cpu_buffer->committing, 0);
80257@@ -4538,8 +4538,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
80258 rb_init_page(bpage);
80259 bpage = reader->page;
80260 reader->page = *data_page;
80261- local_set(&reader->write, 0);
80262- local_set(&reader->entries, 0);
80263+ local_set_unchecked(&reader->write, 0);
80264+ local_set_unchecked(&reader->entries, 0);
80265 reader->read = 0;
80266 *data_page = bpage;
80267
80268diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
80269index e71a8be..948710a 100644
80270--- a/kernel/trace/trace.c
80271+++ b/kernel/trace/trace.c
80272@@ -3201,7 +3201,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
80273 return 0;
80274 }
80275
80276-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
80277+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
80278 {
80279 /* do nothing if flag is already set */
80280 if (!!(trace_flags & mask) == !!enabled)
80281diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
80282index 20572ed..fe55cf3 100644
80283--- a/kernel/trace/trace.h
80284+++ b/kernel/trace/trace.h
80285@@ -1030,7 +1030,7 @@ extern const char *__stop___trace_bprintk_fmt[];
80286 void trace_printk_init_buffers(void);
80287 void trace_printk_start_comm(void);
80288 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
80289-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
80290+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
80291
80292 /*
80293 * Normal trace_printk() and friends allocates special buffers
80294diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
80295index 27963e2..5a6936f 100644
80296--- a/kernel/trace/trace_events.c
80297+++ b/kernel/trace/trace_events.c
80298@@ -1637,10 +1637,6 @@ static LIST_HEAD(ftrace_module_file_list);
80299 struct ftrace_module_file_ops {
80300 struct list_head list;
80301 struct module *mod;
80302- struct file_operations id;
80303- struct file_operations enable;
80304- struct file_operations format;
80305- struct file_operations filter;
80306 };
80307
80308 static struct ftrace_module_file_ops *
80309@@ -1681,17 +1677,12 @@ trace_create_file_ops(struct module *mod)
80310
80311 file_ops->mod = mod;
80312
80313- file_ops->id = ftrace_event_id_fops;
80314- file_ops->id.owner = mod;
80315-
80316- file_ops->enable = ftrace_enable_fops;
80317- file_ops->enable.owner = mod;
80318-
80319- file_ops->filter = ftrace_event_filter_fops;
80320- file_ops->filter.owner = mod;
80321-
80322- file_ops->format = ftrace_event_format_fops;
80323- file_ops->format.owner = mod;
80324+ pax_open_kernel();
80325+ mod->trace_id.owner = mod;
80326+ mod->trace_enable.owner = mod;
80327+ mod->trace_filter.owner = mod;
80328+ mod->trace_format.owner = mod;
80329+ pax_close_kernel();
80330
80331 list_add(&file_ops->list, &ftrace_module_file_list);
80332
80333@@ -1782,8 +1773,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
80334 struct ftrace_module_file_ops *file_ops)
80335 {
80336 return __trace_add_new_event(call, tr,
80337- &file_ops->id, &file_ops->enable,
80338- &file_ops->filter, &file_ops->format);
80339+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
80340+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
80341 }
80342
80343 #else
80344diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80345index a5e8f48..a9690d2 100644
80346--- a/kernel/trace/trace_mmiotrace.c
80347+++ b/kernel/trace/trace_mmiotrace.c
80348@@ -24,7 +24,7 @@ struct header_iter {
80349 static struct trace_array *mmio_trace_array;
80350 static bool overrun_detected;
80351 static unsigned long prev_overruns;
80352-static atomic_t dropped_count;
80353+static atomic_unchecked_t dropped_count;
80354
80355 static void mmio_reset_data(struct trace_array *tr)
80356 {
80357@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80358
80359 static unsigned long count_overruns(struct trace_iterator *iter)
80360 {
80361- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80362+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80363 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
80364
80365 if (over > prev_overruns)
80366@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80367 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80368 sizeof(*entry), 0, pc);
80369 if (!event) {
80370- atomic_inc(&dropped_count);
80371+ atomic_inc_unchecked(&dropped_count);
80372 return;
80373 }
80374 entry = ring_buffer_event_data(event);
80375@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80376 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80377 sizeof(*entry), 0, pc);
80378 if (!event) {
80379- atomic_inc(&dropped_count);
80380+ atomic_inc_unchecked(&dropped_count);
80381 return;
80382 }
80383 entry = ring_buffer_event_data(event);
80384diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80385index bb922d9..2a54a257 100644
80386--- a/kernel/trace/trace_output.c
80387+++ b/kernel/trace/trace_output.c
80388@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80389
80390 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80391 if (!IS_ERR(p)) {
80392- p = mangle_path(s->buffer + s->len, p, "\n");
80393+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80394 if (p) {
80395 s->len = p - s->buffer;
80396 return 1;
80397@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
80398 goto out;
80399 }
80400
80401+ pax_open_kernel();
80402 if (event->funcs->trace == NULL)
80403- event->funcs->trace = trace_nop_print;
80404+ *(void **)&event->funcs->trace = trace_nop_print;
80405 if (event->funcs->raw == NULL)
80406- event->funcs->raw = trace_nop_print;
80407+ *(void **)&event->funcs->raw = trace_nop_print;
80408 if (event->funcs->hex == NULL)
80409- event->funcs->hex = trace_nop_print;
80410+ *(void **)&event->funcs->hex = trace_nop_print;
80411 if (event->funcs->binary == NULL)
80412- event->funcs->binary = trace_nop_print;
80413+ *(void **)&event->funcs->binary = trace_nop_print;
80414+ pax_close_kernel();
80415
80416 key = event->type & (EVENT_HASHSIZE - 1);
80417
80418diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80419index b20428c..4845a10 100644
80420--- a/kernel/trace/trace_stack.c
80421+++ b/kernel/trace/trace_stack.c
80422@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
80423 return;
80424
80425 /* we do not handle interrupt stacks yet */
80426- if (!object_is_on_stack(stack))
80427+ if (!object_starts_on_stack(stack))
80428 return;
80429
80430 local_irq_save(flags);
80431diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80432index d8c30db..e065e89 100644
80433--- a/kernel/user_namespace.c
80434+++ b/kernel/user_namespace.c
80435@@ -853,7 +853,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80436 if (atomic_read(&current->mm->mm_users) > 1)
80437 return -EINVAL;
80438
80439- if (current->fs->users != 1)
80440+ if (atomic_read(&current->fs->users) != 1)
80441 return -EINVAL;
80442
80443 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80444diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80445index 4f69f9a..7c6f8f8 100644
80446--- a/kernel/utsname_sysctl.c
80447+++ b/kernel/utsname_sysctl.c
80448@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80449 static int proc_do_uts_string(ctl_table *table, int write,
80450 void __user *buffer, size_t *lenp, loff_t *ppos)
80451 {
80452- struct ctl_table uts_table;
80453+ ctl_table_no_const uts_table;
80454 int r;
80455 memcpy(&uts_table, table, sizeof(uts_table));
80456 uts_table.data = get_uts(table, write);
80457diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80458index 05039e3..17490c7 100644
80459--- a/kernel/watchdog.c
80460+++ b/kernel/watchdog.c
80461@@ -531,7 +531,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80462 }
80463 #endif /* CONFIG_SYSCTL */
80464
80465-static struct smp_hotplug_thread watchdog_threads = {
80466+static struct smp_hotplug_thread watchdog_threads __read_only = {
80467 .store = &softlockup_watchdog,
80468 .thread_should_run = watchdog_should_run,
80469 .thread_fn = watchdog,
80470diff --git a/kernel/workqueue.c b/kernel/workqueue.c
80471index ee8e29a..410568e 100644
80472--- a/kernel/workqueue.c
80473+++ b/kernel/workqueue.c
80474@@ -4584,7 +4584,7 @@ static void rebind_workers(struct worker_pool *pool)
80475 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
80476 worker_flags |= WORKER_REBOUND;
80477 worker_flags &= ~WORKER_UNBOUND;
80478- ACCESS_ONCE(worker->flags) = worker_flags;
80479+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
80480 }
80481
80482 spin_unlock_irq(&pool->lock);
80483diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80484index 566cf2b..fdaa52c 100644
80485--- a/lib/Kconfig.debug
80486+++ b/lib/Kconfig.debug
80487@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
80488
80489 config DEBUG_LOCK_ALLOC
80490 bool "Lock debugging: detect incorrect freeing of live locks"
80491- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80492+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80493 select DEBUG_SPINLOCK
80494 select DEBUG_MUTEXES
80495 select LOCKDEP
80496@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
80497
80498 config PROVE_LOCKING
80499 bool "Lock debugging: prove locking correctness"
80500- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80501+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80502 select LOCKDEP
80503 select DEBUG_SPINLOCK
80504 select DEBUG_MUTEXES
80505@@ -614,7 +614,7 @@ config LOCKDEP
80506
80507 config LOCK_STAT
80508 bool "Lock usage statistics"
80509- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80510+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80511 select LOCKDEP
80512 select DEBUG_SPINLOCK
80513 select DEBUG_MUTEXES
80514@@ -1282,6 +1282,7 @@ config LATENCYTOP
80515 depends on DEBUG_KERNEL
80516 depends on STACKTRACE_SUPPORT
80517 depends on PROC_FS
80518+ depends on !GRKERNSEC_HIDESYM
80519 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80520 select KALLSYMS
80521 select KALLSYMS_ALL
80522@@ -1298,7 +1299,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
80523 config DEBUG_STRICT_USER_COPY_CHECKS
80524 bool "Strict user copy size checks"
80525 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
80526- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
80527+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
80528 help
80529 Enabling this option turns a certain set of sanity checks for user
80530 copy operations into compile time failures.
80531@@ -1328,7 +1329,7 @@ config INTERVAL_TREE_TEST
80532
80533 config PROVIDE_OHCI1394_DMA_INIT
80534 bool "Remote debugging over FireWire early on boot"
80535- depends on PCI && X86
80536+ depends on PCI && X86 && !GRKERNSEC
80537 help
80538 If you want to debug problems which hang or crash the kernel early
80539 on boot and the crashing machine has a FireWire port, you can use
80540@@ -1357,7 +1358,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80541
80542 config FIREWIRE_OHCI_REMOTE_DMA
80543 bool "Remote debugging over FireWire with firewire-ohci"
80544- depends on FIREWIRE_OHCI
80545+ depends on FIREWIRE_OHCI && !GRKERNSEC
80546 help
80547 This option lets you use the FireWire bus for remote debugging
80548 with help of the firewire-ohci driver. It enables unfiltered
80549diff --git a/lib/Makefile b/lib/Makefile
80550index c55a037..fb46e3b 100644
80551--- a/lib/Makefile
80552+++ b/lib/Makefile
80553@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80554
80555 obj-$(CONFIG_BTREE) += btree.o
80556 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80557-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80558+obj-y += list_debug.o
80559 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80560
80561 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80562diff --git a/lib/bitmap.c b/lib/bitmap.c
80563index 06f7e4f..f3cf2b0 100644
80564--- a/lib/bitmap.c
80565+++ b/lib/bitmap.c
80566@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80567 {
80568 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80569 u32 chunk;
80570- const char __user __force *ubuf = (const char __user __force *)buf;
80571+ const char __user *ubuf = (const char __force_user *)buf;
80572
80573 bitmap_zero(maskp, nmaskbits);
80574
80575@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80576 {
80577 if (!access_ok(VERIFY_READ, ubuf, ulen))
80578 return -EFAULT;
80579- return __bitmap_parse((const char __force *)ubuf,
80580+ return __bitmap_parse((const char __force_kernel *)ubuf,
80581 ulen, 1, maskp, nmaskbits);
80582
80583 }
80584@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80585 {
80586 unsigned a, b;
80587 int c, old_c, totaldigits;
80588- const char __user __force *ubuf = (const char __user __force *)buf;
80589+ const char __user *ubuf = (const char __force_user *)buf;
80590 int exp_digit, in_range;
80591
80592 totaldigits = c = 0;
80593@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80594 {
80595 if (!access_ok(VERIFY_READ, ubuf, ulen))
80596 return -EFAULT;
80597- return __bitmap_parselist((const char __force *)ubuf,
80598+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80599 ulen, 1, maskp, nmaskbits);
80600 }
80601 EXPORT_SYMBOL(bitmap_parselist_user);
80602diff --git a/lib/bug.c b/lib/bug.c
80603index 1686034..a9c00c8 100644
80604--- a/lib/bug.c
80605+++ b/lib/bug.c
80606@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80607 return BUG_TRAP_TYPE_NONE;
80608
80609 bug = find_bug(bugaddr);
80610+ if (!bug)
80611+ return BUG_TRAP_TYPE_NONE;
80612
80613 file = NULL;
80614 line = 0;
80615diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80616index 37061ed..da83f48 100644
80617--- a/lib/debugobjects.c
80618+++ b/lib/debugobjects.c
80619@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80620 if (limit > 4)
80621 return;
80622
80623- is_on_stack = object_is_on_stack(addr);
80624+ is_on_stack = object_starts_on_stack(addr);
80625 if (is_on_stack == onstack)
80626 return;
80627
80628diff --git a/lib/devres.c b/lib/devres.c
80629index 8235331..5881053 100644
80630--- a/lib/devres.c
80631+++ b/lib/devres.c
80632@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80633 void devm_iounmap(struct device *dev, void __iomem *addr)
80634 {
80635 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80636- (void *)addr));
80637+ (void __force *)addr));
80638 iounmap(addr);
80639 }
80640 EXPORT_SYMBOL(devm_iounmap);
80641@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80642 {
80643 ioport_unmap(addr);
80644 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80645- devm_ioport_map_match, (void *)addr));
80646+ devm_ioport_map_match, (void __force *)addr));
80647 }
80648 EXPORT_SYMBOL(devm_ioport_unmap);
80649 #endif /* CONFIG_HAS_IOPORT */
80650diff --git a/lib/div64.c b/lib/div64.c
80651index a163b6c..9618fa5 100644
80652--- a/lib/div64.c
80653+++ b/lib/div64.c
80654@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80655 EXPORT_SYMBOL(__div64_32);
80656
80657 #ifndef div_s64_rem
80658-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80659+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80660 {
80661 u64 quotient;
80662
80663@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80664 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80665 */
80666 #ifndef div64_u64
80667-u64 div64_u64(u64 dividend, u64 divisor)
80668+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80669 {
80670 u32 high = divisor >> 32;
80671 u64 quot;
80672diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80673index d87a17a..ac0d79a 100644
80674--- a/lib/dma-debug.c
80675+++ b/lib/dma-debug.c
80676@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80677
80678 void dma_debug_add_bus(struct bus_type *bus)
80679 {
80680- struct notifier_block *nb;
80681+ notifier_block_no_const *nb;
80682
80683 if (global_disable)
80684 return;
80685@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
80686
80687 static void check_for_stack(struct device *dev, void *addr)
80688 {
80689- if (object_is_on_stack(addr))
80690+ if (object_starts_on_stack(addr))
80691 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80692 "stack [addr=%p]\n", addr);
80693 }
80694diff --git a/lib/inflate.c b/lib/inflate.c
80695index 013a761..c28f3fc 100644
80696--- a/lib/inflate.c
80697+++ b/lib/inflate.c
80698@@ -269,7 +269,7 @@ static void free(void *where)
80699 malloc_ptr = free_mem_ptr;
80700 }
80701 #else
80702-#define malloc(a) kmalloc(a, GFP_KERNEL)
80703+#define malloc(a) kmalloc((a), GFP_KERNEL)
80704 #define free(a) kfree(a)
80705 #endif
80706
80707diff --git a/lib/ioremap.c b/lib/ioremap.c
80708index 0c9216c..863bd89 100644
80709--- a/lib/ioremap.c
80710+++ b/lib/ioremap.c
80711@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80712 unsigned long next;
80713
80714 phys_addr -= addr;
80715- pmd = pmd_alloc(&init_mm, pud, addr);
80716+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80717 if (!pmd)
80718 return -ENOMEM;
80719 do {
80720@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80721 unsigned long next;
80722
80723 phys_addr -= addr;
80724- pud = pud_alloc(&init_mm, pgd, addr);
80725+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80726 if (!pud)
80727 return -ENOMEM;
80728 do {
80729diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80730index bd2bea9..6b3c95e 100644
80731--- a/lib/is_single_threaded.c
80732+++ b/lib/is_single_threaded.c
80733@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80734 struct task_struct *p, *t;
80735 bool ret;
80736
80737+ if (!mm)
80738+ return true;
80739+
80740 if (atomic_read(&task->signal->live) != 1)
80741 return false;
80742
80743diff --git a/lib/kobject.c b/lib/kobject.c
80744index b7e29a6..2f3ca75 100644
80745--- a/lib/kobject.c
80746+++ b/lib/kobject.c
80747@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
80748 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
80749 if (!kset)
80750 return NULL;
80751- retval = kobject_set_name(&kset->kobj, name);
80752+ retval = kobject_set_name(&kset->kobj, "%s", name);
80753 if (retval) {
80754 kfree(kset);
80755 return NULL;
80756@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80757
80758
80759 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80760-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80761+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80762
80763-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80764+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80765 {
80766 enum kobj_ns_type type = ops->type;
80767 int error;
80768diff --git a/lib/list_debug.c b/lib/list_debug.c
80769index c24c2f7..06e070b 100644
80770--- a/lib/list_debug.c
80771+++ b/lib/list_debug.c
80772@@ -11,7 +11,9 @@
80773 #include <linux/bug.h>
80774 #include <linux/kernel.h>
80775 #include <linux/rculist.h>
80776+#include <linux/mm.h>
80777
80778+#ifdef CONFIG_DEBUG_LIST
80779 /*
80780 * Insert a new entry between two known consecutive entries.
80781 *
80782@@ -19,21 +21,32 @@
80783 * the prev/next entries already!
80784 */
80785
80786-void __list_add(struct list_head *new,
80787- struct list_head *prev,
80788- struct list_head *next)
80789+static bool __list_add_debug(struct list_head *new,
80790+ struct list_head *prev,
80791+ struct list_head *next)
80792 {
80793- WARN(next->prev != prev,
80794+ if (WARN(next->prev != prev,
80795 "list_add corruption. next->prev should be "
80796 "prev (%p), but was %p. (next=%p).\n",
80797- prev, next->prev, next);
80798- WARN(prev->next != next,
80799+ prev, next->prev, next) ||
80800+ WARN(prev->next != next,
80801 "list_add corruption. prev->next should be "
80802 "next (%p), but was %p. (prev=%p).\n",
80803- next, prev->next, prev);
80804- WARN(new == prev || new == next,
80805- "list_add double add: new=%p, prev=%p, next=%p.\n",
80806- new, prev, next);
80807+ next, prev->next, prev) ||
80808+ WARN(new == prev || new == next,
80809+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80810+ new, prev, next))
80811+ return false;
80812+ return true;
80813+}
80814+
80815+void __list_add(struct list_head *new,
80816+ struct list_head *prev,
80817+ struct list_head *next)
80818+{
80819+ if (!__list_add_debug(new, prev, next))
80820+ return;
80821+
80822 next->prev = new;
80823 new->next = next;
80824 new->prev = prev;
80825@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80826 }
80827 EXPORT_SYMBOL(__list_add);
80828
80829-void __list_del_entry(struct list_head *entry)
80830+static bool __list_del_entry_debug(struct list_head *entry)
80831 {
80832 struct list_head *prev, *next;
80833
80834@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80835 WARN(next->prev != entry,
80836 "list_del corruption. next->prev should be %p, "
80837 "but was %p\n", entry, next->prev))
80838+ return false;
80839+ return true;
80840+}
80841+
80842+void __list_del_entry(struct list_head *entry)
80843+{
80844+ if (!__list_del_entry_debug(entry))
80845 return;
80846
80847- __list_del(prev, next);
80848+ __list_del(entry->prev, entry->next);
80849 }
80850 EXPORT_SYMBOL(__list_del_entry);
80851
80852@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80853 void __list_add_rcu(struct list_head *new,
80854 struct list_head *prev, struct list_head *next)
80855 {
80856- WARN(next->prev != prev,
80857- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80858- prev, next->prev, next);
80859- WARN(prev->next != next,
80860- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80861- next, prev->next, prev);
80862+ if (!__list_add_debug(new, prev, next))
80863+ return;
80864+
80865 new->next = next;
80866 new->prev = prev;
80867 rcu_assign_pointer(list_next_rcu(prev), new);
80868 next->prev = new;
80869 }
80870 EXPORT_SYMBOL(__list_add_rcu);
80871+#endif
80872+
80873+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80874+{
80875+#ifdef CONFIG_DEBUG_LIST
80876+ if (!__list_add_debug(new, prev, next))
80877+ return;
80878+#endif
80879+
80880+ pax_open_kernel();
80881+ next->prev = new;
80882+ new->next = next;
80883+ new->prev = prev;
80884+ prev->next = new;
80885+ pax_close_kernel();
80886+}
80887+EXPORT_SYMBOL(__pax_list_add);
80888+
80889+void pax_list_del(struct list_head *entry)
80890+{
80891+#ifdef CONFIG_DEBUG_LIST
80892+ if (!__list_del_entry_debug(entry))
80893+ return;
80894+#endif
80895+
80896+ pax_open_kernel();
80897+ __list_del(entry->prev, entry->next);
80898+ entry->next = LIST_POISON1;
80899+ entry->prev = LIST_POISON2;
80900+ pax_close_kernel();
80901+}
80902+EXPORT_SYMBOL(pax_list_del);
80903+
80904+void pax_list_del_init(struct list_head *entry)
80905+{
80906+ pax_open_kernel();
80907+ __list_del(entry->prev, entry->next);
80908+ INIT_LIST_HEAD(entry);
80909+ pax_close_kernel();
80910+}
80911+EXPORT_SYMBOL(pax_list_del_init);
80912+
80913+void __pax_list_add_rcu(struct list_head *new,
80914+ struct list_head *prev, struct list_head *next)
80915+{
80916+#ifdef CONFIG_DEBUG_LIST
80917+ if (!__list_add_debug(new, prev, next))
80918+ return;
80919+#endif
80920+
80921+ pax_open_kernel();
80922+ new->next = next;
80923+ new->prev = prev;
80924+ rcu_assign_pointer(list_next_rcu(prev), new);
80925+ next->prev = new;
80926+ pax_close_kernel();
80927+}
80928+EXPORT_SYMBOL(__pax_list_add_rcu);
80929+
80930+void pax_list_del_rcu(struct list_head *entry)
80931+{
80932+#ifdef CONFIG_DEBUG_LIST
80933+ if (!__list_del_entry_debug(entry))
80934+ return;
80935+#endif
80936+
80937+ pax_open_kernel();
80938+ __list_del(entry->prev, entry->next);
80939+ entry->next = LIST_POISON1;
80940+ entry->prev = LIST_POISON2;
80941+ pax_close_kernel();
80942+}
80943+EXPORT_SYMBOL(pax_list_del_rcu);
80944diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80945index e796429..6e38f9f 100644
80946--- a/lib/radix-tree.c
80947+++ b/lib/radix-tree.c
80948@@ -92,7 +92,7 @@ struct radix_tree_preload {
80949 int nr;
80950 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80951 };
80952-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80953+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80954
80955 static inline void *ptr_to_indirect(void *ptr)
80956 {
80957diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80958index bb2b201..46abaf9 100644
80959--- a/lib/strncpy_from_user.c
80960+++ b/lib/strncpy_from_user.c
80961@@ -21,7 +21,7 @@
80962 */
80963 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80964 {
80965- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80966+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80967 long res = 0;
80968
80969 /*
80970diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80971index a28df52..3d55877 100644
80972--- a/lib/strnlen_user.c
80973+++ b/lib/strnlen_user.c
80974@@ -26,7 +26,7 @@
80975 */
80976 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80977 {
80978- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80979+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80980 long align, res = 0;
80981 unsigned long c;
80982
80983diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80984index d23762e..e21eab2 100644
80985--- a/lib/swiotlb.c
80986+++ b/lib/swiotlb.c
80987@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80988
80989 void
80990 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80991- dma_addr_t dev_addr)
80992+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80993 {
80994 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80995
80996diff --git a/lib/usercopy.c b/lib/usercopy.c
80997index 4f5b1dd..7cab418 100644
80998--- a/lib/usercopy.c
80999+++ b/lib/usercopy.c
81000@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
81001 WARN(1, "Buffer overflow detected!\n");
81002 }
81003 EXPORT_SYMBOL(copy_from_user_overflow);
81004+
81005+void copy_to_user_overflow(void)
81006+{
81007+ WARN(1, "Buffer overflow detected!\n");
81008+}
81009+EXPORT_SYMBOL(copy_to_user_overflow);
81010diff --git a/lib/vsprintf.c b/lib/vsprintf.c
81011index e149c64..24aa71a 100644
81012--- a/lib/vsprintf.c
81013+++ b/lib/vsprintf.c
81014@@ -16,6 +16,9 @@
81015 * - scnprintf and vscnprintf
81016 */
81017
81018+#ifdef CONFIG_GRKERNSEC_HIDESYM
81019+#define __INCLUDED_BY_HIDESYM 1
81020+#endif
81021 #include <stdarg.h>
81022 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
81023 #include <linux/types.h>
81024@@ -981,7 +984,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
81025 return number(buf, end, *(const netdev_features_t *)addr, spec);
81026 }
81027
81028+#ifdef CONFIG_GRKERNSEC_HIDESYM
81029+int kptr_restrict __read_mostly = 2;
81030+#else
81031 int kptr_restrict __read_mostly;
81032+#endif
81033
81034 /*
81035 * Show a '%p' thing. A kernel extension is that the '%p' is followed
81036@@ -994,6 +1001,7 @@ int kptr_restrict __read_mostly;
81037 * - 'f' For simple symbolic function names without offset
81038 * - 'S' For symbolic direct pointers with offset
81039 * - 's' For symbolic direct pointers without offset
81040+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
81041 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
81042 * - 'B' For backtraced symbolic direct pointers with offset
81043 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
81044@@ -1052,12 +1060,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81045
81046 if (!ptr && *fmt != 'K') {
81047 /*
81048- * Print (null) with the same width as a pointer so it makes
81049+ * Print (nil) with the same width as a pointer so it makes
81050 * tabular output look nice.
81051 */
81052 if (spec.field_width == -1)
81053 spec.field_width = default_width;
81054- return string(buf, end, "(null)", spec);
81055+ return string(buf, end, "(nil)", spec);
81056 }
81057
81058 switch (*fmt) {
81059@@ -1067,6 +1075,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81060 /* Fallthrough */
81061 case 'S':
81062 case 's':
81063+#ifdef CONFIG_GRKERNSEC_HIDESYM
81064+ break;
81065+#else
81066+ return symbol_string(buf, end, ptr, spec, fmt);
81067+#endif
81068+ case 'A':
81069 case 'B':
81070 return symbol_string(buf, end, ptr, spec, fmt);
81071 case 'R':
81072@@ -1107,6 +1121,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81073 va_end(va);
81074 return buf;
81075 }
81076+ case 'P':
81077+ break;
81078 case 'K':
81079 /*
81080 * %pK cannot be used in IRQ context because its test
81081@@ -1136,6 +1152,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
81082 return number(buf, end,
81083 (unsigned long long) *((phys_addr_t *)ptr), spec);
81084 }
81085+
81086+#ifdef CONFIG_GRKERNSEC_HIDESYM
81087+ /* 'P' = approved pointers to copy to userland,
81088+ as in the /proc/kallsyms case, as we make it display nothing
81089+ for non-root users, and the real contents for root users
81090+ Also ignore 'K' pointers, since we force their NULLing for non-root users
81091+ above
81092+ */
81093+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
81094+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
81095+ dump_stack();
81096+ ptr = NULL;
81097+ }
81098+#endif
81099+
81100 spec.flags |= SMALL;
81101 if (spec.field_width == -1) {
81102 spec.field_width = default_width;
81103@@ -1857,11 +1888,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81104 typeof(type) value; \
81105 if (sizeof(type) == 8) { \
81106 args = PTR_ALIGN(args, sizeof(u32)); \
81107- *(u32 *)&value = *(u32 *)args; \
81108- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
81109+ *(u32 *)&value = *(const u32 *)args; \
81110+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
81111 } else { \
81112 args = PTR_ALIGN(args, sizeof(type)); \
81113- value = *(typeof(type) *)args; \
81114+ value = *(const typeof(type) *)args; \
81115 } \
81116 args += sizeof(type); \
81117 value; \
81118@@ -1924,7 +1955,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
81119 case FORMAT_TYPE_STR: {
81120 const char *str_arg = args;
81121 args += strlen(str_arg) + 1;
81122- str = string(str, end, (char *)str_arg, spec);
81123+ str = string(str, end, str_arg, spec);
81124 break;
81125 }
81126
81127diff --git a/localversion-grsec b/localversion-grsec
81128new file mode 100644
81129index 0000000..7cd6065
81130--- /dev/null
81131+++ b/localversion-grsec
81132@@ -0,0 +1 @@
81133+-grsec
81134diff --git a/mm/Kconfig b/mm/Kconfig
81135index e742d06..c56fdd8 100644
81136--- a/mm/Kconfig
81137+++ b/mm/Kconfig
81138@@ -317,10 +317,10 @@ config KSM
81139 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
81140
81141 config DEFAULT_MMAP_MIN_ADDR
81142- int "Low address space to protect from user allocation"
81143+ int "Low address space to protect from user allocation"
81144 depends on MMU
81145- default 4096
81146- help
81147+ default 65536
81148+ help
81149 This is the portion of low virtual memory which should be protected
81150 from userspace allocation. Keeping a user from writing to low pages
81151 can help reduce the impact of kernel NULL pointer bugs.
81152@@ -351,7 +351,7 @@ config MEMORY_FAILURE
81153
81154 config HWPOISON_INJECT
81155 tristate "HWPoison pages injector"
81156- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
81157+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
81158 select PROC_PAGE_MONITOR
81159
81160 config NOMMU_INITIAL_TRIM_EXCESS
81161diff --git a/mm/backing-dev.c b/mm/backing-dev.c
81162index 5025174..9fc1c5c 100644
81163--- a/mm/backing-dev.c
81164+++ b/mm/backing-dev.c
81165@@ -515,7 +515,6 @@ EXPORT_SYMBOL(bdi_destroy);
81166 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
81167 unsigned int cap)
81168 {
81169- char tmp[32];
81170 int err;
81171
81172 bdi->name = name;
81173@@ -524,8 +523,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
81174 if (err)
81175 return err;
81176
81177- sprintf(tmp, "%.28s%s", name, "-%d");
81178- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
81179+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return(&bdi_seq));
81180 if (err) {
81181 bdi_destroy(bdi);
81182 return err;
81183diff --git a/mm/filemap.c b/mm/filemap.c
81184index 7905fe7..e60faa8 100644
81185--- a/mm/filemap.c
81186+++ b/mm/filemap.c
81187@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
81188 struct address_space *mapping = file->f_mapping;
81189
81190 if (!mapping->a_ops->readpage)
81191- return -ENOEXEC;
81192+ return -ENODEV;
81193 file_accessed(file);
81194 vma->vm_ops = &generic_file_vm_ops;
81195 return 0;
81196@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
81197 *pos = i_size_read(inode);
81198
81199 if (limit != RLIM_INFINITY) {
81200+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
81201 if (*pos >= limit) {
81202 send_sig(SIGXFSZ, current, 0);
81203 return -EFBIG;
81204diff --git a/mm/fremap.c b/mm/fremap.c
81205index 87da359..3f41cb1 100644
81206--- a/mm/fremap.c
81207+++ b/mm/fremap.c
81208@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
81209 retry:
81210 vma = find_vma(mm, start);
81211
81212+#ifdef CONFIG_PAX_SEGMEXEC
81213+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
81214+ goto out;
81215+#endif
81216+
81217 /*
81218 * Make sure the vma is shared, that it supports prefaulting,
81219 * and that the remapped range is valid and fully within
81220diff --git a/mm/highmem.c b/mm/highmem.c
81221index b32b70c..e512eb0 100644
81222--- a/mm/highmem.c
81223+++ b/mm/highmem.c
81224@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
81225 * So no dangers, even with speculative execution.
81226 */
81227 page = pte_page(pkmap_page_table[i]);
81228+ pax_open_kernel();
81229 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
81230-
81231+ pax_close_kernel();
81232 set_page_address(page, NULL);
81233 need_flush = 1;
81234 }
81235@@ -198,9 +199,11 @@ start:
81236 }
81237 }
81238 vaddr = PKMAP_ADDR(last_pkmap_nr);
81239+
81240+ pax_open_kernel();
81241 set_pte_at(&init_mm, vaddr,
81242 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
81243-
81244+ pax_close_kernel();
81245 pkmap_count[last_pkmap_nr] = 1;
81246 set_page_address(page, (void *)vaddr);
81247
81248diff --git a/mm/hugetlb.c b/mm/hugetlb.c
81249index 5cf99bf..28634c8 100644
81250--- a/mm/hugetlb.c
81251+++ b/mm/hugetlb.c
81252@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
81253 struct hstate *h = &default_hstate;
81254 unsigned long tmp;
81255 int ret;
81256+ ctl_table_no_const hugetlb_table;
81257
81258 tmp = h->max_huge_pages;
81259
81260 if (write && h->order >= MAX_ORDER)
81261 return -EINVAL;
81262
81263- table->data = &tmp;
81264- table->maxlen = sizeof(unsigned long);
81265- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81266+ hugetlb_table = *table;
81267+ hugetlb_table.data = &tmp;
81268+ hugetlb_table.maxlen = sizeof(unsigned long);
81269+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81270 if (ret)
81271 goto out;
81272
81273@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
81274 struct hstate *h = &default_hstate;
81275 unsigned long tmp;
81276 int ret;
81277+ ctl_table_no_const hugetlb_table;
81278
81279 tmp = h->nr_overcommit_huge_pages;
81280
81281 if (write && h->order >= MAX_ORDER)
81282 return -EINVAL;
81283
81284- table->data = &tmp;
81285- table->maxlen = sizeof(unsigned long);
81286- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81287+ hugetlb_table = *table;
81288+ hugetlb_table.data = &tmp;
81289+ hugetlb_table.maxlen = sizeof(unsigned long);
81290+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81291 if (ret)
81292 goto out;
81293
81294@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
81295 return 1;
81296 }
81297
81298+#ifdef CONFIG_PAX_SEGMEXEC
81299+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
81300+{
81301+ struct mm_struct *mm = vma->vm_mm;
81302+ struct vm_area_struct *vma_m;
81303+ unsigned long address_m;
81304+ pte_t *ptep_m;
81305+
81306+ vma_m = pax_find_mirror_vma(vma);
81307+ if (!vma_m)
81308+ return;
81309+
81310+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81311+ address_m = address + SEGMEXEC_TASK_SIZE;
81312+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
81313+ get_page(page_m);
81314+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
81315+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
81316+}
81317+#endif
81318+
81319 /*
81320 * Hugetlb_cow() should be called with page lock of the original hugepage held.
81321 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
81322@@ -2663,6 +2688,11 @@ retry_avoidcopy:
81323 make_huge_pte(vma, new_page, 1));
81324 page_remove_rmap(old_page);
81325 hugepage_add_new_anon_rmap(new_page, vma, address);
81326+
81327+#ifdef CONFIG_PAX_SEGMEXEC
81328+ pax_mirror_huge_pte(vma, address, new_page);
81329+#endif
81330+
81331 /* Make the old page be freed below */
81332 new_page = old_page;
81333 }
81334@@ -2821,6 +2851,10 @@ retry:
81335 && (vma->vm_flags & VM_SHARED)));
81336 set_huge_pte_at(mm, address, ptep, new_pte);
81337
81338+#ifdef CONFIG_PAX_SEGMEXEC
81339+ pax_mirror_huge_pte(vma, address, page);
81340+#endif
81341+
81342 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81343 /* Optimization, do the COW without a second fault */
81344 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81345@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81346 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81347 struct hstate *h = hstate_vma(vma);
81348
81349+#ifdef CONFIG_PAX_SEGMEXEC
81350+ struct vm_area_struct *vma_m;
81351+#endif
81352+
81353 address &= huge_page_mask(h);
81354
81355 ptep = huge_pte_offset(mm, address);
81356@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81357 VM_FAULT_SET_HINDEX(hstate_index(h));
81358 }
81359
81360+#ifdef CONFIG_PAX_SEGMEXEC
81361+ vma_m = pax_find_mirror_vma(vma);
81362+ if (vma_m) {
81363+ unsigned long address_m;
81364+
81365+ if (vma->vm_start > vma_m->vm_start) {
81366+ address_m = address;
81367+ address -= SEGMEXEC_TASK_SIZE;
81368+ vma = vma_m;
81369+ h = hstate_vma(vma);
81370+ } else
81371+ address_m = address + SEGMEXEC_TASK_SIZE;
81372+
81373+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81374+ return VM_FAULT_OOM;
81375+ address_m &= HPAGE_MASK;
81376+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81377+ }
81378+#endif
81379+
81380 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81381 if (!ptep)
81382 return VM_FAULT_OOM;
81383diff --git a/mm/internal.h b/mm/internal.h
81384index 8562de0..7fdfe92 100644
81385--- a/mm/internal.h
81386+++ b/mm/internal.h
81387@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81388 * in mm/page_alloc.c
81389 */
81390 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81391+extern void free_compound_page(struct page *page);
81392 extern void prep_compound_page(struct page *page, unsigned long order);
81393 #ifdef CONFIG_MEMORY_FAILURE
81394 extern bool is_free_buddy_page(struct page *page);
81395diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81396index c8d7f31..2dbeffd 100644
81397--- a/mm/kmemleak.c
81398+++ b/mm/kmemleak.c
81399@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81400
81401 for (i = 0; i < object->trace_len; i++) {
81402 void *ptr = (void *)object->trace[i];
81403- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81404+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81405 }
81406 }
81407
81408@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
81409 return -ENOMEM;
81410 }
81411
81412- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81413+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81414 &kmemleak_fops);
81415 if (!dentry)
81416 pr_warning("Failed to create the debugfs kmemleak file\n");
81417diff --git a/mm/maccess.c b/mm/maccess.c
81418index d53adf9..03a24bf 100644
81419--- a/mm/maccess.c
81420+++ b/mm/maccess.c
81421@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81422 set_fs(KERNEL_DS);
81423 pagefault_disable();
81424 ret = __copy_from_user_inatomic(dst,
81425- (__force const void __user *)src, size);
81426+ (const void __force_user *)src, size);
81427 pagefault_enable();
81428 set_fs(old_fs);
81429
81430@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81431
81432 set_fs(KERNEL_DS);
81433 pagefault_disable();
81434- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81435+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81436 pagefault_enable();
81437 set_fs(old_fs);
81438
81439diff --git a/mm/madvise.c b/mm/madvise.c
81440index 7055883..aafb1ed 100644
81441--- a/mm/madvise.c
81442+++ b/mm/madvise.c
81443@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81444 pgoff_t pgoff;
81445 unsigned long new_flags = vma->vm_flags;
81446
81447+#ifdef CONFIG_PAX_SEGMEXEC
81448+ struct vm_area_struct *vma_m;
81449+#endif
81450+
81451 switch (behavior) {
81452 case MADV_NORMAL:
81453 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81454@@ -126,6 +130,13 @@ success:
81455 /*
81456 * vm_flags is protected by the mmap_sem held in write mode.
81457 */
81458+
81459+#ifdef CONFIG_PAX_SEGMEXEC
81460+ vma_m = pax_find_mirror_vma(vma);
81461+ if (vma_m)
81462+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81463+#endif
81464+
81465 vma->vm_flags = new_flags;
81466
81467 out:
81468@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81469 struct vm_area_struct ** prev,
81470 unsigned long start, unsigned long end)
81471 {
81472+
81473+#ifdef CONFIG_PAX_SEGMEXEC
81474+ struct vm_area_struct *vma_m;
81475+#endif
81476+
81477 *prev = vma;
81478 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81479 return -EINVAL;
81480@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81481 zap_page_range(vma, start, end - start, &details);
81482 } else
81483 zap_page_range(vma, start, end - start, NULL);
81484+
81485+#ifdef CONFIG_PAX_SEGMEXEC
81486+ vma_m = pax_find_mirror_vma(vma);
81487+ if (vma_m) {
81488+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81489+ struct zap_details details = {
81490+ .nonlinear_vma = vma_m,
81491+ .last_index = ULONG_MAX,
81492+ };
81493+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81494+ } else
81495+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81496+ }
81497+#endif
81498+
81499 return 0;
81500 }
81501
81502@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81503 if (end < start)
81504 return error;
81505
81506+#ifdef CONFIG_PAX_SEGMEXEC
81507+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81508+ if (end > SEGMEXEC_TASK_SIZE)
81509+ return error;
81510+ } else
81511+#endif
81512+
81513+ if (end > TASK_SIZE)
81514+ return error;
81515+
81516 error = 0;
81517 if (end == start)
81518 return error;
81519diff --git a/mm/memcontrol.c b/mm/memcontrol.c
81520index fd79df5..15b0409 100644
81521--- a/mm/memcontrol.c
81522+++ b/mm/memcontrol.c
81523@@ -6296,14 +6296,6 @@ mem_cgroup_css_online(struct cgroup *cont)
81524
81525 error = memcg_init_kmem(memcg, &mem_cgroup_subsys);
81526 mutex_unlock(&memcg_create_mutex);
81527- if (error) {
81528- /*
81529- * We call put now because our (and parent's) refcnts
81530- * are already in place. mem_cgroup_put() will internally
81531- * call __mem_cgroup_free, so return directly
81532- */
81533- mem_cgroup_put(memcg);
81534- }
81535 return error;
81536 }
81537
81538diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81539index ceb0c7f..b2b8e94 100644
81540--- a/mm/memory-failure.c
81541+++ b/mm/memory-failure.c
81542@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81543
81544 int sysctl_memory_failure_recovery __read_mostly = 1;
81545
81546-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81547+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81548
81549 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81550
81551@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81552 pfn, t->comm, t->pid);
81553 si.si_signo = SIGBUS;
81554 si.si_errno = 0;
81555- si.si_addr = (void *)addr;
81556+ si.si_addr = (void __user *)addr;
81557 #ifdef __ARCH_SI_TRAPNO
81558 si.si_trapno = trapno;
81559 #endif
81560@@ -760,7 +760,7 @@ static struct page_state {
81561 unsigned long res;
81562 char *msg;
81563 int (*action)(struct page *p, unsigned long pfn);
81564-} error_states[] = {
81565+} __do_const error_states[] = {
81566 { reserved, reserved, "reserved kernel", me_kernel },
81567 /*
81568 * free pages are specially detected outside this table:
81569@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81570 nr_pages = 1 << compound_order(hpage);
81571 else /* normal page or thp */
81572 nr_pages = 1;
81573- atomic_long_add(nr_pages, &num_poisoned_pages);
81574+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
81575
81576 /*
81577 * We need/can do nothing about count=0 pages.
81578@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81579 if (!PageHWPoison(hpage)
81580 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81581 || (p != hpage && TestSetPageHWPoison(hpage))) {
81582- atomic_long_sub(nr_pages, &num_poisoned_pages);
81583+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81584 return 0;
81585 }
81586 set_page_hwpoison_huge_page(hpage);
81587@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81588 }
81589 if (hwpoison_filter(p)) {
81590 if (TestClearPageHWPoison(p))
81591- atomic_long_sub(nr_pages, &num_poisoned_pages);
81592+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81593 unlock_page(hpage);
81594 put_page(hpage);
81595 return 0;
81596@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
81597 return 0;
81598 }
81599 if (TestClearPageHWPoison(p))
81600- atomic_long_sub(nr_pages, &num_poisoned_pages);
81601+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81602 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81603 return 0;
81604 }
81605@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
81606 */
81607 if (TestClearPageHWPoison(page)) {
81608 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81609- atomic_long_sub(nr_pages, &num_poisoned_pages);
81610+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81611 freeit = 1;
81612 if (PageHuge(page))
81613 clear_page_hwpoison_huge_page(page);
81614@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81615 } else {
81616 set_page_hwpoison_huge_page(hpage);
81617 dequeue_hwpoisoned_huge_page(hpage);
81618- atomic_long_add(1 << compound_trans_order(hpage),
81619+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81620 &num_poisoned_pages);
81621 }
81622 /* keep elevated page count for bad page */
81623@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
81624 if (PageHuge(page)) {
81625 set_page_hwpoison_huge_page(hpage);
81626 dequeue_hwpoisoned_huge_page(hpage);
81627- atomic_long_add(1 << compound_trans_order(hpage),
81628+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81629 &num_poisoned_pages);
81630 } else {
81631 SetPageHWPoison(page);
81632- atomic_long_inc(&num_poisoned_pages);
81633+ atomic_long_inc_unchecked(&num_poisoned_pages);
81634 }
81635 }
81636 /* keep elevated page count for bad page */
81637@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
81638 put_page(page);
81639 pr_info("soft_offline: %#lx: invalidated\n", pfn);
81640 SetPageHWPoison(page);
81641- atomic_long_inc(&num_poisoned_pages);
81642+ atomic_long_inc_unchecked(&num_poisoned_pages);
81643 return 0;
81644 }
81645
81646@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
81647 ret = -EIO;
81648 } else {
81649 SetPageHWPoison(page);
81650- atomic_long_inc(&num_poisoned_pages);
81651+ atomic_long_inc_unchecked(&num_poisoned_pages);
81652 }
81653 } else {
81654 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
81655diff --git a/mm/memory.c b/mm/memory.c
81656index 61a262b..77a94d1 100644
81657--- a/mm/memory.c
81658+++ b/mm/memory.c
81659@@ -429,6 +429,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81660 free_pte_range(tlb, pmd, addr);
81661 } while (pmd++, addr = next, addr != end);
81662
81663+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81664 start &= PUD_MASK;
81665 if (start < floor)
81666 return;
81667@@ -443,6 +444,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81668 pmd = pmd_offset(pud, start);
81669 pud_clear(pud);
81670 pmd_free_tlb(tlb, pmd, start);
81671+#endif
81672+
81673 }
81674
81675 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81676@@ -462,6 +465,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81677 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81678 } while (pud++, addr = next, addr != end);
81679
81680+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81681 start &= PGDIR_MASK;
81682 if (start < floor)
81683 return;
81684@@ -476,6 +480,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81685 pud = pud_offset(pgd, start);
81686 pgd_clear(pgd);
81687 pud_free_tlb(tlb, pud, start);
81688+#endif
81689+
81690 }
81691
81692 /*
81693@@ -1635,12 +1641,6 @@ no_page_table:
81694 return page;
81695 }
81696
81697-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81698-{
81699- return stack_guard_page_start(vma, addr) ||
81700- stack_guard_page_end(vma, addr+PAGE_SIZE);
81701-}
81702-
81703 /**
81704 * __get_user_pages() - pin user pages in memory
81705 * @tsk: task_struct of target task
81706@@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81707
81708 i = 0;
81709
81710- do {
81711+ while (nr_pages) {
81712 struct vm_area_struct *vma;
81713
81714- vma = find_extend_vma(mm, start);
81715+ vma = find_vma(mm, start);
81716 if (!vma && in_gate_area(mm, start)) {
81717 unsigned long pg = start & PAGE_MASK;
81718 pgd_t *pgd;
81719@@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81720 goto next_page;
81721 }
81722
81723- if (!vma ||
81724+ if (!vma || start < vma->vm_start ||
81725 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81726 !(vm_flags & vma->vm_flags))
81727 return i ? : -EFAULT;
81728@@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81729 int ret;
81730 unsigned int fault_flags = 0;
81731
81732- /* For mlock, just skip the stack guard page. */
81733- if (foll_flags & FOLL_MLOCK) {
81734- if (stack_guard_page(vma, start))
81735- goto next_page;
81736- }
81737 if (foll_flags & FOLL_WRITE)
81738 fault_flags |= FAULT_FLAG_WRITE;
81739 if (nonblocking)
81740@@ -1892,7 +1887,7 @@ next_page:
81741 start += page_increm * PAGE_SIZE;
81742 nr_pages -= page_increm;
81743 } while (nr_pages && start < vma->vm_end);
81744- } while (nr_pages);
81745+ }
81746 return i;
81747 }
81748 EXPORT_SYMBOL(__get_user_pages);
81749@@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81750 page_add_file_rmap(page);
81751 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81752
81753+#ifdef CONFIG_PAX_SEGMEXEC
81754+ pax_mirror_file_pte(vma, addr, page, ptl);
81755+#endif
81756+
81757 retval = 0;
81758 pte_unmap_unlock(pte, ptl);
81759 return retval;
81760@@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81761 if (!page_count(page))
81762 return -EINVAL;
81763 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81764+
81765+#ifdef CONFIG_PAX_SEGMEXEC
81766+ struct vm_area_struct *vma_m;
81767+#endif
81768+
81769 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81770 BUG_ON(vma->vm_flags & VM_PFNMAP);
81771 vma->vm_flags |= VM_MIXEDMAP;
81772+
81773+#ifdef CONFIG_PAX_SEGMEXEC
81774+ vma_m = pax_find_mirror_vma(vma);
81775+ if (vma_m)
81776+ vma_m->vm_flags |= VM_MIXEDMAP;
81777+#endif
81778+
81779 }
81780 return insert_page(vma, addr, page, vma->vm_page_prot);
81781 }
81782@@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81783 unsigned long pfn)
81784 {
81785 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81786+ BUG_ON(vma->vm_mirror);
81787
81788 if (addr < vma->vm_start || addr >= vma->vm_end)
81789 return -EFAULT;
81790@@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81791
81792 BUG_ON(pud_huge(*pud));
81793
81794- pmd = pmd_alloc(mm, pud, addr);
81795+ pmd = (mm == &init_mm) ?
81796+ pmd_alloc_kernel(mm, pud, addr) :
81797+ pmd_alloc(mm, pud, addr);
81798 if (!pmd)
81799 return -ENOMEM;
81800 do {
81801@@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81802 unsigned long next;
81803 int err;
81804
81805- pud = pud_alloc(mm, pgd, addr);
81806+ pud = (mm == &init_mm) ?
81807+ pud_alloc_kernel(mm, pgd, addr) :
81808+ pud_alloc(mm, pgd, addr);
81809 if (!pud)
81810 return -ENOMEM;
81811 do {
81812@@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81813 copy_user_highpage(dst, src, va, vma);
81814 }
81815
81816+#ifdef CONFIG_PAX_SEGMEXEC
81817+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81818+{
81819+ struct mm_struct *mm = vma->vm_mm;
81820+ spinlock_t *ptl;
81821+ pte_t *pte, entry;
81822+
81823+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81824+ entry = *pte;
81825+ if (!pte_present(entry)) {
81826+ if (!pte_none(entry)) {
81827+ BUG_ON(pte_file(entry));
81828+ free_swap_and_cache(pte_to_swp_entry(entry));
81829+ pte_clear_not_present_full(mm, address, pte, 0);
81830+ }
81831+ } else {
81832+ struct page *page;
81833+
81834+ flush_cache_page(vma, address, pte_pfn(entry));
81835+ entry = ptep_clear_flush(vma, address, pte);
81836+ BUG_ON(pte_dirty(entry));
81837+ page = vm_normal_page(vma, address, entry);
81838+ if (page) {
81839+ update_hiwater_rss(mm);
81840+ if (PageAnon(page))
81841+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81842+ else
81843+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81844+ page_remove_rmap(page);
81845+ page_cache_release(page);
81846+ }
81847+ }
81848+ pte_unmap_unlock(pte, ptl);
81849+}
81850+
81851+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81852+ *
81853+ * the ptl of the lower mapped page is held on entry and is not released on exit
81854+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81855+ */
81856+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81857+{
81858+ struct mm_struct *mm = vma->vm_mm;
81859+ unsigned long address_m;
81860+ spinlock_t *ptl_m;
81861+ struct vm_area_struct *vma_m;
81862+ pmd_t *pmd_m;
81863+ pte_t *pte_m, entry_m;
81864+
81865+ BUG_ON(!page_m || !PageAnon(page_m));
81866+
81867+ vma_m = pax_find_mirror_vma(vma);
81868+ if (!vma_m)
81869+ return;
81870+
81871+ BUG_ON(!PageLocked(page_m));
81872+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81873+ address_m = address + SEGMEXEC_TASK_SIZE;
81874+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81875+ pte_m = pte_offset_map(pmd_m, address_m);
81876+ ptl_m = pte_lockptr(mm, pmd_m);
81877+ if (ptl != ptl_m) {
81878+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81879+ if (!pte_none(*pte_m))
81880+ goto out;
81881+ }
81882+
81883+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81884+ page_cache_get(page_m);
81885+ page_add_anon_rmap(page_m, vma_m, address_m);
81886+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81887+ set_pte_at(mm, address_m, pte_m, entry_m);
81888+ update_mmu_cache(vma_m, address_m, pte_m);
81889+out:
81890+ if (ptl != ptl_m)
81891+ spin_unlock(ptl_m);
81892+ pte_unmap(pte_m);
81893+ unlock_page(page_m);
81894+}
81895+
81896+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81897+{
81898+ struct mm_struct *mm = vma->vm_mm;
81899+ unsigned long address_m;
81900+ spinlock_t *ptl_m;
81901+ struct vm_area_struct *vma_m;
81902+ pmd_t *pmd_m;
81903+ pte_t *pte_m, entry_m;
81904+
81905+ BUG_ON(!page_m || PageAnon(page_m));
81906+
81907+ vma_m = pax_find_mirror_vma(vma);
81908+ if (!vma_m)
81909+ return;
81910+
81911+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81912+ address_m = address + SEGMEXEC_TASK_SIZE;
81913+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81914+ pte_m = pte_offset_map(pmd_m, address_m);
81915+ ptl_m = pte_lockptr(mm, pmd_m);
81916+ if (ptl != ptl_m) {
81917+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81918+ if (!pte_none(*pte_m))
81919+ goto out;
81920+ }
81921+
81922+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81923+ page_cache_get(page_m);
81924+ page_add_file_rmap(page_m);
81925+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81926+ set_pte_at(mm, address_m, pte_m, entry_m);
81927+ update_mmu_cache(vma_m, address_m, pte_m);
81928+out:
81929+ if (ptl != ptl_m)
81930+ spin_unlock(ptl_m);
81931+ pte_unmap(pte_m);
81932+}
81933+
81934+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81935+{
81936+ struct mm_struct *mm = vma->vm_mm;
81937+ unsigned long address_m;
81938+ spinlock_t *ptl_m;
81939+ struct vm_area_struct *vma_m;
81940+ pmd_t *pmd_m;
81941+ pte_t *pte_m, entry_m;
81942+
81943+ vma_m = pax_find_mirror_vma(vma);
81944+ if (!vma_m)
81945+ return;
81946+
81947+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81948+ address_m = address + SEGMEXEC_TASK_SIZE;
81949+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81950+ pte_m = pte_offset_map(pmd_m, address_m);
81951+ ptl_m = pte_lockptr(mm, pmd_m);
81952+ if (ptl != ptl_m) {
81953+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81954+ if (!pte_none(*pte_m))
81955+ goto out;
81956+ }
81957+
81958+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81959+ set_pte_at(mm, address_m, pte_m, entry_m);
81960+out:
81961+ if (ptl != ptl_m)
81962+ spin_unlock(ptl_m);
81963+ pte_unmap(pte_m);
81964+}
81965+
81966+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81967+{
81968+ struct page *page_m;
81969+ pte_t entry;
81970+
81971+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81972+ goto out;
81973+
81974+ entry = *pte;
81975+ page_m = vm_normal_page(vma, address, entry);
81976+ if (!page_m)
81977+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81978+ else if (PageAnon(page_m)) {
81979+ if (pax_find_mirror_vma(vma)) {
81980+ pte_unmap_unlock(pte, ptl);
81981+ lock_page(page_m);
81982+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81983+ if (pte_same(entry, *pte))
81984+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81985+ else
81986+ unlock_page(page_m);
81987+ }
81988+ } else
81989+ pax_mirror_file_pte(vma, address, page_m, ptl);
81990+
81991+out:
81992+ pte_unmap_unlock(pte, ptl);
81993+}
81994+#endif
81995+
81996 /*
81997 * This routine handles present pages, when users try to write
81998 * to a shared page. It is done by copying the page to a new address
81999@@ -2799,6 +2995,12 @@ gotten:
82000 */
82001 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82002 if (likely(pte_same(*page_table, orig_pte))) {
82003+
82004+#ifdef CONFIG_PAX_SEGMEXEC
82005+ if (pax_find_mirror_vma(vma))
82006+ BUG_ON(!trylock_page(new_page));
82007+#endif
82008+
82009 if (old_page) {
82010 if (!PageAnon(old_page)) {
82011 dec_mm_counter_fast(mm, MM_FILEPAGES);
82012@@ -2850,6 +3052,10 @@ gotten:
82013 page_remove_rmap(old_page);
82014 }
82015
82016+#ifdef CONFIG_PAX_SEGMEXEC
82017+ pax_mirror_anon_pte(vma, address, new_page, ptl);
82018+#endif
82019+
82020 /* Free the old page.. */
82021 new_page = old_page;
82022 ret |= VM_FAULT_WRITE;
82023@@ -3125,6 +3331,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82024 swap_free(entry);
82025 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
82026 try_to_free_swap(page);
82027+
82028+#ifdef CONFIG_PAX_SEGMEXEC
82029+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
82030+#endif
82031+
82032 unlock_page(page);
82033 if (page != swapcache) {
82034 /*
82035@@ -3148,6 +3359,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
82036
82037 /* No need to invalidate - it was non-present before */
82038 update_mmu_cache(vma, address, page_table);
82039+
82040+#ifdef CONFIG_PAX_SEGMEXEC
82041+ pax_mirror_anon_pte(vma, address, page, ptl);
82042+#endif
82043+
82044 unlock:
82045 pte_unmap_unlock(page_table, ptl);
82046 out:
82047@@ -3167,40 +3383,6 @@ out_release:
82048 }
82049
82050 /*
82051- * This is like a special single-page "expand_{down|up}wards()",
82052- * except we must first make sure that 'address{-|+}PAGE_SIZE'
82053- * doesn't hit another vma.
82054- */
82055-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
82056-{
82057- address &= PAGE_MASK;
82058- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
82059- struct vm_area_struct *prev = vma->vm_prev;
82060-
82061- /*
82062- * Is there a mapping abutting this one below?
82063- *
82064- * That's only ok if it's the same stack mapping
82065- * that has gotten split..
82066- */
82067- if (prev && prev->vm_end == address)
82068- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
82069-
82070- expand_downwards(vma, address - PAGE_SIZE);
82071- }
82072- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
82073- struct vm_area_struct *next = vma->vm_next;
82074-
82075- /* As VM_GROWSDOWN but s/below/above/ */
82076- if (next && next->vm_start == address + PAGE_SIZE)
82077- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
82078-
82079- expand_upwards(vma, address + PAGE_SIZE);
82080- }
82081- return 0;
82082-}
82083-
82084-/*
82085 * We enter with non-exclusive mmap_sem (to exclude vma changes,
82086 * but allow concurrent faults), and pte mapped but not yet locked.
82087 * We return with mmap_sem still held, but pte unmapped and unlocked.
82088@@ -3209,27 +3391,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82089 unsigned long address, pte_t *page_table, pmd_t *pmd,
82090 unsigned int flags)
82091 {
82092- struct page *page;
82093+ struct page *page = NULL;
82094 spinlock_t *ptl;
82095 pte_t entry;
82096
82097- pte_unmap(page_table);
82098-
82099- /* Check if we need to add a guard page to the stack */
82100- if (check_stack_guard_page(vma, address) < 0)
82101- return VM_FAULT_SIGBUS;
82102-
82103- /* Use the zero-page for reads */
82104 if (!(flags & FAULT_FLAG_WRITE)) {
82105 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
82106 vma->vm_page_prot));
82107- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
82108+ ptl = pte_lockptr(mm, pmd);
82109+ spin_lock(ptl);
82110 if (!pte_none(*page_table))
82111 goto unlock;
82112 goto setpte;
82113 }
82114
82115 /* Allocate our own private page. */
82116+ pte_unmap(page_table);
82117+
82118 if (unlikely(anon_vma_prepare(vma)))
82119 goto oom;
82120 page = alloc_zeroed_user_highpage_movable(vma, address);
82121@@ -3253,6 +3431,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
82122 if (!pte_none(*page_table))
82123 goto release;
82124
82125+#ifdef CONFIG_PAX_SEGMEXEC
82126+ if (pax_find_mirror_vma(vma))
82127+ BUG_ON(!trylock_page(page));
82128+#endif
82129+
82130 inc_mm_counter_fast(mm, MM_ANONPAGES);
82131 page_add_new_anon_rmap(page, vma, address);
82132 setpte:
82133@@ -3260,6 +3443,12 @@ setpte:
82134
82135 /* No need to invalidate - it was non-present before */
82136 update_mmu_cache(vma, address, page_table);
82137+
82138+#ifdef CONFIG_PAX_SEGMEXEC
82139+ if (page)
82140+ pax_mirror_anon_pte(vma, address, page, ptl);
82141+#endif
82142+
82143 unlock:
82144 pte_unmap_unlock(page_table, ptl);
82145 return 0;
82146@@ -3403,6 +3592,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82147 */
82148 /* Only go through if we didn't race with anybody else... */
82149 if (likely(pte_same(*page_table, orig_pte))) {
82150+
82151+#ifdef CONFIG_PAX_SEGMEXEC
82152+ if (anon && pax_find_mirror_vma(vma))
82153+ BUG_ON(!trylock_page(page));
82154+#endif
82155+
82156 flush_icache_page(vma, page);
82157 entry = mk_pte(page, vma->vm_page_prot);
82158 if (flags & FAULT_FLAG_WRITE)
82159@@ -3422,6 +3617,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82160
82161 /* no need to invalidate: a not-present page won't be cached */
82162 update_mmu_cache(vma, address, page_table);
82163+
82164+#ifdef CONFIG_PAX_SEGMEXEC
82165+ if (anon)
82166+ pax_mirror_anon_pte(vma, address, page, ptl);
82167+ else
82168+ pax_mirror_file_pte(vma, address, page, ptl);
82169+#endif
82170+
82171 } else {
82172 if (cow_page)
82173 mem_cgroup_uncharge_page(cow_page);
82174@@ -3743,6 +3946,12 @@ int handle_pte_fault(struct mm_struct *mm,
82175 if (flags & FAULT_FLAG_WRITE)
82176 flush_tlb_fix_spurious_fault(vma, address);
82177 }
82178+
82179+#ifdef CONFIG_PAX_SEGMEXEC
82180+ pax_mirror_pte(vma, address, pte, pmd, ptl);
82181+ return 0;
82182+#endif
82183+
82184 unlock:
82185 pte_unmap_unlock(pte, ptl);
82186 return 0;
82187@@ -3759,6 +3968,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82188 pmd_t *pmd;
82189 pte_t *pte;
82190
82191+#ifdef CONFIG_PAX_SEGMEXEC
82192+ struct vm_area_struct *vma_m;
82193+#endif
82194+
82195 __set_current_state(TASK_RUNNING);
82196
82197 count_vm_event(PGFAULT);
82198@@ -3770,6 +3983,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
82199 if (unlikely(is_vm_hugetlb_page(vma)))
82200 return hugetlb_fault(mm, vma, address, flags);
82201
82202+#ifdef CONFIG_PAX_SEGMEXEC
82203+ vma_m = pax_find_mirror_vma(vma);
82204+ if (vma_m) {
82205+ unsigned long address_m;
82206+ pgd_t *pgd_m;
82207+ pud_t *pud_m;
82208+ pmd_t *pmd_m;
82209+
82210+ if (vma->vm_start > vma_m->vm_start) {
82211+ address_m = address;
82212+ address -= SEGMEXEC_TASK_SIZE;
82213+ vma = vma_m;
82214+ } else
82215+ address_m = address + SEGMEXEC_TASK_SIZE;
82216+
82217+ pgd_m = pgd_offset(mm, address_m);
82218+ pud_m = pud_alloc(mm, pgd_m, address_m);
82219+ if (!pud_m)
82220+ return VM_FAULT_OOM;
82221+ pmd_m = pmd_alloc(mm, pud_m, address_m);
82222+ if (!pmd_m)
82223+ return VM_FAULT_OOM;
82224+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
82225+ return VM_FAULT_OOM;
82226+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
82227+ }
82228+#endif
82229+
82230 retry:
82231 pgd = pgd_offset(mm, address);
82232 pud = pud_alloc(mm, pgd, address);
82233@@ -3868,6 +4109,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82234 spin_unlock(&mm->page_table_lock);
82235 return 0;
82236 }
82237+
82238+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82239+{
82240+ pud_t *new = pud_alloc_one(mm, address);
82241+ if (!new)
82242+ return -ENOMEM;
82243+
82244+ smp_wmb(); /* See comment in __pte_alloc */
82245+
82246+ spin_lock(&mm->page_table_lock);
82247+ if (pgd_present(*pgd)) /* Another has populated it */
82248+ pud_free(mm, new);
82249+ else
82250+ pgd_populate_kernel(mm, pgd, new);
82251+ spin_unlock(&mm->page_table_lock);
82252+ return 0;
82253+}
82254 #endif /* __PAGETABLE_PUD_FOLDED */
82255
82256 #ifndef __PAGETABLE_PMD_FOLDED
82257@@ -3898,6 +4156,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
82258 spin_unlock(&mm->page_table_lock);
82259 return 0;
82260 }
82261+
82262+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
82263+{
82264+ pmd_t *new = pmd_alloc_one(mm, address);
82265+ if (!new)
82266+ return -ENOMEM;
82267+
82268+ smp_wmb(); /* See comment in __pte_alloc */
82269+
82270+ spin_lock(&mm->page_table_lock);
82271+#ifndef __ARCH_HAS_4LEVEL_HACK
82272+ if (pud_present(*pud)) /* Another has populated it */
82273+ pmd_free(mm, new);
82274+ else
82275+ pud_populate_kernel(mm, pud, new);
82276+#else
82277+ if (pgd_present(*pud)) /* Another has populated it */
82278+ pmd_free(mm, new);
82279+ else
82280+ pgd_populate_kernel(mm, pud, new);
82281+#endif /* __ARCH_HAS_4LEVEL_HACK */
82282+ spin_unlock(&mm->page_table_lock);
82283+ return 0;
82284+}
82285 #endif /* __PAGETABLE_PMD_FOLDED */
82286
82287 #if !defined(__HAVE_ARCH_GATE_AREA)
82288@@ -3911,7 +4193,7 @@ static int __init gate_vma_init(void)
82289 gate_vma.vm_start = FIXADDR_USER_START;
82290 gate_vma.vm_end = FIXADDR_USER_END;
82291 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
82292- gate_vma.vm_page_prot = __P101;
82293+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
82294
82295 return 0;
82296 }
82297@@ -4045,8 +4327,8 @@ out:
82298 return ret;
82299 }
82300
82301-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82302- void *buf, int len, int write)
82303+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82304+ void *buf, size_t len, int write)
82305 {
82306 resource_size_t phys_addr;
82307 unsigned long prot = 0;
82308@@ -4071,8 +4353,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82309 * Access another process' address space as given in mm. If non-NULL, use the
82310 * given task for page fault accounting.
82311 */
82312-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82313- unsigned long addr, void *buf, int len, int write)
82314+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82315+ unsigned long addr, void *buf, size_t len, int write)
82316 {
82317 struct vm_area_struct *vma;
82318 void *old_buf = buf;
82319@@ -4080,7 +4362,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82320 down_read(&mm->mmap_sem);
82321 /* ignore errors, just check how much was successfully transferred */
82322 while (len) {
82323- int bytes, ret, offset;
82324+ ssize_t bytes, ret, offset;
82325 void *maddr;
82326 struct page *page = NULL;
82327
82328@@ -4139,8 +4421,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82329 *
82330 * The caller must hold a reference on @mm.
82331 */
82332-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82333- void *buf, int len, int write)
82334+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
82335+ void *buf, size_t len, int write)
82336 {
82337 return __access_remote_vm(NULL, mm, addr, buf, len, write);
82338 }
82339@@ -4150,11 +4432,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82340 * Source/target buffer must be kernel space,
82341 * Do not walk the page table directly, use get_user_pages
82342 */
82343-int access_process_vm(struct task_struct *tsk, unsigned long addr,
82344- void *buf, int len, int write)
82345+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
82346+ void *buf, size_t len, int write)
82347 {
82348 struct mm_struct *mm;
82349- int ret;
82350+ ssize_t ret;
82351
82352 mm = get_task_mm(tsk);
82353 if (!mm)
82354diff --git a/mm/mempolicy.c b/mm/mempolicy.c
82355index 7431001..0f8344e 100644
82356--- a/mm/mempolicy.c
82357+++ b/mm/mempolicy.c
82358@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82359 unsigned long vmstart;
82360 unsigned long vmend;
82361
82362+#ifdef CONFIG_PAX_SEGMEXEC
82363+ struct vm_area_struct *vma_m;
82364+#endif
82365+
82366 vma = find_vma(mm, start);
82367 if (!vma || vma->vm_start > start)
82368 return -EFAULT;
82369@@ -744,9 +748,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82370 if (err)
82371 goto out;
82372 }
82373+
82374 err = vma_replace_policy(vma, new_pol);
82375 if (err)
82376 goto out;
82377+
82378+#ifdef CONFIG_PAX_SEGMEXEC
82379+ vma_m = pax_find_mirror_vma(vma);
82380+ if (vma_m) {
82381+ err = vma_replace_policy(vma_m, new_pol);
82382+ if (err)
82383+ goto out;
82384+ }
82385+#endif
82386+
82387 }
82388
82389 out:
82390@@ -1202,6 +1217,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82391
82392 if (end < start)
82393 return -EINVAL;
82394+
82395+#ifdef CONFIG_PAX_SEGMEXEC
82396+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82397+ if (end > SEGMEXEC_TASK_SIZE)
82398+ return -EINVAL;
82399+ } else
82400+#endif
82401+
82402+ if (end > TASK_SIZE)
82403+ return -EINVAL;
82404+
82405 if (end == start)
82406 return 0;
82407
82408@@ -1430,8 +1456,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82409 */
82410 tcred = __task_cred(task);
82411 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82412- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82413- !capable(CAP_SYS_NICE)) {
82414+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82415 rcu_read_unlock();
82416 err = -EPERM;
82417 goto out_put;
82418@@ -1462,6 +1487,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82419 goto out;
82420 }
82421
82422+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82423+ if (mm != current->mm &&
82424+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82425+ mmput(mm);
82426+ err = -EPERM;
82427+ goto out;
82428+ }
82429+#endif
82430+
82431 err = do_migrate_pages(mm, old, new,
82432 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82433
82434diff --git a/mm/migrate.c b/mm/migrate.c
82435index 6f0c244..6d1ae32 100644
82436--- a/mm/migrate.c
82437+++ b/mm/migrate.c
82438@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82439 */
82440 tcred = __task_cred(task);
82441 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82442- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82443- !capable(CAP_SYS_NICE)) {
82444+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82445 rcu_read_unlock();
82446 err = -EPERM;
82447 goto out;
82448diff --git a/mm/mlock.c b/mm/mlock.c
82449index 79b7cf7..9944291 100644
82450--- a/mm/mlock.c
82451+++ b/mm/mlock.c
82452@@ -13,6 +13,7 @@
82453 #include <linux/pagemap.h>
82454 #include <linux/mempolicy.h>
82455 #include <linux/syscalls.h>
82456+#include <linux/security.h>
82457 #include <linux/sched.h>
82458 #include <linux/export.h>
82459 #include <linux/rmap.h>
82460@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82461 {
82462 unsigned long nstart, end, tmp;
82463 struct vm_area_struct * vma, * prev;
82464- int error;
82465+ int error = 0;
82466
82467 VM_BUG_ON(start & ~PAGE_MASK);
82468 VM_BUG_ON(len != PAGE_ALIGN(len));
82469@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82470 return -EINVAL;
82471 if (end == start)
82472 return 0;
82473+ if (end > TASK_SIZE)
82474+ return -EINVAL;
82475+
82476 vma = find_vma(current->mm, start);
82477 if (!vma || vma->vm_start > start)
82478 return -ENOMEM;
82479@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82480 for (nstart = start ; ; ) {
82481 vm_flags_t newflags;
82482
82483+#ifdef CONFIG_PAX_SEGMEXEC
82484+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82485+ break;
82486+#endif
82487+
82488 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82489
82490 newflags = vma->vm_flags & ~VM_LOCKED;
82491@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82492 lock_limit >>= PAGE_SHIFT;
82493
82494 /* check against resource limits */
82495+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82496 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82497 error = do_mlock(start, len, 1);
82498 up_write(&current->mm->mmap_sem);
82499@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
82500 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82501 vm_flags_t newflags;
82502
82503+#ifdef CONFIG_PAX_SEGMEXEC
82504+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82505+ break;
82506+#endif
82507+
82508 newflags = vma->vm_flags & ~VM_LOCKED;
82509 if (flags & MCL_CURRENT)
82510 newflags |= VM_LOCKED;
82511@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82512 lock_limit >>= PAGE_SHIFT;
82513
82514 ret = -ENOMEM;
82515+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82516 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82517 capable(CAP_IPC_LOCK))
82518 ret = do_mlockall(flags);
82519diff --git a/mm/mmap.c b/mm/mmap.c
82520index f681e18..4c2577f 100644
82521--- a/mm/mmap.c
82522+++ b/mm/mmap.c
82523@@ -36,6 +36,7 @@
82524 #include <linux/sched/sysctl.h>
82525 #include <linux/notifier.h>
82526 #include <linux/memory.h>
82527+#include <linux/random.h>
82528
82529 #include <asm/uaccess.h>
82530 #include <asm/cacheflush.h>
82531@@ -52,6 +53,16 @@
82532 #define arch_rebalance_pgtables(addr, len) (addr)
82533 #endif
82534
82535+static inline void verify_mm_writelocked(struct mm_struct *mm)
82536+{
82537+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82538+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82539+ up_read(&mm->mmap_sem);
82540+ BUG();
82541+ }
82542+#endif
82543+}
82544+
82545 static void unmap_region(struct mm_struct *mm,
82546 struct vm_area_struct *vma, struct vm_area_struct *prev,
82547 unsigned long start, unsigned long end);
82548@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
82549 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82550 *
82551 */
82552-pgprot_t protection_map[16] = {
82553+pgprot_t protection_map[16] __read_only = {
82554 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82555 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82556 };
82557
82558-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82559+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82560 {
82561- return __pgprot(pgprot_val(protection_map[vm_flags &
82562+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82563 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82564 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82565+
82566+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82567+ if (!(__supported_pte_mask & _PAGE_NX) &&
82568+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82569+ (vm_flags & (VM_READ | VM_WRITE)))
82570+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82571+#endif
82572+
82573+ return prot;
82574 }
82575 EXPORT_SYMBOL(vm_get_page_prot);
82576
82577@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82578 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82579 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
82580 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
82581+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82582 /*
82583 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82584 * other variables. It can be updated by several CPUs frequently.
82585@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82586 struct vm_area_struct *next = vma->vm_next;
82587
82588 might_sleep();
82589+ BUG_ON(vma->vm_mirror);
82590 if (vma->vm_ops && vma->vm_ops->close)
82591 vma->vm_ops->close(vma);
82592 if (vma->vm_file)
82593@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82594 * not page aligned -Ram Gupta
82595 */
82596 rlim = rlimit(RLIMIT_DATA);
82597+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82598 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82599 (mm->end_data - mm->start_data) > rlim)
82600 goto out;
82601@@ -933,6 +956,12 @@ static int
82602 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82603 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82604 {
82605+
82606+#ifdef CONFIG_PAX_SEGMEXEC
82607+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82608+ return 0;
82609+#endif
82610+
82611 if (is_mergeable_vma(vma, file, vm_flags) &&
82612 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82613 if (vma->vm_pgoff == vm_pgoff)
82614@@ -952,6 +981,12 @@ static int
82615 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82616 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82617 {
82618+
82619+#ifdef CONFIG_PAX_SEGMEXEC
82620+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82621+ return 0;
82622+#endif
82623+
82624 if (is_mergeable_vma(vma, file, vm_flags) &&
82625 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82626 pgoff_t vm_pglen;
82627@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82628 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82629 struct vm_area_struct *prev, unsigned long addr,
82630 unsigned long end, unsigned long vm_flags,
82631- struct anon_vma *anon_vma, struct file *file,
82632+ struct anon_vma *anon_vma, struct file *file,
82633 pgoff_t pgoff, struct mempolicy *policy)
82634 {
82635 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82636 struct vm_area_struct *area, *next;
82637 int err;
82638
82639+#ifdef CONFIG_PAX_SEGMEXEC
82640+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82641+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82642+
82643+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82644+#endif
82645+
82646 /*
82647 * We later require that vma->vm_flags == vm_flags,
82648 * so this tests vma->vm_flags & VM_SPECIAL, too.
82649@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82650 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82651 next = next->vm_next;
82652
82653+#ifdef CONFIG_PAX_SEGMEXEC
82654+ if (prev)
82655+ prev_m = pax_find_mirror_vma(prev);
82656+ if (area)
82657+ area_m = pax_find_mirror_vma(area);
82658+ if (next)
82659+ next_m = pax_find_mirror_vma(next);
82660+#endif
82661+
82662 /*
82663 * Can it merge with the predecessor?
82664 */
82665@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82666 /* cases 1, 6 */
82667 err = vma_adjust(prev, prev->vm_start,
82668 next->vm_end, prev->vm_pgoff, NULL);
82669- } else /* cases 2, 5, 7 */
82670+
82671+#ifdef CONFIG_PAX_SEGMEXEC
82672+ if (!err && prev_m)
82673+ err = vma_adjust(prev_m, prev_m->vm_start,
82674+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82675+#endif
82676+
82677+ } else { /* cases 2, 5, 7 */
82678 err = vma_adjust(prev, prev->vm_start,
82679 end, prev->vm_pgoff, NULL);
82680+
82681+#ifdef CONFIG_PAX_SEGMEXEC
82682+ if (!err && prev_m)
82683+ err = vma_adjust(prev_m, prev_m->vm_start,
82684+ end_m, prev_m->vm_pgoff, NULL);
82685+#endif
82686+
82687+ }
82688 if (err)
82689 return NULL;
82690 khugepaged_enter_vma_merge(prev);
82691@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82692 mpol_equal(policy, vma_policy(next)) &&
82693 can_vma_merge_before(next, vm_flags,
82694 anon_vma, file, pgoff+pglen)) {
82695- if (prev && addr < prev->vm_end) /* case 4 */
82696+ if (prev && addr < prev->vm_end) { /* case 4 */
82697 err = vma_adjust(prev, prev->vm_start,
82698 addr, prev->vm_pgoff, NULL);
82699- else /* cases 3, 8 */
82700+
82701+#ifdef CONFIG_PAX_SEGMEXEC
82702+ if (!err && prev_m)
82703+ err = vma_adjust(prev_m, prev_m->vm_start,
82704+ addr_m, prev_m->vm_pgoff, NULL);
82705+#endif
82706+
82707+ } else { /* cases 3, 8 */
82708 err = vma_adjust(area, addr, next->vm_end,
82709 next->vm_pgoff - pglen, NULL);
82710+
82711+#ifdef CONFIG_PAX_SEGMEXEC
82712+ if (!err && area_m)
82713+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82714+ next_m->vm_pgoff - pglen, NULL);
82715+#endif
82716+
82717+ }
82718 if (err)
82719 return NULL;
82720 khugepaged_enter_vma_merge(area);
82721@@ -1165,8 +1246,10 @@ none:
82722 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82723 struct file *file, long pages)
82724 {
82725- const unsigned long stack_flags
82726- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82727+
82728+#ifdef CONFIG_PAX_RANDMMAP
82729+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82730+#endif
82731
82732 mm->total_vm += pages;
82733
82734@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82735 mm->shared_vm += pages;
82736 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82737 mm->exec_vm += pages;
82738- } else if (flags & stack_flags)
82739+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82740 mm->stack_vm += pages;
82741 }
82742 #endif /* CONFIG_PROC_FS */
82743@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82744 * (the exception is when the underlying filesystem is noexec
82745 * mounted, in which case we dont add PROT_EXEC.)
82746 */
82747- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82748+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82749 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82750 prot |= PROT_EXEC;
82751
82752@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82753 /* Obtain the address to map to. we verify (or select) it and ensure
82754 * that it represents a valid section of the address space.
82755 */
82756- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82757+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82758 if (addr & ~PAGE_MASK)
82759 return addr;
82760
82761@@ -1250,6 +1333,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82762 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82763 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82764
82765+#ifdef CONFIG_PAX_MPROTECT
82766+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82767+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82768+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82769+ gr_log_rwxmmap(file);
82770+
82771+#ifdef CONFIG_PAX_EMUPLT
82772+ vm_flags &= ~VM_EXEC;
82773+#else
82774+ return -EPERM;
82775+#endif
82776+
82777+ }
82778+
82779+ if (!(vm_flags & VM_EXEC))
82780+ vm_flags &= ~VM_MAYEXEC;
82781+#else
82782+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82783+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82784+#endif
82785+ else
82786+ vm_flags &= ~VM_MAYWRITE;
82787+ }
82788+#endif
82789+
82790+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82791+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82792+ vm_flags &= ~VM_PAGEEXEC;
82793+#endif
82794+
82795 if (flags & MAP_LOCKED)
82796 if (!can_do_mlock())
82797 return -EPERM;
82798@@ -1261,6 +1374,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82799 locked += mm->locked_vm;
82800 lock_limit = rlimit(RLIMIT_MEMLOCK);
82801 lock_limit >>= PAGE_SHIFT;
82802+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82803 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82804 return -EAGAIN;
82805 }
82806@@ -1341,6 +1455,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82807 vm_flags |= VM_NORESERVE;
82808 }
82809
82810+ if (!gr_acl_handle_mmap(file, prot))
82811+ return -EACCES;
82812+
82813 addr = mmap_region(file, addr, len, vm_flags, pgoff);
82814 if (!IS_ERR_VALUE(addr) &&
82815 ((vm_flags & VM_LOCKED) ||
82816@@ -1432,7 +1549,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82817 vm_flags_t vm_flags = vma->vm_flags;
82818
82819 /* If it was private or non-writable, the write bit is already clear */
82820- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82821+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82822 return 0;
82823
82824 /* The backer wishes to know when pages are first written to? */
82825@@ -1480,7 +1597,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82826 unsigned long charged = 0;
82827 struct inode *inode = file ? file_inode(file) : NULL;
82828
82829+#ifdef CONFIG_PAX_SEGMEXEC
82830+ struct vm_area_struct *vma_m = NULL;
82831+#endif
82832+
82833+ /*
82834+ * mm->mmap_sem is required to protect against another thread
82835+ * changing the mappings in case we sleep.
82836+ */
82837+ verify_mm_writelocked(mm);
82838+
82839 /* Check against address space limit. */
82840+
82841+#ifdef CONFIG_PAX_RANDMMAP
82842+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82843+#endif
82844+
82845 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
82846 unsigned long nr_pages;
82847
82848@@ -1499,11 +1631,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82849
82850 /* Clear old maps */
82851 error = -ENOMEM;
82852-munmap_back:
82853 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82854 if (do_munmap(mm, addr, len))
82855 return -ENOMEM;
82856- goto munmap_back;
82857+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82858 }
82859
82860 /*
82861@@ -1534,6 +1665,16 @@ munmap_back:
82862 goto unacct_error;
82863 }
82864
82865+#ifdef CONFIG_PAX_SEGMEXEC
82866+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82867+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82868+ if (!vma_m) {
82869+ error = -ENOMEM;
82870+ goto free_vma;
82871+ }
82872+ }
82873+#endif
82874+
82875 vma->vm_mm = mm;
82876 vma->vm_start = addr;
82877 vma->vm_end = addr + len;
82878@@ -1558,6 +1699,13 @@ munmap_back:
82879 if (error)
82880 goto unmap_and_free_vma;
82881
82882+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82883+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82884+ vma->vm_flags |= VM_PAGEEXEC;
82885+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82886+ }
82887+#endif
82888+
82889 /* Can addr have changed??
82890 *
82891 * Answer: Yes, several device drivers can do it in their
82892@@ -1596,6 +1744,11 @@ munmap_back:
82893 vma_link(mm, vma, prev, rb_link, rb_parent);
82894 file = vma->vm_file;
82895
82896+#ifdef CONFIG_PAX_SEGMEXEC
82897+ if (vma_m)
82898+ BUG_ON(pax_mirror_vma(vma_m, vma));
82899+#endif
82900+
82901 /* Once vma denies write, undo our temporary denial count */
82902 if (correct_wcount)
82903 atomic_inc(&inode->i_writecount);
82904@@ -1603,6 +1756,7 @@ out:
82905 perf_event_mmap(vma);
82906
82907 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82908+ track_exec_limit(mm, addr, addr + len, vm_flags);
82909 if (vm_flags & VM_LOCKED) {
82910 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
82911 vma == get_gate_vma(current->mm)))
82912@@ -1626,6 +1780,12 @@ unmap_and_free_vma:
82913 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82914 charged = 0;
82915 free_vma:
82916+
82917+#ifdef CONFIG_PAX_SEGMEXEC
82918+ if (vma_m)
82919+ kmem_cache_free(vm_area_cachep, vma_m);
82920+#endif
82921+
82922 kmem_cache_free(vm_area_cachep, vma);
82923 unacct_error:
82924 if (charged)
82925@@ -1633,7 +1793,63 @@ unacct_error:
82926 return error;
82927 }
82928
82929-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82930+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82931+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82932+{
82933+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82934+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
82935+
82936+ return 0;
82937+}
82938+#endif
82939+
82940+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82941+{
82942+ if (!vma) {
82943+#ifdef CONFIG_STACK_GROWSUP
82944+ if (addr > sysctl_heap_stack_gap)
82945+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82946+ else
82947+ vma = find_vma(current->mm, 0);
82948+ if (vma && (vma->vm_flags & VM_GROWSUP))
82949+ return false;
82950+#endif
82951+ return true;
82952+ }
82953+
82954+ if (addr + len > vma->vm_start)
82955+ return false;
82956+
82957+ if (vma->vm_flags & VM_GROWSDOWN)
82958+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82959+#ifdef CONFIG_STACK_GROWSUP
82960+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82961+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
82962+#endif
82963+ else if (offset)
82964+ return offset <= vma->vm_start - addr - len;
82965+
82966+ return true;
82967+}
82968+
82969+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82970+{
82971+ if (vma->vm_start < len)
82972+ return -ENOMEM;
82973+
82974+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82975+ if (offset <= vma->vm_start - len)
82976+ return vma->vm_start - len - offset;
82977+ else
82978+ return -ENOMEM;
82979+ }
82980+
82981+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82982+ return vma->vm_start - len - sysctl_heap_stack_gap;
82983+ return -ENOMEM;
82984+}
82985+
82986+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
82987 {
82988 /*
82989 * We implement the search by looking for an rbtree node that
82990@@ -1681,11 +1897,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82991 }
82992 }
82993
82994- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
82995+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
82996 check_current:
82997 /* Check if current node has a suitable gap */
82998 if (gap_start > high_limit)
82999 return -ENOMEM;
83000+
83001+ if (gap_end - gap_start > info->threadstack_offset)
83002+ gap_start += info->threadstack_offset;
83003+ else
83004+ gap_start = gap_end;
83005+
83006+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
83007+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83008+ gap_start += sysctl_heap_stack_gap;
83009+ else
83010+ gap_start = gap_end;
83011+ }
83012+ if (vma->vm_flags & VM_GROWSDOWN) {
83013+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83014+ gap_end -= sysctl_heap_stack_gap;
83015+ else
83016+ gap_end = gap_start;
83017+ }
83018 if (gap_end >= low_limit && gap_end - gap_start >= length)
83019 goto found;
83020
83021@@ -1735,7 +1969,7 @@ found:
83022 return gap_start;
83023 }
83024
83025-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
83026+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
83027 {
83028 struct mm_struct *mm = current->mm;
83029 struct vm_area_struct *vma;
83030@@ -1789,6 +2023,24 @@ check_current:
83031 gap_end = vma->vm_start;
83032 if (gap_end < low_limit)
83033 return -ENOMEM;
83034+
83035+ if (gap_end - gap_start > info->threadstack_offset)
83036+ gap_end -= info->threadstack_offset;
83037+ else
83038+ gap_end = gap_start;
83039+
83040+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
83041+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83042+ gap_start += sysctl_heap_stack_gap;
83043+ else
83044+ gap_start = gap_end;
83045+ }
83046+ if (vma->vm_flags & VM_GROWSDOWN) {
83047+ if (gap_end - gap_start > sysctl_heap_stack_gap)
83048+ gap_end -= sysctl_heap_stack_gap;
83049+ else
83050+ gap_end = gap_start;
83051+ }
83052 if (gap_start <= high_limit && gap_end - gap_start >= length)
83053 goto found;
83054
83055@@ -1852,6 +2104,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83056 struct mm_struct *mm = current->mm;
83057 struct vm_area_struct *vma;
83058 struct vm_unmapped_area_info info;
83059+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83060
83061 if (len > TASK_SIZE)
83062 return -ENOMEM;
83063@@ -1859,29 +2112,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
83064 if (flags & MAP_FIXED)
83065 return addr;
83066
83067+#ifdef CONFIG_PAX_RANDMMAP
83068+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83069+#endif
83070+
83071 if (addr) {
83072 addr = PAGE_ALIGN(addr);
83073 vma = find_vma(mm, addr);
83074- if (TASK_SIZE - len >= addr &&
83075- (!vma || addr + len <= vma->vm_start))
83076+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83077 return addr;
83078 }
83079
83080 info.flags = 0;
83081 info.length = len;
83082 info.low_limit = TASK_UNMAPPED_BASE;
83083+
83084+#ifdef CONFIG_PAX_RANDMMAP
83085+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83086+ info.low_limit += mm->delta_mmap;
83087+#endif
83088+
83089 info.high_limit = TASK_SIZE;
83090 info.align_mask = 0;
83091+ info.threadstack_offset = offset;
83092 return vm_unmapped_area(&info);
83093 }
83094 #endif
83095
83096 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
83097 {
83098+
83099+#ifdef CONFIG_PAX_SEGMEXEC
83100+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83101+ return;
83102+#endif
83103+
83104 /*
83105 * Is this a new hole at the lowest possible address?
83106 */
83107- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
83108+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
83109 mm->free_area_cache = addr;
83110 }
83111
83112@@ -1899,6 +2168,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83113 struct mm_struct *mm = current->mm;
83114 unsigned long addr = addr0;
83115 struct vm_unmapped_area_info info;
83116+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
83117
83118 /* requested length too big for entire address space */
83119 if (len > TASK_SIZE)
83120@@ -1907,12 +2177,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83121 if (flags & MAP_FIXED)
83122 return addr;
83123
83124+#ifdef CONFIG_PAX_RANDMMAP
83125+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
83126+#endif
83127+
83128 /* requesting a specific address */
83129 if (addr) {
83130 addr = PAGE_ALIGN(addr);
83131 vma = find_vma(mm, addr);
83132- if (TASK_SIZE - len >= addr &&
83133- (!vma || addr + len <= vma->vm_start))
83134+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
83135 return addr;
83136 }
83137
83138@@ -1921,6 +2194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83139 info.low_limit = PAGE_SIZE;
83140 info.high_limit = mm->mmap_base;
83141 info.align_mask = 0;
83142+ info.threadstack_offset = offset;
83143 addr = vm_unmapped_area(&info);
83144
83145 /*
83146@@ -1933,6 +2207,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83147 VM_BUG_ON(addr != -ENOMEM);
83148 info.flags = 0;
83149 info.low_limit = TASK_UNMAPPED_BASE;
83150+
83151+#ifdef CONFIG_PAX_RANDMMAP
83152+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83153+ info.low_limit += mm->delta_mmap;
83154+#endif
83155+
83156 info.high_limit = TASK_SIZE;
83157 addr = vm_unmapped_area(&info);
83158 }
83159@@ -1943,6 +2223,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
83160
83161 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83162 {
83163+
83164+#ifdef CONFIG_PAX_SEGMEXEC
83165+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
83166+ return;
83167+#endif
83168+
83169 /*
83170 * Is this a new hole at the highest possible address?
83171 */
83172@@ -1950,8 +2236,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
83173 mm->free_area_cache = addr;
83174
83175 /* dont allow allocations above current base */
83176- if (mm->free_area_cache > mm->mmap_base)
83177+ if (mm->free_area_cache > mm->mmap_base) {
83178 mm->free_area_cache = mm->mmap_base;
83179+ mm->cached_hole_size = ~0UL;
83180+ }
83181 }
83182
83183 unsigned long
83184@@ -2047,6 +2335,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
83185 return vma;
83186 }
83187
83188+#ifdef CONFIG_PAX_SEGMEXEC
83189+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
83190+{
83191+ struct vm_area_struct *vma_m;
83192+
83193+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
83194+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
83195+ BUG_ON(vma->vm_mirror);
83196+ return NULL;
83197+ }
83198+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
83199+ vma_m = vma->vm_mirror;
83200+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
83201+ BUG_ON(vma->vm_file != vma_m->vm_file);
83202+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
83203+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
83204+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
83205+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
83206+ return vma_m;
83207+}
83208+#endif
83209+
83210 /*
83211 * Verify that the stack growth is acceptable and
83212 * update accounting. This is shared with both the
83213@@ -2063,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83214 return -ENOMEM;
83215
83216 /* Stack limit test */
83217+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
83218 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
83219 return -ENOMEM;
83220
83221@@ -2073,6 +2384,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83222 locked = mm->locked_vm + grow;
83223 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
83224 limit >>= PAGE_SHIFT;
83225+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
83226 if (locked > limit && !capable(CAP_IPC_LOCK))
83227 return -ENOMEM;
83228 }
83229@@ -2102,37 +2414,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83230 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
83231 * vma is the last one with address > vma->vm_end. Have to extend vma.
83232 */
83233+#ifndef CONFIG_IA64
83234+static
83235+#endif
83236 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83237 {
83238 int error;
83239+ bool locknext;
83240
83241 if (!(vma->vm_flags & VM_GROWSUP))
83242 return -EFAULT;
83243
83244+ /* Also guard against wrapping around to address 0. */
83245+ if (address < PAGE_ALIGN(address+1))
83246+ address = PAGE_ALIGN(address+1);
83247+ else
83248+ return -ENOMEM;
83249+
83250 /*
83251 * We must make sure the anon_vma is allocated
83252 * so that the anon_vma locking is not a noop.
83253 */
83254 if (unlikely(anon_vma_prepare(vma)))
83255 return -ENOMEM;
83256+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
83257+ if (locknext && anon_vma_prepare(vma->vm_next))
83258+ return -ENOMEM;
83259 vma_lock_anon_vma(vma);
83260+ if (locknext)
83261+ vma_lock_anon_vma(vma->vm_next);
83262
83263 /*
83264 * vma->vm_start/vm_end cannot change under us because the caller
83265 * is required to hold the mmap_sem in read mode. We need the
83266- * anon_vma lock to serialize against concurrent expand_stacks.
83267- * Also guard against wrapping around to address 0.
83268+ * anon_vma locks to serialize against concurrent expand_stacks
83269+ * and expand_upwards.
83270 */
83271- if (address < PAGE_ALIGN(address+4))
83272- address = PAGE_ALIGN(address+4);
83273- else {
83274- vma_unlock_anon_vma(vma);
83275- return -ENOMEM;
83276- }
83277 error = 0;
83278
83279 /* Somebody else might have raced and expanded it already */
83280- if (address > vma->vm_end) {
83281+ 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)
83282+ error = -ENOMEM;
83283+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
83284 unsigned long size, grow;
83285
83286 size = address - vma->vm_start;
83287@@ -2167,6 +2490,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83288 }
83289 }
83290 }
83291+ if (locknext)
83292+ vma_unlock_anon_vma(vma->vm_next);
83293 vma_unlock_anon_vma(vma);
83294 khugepaged_enter_vma_merge(vma);
83295 validate_mm(vma->vm_mm);
83296@@ -2181,6 +2506,8 @@ int expand_downwards(struct vm_area_struct *vma,
83297 unsigned long address)
83298 {
83299 int error;
83300+ bool lockprev = false;
83301+ struct vm_area_struct *prev;
83302
83303 /*
83304 * We must make sure the anon_vma is allocated
83305@@ -2194,6 +2521,15 @@ int expand_downwards(struct vm_area_struct *vma,
83306 if (error)
83307 return error;
83308
83309+ prev = vma->vm_prev;
83310+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
83311+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
83312+#endif
83313+ if (lockprev && anon_vma_prepare(prev))
83314+ return -ENOMEM;
83315+ if (lockprev)
83316+ vma_lock_anon_vma(prev);
83317+
83318 vma_lock_anon_vma(vma);
83319
83320 /*
83321@@ -2203,9 +2539,17 @@ int expand_downwards(struct vm_area_struct *vma,
83322 */
83323
83324 /* Somebody else might have raced and expanded it already */
83325- if (address < vma->vm_start) {
83326+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
83327+ error = -ENOMEM;
83328+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
83329 unsigned long size, grow;
83330
83331+#ifdef CONFIG_PAX_SEGMEXEC
83332+ struct vm_area_struct *vma_m;
83333+
83334+ vma_m = pax_find_mirror_vma(vma);
83335+#endif
83336+
83337 size = vma->vm_end - address;
83338 grow = (vma->vm_start - address) >> PAGE_SHIFT;
83339
83340@@ -2230,13 +2574,27 @@ int expand_downwards(struct vm_area_struct *vma,
83341 vma->vm_pgoff -= grow;
83342 anon_vma_interval_tree_post_update_vma(vma);
83343 vma_gap_update(vma);
83344+
83345+#ifdef CONFIG_PAX_SEGMEXEC
83346+ if (vma_m) {
83347+ anon_vma_interval_tree_pre_update_vma(vma_m);
83348+ vma_m->vm_start -= grow << PAGE_SHIFT;
83349+ vma_m->vm_pgoff -= grow;
83350+ anon_vma_interval_tree_post_update_vma(vma_m);
83351+ vma_gap_update(vma_m);
83352+ }
83353+#endif
83354+
83355 spin_unlock(&vma->vm_mm->page_table_lock);
83356
83357+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
83358 perf_event_mmap(vma);
83359 }
83360 }
83361 }
83362 vma_unlock_anon_vma(vma);
83363+ if (lockprev)
83364+ vma_unlock_anon_vma(prev);
83365 khugepaged_enter_vma_merge(vma);
83366 validate_mm(vma->vm_mm);
83367 return error;
83368@@ -2334,6 +2692,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
83369 do {
83370 long nrpages = vma_pages(vma);
83371
83372+#ifdef CONFIG_PAX_SEGMEXEC
83373+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
83374+ vma = remove_vma(vma);
83375+ continue;
83376+ }
83377+#endif
83378+
83379 if (vma->vm_flags & VM_ACCOUNT)
83380 nr_accounted += nrpages;
83381 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
83382@@ -2379,6 +2744,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
83383 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
83384 vma->vm_prev = NULL;
83385 do {
83386+
83387+#ifdef CONFIG_PAX_SEGMEXEC
83388+ if (vma->vm_mirror) {
83389+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
83390+ vma->vm_mirror->vm_mirror = NULL;
83391+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
83392+ vma->vm_mirror = NULL;
83393+ }
83394+#endif
83395+
83396 vma_rb_erase(vma, &mm->mm_rb);
83397 mm->map_count--;
83398 tail_vma = vma;
83399@@ -2410,14 +2785,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83400 struct vm_area_struct *new;
83401 int err = -ENOMEM;
83402
83403+#ifdef CONFIG_PAX_SEGMEXEC
83404+ struct vm_area_struct *vma_m, *new_m = NULL;
83405+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
83406+#endif
83407+
83408 if (is_vm_hugetlb_page(vma) && (addr &
83409 ~(huge_page_mask(hstate_vma(vma)))))
83410 return -EINVAL;
83411
83412+#ifdef CONFIG_PAX_SEGMEXEC
83413+ vma_m = pax_find_mirror_vma(vma);
83414+#endif
83415+
83416 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83417 if (!new)
83418 goto out_err;
83419
83420+#ifdef CONFIG_PAX_SEGMEXEC
83421+ if (vma_m) {
83422+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83423+ if (!new_m) {
83424+ kmem_cache_free(vm_area_cachep, new);
83425+ goto out_err;
83426+ }
83427+ }
83428+#endif
83429+
83430 /* most fields are the same, copy all, and then fixup */
83431 *new = *vma;
83432
83433@@ -2430,6 +2824,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83434 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
83435 }
83436
83437+#ifdef CONFIG_PAX_SEGMEXEC
83438+ if (vma_m) {
83439+ *new_m = *vma_m;
83440+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
83441+ new_m->vm_mirror = new;
83442+ new->vm_mirror = new_m;
83443+
83444+ if (new_below)
83445+ new_m->vm_end = addr_m;
83446+ else {
83447+ new_m->vm_start = addr_m;
83448+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
83449+ }
83450+ }
83451+#endif
83452+
83453 pol = mpol_dup(vma_policy(vma));
83454 if (IS_ERR(pol)) {
83455 err = PTR_ERR(pol);
83456@@ -2452,6 +2862,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83457 else
83458 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83459
83460+#ifdef CONFIG_PAX_SEGMEXEC
83461+ if (!err && vma_m) {
83462+ if (anon_vma_clone(new_m, vma_m))
83463+ goto out_free_mpol;
83464+
83465+ mpol_get(pol);
83466+ vma_set_policy(new_m, pol);
83467+
83468+ if (new_m->vm_file)
83469+ get_file(new_m->vm_file);
83470+
83471+ if (new_m->vm_ops && new_m->vm_ops->open)
83472+ new_m->vm_ops->open(new_m);
83473+
83474+ if (new_below)
83475+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83476+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83477+ else
83478+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83479+
83480+ if (err) {
83481+ if (new_m->vm_ops && new_m->vm_ops->close)
83482+ new_m->vm_ops->close(new_m);
83483+ if (new_m->vm_file)
83484+ fput(new_m->vm_file);
83485+ mpol_put(pol);
83486+ }
83487+ }
83488+#endif
83489+
83490 /* Success. */
83491 if (!err)
83492 return 0;
83493@@ -2461,10 +2901,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83494 new->vm_ops->close(new);
83495 if (new->vm_file)
83496 fput(new->vm_file);
83497- unlink_anon_vmas(new);
83498 out_free_mpol:
83499 mpol_put(pol);
83500 out_free_vma:
83501+
83502+#ifdef CONFIG_PAX_SEGMEXEC
83503+ if (new_m) {
83504+ unlink_anon_vmas(new_m);
83505+ kmem_cache_free(vm_area_cachep, new_m);
83506+ }
83507+#endif
83508+
83509+ unlink_anon_vmas(new);
83510 kmem_cache_free(vm_area_cachep, new);
83511 out_err:
83512 return err;
83513@@ -2477,6 +2925,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83514 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83515 unsigned long addr, int new_below)
83516 {
83517+
83518+#ifdef CONFIG_PAX_SEGMEXEC
83519+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83520+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83521+ if (mm->map_count >= sysctl_max_map_count-1)
83522+ return -ENOMEM;
83523+ } else
83524+#endif
83525+
83526 if (mm->map_count >= sysctl_max_map_count)
83527 return -ENOMEM;
83528
83529@@ -2488,11 +2945,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83530 * work. This now handles partial unmappings.
83531 * Jeremy Fitzhardinge <jeremy@goop.org>
83532 */
83533+#ifdef CONFIG_PAX_SEGMEXEC
83534 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83535 {
83536+ int ret = __do_munmap(mm, start, len);
83537+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83538+ return ret;
83539+
83540+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83541+}
83542+
83543+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83544+#else
83545+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83546+#endif
83547+{
83548 unsigned long end;
83549 struct vm_area_struct *vma, *prev, *last;
83550
83551+ /*
83552+ * mm->mmap_sem is required to protect against another thread
83553+ * changing the mappings in case we sleep.
83554+ */
83555+ verify_mm_writelocked(mm);
83556+
83557 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83558 return -EINVAL;
83559
83560@@ -2567,6 +3043,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83561 /* Fix up all other VM information */
83562 remove_vma_list(mm, vma);
83563
83564+ track_exec_limit(mm, start, end, 0UL);
83565+
83566 return 0;
83567 }
83568
83569@@ -2575,6 +3053,13 @@ int vm_munmap(unsigned long start, size_t len)
83570 int ret;
83571 struct mm_struct *mm = current->mm;
83572
83573+
83574+#ifdef CONFIG_PAX_SEGMEXEC
83575+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83576+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83577+ return -EINVAL;
83578+#endif
83579+
83580 down_write(&mm->mmap_sem);
83581 ret = do_munmap(mm, start, len);
83582 up_write(&mm->mmap_sem);
83583@@ -2588,16 +3073,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83584 return vm_munmap(addr, len);
83585 }
83586
83587-static inline void verify_mm_writelocked(struct mm_struct *mm)
83588-{
83589-#ifdef CONFIG_DEBUG_VM
83590- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83591- WARN_ON(1);
83592- up_read(&mm->mmap_sem);
83593- }
83594-#endif
83595-}
83596-
83597 /*
83598 * this is really a simplified "do_mmap". it only handles
83599 * anonymous maps. eventually we may be able to do some
83600@@ -2611,6 +3086,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83601 struct rb_node ** rb_link, * rb_parent;
83602 pgoff_t pgoff = addr >> PAGE_SHIFT;
83603 int error;
83604+ unsigned long charged;
83605
83606 len = PAGE_ALIGN(len);
83607 if (!len)
83608@@ -2618,16 +3094,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83609
83610 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83611
83612+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83613+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83614+ flags &= ~VM_EXEC;
83615+
83616+#ifdef CONFIG_PAX_MPROTECT
83617+ if (mm->pax_flags & MF_PAX_MPROTECT)
83618+ flags &= ~VM_MAYEXEC;
83619+#endif
83620+
83621+ }
83622+#endif
83623+
83624 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83625 if (error & ~PAGE_MASK)
83626 return error;
83627
83628+ charged = len >> PAGE_SHIFT;
83629+
83630 /*
83631 * mlock MCL_FUTURE?
83632 */
83633 if (mm->def_flags & VM_LOCKED) {
83634 unsigned long locked, lock_limit;
83635- locked = len >> PAGE_SHIFT;
83636+ locked = charged;
83637 locked += mm->locked_vm;
83638 lock_limit = rlimit(RLIMIT_MEMLOCK);
83639 lock_limit >>= PAGE_SHIFT;
83640@@ -2644,21 +3134,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83641 /*
83642 * Clear old maps. this also does some error checking for us
83643 */
83644- munmap_back:
83645 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83646 if (do_munmap(mm, addr, len))
83647 return -ENOMEM;
83648- goto munmap_back;
83649+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83650 }
83651
83652 /* Check against address space limits *after* clearing old maps... */
83653- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83654+ if (!may_expand_vm(mm, charged))
83655 return -ENOMEM;
83656
83657 if (mm->map_count > sysctl_max_map_count)
83658 return -ENOMEM;
83659
83660- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83661+ if (security_vm_enough_memory_mm(mm, charged))
83662 return -ENOMEM;
83663
83664 /* Can we just expand an old private anonymous mapping? */
83665@@ -2672,7 +3161,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83666 */
83667 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83668 if (!vma) {
83669- vm_unacct_memory(len >> PAGE_SHIFT);
83670+ vm_unacct_memory(charged);
83671 return -ENOMEM;
83672 }
83673
83674@@ -2686,9 +3175,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83675 vma_link(mm, vma, prev, rb_link, rb_parent);
83676 out:
83677 perf_event_mmap(vma);
83678- mm->total_vm += len >> PAGE_SHIFT;
83679+ mm->total_vm += charged;
83680 if (flags & VM_LOCKED)
83681- mm->locked_vm += (len >> PAGE_SHIFT);
83682+ mm->locked_vm += charged;
83683+ track_exec_limit(mm, addr, addr + len, flags);
83684 return addr;
83685 }
83686
83687@@ -2750,6 +3240,7 @@ void exit_mmap(struct mm_struct *mm)
83688 while (vma) {
83689 if (vma->vm_flags & VM_ACCOUNT)
83690 nr_accounted += vma_pages(vma);
83691+ vma->vm_mirror = NULL;
83692 vma = remove_vma(vma);
83693 }
83694 vm_unacct_memory(nr_accounted);
83695@@ -2766,6 +3257,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83696 struct vm_area_struct *prev;
83697 struct rb_node **rb_link, *rb_parent;
83698
83699+#ifdef CONFIG_PAX_SEGMEXEC
83700+ struct vm_area_struct *vma_m = NULL;
83701+#endif
83702+
83703+ if (security_mmap_addr(vma->vm_start))
83704+ return -EPERM;
83705+
83706 /*
83707 * The vm_pgoff of a purely anonymous vma should be irrelevant
83708 * until its first write fault, when page's anon_vma and index
83709@@ -2789,7 +3287,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83710 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83711 return -ENOMEM;
83712
83713+#ifdef CONFIG_PAX_SEGMEXEC
83714+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83715+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83716+ if (!vma_m)
83717+ return -ENOMEM;
83718+ }
83719+#endif
83720+
83721 vma_link(mm, vma, prev, rb_link, rb_parent);
83722+
83723+#ifdef CONFIG_PAX_SEGMEXEC
83724+ if (vma_m)
83725+ BUG_ON(pax_mirror_vma(vma_m, vma));
83726+#endif
83727+
83728 return 0;
83729 }
83730
83731@@ -2809,6 +3321,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83732 struct mempolicy *pol;
83733 bool faulted_in_anon_vma = true;
83734
83735+ BUG_ON(vma->vm_mirror);
83736+
83737 /*
83738 * If anonymous vma has not yet been faulted, update new pgoff
83739 * to match new location, to increase its chance of merging.
83740@@ -2875,6 +3389,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83741 return NULL;
83742 }
83743
83744+#ifdef CONFIG_PAX_SEGMEXEC
83745+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83746+{
83747+ struct vm_area_struct *prev_m;
83748+ struct rb_node **rb_link_m, *rb_parent_m;
83749+ struct mempolicy *pol_m;
83750+
83751+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83752+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83753+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83754+ *vma_m = *vma;
83755+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83756+ if (anon_vma_clone(vma_m, vma))
83757+ return -ENOMEM;
83758+ pol_m = vma_policy(vma_m);
83759+ mpol_get(pol_m);
83760+ vma_set_policy(vma_m, pol_m);
83761+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83762+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83763+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83764+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83765+ if (vma_m->vm_file)
83766+ get_file(vma_m->vm_file);
83767+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83768+ vma_m->vm_ops->open(vma_m);
83769+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83770+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83771+ vma_m->vm_mirror = vma;
83772+ vma->vm_mirror = vma_m;
83773+ return 0;
83774+}
83775+#endif
83776+
83777 /*
83778 * Return true if the calling process may expand its vm space by the passed
83779 * number of pages
83780@@ -2886,6 +3433,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83781
83782 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83783
83784+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83785 if (cur + npages > lim)
83786 return 0;
83787 return 1;
83788@@ -2956,6 +3504,22 @@ int install_special_mapping(struct mm_struct *mm,
83789 vma->vm_start = addr;
83790 vma->vm_end = addr + len;
83791
83792+#ifdef CONFIG_PAX_MPROTECT
83793+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83794+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83795+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83796+ return -EPERM;
83797+ if (!(vm_flags & VM_EXEC))
83798+ vm_flags &= ~VM_MAYEXEC;
83799+#else
83800+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83801+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83802+#endif
83803+ else
83804+ vm_flags &= ~VM_MAYWRITE;
83805+ }
83806+#endif
83807+
83808 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83809 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83810
83811diff --git a/mm/mprotect.c b/mm/mprotect.c
83812index 94722a4..07d9926 100644
83813--- a/mm/mprotect.c
83814+++ b/mm/mprotect.c
83815@@ -23,10 +23,18 @@
83816 #include <linux/mmu_notifier.h>
83817 #include <linux/migrate.h>
83818 #include <linux/perf_event.h>
83819+#include <linux/sched/sysctl.h>
83820+
83821+#ifdef CONFIG_PAX_MPROTECT
83822+#include <linux/elf.h>
83823+#include <linux/binfmts.h>
83824+#endif
83825+
83826 #include <asm/uaccess.h>
83827 #include <asm/pgtable.h>
83828 #include <asm/cacheflush.h>
83829 #include <asm/tlbflush.h>
83830+#include <asm/mmu_context.h>
83831
83832 #ifndef pgprot_modify
83833 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83834@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83835 return pages;
83836 }
83837
83838+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83839+/* called while holding the mmap semaphor for writing except stack expansion */
83840+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83841+{
83842+ unsigned long oldlimit, newlimit = 0UL;
83843+
83844+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83845+ return;
83846+
83847+ spin_lock(&mm->page_table_lock);
83848+ oldlimit = mm->context.user_cs_limit;
83849+ if ((prot & VM_EXEC) && oldlimit < end)
83850+ /* USER_CS limit moved up */
83851+ newlimit = end;
83852+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83853+ /* USER_CS limit moved down */
83854+ newlimit = start;
83855+
83856+ if (newlimit) {
83857+ mm->context.user_cs_limit = newlimit;
83858+
83859+#ifdef CONFIG_SMP
83860+ wmb();
83861+ cpus_clear(mm->context.cpu_user_cs_mask);
83862+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83863+#endif
83864+
83865+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83866+ }
83867+ spin_unlock(&mm->page_table_lock);
83868+ if (newlimit == end) {
83869+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83870+
83871+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83872+ if (is_vm_hugetlb_page(vma))
83873+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83874+ else
83875+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83876+ }
83877+}
83878+#endif
83879+
83880 int
83881 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83882 unsigned long start, unsigned long end, unsigned long newflags)
83883@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83884 int error;
83885 int dirty_accountable = 0;
83886
83887+#ifdef CONFIG_PAX_SEGMEXEC
83888+ struct vm_area_struct *vma_m = NULL;
83889+ unsigned long start_m, end_m;
83890+
83891+ start_m = start + SEGMEXEC_TASK_SIZE;
83892+ end_m = end + SEGMEXEC_TASK_SIZE;
83893+#endif
83894+
83895 if (newflags == oldflags) {
83896 *pprev = vma;
83897 return 0;
83898 }
83899
83900+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83901+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83902+
83903+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83904+ return -ENOMEM;
83905+
83906+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83907+ return -ENOMEM;
83908+ }
83909+
83910 /*
83911 * If we make a private mapping writable we increase our commit;
83912 * but (without finer accounting) cannot reduce our commit if we
83913@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83914 }
83915 }
83916
83917+#ifdef CONFIG_PAX_SEGMEXEC
83918+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83919+ if (start != vma->vm_start) {
83920+ error = split_vma(mm, vma, start, 1);
83921+ if (error)
83922+ goto fail;
83923+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83924+ *pprev = (*pprev)->vm_next;
83925+ }
83926+
83927+ if (end != vma->vm_end) {
83928+ error = split_vma(mm, vma, end, 0);
83929+ if (error)
83930+ goto fail;
83931+ }
83932+
83933+ if (pax_find_mirror_vma(vma)) {
83934+ error = __do_munmap(mm, start_m, end_m - start_m);
83935+ if (error)
83936+ goto fail;
83937+ } else {
83938+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83939+ if (!vma_m) {
83940+ error = -ENOMEM;
83941+ goto fail;
83942+ }
83943+ vma->vm_flags = newflags;
83944+ error = pax_mirror_vma(vma_m, vma);
83945+ if (error) {
83946+ vma->vm_flags = oldflags;
83947+ goto fail;
83948+ }
83949+ }
83950+ }
83951+#endif
83952+
83953 /*
83954 * First try to merge with previous and/or next vma.
83955 */
83956@@ -296,9 +400,21 @@ success:
83957 * vm_flags and vm_page_prot are protected by the mmap_sem
83958 * held in write mode.
83959 */
83960+
83961+#ifdef CONFIG_PAX_SEGMEXEC
83962+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83963+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83964+#endif
83965+
83966 vma->vm_flags = newflags;
83967+
83968+#ifdef CONFIG_PAX_MPROTECT
83969+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83970+ mm->binfmt->handle_mprotect(vma, newflags);
83971+#endif
83972+
83973 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83974- vm_get_page_prot(newflags));
83975+ vm_get_page_prot(vma->vm_flags));
83976
83977 if (vma_wants_writenotify(vma)) {
83978 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83979@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83980 end = start + len;
83981 if (end <= start)
83982 return -ENOMEM;
83983+
83984+#ifdef CONFIG_PAX_SEGMEXEC
83985+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83986+ if (end > SEGMEXEC_TASK_SIZE)
83987+ return -EINVAL;
83988+ } else
83989+#endif
83990+
83991+ if (end > TASK_SIZE)
83992+ return -EINVAL;
83993+
83994 if (!arch_validate_prot(prot))
83995 return -EINVAL;
83996
83997@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83998 /*
83999 * Does the application expect PROT_READ to imply PROT_EXEC:
84000 */
84001- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
84002+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
84003 prot |= PROT_EXEC;
84004
84005 vm_flags = calc_vm_prot_bits(prot);
84006@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84007 if (start > vma->vm_start)
84008 prev = vma;
84009
84010+#ifdef CONFIG_PAX_MPROTECT
84011+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
84012+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
84013+#endif
84014+
84015 for (nstart = start ; ; ) {
84016 unsigned long newflags;
84017
84018@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84019
84020 /* newflags >> 4 shift VM_MAY% in place of VM_% */
84021 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
84022+ if (prot & (PROT_WRITE | PROT_EXEC))
84023+ gr_log_rwxmprotect(vma->vm_file);
84024+
84025+ error = -EACCES;
84026+ goto out;
84027+ }
84028+
84029+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
84030 error = -EACCES;
84031 goto out;
84032 }
84033@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
84034 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
84035 if (error)
84036 goto out;
84037+
84038+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
84039+
84040 nstart = tmp;
84041
84042 if (nstart < prev->vm_end)
84043diff --git a/mm/mremap.c b/mm/mremap.c
84044index 463a257..c0c7a92 100644
84045--- a/mm/mremap.c
84046+++ b/mm/mremap.c
84047@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
84048 continue;
84049 pte = ptep_get_and_clear(mm, old_addr, old_pte);
84050 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
84051+
84052+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
84053+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
84054+ pte = pte_exprotect(pte);
84055+#endif
84056+
84057 set_pte_at(mm, new_addr, new_pte, pte);
84058 }
84059
84060@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
84061 if (is_vm_hugetlb_page(vma))
84062 goto Einval;
84063
84064+#ifdef CONFIG_PAX_SEGMEXEC
84065+ if (pax_find_mirror_vma(vma))
84066+ goto Einval;
84067+#endif
84068+
84069 /* We can't remap across vm area boundaries */
84070 if (old_len > vma->vm_end - addr)
84071 goto Efault;
84072@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
84073 unsigned long ret = -EINVAL;
84074 unsigned long charged = 0;
84075 unsigned long map_flags;
84076+ unsigned long pax_task_size = TASK_SIZE;
84077
84078 if (new_addr & ~PAGE_MASK)
84079 goto out;
84080
84081- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
84082+#ifdef CONFIG_PAX_SEGMEXEC
84083+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84084+ pax_task_size = SEGMEXEC_TASK_SIZE;
84085+#endif
84086+
84087+ pax_task_size -= PAGE_SIZE;
84088+
84089+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
84090 goto out;
84091
84092 /* Check if the location we're moving into overlaps the
84093 * old location at all, and fail if it does.
84094 */
84095- if ((new_addr <= addr) && (new_addr+new_len) > addr)
84096- goto out;
84097-
84098- if ((addr <= new_addr) && (addr+old_len) > new_addr)
84099+ if (addr + old_len > new_addr && new_addr + new_len > addr)
84100 goto out;
84101
84102 ret = do_munmap(mm, new_addr, new_len);
84103@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84104 unsigned long ret = -EINVAL;
84105 unsigned long charged = 0;
84106 bool locked = false;
84107+ unsigned long pax_task_size = TASK_SIZE;
84108
84109 down_write(&current->mm->mmap_sem);
84110
84111@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84112 if (!new_len)
84113 goto out;
84114
84115+#ifdef CONFIG_PAX_SEGMEXEC
84116+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
84117+ pax_task_size = SEGMEXEC_TASK_SIZE;
84118+#endif
84119+
84120+ pax_task_size -= PAGE_SIZE;
84121+
84122+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
84123+ old_len > pax_task_size || addr > pax_task_size-old_len)
84124+ goto out;
84125+
84126 if (flags & MREMAP_FIXED) {
84127 if (flags & MREMAP_MAYMOVE)
84128 ret = mremap_to(addr, old_len, new_addr, new_len,
84129@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84130 new_addr = addr;
84131 }
84132 ret = addr;
84133+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
84134 goto out;
84135 }
84136 }
84137@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
84138 goto out;
84139 }
84140
84141+ map_flags = vma->vm_flags;
84142 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
84143+ if (!(ret & ~PAGE_MASK)) {
84144+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
84145+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
84146+ }
84147 }
84148 out:
84149 if (ret & ~PAGE_MASK)
84150diff --git a/mm/nommu.c b/mm/nommu.c
84151index 298884d..5f74980 100644
84152--- a/mm/nommu.c
84153+++ b/mm/nommu.c
84154@@ -65,7 +65,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
84155 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
84156 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
84157 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
84158-int heap_stack_gap = 0;
84159
84160 atomic_long_t mmap_pages_allocated;
84161
84162@@ -842,15 +841,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
84163 EXPORT_SYMBOL(find_vma);
84164
84165 /*
84166- * find a VMA
84167- * - we don't extend stack VMAs under NOMMU conditions
84168- */
84169-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
84170-{
84171- return find_vma(mm, addr);
84172-}
84173-
84174-/*
84175 * expand a stack to a given address
84176 * - not supported under NOMMU conditions
84177 */
84178@@ -1561,6 +1551,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
84179
84180 /* most fields are the same, copy all, and then fixup */
84181 *new = *vma;
84182+ INIT_LIST_HEAD(&new->anon_vma_chain);
84183 *region = *vma->vm_region;
84184 new->vm_region = region;
84185
84186@@ -1995,8 +1986,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
84187 }
84188 EXPORT_SYMBOL(generic_file_remap_pages);
84189
84190-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84191- unsigned long addr, void *buf, int len, int write)
84192+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84193+ unsigned long addr, void *buf, size_t len, int write)
84194 {
84195 struct vm_area_struct *vma;
84196
84197@@ -2037,8 +2028,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
84198 *
84199 * The caller must hold a reference on @mm.
84200 */
84201-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84202- void *buf, int len, int write)
84203+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
84204+ void *buf, size_t len, int write)
84205 {
84206 return __access_remote_vm(NULL, mm, addr, buf, len, write);
84207 }
84208@@ -2047,7 +2038,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
84209 * Access another process' address space.
84210 * - source/target buffer must be kernel space
84211 */
84212-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
84213+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
84214 {
84215 struct mm_struct *mm;
84216
84217diff --git a/mm/page-writeback.c b/mm/page-writeback.c
84218index 4514ad7..92eaa1c 100644
84219--- a/mm/page-writeback.c
84220+++ b/mm/page-writeback.c
84221@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
84222 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
84223 * - the bdi dirty thresh drops quickly due to change of JBOD workload
84224 */
84225-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
84226+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
84227 unsigned long thresh,
84228 unsigned long bg_thresh,
84229 unsigned long dirty,
84230@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
84231 }
84232 }
84233
84234-static struct notifier_block __cpuinitdata ratelimit_nb = {
84235+static struct notifier_block ratelimit_nb = {
84236 .notifier_call = ratelimit_handler,
84237 .next = NULL,
84238 };
84239diff --git a/mm/page_alloc.c b/mm/page_alloc.c
84240index c3edb62..2d60097 100644
84241--- a/mm/page_alloc.c
84242+++ b/mm/page_alloc.c
84243@@ -60,6 +60,7 @@
84244 #include <linux/page-debug-flags.h>
84245 #include <linux/hugetlb.h>
84246 #include <linux/sched/rt.h>
84247+#include <linux/random.h>
84248
84249 #include <asm/tlbflush.h>
84250 #include <asm/div64.h>
84251@@ -345,7 +346,7 @@ out:
84252 * This usage means that zero-order pages may not be compound.
84253 */
84254
84255-static void free_compound_page(struct page *page)
84256+void free_compound_page(struct page *page)
84257 {
84258 __free_pages_ok(page, compound_order(page));
84259 }
84260@@ -702,6 +703,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84261 int i;
84262 int bad = 0;
84263
84264+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84265+ unsigned long index = 1UL << order;
84266+#endif
84267+
84268 trace_mm_page_free(page, order);
84269 kmemcheck_free_shadow(page, order);
84270
84271@@ -717,6 +722,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84272 debug_check_no_obj_freed(page_address(page),
84273 PAGE_SIZE << order);
84274 }
84275+
84276+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84277+ for (; index; --index)
84278+ sanitize_highpage(page + index - 1);
84279+#endif
84280+
84281 arch_free_page(page, order);
84282 kernel_map_pages(page, 1 << order, 0);
84283
84284@@ -739,6 +750,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
84285 local_irq_restore(flags);
84286 }
84287
84288+#ifdef CONFIG_PAX_LATENT_ENTROPY
84289+bool __meminitdata extra_latent_entropy;
84290+
84291+static int __init setup_pax_extra_latent_entropy(char *str)
84292+{
84293+ extra_latent_entropy = true;
84294+ return 0;
84295+}
84296+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
84297+
84298+volatile u64 latent_entropy;
84299+#endif
84300+
84301 /*
84302 * Read access to zone->managed_pages is safe because it's unsigned long,
84303 * but we still need to serialize writers. Currently all callers of
84304@@ -761,6 +785,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
84305 set_page_count(p, 0);
84306 }
84307
84308+#ifdef CONFIG_PAX_LATENT_ENTROPY
84309+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
84310+ u64 hash = 0;
84311+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
84312+ const u64 *data = lowmem_page_address(page);
84313+
84314+ for (index = 0; index < end; index++)
84315+ hash ^= hash + data[index];
84316+ latent_entropy ^= hash;
84317+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84318+ }
84319+#endif
84320+
84321 page_zone(page)->managed_pages += 1 << order;
84322 set_page_refcounted(page);
84323 __free_pages(page, order);
84324@@ -870,8 +907,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
84325 arch_alloc_page(page, order);
84326 kernel_map_pages(page, 1 << order, 1);
84327
84328+#ifndef CONFIG_PAX_MEMORY_SANITIZE
84329 if (gfp_flags & __GFP_ZERO)
84330 prep_zero_page(page, order, gfp_flags);
84331+#endif
84332
84333 if (order && (gfp_flags & __GFP_COMP))
84334 prep_compound_page(page, order);
84335diff --git a/mm/page_io.c b/mm/page_io.c
84336index a8a3ef4..7260a60 100644
84337--- a/mm/page_io.c
84338+++ b/mm/page_io.c
84339@@ -214,7 +214,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
84340 struct file *swap_file = sis->swap_file;
84341 struct address_space *mapping = swap_file->f_mapping;
84342 struct iovec iov = {
84343- .iov_base = kmap(page),
84344+ .iov_base = (void __force_user *)kmap(page),
84345 .iov_len = PAGE_SIZE,
84346 };
84347
84348diff --git a/mm/percpu.c b/mm/percpu.c
84349index 8c8e08f..73a5cda 100644
84350--- a/mm/percpu.c
84351+++ b/mm/percpu.c
84352@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
84353 static unsigned int pcpu_high_unit_cpu __read_mostly;
84354
84355 /* the address of the first chunk which starts with the kernel static area */
84356-void *pcpu_base_addr __read_mostly;
84357+void *pcpu_base_addr __read_only;
84358 EXPORT_SYMBOL_GPL(pcpu_base_addr);
84359
84360 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
84361diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
84362index fd26d04..0cea1b0 100644
84363--- a/mm/process_vm_access.c
84364+++ b/mm/process_vm_access.c
84365@@ -13,6 +13,7 @@
84366 #include <linux/uio.h>
84367 #include <linux/sched.h>
84368 #include <linux/highmem.h>
84369+#include <linux/security.h>
84370 #include <linux/ptrace.h>
84371 #include <linux/slab.h>
84372 #include <linux/syscalls.h>
84373@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84374 size_t iov_l_curr_offset = 0;
84375 ssize_t iov_len;
84376
84377+ return -ENOSYS; // PaX: until properly audited
84378+
84379 /*
84380 * Work out how many pages of struct pages we're going to need
84381 * when eventually calling get_user_pages
84382 */
84383 for (i = 0; i < riovcnt; i++) {
84384 iov_len = rvec[i].iov_len;
84385- if (iov_len > 0) {
84386- nr_pages_iov = ((unsigned long)rvec[i].iov_base
84387- + iov_len)
84388- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
84389- / PAGE_SIZE + 1;
84390- nr_pages = max(nr_pages, nr_pages_iov);
84391- }
84392+ if (iov_len <= 0)
84393+ continue;
84394+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
84395+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
84396+ nr_pages = max(nr_pages, nr_pages_iov);
84397 }
84398
84399 if (nr_pages == 0)
84400@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84401 goto free_proc_pages;
84402 }
84403
84404+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
84405+ rc = -EPERM;
84406+ goto put_task_struct;
84407+ }
84408+
84409 mm = mm_access(task, PTRACE_MODE_ATTACH);
84410 if (!mm || IS_ERR(mm)) {
84411 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
84412diff --git a/mm/rmap.c b/mm/rmap.c
84413index 6280da8..ecce194 100644
84414--- a/mm/rmap.c
84415+++ b/mm/rmap.c
84416@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84417 struct anon_vma *anon_vma = vma->anon_vma;
84418 struct anon_vma_chain *avc;
84419
84420+#ifdef CONFIG_PAX_SEGMEXEC
84421+ struct anon_vma_chain *avc_m = NULL;
84422+#endif
84423+
84424 might_sleep();
84425 if (unlikely(!anon_vma)) {
84426 struct mm_struct *mm = vma->vm_mm;
84427@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84428 if (!avc)
84429 goto out_enomem;
84430
84431+#ifdef CONFIG_PAX_SEGMEXEC
84432+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
84433+ if (!avc_m)
84434+ goto out_enomem_free_avc;
84435+#endif
84436+
84437 anon_vma = find_mergeable_anon_vma(vma);
84438 allocated = NULL;
84439 if (!anon_vma) {
84440@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84441 /* page_table_lock to protect against threads */
84442 spin_lock(&mm->page_table_lock);
84443 if (likely(!vma->anon_vma)) {
84444+
84445+#ifdef CONFIG_PAX_SEGMEXEC
84446+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
84447+
84448+ if (vma_m) {
84449+ BUG_ON(vma_m->anon_vma);
84450+ vma_m->anon_vma = anon_vma;
84451+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
84452+ avc_m = NULL;
84453+ }
84454+#endif
84455+
84456 vma->anon_vma = anon_vma;
84457 anon_vma_chain_link(vma, avc, anon_vma);
84458 allocated = NULL;
84459@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84460
84461 if (unlikely(allocated))
84462 put_anon_vma(allocated);
84463+
84464+#ifdef CONFIG_PAX_SEGMEXEC
84465+ if (unlikely(avc_m))
84466+ anon_vma_chain_free(avc_m);
84467+#endif
84468+
84469 if (unlikely(avc))
84470 anon_vma_chain_free(avc);
84471 }
84472 return 0;
84473
84474 out_enomem_free_avc:
84475+
84476+#ifdef CONFIG_PAX_SEGMEXEC
84477+ if (avc_m)
84478+ anon_vma_chain_free(avc_m);
84479+#endif
84480+
84481 anon_vma_chain_free(avc);
84482 out_enomem:
84483 return -ENOMEM;
84484@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84485 * Attach the anon_vmas from src to dst.
84486 * Returns 0 on success, -ENOMEM on failure.
84487 */
84488-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84489+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84490 {
84491 struct anon_vma_chain *avc, *pavc;
84492 struct anon_vma *root = NULL;
84493@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84494 * the corresponding VMA in the parent process is attached to.
84495 * Returns 0 on success, non-zero on failure.
84496 */
84497-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84498+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84499 {
84500 struct anon_vma_chain *avc;
84501 struct anon_vma *anon_vma;
84502diff --git a/mm/shmem.c b/mm/shmem.c
84503index 5e6a842..b41916e 100644
84504--- a/mm/shmem.c
84505+++ b/mm/shmem.c
84506@@ -33,7 +33,7 @@
84507 #include <linux/swap.h>
84508 #include <linux/aio.h>
84509
84510-static struct vfsmount *shm_mnt;
84511+struct vfsmount *shm_mnt;
84512
84513 #ifdef CONFIG_SHMEM
84514 /*
84515@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
84516 #define BOGO_DIRENT_SIZE 20
84517
84518 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84519-#define SHORT_SYMLINK_LEN 128
84520+#define SHORT_SYMLINK_LEN 64
84521
84522 /*
84523 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84524@@ -2203,6 +2203,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84525 static int shmem_xattr_validate(const char *name)
84526 {
84527 struct { const char *prefix; size_t len; } arr[] = {
84528+
84529+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84530+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84531+#endif
84532+
84533 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84534 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84535 };
84536@@ -2258,6 +2263,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84537 if (err)
84538 return err;
84539
84540+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84541+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84542+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84543+ return -EOPNOTSUPP;
84544+ if (size > 8)
84545+ return -EINVAL;
84546+ }
84547+#endif
84548+
84549 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84550 }
84551
84552@@ -2570,8 +2584,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84553 int err = -ENOMEM;
84554
84555 /* Round up to L1_CACHE_BYTES to resist false sharing */
84556- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84557- L1_CACHE_BYTES), GFP_KERNEL);
84558+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84559 if (!sbinfo)
84560 return -ENOMEM;
84561
84562diff --git a/mm/slab.c b/mm/slab.c
84563index 8ccd296..012fe4e 100644
84564--- a/mm/slab.c
84565+++ b/mm/slab.c
84566@@ -366,10 +366,10 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
84567 if ((x)->max_freeable < i) \
84568 (x)->max_freeable = i; \
84569 } while (0)
84570-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84571-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84572-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84573-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84574+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84575+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84576+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84577+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84578 #else
84579 #define STATS_INC_ACTIVE(x) do { } while (0)
84580 #define STATS_DEC_ACTIVE(x) do { } while (0)
84581@@ -477,7 +477,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84582 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84583 */
84584 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84585- const struct slab *slab, void *obj)
84586+ const struct slab *slab, const void *obj)
84587 {
84588 u32 offset = (obj - slab->s_mem);
84589 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84590@@ -1384,7 +1384,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84591 return notifier_from_errno(err);
84592 }
84593
84594-static struct notifier_block __cpuinitdata cpucache_notifier = {
84595+static struct notifier_block cpucache_notifier = {
84596 &cpuup_callback, NULL, 0
84597 };
84598
84599@@ -1565,12 +1565,12 @@ void __init kmem_cache_init(void)
84600 */
84601
84602 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
84603- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
84604+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
84605
84606 if (INDEX_AC != INDEX_NODE)
84607 kmalloc_caches[INDEX_NODE] =
84608 create_kmalloc_cache("kmalloc-node",
84609- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
84610+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
84611
84612 slab_early_init = 0;
84613
84614@@ -3800,6 +3800,7 @@ void kfree(const void *objp)
84615
84616 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84617 return;
84618+ VM_BUG_ON(!virt_addr_valid(objp));
84619 local_irq_save(flags);
84620 kfree_debugcheck(objp);
84621 c = virt_to_cache(objp);
84622@@ -4241,10 +4242,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84623 }
84624 /* cpu stats */
84625 {
84626- unsigned long allochit = atomic_read(&cachep->allochit);
84627- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84628- unsigned long freehit = atomic_read(&cachep->freehit);
84629- unsigned long freemiss = atomic_read(&cachep->freemiss);
84630+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84631+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84632+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84633+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84634
84635 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84636 allochit, allocmiss, freehit, freemiss);
84637@@ -4476,13 +4477,71 @@ static const struct file_operations proc_slabstats_operations = {
84638 static int __init slab_proc_init(void)
84639 {
84640 #ifdef CONFIG_DEBUG_SLAB_LEAK
84641- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84642+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84643 #endif
84644 return 0;
84645 }
84646 module_init(slab_proc_init);
84647 #endif
84648
84649+bool is_usercopy_object(const void *ptr)
84650+{
84651+ struct page *page;
84652+ struct kmem_cache *cachep;
84653+
84654+ if (ZERO_OR_NULL_PTR(ptr))
84655+ return false;
84656+
84657+ if (!slab_is_available())
84658+ return false;
84659+
84660+ if (!virt_addr_valid(ptr))
84661+ return false;
84662+
84663+ page = virt_to_head_page(ptr);
84664+
84665+ if (!PageSlab(page))
84666+ return false;
84667+
84668+ cachep = page->slab_cache;
84669+ return cachep->flags & SLAB_USERCOPY;
84670+}
84671+
84672+#ifdef CONFIG_PAX_USERCOPY
84673+const char *check_heap_object(const void *ptr, unsigned long n)
84674+{
84675+ struct page *page;
84676+ struct kmem_cache *cachep;
84677+ struct slab *slabp;
84678+ unsigned int objnr;
84679+ unsigned long offset;
84680+
84681+ if (ZERO_OR_NULL_PTR(ptr))
84682+ return "<null>";
84683+
84684+ if (!virt_addr_valid(ptr))
84685+ return NULL;
84686+
84687+ page = virt_to_head_page(ptr);
84688+
84689+ if (!PageSlab(page))
84690+ return NULL;
84691+
84692+ cachep = page->slab_cache;
84693+ if (!(cachep->flags & SLAB_USERCOPY))
84694+ return cachep->name;
84695+
84696+ slabp = page->slab_page;
84697+ objnr = obj_to_index(cachep, slabp, ptr);
84698+ BUG_ON(objnr >= cachep->num);
84699+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84700+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84701+ return NULL;
84702+
84703+ return cachep->name;
84704+}
84705+#endif
84706+
84707 /**
84708 * ksize - get the actual amount of memory allocated for a given object
84709 * @objp: Pointer to the object
84710diff --git a/mm/slab.h b/mm/slab.h
84711index f96b49e..5634e90 100644
84712--- a/mm/slab.h
84713+++ b/mm/slab.h
84714@@ -67,7 +67,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84715
84716 /* Legal flag mask for kmem_cache_create(), for various configurations */
84717 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84718- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84719+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84720
84721 #if defined(CONFIG_DEBUG_SLAB)
84722 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84723@@ -229,6 +229,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84724 return s;
84725
84726 page = virt_to_head_page(x);
84727+
84728+ BUG_ON(!PageSlab(page));
84729+
84730 cachep = page->slab_cache;
84731 if (slab_equal_or_root(cachep, s))
84732 return cachep;
84733diff --git a/mm/slab_common.c b/mm/slab_common.c
84734index 2d41450..e22088e 100644
84735--- a/mm/slab_common.c
84736+++ b/mm/slab_common.c
84737@@ -22,7 +22,7 @@
84738
84739 #include "slab.h"
84740
84741-enum slab_state slab_state;
84742+enum slab_state slab_state __read_only;
84743 LIST_HEAD(slab_caches);
84744 DEFINE_MUTEX(slab_mutex);
84745 struct kmem_cache *kmem_cache;
84746@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84747
84748 err = __kmem_cache_create(s, flags);
84749 if (!err) {
84750- s->refcount = 1;
84751+ atomic_set(&s->refcount, 1);
84752 list_add(&s->list, &slab_caches);
84753 memcg_cache_list_add(memcg, s);
84754 } else {
84755@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84756
84757 get_online_cpus();
84758 mutex_lock(&slab_mutex);
84759- s->refcount--;
84760- if (!s->refcount) {
84761+ if (atomic_dec_and_test(&s->refcount)) {
84762 list_del(&s->list);
84763
84764 if (!__kmem_cache_shutdown(s)) {
84765@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84766 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
84767 name, size, err);
84768
84769- s->refcount = -1; /* Exempt from merging for now */
84770+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84771 }
84772
84773 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84774@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84775
84776 create_boot_cache(s, name, size, flags);
84777 list_add(&s->list, &slab_caches);
84778- s->refcount = 1;
84779+ atomic_set(&s->refcount, 1);
84780 return s;
84781 }
84782
84783@@ -327,6 +326,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
84784 EXPORT_SYMBOL(kmalloc_dma_caches);
84785 #endif
84786
84787+#ifdef CONFIG_PAX_USERCOPY_SLABS
84788+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
84789+EXPORT_SYMBOL(kmalloc_usercopy_caches);
84790+#endif
84791+
84792 /*
84793 * Conversion table for small slabs sizes / 8 to the index in the
84794 * kmalloc array. This is necessary for slabs < 192 since we have non power
84795@@ -391,6 +395,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
84796 return kmalloc_dma_caches[index];
84797
84798 #endif
84799+
84800+#ifdef CONFIG_PAX_USERCOPY_SLABS
84801+ if (unlikely((flags & GFP_USERCOPY)))
84802+ return kmalloc_usercopy_caches[index];
84803+
84804+#endif
84805+
84806 return kmalloc_caches[index];
84807 }
84808
84809@@ -447,7 +458,7 @@ void __init create_kmalloc_caches(unsigned long flags)
84810 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
84811 if (!kmalloc_caches[i]) {
84812 kmalloc_caches[i] = create_kmalloc_cache(NULL,
84813- 1 << i, flags);
84814+ 1 << i, SLAB_USERCOPY | flags);
84815 }
84816
84817 /*
84818@@ -456,10 +467,10 @@ void __init create_kmalloc_caches(unsigned long flags)
84819 * earlier power of two caches
84820 */
84821 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
84822- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
84823+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
84824
84825 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
84826- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
84827+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
84828 }
84829
84830 /* Kmalloc array is now usable */
84831@@ -492,6 +503,23 @@ void __init create_kmalloc_caches(unsigned long flags)
84832 }
84833 }
84834 #endif
84835+
84836+#ifdef CONFIG_PAX_USERCOPY_SLABS
84837+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
84838+ struct kmem_cache *s = kmalloc_caches[i];
84839+
84840+ if (s) {
84841+ int size = kmalloc_size(i);
84842+ char *n = kasprintf(GFP_NOWAIT,
84843+ "usercopy-kmalloc-%d", size);
84844+
84845+ BUG_ON(!n);
84846+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
84847+ size, SLAB_USERCOPY | flags);
84848+ }
84849+ }
84850+#endif
84851+
84852 }
84853 #endif /* !CONFIG_SLOB */
84854
84855diff --git a/mm/slob.c b/mm/slob.c
84856index eeed4a0..c414c12 100644
84857--- a/mm/slob.c
84858+++ b/mm/slob.c
84859@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84860 /*
84861 * Return the size of a slob block.
84862 */
84863-static slobidx_t slob_units(slob_t *s)
84864+static slobidx_t slob_units(const slob_t *s)
84865 {
84866 if (s->units > 0)
84867 return s->units;
84868@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84869 /*
84870 * Return the next free slob block pointer after this one.
84871 */
84872-static slob_t *slob_next(slob_t *s)
84873+static slob_t *slob_next(const slob_t *s)
84874 {
84875 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84876 slobidx_t next;
84877@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84878 /*
84879 * Returns true if s is the last free block in its page.
84880 */
84881-static int slob_last(slob_t *s)
84882+static int slob_last(const slob_t *s)
84883 {
84884 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84885 }
84886
84887-static void *slob_new_pages(gfp_t gfp, int order, int node)
84888+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84889 {
84890- void *page;
84891+ struct page *page;
84892
84893 #ifdef CONFIG_NUMA
84894 if (node != NUMA_NO_NODE)
84895@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84896 if (!page)
84897 return NULL;
84898
84899- return page_address(page);
84900+ __SetPageSlab(page);
84901+ return page;
84902 }
84903
84904-static void slob_free_pages(void *b, int order)
84905+static void slob_free_pages(struct page *sp, int order)
84906 {
84907 if (current->reclaim_state)
84908 current->reclaim_state->reclaimed_slab += 1 << order;
84909- free_pages((unsigned long)b, order);
84910+ __ClearPageSlab(sp);
84911+ page_mapcount_reset(sp);
84912+ sp->private = 0;
84913+ __free_pages(sp, order);
84914 }
84915
84916 /*
84917@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84918
84919 /* Not enough space: must allocate a new page */
84920 if (!b) {
84921- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84922- if (!b)
84923+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84924+ if (!sp)
84925 return NULL;
84926- sp = virt_to_page(b);
84927- __SetPageSlab(sp);
84928+ b = page_address(sp);
84929
84930 spin_lock_irqsave(&slob_lock, flags);
84931 sp->units = SLOB_UNITS(PAGE_SIZE);
84932 sp->freelist = b;
84933+ sp->private = 0;
84934 INIT_LIST_HEAD(&sp->list);
84935 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84936 set_slob_page_free(sp, slob_list);
84937@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84938 if (slob_page_free(sp))
84939 clear_slob_page_free(sp);
84940 spin_unlock_irqrestore(&slob_lock, flags);
84941- __ClearPageSlab(sp);
84942- page_mapcount_reset(sp);
84943- slob_free_pages(b, 0);
84944+ slob_free_pages(sp, 0);
84945 return;
84946 }
84947
84948@@ -424,11 +426,10 @@ out:
84949 */
84950
84951 static __always_inline void *
84952-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84953+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84954 {
84955- unsigned int *m;
84956- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84957- void *ret;
84958+ slob_t *m;
84959+ void *ret = NULL;
84960
84961 gfp &= gfp_allowed_mask;
84962
84963@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84964
84965 if (!m)
84966 return NULL;
84967- *m = size;
84968+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84969+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84970+ m[0].units = size;
84971+ m[1].units = align;
84972 ret = (void *)m + align;
84973
84974 trace_kmalloc_node(caller, ret,
84975 size, size + align, gfp, node);
84976 } else {
84977 unsigned int order = get_order(size);
84978+ struct page *page;
84979
84980 if (likely(order))
84981 gfp |= __GFP_COMP;
84982- ret = slob_new_pages(gfp, order, node);
84983+ page = slob_new_pages(gfp, order, node);
84984+ if (page) {
84985+ ret = page_address(page);
84986+ page->private = size;
84987+ }
84988
84989 trace_kmalloc_node(caller, ret,
84990 size, PAGE_SIZE << order, gfp, node);
84991 }
84992
84993- kmemleak_alloc(ret, size, 1, gfp);
84994+ return ret;
84995+}
84996+
84997+static __always_inline void *
84998+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84999+{
85000+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85001+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
85002+
85003+ if (!ZERO_OR_NULL_PTR(ret))
85004+ kmemleak_alloc(ret, size, 1, gfp);
85005 return ret;
85006 }
85007
85008@@ -493,34 +512,112 @@ void kfree(const void *block)
85009 return;
85010 kmemleak_free(block);
85011
85012+ VM_BUG_ON(!virt_addr_valid(block));
85013 sp = virt_to_page(block);
85014- if (PageSlab(sp)) {
85015+ VM_BUG_ON(!PageSlab(sp));
85016+ if (!sp->private) {
85017 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85018- unsigned int *m = (unsigned int *)(block - align);
85019- slob_free(m, *m + align);
85020- } else
85021+ slob_t *m = (slob_t *)(block - align);
85022+ slob_free(m, m[0].units + align);
85023+ } else {
85024+ __ClearPageSlab(sp);
85025+ page_mapcount_reset(sp);
85026+ sp->private = 0;
85027 __free_pages(sp, compound_order(sp));
85028+ }
85029 }
85030 EXPORT_SYMBOL(kfree);
85031
85032+bool is_usercopy_object(const void *ptr)
85033+{
85034+ if (!slab_is_available())
85035+ return false;
85036+
85037+ // PAX: TODO
85038+
85039+ return false;
85040+}
85041+
85042+#ifdef CONFIG_PAX_USERCOPY
85043+const char *check_heap_object(const void *ptr, unsigned long n)
85044+{
85045+ struct page *page;
85046+ const slob_t *free;
85047+ const void *base;
85048+ unsigned long flags;
85049+
85050+ if (ZERO_OR_NULL_PTR(ptr))
85051+ return "<null>";
85052+
85053+ if (!virt_addr_valid(ptr))
85054+ return NULL;
85055+
85056+ page = virt_to_head_page(ptr);
85057+ if (!PageSlab(page))
85058+ return NULL;
85059+
85060+ if (page->private) {
85061+ base = page;
85062+ if (base <= ptr && n <= page->private - (ptr - base))
85063+ return NULL;
85064+ return "<slob>";
85065+ }
85066+
85067+ /* some tricky double walking to find the chunk */
85068+ spin_lock_irqsave(&slob_lock, flags);
85069+ base = (void *)((unsigned long)ptr & PAGE_MASK);
85070+ free = page->freelist;
85071+
85072+ while (!slob_last(free) && (void *)free <= ptr) {
85073+ base = free + slob_units(free);
85074+ free = slob_next(free);
85075+ }
85076+
85077+ while (base < (void *)free) {
85078+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
85079+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
85080+ int offset;
85081+
85082+ if (ptr < base + align)
85083+ break;
85084+
85085+ offset = ptr - base - align;
85086+ if (offset >= m) {
85087+ base += size;
85088+ continue;
85089+ }
85090+
85091+ if (n > m - offset)
85092+ break;
85093+
85094+ spin_unlock_irqrestore(&slob_lock, flags);
85095+ return NULL;
85096+ }
85097+
85098+ spin_unlock_irqrestore(&slob_lock, flags);
85099+ return "<slob>";
85100+}
85101+#endif
85102+
85103 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
85104 size_t ksize(const void *block)
85105 {
85106 struct page *sp;
85107 int align;
85108- unsigned int *m;
85109+ slob_t *m;
85110
85111 BUG_ON(!block);
85112 if (unlikely(block == ZERO_SIZE_PTR))
85113 return 0;
85114
85115 sp = virt_to_page(block);
85116- if (unlikely(!PageSlab(sp)))
85117- return PAGE_SIZE << compound_order(sp);
85118+ VM_BUG_ON(!PageSlab(sp));
85119+ if (sp->private)
85120+ return sp->private;
85121
85122 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
85123- m = (unsigned int *)(block - align);
85124- return SLOB_UNITS(*m) * SLOB_UNIT;
85125+ m = (slob_t *)(block - align);
85126+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
85127 }
85128 EXPORT_SYMBOL(ksize);
85129
85130@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
85131
85132 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
85133 {
85134- void *b;
85135+ void *b = NULL;
85136
85137 flags &= gfp_allowed_mask;
85138
85139 lockdep_trace_alloc(flags);
85140
85141+#ifdef CONFIG_PAX_USERCOPY_SLABS
85142+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
85143+#else
85144 if (c->size < PAGE_SIZE) {
85145 b = slob_alloc(c->size, flags, c->align, node);
85146 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
85147 SLOB_UNITS(c->size) * SLOB_UNIT,
85148 flags, node);
85149 } else {
85150- b = slob_new_pages(flags, get_order(c->size), node);
85151+ struct page *sp;
85152+
85153+ sp = slob_new_pages(flags, get_order(c->size), node);
85154+ if (sp) {
85155+ b = page_address(sp);
85156+ sp->private = c->size;
85157+ }
85158 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
85159 PAGE_SIZE << get_order(c->size),
85160 flags, node);
85161 }
85162+#endif
85163
85164 if (c->ctor)
85165 c->ctor(b);
85166@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
85167
85168 static void __kmem_cache_free(void *b, int size)
85169 {
85170- if (size < PAGE_SIZE)
85171+ struct page *sp;
85172+
85173+ sp = virt_to_page(b);
85174+ BUG_ON(!PageSlab(sp));
85175+ if (!sp->private)
85176 slob_free(b, size);
85177 else
85178- slob_free_pages(b, get_order(size));
85179+ slob_free_pages(sp, get_order(size));
85180 }
85181
85182 static void kmem_rcu_free(struct rcu_head *head)
85183@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
85184
85185 void kmem_cache_free(struct kmem_cache *c, void *b)
85186 {
85187+ int size = c->size;
85188+
85189+#ifdef CONFIG_PAX_USERCOPY_SLABS
85190+ if (size + c->align < PAGE_SIZE) {
85191+ size += c->align;
85192+ b -= c->align;
85193+ }
85194+#endif
85195+
85196 kmemleak_free_recursive(b, c->flags);
85197 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
85198 struct slob_rcu *slob_rcu;
85199- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
85200- slob_rcu->size = c->size;
85201+ slob_rcu = b + (size - sizeof(struct slob_rcu));
85202+ slob_rcu->size = size;
85203 call_rcu(&slob_rcu->head, kmem_rcu_free);
85204 } else {
85205- __kmem_cache_free(b, c->size);
85206+ __kmem_cache_free(b, size);
85207 }
85208
85209+#ifdef CONFIG_PAX_USERCOPY_SLABS
85210+ trace_kfree(_RET_IP_, b);
85211+#else
85212 trace_kmem_cache_free(_RET_IP_, b);
85213+#endif
85214+
85215 }
85216 EXPORT_SYMBOL(kmem_cache_free);
85217
85218diff --git a/mm/slub.c b/mm/slub.c
85219index 57707f0..c28619b 100644
85220--- a/mm/slub.c
85221+++ b/mm/slub.c
85222@@ -198,7 +198,7 @@ struct track {
85223
85224 enum track_item { TRACK_ALLOC, TRACK_FREE };
85225
85226-#ifdef CONFIG_SYSFS
85227+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85228 static int sysfs_slab_add(struct kmem_cache *);
85229 static int sysfs_slab_alias(struct kmem_cache *, const char *);
85230 static void sysfs_slab_remove(struct kmem_cache *);
85231@@ -519,7 +519,7 @@ static void print_track(const char *s, struct track *t)
85232 if (!t->addr)
85233 return;
85234
85235- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
85236+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
85237 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
85238 #ifdef CONFIG_STACKTRACE
85239 {
85240@@ -2661,7 +2661,7 @@ static int slub_min_objects;
85241 * Merge control. If this is set then no merging of slab caches will occur.
85242 * (Could be removed. This was introduced to pacify the merge skeptics.)
85243 */
85244-static int slub_nomerge;
85245+static int slub_nomerge = 1;
85246
85247 /*
85248 * Calculate the order of allocation given an slab object size.
85249@@ -3283,6 +3283,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
85250 EXPORT_SYMBOL(__kmalloc_node);
85251 #endif
85252
85253+bool is_usercopy_object(const void *ptr)
85254+{
85255+ struct page *page;
85256+ struct kmem_cache *s;
85257+
85258+ if (ZERO_OR_NULL_PTR(ptr))
85259+ return false;
85260+
85261+ if (!slab_is_available())
85262+ return false;
85263+
85264+ if (!virt_addr_valid(ptr))
85265+ return false;
85266+
85267+ page = virt_to_head_page(ptr);
85268+
85269+ if (!PageSlab(page))
85270+ return false;
85271+
85272+ s = page->slab_cache;
85273+ return s->flags & SLAB_USERCOPY;
85274+}
85275+
85276+#ifdef CONFIG_PAX_USERCOPY
85277+const char *check_heap_object(const void *ptr, unsigned long n)
85278+{
85279+ struct page *page;
85280+ struct kmem_cache *s;
85281+ unsigned long offset;
85282+
85283+ if (ZERO_OR_NULL_PTR(ptr))
85284+ return "<null>";
85285+
85286+ if (!virt_addr_valid(ptr))
85287+ return NULL;
85288+
85289+ page = virt_to_head_page(ptr);
85290+
85291+ if (!PageSlab(page))
85292+ return NULL;
85293+
85294+ s = page->slab_cache;
85295+ if (!(s->flags & SLAB_USERCOPY))
85296+ return s->name;
85297+
85298+ offset = (ptr - page_address(page)) % s->size;
85299+ if (offset <= s->object_size && n <= s->object_size - offset)
85300+ return NULL;
85301+
85302+ return s->name;
85303+}
85304+#endif
85305+
85306 size_t ksize(const void *object)
85307 {
85308 struct page *page;
85309@@ -3347,6 +3400,7 @@ void kfree(const void *x)
85310 if (unlikely(ZERO_OR_NULL_PTR(x)))
85311 return;
85312
85313+ VM_BUG_ON(!virt_addr_valid(x));
85314 page = virt_to_head_page(x);
85315 if (unlikely(!PageSlab(page))) {
85316 BUG_ON(!PageCompound(page));
85317@@ -3652,7 +3706,7 @@ static int slab_unmergeable(struct kmem_cache *s)
85318 /*
85319 * We may have set a slab to be unmergeable during bootstrap.
85320 */
85321- if (s->refcount < 0)
85322+ if (atomic_read(&s->refcount) < 0)
85323 return 1;
85324
85325 return 0;
85326@@ -3710,7 +3764,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85327
85328 s = find_mergeable(memcg, size, align, flags, name, ctor);
85329 if (s) {
85330- s->refcount++;
85331+ atomic_inc(&s->refcount);
85332 /*
85333 * Adjust the object sizes so that we clear
85334 * the complete object on kzalloc.
85335@@ -3719,7 +3773,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85336 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
85337
85338 if (sysfs_slab_alias(s, name)) {
85339- s->refcount--;
85340+ atomic_dec(&s->refcount);
85341 s = NULL;
85342 }
85343 }
85344@@ -3781,7 +3835,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
85345 return NOTIFY_OK;
85346 }
85347
85348-static struct notifier_block __cpuinitdata slab_notifier = {
85349+static struct notifier_block slab_notifier = {
85350 .notifier_call = slab_cpuup_callback
85351 };
85352
85353@@ -3839,7 +3893,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
85354 }
85355 #endif
85356
85357-#ifdef CONFIG_SYSFS
85358+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85359 static int count_inuse(struct page *page)
85360 {
85361 return page->inuse;
85362@@ -4226,12 +4280,12 @@ static void resiliency_test(void)
85363 validate_slab_cache(kmalloc_caches[9]);
85364 }
85365 #else
85366-#ifdef CONFIG_SYSFS
85367+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85368 static void resiliency_test(void) {};
85369 #endif
85370 #endif
85371
85372-#ifdef CONFIG_SYSFS
85373+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85374 enum slab_stat_type {
85375 SL_ALL, /* All slabs */
85376 SL_PARTIAL, /* Only partially allocated slabs */
85377@@ -4475,7 +4529,7 @@ SLAB_ATTR_RO(ctor);
85378
85379 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
85380 {
85381- return sprintf(buf, "%d\n", s->refcount - 1);
85382+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
85383 }
85384 SLAB_ATTR_RO(aliases);
85385
85386@@ -4563,6 +4617,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
85387 SLAB_ATTR_RO(cache_dma);
85388 #endif
85389
85390+#ifdef CONFIG_PAX_USERCOPY_SLABS
85391+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
85392+{
85393+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
85394+}
85395+SLAB_ATTR_RO(usercopy);
85396+#endif
85397+
85398 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
85399 {
85400 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
85401@@ -4897,6 +4959,9 @@ static struct attribute *slab_attrs[] = {
85402 #ifdef CONFIG_ZONE_DMA
85403 &cache_dma_attr.attr,
85404 #endif
85405+#ifdef CONFIG_PAX_USERCOPY_SLABS
85406+ &usercopy_attr.attr,
85407+#endif
85408 #ifdef CONFIG_NUMA
85409 &remote_node_defrag_ratio_attr.attr,
85410 #endif
85411@@ -5128,6 +5193,7 @@ static char *create_unique_id(struct kmem_cache *s)
85412 return name;
85413 }
85414
85415+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85416 static int sysfs_slab_add(struct kmem_cache *s)
85417 {
85418 int err;
85419@@ -5151,7 +5217,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
85420 }
85421
85422 s->kobj.kset = slab_kset;
85423- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
85424+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
85425 if (err) {
85426 kobject_put(&s->kobj);
85427 return err;
85428@@ -5185,6 +5251,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
85429 kobject_del(&s->kobj);
85430 kobject_put(&s->kobj);
85431 }
85432+#endif
85433
85434 /*
85435 * Need to buffer aliases during bootup until sysfs becomes
85436@@ -5198,6 +5265,7 @@ struct saved_alias {
85437
85438 static struct saved_alias *alias_list;
85439
85440+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85441 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85442 {
85443 struct saved_alias *al;
85444@@ -5220,6 +5288,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85445 alias_list = al;
85446 return 0;
85447 }
85448+#endif
85449
85450 static int __init slab_sysfs_init(void)
85451 {
85452diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85453index 27eeab3..7c3f7f2 100644
85454--- a/mm/sparse-vmemmap.c
85455+++ b/mm/sparse-vmemmap.c
85456@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85457 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85458 if (!p)
85459 return NULL;
85460- pud_populate(&init_mm, pud, p);
85461+ pud_populate_kernel(&init_mm, pud, p);
85462 }
85463 return pud;
85464 }
85465@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85466 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85467 if (!p)
85468 return NULL;
85469- pgd_populate(&init_mm, pgd, p);
85470+ pgd_populate_kernel(&init_mm, pgd, p);
85471 }
85472 return pgd;
85473 }
85474diff --git a/mm/sparse.c b/mm/sparse.c
85475index 1c91f0d3..485470a 100644
85476--- a/mm/sparse.c
85477+++ b/mm/sparse.c
85478@@ -761,7 +761,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85479
85480 for (i = 0; i < PAGES_PER_SECTION; i++) {
85481 if (PageHWPoison(&memmap[i])) {
85482- atomic_long_sub(1, &num_poisoned_pages);
85483+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
85484 ClearPageHWPoison(&memmap[i]);
85485 }
85486 }
85487diff --git a/mm/swap.c b/mm/swap.c
85488index dfd7d71..ccdf688 100644
85489--- a/mm/swap.c
85490+++ b/mm/swap.c
85491@@ -31,6 +31,7 @@
85492 #include <linux/memcontrol.h>
85493 #include <linux/gfp.h>
85494 #include <linux/uio.h>
85495+#include <linux/hugetlb.h>
85496
85497 #include "internal.h"
85498
85499@@ -73,6 +74,8 @@ static void __put_compound_page(struct page *page)
85500
85501 __page_cache_release(page);
85502 dtor = get_compound_page_dtor(page);
85503+ if (!PageHuge(page))
85504+ BUG_ON(dtor != free_compound_page);
85505 (*dtor)(page);
85506 }
85507
85508diff --git a/mm/swapfile.c b/mm/swapfile.c
85509index 746af55b..7ac94ae 100644
85510--- a/mm/swapfile.c
85511+++ b/mm/swapfile.c
85512@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
85513
85514 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85515 /* Activity counter to indicate that a swapon or swapoff has occurred */
85516-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85517+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85518
85519 static inline unsigned char swap_count(unsigned char ent)
85520 {
85521@@ -1684,7 +1684,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85522 }
85523 filp_close(swap_file, NULL);
85524 err = 0;
85525- atomic_inc(&proc_poll_event);
85526+ atomic_inc_unchecked(&proc_poll_event);
85527 wake_up_interruptible(&proc_poll_wait);
85528
85529 out_dput:
85530@@ -1701,8 +1701,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85531
85532 poll_wait(file, &proc_poll_wait, wait);
85533
85534- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85535- seq->poll_event = atomic_read(&proc_poll_event);
85536+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85537+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85538 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85539 }
85540
85541@@ -1800,7 +1800,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85542 return ret;
85543
85544 seq = file->private_data;
85545- seq->poll_event = atomic_read(&proc_poll_event);
85546+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85547 return 0;
85548 }
85549
85550@@ -2143,7 +2143,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85551 (frontswap_map) ? "FS" : "");
85552
85553 mutex_unlock(&swapon_mutex);
85554- atomic_inc(&proc_poll_event);
85555+ atomic_inc_unchecked(&proc_poll_event);
85556 wake_up_interruptible(&proc_poll_wait);
85557
85558 if (S_ISREG(inode->i_mode))
85559diff --git a/mm/util.c b/mm/util.c
85560index ab1424d..7c5bd5a 100644
85561--- a/mm/util.c
85562+++ b/mm/util.c
85563@@ -294,6 +294,12 @@ done:
85564 void arch_pick_mmap_layout(struct mm_struct *mm)
85565 {
85566 mm->mmap_base = TASK_UNMAPPED_BASE;
85567+
85568+#ifdef CONFIG_PAX_RANDMMAP
85569+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85570+ mm->mmap_base += mm->delta_mmap;
85571+#endif
85572+
85573 mm->get_unmapped_area = arch_get_unmapped_area;
85574 mm->unmap_area = arch_unmap_area;
85575 }
85576diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85577index d365724..6cae7c2 100644
85578--- a/mm/vmalloc.c
85579+++ b/mm/vmalloc.c
85580@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85581
85582 pte = pte_offset_kernel(pmd, addr);
85583 do {
85584- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85585- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85586+
85587+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85588+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85589+ BUG_ON(!pte_exec(*pte));
85590+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85591+ continue;
85592+ }
85593+#endif
85594+
85595+ {
85596+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85597+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85598+ }
85599 } while (pte++, addr += PAGE_SIZE, addr != end);
85600 }
85601
85602@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85603 pte = pte_alloc_kernel(pmd, addr);
85604 if (!pte)
85605 return -ENOMEM;
85606+
85607+ pax_open_kernel();
85608 do {
85609 struct page *page = pages[*nr];
85610
85611- if (WARN_ON(!pte_none(*pte)))
85612+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85613+ if (pgprot_val(prot) & _PAGE_NX)
85614+#endif
85615+
85616+ if (!pte_none(*pte)) {
85617+ pax_close_kernel();
85618+ WARN_ON(1);
85619 return -EBUSY;
85620- if (WARN_ON(!page))
85621+ }
85622+ if (!page) {
85623+ pax_close_kernel();
85624+ WARN_ON(1);
85625 return -ENOMEM;
85626+ }
85627 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85628 (*nr)++;
85629 } while (pte++, addr += PAGE_SIZE, addr != end);
85630+ pax_close_kernel();
85631 return 0;
85632 }
85633
85634@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85635 pmd_t *pmd;
85636 unsigned long next;
85637
85638- pmd = pmd_alloc(&init_mm, pud, addr);
85639+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85640 if (!pmd)
85641 return -ENOMEM;
85642 do {
85643@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85644 pud_t *pud;
85645 unsigned long next;
85646
85647- pud = pud_alloc(&init_mm, pgd, addr);
85648+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85649 if (!pud)
85650 return -ENOMEM;
85651 do {
85652@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
85653 if (addr >= MODULES_VADDR && addr < MODULES_END)
85654 return 1;
85655 #endif
85656+
85657+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85658+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85659+ return 1;
85660+#endif
85661+
85662 return is_vmalloc_addr(x);
85663 }
85664
85665@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85666
85667 if (!pgd_none(*pgd)) {
85668 pud_t *pud = pud_offset(pgd, addr);
85669+#ifdef CONFIG_X86
85670+ if (!pud_large(*pud))
85671+#endif
85672 if (!pud_none(*pud)) {
85673 pmd_t *pmd = pmd_offset(pud, addr);
85674+#ifdef CONFIG_X86
85675+ if (!pmd_large(*pmd))
85676+#endif
85677 if (!pmd_none(*pmd)) {
85678 pte_t *ptep, pte;
85679
85680@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
85681 * Allocate a region of KVA of the specified size and alignment, within the
85682 * vstart and vend.
85683 */
85684-static struct vmap_area *alloc_vmap_area(unsigned long size,
85685+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85686 unsigned long align,
85687 unsigned long vstart, unsigned long vend,
85688 int node, gfp_t gfp_mask)
85689@@ -1337,6 +1373,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85690 struct vm_struct *area;
85691
85692 BUG_ON(in_interrupt());
85693+
85694+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85695+ if (flags & VM_KERNEXEC) {
85696+ if (start != VMALLOC_START || end != VMALLOC_END)
85697+ return NULL;
85698+ start = (unsigned long)MODULES_EXEC_VADDR;
85699+ end = (unsigned long)MODULES_EXEC_END;
85700+ }
85701+#endif
85702+
85703 if (flags & VM_IOREMAP) {
85704 int bit = fls(size);
85705
85706@@ -1581,6 +1627,11 @@ void *vmap(struct page **pages, unsigned int count,
85707 if (count > totalram_pages)
85708 return NULL;
85709
85710+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85711+ if (!(pgprot_val(prot) & _PAGE_NX))
85712+ flags |= VM_KERNEXEC;
85713+#endif
85714+
85715 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85716 __builtin_return_address(0));
85717 if (!area)
85718@@ -1682,6 +1733,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85719 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85720 goto fail;
85721
85722+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85723+ if (!(pgprot_val(prot) & _PAGE_NX))
85724+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85725+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85726+ else
85727+#endif
85728+
85729 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85730 start, end, node, gfp_mask, caller);
85731 if (!area)
85732@@ -1858,10 +1916,9 @@ EXPORT_SYMBOL(vzalloc_node);
85733 * For tight control over page level allocator and protection flags
85734 * use __vmalloc() instead.
85735 */
85736-
85737 void *vmalloc_exec(unsigned long size)
85738 {
85739- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85740+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85741 NUMA_NO_NODE, __builtin_return_address(0));
85742 }
85743
85744@@ -2168,6 +2225,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85745 unsigned long uaddr = vma->vm_start;
85746 unsigned long usize = vma->vm_end - vma->vm_start;
85747
85748+ BUG_ON(vma->vm_mirror);
85749+
85750 if ((PAGE_SIZE-1) & (unsigned long)addr)
85751 return -EINVAL;
85752
85753@@ -2629,7 +2688,11 @@ static int s_show(struct seq_file *m, void *p)
85754 v->addr, v->addr + v->size, v->size);
85755
85756 if (v->caller)
85757+#ifdef CONFIG_GRKERNSEC_HIDESYM
85758+ seq_printf(m, " %pK", v->caller);
85759+#else
85760 seq_printf(m, " %pS", v->caller);
85761+#endif
85762
85763 if (v->nr_pages)
85764 seq_printf(m, " pages=%d", v->nr_pages);
85765diff --git a/mm/vmstat.c b/mm/vmstat.c
85766index f42745e..62f8346 100644
85767--- a/mm/vmstat.c
85768+++ b/mm/vmstat.c
85769@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
85770 *
85771 * vm_stat contains the global counters
85772 */
85773-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85774+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85775 EXPORT_SYMBOL(vm_stat);
85776
85777 #ifdef CONFIG_SMP
85778@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
85779 v = p->vm_stat_diff[i];
85780 p->vm_stat_diff[i] = 0;
85781 local_irq_restore(flags);
85782- atomic_long_add(v, &zone->vm_stat[i]);
85783+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85784 global_diff[i] += v;
85785 #ifdef CONFIG_NUMA
85786 /* 3 seconds idle till flush */
85787@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
85788
85789 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85790 if (global_diff[i])
85791- atomic_long_add(global_diff[i], &vm_stat[i]);
85792+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85793 }
85794
85795 /*
85796@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85797 if (pset->vm_stat_diff[i]) {
85798 int v = pset->vm_stat_diff[i];
85799 pset->vm_stat_diff[i] = 0;
85800- atomic_long_add(v, &zone->vm_stat[i]);
85801- atomic_long_add(v, &vm_stat[i]);
85802+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85803+ atomic_long_add_unchecked(v, &vm_stat[i]);
85804 }
85805 }
85806 #endif
85807@@ -1226,7 +1226,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85808 return NOTIFY_OK;
85809 }
85810
85811-static struct notifier_block __cpuinitdata vmstat_notifier =
85812+static struct notifier_block vmstat_notifier =
85813 { &vmstat_cpuup_callback, NULL, 0 };
85814 #endif
85815
85816@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
85817 start_cpu_timer(cpu);
85818 #endif
85819 #ifdef CONFIG_PROC_FS
85820- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85821- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85822- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85823- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85824+ {
85825+ mode_t gr_mode = S_IRUGO;
85826+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85827+ gr_mode = S_IRUSR;
85828+#endif
85829+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85830+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85831+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85832+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85833+#else
85834+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85835+#endif
85836+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85837+ }
85838 #endif
85839 return 0;
85840 }
85841diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85842index 9424f37..6aabf19 100644
85843--- a/net/8021q/vlan.c
85844+++ b/net/8021q/vlan.c
85845@@ -469,7 +469,7 @@ out:
85846 return NOTIFY_DONE;
85847 }
85848
85849-static struct notifier_block vlan_notifier_block __read_mostly = {
85850+static struct notifier_block vlan_notifier_block = {
85851 .notifier_call = vlan_device_event,
85852 };
85853
85854@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85855 err = -EPERM;
85856 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85857 break;
85858- if ((args.u.name_type >= 0) &&
85859- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85860+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85861 struct vlan_net *vn;
85862
85863 vn = net_generic(net, vlan_net_id);
85864diff --git a/net/9p/mod.c b/net/9p/mod.c
85865index 6ab36ae..6f1841b 100644
85866--- a/net/9p/mod.c
85867+++ b/net/9p/mod.c
85868@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85869 void v9fs_register_trans(struct p9_trans_module *m)
85870 {
85871 spin_lock(&v9fs_trans_lock);
85872- list_add_tail(&m->list, &v9fs_trans_list);
85873+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85874 spin_unlock(&v9fs_trans_lock);
85875 }
85876 EXPORT_SYMBOL(v9fs_register_trans);
85877@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85878 void v9fs_unregister_trans(struct p9_trans_module *m)
85879 {
85880 spin_lock(&v9fs_trans_lock);
85881- list_del_init(&m->list);
85882+ pax_list_del_init((struct list_head *)&m->list);
85883 spin_unlock(&v9fs_trans_lock);
85884 }
85885 EXPORT_SYMBOL(v9fs_unregister_trans);
85886diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85887index 02efb25..41541a9 100644
85888--- a/net/9p/trans_fd.c
85889+++ b/net/9p/trans_fd.c
85890@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85891 oldfs = get_fs();
85892 set_fs(get_ds());
85893 /* The cast to a user pointer is valid due to the set_fs() */
85894- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85895+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85896 set_fs(oldfs);
85897
85898 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85899diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85900index 876fbe8..8bbea9f 100644
85901--- a/net/atm/atm_misc.c
85902+++ b/net/atm/atm_misc.c
85903@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85904 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85905 return 1;
85906 atm_return(vcc, truesize);
85907- atomic_inc(&vcc->stats->rx_drop);
85908+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85909 return 0;
85910 }
85911 EXPORT_SYMBOL(atm_charge);
85912@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85913 }
85914 }
85915 atm_return(vcc, guess);
85916- atomic_inc(&vcc->stats->rx_drop);
85917+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85918 return NULL;
85919 }
85920 EXPORT_SYMBOL(atm_alloc_charge);
85921@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85922
85923 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85924 {
85925-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85926+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85927 __SONET_ITEMS
85928 #undef __HANDLE_ITEM
85929 }
85930@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85931
85932 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85933 {
85934-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85935+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85936 __SONET_ITEMS
85937 #undef __HANDLE_ITEM
85938 }
85939diff --git a/net/atm/lec.h b/net/atm/lec.h
85940index 4149db1..f2ab682 100644
85941--- a/net/atm/lec.h
85942+++ b/net/atm/lec.h
85943@@ -48,7 +48,7 @@ struct lane2_ops {
85944 const u8 *tlvs, u32 sizeoftlvs);
85945 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85946 const u8 *tlvs, u32 sizeoftlvs);
85947-};
85948+} __no_const;
85949
85950 /*
85951 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85952diff --git a/net/atm/proc.c b/net/atm/proc.c
85953index bbb6461..cf04016 100644
85954--- a/net/atm/proc.c
85955+++ b/net/atm/proc.c
85956@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85957 const struct k_atm_aal_stats *stats)
85958 {
85959 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85960- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85961- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85962- atomic_read(&stats->rx_drop));
85963+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85964+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85965+ atomic_read_unchecked(&stats->rx_drop));
85966 }
85967
85968 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85969diff --git a/net/atm/resources.c b/net/atm/resources.c
85970index 0447d5d..3cf4728 100644
85971--- a/net/atm/resources.c
85972+++ b/net/atm/resources.c
85973@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85974 static void copy_aal_stats(struct k_atm_aal_stats *from,
85975 struct atm_aal_stats *to)
85976 {
85977-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85978+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85979 __AAL_STAT_ITEMS
85980 #undef __HANDLE_ITEM
85981 }
85982@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85983 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85984 struct atm_aal_stats *to)
85985 {
85986-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85987+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85988 __AAL_STAT_ITEMS
85989 #undef __HANDLE_ITEM
85990 }
85991diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85992index d5744b7..506bae3 100644
85993--- a/net/ax25/sysctl_net_ax25.c
85994+++ b/net/ax25/sysctl_net_ax25.c
85995@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85996 {
85997 char path[sizeof("net/ax25/") + IFNAMSIZ];
85998 int k;
85999- struct ctl_table *table;
86000+ ctl_table_no_const *table;
86001
86002 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
86003 if (!table)
86004diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
86005index f680ee1..97e3542 100644
86006--- a/net/batman-adv/bat_iv_ogm.c
86007+++ b/net/batman-adv/bat_iv_ogm.c
86008@@ -79,7 +79,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
86009
86010 /* randomize initial seqno to avoid collision */
86011 get_random_bytes(&random_seqno, sizeof(random_seqno));
86012- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
86013+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
86014
86015 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
86016 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
86017@@ -627,9 +627,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
86018 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
86019
86020 /* change sequence number to network order */
86021- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
86022+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
86023 batadv_ogm_packet->seqno = htonl(seqno);
86024- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
86025+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
86026
86027 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
86028 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
86029@@ -1037,7 +1037,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
86030 return;
86031
86032 /* could be changed by schedule_own_packet() */
86033- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
86034+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
86035
86036 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
86037 has_directlink_flag = 1;
86038diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
86039index 522243a..b48c0ef 100644
86040--- a/net/batman-adv/hard-interface.c
86041+++ b/net/batman-adv/hard-interface.c
86042@@ -401,7 +401,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
86043 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
86044 dev_add_pack(&hard_iface->batman_adv_ptype);
86045
86046- atomic_set(&hard_iface->frag_seqno, 1);
86047+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
86048 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
86049 hard_iface->net_dev->name);
86050
86051@@ -550,7 +550,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
86052 /* This can't be called via a bat_priv callback because
86053 * we have no bat_priv yet.
86054 */
86055- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
86056+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
86057 hard_iface->bat_iv.ogm_buff = NULL;
86058
86059 return hard_iface;
86060diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
86061index 819dfb0..9a672d1 100644
86062--- a/net/batman-adv/soft-interface.c
86063+++ b/net/batman-adv/soft-interface.c
86064@@ -253,7 +253,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
86065 primary_if->net_dev->dev_addr, ETH_ALEN);
86066
86067 /* set broadcast sequence number */
86068- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
86069+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
86070 bcast_packet->seqno = htonl(seqno);
86071
86072 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
86073@@ -472,7 +472,7 @@ static int batadv_softif_init_late(struct net_device *dev)
86074 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
86075
86076 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
86077- atomic_set(&bat_priv->bcast_seqno, 1);
86078+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
86079 atomic_set(&bat_priv->tt.vn, 0);
86080 atomic_set(&bat_priv->tt.local_changes, 0);
86081 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
86082diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
86083index aba8364..50fcbb8 100644
86084--- a/net/batman-adv/types.h
86085+++ b/net/batman-adv/types.h
86086@@ -51,7 +51,7 @@
86087 struct batadv_hard_iface_bat_iv {
86088 unsigned char *ogm_buff;
86089 int ogm_buff_len;
86090- atomic_t ogm_seqno;
86091+ atomic_unchecked_t ogm_seqno;
86092 };
86093
86094 /**
86095@@ -75,7 +75,7 @@ struct batadv_hard_iface {
86096 int16_t if_num;
86097 char if_status;
86098 struct net_device *net_dev;
86099- atomic_t frag_seqno;
86100+ atomic_unchecked_t frag_seqno;
86101 struct kobject *hardif_obj;
86102 atomic_t refcount;
86103 struct packet_type batman_adv_ptype;
86104@@ -558,7 +558,7 @@ struct batadv_priv {
86105 #ifdef CONFIG_BATMAN_ADV_DEBUG
86106 atomic_t log_level;
86107 #endif
86108- atomic_t bcast_seqno;
86109+ atomic_unchecked_t bcast_seqno;
86110 atomic_t bcast_queue_left;
86111 atomic_t batman_queue_left;
86112 char num_ifaces;
86113diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
86114index 0bb3b59..ffcbf2f 100644
86115--- a/net/batman-adv/unicast.c
86116+++ b/net/batman-adv/unicast.c
86117@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
86118 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
86119 frag2->flags = large_tail;
86120
86121- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
86122+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
86123 frag1->seqno = htons(seqno - 1);
86124 frag2->seqno = htons(seqno);
86125
86126diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
86127index ace5e55..a65a1c0 100644
86128--- a/net/bluetooth/hci_core.c
86129+++ b/net/bluetooth/hci_core.c
86130@@ -2211,16 +2211,16 @@ int hci_register_dev(struct hci_dev *hdev)
86131 list_add(&hdev->list, &hci_dev_list);
86132 write_unlock(&hci_dev_list_lock);
86133
86134- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
86135- WQ_MEM_RECLAIM, 1);
86136+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
86137+ WQ_MEM_RECLAIM, 1, hdev->name);
86138 if (!hdev->workqueue) {
86139 error = -ENOMEM;
86140 goto err;
86141 }
86142
86143- hdev->req_workqueue = alloc_workqueue(hdev->name,
86144+ hdev->req_workqueue = alloc_workqueue("%s",
86145 WQ_HIGHPRI | WQ_UNBOUND |
86146- WQ_MEM_RECLAIM, 1);
86147+ WQ_MEM_RECLAIM, 1, hdev->name);
86148 if (!hdev->req_workqueue) {
86149 destroy_workqueue(hdev->workqueue);
86150 error = -ENOMEM;
86151diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
86152index 9bd7d95..6c4884f 100644
86153--- a/net/bluetooth/hci_sock.c
86154+++ b/net/bluetooth/hci_sock.c
86155@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
86156 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
86157 }
86158
86159- len = min_t(unsigned int, len, sizeof(uf));
86160+ len = min((size_t)len, sizeof(uf));
86161 if (copy_from_user(&uf, optval, len)) {
86162 err = -EFAULT;
86163 break;
86164diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
86165index 68843a2..30e9342 100644
86166--- a/net/bluetooth/l2cap_core.c
86167+++ b/net/bluetooth/l2cap_core.c
86168@@ -3507,8 +3507,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
86169 break;
86170
86171 case L2CAP_CONF_RFC:
86172- if (olen == sizeof(rfc))
86173- memcpy(&rfc, (void *)val, olen);
86174+ if (olen != sizeof(rfc))
86175+ break;
86176+
86177+ memcpy(&rfc, (void *)val, olen);
86178
86179 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
86180 rfc.mode != chan->mode)
86181diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
86182index 36fed40..be2eeb2 100644
86183--- a/net/bluetooth/l2cap_sock.c
86184+++ b/net/bluetooth/l2cap_sock.c
86185@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86186 struct sock *sk = sock->sk;
86187 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
86188 struct l2cap_options opts;
86189- int len, err = 0;
86190+ int err = 0;
86191+ size_t len = optlen;
86192 u32 opt;
86193
86194 BT_DBG("sk %p", sk);
86195@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86196 opts.max_tx = chan->max_tx;
86197 opts.txwin_size = chan->tx_win;
86198
86199- len = min_t(unsigned int, sizeof(opts), optlen);
86200+ len = min(sizeof(opts), len);
86201 if (copy_from_user((char *) &opts, optval, len)) {
86202 err = -EFAULT;
86203 break;
86204@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86205 struct bt_security sec;
86206 struct bt_power pwr;
86207 struct l2cap_conn *conn;
86208- int len, err = 0;
86209+ int err = 0;
86210+ size_t len = optlen;
86211 u32 opt;
86212
86213 BT_DBG("sk %p", sk);
86214@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86215
86216 sec.level = BT_SECURITY_LOW;
86217
86218- len = min_t(unsigned int, sizeof(sec), optlen);
86219+ len = min(sizeof(sec), len);
86220 if (copy_from_user((char *) &sec, optval, len)) {
86221 err = -EFAULT;
86222 break;
86223@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86224
86225 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
86226
86227- len = min_t(unsigned int, sizeof(pwr), optlen);
86228+ len = min(sizeof(pwr), len);
86229 if (copy_from_user((char *) &pwr, optval, len)) {
86230 err = -EFAULT;
86231 break;
86232diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
86233index 30b3721..c1bd0a0 100644
86234--- a/net/bluetooth/rfcomm/sock.c
86235+++ b/net/bluetooth/rfcomm/sock.c
86236@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86237 struct sock *sk = sock->sk;
86238 struct bt_security sec;
86239 int err = 0;
86240- size_t len;
86241+ size_t len = optlen;
86242 u32 opt;
86243
86244 BT_DBG("sk %p", sk);
86245@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86246
86247 sec.level = BT_SECURITY_LOW;
86248
86249- len = min_t(unsigned int, sizeof(sec), optlen);
86250+ len = min(sizeof(sec), len);
86251 if (copy_from_user((char *) &sec, optval, len)) {
86252 err = -EFAULT;
86253 break;
86254diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
86255index b6e44ad..5b0d514 100644
86256--- a/net/bluetooth/rfcomm/tty.c
86257+++ b/net/bluetooth/rfcomm/tty.c
86258@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
86259 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
86260
86261 spin_lock_irqsave(&dev->port.lock, flags);
86262- if (dev->port.count > 0) {
86263+ if (atomic_read(&dev->port.count) > 0) {
86264 spin_unlock_irqrestore(&dev->port.lock, flags);
86265 return;
86266 }
86267@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
86268 return -ENODEV;
86269
86270 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
86271- dev->channel, dev->port.count);
86272+ dev->channel, atomic_read(&dev->port.count));
86273
86274 spin_lock_irqsave(&dev->port.lock, flags);
86275- if (++dev->port.count > 1) {
86276+ if (atomic_inc_return(&dev->port.count) > 1) {
86277 spin_unlock_irqrestore(&dev->port.lock, flags);
86278 return 0;
86279 }
86280@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
86281 return;
86282
86283 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
86284- dev->port.count);
86285+ atomic_read(&dev->port.count));
86286
86287 spin_lock_irqsave(&dev->port.lock, flags);
86288- if (!--dev->port.count) {
86289+ if (!atomic_dec_return(&dev->port.count)) {
86290 spin_unlock_irqrestore(&dev->port.lock, flags);
86291 if (dev->tty_dev->parent)
86292 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
86293diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
86294index 3d110c4..4e1b2eb 100644
86295--- a/net/bridge/netfilter/ebtables.c
86296+++ b/net/bridge/netfilter/ebtables.c
86297@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86298 tmp.valid_hooks = t->table->valid_hooks;
86299 }
86300 mutex_unlock(&ebt_mutex);
86301- if (copy_to_user(user, &tmp, *len) != 0){
86302+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
86303 BUGPRINT("c2u Didn't work\n");
86304 ret = -EFAULT;
86305 break;
86306@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86307 goto out;
86308 tmp.valid_hooks = t->valid_hooks;
86309
86310- if (copy_to_user(user, &tmp, *len) != 0) {
86311+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86312 ret = -EFAULT;
86313 break;
86314 }
86315@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86316 tmp.entries_size = t->table->entries_size;
86317 tmp.valid_hooks = t->table->valid_hooks;
86318
86319- if (copy_to_user(user, &tmp, *len) != 0) {
86320+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86321 ret = -EFAULT;
86322 break;
86323 }
86324diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
86325index 2bd4b58..0dc30a1 100644
86326--- a/net/caif/cfctrl.c
86327+++ b/net/caif/cfctrl.c
86328@@ -10,6 +10,7 @@
86329 #include <linux/spinlock.h>
86330 #include <linux/slab.h>
86331 #include <linux/pkt_sched.h>
86332+#include <linux/sched.h>
86333 #include <net/caif/caif_layer.h>
86334 #include <net/caif/cfpkt.h>
86335 #include <net/caif/cfctrl.h>
86336@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
86337 memset(&dev_info, 0, sizeof(dev_info));
86338 dev_info.id = 0xff;
86339 cfsrvl_init(&this->serv, 0, &dev_info, false);
86340- atomic_set(&this->req_seq_no, 1);
86341- atomic_set(&this->rsp_seq_no, 1);
86342+ atomic_set_unchecked(&this->req_seq_no, 1);
86343+ atomic_set_unchecked(&this->rsp_seq_no, 1);
86344 this->serv.layer.receive = cfctrl_recv;
86345 sprintf(this->serv.layer.name, "ctrl");
86346 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
86347@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
86348 struct cfctrl_request_info *req)
86349 {
86350 spin_lock_bh(&ctrl->info_list_lock);
86351- atomic_inc(&ctrl->req_seq_no);
86352- req->sequence_no = atomic_read(&ctrl->req_seq_no);
86353+ atomic_inc_unchecked(&ctrl->req_seq_no);
86354+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
86355 list_add_tail(&req->list, &ctrl->list);
86356 spin_unlock_bh(&ctrl->info_list_lock);
86357 }
86358@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
86359 if (p != first)
86360 pr_warn("Requests are not received in order\n");
86361
86362- atomic_set(&ctrl->rsp_seq_no,
86363+ atomic_set_unchecked(&ctrl->rsp_seq_no,
86364 p->sequence_no);
86365 list_del(&p->list);
86366 goto out;
86367diff --git a/net/can/af_can.c b/net/can/af_can.c
86368index c4e5085..aa9efdf 100644
86369--- a/net/can/af_can.c
86370+++ b/net/can/af_can.c
86371@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
86372 };
86373
86374 /* notifier block for netdevice event */
86375-static struct notifier_block can_netdev_notifier __read_mostly = {
86376+static struct notifier_block can_netdev_notifier = {
86377 .notifier_call = can_notifier,
86378 };
86379
86380diff --git a/net/can/gw.c b/net/can/gw.c
86381index 3ee690e..00d581b 100644
86382--- a/net/can/gw.c
86383+++ b/net/can/gw.c
86384@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
86385 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
86386
86387 static HLIST_HEAD(cgw_list);
86388-static struct notifier_block notifier;
86389
86390 static struct kmem_cache *cgw_cache __read_mostly;
86391
86392@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
86393 return err;
86394 }
86395
86396+static struct notifier_block notifier = {
86397+ .notifier_call = cgw_notifier
86398+};
86399+
86400 static __init int cgw_module_init(void)
86401 {
86402 /* sanitize given module parameter */
86403@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
86404 return -ENOMEM;
86405
86406 /* set notifier */
86407- notifier.notifier_call = cgw_notifier;
86408 register_netdevice_notifier(&notifier);
86409
86410 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
86411diff --git a/net/compat.c b/net/compat.c
86412index f0a1ba6..0541331 100644
86413--- a/net/compat.c
86414+++ b/net/compat.c
86415@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
86416 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
86417 __get_user(kmsg->msg_flags, &umsg->msg_flags))
86418 return -EFAULT;
86419- kmsg->msg_name = compat_ptr(tmp1);
86420- kmsg->msg_iov = compat_ptr(tmp2);
86421- kmsg->msg_control = compat_ptr(tmp3);
86422+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
86423+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
86424+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
86425 return 0;
86426 }
86427
86428@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86429
86430 if (kern_msg->msg_namelen) {
86431 if (mode == VERIFY_READ) {
86432- int err = move_addr_to_kernel(kern_msg->msg_name,
86433+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86434 kern_msg->msg_namelen,
86435 kern_address);
86436 if (err < 0)
86437@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86438 kern_msg->msg_name = NULL;
86439
86440 tot_len = iov_from_user_compat_to_kern(kern_iov,
86441- (struct compat_iovec __user *)kern_msg->msg_iov,
86442+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86443 kern_msg->msg_iovlen);
86444 if (tot_len >= 0)
86445 kern_msg->msg_iov = kern_iov;
86446@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86447
86448 #define CMSG_COMPAT_FIRSTHDR(msg) \
86449 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86450- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86451+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86452 (struct compat_cmsghdr __user *)NULL)
86453
86454 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86455 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86456 (ucmlen) <= (unsigned long) \
86457 ((mhdr)->msg_controllen - \
86458- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86459+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86460
86461 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86462 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86463 {
86464 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86465- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86466+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86467 msg->msg_controllen)
86468 return NULL;
86469 return (struct compat_cmsghdr __user *)ptr;
86470@@ -219,7 +219,7 @@ Efault:
86471
86472 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86473 {
86474- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86475+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86476 struct compat_cmsghdr cmhdr;
86477 struct compat_timeval ctv;
86478 struct compat_timespec cts[3];
86479@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86480
86481 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86482 {
86483- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86484+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86485 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86486 int fdnum = scm->fp->count;
86487 struct file **fp = scm->fp->fp;
86488@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86489 return -EFAULT;
86490 old_fs = get_fs();
86491 set_fs(KERNEL_DS);
86492- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86493+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86494 set_fs(old_fs);
86495
86496 return err;
86497@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86498 len = sizeof(ktime);
86499 old_fs = get_fs();
86500 set_fs(KERNEL_DS);
86501- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86502+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86503 set_fs(old_fs);
86504
86505 if (!err) {
86506@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86507 case MCAST_JOIN_GROUP:
86508 case MCAST_LEAVE_GROUP:
86509 {
86510- struct compat_group_req __user *gr32 = (void *)optval;
86511+ struct compat_group_req __user *gr32 = (void __user *)optval;
86512 struct group_req __user *kgr =
86513 compat_alloc_user_space(sizeof(struct group_req));
86514 u32 interface;
86515@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86516 case MCAST_BLOCK_SOURCE:
86517 case MCAST_UNBLOCK_SOURCE:
86518 {
86519- struct compat_group_source_req __user *gsr32 = (void *)optval;
86520+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86521 struct group_source_req __user *kgsr = compat_alloc_user_space(
86522 sizeof(struct group_source_req));
86523 u32 interface;
86524@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86525 }
86526 case MCAST_MSFILTER:
86527 {
86528- struct compat_group_filter __user *gf32 = (void *)optval;
86529+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86530 struct group_filter __user *kgf;
86531 u32 interface, fmode, numsrc;
86532
86533@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86534 char __user *optval, int __user *optlen,
86535 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86536 {
86537- struct compat_group_filter __user *gf32 = (void *)optval;
86538+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86539 struct group_filter __user *kgf;
86540 int __user *koptlen;
86541 u32 interface, fmode, numsrc;
86542@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86543
86544 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86545 return -EINVAL;
86546- if (copy_from_user(a, args, nas[call]))
86547+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86548 return -EFAULT;
86549 a0 = a[0];
86550 a1 = a[1];
86551diff --git a/net/core/datagram.c b/net/core/datagram.c
86552index b71423d..0360434 100644
86553--- a/net/core/datagram.c
86554+++ b/net/core/datagram.c
86555@@ -295,7 +295,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86556 }
86557
86558 kfree_skb(skb);
86559- atomic_inc(&sk->sk_drops);
86560+ atomic_inc_unchecked(&sk->sk_drops);
86561 sk_mem_reclaim_partial(sk);
86562
86563 return err;
86564diff --git a/net/core/dev.c b/net/core/dev.c
86565index faebb39..a38fb42 100644
86566--- a/net/core/dev.c
86567+++ b/net/core/dev.c
86568@@ -1649,7 +1649,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86569 {
86570 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86571 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86572- atomic_long_inc(&dev->rx_dropped);
86573+ atomic_long_inc_unchecked(&dev->rx_dropped);
86574 kfree_skb(skb);
86575 return NET_RX_DROP;
86576 }
86577@@ -1658,7 +1658,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86578 skb_orphan(skb);
86579
86580 if (unlikely(!is_skb_forwardable(dev, skb))) {
86581- atomic_long_inc(&dev->rx_dropped);
86582+ atomic_long_inc_unchecked(&dev->rx_dropped);
86583 kfree_skb(skb);
86584 return NET_RX_DROP;
86585 }
86586@@ -2404,7 +2404,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86587
86588 struct dev_gso_cb {
86589 void (*destructor)(struct sk_buff *skb);
86590-};
86591+} __no_const;
86592
86593 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86594
86595@@ -3139,7 +3139,7 @@ enqueue:
86596
86597 local_irq_restore(flags);
86598
86599- atomic_long_inc(&skb->dev->rx_dropped);
86600+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86601 kfree_skb(skb);
86602 return NET_RX_DROP;
86603 }
86604@@ -3211,7 +3211,7 @@ int netif_rx_ni(struct sk_buff *skb)
86605 }
86606 EXPORT_SYMBOL(netif_rx_ni);
86607
86608-static void net_tx_action(struct softirq_action *h)
86609+static void net_tx_action(void)
86610 {
86611 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86612
86613@@ -3538,7 +3538,7 @@ ncls:
86614 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86615 } else {
86616 drop:
86617- atomic_long_inc(&skb->dev->rx_dropped);
86618+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86619 kfree_skb(skb);
86620 /* Jamal, now you will not able to escape explaining
86621 * me how you were going to use this. :-)
86622@@ -4146,7 +4146,7 @@ void netif_napi_del(struct napi_struct *napi)
86623 }
86624 EXPORT_SYMBOL(netif_napi_del);
86625
86626-static void net_rx_action(struct softirq_action *h)
86627+static void net_rx_action(void)
86628 {
86629 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86630 unsigned long time_limit = jiffies + 2;
86631@@ -5583,7 +5583,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86632 } else {
86633 netdev_stats_to_stats64(storage, &dev->stats);
86634 }
86635- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86636+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86637 return storage;
86638 }
86639 EXPORT_SYMBOL(dev_get_stats);
86640diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
86641index 5b7d0e1..cb960fc 100644
86642--- a/net/core/dev_ioctl.c
86643+++ b/net/core/dev_ioctl.c
86644@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
86645 if (no_module && capable(CAP_NET_ADMIN))
86646 no_module = request_module("netdev-%s", name);
86647 if (no_module && capable(CAP_SYS_MODULE)) {
86648+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86649+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86650+#else
86651 if (!request_module("%s", name))
86652 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86653 name);
86654+#endif
86655 }
86656 }
86657 EXPORT_SYMBOL(dev_load);
86658diff --git a/net/core/ethtool.c b/net/core/ethtool.c
86659index ce91766..3b71cdb 100644
86660--- a/net/core/ethtool.c
86661+++ b/net/core/ethtool.c
86662@@ -1319,10 +1319,19 @@ static int ethtool_get_dump_data(struct net_device *dev,
86663 if (ret)
86664 return ret;
86665
86666- len = (tmp.len > dump.len) ? dump.len : tmp.len;
86667+ len = min(tmp.len, dump.len);
86668 if (!len)
86669 return -EFAULT;
86670
86671+ /* Don't ever let the driver think there's more space available
86672+ * than it requested with .get_dump_flag().
86673+ */
86674+ dump.len = len;
86675+
86676+ /* Always allocate enough space to hold the whole thing so that the
86677+ * driver does not need to check the length and bother with partial
86678+ * dumping.
86679+ */
86680 data = vzalloc(tmp.len);
86681 if (!data)
86682 return -ENOMEM;
86683@@ -1330,6 +1339,16 @@ static int ethtool_get_dump_data(struct net_device *dev,
86684 if (ret)
86685 goto out;
86686
86687+ /* There are two sane possibilities:
86688+ * 1. The driver's .get_dump_data() does not touch dump.len.
86689+ * 2. Or it may set dump.len to how much it really writes, which
86690+ * should be tmp.len (or len if it can do a partial dump).
86691+ * In any case respond to userspace with the actual length of data
86692+ * it's receiving.
86693+ */
86694+ WARN_ON(dump.len != len && dump.len != tmp.len);
86695+ dump.len = len;
86696+
86697 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
86698 ret = -EFAULT;
86699 goto out;
86700diff --git a/net/core/flow.c b/net/core/flow.c
86701index 7102f16..146b4bd 100644
86702--- a/net/core/flow.c
86703+++ b/net/core/flow.c
86704@@ -61,7 +61,7 @@ struct flow_cache {
86705 struct timer_list rnd_timer;
86706 };
86707
86708-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86709+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86710 EXPORT_SYMBOL(flow_cache_genid);
86711 static struct flow_cache flow_cache_global;
86712 static struct kmem_cache *flow_cachep __read_mostly;
86713@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86714
86715 static int flow_entry_valid(struct flow_cache_entry *fle)
86716 {
86717- if (atomic_read(&flow_cache_genid) != fle->genid)
86718+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86719 return 0;
86720 if (fle->object && !fle->object->ops->check(fle->object))
86721 return 0;
86722@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86723 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86724 fcp->hash_count++;
86725 }
86726- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86727+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86728 flo = fle->object;
86729 if (!flo)
86730 goto ret_object;
86731@@ -279,7 +279,7 @@ nocache:
86732 }
86733 flo = resolver(net, key, family, dir, flo, ctx);
86734 if (fle) {
86735- fle->genid = atomic_read(&flow_cache_genid);
86736+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86737 if (!IS_ERR(flo))
86738 fle->object = flo;
86739 else
86740diff --git a/net/core/iovec.c b/net/core/iovec.c
86741index de178e4..1dabd8b 100644
86742--- a/net/core/iovec.c
86743+++ b/net/core/iovec.c
86744@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86745 if (m->msg_namelen) {
86746 if (mode == VERIFY_READ) {
86747 void __user *namep;
86748- namep = (void __user __force *) m->msg_name;
86749+ namep = (void __force_user *) m->msg_name;
86750 err = move_addr_to_kernel(namep, m->msg_namelen,
86751 address);
86752 if (err < 0)
86753@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86754 }
86755
86756 size = m->msg_iovlen * sizeof(struct iovec);
86757- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86758+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86759 return -EFAULT;
86760
86761 m->msg_iov = iov;
86762diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86763index 5c56b21..8766fbf 100644
86764--- a/net/core/neighbour.c
86765+++ b/net/core/neighbour.c
86766@@ -2769,7 +2769,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86767 size_t *lenp, loff_t *ppos)
86768 {
86769 int size, ret;
86770- ctl_table tmp = *ctl;
86771+ ctl_table_no_const tmp = *ctl;
86772
86773 tmp.extra1 = &zero;
86774 tmp.extra2 = &unres_qlen_max;
86775diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
86776index 569d355..79cf2d0 100644
86777--- a/net/core/net-procfs.c
86778+++ b/net/core/net-procfs.c
86779@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86780 else
86781 seq_printf(seq, "%04x", ntohs(pt->type));
86782
86783+#ifdef CONFIG_GRKERNSEC_HIDESYM
86784+ seq_printf(seq, " %-8s %pf\n",
86785+ pt->dev ? pt->dev->name : "", NULL);
86786+#else
86787 seq_printf(seq, " %-8s %pf\n",
86788 pt->dev ? pt->dev->name : "", pt->func);
86789+#endif
86790 }
86791
86792 return 0;
86793diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86794index 981fed3..536af34 100644
86795--- a/net/core/net-sysfs.c
86796+++ b/net/core/net-sysfs.c
86797@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86798 }
86799 EXPORT_SYMBOL(netdev_class_remove_file);
86800
86801-int netdev_kobject_init(void)
86802+int __init netdev_kobject_init(void)
86803 {
86804 kobj_ns_type_register(&net_ns_type_operations);
86805 return class_register(&net_class);
86806diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86807index f9765203..9feaef8 100644
86808--- a/net/core/net_namespace.c
86809+++ b/net/core/net_namespace.c
86810@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
86811 int error;
86812 LIST_HEAD(net_exit_list);
86813
86814- list_add_tail(&ops->list, list);
86815+ pax_list_add_tail((struct list_head *)&ops->list, list);
86816 if (ops->init || (ops->id && ops->size)) {
86817 for_each_net(net) {
86818 error = ops_init(ops, net);
86819@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
86820
86821 out_undo:
86822 /* If I have an error cleanup all namespaces I initialized */
86823- list_del(&ops->list);
86824+ pax_list_del((struct list_head *)&ops->list);
86825 ops_exit_list(ops, &net_exit_list);
86826 ops_free_list(ops, &net_exit_list);
86827 return error;
86828@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86829 struct net *net;
86830 LIST_HEAD(net_exit_list);
86831
86832- list_del(&ops->list);
86833+ pax_list_del((struct list_head *)&ops->list);
86834 for_each_net(net)
86835 list_add_tail(&net->exit_list, &net_exit_list);
86836 ops_exit_list(ops, &net_exit_list);
86837@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
86838 mutex_lock(&net_mutex);
86839 error = register_pernet_operations(&pernet_list, ops);
86840 if (!error && (first_device == &pernet_list))
86841- first_device = &ops->list;
86842+ first_device = (struct list_head *)&ops->list;
86843 mutex_unlock(&net_mutex);
86844 return error;
86845 }
86846diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86847index a08bd2b..4e8f43c 100644
86848--- a/net/core/rtnetlink.c
86849+++ b/net/core/rtnetlink.c
86850@@ -58,7 +58,7 @@ struct rtnl_link {
86851 rtnl_doit_func doit;
86852 rtnl_dumpit_func dumpit;
86853 rtnl_calcit_func calcit;
86854-};
86855+} __no_const;
86856
86857 static DEFINE_MUTEX(rtnl_mutex);
86858
86859@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86860 if (rtnl_link_ops_get(ops->kind))
86861 return -EEXIST;
86862
86863- if (!ops->dellink)
86864- ops->dellink = unregister_netdevice_queue;
86865+ if (!ops->dellink) {
86866+ pax_open_kernel();
86867+ *(void **)&ops->dellink = unregister_netdevice_queue;
86868+ pax_close_kernel();
86869+ }
86870
86871- list_add_tail(&ops->list, &link_ops);
86872+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86873 return 0;
86874 }
86875 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86876@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86877 for_each_net(net) {
86878 __rtnl_kill_links(net, ops);
86879 }
86880- list_del(&ops->list);
86881+ pax_list_del((struct list_head *)&ops->list);
86882 }
86883 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86884
86885diff --git a/net/core/scm.c b/net/core/scm.c
86886index 03795d0..eaf7368 100644
86887--- a/net/core/scm.c
86888+++ b/net/core/scm.c
86889@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
86890 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86891 {
86892 struct cmsghdr __user *cm
86893- = (__force struct cmsghdr __user *)msg->msg_control;
86894+ = (struct cmsghdr __force_user *)msg->msg_control;
86895 struct cmsghdr cmhdr;
86896 int cmlen = CMSG_LEN(len);
86897 int err;
86898@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86899 err = -EFAULT;
86900 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86901 goto out;
86902- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86903+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86904 goto out;
86905 cmlen = CMSG_SPACE(len);
86906 if (msg->msg_controllen < cmlen)
86907@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
86908 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86909 {
86910 struct cmsghdr __user *cm
86911- = (__force struct cmsghdr __user*)msg->msg_control;
86912+ = (struct cmsghdr __force_user *)msg->msg_control;
86913
86914 int fdmax = 0;
86915 int fdnum = scm->fp->count;
86916@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86917 if (fdnum < fdmax)
86918 fdmax = fdnum;
86919
86920- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86921+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86922 i++, cmfptr++)
86923 {
86924 struct socket *sock;
86925diff --git a/net/core/sock.c b/net/core/sock.c
86926index d6d024c..6ea7ab4 100644
86927--- a/net/core/sock.c
86928+++ b/net/core/sock.c
86929@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86930 struct sk_buff_head *list = &sk->sk_receive_queue;
86931
86932 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86933- atomic_inc(&sk->sk_drops);
86934+ atomic_inc_unchecked(&sk->sk_drops);
86935 trace_sock_rcvqueue_full(sk, skb);
86936 return -ENOMEM;
86937 }
86938@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86939 return err;
86940
86941 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86942- atomic_inc(&sk->sk_drops);
86943+ atomic_inc_unchecked(&sk->sk_drops);
86944 return -ENOBUFS;
86945 }
86946
86947@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86948 skb_dst_force(skb);
86949
86950 spin_lock_irqsave(&list->lock, flags);
86951- skb->dropcount = atomic_read(&sk->sk_drops);
86952+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86953 __skb_queue_tail(list, skb);
86954 spin_unlock_irqrestore(&list->lock, flags);
86955
86956@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86957 skb->dev = NULL;
86958
86959 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86960- atomic_inc(&sk->sk_drops);
86961+ atomic_inc_unchecked(&sk->sk_drops);
86962 goto discard_and_relse;
86963 }
86964 if (nested)
86965@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86966 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86967 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86968 bh_unlock_sock(sk);
86969- atomic_inc(&sk->sk_drops);
86970+ atomic_inc_unchecked(&sk->sk_drops);
86971 goto discard_and_relse;
86972 }
86973
86974@@ -933,12 +933,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86975 struct timeval tm;
86976 } v;
86977
86978- int lv = sizeof(int);
86979- int len;
86980+ unsigned int lv = sizeof(int);
86981+ unsigned int len;
86982
86983 if (get_user(len, optlen))
86984 return -EFAULT;
86985- if (len < 0)
86986+ if (len > INT_MAX)
86987 return -EINVAL;
86988
86989 memset(&v, 0, sizeof(v));
86990@@ -1090,11 +1090,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86991
86992 case SO_PEERNAME:
86993 {
86994- char address[128];
86995+ char address[_K_SS_MAXSIZE];
86996
86997 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86998 return -ENOTCONN;
86999- if (lv < len)
87000+ if (lv < len || sizeof address < len)
87001 return -EINVAL;
87002 if (copy_to_user(optval, address, len))
87003 return -EFAULT;
87004@@ -1161,7 +1161,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
87005
87006 if (len > lv)
87007 len = lv;
87008- if (copy_to_user(optval, &v, len))
87009+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
87010 return -EFAULT;
87011 lenout:
87012 if (put_user(len, optlen))
87013@@ -2277,7 +2277,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
87014 */
87015 smp_wmb();
87016 atomic_set(&sk->sk_refcnt, 1);
87017- atomic_set(&sk->sk_drops, 0);
87018+ atomic_set_unchecked(&sk->sk_drops, 0);
87019 }
87020 EXPORT_SYMBOL(sock_init_data);
87021
87022diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
87023index a0e9cf6..ef7f9ed 100644
87024--- a/net/core/sock_diag.c
87025+++ b/net/core/sock_diag.c
87026@@ -9,26 +9,33 @@
87027 #include <linux/inet_diag.h>
87028 #include <linux/sock_diag.h>
87029
87030-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
87031+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
87032 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
87033 static DEFINE_MUTEX(sock_diag_table_mutex);
87034
87035 int sock_diag_check_cookie(void *sk, __u32 *cookie)
87036 {
87037+#ifndef CONFIG_GRKERNSEC_HIDESYM
87038 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
87039 cookie[1] != INET_DIAG_NOCOOKIE) &&
87040 ((u32)(unsigned long)sk != cookie[0] ||
87041 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
87042 return -ESTALE;
87043 else
87044+#endif
87045 return 0;
87046 }
87047 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
87048
87049 void sock_diag_save_cookie(void *sk, __u32 *cookie)
87050 {
87051+#ifdef CONFIG_GRKERNSEC_HIDESYM
87052+ cookie[0] = 0;
87053+ cookie[1] = 0;
87054+#else
87055 cookie[0] = (u32)(unsigned long)sk;
87056 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
87057+#endif
87058 }
87059 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
87060
87061@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
87062 mutex_lock(&sock_diag_table_mutex);
87063 if (sock_diag_handlers[hndl->family])
87064 err = -EBUSY;
87065- else
87066+ else {
87067+ pax_open_kernel();
87068 sock_diag_handlers[hndl->family] = hndl;
87069+ pax_close_kernel();
87070+ }
87071 mutex_unlock(&sock_diag_table_mutex);
87072
87073 return err;
87074@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
87075
87076 mutex_lock(&sock_diag_table_mutex);
87077 BUG_ON(sock_diag_handlers[family] != hnld);
87078+ pax_open_kernel();
87079 sock_diag_handlers[family] = NULL;
87080+ pax_close_kernel();
87081 mutex_unlock(&sock_diag_table_mutex);
87082 }
87083 EXPORT_SYMBOL_GPL(sock_diag_unregister);
87084diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
87085index cfdb46a..cef55e1 100644
87086--- a/net/core/sysctl_net_core.c
87087+++ b/net/core/sysctl_net_core.c
87088@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
87089 {
87090 unsigned int orig_size, size;
87091 int ret, i;
87092- ctl_table tmp = {
87093+ ctl_table_no_const tmp = {
87094 .data = &size,
87095 .maxlen = sizeof(size),
87096 .mode = table->mode
87097@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
87098
87099 static __net_init int sysctl_core_net_init(struct net *net)
87100 {
87101- struct ctl_table *tbl;
87102+ ctl_table_no_const *tbl = NULL;
87103
87104 net->core.sysctl_somaxconn = SOMAXCONN;
87105
87106- tbl = netns_core_table;
87107 if (!net_eq(net, &init_net)) {
87108- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
87109+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
87110 if (tbl == NULL)
87111 goto err_dup;
87112
87113@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
87114 if (net->user_ns != &init_user_ns) {
87115 tbl[0].procname = NULL;
87116 }
87117- }
87118-
87119- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
87120+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
87121+ } else
87122+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
87123 if (net->core.sysctl_hdr == NULL)
87124 goto err_reg;
87125
87126 return 0;
87127
87128 err_reg:
87129- if (tbl != netns_core_table)
87130- kfree(tbl);
87131+ kfree(tbl);
87132 err_dup:
87133 return -ENOMEM;
87134 }
87135@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
87136 kfree(tbl);
87137 }
87138
87139-static __net_initdata struct pernet_operations sysctl_core_ops = {
87140+static __net_initconst struct pernet_operations sysctl_core_ops = {
87141 .init = sysctl_core_net_init,
87142 .exit = sysctl_core_net_exit,
87143 };
87144diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
87145index c21f200..bc4565b 100644
87146--- a/net/decnet/af_decnet.c
87147+++ b/net/decnet/af_decnet.c
87148@@ -465,6 +465,7 @@ static struct proto dn_proto = {
87149 .sysctl_rmem = sysctl_decnet_rmem,
87150 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
87151 .obj_size = sizeof(struct dn_sock),
87152+ .slab_flags = SLAB_USERCOPY,
87153 };
87154
87155 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
87156diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
87157index a55eecc..dd8428c 100644
87158--- a/net/decnet/sysctl_net_decnet.c
87159+++ b/net/decnet/sysctl_net_decnet.c
87160@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
87161
87162 if (len > *lenp) len = *lenp;
87163
87164- if (copy_to_user(buffer, addr, len))
87165+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
87166 return -EFAULT;
87167
87168 *lenp = len;
87169@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
87170
87171 if (len > *lenp) len = *lenp;
87172
87173- if (copy_to_user(buffer, devname, len))
87174+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
87175 return -EFAULT;
87176
87177 *lenp = len;
87178diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
87179index d01be2a..8976537 100644
87180--- a/net/ipv4/af_inet.c
87181+++ b/net/ipv4/af_inet.c
87182@@ -1703,13 +1703,9 @@ static int __init inet_init(void)
87183
87184 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
87185
87186- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
87187- if (!sysctl_local_reserved_ports)
87188- goto out;
87189-
87190 rc = proto_register(&tcp_prot, 1);
87191 if (rc)
87192- goto out_free_reserved_ports;
87193+ goto out;
87194
87195 rc = proto_register(&udp_prot, 1);
87196 if (rc)
87197@@ -1818,8 +1814,6 @@ out_unregister_udp_proto:
87198 proto_unregister(&udp_prot);
87199 out_unregister_tcp_proto:
87200 proto_unregister(&tcp_prot);
87201-out_free_reserved_ports:
87202- kfree(sysctl_local_reserved_ports);
87203 goto out;
87204 }
87205
87206diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
87207index 2e7f194..0fa4d6d 100644
87208--- a/net/ipv4/ah4.c
87209+++ b/net/ipv4/ah4.c
87210@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
87211 return;
87212
87213 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87214- atomic_inc(&flow_cache_genid);
87215+ atomic_inc_unchecked(&flow_cache_genid);
87216 rt_genid_bump(net);
87217
87218 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
87219diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
87220index dfc39d4..0b82c4d 100644
87221--- a/net/ipv4/devinet.c
87222+++ b/net/ipv4/devinet.c
87223@@ -1529,7 +1529,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
87224 idx = 0;
87225 head = &net->dev_index_head[h];
87226 rcu_read_lock();
87227- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
87228+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
87229 net->dev_base_seq;
87230 hlist_for_each_entry_rcu(dev, head, index_hlist) {
87231 if (idx < s_idx)
87232@@ -1840,7 +1840,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
87233 idx = 0;
87234 head = &net->dev_index_head[h];
87235 rcu_read_lock();
87236- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
87237+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
87238 net->dev_base_seq;
87239 hlist_for_each_entry_rcu(dev, head, index_hlist) {
87240 if (idx < s_idx)
87241@@ -2065,7 +2065,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
87242 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
87243 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
87244
87245-static struct devinet_sysctl_table {
87246+static const struct devinet_sysctl_table {
87247 struct ctl_table_header *sysctl_header;
87248 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
87249 } devinet_sysctl = {
87250@@ -2183,7 +2183,7 @@ static __net_init int devinet_init_net(struct net *net)
87251 int err;
87252 struct ipv4_devconf *all, *dflt;
87253 #ifdef CONFIG_SYSCTL
87254- struct ctl_table *tbl = ctl_forward_entry;
87255+ ctl_table_no_const *tbl = NULL;
87256 struct ctl_table_header *forw_hdr;
87257 #endif
87258
87259@@ -2201,7 +2201,7 @@ static __net_init int devinet_init_net(struct net *net)
87260 goto err_alloc_dflt;
87261
87262 #ifdef CONFIG_SYSCTL
87263- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
87264+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
87265 if (tbl == NULL)
87266 goto err_alloc_ctl;
87267
87268@@ -2221,7 +2221,10 @@ static __net_init int devinet_init_net(struct net *net)
87269 goto err_reg_dflt;
87270
87271 err = -ENOMEM;
87272- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87273+ if (!net_eq(net, &init_net))
87274+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87275+ else
87276+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
87277 if (forw_hdr == NULL)
87278 goto err_reg_ctl;
87279 net->ipv4.forw_hdr = forw_hdr;
87280@@ -2237,8 +2240,7 @@ err_reg_ctl:
87281 err_reg_dflt:
87282 __devinet_sysctl_unregister(all);
87283 err_reg_all:
87284- if (tbl != ctl_forward_entry)
87285- kfree(tbl);
87286+ kfree(tbl);
87287 err_alloc_ctl:
87288 #endif
87289 if (dflt != &ipv4_devconf_dflt)
87290diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
87291index 4cfe34d..a6ba66e 100644
87292--- a/net/ipv4/esp4.c
87293+++ b/net/ipv4/esp4.c
87294@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
87295 return;
87296
87297 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87298- atomic_inc(&flow_cache_genid);
87299+ atomic_inc_unchecked(&flow_cache_genid);
87300 rt_genid_bump(net);
87301
87302 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
87303diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
87304index c7629a2..b62d139 100644
87305--- a/net/ipv4/fib_frontend.c
87306+++ b/net/ipv4/fib_frontend.c
87307@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
87308 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87309 fib_sync_up(dev);
87310 #endif
87311- atomic_inc(&net->ipv4.dev_addr_genid);
87312+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87313 rt_cache_flush(dev_net(dev));
87314 break;
87315 case NETDEV_DOWN:
87316 fib_del_ifaddr(ifa, NULL);
87317- atomic_inc(&net->ipv4.dev_addr_genid);
87318+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87319 if (ifa->ifa_dev->ifa_list == NULL) {
87320 /* Last address was deleted from this interface.
87321 * Disable IP.
87322@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
87323 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87324 fib_sync_up(dev);
87325 #endif
87326- atomic_inc(&net->ipv4.dev_addr_genid);
87327+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87328 rt_cache_flush(net);
87329 break;
87330 case NETDEV_DOWN:
87331diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
87332index 8f6cb7a..34507f9 100644
87333--- a/net/ipv4/fib_semantics.c
87334+++ b/net/ipv4/fib_semantics.c
87335@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
87336 nh->nh_saddr = inet_select_addr(nh->nh_dev,
87337 nh->nh_gw,
87338 nh->nh_parent->fib_scope);
87339- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
87340+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
87341
87342 return nh->nh_saddr;
87343 }
87344diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
87345index 6acb541..9ea617d 100644
87346--- a/net/ipv4/inet_connection_sock.c
87347+++ b/net/ipv4/inet_connection_sock.c
87348@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
87349 .range = { 32768, 61000 },
87350 };
87351
87352-unsigned long *sysctl_local_reserved_ports;
87353+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
87354 EXPORT_SYMBOL(sysctl_local_reserved_ports);
87355
87356 void inet_get_local_port_range(int *low, int *high)
87357diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
87358index 6af375a..c493c74 100644
87359--- a/net/ipv4/inet_hashtables.c
87360+++ b/net/ipv4/inet_hashtables.c
87361@@ -18,12 +18,15 @@
87362 #include <linux/sched.h>
87363 #include <linux/slab.h>
87364 #include <linux/wait.h>
87365+#include <linux/security.h>
87366
87367 #include <net/inet_connection_sock.h>
87368 #include <net/inet_hashtables.h>
87369 #include <net/secure_seq.h>
87370 #include <net/ip.h>
87371
87372+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
87373+
87374 /*
87375 * Allocate and initialize a new local port bind bucket.
87376 * The bindhash mutex for snum's hash chain must be held here.
87377@@ -554,6 +557,8 @@ ok:
87378 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
87379 spin_unlock(&head->lock);
87380
87381+ gr_update_task_in_ip_table(current, inet_sk(sk));
87382+
87383 if (tw) {
87384 inet_twsk_deschedule(tw, death_row);
87385 while (twrefcnt) {
87386diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
87387index 000e3d2..5472da3 100644
87388--- a/net/ipv4/inetpeer.c
87389+++ b/net/ipv4/inetpeer.c
87390@@ -503,8 +503,8 @@ relookup:
87391 if (p) {
87392 p->daddr = *daddr;
87393 atomic_set(&p->refcnt, 1);
87394- atomic_set(&p->rid, 0);
87395- atomic_set(&p->ip_id_count,
87396+ atomic_set_unchecked(&p->rid, 0);
87397+ atomic_set_unchecked(&p->ip_id_count,
87398 (daddr->family == AF_INET) ?
87399 secure_ip_id(daddr->addr.a4) :
87400 secure_ipv6_id(daddr->addr.a6));
87401diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
87402index b66910a..cfe416e 100644
87403--- a/net/ipv4/ip_fragment.c
87404+++ b/net/ipv4/ip_fragment.c
87405@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
87406 return 0;
87407
87408 start = qp->rid;
87409- end = atomic_inc_return(&peer->rid);
87410+ end = atomic_inc_return_unchecked(&peer->rid);
87411 qp->rid = end;
87412
87413 rc = qp->q.fragments && (end - start) > max;
87414@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
87415
87416 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87417 {
87418- struct ctl_table *table;
87419+ ctl_table_no_const *table = NULL;
87420 struct ctl_table_header *hdr;
87421
87422- table = ip4_frags_ns_ctl_table;
87423 if (!net_eq(net, &init_net)) {
87424- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87425+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87426 if (table == NULL)
87427 goto err_alloc;
87428
87429@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87430 /* Don't export sysctls to unprivileged users */
87431 if (net->user_ns != &init_user_ns)
87432 table[0].procname = NULL;
87433- }
87434+ hdr = register_net_sysctl(net, "net/ipv4", table);
87435+ } else
87436+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87437
87438- hdr = register_net_sysctl(net, "net/ipv4", table);
87439 if (hdr == NULL)
87440 goto err_reg;
87441
87442@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87443 return 0;
87444
87445 err_reg:
87446- if (!net_eq(net, &init_net))
87447- kfree(table);
87448+ kfree(table);
87449 err_alloc:
87450 return -ENOMEM;
87451 }
87452diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87453index 2a83591..68e7458 100644
87454--- a/net/ipv4/ip_gre.c
87455+++ b/net/ipv4/ip_gre.c
87456@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
87457 module_param(log_ecn_error, bool, 0644);
87458 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87459
87460-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87461+static struct rtnl_link_ops ipgre_link_ops;
87462 static int ipgre_tunnel_init(struct net_device *dev);
87463
87464 static int ipgre_net_id __read_mostly;
87465@@ -503,10 +503,11 @@ static int ipgre_tunnel_ioctl(struct net_device *dev,
87466
87467 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
87468 return -EFAULT;
87469- if (p.iph.version != 4 || p.iph.protocol != IPPROTO_GRE ||
87470- p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)) ||
87471- ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING))) {
87472- return -EINVAL;
87473+ if (cmd == SIOCADDTUNNEL || cmd == SIOCCHGTUNNEL) {
87474+ if (p.iph.version != 4 || p.iph.protocol != IPPROTO_GRE ||
87475+ p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)) ||
87476+ ((p.i_flags|p.o_flags)&(GRE_VERSION|GRE_ROUTING)))
87477+ return -EINVAL;
87478 }
87479 p.i_flags = gre_flags_to_tnl_flags(p.i_flags);
87480 p.o_flags = gre_flags_to_tnl_flags(p.o_flags);
87481@@ -918,7 +919,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87482 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87483 };
87484
87485-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87486+static struct rtnl_link_ops ipgre_link_ops = {
87487 .kind = "gre",
87488 .maxtype = IFLA_GRE_MAX,
87489 .policy = ipgre_policy,
87490@@ -932,7 +933,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87491 .fill_info = ipgre_fill_info,
87492 };
87493
87494-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87495+static struct rtnl_link_ops ipgre_tap_ops = {
87496 .kind = "gretap",
87497 .maxtype = IFLA_GRE_MAX,
87498 .policy = ipgre_policy,
87499diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87500index d9c4f11..02b82dbc 100644
87501--- a/net/ipv4/ip_sockglue.c
87502+++ b/net/ipv4/ip_sockglue.c
87503@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87504 len = min_t(unsigned int, len, opt->optlen);
87505 if (put_user(len, optlen))
87506 return -EFAULT;
87507- if (copy_to_user(optval, opt->__data, len))
87508+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87509+ copy_to_user(optval, opt->__data, len))
87510 return -EFAULT;
87511 return 0;
87512 }
87513@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87514 if (sk->sk_type != SOCK_STREAM)
87515 return -ENOPROTOOPT;
87516
87517- msg.msg_control = optval;
87518+ msg.msg_control = (void __force_kernel *)optval;
87519 msg.msg_controllen = len;
87520 msg.msg_flags = flags;
87521
87522diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87523index c118f6b..63856c4 100644
87524--- a/net/ipv4/ip_vti.c
87525+++ b/net/ipv4/ip_vti.c
87526@@ -47,7 +47,7 @@
87527 #define HASH_SIZE 16
87528 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87529
87530-static struct rtnl_link_ops vti_link_ops __read_mostly;
87531+static struct rtnl_link_ops vti_link_ops;
87532
87533 static int vti_net_id __read_mostly;
87534 struct vti_net {
87535@@ -606,17 +606,10 @@ static int __net_init vti_fb_tunnel_init(struct net_device *dev)
87536 struct iphdr *iph = &tunnel->parms.iph;
87537 struct vti_net *ipn = net_generic(dev_net(dev), vti_net_id);
87538
87539- tunnel->dev = dev;
87540- strcpy(tunnel->parms.name, dev->name);
87541-
87542 iph->version = 4;
87543 iph->protocol = IPPROTO_IPIP;
87544 iph->ihl = 5;
87545
87546- dev->tstats = alloc_percpu(struct pcpu_tstats);
87547- if (!dev->tstats)
87548- return -ENOMEM;
87549-
87550 dev_hold(dev);
87551 rcu_assign_pointer(ipn->tunnels_wc[0], tunnel);
87552 return 0;
87553@@ -847,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87554 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87555 };
87556
87557-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87558+static struct rtnl_link_ops vti_link_ops = {
87559 .kind = "vti",
87560 .maxtype = IFLA_VTI_MAX,
87561 .policy = vti_policy,
87562diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87563index 59cb8c7..a72160c 100644
87564--- a/net/ipv4/ipcomp.c
87565+++ b/net/ipv4/ipcomp.c
87566@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87567 return;
87568
87569 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87570- atomic_inc(&flow_cache_genid);
87571+ atomic_inc_unchecked(&flow_cache_genid);
87572 rt_genid_bump(net);
87573
87574 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87575diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87576index efa1138..20dbba0 100644
87577--- a/net/ipv4/ipconfig.c
87578+++ b/net/ipv4/ipconfig.c
87579@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87580
87581 mm_segment_t oldfs = get_fs();
87582 set_fs(get_ds());
87583- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87584+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87585 set_fs(oldfs);
87586 return res;
87587 }
87588@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87589
87590 mm_segment_t oldfs = get_fs();
87591 set_fs(get_ds());
87592- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87593+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87594 set_fs(oldfs);
87595 return res;
87596 }
87597@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87598
87599 mm_segment_t oldfs = get_fs();
87600 set_fs(get_ds());
87601- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87602+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87603 set_fs(oldfs);
87604 return res;
87605 }
87606diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87607index 77bfcce..64a55d4 100644
87608--- a/net/ipv4/ipip.c
87609+++ b/net/ipv4/ipip.c
87610@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87611 static int ipip_net_id __read_mostly;
87612
87613 static int ipip_tunnel_init(struct net_device *dev);
87614-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87615+static struct rtnl_link_ops ipip_link_ops;
87616
87617 static int ipip_err(struct sk_buff *skb, u32 info)
87618 {
87619@@ -404,7 +404,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87620 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87621 };
87622
87623-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87624+static struct rtnl_link_ops ipip_link_ops = {
87625 .kind = "ipip",
87626 .maxtype = IFLA_IPTUN_MAX,
87627 .policy = ipip_policy,
87628diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87629index 85a4f21..1beb1f5 100644
87630--- a/net/ipv4/netfilter/arp_tables.c
87631+++ b/net/ipv4/netfilter/arp_tables.c
87632@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
87633 #endif
87634
87635 static int get_info(struct net *net, void __user *user,
87636- const int *len, int compat)
87637+ int len, int compat)
87638 {
87639 char name[XT_TABLE_MAXNAMELEN];
87640 struct xt_table *t;
87641 int ret;
87642
87643- if (*len != sizeof(struct arpt_getinfo)) {
87644- duprintf("length %u != %Zu\n", *len,
87645+ if (len != sizeof(struct arpt_getinfo)) {
87646+ duprintf("length %u != %Zu\n", len,
87647 sizeof(struct arpt_getinfo));
87648 return -EINVAL;
87649 }
87650@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
87651 info.size = private->size;
87652 strcpy(info.name, name);
87653
87654- if (copy_to_user(user, &info, *len) != 0)
87655+ if (copy_to_user(user, &info, len) != 0)
87656 ret = -EFAULT;
87657 else
87658 ret = 0;
87659@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87660
87661 switch (cmd) {
87662 case ARPT_SO_GET_INFO:
87663- ret = get_info(sock_net(sk), user, len, 1);
87664+ ret = get_info(sock_net(sk), user, *len, 1);
87665 break;
87666 case ARPT_SO_GET_ENTRIES:
87667 ret = compat_get_entries(sock_net(sk), user, len);
87668@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87669
87670 switch (cmd) {
87671 case ARPT_SO_GET_INFO:
87672- ret = get_info(sock_net(sk), user, len, 0);
87673+ ret = get_info(sock_net(sk), user, *len, 0);
87674 break;
87675
87676 case ARPT_SO_GET_ENTRIES:
87677diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87678index d23118d..6ad7277 100644
87679--- a/net/ipv4/netfilter/ip_tables.c
87680+++ b/net/ipv4/netfilter/ip_tables.c
87681@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87682 #endif
87683
87684 static int get_info(struct net *net, void __user *user,
87685- const int *len, int compat)
87686+ int len, int compat)
87687 {
87688 char name[XT_TABLE_MAXNAMELEN];
87689 struct xt_table *t;
87690 int ret;
87691
87692- if (*len != sizeof(struct ipt_getinfo)) {
87693- duprintf("length %u != %zu\n", *len,
87694+ if (len != sizeof(struct ipt_getinfo)) {
87695+ duprintf("length %u != %zu\n", len,
87696 sizeof(struct ipt_getinfo));
87697 return -EINVAL;
87698 }
87699@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87700 info.size = private->size;
87701 strcpy(info.name, name);
87702
87703- if (copy_to_user(user, &info, *len) != 0)
87704+ if (copy_to_user(user, &info, len) != 0)
87705 ret = -EFAULT;
87706 else
87707 ret = 0;
87708@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87709
87710 switch (cmd) {
87711 case IPT_SO_GET_INFO:
87712- ret = get_info(sock_net(sk), user, len, 1);
87713+ ret = get_info(sock_net(sk), user, *len, 1);
87714 break;
87715 case IPT_SO_GET_ENTRIES:
87716 ret = compat_get_entries(sock_net(sk), user, len);
87717@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87718
87719 switch (cmd) {
87720 case IPT_SO_GET_INFO:
87721- ret = get_info(sock_net(sk), user, len, 0);
87722+ ret = get_info(sock_net(sk), user, *len, 0);
87723 break;
87724
87725 case IPT_SO_GET_ENTRIES:
87726diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87727index 7d93d62..cbbf2a3 100644
87728--- a/net/ipv4/ping.c
87729+++ b/net/ipv4/ping.c
87730@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87731 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87732 0, sock_i_ino(sp),
87733 atomic_read(&sp->sk_refcnt), sp,
87734- atomic_read(&sp->sk_drops), len);
87735+ atomic_read_unchecked(&sp->sk_drops), len);
87736 }
87737
87738 static int ping_seq_show(struct seq_file *seq, void *v)
87739diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87740index dd44e0a..06dcca4 100644
87741--- a/net/ipv4/raw.c
87742+++ b/net/ipv4/raw.c
87743@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87744 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87745 {
87746 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87747- atomic_inc(&sk->sk_drops);
87748+ atomic_inc_unchecked(&sk->sk_drops);
87749 kfree_skb(skb);
87750 return NET_RX_DROP;
87751 }
87752@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
87753
87754 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87755 {
87756+ struct icmp_filter filter;
87757+
87758 if (optlen > sizeof(struct icmp_filter))
87759 optlen = sizeof(struct icmp_filter);
87760- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87761+ if (copy_from_user(&filter, optval, optlen))
87762 return -EFAULT;
87763+ raw_sk(sk)->filter = filter;
87764 return 0;
87765 }
87766
87767 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87768 {
87769 int len, ret = -EFAULT;
87770+ struct icmp_filter filter;
87771
87772 if (get_user(len, optlen))
87773 goto out;
87774@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87775 if (len > sizeof(struct icmp_filter))
87776 len = sizeof(struct icmp_filter);
87777 ret = -EFAULT;
87778- if (put_user(len, optlen) ||
87779- copy_to_user(optval, &raw_sk(sk)->filter, len))
87780+ filter = raw_sk(sk)->filter;
87781+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87782 goto out;
87783 ret = 0;
87784 out: return ret;
87785@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87786 0, 0L, 0,
87787 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87788 0, sock_i_ino(sp),
87789- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87790+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87791 }
87792
87793 static int raw_seq_show(struct seq_file *seq, void *v)
87794diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87795index d35bbf0..faa3ab8 100644
87796--- a/net/ipv4/route.c
87797+++ b/net/ipv4/route.c
87798@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87799 .maxlen = sizeof(int),
87800 .mode = 0200,
87801 .proc_handler = ipv4_sysctl_rtcache_flush,
87802+ .extra1 = &init_net,
87803 },
87804 { },
87805 };
87806
87807 static __net_init int sysctl_route_net_init(struct net *net)
87808 {
87809- struct ctl_table *tbl;
87810+ ctl_table_no_const *tbl = NULL;
87811
87812- tbl = ipv4_route_flush_table;
87813 if (!net_eq(net, &init_net)) {
87814- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87815+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87816 if (tbl == NULL)
87817 goto err_dup;
87818
87819 /* Don't export sysctls to unprivileged users */
87820 if (net->user_ns != &init_user_ns)
87821 tbl[0].procname = NULL;
87822- }
87823- tbl[0].extra1 = net;
87824+ tbl[0].extra1 = net;
87825+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87826+ } else
87827+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87828
87829- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87830 if (net->ipv4.route_hdr == NULL)
87831 goto err_reg;
87832 return 0;
87833
87834 err_reg:
87835- if (tbl != ipv4_route_flush_table)
87836- kfree(tbl);
87837+ kfree(tbl);
87838 err_dup:
87839 return -ENOMEM;
87840 }
87841@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87842
87843 static __net_init int rt_genid_init(struct net *net)
87844 {
87845- atomic_set(&net->rt_genid, 0);
87846+ atomic_set_unchecked(&net->rt_genid, 0);
87847 get_random_bytes(&net->ipv4.dev_addr_genid,
87848 sizeof(net->ipv4.dev_addr_genid));
87849 return 0;
87850diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87851index fa2f63f..6554815 100644
87852--- a/net/ipv4/sysctl_net_ipv4.c
87853+++ b/net/ipv4/sysctl_net_ipv4.c
87854@@ -55,7 +55,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87855 {
87856 int ret;
87857 int range[2];
87858- ctl_table tmp = {
87859+ ctl_table_no_const tmp = {
87860 .data = &range,
87861 .maxlen = sizeof(range),
87862 .mode = table->mode,
87863@@ -108,7 +108,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87864 int ret;
87865 gid_t urange[2];
87866 kgid_t low, high;
87867- ctl_table tmp = {
87868+ ctl_table_no_const tmp = {
87869 .data = &urange,
87870 .maxlen = sizeof(urange),
87871 .mode = table->mode,
87872@@ -139,7 +139,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87873 void __user *buffer, size_t *lenp, loff_t *ppos)
87874 {
87875 char val[TCP_CA_NAME_MAX];
87876- ctl_table tbl = {
87877+ ctl_table_no_const tbl = {
87878 .data = val,
87879 .maxlen = TCP_CA_NAME_MAX,
87880 };
87881@@ -158,7 +158,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87882 void __user *buffer, size_t *lenp,
87883 loff_t *ppos)
87884 {
87885- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87886+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87887 int ret;
87888
87889 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87890@@ -175,7 +175,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87891 void __user *buffer, size_t *lenp,
87892 loff_t *ppos)
87893 {
87894- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87895+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87896 int ret;
87897
87898 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87899@@ -201,15 +201,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87900 struct mem_cgroup *memcg;
87901 #endif
87902
87903- ctl_table tmp = {
87904+ ctl_table_no_const tmp = {
87905 .data = &vec,
87906 .maxlen = sizeof(vec),
87907 .mode = ctl->mode,
87908 };
87909
87910 if (!write) {
87911- ctl->data = &net->ipv4.sysctl_tcp_mem;
87912- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87913+ ctl_table_no_const tcp_mem = *ctl;
87914+
87915+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87916+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87917 }
87918
87919 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87920@@ -236,7 +238,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87921 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87922 size_t *lenp, loff_t *ppos)
87923 {
87924- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87925+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87926 struct tcp_fastopen_context *ctxt;
87927 int ret;
87928 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87929@@ -477,7 +479,7 @@ static struct ctl_table ipv4_table[] = {
87930 },
87931 {
87932 .procname = "ip_local_reserved_ports",
87933- .data = NULL, /* initialized in sysctl_ipv4_init */
87934+ .data = sysctl_local_reserved_ports,
87935 .maxlen = 65536,
87936 .mode = 0644,
87937 .proc_handler = proc_do_large_bitmap,
87938@@ -842,11 +844,10 @@ static struct ctl_table ipv4_net_table[] = {
87939
87940 static __net_init int ipv4_sysctl_init_net(struct net *net)
87941 {
87942- struct ctl_table *table;
87943+ ctl_table_no_const *table = NULL;
87944
87945- table = ipv4_net_table;
87946 if (!net_eq(net, &init_net)) {
87947- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87948+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87949 if (table == NULL)
87950 goto err_alloc;
87951
87952@@ -881,15 +882,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87953
87954 tcp_init_mem(net);
87955
87956- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87957+ if (!net_eq(net, &init_net))
87958+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87959+ else
87960+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87961 if (net->ipv4.ipv4_hdr == NULL)
87962 goto err_reg;
87963
87964 return 0;
87965
87966 err_reg:
87967- if (!net_eq(net, &init_net))
87968- kfree(table);
87969+ kfree(table);
87970 err_alloc:
87971 return -ENOMEM;
87972 }
87973@@ -911,16 +914,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87974 static __init int sysctl_ipv4_init(void)
87975 {
87976 struct ctl_table_header *hdr;
87977- struct ctl_table *i;
87978-
87979- for (i = ipv4_table; i->procname; i++) {
87980- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87981- i->data = sysctl_local_reserved_ports;
87982- break;
87983- }
87984- }
87985- if (!i->procname)
87986- return -EINVAL;
87987
87988 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87989 if (hdr == NULL)
87990diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87991index 9c62257..651cc27 100644
87992--- a/net/ipv4/tcp_input.c
87993+++ b/net/ipv4/tcp_input.c
87994@@ -4436,7 +4436,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87995 * simplifies code)
87996 */
87997 static void
87998-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87999+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
88000 struct sk_buff *head, struct sk_buff *tail,
88001 u32 start, u32 end)
88002 {
88003@@ -5522,6 +5522,7 @@ discard:
88004 tcp_paws_reject(&tp->rx_opt, 0))
88005 goto discard_and_undo;
88006
88007+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
88008 if (th->syn) {
88009 /* We see SYN without ACK. It is attempt of
88010 * simultaneous connect with crossed SYNs.
88011@@ -5572,6 +5573,7 @@ discard:
88012 goto discard;
88013 #endif
88014 }
88015+#endif
88016 /* "fifth, if neither of the SYN or RST bits is set then
88017 * drop the segment and return."
88018 */
88019@@ -5616,7 +5618,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
88020 goto discard;
88021
88022 if (th->syn) {
88023- if (th->fin)
88024+ if (th->fin || th->urg || th->psh)
88025 goto discard;
88026 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
88027 return 1;
88028diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
88029index 7999fc5..c812f42 100644
88030--- a/net/ipv4/tcp_ipv4.c
88031+++ b/net/ipv4/tcp_ipv4.c
88032@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
88033 EXPORT_SYMBOL(sysctl_tcp_low_latency);
88034
88035
88036+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88037+extern int grsec_enable_blackhole;
88038+#endif
88039+
88040 #ifdef CONFIG_TCP_MD5SIG
88041 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
88042 __be32 daddr, __be32 saddr, const struct tcphdr *th);
88043@@ -1855,6 +1859,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
88044 return 0;
88045
88046 reset:
88047+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88048+ if (!grsec_enable_blackhole)
88049+#endif
88050 tcp_v4_send_reset(rsk, skb);
88051 discard:
88052 kfree_skb(skb);
88053@@ -2000,12 +2007,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
88054 TCP_SKB_CB(skb)->sacked = 0;
88055
88056 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88057- if (!sk)
88058+ if (!sk) {
88059+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88060+ ret = 1;
88061+#endif
88062 goto no_tcp_socket;
88063-
88064+ }
88065 process:
88066- if (sk->sk_state == TCP_TIME_WAIT)
88067+ if (sk->sk_state == TCP_TIME_WAIT) {
88068+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88069+ ret = 2;
88070+#endif
88071 goto do_time_wait;
88072+ }
88073
88074 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
88075 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88076@@ -2058,6 +2072,10 @@ csum_error:
88077 bad_packet:
88078 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88079 } else {
88080+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88081+ if (!grsec_enable_blackhole || (ret == 1 &&
88082+ (skb->dev->flags & IFF_LOOPBACK)))
88083+#endif
88084 tcp_v4_send_reset(NULL, skb);
88085 }
88086
88087diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
88088index 0f01788..d52a859 100644
88089--- a/net/ipv4/tcp_minisocks.c
88090+++ b/net/ipv4/tcp_minisocks.c
88091@@ -27,6 +27,10 @@
88092 #include <net/inet_common.h>
88093 #include <net/xfrm.h>
88094
88095+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88096+extern int grsec_enable_blackhole;
88097+#endif
88098+
88099 int sysctl_tcp_syncookies __read_mostly = 1;
88100 EXPORT_SYMBOL(sysctl_tcp_syncookies);
88101
88102@@ -717,7 +721,10 @@ embryonic_reset:
88103 * avoid becoming vulnerable to outside attack aiming at
88104 * resetting legit local connections.
88105 */
88106- req->rsk_ops->send_reset(sk, skb);
88107+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88108+ if (!grsec_enable_blackhole)
88109+#endif
88110+ req->rsk_ops->send_reset(sk, skb);
88111 } else if (fastopen) { /* received a valid RST pkt */
88112 reqsk_fastopen_remove(sk, req, true);
88113 tcp_reset(sk);
88114diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
88115index d4943f6..e7a74a5 100644
88116--- a/net/ipv4/tcp_probe.c
88117+++ b/net/ipv4/tcp_probe.c
88118@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
88119 if (cnt + width >= len)
88120 break;
88121
88122- if (copy_to_user(buf + cnt, tbuf, width))
88123+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
88124 return -EFAULT;
88125 cnt += width;
88126 }
88127diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
88128index 4b85e6f..22f9ac9 100644
88129--- a/net/ipv4/tcp_timer.c
88130+++ b/net/ipv4/tcp_timer.c
88131@@ -22,6 +22,10 @@
88132 #include <linux/gfp.h>
88133 #include <net/tcp.h>
88134
88135+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88136+extern int grsec_lastack_retries;
88137+#endif
88138+
88139 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
88140 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
88141 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
88142@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
88143 }
88144 }
88145
88146+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88147+ if ((sk->sk_state == TCP_LAST_ACK) &&
88148+ (grsec_lastack_retries > 0) &&
88149+ (grsec_lastack_retries < retry_until))
88150+ retry_until = grsec_lastack_retries;
88151+#endif
88152+
88153 if (retransmits_timed_out(sk, retry_until,
88154 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
88155 /* Has it gone just too far? */
88156diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
88157index 0bf5d399..5a2dd92 100644
88158--- a/net/ipv4/udp.c
88159+++ b/net/ipv4/udp.c
88160@@ -87,6 +87,7 @@
88161 #include <linux/types.h>
88162 #include <linux/fcntl.h>
88163 #include <linux/module.h>
88164+#include <linux/security.h>
88165 #include <linux/socket.h>
88166 #include <linux/sockios.h>
88167 #include <linux/igmp.h>
88168@@ -111,6 +112,10 @@
88169 #include <trace/events/skb.h>
88170 #include "udp_impl.h"
88171
88172+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88173+extern int grsec_enable_blackhole;
88174+#endif
88175+
88176 struct udp_table udp_table __read_mostly;
88177 EXPORT_SYMBOL(udp_table);
88178
88179@@ -594,6 +599,9 @@ found:
88180 return s;
88181 }
88182
88183+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
88184+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
88185+
88186 /*
88187 * This routine is called by the ICMP module when it gets some
88188 * sort of error condition. If err < 0 then the socket should
88189@@ -799,7 +807,7 @@ send:
88190 /*
88191 * Push out all pending data as one UDP datagram. Socket is locked.
88192 */
88193-static int udp_push_pending_frames(struct sock *sk)
88194+int udp_push_pending_frames(struct sock *sk)
88195 {
88196 struct udp_sock *up = udp_sk(sk);
88197 struct inet_sock *inet = inet_sk(sk);
88198@@ -818,6 +826,7 @@ out:
88199 up->pending = 0;
88200 return err;
88201 }
88202+EXPORT_SYMBOL(udp_push_pending_frames);
88203
88204 int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
88205 size_t len)
88206@@ -889,9 +898,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
88207 dport = usin->sin_port;
88208 if (dport == 0)
88209 return -EINVAL;
88210+
88211+ err = gr_search_udp_sendmsg(sk, usin);
88212+ if (err)
88213+ return err;
88214 } else {
88215 if (sk->sk_state != TCP_ESTABLISHED)
88216 return -EDESTADDRREQ;
88217+
88218+ err = gr_search_udp_sendmsg(sk, NULL);
88219+ if (err)
88220+ return err;
88221+
88222 daddr = inet->inet_daddr;
88223 dport = inet->inet_dport;
88224 /* Open fast path for connected socket.
88225@@ -1135,7 +1153,7 @@ static unsigned int first_packet_length(struct sock *sk)
88226 IS_UDPLITE(sk));
88227 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88228 IS_UDPLITE(sk));
88229- atomic_inc(&sk->sk_drops);
88230+ atomic_inc_unchecked(&sk->sk_drops);
88231 __skb_unlink(skb, rcvq);
88232 __skb_queue_tail(&list_kill, skb);
88233 }
88234@@ -1221,6 +1239,10 @@ try_again:
88235 if (!skb)
88236 goto out;
88237
88238+ err = gr_search_udp_recvmsg(sk, skb);
88239+ if (err)
88240+ goto out_free;
88241+
88242 ulen = skb->len - sizeof(struct udphdr);
88243 copied = len;
88244 if (copied > ulen)
88245@@ -1254,7 +1276,7 @@ try_again:
88246 if (unlikely(err)) {
88247 trace_kfree_skb(skb, udp_recvmsg);
88248 if (!peeked) {
88249- atomic_inc(&sk->sk_drops);
88250+ atomic_inc_unchecked(&sk->sk_drops);
88251 UDP_INC_STATS_USER(sock_net(sk),
88252 UDP_MIB_INERRORS, is_udplite);
88253 }
88254@@ -1541,7 +1563,7 @@ csum_error:
88255 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
88256 drop:
88257 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88258- atomic_inc(&sk->sk_drops);
88259+ atomic_inc_unchecked(&sk->sk_drops);
88260 kfree_skb(skb);
88261 return -1;
88262 }
88263@@ -1560,7 +1582,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88264 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88265
88266 if (!skb1) {
88267- atomic_inc(&sk->sk_drops);
88268+ atomic_inc_unchecked(&sk->sk_drops);
88269 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88270 IS_UDPLITE(sk));
88271 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88272@@ -1729,6 +1751,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88273 goto csum_error;
88274
88275 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88276+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88277+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88278+#endif
88279 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
88280
88281 /*
88282@@ -2159,7 +2184,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
88283 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
88284 0, sock_i_ino(sp),
88285 atomic_read(&sp->sk_refcnt), sp,
88286- atomic_read(&sp->sk_drops), len);
88287+ atomic_read_unchecked(&sp->sk_drops), len);
88288 }
88289
88290 int udp4_seq_show(struct seq_file *seq, void *v)
88291diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
88292index 9a459be..086b866 100644
88293--- a/net/ipv4/xfrm4_policy.c
88294+++ b/net/ipv4/xfrm4_policy.c
88295@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
88296
88297 static int __net_init xfrm4_net_init(struct net *net)
88298 {
88299- struct ctl_table *table;
88300+ ctl_table_no_const *table = NULL;
88301 struct ctl_table_header *hdr;
88302
88303- table = xfrm4_policy_table;
88304 if (!net_eq(net, &init_net)) {
88305- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88306+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88307 if (!table)
88308 goto err_alloc;
88309
88310 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
88311- }
88312-
88313- hdr = register_net_sysctl(net, "net/ipv4", table);
88314+ hdr = register_net_sysctl(net, "net/ipv4", table);
88315+ } else
88316+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
88317 if (!hdr)
88318 goto err_reg;
88319
88320@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
88321 return 0;
88322
88323 err_reg:
88324- if (!net_eq(net, &init_net))
88325- kfree(table);
88326+ kfree(table);
88327 err_alloc:
88328 return -ENOMEM;
88329 }
88330diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
88331index 4ab4c38..1533b2d 100644
88332--- a/net/ipv6/addrconf.c
88333+++ b/net/ipv6/addrconf.c
88334@@ -621,7 +621,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
88335 idx = 0;
88336 head = &net->dev_index_head[h];
88337 rcu_read_lock();
88338- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
88339+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
88340 net->dev_base_seq;
88341 hlist_for_each_entry_rcu(dev, head, index_hlist) {
88342 if (idx < s_idx)
88343@@ -2372,7 +2372,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
88344 p.iph.ihl = 5;
88345 p.iph.protocol = IPPROTO_IPV6;
88346 p.iph.ttl = 64;
88347- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
88348+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
88349
88350 if (ops->ndo_do_ioctl) {
88351 mm_segment_t oldfs = get_fs();
88352@@ -3994,7 +3994,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
88353 s_ip_idx = ip_idx = cb->args[2];
88354
88355 rcu_read_lock();
88356- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
88357+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
88358 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
88359 idx = 0;
88360 head = &net->dev_index_head[h];
88361@@ -4579,7 +4579,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
88362 dst_free(&ifp->rt->dst);
88363 break;
88364 }
88365- atomic_inc(&net->ipv6.dev_addr_genid);
88366+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
88367 }
88368
88369 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
88370@@ -4599,7 +4599,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
88371 int *valp = ctl->data;
88372 int val = *valp;
88373 loff_t pos = *ppos;
88374- ctl_table lctl;
88375+ ctl_table_no_const lctl;
88376 int ret;
88377
88378 /*
88379@@ -4681,7 +4681,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
88380 int *valp = ctl->data;
88381 int val = *valp;
88382 loff_t pos = *ppos;
88383- ctl_table lctl;
88384+ ctl_table_no_const lctl;
88385 int ret;
88386
88387 /*
88388diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
88389index b4ff0a4..db9b764 100644
88390--- a/net/ipv6/icmp.c
88391+++ b/net/ipv6/icmp.c
88392@@ -980,7 +980,7 @@ ctl_table ipv6_icmp_table_template[] = {
88393
88394 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
88395 {
88396- struct ctl_table *table;
88397+ ctl_table_no_const *table;
88398
88399 table = kmemdup(ipv6_icmp_table_template,
88400 sizeof(ipv6_icmp_table_template),
88401diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
88402index ecd6073..58162ae 100644
88403--- a/net/ipv6/ip6_gre.c
88404+++ b/net/ipv6/ip6_gre.c
88405@@ -74,7 +74,7 @@ struct ip6gre_net {
88406 struct net_device *fb_tunnel_dev;
88407 };
88408
88409-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
88410+static struct rtnl_link_ops ip6gre_link_ops;
88411 static int ip6gre_tunnel_init(struct net_device *dev);
88412 static void ip6gre_tunnel_setup(struct net_device *dev);
88413 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
88414@@ -1283,7 +1283,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
88415 }
88416
88417
88418-static struct inet6_protocol ip6gre_protocol __read_mostly = {
88419+static struct inet6_protocol ip6gre_protocol = {
88420 .handler = ip6gre_rcv,
88421 .err_handler = ip6gre_err,
88422 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
88423@@ -1617,7 +1617,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
88424 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
88425 };
88426
88427-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88428+static struct rtnl_link_ops ip6gre_link_ops = {
88429 .kind = "ip6gre",
88430 .maxtype = IFLA_GRE_MAX,
88431 .policy = ip6gre_policy,
88432@@ -1630,7 +1630,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88433 .fill_info = ip6gre_fill_info,
88434 };
88435
88436-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
88437+static struct rtnl_link_ops ip6gre_tap_ops = {
88438 .kind = "ip6gretap",
88439 .maxtype = IFLA_GRE_MAX,
88440 .policy = ip6gre_policy,
88441diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
88442index d5d20cd..6e3ddf8 100644
88443--- a/net/ipv6/ip6_output.c
88444+++ b/net/ipv6/ip6_output.c
88445@@ -1098,11 +1098,12 @@ static inline struct ipv6_rt_hdr *ip6_rthdr_dup(struct ipv6_rt_hdr *src,
88446 return src ? kmemdup(src, (src->hdrlen + 1) * 8, gfp) : NULL;
88447 }
88448
88449-static void ip6_append_data_mtu(int *mtu,
88450+static void ip6_append_data_mtu(unsigned int *mtu,
88451 int *maxfraglen,
88452 unsigned int fragheaderlen,
88453 struct sk_buff *skb,
88454- struct rt6_info *rt)
88455+ struct rt6_info *rt,
88456+ bool pmtuprobe)
88457 {
88458 if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
88459 if (skb == NULL) {
88460@@ -1114,7 +1115,9 @@ static void ip6_append_data_mtu(int *mtu,
88461 * this fragment is not first, the headers
88462 * space is regarded as data space.
88463 */
88464- *mtu = dst_mtu(rt->dst.path);
88465+ *mtu = min(*mtu, pmtuprobe ?
88466+ rt->dst.dev->mtu :
88467+ dst_mtu(rt->dst.path));
88468 }
88469 *maxfraglen = ((*mtu - fragheaderlen) & ~7)
88470 + fragheaderlen - sizeof(struct frag_hdr);
88471@@ -1131,11 +1134,10 @@ int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
88472 struct ipv6_pinfo *np = inet6_sk(sk);
88473 struct inet_cork *cork;
88474 struct sk_buff *skb, *skb_prev = NULL;
88475- unsigned int maxfraglen, fragheaderlen;
88476+ unsigned int maxfraglen, fragheaderlen, mtu;
88477 int exthdrlen;
88478 int dst_exthdrlen;
88479 int hh_len;
88480- int mtu;
88481 int copy;
88482 int err;
88483 int offset = 0;
88484@@ -1292,7 +1294,9 @@ alloc_new_skb:
88485 /* update mtu and maxfraglen if necessary */
88486 if (skb == NULL || skb_prev == NULL)
88487 ip6_append_data_mtu(&mtu, &maxfraglen,
88488- fragheaderlen, skb, rt);
88489+ fragheaderlen, skb, rt,
88490+ np->pmtudisc ==
88491+ IPV6_PMTUDISC_PROBE);
88492
88493 skb_prev = skb;
88494
88495diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
88496index 1e55866..b398dab 100644
88497--- a/net/ipv6/ip6_tunnel.c
88498+++ b/net/ipv6/ip6_tunnel.c
88499@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
88500
88501 static int ip6_tnl_dev_init(struct net_device *dev);
88502 static void ip6_tnl_dev_setup(struct net_device *dev);
88503-static struct rtnl_link_ops ip6_link_ops __read_mostly;
88504+static struct rtnl_link_ops ip6_link_ops;
88505
88506 static int ip6_tnl_net_id __read_mostly;
88507 struct ip6_tnl_net {
88508@@ -1672,7 +1672,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
88509 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
88510 };
88511
88512-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
88513+static struct rtnl_link_ops ip6_link_ops = {
88514 .kind = "ip6tnl",
88515 .maxtype = IFLA_IPTUN_MAX,
88516 .policy = ip6_tnl_policy,
88517diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
88518index d1e2e8e..51c19ae 100644
88519--- a/net/ipv6/ipv6_sockglue.c
88520+++ b/net/ipv6/ipv6_sockglue.c
88521@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
88522 if (sk->sk_type != SOCK_STREAM)
88523 return -ENOPROTOOPT;
88524
88525- msg.msg_control = optval;
88526+ msg.msg_control = (void __force_kernel *)optval;
88527 msg.msg_controllen = len;
88528 msg.msg_flags = flags;
88529
88530diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
88531index 44400c2..8e11f52 100644
88532--- a/net/ipv6/netfilter/ip6_tables.c
88533+++ b/net/ipv6/netfilter/ip6_tables.c
88534@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
88535 #endif
88536
88537 static int get_info(struct net *net, void __user *user,
88538- const int *len, int compat)
88539+ int len, int compat)
88540 {
88541 char name[XT_TABLE_MAXNAMELEN];
88542 struct xt_table *t;
88543 int ret;
88544
88545- if (*len != sizeof(struct ip6t_getinfo)) {
88546- duprintf("length %u != %zu\n", *len,
88547+ if (len != sizeof(struct ip6t_getinfo)) {
88548+ duprintf("length %u != %zu\n", len,
88549 sizeof(struct ip6t_getinfo));
88550 return -EINVAL;
88551 }
88552@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
88553 info.size = private->size;
88554 strcpy(info.name, name);
88555
88556- if (copy_to_user(user, &info, *len) != 0)
88557+ if (copy_to_user(user, &info, len) != 0)
88558 ret = -EFAULT;
88559 else
88560 ret = 0;
88561@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88562
88563 switch (cmd) {
88564 case IP6T_SO_GET_INFO:
88565- ret = get_info(sock_net(sk), user, len, 1);
88566+ ret = get_info(sock_net(sk), user, *len, 1);
88567 break;
88568 case IP6T_SO_GET_ENTRIES:
88569 ret = compat_get_entries(sock_net(sk), user, len);
88570@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88571
88572 switch (cmd) {
88573 case IP6T_SO_GET_INFO:
88574- ret = get_info(sock_net(sk), user, len, 0);
88575+ ret = get_info(sock_net(sk), user, *len, 0);
88576 break;
88577
88578 case IP6T_SO_GET_ENTRIES:
88579diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
88580index dffdc1a..ccc6678 100644
88581--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
88582+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
88583@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
88584
88585 static int nf_ct_frag6_sysctl_register(struct net *net)
88586 {
88587- struct ctl_table *table;
88588+ ctl_table_no_const *table = NULL;
88589 struct ctl_table_header *hdr;
88590
88591- table = nf_ct_frag6_sysctl_table;
88592 if (!net_eq(net, &init_net)) {
88593- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88594+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88595 GFP_KERNEL);
88596 if (table == NULL)
88597 goto err_alloc;
88598@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88599 table[0].data = &net->nf_frag.frags.timeout;
88600 table[1].data = &net->nf_frag.frags.low_thresh;
88601 table[2].data = &net->nf_frag.frags.high_thresh;
88602- }
88603-
88604- hdr = register_net_sysctl(net, "net/netfilter", table);
88605+ hdr = register_net_sysctl(net, "net/netfilter", table);
88606+ } else
88607+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88608 if (hdr == NULL)
88609 goto err_reg;
88610
88611@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88612 return 0;
88613
88614 err_reg:
88615- if (!net_eq(net, &init_net))
88616- kfree(table);
88617+ kfree(table);
88618 err_alloc:
88619 return -ENOMEM;
88620 }
88621diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88622index eedff8c..6e13a47 100644
88623--- a/net/ipv6/raw.c
88624+++ b/net/ipv6/raw.c
88625@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88626 {
88627 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88628 skb_checksum_complete(skb)) {
88629- atomic_inc(&sk->sk_drops);
88630+ atomic_inc_unchecked(&sk->sk_drops);
88631 kfree_skb(skb);
88632 return NET_RX_DROP;
88633 }
88634@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88635 struct raw6_sock *rp = raw6_sk(sk);
88636
88637 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88638- atomic_inc(&sk->sk_drops);
88639+ atomic_inc_unchecked(&sk->sk_drops);
88640 kfree_skb(skb);
88641 return NET_RX_DROP;
88642 }
88643@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88644
88645 if (inet->hdrincl) {
88646 if (skb_checksum_complete(skb)) {
88647- atomic_inc(&sk->sk_drops);
88648+ atomic_inc_unchecked(&sk->sk_drops);
88649 kfree_skb(skb);
88650 return NET_RX_DROP;
88651 }
88652@@ -602,7 +602,7 @@ out:
88653 return err;
88654 }
88655
88656-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88657+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88658 struct flowi6 *fl6, struct dst_entry **dstp,
88659 unsigned int flags)
88660 {
88661@@ -914,12 +914,15 @@ do_confirm:
88662 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88663 char __user *optval, int optlen)
88664 {
88665+ struct icmp6_filter filter;
88666+
88667 switch (optname) {
88668 case ICMPV6_FILTER:
88669 if (optlen > sizeof(struct icmp6_filter))
88670 optlen = sizeof(struct icmp6_filter);
88671- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88672+ if (copy_from_user(&filter, optval, optlen))
88673 return -EFAULT;
88674+ raw6_sk(sk)->filter = filter;
88675 return 0;
88676 default:
88677 return -ENOPROTOOPT;
88678@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88679 char __user *optval, int __user *optlen)
88680 {
88681 int len;
88682+ struct icmp6_filter filter;
88683
88684 switch (optname) {
88685 case ICMPV6_FILTER:
88686@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88687 len = sizeof(struct icmp6_filter);
88688 if (put_user(len, optlen))
88689 return -EFAULT;
88690- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88691+ filter = raw6_sk(sk)->filter;
88692+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88693 return -EFAULT;
88694 return 0;
88695 default:
88696@@ -1251,7 +1256,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88697 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88698 0,
88699 sock_i_ino(sp),
88700- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88701+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88702 }
88703
88704 static int raw6_seq_show(struct seq_file *seq, void *v)
88705diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88706index 790d9f4..68ae078 100644
88707--- a/net/ipv6/reassembly.c
88708+++ b/net/ipv6/reassembly.c
88709@@ -621,12 +621,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88710
88711 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88712 {
88713- struct ctl_table *table;
88714+ ctl_table_no_const *table = NULL;
88715 struct ctl_table_header *hdr;
88716
88717- table = ip6_frags_ns_ctl_table;
88718 if (!net_eq(net, &init_net)) {
88719- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88720+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88721 if (table == NULL)
88722 goto err_alloc;
88723
88724@@ -637,9 +636,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88725 /* Don't export sysctls to unprivileged users */
88726 if (net->user_ns != &init_user_ns)
88727 table[0].procname = NULL;
88728- }
88729+ hdr = register_net_sysctl(net, "net/ipv6", table);
88730+ } else
88731+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88732
88733- hdr = register_net_sysctl(net, "net/ipv6", table);
88734 if (hdr == NULL)
88735 goto err_reg;
88736
88737@@ -647,8 +647,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88738 return 0;
88739
88740 err_reg:
88741- if (!net_eq(net, &init_net))
88742- kfree(table);
88743+ kfree(table);
88744 err_alloc:
88745 return -ENOMEM;
88746 }
88747diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88748index ad0aa6b..beaef03 100644
88749--- a/net/ipv6/route.c
88750+++ b/net/ipv6/route.c
88751@@ -2881,7 +2881,7 @@ ctl_table ipv6_route_table_template[] = {
88752
88753 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88754 {
88755- struct ctl_table *table;
88756+ ctl_table_no_const *table;
88757
88758 table = kmemdup(ipv6_route_table_template,
88759 sizeof(ipv6_route_table_template),
88760diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88761index 3353634..3d5084a 100644
88762--- a/net/ipv6/sit.c
88763+++ b/net/ipv6/sit.c
88764@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
88765 static void ipip6_dev_free(struct net_device *dev);
88766 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
88767 __be32 *v4dst);
88768-static struct rtnl_link_ops sit_link_ops __read_mostly;
88769+static struct rtnl_link_ops sit_link_ops;
88770
88771 static int sit_net_id __read_mostly;
88772 struct sit_net {
88773@@ -1453,7 +1453,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88774 #endif
88775 };
88776
88777-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88778+static struct rtnl_link_ops sit_link_ops = {
88779 .kind = "sit",
88780 .maxtype = IFLA_IPTUN_MAX,
88781 .policy = ipip6_policy,
88782diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88783index e85c48b..b8268d3 100644
88784--- a/net/ipv6/sysctl_net_ipv6.c
88785+++ b/net/ipv6/sysctl_net_ipv6.c
88786@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88787
88788 static int __net_init ipv6_sysctl_net_init(struct net *net)
88789 {
88790- struct ctl_table *ipv6_table;
88791+ ctl_table_no_const *ipv6_table;
88792 struct ctl_table *ipv6_route_table;
88793 struct ctl_table *ipv6_icmp_table;
88794 int err;
88795diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88796index 0a17ed9..2526cc3 100644
88797--- a/net/ipv6/tcp_ipv6.c
88798+++ b/net/ipv6/tcp_ipv6.c
88799@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88800 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88801 }
88802
88803+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88804+extern int grsec_enable_blackhole;
88805+#endif
88806+
88807 static void tcp_v6_hash(struct sock *sk)
88808 {
88809 if (sk->sk_state != TCP_CLOSE) {
88810@@ -1398,6 +1402,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88811 return 0;
88812
88813 reset:
88814+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88815+ if (!grsec_enable_blackhole)
88816+#endif
88817 tcp_v6_send_reset(sk, skb);
88818 discard:
88819 if (opt_skb)
88820@@ -1480,12 +1487,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88821 TCP_SKB_CB(skb)->sacked = 0;
88822
88823 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88824- if (!sk)
88825+ if (!sk) {
88826+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88827+ ret = 1;
88828+#endif
88829 goto no_tcp_socket;
88830+ }
88831
88832 process:
88833- if (sk->sk_state == TCP_TIME_WAIT)
88834+ if (sk->sk_state == TCP_TIME_WAIT) {
88835+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88836+ ret = 2;
88837+#endif
88838 goto do_time_wait;
88839+ }
88840
88841 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88842 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88843@@ -1536,6 +1551,10 @@ csum_error:
88844 bad_packet:
88845 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88846 } else {
88847+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88848+ if (!grsec_enable_blackhole || (ret == 1 &&
88849+ (skb->dev->flags & IFF_LOOPBACK)))
88850+#endif
88851 tcp_v6_send_reset(NULL, skb);
88852 }
88853
88854diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88855index 42923b1..d09c290 100644
88856--- a/net/ipv6/udp.c
88857+++ b/net/ipv6/udp.c
88858@@ -52,6 +52,10 @@
88859 #include <trace/events/skb.h>
88860 #include "udp_impl.h"
88861
88862+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88863+extern int grsec_enable_blackhole;
88864+#endif
88865+
88866 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88867 {
88868 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88869@@ -419,7 +423,7 @@ try_again:
88870 if (unlikely(err)) {
88871 trace_kfree_skb(skb, udpv6_recvmsg);
88872 if (!peeked) {
88873- atomic_inc(&sk->sk_drops);
88874+ atomic_inc_unchecked(&sk->sk_drops);
88875 if (is_udp4)
88876 UDP_INC_STATS_USER(sock_net(sk),
88877 UDP_MIB_INERRORS,
88878@@ -665,7 +669,7 @@ csum_error:
88879 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
88880 drop:
88881 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88882- atomic_inc(&sk->sk_drops);
88883+ atomic_inc_unchecked(&sk->sk_drops);
88884 kfree_skb(skb);
88885 return -1;
88886 }
88887@@ -723,7 +727,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88888 if (likely(skb1 == NULL))
88889 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88890 if (!skb1) {
88891- atomic_inc(&sk->sk_drops);
88892+ atomic_inc_unchecked(&sk->sk_drops);
88893 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88894 IS_UDPLITE(sk));
88895 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88896@@ -860,6 +864,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88897 goto csum_error;
88898
88899 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88900+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88901+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88902+#endif
88903 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88904
88905 kfree_skb(skb);
88906@@ -955,11 +962,16 @@ static int udp_v6_push_pending_frames(struct sock *sk)
88907 struct udphdr *uh;
88908 struct udp_sock *up = udp_sk(sk);
88909 struct inet_sock *inet = inet_sk(sk);
88910- struct flowi6 *fl6 = &inet->cork.fl.u.ip6;
88911+ struct flowi6 *fl6;
88912 int err = 0;
88913 int is_udplite = IS_UDPLITE(sk);
88914 __wsum csum = 0;
88915
88916+ if (up->pending == AF_INET)
88917+ return udp_push_pending_frames(sk);
88918+
88919+ fl6 = &inet->cork.fl.u.ip6;
88920+
88921 /* Grab the skbuff where UDP header space exists. */
88922 if ((skb = skb_peek(&sk->sk_write_queue)) == NULL)
88923 goto out;
88924@@ -1387,7 +1399,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88925 0,
88926 sock_i_ino(sp),
88927 atomic_read(&sp->sk_refcnt), sp,
88928- atomic_read(&sp->sk_drops));
88929+ atomic_read_unchecked(&sp->sk_drops));
88930 }
88931
88932 int udp6_seq_show(struct seq_file *seq, void *v)
88933diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
88934index 23ed03d..465a71d 100644
88935--- a/net/ipv6/xfrm6_policy.c
88936+++ b/net/ipv6/xfrm6_policy.c
88937@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
88938
88939 static int __net_init xfrm6_net_init(struct net *net)
88940 {
88941- struct ctl_table *table;
88942+ ctl_table_no_const *table = NULL;
88943 struct ctl_table_header *hdr;
88944
88945- table = xfrm6_policy_table;
88946 if (!net_eq(net, &init_net)) {
88947- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88948+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88949 if (!table)
88950 goto err_alloc;
88951
88952 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
88953- }
88954+ hdr = register_net_sysctl(net, "net/ipv6", table);
88955+ } else
88956+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
88957
88958- hdr = register_net_sysctl(net, "net/ipv6", table);
88959 if (!hdr)
88960 goto err_reg;
88961
88962@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
88963 return 0;
88964
88965 err_reg:
88966- if (!net_eq(net, &init_net))
88967- kfree(table);
88968+ kfree(table);
88969 err_alloc:
88970 return -ENOMEM;
88971 }
88972diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88973index 41ac7938..75e3bb1 100644
88974--- a/net/irda/ircomm/ircomm_tty.c
88975+++ b/net/irda/ircomm/ircomm_tty.c
88976@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88977 add_wait_queue(&port->open_wait, &wait);
88978
88979 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88980- __FILE__, __LINE__, tty->driver->name, port->count);
88981+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88982
88983 spin_lock_irqsave(&port->lock, flags);
88984 if (!tty_hung_up_p(filp))
88985- port->count--;
88986+ atomic_dec(&port->count);
88987 port->blocked_open++;
88988 spin_unlock_irqrestore(&port->lock, flags);
88989
88990@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88991 }
88992
88993 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88994- __FILE__, __LINE__, tty->driver->name, port->count);
88995+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88996
88997 schedule();
88998 }
88999@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
89000
89001 spin_lock_irqsave(&port->lock, flags);
89002 if (!tty_hung_up_p(filp))
89003- port->count++;
89004+ atomic_inc(&port->count);
89005 port->blocked_open--;
89006 spin_unlock_irqrestore(&port->lock, flags);
89007
89008 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
89009- __FILE__, __LINE__, tty->driver->name, port->count);
89010+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
89011
89012 if (!retval)
89013 port->flags |= ASYNC_NORMAL_ACTIVE;
89014@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
89015
89016 /* ++ is not atomic, so this should be protected - Jean II */
89017 spin_lock_irqsave(&self->port.lock, flags);
89018- self->port.count++;
89019+ atomic_inc(&self->port.count);
89020 spin_unlock_irqrestore(&self->port.lock, flags);
89021 tty_port_tty_set(&self->port, tty);
89022
89023 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
89024- self->line, self->port.count);
89025+ self->line, atomic_read(&self->port.count));
89026
89027 /* Not really used by us, but lets do it anyway */
89028 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
89029@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
89030 tty_kref_put(port->tty);
89031 }
89032 port->tty = NULL;
89033- port->count = 0;
89034+ atomic_set(&port->count, 0);
89035 spin_unlock_irqrestore(&port->lock, flags);
89036
89037 wake_up_interruptible(&port->open_wait);
89038@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
89039 seq_putc(m, '\n');
89040
89041 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
89042- seq_printf(m, "Open count: %d\n", self->port.count);
89043+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
89044 seq_printf(m, "Max data size: %d\n", self->max_data_size);
89045 seq_printf(m, "Max header size: %d\n", self->max_header_size);
89046
89047diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
89048index ae69165..c8b82d8 100644
89049--- a/net/iucv/af_iucv.c
89050+++ b/net/iucv/af_iucv.c
89051@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
89052
89053 write_lock_bh(&iucv_sk_list.lock);
89054
89055- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
89056+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
89057 while (__iucv_get_sock_by_name(name)) {
89058 sprintf(name, "%08x",
89059- atomic_inc_return(&iucv_sk_list.autobind_name));
89060+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
89061 }
89062
89063 write_unlock_bh(&iucv_sk_list.lock);
89064diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
89065index 4fe76ff..426a904 100644
89066--- a/net/iucv/iucv.c
89067+++ b/net/iucv/iucv.c
89068@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
89069 return NOTIFY_OK;
89070 }
89071
89072-static struct notifier_block __refdata iucv_cpu_notifier = {
89073+static struct notifier_block iucv_cpu_notifier = {
89074 .notifier_call = iucv_cpu_notify,
89075 };
89076
89077diff --git a/net/key/af_key.c b/net/key/af_key.c
89078index 9da8620..97070ad 100644
89079--- a/net/key/af_key.c
89080+++ b/net/key/af_key.c
89081@@ -3047,10 +3047,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
89082 static u32 get_acqseq(void)
89083 {
89084 u32 res;
89085- static atomic_t acqseq;
89086+ static atomic_unchecked_t acqseq;
89087
89088 do {
89089- res = atomic_inc_return(&acqseq);
89090+ res = atomic_inc_return_unchecked(&acqseq);
89091 } while (!res);
89092 return res;
89093 }
89094diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
89095index 8dec687..5ebee2d 100644
89096--- a/net/l2tp/l2tp_ppp.c
89097+++ b/net/l2tp/l2tp_ppp.c
89098@@ -1793,7 +1793,8 @@ static const struct proto_ops pppol2tp_ops = {
89099
89100 static const struct pppox_proto pppol2tp_proto = {
89101 .create = pppol2tp_create,
89102- .ioctl = pppol2tp_ioctl
89103+ .ioctl = pppol2tp_ioctl,
89104+ .owner = THIS_MODULE,
89105 };
89106
89107 #ifdef CONFIG_L2TP_V3
89108diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
89109index 4fdb306e..920086a 100644
89110--- a/net/mac80211/cfg.c
89111+++ b/net/mac80211/cfg.c
89112@@ -804,7 +804,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
89113 ret = ieee80211_vif_use_channel(sdata, chandef,
89114 IEEE80211_CHANCTX_EXCLUSIVE);
89115 }
89116- } else if (local->open_count == local->monitors) {
89117+ } else if (local_read(&local->open_count) == local->monitors) {
89118 local->_oper_chandef = *chandef;
89119 ieee80211_hw_config(local, 0);
89120 }
89121@@ -2920,7 +2920,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
89122 else
89123 local->probe_req_reg--;
89124
89125- if (!local->open_count)
89126+ if (!local_read(&local->open_count))
89127 break;
89128
89129 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
89130@@ -3383,8 +3383,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
89131 if (chanctx_conf) {
89132 *chandef = chanctx_conf->def;
89133 ret = 0;
89134- } else if (local->open_count > 0 &&
89135- local->open_count == local->monitors &&
89136+ } else if (local_read(&local->open_count) > 0 &&
89137+ local_read(&local->open_count) == local->monitors &&
89138 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
89139 if (local->use_chanctx)
89140 *chandef = local->monitor_chandef;
89141diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
89142index 9ca8e32..48e4a9b 100644
89143--- a/net/mac80211/ieee80211_i.h
89144+++ b/net/mac80211/ieee80211_i.h
89145@@ -28,6 +28,7 @@
89146 #include <net/ieee80211_radiotap.h>
89147 #include <net/cfg80211.h>
89148 #include <net/mac80211.h>
89149+#include <asm/local.h>
89150 #include "key.h"
89151 #include "sta_info.h"
89152 #include "debug.h"
89153@@ -891,7 +892,7 @@ struct ieee80211_local {
89154 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
89155 spinlock_t queue_stop_reason_lock;
89156
89157- int open_count;
89158+ local_t open_count;
89159 int monitors, cooked_mntrs;
89160 /* number of interfaces with corresponding FIF_ flags */
89161 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
89162diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
89163index 98d20c0..586675b 100644
89164--- a/net/mac80211/iface.c
89165+++ b/net/mac80211/iface.c
89166@@ -502,7 +502,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89167 break;
89168 }
89169
89170- if (local->open_count == 0) {
89171+ if (local_read(&local->open_count) == 0) {
89172 res = drv_start(local);
89173 if (res)
89174 goto err_del_bss;
89175@@ -545,7 +545,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89176 break;
89177 }
89178
89179- if (local->monitors == 0 && local->open_count == 0) {
89180+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
89181 res = ieee80211_add_virtual_monitor(local);
89182 if (res)
89183 goto err_stop;
89184@@ -653,7 +653,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89185 atomic_inc(&local->iff_promiscs);
89186
89187 if (coming_up)
89188- local->open_count++;
89189+ local_inc(&local->open_count);
89190
89191 if (hw_reconf_flags)
89192 ieee80211_hw_config(local, hw_reconf_flags);
89193@@ -691,7 +691,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
89194 err_del_interface:
89195 drv_remove_interface(local, sdata);
89196 err_stop:
89197- if (!local->open_count)
89198+ if (!local_read(&local->open_count))
89199 drv_stop(local);
89200 err_del_bss:
89201 sdata->bss = NULL;
89202@@ -828,7 +828,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89203 }
89204
89205 if (going_down)
89206- local->open_count--;
89207+ local_dec(&local->open_count);
89208
89209 switch (sdata->vif.type) {
89210 case NL80211_IFTYPE_AP_VLAN:
89211@@ -895,7 +895,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89212 }
89213 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
89214
89215- if (local->open_count == 0)
89216+ if (local_read(&local->open_count) == 0)
89217 ieee80211_clear_tx_pending(local);
89218
89219 /*
89220@@ -931,7 +931,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89221
89222 ieee80211_recalc_ps(local, -1);
89223
89224- if (local->open_count == 0) {
89225+ if (local_read(&local->open_count) == 0) {
89226 ieee80211_stop_device(local);
89227
89228 /* no reconfiguring after stop! */
89229@@ -942,7 +942,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
89230 ieee80211_configure_filter(local);
89231 ieee80211_hw_config(local, hw_reconf_flags);
89232
89233- if (local->monitors == local->open_count)
89234+ if (local->monitors == local_read(&local->open_count))
89235 ieee80211_add_virtual_monitor(local);
89236 }
89237
89238diff --git a/net/mac80211/main.c b/net/mac80211/main.c
89239index 8a7bfc4..4407cd0 100644
89240--- a/net/mac80211/main.c
89241+++ b/net/mac80211/main.c
89242@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
89243 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
89244 IEEE80211_CONF_CHANGE_POWER);
89245
89246- if (changed && local->open_count) {
89247+ if (changed && local_read(&local->open_count)) {
89248 ret = drv_config(local, changed);
89249 /*
89250 * Goal:
89251diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
89252index 7fc5d0d..07ea536 100644
89253--- a/net/mac80211/pm.c
89254+++ b/net/mac80211/pm.c
89255@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89256 struct ieee80211_sub_if_data *sdata;
89257 struct sta_info *sta;
89258
89259- if (!local->open_count)
89260+ if (!local_read(&local->open_count))
89261 goto suspend;
89262
89263 ieee80211_scan_cancel(local);
89264@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89265 cancel_work_sync(&local->dynamic_ps_enable_work);
89266 del_timer_sync(&local->dynamic_ps_timer);
89267
89268- local->wowlan = wowlan && local->open_count;
89269+ local->wowlan = wowlan && local_read(&local->open_count);
89270 if (local->wowlan) {
89271 int err = drv_suspend(local, wowlan);
89272 if (err < 0) {
89273@@ -113,7 +113,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
89274 WARN_ON(!list_empty(&local->chanctx_list));
89275
89276 /* stop hardware - this must stop RX */
89277- if (local->open_count)
89278+ if (local_read(&local->open_count))
89279 ieee80211_stop_device(local);
89280
89281 suspend:
89282diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
89283index a02bef3..f2f38dd 100644
89284--- a/net/mac80211/rate.c
89285+++ b/net/mac80211/rate.c
89286@@ -712,7 +712,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
89287
89288 ASSERT_RTNL();
89289
89290- if (local->open_count)
89291+ if (local_read(&local->open_count))
89292 return -EBUSY;
89293
89294 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
89295diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
89296index c97a065..ff61928 100644
89297--- a/net/mac80211/rc80211_pid_debugfs.c
89298+++ b/net/mac80211/rc80211_pid_debugfs.c
89299@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
89300
89301 spin_unlock_irqrestore(&events->lock, status);
89302
89303- if (copy_to_user(buf, pb, p))
89304+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
89305 return -EFAULT;
89306
89307 return p;
89308diff --git a/net/mac80211/util.c b/net/mac80211/util.c
89309index 72e6292..e6319eb 100644
89310--- a/net/mac80211/util.c
89311+++ b/net/mac80211/util.c
89312@@ -1472,7 +1472,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89313 }
89314 #endif
89315 /* everything else happens only if HW was up & running */
89316- if (!local->open_count)
89317+ if (!local_read(&local->open_count))
89318 goto wake_up;
89319
89320 /*
89321@@ -1696,7 +1696,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89322 local->in_reconfig = false;
89323 barrier();
89324
89325- if (local->monitors == local->open_count && local->monitors > 0)
89326+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
89327 ieee80211_add_virtual_monitor(local);
89328
89329 /*
89330diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
89331index 56d22ca..87c778f 100644
89332--- a/net/netfilter/Kconfig
89333+++ b/net/netfilter/Kconfig
89334@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
89335
89336 To compile it as a module, choose M here. If unsure, say N.
89337
89338+config NETFILTER_XT_MATCH_GRADM
89339+ tristate '"gradm" match support'
89340+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
89341+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
89342+ ---help---
89343+ The gradm match allows to match on grsecurity RBAC being enabled.
89344+ It is useful when iptables rules are applied early on bootup to
89345+ prevent connections to the machine (except from a trusted host)
89346+ while the RBAC system is disabled.
89347+
89348 config NETFILTER_XT_MATCH_HASHLIMIT
89349 tristate '"hashlimit" match support'
89350 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
89351diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
89352index a1abf87..dbcb7ee 100644
89353--- a/net/netfilter/Makefile
89354+++ b/net/netfilter/Makefile
89355@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
89356 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
89357 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
89358 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
89359+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
89360 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
89361 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
89362 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
89363diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
89364index f771390..145b765 100644
89365--- a/net/netfilter/ipset/ip_set_core.c
89366+++ b/net/netfilter/ipset/ip_set_core.c
89367@@ -1820,7 +1820,7 @@ done:
89368 return ret;
89369 }
89370
89371-static struct nf_sockopt_ops so_set __read_mostly = {
89372+static struct nf_sockopt_ops so_set = {
89373 .pf = PF_INET,
89374 .get_optmin = SO_IP_SET,
89375 .get_optmax = SO_IP_SET + 1,
89376diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
89377index a083bda..da661c3 100644
89378--- a/net/netfilter/ipvs/ip_vs_conn.c
89379+++ b/net/netfilter/ipvs/ip_vs_conn.c
89380@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
89381 /* Increase the refcnt counter of the dest */
89382 ip_vs_dest_hold(dest);
89383
89384- conn_flags = atomic_read(&dest->conn_flags);
89385+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
89386 if (cp->protocol != IPPROTO_UDP)
89387 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
89388 flags = cp->flags;
89389@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
89390
89391 cp->control = NULL;
89392 atomic_set(&cp->n_control, 0);
89393- atomic_set(&cp->in_pkts, 0);
89394+ atomic_set_unchecked(&cp->in_pkts, 0);
89395
89396 cp->packet_xmit = NULL;
89397 cp->app = NULL;
89398@@ -1190,7 +1190,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
89399
89400 /* Don't drop the entry if its number of incoming packets is not
89401 located in [0, 8] */
89402- i = atomic_read(&cp->in_pkts);
89403+ i = atomic_read_unchecked(&cp->in_pkts);
89404 if (i > 8 || i < 0) return 0;
89405
89406 if (!todrop_rate[i]) return 0;
89407diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
89408index 23b8eb5..48a8959 100644
89409--- a/net/netfilter/ipvs/ip_vs_core.c
89410+++ b/net/netfilter/ipvs/ip_vs_core.c
89411@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
89412 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
89413 /* do not touch skb anymore */
89414
89415- atomic_inc(&cp->in_pkts);
89416+ atomic_inc_unchecked(&cp->in_pkts);
89417 ip_vs_conn_put(cp);
89418 return ret;
89419 }
89420@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
89421 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
89422 pkts = sysctl_sync_threshold(ipvs);
89423 else
89424- pkts = atomic_add_return(1, &cp->in_pkts);
89425+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89426
89427 if (ipvs->sync_state & IP_VS_STATE_MASTER)
89428 ip_vs_sync_conn(net, cp, pkts);
89429diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
89430index 9e6c2a0..28552e2 100644
89431--- a/net/netfilter/ipvs/ip_vs_ctl.c
89432+++ b/net/netfilter/ipvs/ip_vs_ctl.c
89433@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
89434 */
89435 ip_vs_rs_hash(ipvs, dest);
89436 }
89437- atomic_set(&dest->conn_flags, conn_flags);
89438+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
89439
89440 /* bind the service */
89441 if (!dest->svc) {
89442@@ -1657,7 +1657,7 @@ proc_do_sync_ports(ctl_table *table, int write,
89443 * align with netns init in ip_vs_control_net_init()
89444 */
89445
89446-static struct ctl_table vs_vars[] = {
89447+static ctl_table_no_const vs_vars[] __read_only = {
89448 {
89449 .procname = "amemthresh",
89450 .maxlen = sizeof(int),
89451@@ -2060,7 +2060,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89452 " %-7s %-6d %-10d %-10d\n",
89453 &dest->addr.in6,
89454 ntohs(dest->port),
89455- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89456+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89457 atomic_read(&dest->weight),
89458 atomic_read(&dest->activeconns),
89459 atomic_read(&dest->inactconns));
89460@@ -2071,7 +2071,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89461 "%-7s %-6d %-10d %-10d\n",
89462 ntohl(dest->addr.ip),
89463 ntohs(dest->port),
89464- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89465+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89466 atomic_read(&dest->weight),
89467 atomic_read(&dest->activeconns),
89468 atomic_read(&dest->inactconns));
89469@@ -2549,7 +2549,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
89470
89471 entry.addr = dest->addr.ip;
89472 entry.port = dest->port;
89473- entry.conn_flags = atomic_read(&dest->conn_flags);
89474+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
89475 entry.weight = atomic_read(&dest->weight);
89476 entry.u_threshold = dest->u_threshold;
89477 entry.l_threshold = dest->l_threshold;
89478@@ -3092,7 +3092,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
89479 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
89480 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
89481 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
89482- (atomic_read(&dest->conn_flags) &
89483+ (atomic_read_unchecked(&dest->conn_flags) &
89484 IP_VS_CONN_F_FWD_MASK)) ||
89485 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
89486 atomic_read(&dest->weight)) ||
89487@@ -3682,7 +3682,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
89488 {
89489 int idx;
89490 struct netns_ipvs *ipvs = net_ipvs(net);
89491- struct ctl_table *tbl;
89492+ ctl_table_no_const *tbl;
89493
89494 atomic_set(&ipvs->dropentry, 0);
89495 spin_lock_init(&ipvs->dropentry_lock);
89496diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
89497index 5ea26bd..c9bc65f 100644
89498--- a/net/netfilter/ipvs/ip_vs_lblc.c
89499+++ b/net/netfilter/ipvs/ip_vs_lblc.c
89500@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
89501 * IPVS LBLC sysctl table
89502 */
89503 #ifdef CONFIG_SYSCTL
89504-static ctl_table vs_vars_table[] = {
89505+static ctl_table_no_const vs_vars_table[] __read_only = {
89506 {
89507 .procname = "lblc_expiration",
89508 .data = NULL,
89509diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
89510index 50123c2..067c773 100644
89511--- a/net/netfilter/ipvs/ip_vs_lblcr.c
89512+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
89513@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
89514 * IPVS LBLCR sysctl table
89515 */
89516
89517-static ctl_table vs_vars_table[] = {
89518+static ctl_table_no_const vs_vars_table[] __read_only = {
89519 {
89520 .procname = "lblcr_expiration",
89521 .data = NULL,
89522diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
89523index f6046d9..4f10cfd 100644
89524--- a/net/netfilter/ipvs/ip_vs_sync.c
89525+++ b/net/netfilter/ipvs/ip_vs_sync.c
89526@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
89527 cp = cp->control;
89528 if (cp) {
89529 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89530- pkts = atomic_add_return(1, &cp->in_pkts);
89531+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89532 else
89533 pkts = sysctl_sync_threshold(ipvs);
89534 ip_vs_sync_conn(net, cp->control, pkts);
89535@@ -758,7 +758,7 @@ control:
89536 if (!cp)
89537 return;
89538 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89539- pkts = atomic_add_return(1, &cp->in_pkts);
89540+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89541 else
89542 pkts = sysctl_sync_threshold(ipvs);
89543 goto sloop;
89544@@ -882,7 +882,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
89545
89546 if (opt)
89547 memcpy(&cp->in_seq, opt, sizeof(*opt));
89548- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89549+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89550 cp->state = state;
89551 cp->old_state = cp->state;
89552 /*
89553diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
89554index b75ff64..0c51bbe 100644
89555--- a/net/netfilter/ipvs/ip_vs_xmit.c
89556+++ b/net/netfilter/ipvs/ip_vs_xmit.c
89557@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
89558 else
89559 rc = NF_ACCEPT;
89560 /* do not touch skb anymore */
89561- atomic_inc(&cp->in_pkts);
89562+ atomic_inc_unchecked(&cp->in_pkts);
89563 goto out;
89564 }
89565
89566@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
89567 else
89568 rc = NF_ACCEPT;
89569 /* do not touch skb anymore */
89570- atomic_inc(&cp->in_pkts);
89571+ atomic_inc_unchecked(&cp->in_pkts);
89572 goto out;
89573 }
89574
89575diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
89576index 2d3030a..7ba1c0a 100644
89577--- a/net/netfilter/nf_conntrack_acct.c
89578+++ b/net/netfilter/nf_conntrack_acct.c
89579@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
89580 #ifdef CONFIG_SYSCTL
89581 static int nf_conntrack_acct_init_sysctl(struct net *net)
89582 {
89583- struct ctl_table *table;
89584+ ctl_table_no_const *table;
89585
89586 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
89587 GFP_KERNEL);
89588diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
89589index 0283bae..5febcb0 100644
89590--- a/net/netfilter/nf_conntrack_core.c
89591+++ b/net/netfilter/nf_conntrack_core.c
89592@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
89593 #define DYING_NULLS_VAL ((1<<30)+1)
89594 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
89595
89596+#ifdef CONFIG_GRKERNSEC_HIDESYM
89597+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
89598+#endif
89599+
89600 int nf_conntrack_init_net(struct net *net)
89601 {
89602 int ret;
89603@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
89604 goto err_stat;
89605 }
89606
89607+#ifdef CONFIG_GRKERNSEC_HIDESYM
89608+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
89609+#else
89610 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
89611+#endif
89612 if (!net->ct.slabname) {
89613 ret = -ENOMEM;
89614 goto err_slabname;
89615diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
89616index 1df1761..ce8b88a 100644
89617--- a/net/netfilter/nf_conntrack_ecache.c
89618+++ b/net/netfilter/nf_conntrack_ecache.c
89619@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
89620 #ifdef CONFIG_SYSCTL
89621 static int nf_conntrack_event_init_sysctl(struct net *net)
89622 {
89623- struct ctl_table *table;
89624+ ctl_table_no_const *table;
89625
89626 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
89627 GFP_KERNEL);
89628diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
89629index 974a2a4..52cc6ff 100644
89630--- a/net/netfilter/nf_conntrack_helper.c
89631+++ b/net/netfilter/nf_conntrack_helper.c
89632@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
89633
89634 static int nf_conntrack_helper_init_sysctl(struct net *net)
89635 {
89636- struct ctl_table *table;
89637+ ctl_table_no_const *table;
89638
89639 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
89640 GFP_KERNEL);
89641diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
89642index 0ab9636..cea3c6a 100644
89643--- a/net/netfilter/nf_conntrack_proto.c
89644+++ b/net/netfilter/nf_conntrack_proto.c
89645@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
89646
89647 static void
89648 nf_ct_unregister_sysctl(struct ctl_table_header **header,
89649- struct ctl_table **table,
89650+ ctl_table_no_const **table,
89651 unsigned int users)
89652 {
89653 if (users > 0)
89654diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
89655index a99b6c3..3841268 100644
89656--- a/net/netfilter/nf_conntrack_proto_dccp.c
89657+++ b/net/netfilter/nf_conntrack_proto_dccp.c
89658@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
89659 out_invalid:
89660 if (LOG_INVALID(net, IPPROTO_DCCP))
89661 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
89662- NULL, msg);
89663+ NULL, "%s", msg);
89664 return false;
89665 }
89666
89667@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
89668
89669 out_invalid:
89670 if (LOG_INVALID(net, IPPROTO_DCCP))
89671- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
89672+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
89673 return -NF_ACCEPT;
89674 }
89675
89676diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
89677index bd700b4..4a3dc61 100644
89678--- a/net/netfilter/nf_conntrack_standalone.c
89679+++ b/net/netfilter/nf_conntrack_standalone.c
89680@@ -471,7 +471,7 @@ static ctl_table nf_ct_netfilter_table[] = {
89681
89682 static int nf_conntrack_standalone_init_sysctl(struct net *net)
89683 {
89684- struct ctl_table *table;
89685+ ctl_table_no_const *table;
89686
89687 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
89688 GFP_KERNEL);
89689diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89690index 902fb0a..87f7fdb 100644
89691--- a/net/netfilter/nf_conntrack_timestamp.c
89692+++ b/net/netfilter/nf_conntrack_timestamp.c
89693@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89694 #ifdef CONFIG_SYSCTL
89695 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89696 {
89697- struct ctl_table *table;
89698+ ctl_table_no_const *table;
89699
89700 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89701 GFP_KERNEL);
89702diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89703index 3b18dd1..f79e0ca 100644
89704--- a/net/netfilter/nf_log.c
89705+++ b/net/netfilter/nf_log.c
89706@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
89707
89708 #ifdef CONFIG_SYSCTL
89709 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89710-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89711+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89712
89713 static int nf_log_proc_dostring(ctl_table *table, int write,
89714 void __user *buffer, size_t *lenp, loff_t *ppos)
89715@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89716 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
89717 mutex_unlock(&nf_log_mutex);
89718 } else {
89719+ ctl_table_no_const nf_log_table = *table;
89720+
89721 mutex_lock(&nf_log_mutex);
89722 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
89723 lockdep_is_held(&nf_log_mutex));
89724 if (!logger)
89725- table->data = "NONE";
89726+ nf_log_table.data = "NONE";
89727 else
89728- table->data = logger->name;
89729- r = proc_dostring(table, write, buffer, lenp, ppos);
89730+ nf_log_table.data = logger->name;
89731+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89732 mutex_unlock(&nf_log_mutex);
89733 }
89734
89735diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89736index f042ae5..30ea486 100644
89737--- a/net/netfilter/nf_sockopt.c
89738+++ b/net/netfilter/nf_sockopt.c
89739@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89740 }
89741 }
89742
89743- list_add(&reg->list, &nf_sockopts);
89744+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89745 out:
89746 mutex_unlock(&nf_sockopt_mutex);
89747 return ret;
89748@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89749 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89750 {
89751 mutex_lock(&nf_sockopt_mutex);
89752- list_del(&reg->list);
89753+ pax_list_del((struct list_head *)&reg->list);
89754 mutex_unlock(&nf_sockopt_mutex);
89755 }
89756 EXPORT_SYMBOL(nf_unregister_sockopt);
89757diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89758index 962e979..d4ae2e9 100644
89759--- a/net/netfilter/nfnetlink_log.c
89760+++ b/net/netfilter/nfnetlink_log.c
89761@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
89762 struct nfnl_log_net {
89763 spinlock_t instances_lock;
89764 struct hlist_head instance_table[INSTANCE_BUCKETS];
89765- atomic_t global_seq;
89766+ atomic_unchecked_t global_seq;
89767 };
89768
89769 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
89770@@ -559,7 +559,7 @@ __build_packet_message(struct nfnl_log_net *log,
89771 /* global sequence number */
89772 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89773 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89774- htonl(atomic_inc_return(&log->global_seq))))
89775+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
89776 goto nla_put_failure;
89777
89778 if (data_len) {
89779diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89780new file mode 100644
89781index 0000000..c566332
89782--- /dev/null
89783+++ b/net/netfilter/xt_gradm.c
89784@@ -0,0 +1,51 @@
89785+/*
89786+ * gradm match for netfilter
89787